├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── .DS_Store
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── hpsc.jpg
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── dimens.xml
│ │ │ ├── xml
│ │ │ │ ├── authenticator.xml
│ │ │ │ └── syncadapter.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── me
│ │ │ │ └── himanshusoni
│ │ │ │ └── quantumflux
│ │ │ │ └── sample
│ │ │ │ ├── sync
│ │ │ │ ├── SyncConstants.java
│ │ │ │ ├── AuthenticatorService.java
│ │ │ │ ├── SyncService.java
│ │ │ │ ├── SyncAdapter.java
│ │ │ │ ├── Authenticator.java
│ │ │ │ └── SyncUtils.java
│ │ │ │ ├── data
│ │ │ │ ├── Author.java
│ │ │ │ ├── Publisher.java
│ │ │ │ ├── Book.java
│ │ │ │ ├── view
│ │ │ │ │ └── BookAuthor.java
│ │ │ │ └── type
│ │ │ │ │ └── BlobTypeMapping.java
│ │ │ │ ├── SampleApplication.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── me
│ │ └── himanshusoni
│ │ └── quantumflux
│ │ └── sample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── quantum-flux
├── .gitignore
├── .DS_Store
├── src
│ ├── .DS_Store
│ ├── main
│ │ ├── .DS_Store
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── me
│ │ │ │ └── himanshusoni
│ │ │ │ └── quantumflux
│ │ │ │ ├── model
│ │ │ │ ├── annotation
│ │ │ │ │ ├── Authority.java
│ │ │ │ │ ├── References.java
│ │ │ │ │ ├── ChangeListeners.java
│ │ │ │ │ ├── Column
│ │ │ │ │ │ ├── Unique.java
│ │ │ │ │ │ ├── PrimaryKey.java
│ │ │ │ │ │ └── Column.java
│ │ │ │ │ ├── Indices.java
│ │ │ │ │ ├── Index.java
│ │ │ │ │ ├── Table.java
│ │ │ │ │ └── TableConstraint.java
│ │ │ │ ├── util
│ │ │ │ │ ├── QuantumFluxException.java
│ │ │ │ │ ├── NamingUtils.java
│ │ │ │ │ ├── QuantumFluxCursorFactory.java
│ │ │ │ │ ├── ContentResolverValues.java
│ │ │ │ │ ├── ReferenceMap.java
│ │ │ │ │ ├── CursorIterator.java
│ │ │ │ │ ├── TableDetailsCache.java
│ │ │ │ │ ├── QuantumFluxBatchDispatcher.java
│ │ │ │ │ ├── QuantumFluxCursor.java
│ │ │ │ │ ├── ManifestHelper.java
│ │ │ │ │ └── ModelInflater.java
│ │ │ │ ├── generate
│ │ │ │ │ ├── TableView.java
│ │ │ │ │ ├── TableViewGenerator.java
│ │ │ │ │ ├── TableGenerator.java
│ │ │ │ │ └── TableDetails.java
│ │ │ │ ├── map
│ │ │ │ │ ├── types
│ │ │ │ │ │ ├── LongType.java
│ │ │ │ │ │ ├── FloatType.java
│ │ │ │ │ │ ├── ShortType.java
│ │ │ │ │ │ ├── DoubleType.java
│ │ │ │ │ │ ├── IntegerType.java
│ │ │ │ │ │ ├── StringType.java
│ │ │ │ │ │ ├── DateType.java
│ │ │ │ │ │ ├── UUIDType.java
│ │ │ │ │ │ ├── BooleanType.java
│ │ │ │ │ │ ├── BigDecimalType.java
│ │ │ │ │ │ └── CalendarType.java
│ │ │ │ │ ├── SqlColumnMapping.java
│ │ │ │ │ └── SqlColumnMappingFactory.java
│ │ │ │ ├── query
│ │ │ │ │ ├── DataFilterClause.java
│ │ │ │ │ ├── DataGroupClause.java
│ │ │ │ │ ├── SQLSegment.java
│ │ │ │ │ ├── QueryBuilder.java
│ │ │ │ │ ├── DataFilterCriteria.java
│ │ │ │ │ └── DataFilterCriterion.java
│ │ │ │ ├── loader
│ │ │ │ │ ├── QuantumFluxLoaderCallback.java
│ │ │ │ │ ├── support
│ │ │ │ │ │ ├── QuantumFluxLoaderCallback.java
│ │ │ │ │ │ ├── QuantumFluxCursorAdaptor.java
│ │ │ │ │ │ ├── QuantumFluxLoader.java
│ │ │ │ │ │ └── QuantumFluxAsyncCursorAdaptor.java
│ │ │ │ │ ├── QuantumFluxCursorAdaptor.java
│ │ │ │ │ ├── QuantumFluxLoader.java
│ │ │ │ │ └── QuantumFluxAsyncCursorAdaptor.java
│ │ │ │ ├── QuantumFluxBaseRecord.java
│ │ │ │ └── QuantumFluxRecord.java
│ │ │ │ ├── QuantumFluxDatabaseUpgradeListener.java
│ │ │ │ ├── logger
│ │ │ │ └── QuantumFluxLog.java
│ │ │ │ ├── QuantumFluxDatabase.java
│ │ │ │ ├── provider
│ │ │ │ └── util
│ │ │ │ │ └── UriMatcherHelper.java
│ │ │ │ └── QuantumFluxSyncHelper.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── me
│ │ └── himanshusoni
│ │ └── quantumflux
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── quantum-flux.iml
├── settings.gradle
├── .DS_Store
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── QuantumFlux.iml
├── gradlew.bat
├── README.md
└── gradlew
/.idea/.name:
--------------------------------------------------------------------------------
1 | QuantumFlux
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/quantum-flux/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':quantum-flux'
2 |
--------------------------------------------------------------------------------
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/.DS_Store
--------------------------------------------------------------------------------
/app/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/.DS_Store
--------------------------------------------------------------------------------
/quantum-flux/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/quantum-flux/.DS_Store
--------------------------------------------------------------------------------
/quantum-flux/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/quantum-flux/src/.DS_Store
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/quantum-flux/src/main/.DS_Store
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/hpsc.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/src/main/res/drawable/hpsc.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/quantum-flux/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | quantum flux library
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/himanshu-soni/QuantumFlux/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Authority.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | public @interface Authority {
4 | String value();
5 | }
6 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/sync/SyncConstants.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.sync;
2 |
3 | public interface SyncConstants {
4 | String AUTHORITY = "me.himanshusoni.quantumflux.sample";
5 | }
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Quantum Flux Sample
3 |
4 | Hello world!
5 | Settings
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Sep 06 14:06:07 IST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/QuantumFluxDatabaseUpgradeListener.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux;
2 |
3 | /**
4 | * Created by himanshusoni on 06/09/16.
5 | */
6 | public interface QuantumFluxDatabaseUpgradeListener {
7 | void onDatabaseUpgraded(int oldVersion, int newVersion);
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/authenticator.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/syncadapter.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/References.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.FIELD)
10 | public @interface References {
11 |
12 | Class> value();
13 | }
14 |
--------------------------------------------------------------------------------
/quantum-flux/src/androidTest/java/me/himanshusoni/quantumflux/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/me/himanshusoni/quantumflux/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/ChangeListeners.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.TYPE)
10 | public @interface ChangeListeners {
11 | Class>[] changeListeners();
12 | }
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 | /*/build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Log Files
24 | *.log
25 |
26 | # Android studio specific files
27 | /.idea/workspace.xml
28 | /.idea/libraries
29 |
30 | # for MAC OS
31 | .DS_Store
32 | /captures
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Column/Unique.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation.Column;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Indicates a field that should be marked as unique
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.FIELD)
13 | public @interface Unique {
14 | }
15 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/data/Author.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.data;
2 |
3 | import me.himanshusoni.quantumflux.model.QuantumFluxRecord;
4 | import me.himanshusoni.quantumflux.model.annotation.ChangeListeners;
5 | import me.himanshusoni.quantumflux.sample.data.view.BookAuthor;
6 |
7 | /**
8 | * Created by Himanshu on 8/5/2015.
9 | */
10 | @ChangeListeners(changeListeners = BookAuthor.class)
11 | public class Author extends QuantumFluxRecord {
12 | public String name;
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/data/Publisher.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.data;
2 |
3 | import me.himanshusoni.quantumflux.model.annotation.Column.Column;
4 | import me.himanshusoni.quantumflux.model.annotation.Column.PrimaryKey;
5 | import me.himanshusoni.quantumflux.model.annotation.Table;
6 |
7 | /**
8 | * Created by Himanshu on 8/5/2015.
9 | */
10 |
11 | @Table(tableName = "publishers")
12 | public class Publisher {
13 | @PrimaryKey
14 | public long id;
15 |
16 | @Column(required = true)
17 | public String name;
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/util/QuantumFluxException.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.util;
2 |
3 | public class QuantumFluxException extends RuntimeException {
4 |
5 | public QuantumFluxException() {
6 | }
7 |
8 | public QuantumFluxException(String detailMessage) {
9 | super(detailMessage);
10 | }
11 |
12 | public QuantumFluxException(String detailMessage, Throwable throwable) {
13 | super(detailMessage, throwable);
14 | }
15 |
16 | public QuantumFluxException(Throwable throwable) {
17 | super(throwable);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Indices.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Used to indicate all of the indices to be created for a table.
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.TYPE)
13 | public @interface Indices {
14 |
15 | /**
16 | * A collection of indices to be created for the table
17 | */
18 | Index[] indices();
19 | }
20 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Column/PrimaryKey.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation.Column;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Indicates that a field is a primary key field
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.FIELD)
13 | public @interface PrimaryKey {
14 |
15 | /**If this field should be auto incremented. Default is true. Requires that the field type is long*/
16 | boolean autoIncrement() default true;
17 | }
18 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Index.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Creates the specified index for the table
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.ANNOTATION_TYPE)
13 | public @interface Index {
14 |
15 | /**
16 | * The name of this index
17 | */
18 | String indexName();
19 |
20 | /**
21 | * The columns that will be included in the index
22 | */
23 | String[] indexColumns();
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/data/Book.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.data;
2 |
3 | import me.himanshusoni.quantumflux.model.annotation.ChangeListeners;
4 | import me.himanshusoni.quantumflux.model.annotation.Column.PrimaryKey;
5 | import me.himanshusoni.quantumflux.model.annotation.Table;
6 | import me.himanshusoni.quantumflux.sample.data.view.BookAuthor;
7 |
8 | /**
9 | * Created by Himanshu on 8/5/2015.
10 | */
11 |
12 | @Table
13 | @ChangeListeners(changeListeners = BookAuthor.class)
14 | public class Book {
15 |
16 | @PrimaryKey
17 | public long id;
18 | public String name;
19 | public String isbn;
20 |
21 | public long authorId;
22 |
23 | public byte[] bookCover;
24 | }
25 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Himanshu.Lenovo-PC\Desktop\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/quantum-flux/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Himanshu.Lenovo-PC\Desktop\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/generate/TableView.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.generate;
2 |
3 | import me.himanshusoni.quantumflux.model.annotation.Table;
4 |
5 | /**
6 | * Interface to indicate that a Java Object should be treated as a view instead of a table
7 | * that will be auto generated. For that purpose, and due to the complexity that views can take,
8 | * the creation of the Select Statement for the view is left to implementing class.
9 | *
10 | * Note: The class should still have all of the normal {@link Table} annotations.
11 | */
12 | public interface TableView {
13 |
14 | /**
15 | * The SELECT statement that will be used to create the view.
16 | */
17 | String getTableViewSql();
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/data/view/BookAuthor.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.data.view;
2 |
3 | import me.himanshusoni.quantumflux.model.annotation.Column.PrimaryKey;
4 | import me.himanshusoni.quantumflux.model.annotation.Table;
5 | import me.himanshusoni.quantumflux.model.generate.TableView;
6 |
7 | /**
8 | * Created by Himanshu on 8/6/2015.
9 | */
10 |
11 | @Table
12 | public class BookAuthor implements TableView {
13 |
14 | @Override
15 | public String getTableViewSql() {
16 | return "SELECT b._ID, b.NAME, a.NAME FROM book b INNER JOIN author a ON b.author_id = a._id";
17 | }
18 |
19 | @PrimaryKey
20 | private int _id;
21 |
22 | private String bookName;
23 | private String authorName;
24 |
25 |
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion '24.0.1'
6 |
7 | defaultConfig {
8 | applicationId "me.himanshusoni.quantumflux.sample"
9 | minSdkVersion 12
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | // compile 'info.quantumflux:library:0.9.2'
25 | compile project(':quantum-flux')
26 | compile 'com.android.support:appcompat-v7:24.2.0'
27 | }
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Table.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Marks a Java object as table model
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.TYPE)
13 | public @interface Table {
14 |
15 | /**
16 | * the table name to be used for this object. The default will converted the object name and use that instead.
17 | */
18 | String tableName() default "";
19 |
20 | /**
21 | * Any additional constraints that should be added for the table. Todo: Not implemented yet
22 | */
23 | TableConstraint[] constraints() default {};
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/sync/AuthenticatorService.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.sync;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 |
7 | /**
8 | * A bound Service that instantiates the authenticator
9 | * when started.
10 | */
11 | public class AuthenticatorService extends Service {
12 | // Instance field that stores the authenticator object
13 | private Authenticator mAuthenticator;
14 |
15 | @Override
16 | public void onCreate() {
17 | // Create a new authenticator object
18 | mAuthenticator = new Authenticator(this);
19 | }
20 |
21 | /*
22 | * When the system binds to this Service to make the RPC call
23 | * return the authenticator's IBinder.
24 | */
25 | @Override
26 | public IBinder onBind(Intent intent) {
27 | return mAuthenticator.getIBinder();
28 | }
29 | }
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/LongType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class LongType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return Long.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "INTEGER";
17 | }
18 |
19 | @Override
20 | public Object toSqlType(Object source) {
21 | return source;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getLong(columnIndex);
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, (Long) value);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/QuantumFlux.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/TableConstraint.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * An additional constraint that should be applied to the table
10 | */
11 | @Retention(RetentionPolicy.RUNTIME)
12 | @Target(ElementType.TYPE)
13 | public @interface TableConstraint {
14 | public enum Type {
15 | PRIMARY_KEY,
16 | UNIQUE
17 | }
18 |
19 | /**
20 | * The name of this constraint
21 | */
22 | String name();
23 |
24 | /**
25 | * The type of constraint. Primary key should not be used as currently we only support a single primary key field
26 | */
27 | Type constraintType();
28 |
29 | /**
30 | * The columns on which the constraint applies
31 | */
32 | String[] constraintColumns();
33 | }
34 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/FloatType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class FloatType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return Float.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "NUMERIC";
17 | }
18 |
19 | @Override
20 | public Object toSqlType(Object source) {
21 | return source;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getFloat(columnIndex);
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, (Float) value);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/ShortType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class ShortType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return Short.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "INTEGER";
17 | }
18 |
19 | @Override
20 | public Object toSqlType(Object source) {
21 | return source;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getShort(columnIndex);
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, (Short) value);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/DoubleType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class DoubleType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return Double.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "REAL";
17 | }
18 |
19 | @Override
20 | public Object toSqlType(Object source) {
21 | return source;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getDouble(columnIndex);
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, (Double) value);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/IntegerType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class IntegerType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return Integer.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "INTEGER";
17 | }
18 |
19 | @Override
20 | public Object toSqlType(Object source) {
21 | return source;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getInt(columnIndex);
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, (Integer) value);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/StringType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class StringType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return String.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "TEXT";
17 | }
18 |
19 | @Override
20 | public Object toSqlType(Object source) {
21 | return (String) source;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getString(columnIndex);
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, (String) value);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/query/DataFilterClause.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.query;
2 |
3 | import java.io.Serializable;
4 |
5 | import me.himanshusoni.quantumflux.model.map.SqlColumnMappingFactory;
6 |
7 | /**
8 | * Defines a basic clause interface, that can be used to join queries together
9 | */
10 | public interface DataFilterClause extends Serializable {
11 |
12 | boolean hasFilterValue();
13 |
14 | /**
15 | * The filter conjunction, this is equal to SQL AND and OR
16 | */
17 | public enum DataFilterConjunction {
18 | AND, OR
19 | }
20 |
21 | /**
22 | * The where clause for this query
23 | */
24 | QueryBuilder buildWhereClause(SqlColumnMappingFactory columnMappingFactory);
25 |
26 | /**
27 | * The where clause for this query, without parameters
28 | */
29 | String getWhereClause();
30 |
31 | T addClause(DataFilterClause clause, DataFilterConjunction conjunction);
32 | }
33 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/generate/TableViewGenerator.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.generate;
2 |
3 | import me.himanshusoni.quantumflux.model.util.QuantumFluxException;
4 |
5 | /**
6 | * Generates the statements required to drop and create views
7 | */
8 | public class TableViewGenerator {
9 |
10 | public static String createDropViewStatement(TableDetails tableDetails) {
11 | return "DROP VIEW IF EXISTS " + tableDetails.getTableName();
12 | }
13 |
14 | public static String createViewStatement(TableDetails tableDetails, Class extends TableView> view) {
15 | TableView tableView;
16 | try {
17 | tableView = view.getConstructor().newInstance();
18 | } catch (Exception e) {
19 | throw new QuantumFluxException("Failed to instantiate view " + view.getSimpleName(), e);
20 | }
21 |
22 | return "CREATE VIEW IF NOT EXISTS " + tableDetails.getTableName() + " AS " + tableView.getTableViewSql();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/query/DataGroupClause.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.query;
2 |
3 | import java.io.Serializable;
4 |
5 | import me.himanshusoni.quantumflux.model.map.SqlColumnMappingFactory;
6 |
7 | /**
8 | * Defines a basic group clause interface, that can be used to join queries together
9 | */
10 | public interface DataGroupClause extends Serializable {
11 |
12 | boolean hasFilterValue();
13 |
14 | /**
15 | * The filter conjunction, this is equal to SQL AND and OR
16 | */
17 | public enum DataFilterConjunction {
18 | AND, OR
19 | }
20 |
21 | /**
22 | * The where clause for this query
23 | */
24 | QueryBuilder buildWhereClause(SqlColumnMappingFactory columnMappingFactory);
25 |
26 | /**
27 | * The where clause for this query, without parameters
28 | */
29 | String getWhereClause();
30 |
31 | T addClause(DataGroupClause clause, DataFilterConjunction conjunction);
32 | }
33 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/DateType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import java.util.Date;
7 |
8 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
9 |
10 | public class DateType implements SqlColumnMapping {
11 | @Override
12 | public Class> getJavaType() {
13 | return Date.class;
14 | }
15 |
16 | @Override
17 | public String getSqlColumnTypeName() {
18 | return "INTEGER";
19 | }
20 |
21 | @Override
22 | public Long toSqlType(Object source) {
23 | return ((Date) source).getTime();
24 | }
25 |
26 | @Override
27 | public Object getColumnValue(Cursor cursor, int columnIndex) {
28 | return new Date(cursor.getLong(columnIndex));
29 | }
30 |
31 | @Override
32 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
33 | contentValues.put(key, toSqlType(value));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/UUIDType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import java.util.UUID;
7 |
8 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
9 |
10 | public class UUIDType implements SqlColumnMapping {
11 | @Override
12 | public Class> getJavaType() {
13 | return UUID.class;
14 | }
15 |
16 | @Override
17 | public String getSqlColumnTypeName() {
18 | return "TEXT";
19 | }
20 |
21 | @Override
22 | public String toSqlType(Object source) {
23 | return source.toString();
24 | }
25 |
26 | @Override
27 | public Object getColumnValue(Cursor cursor, int columnIndex) {
28 | return UUID.fromString(cursor.getString(columnIndex));
29 | }
30 |
31 | @Override
32 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
33 | contentValues.put(key, toSqlType(value));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/BooleanType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
7 |
8 | public class BooleanType implements SqlColumnMapping {
9 | @Override
10 | public Class> getJavaType() {
11 | return Boolean.class;
12 | }
13 |
14 | @Override
15 | public String getSqlColumnTypeName() {
16 | return "INTEGER";
17 | }
18 |
19 | @Override
20 | public Integer toSqlType(Object source) {
21 | return ((Boolean) source) ? 1 : 0;
22 | }
23 |
24 | @Override
25 | public Object getColumnValue(Cursor cursor, int columnIndex) {
26 | return cursor.getInt(columnIndex) == 0 ? Boolean.FALSE : Boolean.TRUE;
27 | }
28 |
29 | @Override
30 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
31 | contentValues.put(key, toSqlType(value));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/BigDecimalType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import java.math.BigDecimal;
7 |
8 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
9 |
10 | public class BigDecimalType implements SqlColumnMapping {
11 | @Override
12 | public Class> getJavaType() {
13 | return BigDecimal.class;
14 | }
15 |
16 | @Override
17 | public String getSqlColumnTypeName() {
18 | return "TEXT";
19 | }
20 |
21 | @Override
22 | public String toSqlType(Object source) {
23 | return (source.toString());
24 | }
25 |
26 | @Override
27 | public Object getColumnValue(Cursor cursor, int columnIndex) {
28 | return new BigDecimal(cursor.getString(columnIndex));
29 | }
30 |
31 | @Override
32 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
33 | contentValues.put(key, toSqlType(value));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/util/NamingUtils.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.util;
2 |
3 | /**
4 | * Contains common naming utilities to convert strings to SQL formats
5 | */
6 | public class NamingUtils {
7 |
8 | /**
9 | * Converts the source string to a SQL compatible string. It does this
10 | * by checking for camelcase values, and applying a underscore '_' to whenever one is found. All
11 | * characters are also converted to lower case.
12 | *
13 | * Example: If the provided string is "helloWorld" the resulting string will be "hello_world"
14 | *
15 | * @param original String to converted
16 | * @return the converted string
17 | */
18 | public static String getSQLName(String original) {
19 | StringBuilder sqlName = new StringBuilder();
20 |
21 | for (char character : original.toCharArray()) {
22 | if (Character.isUpperCase(character) && sqlName.length() > 0) sqlName.append("_");
23 | sqlName.append(Character.toLowerCase(character));
24 | }
25 | return sqlName.toString();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/util/QuantumFluxCursorFactory.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.util;
2 |
3 | import android.database.Cursor;
4 | import android.database.sqlite.SQLiteCursor;
5 | import android.database.sqlite.SQLiteCursorDriver;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteQuery;
8 |
9 | import me.himanshusoni.quantumflux.logger.QuantumFluxLog;
10 |
11 | public class QuantumFluxCursorFactory implements SQLiteDatabase.CursorFactory {
12 |
13 | private final boolean isDebugEnabled;
14 |
15 | public QuantumFluxCursorFactory(TableDetailsCache tableDetailCache) {
16 | this(false);
17 | }
18 |
19 | public QuantumFluxCursorFactory(boolean debugEnabled) {
20 | this.isDebugEnabled = debugEnabled;
21 | }
22 |
23 | @Override
24 | public Cursor newCursor(SQLiteDatabase sqLiteDatabase, SQLiteCursorDriver sqLiteCursorDriver, String tableName, SQLiteQuery sqLiteQuery) {
25 | if (isDebugEnabled) {
26 | QuantumFluxLog.d(sqLiteQuery.toString());
27 | }
28 |
29 | return new SQLiteCursor(sqLiteCursorDriver, tableName, sqLiteQuery);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/types/CalendarType.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map.types;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | import java.util.Calendar;
7 |
8 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
9 |
10 | public class CalendarType implements SqlColumnMapping {
11 | @Override
12 | public Class> getJavaType() {
13 | return Calendar.class;
14 | }
15 |
16 | @Override
17 | public String getSqlColumnTypeName() {
18 | return "INTEGER";
19 | }
20 |
21 | @Override
22 | public Long toSqlType(Object source) {
23 | return ((Calendar) source).getTimeInMillis();
24 | }
25 |
26 | @Override
27 | public Object getColumnValue(Cursor cursor, int columnIndex) {
28 | long time = cursor.getLong(columnIndex);
29 | Calendar calendar = Calendar.getInstance();
30 | calendar.setTimeInMillis(time);
31 | return calendar;
32 | }
33 |
34 | @Override
35 | public void setColumnValue(ContentValues contentValues, String key, Object value) {
36 | contentValues.put(key, toSqlType(value));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import java.util.ArrayList;
7 |
8 | import me.himanshusoni.quantumflux.QuantumFlux;
9 | import me.himanshusoni.quantumflux.QuantumFluxDatabaseUpgradeListener;
10 | import me.himanshusoni.quantumflux.model.map.SqlColumnMapping;
11 | import me.himanshusoni.quantumflux.sample.data.type.BlobTypeMapping;
12 |
13 | /**
14 | * Created by Himanshu on 8/5/2015.
15 | */
16 | public class SampleApplication extends Application {
17 |
18 | @Override
19 | protected void attachBaseContext(Context base) {
20 | super.attachBaseContext(base);
21 |
22 | ArrayList mappings = new ArrayList<>();
23 | mappings.add(new BlobTypeMapping());
24 |
25 | QuantumFlux.initialize(this, mappings, new QuantumFluxDatabaseUpgradeListener() {
26 | @Override
27 | public void onDatabaseUpgraded(int oldVersion, int newVersion) {
28 |
29 | }
30 | });
31 | }
32 |
33 | @Override
34 | public void onCreate() {
35 | super.onCreate();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/annotation/Column/Column.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.annotation.Column;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Identifies a field as database column to be generated.
10 | */
11 |
12 | @Retention(RetentionPolicy.RUNTIME)
13 | @Target(ElementType.FIELD)
14 | public @interface Column {
15 |
16 | /**
17 | * The name of the column, if none is provided, the field name will be converted and used instead
18 | */
19 | String columnName() default "";
20 |
21 | /**
22 | * If the field should be set required/nullable, the default is true
23 | */
24 | boolean required() default false;
25 |
26 | /**
27 | * If this setting is set to true, changes will be notified on the content resolver, if it is false it will not.
28 | * If more than one column is passed through on updates, changes will be notified if at least one of the columns being
29 | * updated is set to true.
30 | *
31 | * @return true if changes are to be notified, false otherwise. Default is true.
32 | */
33 | boolean notifyChanges() default true;
34 | }
35 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/loader/QuantumFluxLoaderCallback.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.loader;
2 |
3 | import android.app.LoaderManager;
4 | import android.content.Context;
5 | import android.content.Loader;
6 | import android.database.Cursor;
7 | import android.os.Bundle;
8 | import android.widget.CursorAdapter;
9 |
10 | import me.himanshusoni.quantumflux.model.query.Select;
11 |
12 | public class QuantumFluxLoaderCallback implements LoaderManager.LoaderCallbacks {
13 |
14 | private final Context mContext;
15 | private final CursorAdapter mAdapter;
16 | private final Select mSelect;
17 |
18 | public QuantumFluxLoaderCallback(Context context, CursorAdapter listAdapter, Select select) {
19 | this.mContext = context;
20 | this.mAdapter = listAdapter;
21 | this.mSelect = select;
22 | }
23 |
24 | @Override
25 | public Loader onCreateLoader(int id, Bundle args) {
26 | return new QuantumFluxLoader(mContext, mSelect);
27 | }
28 |
29 | @Override
30 | public void onLoadFinished(Loader loader, Cursor data) {
31 | mAdapter.changeCursor(data);
32 | }
33 |
34 | @Override
35 | public void onLoaderReset(Loader loader) {
36 | mAdapter.changeCursor(null);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/loader/support/QuantumFluxLoaderCallback.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.loader.support;
2 |
3 | import android.content.Context;
4 | import android.database.Cursor;
5 | import android.os.Bundle;
6 | import android.support.v4.app.LoaderManager;
7 | import android.support.v4.content.Loader;
8 | import android.support.v4.widget.CursorAdapter;
9 |
10 | import me.himanshusoni.quantumflux.model.query.Select;
11 |
12 |
13 | public class QuantumFluxLoaderCallback implements LoaderManager.LoaderCallbacks {
14 |
15 | private final Context mContext;
16 | private final CursorAdapter mAdapter;
17 | private final Select mSelect;
18 |
19 | public QuantumFluxLoaderCallback(Context context, CursorAdapter listAdapter, Select select) {
20 | this.mContext = context;
21 | this.mAdapter = listAdapter;
22 | this.mSelect = select;
23 | }
24 |
25 | @Override
26 | public Loader onCreateLoader(int id, Bundle args) {
27 | return new QuantumFluxLoader(mContext, mSelect);
28 | }
29 |
30 | @Override
31 | public void onLoadFinished(Loader loader, Cursor data) {
32 | mAdapter.changeCursor(data);
33 | }
34 |
35 | @Override
36 | public void onLoaderReset(Loader loader) {
37 | mAdapter.changeCursor(null);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/util/ContentResolverValues.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.util;
2 |
3 | import android.net.Uri;
4 |
5 | import me.himanshusoni.quantumflux.model.generate.TableDetails;
6 |
7 | public class ContentResolverValues {
8 |
9 | private final TableDetails mTableDetails;
10 | private final Uri mUri;
11 | private final String[] mProjection;
12 | private final String mWhere;
13 | private final String[] mWhereArgs;
14 | private final String mSortOrder;
15 |
16 | public ContentResolverValues(TableDetails tableDetails, Uri itemUri, String[] projection, String where, String[] whereArgs, String sortOrder) {
17 | this.mTableDetails = tableDetails;
18 | this.mUri = itemUri;
19 | this.mProjection = projection;
20 | this.mWhere = where;
21 | this.mWhereArgs = whereArgs;
22 | this.mSortOrder = sortOrder;
23 | }
24 |
25 | public TableDetails getTableDetails() {
26 | return mTableDetails;
27 | }
28 |
29 | public Uri getItemUri() {
30 | return mUri;
31 | }
32 |
33 | public String[] getProjection() {
34 | return mProjection;
35 | }
36 |
37 | public String getWhere() {
38 | return mWhere;
39 | }
40 |
41 | public String[] getWhereArgs() {
42 | return mWhereArgs;
43 | }
44 |
45 | public String getSortOrder() {
46 | return mSortOrder;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/query/SQLSegment.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.query;
2 |
3 | import android.text.TextUtils;
4 |
5 | import me.himanshusoni.quantumflux.model.map.SqlColumnMappingFactory;
6 | import me.himanshusoni.quantumflux.model.util.QuantumFluxException;
7 |
8 | public class SQLSegment implements DataFilterClause {
9 |
10 | private final String mSqlSegment;
11 | private final Object[] mArgs;
12 |
13 | public SQLSegment(String sqlSegment, Object... args) {
14 | this.mSqlSegment = sqlSegment;
15 | this.mArgs = args;
16 | }
17 |
18 | @Override
19 | public QueryBuilder buildWhereClause(SqlColumnMappingFactory columnMappingFactory) {
20 | for (int i = 0; i < mArgs.length; i++) {
21 | Object argObject = mArgs[i];
22 | mArgs[i] = columnMappingFactory.findColumnMapping(argObject.getClass()).toSqlType(argObject);
23 | }
24 | return new QueryBuilder(mSqlSegment, mArgs);
25 | }
26 |
27 |
28 | @Override
29 | public String getWhereClause() {
30 | return mSqlSegment;
31 | }
32 |
33 | @Override
34 | public SQLSegment addClause(DataFilterClause clause, DataFilterConjunction conjunction) {
35 | throw new QuantumFluxException("Clauses cannot be added to a data filter criterion");
36 | }
37 |
38 | @Override
39 | public boolean hasFilterValue() {
40 | return !TextUtils.isEmpty(mSqlSegment);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/quantum-flux/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion '24.0.1'
6 | resourcePrefix "qf_"
7 |
8 | defaultConfig {
9 | minSdkVersion 12
10 | targetSdkVersion 24
11 | versionCode 3
12 | versionName "0.9.3"
13 | }
14 | buildTypes {
15 | }
16 | }
17 |
18 | ext {
19 | bintrayRepo = 'maven'
20 | bintrayName = 'quantum-flux'
21 |
22 | publishedGroupId = 'me.himanshusoni'
23 | libraryName = 'quantum-flux'
24 | artifact = 'quantum-flux'
25 |
26 | libraryDescription = 'A Powerful Android Content Provider ORM'
27 |
28 | siteUrl = 'https://github.com/himanshu-soni/QuantumFlux'
29 | gitUrl = 'https://github.com/himanshu-soni/QuantumFlux.git'
30 |
31 | libraryVersion = '0.9.3'
32 |
33 | developerId = 'himanshu-soni'
34 | developerName = 'Himanshu Soni'
35 | developerEmail = 'himanshusoni.me@gmail.com'
36 |
37 | licenseName = 'The Apache Software License, Version 2.0'
38 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
39 | allLicenses = ["Apache-2.0"]
40 | }
41 |
42 | apply from: 'https://raw.githubusercontent.com/himanshu-soni/QuantityView/master/install.gradle'
43 | apply from: 'https://raw.githubusercontent.com/himanshu-soni/QuantityView/master/bintray.gradle'
44 |
45 |
46 | dependencies {
47 | compile fileTree(include: ['*.jar'], dir: 'libs')
48 | compile 'com.android.support:support-v4:24.2.0'
49 | }
50 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/logger/QuantumFluxLog.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.logger;
2 |
3 | import android.util.Log;
4 |
5 | public class QuantumFluxLog {
6 |
7 | private final static String TAG = "QuantumFlux";
8 |
9 | public static int println(int level, String msg) {
10 | return Log.println(level, TAG, msg);
11 | }
12 |
13 | public static int v(String msg) {
14 | return Log.v(TAG, msg);
15 | }
16 |
17 | public static int v(String msg, Throwable th) {
18 | return Log.v(TAG, msg, th);
19 | }
20 |
21 | public static int d(String msg) {
22 | return Log.d(TAG, msg);
23 | }
24 |
25 | public static int d(String msg, Throwable th) {
26 | return Log.d(TAG, msg, th);
27 | }
28 |
29 | public static int i(String msg) {
30 | return Log.i(TAG, msg);
31 | }
32 |
33 | public static int i(String msg, Throwable th) {
34 | return Log.i(TAG, msg, th);
35 | }
36 |
37 | public static int w(String msg) {
38 | return Log.w(TAG, msg);
39 | }
40 |
41 | public static int w(String msg, Throwable th) {
42 | return Log.w(TAG, msg, th);
43 | }
44 |
45 | public static int w(Throwable th) {
46 | return Log.w(TAG, th);
47 | }
48 |
49 | public static int e(String msg) {
50 | return Log.w(TAG, msg);
51 | }
52 |
53 | public static int e(String msg, Throwable th) {
54 | return Log.e(TAG, msg, th);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/QuantumFluxBaseRecord.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model;
2 |
3 | import android.content.ContentProviderOperation;
4 |
5 | import java.util.Iterator;
6 |
7 | import me.himanshusoni.quantumflux.QuantumFlux;
8 |
9 | /**
10 | * This class is just a wrapper for {@link QuantumFlux}, sub classes can extend this
11 | * to invoke the basic crud operations on the class itself.
12 | */
13 | public abstract class QuantumFluxBaseRecord {
14 |
15 | public QuantumFluxBaseRecord() {
16 | }
17 |
18 | public Iterator findAll() {
19 | return (Iterator) QuantumFlux.findAll(getClass());
20 | }
21 |
22 | public T findByPrimaryKey(Object key) {
23 | return (T) QuantumFlux.findByPrimaryKey(getClass(), key);
24 | }
25 |
26 | public void insert() {
27 | QuantumFlux.insert(this);
28 | }
29 |
30 | public ContentProviderOperation prepareInsert() {
31 | return QuantumFlux.prepareInsert(this);
32 | }
33 |
34 | public T insertAndReturn() {
35 | return (T) QuantumFlux.insertAndReturn(this);
36 | }
37 |
38 | public void update() {
39 | QuantumFlux.update(this);
40 | }
41 |
42 | public ContentProviderOperation prepareUpdate() {
43 | return QuantumFlux.prepareUpdate(this);
44 | }
45 |
46 | public void delete() {
47 | QuantumFlux.delete(this);
48 | }
49 |
50 | public ContentProviderOperation prepareDelete() {
51 | return QuantumFlux.prepareDelete(this);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/me/himanshusoni/quantumflux/sample/sync/SyncService.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.sample.sync;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.IBinder;
6 |
7 | /**
8 | * Created by Himanshu on 7/29/2015.
9 | */
10 | public class SyncService extends Service {
11 | // Storage for an instance of the sync adapter
12 | private static SyncAdapter sSyncAdapter = null;
13 | // Object to use as a thread-safe lock
14 | private static final Object sSyncAdapterLock = new Object();
15 |
16 | /*
17 | * Instantiate the sync adapter object.
18 | */
19 | @Override
20 | public void onCreate() {
21 | /*
22 | * Create the sync adapter as a singleton.
23 | * Set the sync adapter as syncable
24 | * Disallow parallel syncs
25 | */
26 | synchronized (sSyncAdapterLock) {
27 | if (sSyncAdapter == null) {
28 | sSyncAdapter = new SyncAdapter(getApplicationContext(), true);
29 | }
30 | }
31 | }
32 |
33 | /**
34 | * Return an object that allows the system to invoke
35 | * the sync adapter.
36 | */
37 | @Override
38 | public IBinder onBind(Intent intent) {
39 | /*
40 | * Get the object that allows external processes
41 | * to call onPerformSync(). The object is created
42 | * in the base class code when the SyncAdapter
43 | * constructors call super()
44 | */
45 | return sSyncAdapter.getSyncAdapterBinder();
46 | }
47 | }
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/map/SqlColumnMapping.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.map;
2 |
3 | import android.content.ContentValues;
4 | import android.database.Cursor;
5 |
6 | /**
7 | * This allows us to handle the mapping of objects to and from sql
8 | * in an easy way without having to worry about the implicit type
9 | */
10 | public interface SqlColumnMapping {
11 |
12 | /** The java type this mapping will represent */
13 | Class> getJavaType();
14 |
15 | /** The SQL equivalent column name that will be used to store this type */
16 | String getSqlColumnTypeName();
17 |
18 | /** Converts the source object to the correct representation to be stored in the sql database.
19 | * For example, a Date might be stored as a millisecond long, this will convert the date object to milliseconds.
20 | */
21 | Object toSqlType(Object source);
22 |
23 | /** Gets the appropriate column value from the column in the cursor, it will then
24 | * convert that to the correct java type.
25 | * For example, a Date might be stored as a millisecond long, this will take the long, and a create a new Data object.
26 | */
27 | Object getColumnValue(Cursor cursor, int columnIndex);
28 |
29 | /**
30 | * This will convert and set the correct object type for supplied value.
31 | * An explanation for the conversion can be found on toSqlType(Object source);
32 | * @param contentValues The content values that the object will be placed in
33 | * @param key The key that the object should placed into
34 | * @param value The source object to be converted
35 | */
36 | void setColumnValue(ContentValues contentValues, String key, Object value);
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
16 |
17 |
25 |
26 |
35 |
36 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/quantum-flux/src/main/java/me/himanshusoni/quantumflux/model/query/QueryBuilder.java:
--------------------------------------------------------------------------------
1 | package me.himanshusoni.quantumflux.model.query;
2 |
3 | import java.io.Serializable;
4 | import java.util.Arrays;
5 | import java.util.Collection;
6 | import java.util.Collections;
7 | import java.util.LinkedList;
8 | import java.util.List;
9 |
10 | /**
11 | * This class will keep track of the query and its supplied arguments , so that when multiple
12 | * queries are appended, the query and arguments will always match up.
13 | */
14 | public class QueryBuilder implements Serializable {
15 |
16 | private final StringBuilder mQueryBuffer;
17 | private final List