diff --git a/.gitignore b/.gitignore
index b2d2fc5b..8cfcff0b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,45 @@
-library/bin
-library/gen
-library/.project
-library/.classpath
+.DS_Store
+
+# built application files
+*.apk
+*.ap_
+
+# files for the dex VM
+*.dex
+
+# Java class files
*.class
+
+# generated files
+bin/
+gen/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Eclipse project files
+.classpath
+.project
+
+*.a
+*.dylib
+*.log
+*.o
+*.pot
+*.pyc
+*.pydevproject
+*.so
+*.suo
+*.xcworkspace
+*_ReSharper*
+
.DS_Store
+._.DS_Store
+
+project.properties
+
+.settings
+build/
+.gradle/
+.idea
+*.iml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..6e0beddd
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,31 @@
+language: android
+jdk: oraclejdk7
+
+env:
+ global:
+ - TERM=dumb
+android:
+ components:
+ - sys-img-armeabi-v7a-android-23
+ - tools
+ - build-tools-23.0.3
+ - android-23
+ - extra-android-m2repository
+before_script:
+ - sudo service postgresql stop || true
+ - sudo service mysql stop || true
+ - sudo service memcached stop || true
+ - sudo service bootlogd stop || true
+ - sudo service elasticsearch stop || true
+ - sudo service mongodb stop || true
+ - sudo service neo4j stop || true
+ - sudo service cassandra stop || true
+ - sudo service riak stop || true
+ - sudo service rsync stop || true
+ - sudo service x11-common stop || true
+script:
+ - ./gradlew clean build connectedCheck coveralls
+
+cache:
+ directories:
+ - $HOME/.m2
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..7015053d
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,94 @@
+# Sugar Releases
+
+## [Unreleased]
+
+
+## v1.5
+### Added
+* [#328](https://github.com/satyan/sugar/pull/328) @jedid auto add new columns during database upgrade, fix [#299](https://github.com/satyan/sugar/issues/299) and [#151](https://github.com/satyan/sugar/issues/151)
+* [#389](https://github.com/satyan/sugar/pull/389) @alfmatos MultiUnique DSL to handle MultiColumn Unique Table constraint
+* @sibeliusseraphini update, updateInTx methods based on Unique values of SugarRecord
+* [#155](https://github.com/satyan/sugar/issues/155) @benohalloran adding Cursors for Cursor Adapters [Pull 312](https://github.com/satyan/sugar/pull/312)
+* [#430](https://github.com/satyan/sugar/pull/430) @sibeliusseraphini update to roboelectric 3.0 and target android-32
+
+### Changed
+* [#437](https://github.com/satyan/sugar/pull/437) @dnalves removing guava dependency, using synchronized WeakHashMap instead
+* [#423](https://github.com/satyan/sugar/pull/423) @sibeliusseraphini moving changelog of README.md to CHANGELOG.md
+
+### Fixed
+* [#362](https://github.com/satyan/sugar/pull/362) @mitchyboy9 fixed NoClassDefFoundError
+* [#455](https://github.com/satyan/sugar/pull/455) @nurolopher fixed travis and coveralls config
+* [#434](https://github.com/satyan/sugar/pull/434) @bendaniel10 fix multi-dex
+* [#410](https://github.com/satyan/sugar/pull/410) [#408](https://github.com/satyan/sugar/pull/408) @RoyMontoya simplify code
+* [#327](https://github.com/satyan/sugar/pull/327) @tracytheron support multi-dex
+* [#373](https://github.com/satyan/sugar/pull/373) @salimkamboh use existing tables
+
+## v1.4
+### Added
+* [#306](https://github.com/satyan/sugar/pull/306) @Shyish return boolean/integer on delete methods
+* [#304](https://github.com/satyan/sugar/pull/304) @benohalloran add support to enum type
+* [#197](https://github.com/satyan/sugar/pull/197) @andresteves add suport for bytes[]
+* [#293](https://github.com/satyan/sugar/pull/293) @neilw4 support NULL in queries
+* [#273](https://github.com/satyan/sugar/pull/273) @dominicwong617 findById support an array of ids
+* [#246](https://github.com/satyan/sugar/pull/246) @kwf2030 use sqlite\_master to check whether table already exist
+* [#253](https://github.com/satyan/sugar/pull/202) @JeroenMols add bulk delete
+* [#285](https://github.com/satyan/sugar/pull/202) @Shyish add listAll with orderBy param
+* No need to extend SugarApp - just call SugarContext.init(Context) instead
+* [#129](https://github.com/satyan/sugar/pull/129) @satyan support sugar entities using @Table annotations
+
+### Fixed
+* [#314](https://github.com/satyan/sugar/pull/314) @abscondment fix StrictMode DexFile
+* [#303](https://github.com/satyan/sugar/pull/303) @RossinesP fixed saving row string bug
+* [#258](https://github.com/satyan/sugar/pull/258) @nosrak113 change SugarRecord ID to private to not conflit with other libraries
+* [#254](https://github.com/satyan/sugar/pull/254) @jivimberg use weak keys to keep track of annotated entities
+* [#215](https://github.com/satyan/sugar/issues/215) @jivimberg fix bug persisting relationship
+* [#185](https://github.com/satyan/sugar/issues/185) [#243](https://github.com/satyan/sugar/issues/243) @whoshuu fix save and update method
+* [#202](https://github.com/satyan/sugar/pull/202) @allieus improve getDomainsClass()
+* [#104](https://github.com/satyan/sugar/issues/104) @whoshuu fix nesting "and" and "or"
+
+## v1.4 Beta [[jar](https://github.com/satyan/sugar/releases/download/v1.4_beta/sugar-1.4_beta.jar)]
+### Added
+* [#112](https://github.com/satyan/sugar/pull/112) @androdevcafe added Unique and NotNull annotations
+* [#78](https://github.com/satyan/sugar/pull/78) @HiddenCleverde capability to specify primary key
+
+### Fixed
+* [#113](https://github.com/satyan/sugar/pull/113) @whoshuu override findById to support int
+* [#106](https://github.com/satyan/sugar/issues/106) @whoshuu add documentation to onTerminate
+* [#54](https://github.com/satyan/sugar/issues/54) @whoshuu simplify count interface
+* [#43](https://github.com/satyan/sugar/issues/43) @whoshuu return id on save
+* [#72](https://github.com/satyan/sugar/issues/72) @whoshuu allow null values to Date and Calendar objects
+* [#96](https://github.com/satyan/sugar/issues/96) @whoshuu roboeletric fallback
+
+## v1.3 [[jar](https://github.com/satyan/sugar/releases/download/v1.3/sugar-1.3.jar)]
+
+- Transaction Support
+- Bulk Insert of records
+- Encrypted datastore (branch : sugar-cipher using sqlcipher)
+- Removed Constructor with context parameter. Needs default constructor now.
+- Enhancements to QueryBuilder
+- Bug fixes and other improvements.
+
+## v1.2 [[jar](https://github.com/satyan/sugar/releases/download/v1.2/sugar-1.2.jar)]
+
+- package restriction for domain classes.
+- metadata caching
+- QueryBuilder v1
+- Database Migrations
+- Provision for Raw queries
+- Better and more organized api guide and usage instructions.
+
+## v1.1 [[jar](https://github.com/satyan/sugar/releases/download/v1.1/sugar-1.1.jar)]
+
+- Static api doesn't take context anymore. Hence
+
+```java
+Book.findById(context, Book.class, 1);
+```
+
+becomes
+
+```java
+Book.findById(Book.class, 1);
+```
+
+- Some cleanup in the code.
diff --git a/README.md b/README.md
index e6916fb1..e91b5182 100644
--- a/README.md
+++ b/README.md
@@ -1,34 +1,160 @@
-Please follow the documentation at
-http://satyan.github.io/sugar
+#Sugar Cipher using Sugar ORM v2.4
+ by Ethan Tam(sbhkin)
-The example application is provided in the "example" folder in the source.
+- Extract the libs and assets into your application. This dependency is not included in the sugar library.
+- Clone this branch to you Project root folder
+- Follow [How to use master version](#usemasterv)
+- Add a meta property named DB_PASSWORD in your manifest file along with other Sugar configuration as follows:
+```
+
+```
-# Getting Started:
+You're good to go. Use Sugar as usual and your database is encrypted now.
-Sugar is now available as a library project also. Add it to your project and utilize the latest changes.
-The project is available in the folder "library"
-http://developer.android.com/tools/projects/index.html#LibraryProjects
+# Sugar ORM
-# New in version 1.2
+### How to use master version
+First, download sugar repository
+```
+git clone git@github.com:satyan/sugar.git
+```
-1. package restriction for domain classes.
-2. metadata caching
-3. QueryBuilder v1
-4. Database Migrations
-5. Provision for Raw queries
-6. Better and more organized api guide and usage instructions.
+include this in your **settings.gradle**
+```gradle
+include ':app' // your module app
+include ':sugar'
-# What's new in 1.1:
+def getLocalProperty(prop) {
+ Properties properties = new Properties()
+ properties.load(new File(rootDir.absolutePath + '/local.properties').newDataInputStream())
+ return properties.getProperty(prop, '')
+}
-1. Static api doesn't take context anymore. Hence
+project(':sugar').projectDir = new File(getLocalProperty('sugar.dir'))
- Book.findById(context, Book.class, 1);
+```
- becomes
+include this in your **local.properties**
+```
+sugar.dir=/path/to/sugar/library
+```
- Book.findById(Book.class, 1);
+add sugar project to the dependencies of your main project (build.gradle)
+```gradle
+dependencies {
+ compile project(':sugar')
+}
+```
+You should also comment this line just comment this line (library/build.gradle): https://github.com/satyan/sugar/blob/master/library%2Fbuild.gradle#L2
-2. Some cleanup in the code.
+```gradle
+// apply from: '../maven_push.gradle'
+```
+===================
+After installing, check out how to set up your first database and models [here](http://satyan.github.io/sugar/getting-started.html) **Outdated**. Check examples of 1.4 and master below:
+
+## Examples
+### SugarRecord
+```java
+public class Book extends SugarRecord {
+ @Unique
+ String isbn;
+ String title;
+ String edition;
+
+ // Default constructor is necessary for SugarRecord
+ public Book() {
+
+ }
+
+ public Book(String isbn, String title, String edition) {
+ this.isbn = isbn;
+ this.title = title;
+ this.edition = edition;
+ }
+}
+```
+or
+```java
+@Table
+public class Book { ... }
+```
+
+### Save Entity
+```java
+Book book = new Book("isbn123", "Title here", "2nd edition")
+book.save();
+```
+
+or
+```java
+SugarRecord.save(book); // if using the @Table annotation
+```
+
+### Load Entity
+```java
+Book book = Book.findById(Book.class, 1);
+```
+
+### Update Entity
+```java
+Book book = Book.findById(Book.class, 1);
+book.title = "updated title here"; // modify the values
+book.edition = "3rd edition";
+book.save(); // updates the previous entry with new values.
+```
+
+
+### Delete Entity
+```java
+Book book = Book.findById(Book.class, 1);
+book.delete();
+```
+
+or
+```java
+SugarRecord.delete(book); // if using the @Table annotation
+```
+
+### Update Entity based on Unique values
+```java
+Book book = new Book("isbn123", "Title here", "2nd edition")
+book.save();
+
+// Update book with isbn123
+Book sameBook = new Book("isbn123", "New Title", "5th edition")
+sameBook.update();
+
+book.getId() == sameBook.getId(); // true
+```
+
+or
+```java
+SugarRecord.update(sameBook); // if using the @Table annotation
+```
+
+### Bulk Insert
+```java
+List books = new ArrayList<>();
+books.add(new Book("isbn123", "Title here", "2nd edition"))
+books.add(new Book("isbn456", "Title here 2", "3nd edition"))
+books.add(new Book("isbn789", "Title here 3", "4nd edition"))
+SugarRecord.saveInTx(books);
+```
+
+### When using ProGuard
+```java
+# Ensures entities remain un-obfuscated so table and columns are named correctly
+-keep class com.yourpackage.yourapp.domainclasspackage.** { *; }
+```
+
+## [CHANGELOG](https://github.com/satyan/sugar/blob/master/CHANGELOG.md)
+
+## Contributing
+
+Please fork this repository and contribute back using [pull requests](https://github.com/satyan/sugar/pulls). Features can be requested using [issues](https://github.com/satyan/sugar/issues). All code, comments, and critiques are greatly appreciated.
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 00000000..aa590672
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,103 @@
+apply plugin: 'jacoco'
+apply plugin: 'com.github.kt3k.coveralls'
+apply plugin: 'java'
+
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:2.2.2'
+ classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1'
+ }
+}
+
+def isReleaseBuild() {
+ return version.contains("SNAPSHOT") == false
+}
+test{
+ testLogging{
+ exceptionFormat = 'full'
+ }
+}
+allprojects {
+ version = VERSION_NAME
+ group = GROUP
+
+ repositories {
+ mavenLocal()
+ mavenCentral()
+ jcenter()
+ }
+}
+
+subprojects { proj ->
+ apply plugin: 'jacoco'
+
+ jacoco {
+ version "0.7.1.201405082137"
+ }
+
+ task jacocoTestReport(type: JacocoReport) {
+ group = "Reporting"
+ description = "Generate Jacoco coverage reports after running tests."
+ reports {
+ xml.enabled = true
+ html.enabled = true
+ }
+ classDirectories = fileTree(
+ dir: 'build/intermediates/classes/debug',
+ excludes: ['**/R*.class',
+ '**/BuildConfig*'])
+ sourceDirectories = files('src/main/java')
+ executionData = files('build/jacoco/testDebugUnitTest.exec')
+ doFirst {
+ files('build/intermediates/classes/debug').getFiles().each { file ->
+ if (file.name.contains('$$')) {
+ file.renameTo(file.path.replace('$$', '$'))
+ }
+ }
+ }
+ }
+}
+
+jacoco {
+ toolVersion "0.7.1.201405082137"
+}
+
+task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
+ group = "Reporting"
+ description = 'Generates an aggregate report from all subprojects'
+ dependsOn(subprojects.jacocoTestReport)
+
+ additionalSourceDirs = files('library/src/main/java')
+ sourceDirectories = files('library/src/main/java')
+ classDirectories = files('library/build/intermediates/classes/debug')
+ executionData = files(subprojects.jacocoTestReport.executionData)
+
+ reports {
+ html.enabled = true
+ xml.enabled = true
+ }
+
+ onlyIf = {
+ true
+ }
+
+ doFirst {
+ executionData = files(executionData.findAll { it.exists() })
+ }
+}
+
+coveralls {
+ sourceDirs = files('library/src/main/java').flatten()
+ jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
+}
+
+tasks.coveralls {
+ group = 'Coverage reports'
+ description = 'Uploads the aggregated coverage report to Coveralls'
+
+ dependsOn jacocoRootReport
+ onlyIf { System.env.'CI' }
+}
\ No newline at end of file
diff --git a/dist/sugar-1.0.jar b/dist/sugar-1.0.jar
deleted file mode 100644
index 2bf1abd3..00000000
Binary files a/dist/sugar-1.0.jar and /dev/null differ
diff --git a/dist/sugar-1.1.jar b/dist/sugar-1.1.jar
deleted file mode 100644
index 96a6b77e..00000000
Binary files a/dist/sugar-1.1.jar and /dev/null differ
diff --git a/dist/sugar-1.2.jar b/dist/sugar-1.2.jar
deleted file mode 100644
index 2e6f0290..00000000
Binary files a/dist/sugar-1.2.jar and /dev/null differ
diff --git a/dist/sugar-1.3_beta.jar b/dist/sugar-1.3_beta.jar
deleted file mode 100644
index a9d0ed8c..00000000
Binary files a/dist/sugar-1.3_beta.jar and /dev/null differ
diff --git a/example/build.gradle b/example/build.gradle
new file mode 100644
index 00000000..a8b90f05
--- /dev/null
+++ b/example/build.gradle
@@ -0,0 +1,25 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 23
+ buildToolsVersion "23.0.3"
+
+ defaultConfig {
+ applicationId "com.example"
+ minSdkVersion 9
+ targetSdkVersion 23
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ }
+ }
+ lintOptions {
+ abortOnError false
+ }
+}
+
+dependencies {
+ compile project (':library')
+ compile 'com.android.support:appcompat-v7:23.3.0'
+}
diff --git a/example/build.properties b/example/build.properties
old mode 100755
new mode 100644
diff --git a/example/build.xml b/example/build.xml
old mode 100755
new mode 100644
diff --git a/example/example/project.properties b/example/example/project.properties
deleted file mode 100644
index debfe960..00000000
--- a/example/example/project.properties
+++ /dev/null
@@ -1,15 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-
-# Project target.
-target=android-3
-android.library.reference.1=../library
diff --git a/example/local.properties b/example/local.properties
deleted file mode 100755
index 2543c8bd..00000000
--- a/example/local.properties
+++ /dev/null
@@ -1,10 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must *NOT* be checked in Version Control Systems,
-# as it contains information specific to your local configuration.
-
-# location of the SDK. This is only used by Ant
-# For customization when using a Version Control System, please read the
-# header note.
-sdk.dir=/home/satya/software/android-sdk-linux_x86
diff --git a/example/proguard.cfg b/example/proguard.cfg
deleted file mode 100755
index 12dd0392..00000000
--- a/example/proguard.cfg
+++ /dev/null
@@ -1,36 +0,0 @@
--optimizationpasses 5
--dontusemixedcaseclassnames
--dontskipnonpubliclibraryclasses
--dontpreverify
--verbose
--optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-
--keep public class * extends android.app.Activity
--keep public class * extends android.app.Application
--keep public class * extends android.app.Service
--keep public class * extends android.content.BroadcastReceiver
--keep public class * extends android.content.ContentProvider
--keep public class * extends android.app.backup.BackupAgentHelper
--keep public class * extends android.preference.Preference
--keep public class com.android.vending.licensing.ILicensingService
-
--keepclasseswithmembernames class * {
- native ;
-}
-
--keepclasseswithmembernames class * {
- public (android.content.Context, android.util.AttributeSet);
-}
-
--keepclasseswithmembernames class * {
- public (android.content.Context, android.util.AttributeSet, int);
-}
-
--keepclassmembers enum * {
- public static **[] values();
- public static ** valueOf(java.lang.String);
-}
-
--keep class * implements android.os.Parcelable {
- public static final android.os.Parcelable$Creator *;
-}
diff --git a/example/res/layout/notelist.xml b/example/res/layout/notelist.xml
deleted file mode 100755
index b07f003f..00000000
--- a/example/res/layout/notelist.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/example/src/com/example/AddNoteActivity.java b/example/src/com/example/AddNoteActivity.java
deleted file mode 100755
index 06a6c62f..00000000
--- a/example/src/com/example/AddNoteActivity.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.example;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.View;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-
-public class AddNoteActivity extends Activity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- LinearLayout view = (LinearLayout) findViewById(R.id.layout);
- TextView titleText = new TextView(this);
- titleText.setText("Title");
- TextView descText = new TextView(this);
- descText.setText("Description");
- TextView tagText = new TextView(this);
- tagText.setText("Tag");
- final EditText titleBox = new EditText(this);
- final EditText descBox = new EditText(this);
- final EditText tagBox = new EditText(this);
-
- Button save = new Button(this);
- save.setText("Save");
- view.addView(titleText);
- view.addView(titleBox);
- view.addView(descText);
- view.addView(descBox);
- view.addView(tagText);
- view.addView(tagBox);
- view.addView(save);
-
- save.setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Tag tag = new Tag(tagBox.getText().toString());
- tag.save();
- new Note( 10, titleBox.getText().toString(), descBox.getText().toString(),tag).save();
- Intent intent = new Intent(AddNoteActivity.this, NoteListActivity.class);
- startActivity(intent);
- }
- });
-
- }
-}
\ No newline at end of file
diff --git a/example/src/com/example/Note.java b/example/src/com/example/Note.java
deleted file mode 100755
index 468b074c..00000000
--- a/example/src/com/example/Note.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.example;
-
-import android.content.Context;
-import com.orm.SugarRecord;
-
-public class Note extends SugarRecord{
- private int noteId;
- private String title;
- private String description;
- private String name;
- private Integer noteNumber = 2;
- private Float tagNumber = 4.0f;
- private float tagNo = 5.0f;
- private Boolean isTag = true;
- private boolean isTagged = false;
- private Double noteTagNo = 40.5;
- private double noteTagNumber = 24.4;
- private Tag tag;
-
- public Note(){
- }
-
- public Note(int noteId, String title, String description, Tag tag) {
- this.noteId = noteId;
- this.title = title;
- this.description = description;
- this.tag = tag;
- }
-
- public int getNoteId() {
- return noteId;
- }
-
- public void setNoteId(int noteId) {
- this.noteId = noteId;
- }
-
- public String getTitle() {
- return title;
- }
-
- public String getDescription() {
- return description;
- }
-
- public Tag getTag() {
- return tag;
- }
-
- public void setDescription(String description){
- this.description = description;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- @Override
- public String toString() {
- return title + "id: " + id + " - " + tag + " " + tag.getId();
-
- }
-}
diff --git a/example/src/com/example/NoteListActivity.java b/example/src/com/example/NoteListActivity.java
deleted file mode 100755
index a5d0399b..00000000
--- a/example/src/com/example/NoteListActivity.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.example;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.widget.ArrayAdapter;
-
-import com.orm.query.Condition;
-import com.orm.query.Select;
-
-import java.util.List;
-
-
-public class NoteListActivity extends ListActivity {
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.notelist);
-
- List notes = Select.from(Note.class).orderBy("title").list();//Note.listAll(Note.class);
-
- setListAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, notes));
-
- findViewById(R.id.Button01).setOnClickListener(new View.OnClickListener() {
- public void onClick(View view) {
- Intent intent = new Intent(NoteListActivity.this, AddNoteActivity.class);
- startActivity(intent);
- }
- });
-
- // TEST COUNT
-// android.util.Log.d("COUNT", "Count: " + Select.from(Note.class).where("title like '%ba%'").count() +"/"+notes.size());
- Log.d("COUNT", "Count: " + Select.from(Note.class).where(new Condition[]{new Condition("title").eq("note")}).count() + "/" + notes.size());
- }
-
-}
\ No newline at end of file
diff --git a/example/src/com/example/NoteRelation.java b/example/src/com/example/NoteRelation.java
deleted file mode 100644
index 1a971d7d..00000000
--- a/example/src/com/example/NoteRelation.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.example;
-
-import android.content.Context;
-import com.orm.SugarRecord;
-
-public class NoteRelation extends SugarRecord {
- String name;
- int noteId;
-
-
- public NoteRelation() {
- }
-
- public NoteRelation(Context context, String name, int noteId) {
- this.name = name;
- this.noteId = noteId;
-
- }
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public int getNoteId() {
- return noteId;
- }
-
- public void setNoteId(int noteId) {
- this.noteId = noteId;
- }
-
-
-}
diff --git a/example/src/com/example/SugarActivity.java b/example/src/com/example/SugarActivity.java
deleted file mode 100755
index 22dd9c1c..00000000
--- a/example/src/com/example/SugarActivity.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.example;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.database.sqlite.SQLiteDatabase;
-import android.os.Bundle;
-import android.util.Log;
-import com.orm.Database;
-import com.orm.SugarApp;
-
-public class SugarActivity extends Activity
-{
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Note.deleteAll(Note.class);
- TextNote.deleteAll(TextNote.class);
- Tag.deleteAll(Tag.class);
- initDb();
- Intent intent = new Intent(this, NoteListActivity.class);
- startActivity(intent);
- }
-
- private void initDb() {
-
- Tag t1 = new Tag("tag1");
- Tag t2 = new Tag("tag2");
- t1.save();
- t2.save();
-
- Note n1 = new Note( 10, "note1", "description1", t1);
- Note n2 = new Note(10, "note12", "description2", t1);
- Note n3 = new Note( 10, "note13", "description3", t2);
- Note n4 = new Note( 10, "note4", "description4", t2);
-
- TextNote textNote = new TextNote();
- textNote.desc = "Test";
-
- textNote.save();
- n1.save();
- n2.save();
- n3.save();
- n4.save();
-
- n1.setDescription("matrix");
- n1.setTitle("atrix");
- n1.save();
- n2.setDescription("matrix");
- n2.setTitle("satrix");
- n2.save();
- n3.setDescription("matrix");
- n3.setTitle("batrix");
- n3.save();
-
-
-
- }
-}
diff --git a/example/src/com/example/Tag.java b/example/src/com/example/Tag.java
deleted file mode 100755
index 24d8c145..00000000
--- a/example/src/com/example/Tag.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.example;
-
-import android.content.Context;
-import com.orm.SugarRecord;
-
-public class Tag extends SugarRecord{
- private String name;
-
- public Tag(String name) {
- this.name = name;
- }
-
- public Tag() {
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public String toString() {
- return getName();
- }
-}
diff --git a/example/src/com/example/TextNote.java b/example/src/com/example/TextNote.java
deleted file mode 100644
index c4025774..00000000
--- a/example/src/com/example/TextNote.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.example;
-
-public class TextNote extends Note {
-
- public String desc;
-
- public TextNote() {
- }
-
-
-}
diff --git a/example/AndroidManifest.xml b/example/src/main/AndroidManifest.xml
old mode 100755
new mode 100644
similarity index 74%
rename from example/AndroidManifest.xml
rename to example/src/main/AndroidManifest.xml
index e647f387..eb802533
--- a/example/AndroidManifest.xml
+++ b/example/src/main/AndroidManifest.xml
@@ -3,17 +3,13 @@
package="com.example"
android:versionCode="1"
android:versionName="1.0">
-
-
+
+
-
-
-
diff --git a/example/assets/sugar_upgrades/3.sql b/example/src/main/assets/sugar_upgrades/3.sql
similarity index 100%
rename from example/assets/sugar_upgrades/3.sql
rename to example/src/main/assets/sugar_upgrades/3.sql
diff --git a/example/src/main/java/com/example/activities/SugarActivity.java b/example/src/main/java/com/example/activities/SugarActivity.java
new file mode 100644
index 00000000..81044546
--- /dev/null
+++ b/example/src/main/java/com/example/activities/SugarActivity.java
@@ -0,0 +1,18 @@
+package com.example.activities;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import com.example.R;
+
+
+public class SugarActivity extends Activity
+{
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+}
diff --git a/example/res/drawable-hdpi/icon.png b/example/src/main/res/drawable-hdpi/icon.png
similarity index 100%
rename from example/res/drawable-hdpi/icon.png
rename to example/src/main/res/drawable-hdpi/icon.png
diff --git a/example/res/drawable-ldpi/icon.png b/example/src/main/res/drawable-ldpi/icon.png
similarity index 100%
rename from example/res/drawable-ldpi/icon.png
rename to example/src/main/res/drawable-ldpi/icon.png
diff --git a/example/res/drawable-mdpi/icon.png b/example/src/main/res/drawable-mdpi/icon.png
similarity index 100%
rename from example/res/drawable-mdpi/icon.png
rename to example/src/main/res/drawable-mdpi/icon.png
diff --git a/example/res/layout/main.xml b/example/src/main/res/layout/main.xml
similarity index 100%
rename from example/res/layout/main.xml
rename to example/src/main/res/layout/main.xml
diff --git a/example/res/values/strings.xml b/example/src/main/res/values/strings.xml
similarity index 100%
rename from example/res/values/strings.xml
rename to example/src/main/res/values/strings.xml
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 00000000..35b4c26f
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,34 @@
+# Project-wide Gradle settings.
+
+# IDE (e.g. Android Studio) users:
+# Settings specified in this file will override any Gradle settings
+# configured through the IDE.
+
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx10248m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+org.gradle.daemon=true
+
+VERSION_NAME=2
+VERSION_CODE=2
+GROUP=com.github.satyan
+
+POM_DESCRIPTION=Sugar ORM - Insanely easy way to work with android database
+POM_URL=https://github.com/satyan/sugar
+POM_SCM_URL=https://github.com/satyan/sugar
+POM_SCM_CONNECTION=scm:git@github.com:satyan/sugar.git
+POM_SCM_DEV_CONNECTION=scm:git@github.com:satyan/sugar.git
+POM_LICENCE_NAME=The Apache Software License, Version 2.0
+POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
+POM_LICENCE_DIST=repo
+POM_DEVELOPER_ID=satyan
+POM_DEVELOPER_NAME=Satya Narayan
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 00000000..8c0fb64a
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 00000000..b0bb3ffb
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Sat Apr 09 17:51:14 ART 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 00000000..91a7e269
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched.
+if $cygwin ; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >&-
+APP_HOME="`pwd -P`"
+cd "$SAVED" >&-
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100755
index 00000000..aec99730
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/library/build.gradle b/library/build.gradle
index 43157b3c..1d5acf78 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -1,29 +1,39 @@
-buildscript {
- repositories {
- mavenCentral()
- }
+apply plugin: 'com.android.library'
+//apply from: '../maven_push.gradle'
+
+android {
+ compileSdkVersion 23
+ buildToolsVersion "23.0.3"
- dependencies {
- classpath 'com.android.tools.build:gradle:0.9.+'
+ defaultConfig {
+ minSdkVersion 9
+ targetSdkVersion 23
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
}
}
+ testOptions {
+ unitTests.returnDefaultValues = true
+ }
+ lintOptions {
+ abortOnError false
+ }
+}
- apply plugin: 'android-library'
+dependencies {
+ testCompile 'junit:junit:4.12'
+ testCompile 'org.robolectric:robolectric:3.0'
+ compile 'net.zetetic:android-database-sqlcipher:3.5.4@aar'
+}
- dependencies {
- compile 'com.android.support:support-v4:19.0.1'
- }
- android {
- compileSdkVersion 19
- buildToolsVersion "19.0.3"
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- }
- }
- }
+
+task libraryJar(type: Jar) {
+ dependsOn "assembleRelease"
+ from android.sourceSets.main.java.srcDirs,
+ ['build/intermediates/classes/release/'] // Add the release classes into the jar
+ baseName 'sugar'
+}
+
diff --git a/library/build.properties b/library/build.properties
index ff5c1fe8..b5b95df0 100644
--- a/library/build.properties
+++ b/library/build.properties
@@ -1,2 +1,3 @@
-jdk.home.1.6=/Library/Java/Home
-android.home=/Users/ADMIN/Downloads/android-sdk-macosx/platforms/android-17/android.jar
\ No newline at end of file
+jdk.home.1.6=$JAVA_HOME
+android.home=/Users/ADMIN/Downloads/android-sdk-macosx/platforms/android-17/android.jar
+android.travis.home=/usr/local/android-sdk/platforms/android-17/android.jar
diff --git a/library/build.xml b/library/build.xml
index ef746a37..927b3904 100644
--- a/library/build.xml
+++ b/library/build.xml
@@ -20,6 +20,10 @@
+
+
+
+
@@ -29,10 +33,10 @@
-
+
-
+
@@ -41,12 +45,25 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
\ No newline at end of file
+
diff --git a/library/gradle.properties b/library/gradle.properties
new file mode 100644
index 00000000..07fe1d15
--- /dev/null
+++ b/library/gradle.properties
@@ -0,0 +1,3 @@
+POM_NAME=Sugar ORM
+POM_ARTIFACT_ID=sugar
+POM_PACKAGING=aar
\ No newline at end of file
diff --git a/library/project.properties b/library/project.properties
deleted file mode 100644
index 05d02d38..00000000
--- a/library/project.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-android.library=true
-# Project target.
-target=android-15
diff --git a/library/res/values/strings.xml b/library/res/values/strings.xml
deleted file mode 100644
index 0d2c4cc4..00000000
--- a/library/res/values/strings.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/library/src/com/orm/Database.java b/library/src/com/orm/Database.java
deleted file mode 100644
index 0896ee1f..00000000
--- a/library/src/com/orm/Database.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.orm;
-
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-
-
-public class Database {
- private SugarDb sugarDb;
- private SQLiteDatabase sqLiteDatabase;
-
- public Database(Context context){
- this.sugarDb = new SugarDb(context);
- }
-
-
- public synchronized SQLiteDatabase getDB() {
- if (this.sqLiteDatabase == null) {
- this.sqLiteDatabase = this.sugarDb.getWritableDatabase();
- }
-
- return this.sqLiteDatabase;
- }
-
-}
diff --git a/library/src/com/orm/StringUtil.java b/library/src/com/orm/StringUtil.java
deleted file mode 100644
index 40fabf48..00000000
--- a/library/src/com/orm/StringUtil.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.orm;
-
-public class StringUtil {
- public static String toSQLName(String javaNotation) {
- if(javaNotation.equalsIgnoreCase("_id"))
- return "_id";
-
- StringBuilder sb = new StringBuilder();
- char[] buf = javaNotation.toCharArray();
-
- for (int i = 0; i < buf.length; i++) {
- char prevChar = (i > 0) ? buf[i - 1] : 0;
- char c = buf[i];
- char nextChar = (i < buf.length - 1) ? buf[i + 1] : 0;
- boolean isFirstChar = (i == 0);
-
- if (isFirstChar || Character.isLowerCase(c) || Character.isDigit(c)) {
- sb.append(Character.toUpperCase(c));
- } else if (Character.isUpperCase(c)) {
- if (Character.isLetterOrDigit(prevChar)) {
- if (Character.isLowerCase(prevChar)) {
- sb.append('_').append(Character.toUpperCase(c));
- } else if (nextChar > 0 && Character.isLowerCase(nextChar)) {
- sb.append('_').append(Character.toUpperCase(c));
- } else {
- sb.append(c);
- }
- }
- else {
- sb.append(c);
- }
- }
- }
-
- return sb.toString();
- }
-
-}
diff --git a/library/src/com/orm/SugarApp.java b/library/src/com/orm/SugarApp.java
deleted file mode 100644
index d15c411f..00000000
--- a/library/src/com/orm/SugarApp.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.orm;
-
-public class SugarApp extends android.app.Application{
-
- private Database database;
- private static SugarApp sugarContext;
-
- public void onCreate(){
- super.onCreate();
- SugarApp.sugarContext = this;
- this.database = new Database(this);
- }
-
- public void onTerminate(){
- if (this.database != null) {
- this.database.getDB().close();
- }
- super.onTerminate();
- }
-
- public static SugarApp getSugarContext(){
- return sugarContext;
- }
-
- protected Database getDatabase() {
- return database;
- }
-}
diff --git a/library/src/com/orm/SugarConfig.java b/library/src/com/orm/SugarConfig.java
deleted file mode 100644
index aaeb79b6..00000000
--- a/library/src/com/orm/SugarConfig.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package com.orm;
-
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.util.Log;
-
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class SugarConfig {
-
- static Map, List> fields = new HashMap, List>();
-
- public static String getDatabaseName(Context context) {
- String databaseName = getMetaDataString(context, "DATABASE");
-
- if (databaseName == null) {
- databaseName = "Sugar.db";
- }
-
- return databaseName;
- }
-
- public static void setFields(Class> clazz, List fieldz){
- fields.put(clazz, fieldz);
- }
-
- public static List getFields(Class> clazz){
-
- if(fields.containsKey(clazz)){
- List list = fields.get(clazz);
- return Collections.synchronizedList(list);
- }
-
- return null;
- }
-
- public static void clearCache(){
- fields.clear();
- fields = new HashMap, List>();
- }
-
- public static int getDatabaseVersion(Context context) {
- Integer databaseVersion = getMetaDataInteger(context, "VERSION");
-
- if ((databaseVersion == null) || (databaseVersion == 0)) {
- databaseVersion = 1;
- }
-
- return databaseVersion;
- }
-
- public static String getDomainPackageName(Context context){
- String domainPackageName = getMetaDataString(context, "DOMAIN_PACKAGE_NAME");
-
- if (domainPackageName == null) {
- domainPackageName = "";
- }
-
- return domainPackageName;
- }
-
- public static boolean getDebugEnabled(Context context) {
- return getMetaDataBoolean(context, "QUERY_LOG");
- }
-
- public static String getMetaDataString(Context context, String name) {
- String value = null;
-
- PackageManager pm = context.getPackageManager();
- try {
- ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 128);
- value = ai.metaData.getString(name);
- } catch (Exception e) {
- Log.d("sugar", "Couldn't find config value: " + name);
- }
-
- return value;
- }
-
- public static Integer getMetaDataInteger(Context context, String name) {
- Integer value = null;
-
- PackageManager pm = context.getPackageManager();
- try {
- ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 128);
- value = ai.metaData.getInt(name);
- } catch (Exception e) {
- Log.d("sugar", "Couldn't find config value: " + name);
- }
-
- return value;
- }
-
- public static Boolean getMetaDataBoolean(Context context, String name) {
- Boolean value = false;
-
- PackageManager pm = context.getPackageManager();
- try {
- ApplicationInfo ai = pm.getApplicationInfo(context.getPackageName(), 128);
- value = ai.metaData.getBoolean(name);
- } catch (Exception e) {
- Log.d("sugar", "Couldn't find config value: " + name);
- }
-
- return value;
- }
-}
diff --git a/library/src/com/orm/SugarCursorFactory.java b/library/src/com/orm/SugarCursorFactory.java
deleted file mode 100644
index 17c60c59..00000000
--- a/library/src/com/orm/SugarCursorFactory.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.orm;
-
-import android.database.Cursor;
-import android.database.sqlite.SQLiteCursor;
-import android.database.sqlite.SQLiteCursorDriver;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteQuery;
-import android.util.Log;
-
-public class SugarCursorFactory implements SQLiteDatabase.CursorFactory {
-
- private boolean debugEnabled;
-
- public SugarCursorFactory() {
- this.debugEnabled = false;
- }
-
- public SugarCursorFactory(boolean debugEnabled){
-
- this.debugEnabled = debugEnabled;
- }
-
- @SuppressWarnings("deprecation")
- public Cursor newCursor(SQLiteDatabase sqLiteDatabase, SQLiteCursorDriver sqLiteCursorDriver, String editTable, SQLiteQuery sqLiteQuery) {
-
- if(debugEnabled){
- Log.d("SQL Log", sqLiteQuery.toString());
- }
-
- return new SQLiteCursor(sqLiteDatabase, sqLiteCursorDriver, editTable, sqLiteQuery);
- }
-}
diff --git a/library/src/com/orm/SugarDb.java b/library/src/com/orm/SugarDb.java
deleted file mode 100644
index 0f859afc..00000000
--- a/library/src/com/orm/SugarDb.java
+++ /dev/null
@@ -1,212 +0,0 @@
-package com.orm;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteException;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
-import dalvik.system.DexFile;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-import java.util.*;
-
-import static com.orm.SugarConfig.getDatabaseVersion;
-import static com.orm.SugarConfig.getDebugEnabled;
-
-public class SugarDb extends SQLiteOpenHelper {
- private Context context;
-
- public SugarDb(Context context) {
- super(context, SugarConfig.getDatabaseName(context), new SugarCursorFactory(getDebugEnabled(context)), getDatabaseVersion(context));
- this.context = context;
-
- }
-
- private > List getDomainClasses(Context context) {
- List domainClasses = new ArrayList();
- try {
- Enumeration> allClasses = getAllClasses(context);
-
- while (allClasses.hasMoreElements()) {
- String className = (String) allClasses.nextElement();
-
- if (className.startsWith(SugarConfig.getDomainPackageName(context))) {
- T domainClass = getDomainClass(className, context);
- if (domainClass != null) domainClasses.add(domainClass);
- }
- }
-
- } catch (IOException e) {
- Log.e("Sugar", e.getMessage());
- } catch (PackageManager.NameNotFoundException e) {
- Log.e("Sugar", e.getMessage());
- }
-
- return domainClasses;
- }
-
- @SuppressWarnings("unchecked")
- private > T getDomainClass(String className, Context context) {
- Log.i("Sugar", "domain class");
- Class> discoveredClass = null;
- try {
- discoveredClass = Class.forName(className, true, context.getClass().getClassLoader());
- } catch (ClassNotFoundException e) {
- Log.e("Sugar", e.getMessage());
- }
-
- if ((discoveredClass == null) ||
- (!SugarRecord.class.isAssignableFrom(discoveredClass)) ||
- Modifier.isAbstract(discoveredClass.getModifiers())) {
- return null;
- } else {
- try {
- return (T) discoveredClass.getDeclaredConstructor().newInstance();
- } catch (InstantiationException e) {
- Log.e("Sugar", e.getMessage());
- } catch (IllegalAccessException e) {
- Log.e("Sugar", e.getMessage());
- } catch (NoSuchMethodException e) {
- Log.e("Sugar", e.getMessage());
- } catch (InvocationTargetException e) {
- Log.e("Sugar", e.getMessage());
- }
- }
-
- return null;
-
- }
-
- private Enumeration> getAllClasses(Context context) throws PackageManager.NameNotFoundException, IOException {
- String path = getSourcePath(context);
- DexFile dexfile = new DexFile(path);
- return dexfile.entries();
- }
-
- private String getSourcePath(Context context) throws PackageManager.NameNotFoundException {
- return context.getPackageManager().getApplicationInfo(context.getPackageName(), 0).sourceDir;
- }
-
- @Override
- public void onCreate(SQLiteDatabase sqLiteDatabase) {
- Log.i("Sugar", "on create");
- createDatabase(sqLiteDatabase);
- }
-
- private > void createDatabase(SQLiteDatabase sqLiteDatabase) {
- List domainClasses = getDomainClasses(context);
- for (T domain : domainClasses) {
- createTable(domain, sqLiteDatabase);
- }
- }
-
- private > void createTable(T table, SQLiteDatabase sqLiteDatabase) {
- Log.i("Sugar", "create table");
- List fields = table.getTableFields();
- StringBuilder sb = new StringBuilder("CREATE TABLE ").append(table.getSqlName()).append(
- " ( ID INTEGER PRIMARY KEY AUTOINCREMENT ");
-
- for (Field column : fields) {
- String columnName = StringUtil.toSQLName(column.getName());
- String columnType = QueryBuilder.getColumnType(column.getType());
-
- if (columnType != null) {
-
- if (columnName.equalsIgnoreCase("Id")) {
- continue;
- }
- sb.append(", ").append(columnName).append(" ").append(columnType);
- }
- }
- sb.append(" ) ");
-
- Log.i("Sugar", "creating table " + table.getSqlName());
-
- if (!"".equals(sb.toString()))
- sqLiteDatabase.execSQL(sb.toString());
- }
-
- @Override
- public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
- Log.i("Sugar", "upgrading sugar");
- // check if some tables are to be created
- doUpgrade(sqLiteDatabase);
-
- if (!executeSugarUpgrade(sqLiteDatabase, oldVersion, newVersion)) {
- deleteTables(sqLiteDatabase);
- onCreate(sqLiteDatabase);
- }
- }
-
- /**
- * Create the tables that do not exist.
- */
- private > void doUpgrade(SQLiteDatabase sqLiteDatabase) {
- List domainClasses = getDomainClasses(context);
- for (T domain : domainClasses) {
- try {// we try to do a select, if fails then (?) there isn't the table
- sqLiteDatabase.query(domain.tableName, null, null, null, null, null, null);
- } catch (SQLiteException e) {
- Log.i("Sugar", String.format("creating table on update (error was '%s')", e.getMessage()));
- createTable(domain, sqLiteDatabase);
- }
- }
- }
-
- private > void deleteTables(SQLiteDatabase sqLiteDatabase) {
- List tables = getDomainClasses(this.context);
- for (T table : tables) {
- sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + table.getSqlName());
- }
- }
-
- private boolean executeSugarUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-
- boolean isSuccess = false;
- try {
- List files = Arrays.asList(this.context.getAssets().list("sugar_upgrades"));
- Collections.sort(files, new NumberComparator());
-
- for (String file : files){
- Log.i("Sugar", "filename : " + file);
- try {
- int version = Integer.valueOf(file.replace(".sql", ""));
-
- if ((version > oldVersion) && (version <= newVersion)) {
- executeScript(db, file);
- isSuccess = true;
- }
- } catch (NumberFormatException e) {
- Log.i("Sugar", "not a sugar script. ignored." + file);
- }
- }
- } catch (IOException e) {
- Log.e("Sugar", e.getMessage());
- }
-
- return isSuccess;
- }
-
- private void executeScript(SQLiteDatabase db, String file) {
- try {
- InputStream is = this.context.getAssets().open("sugar_upgrades/" + file);
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
- String line;
- while ((line = reader.readLine()) != null) {
- Log.i("Sugar script", line);
- db.execSQL(line.toString());
- }
- } catch (IOException e) {
- Log.e("Sugar", e.getMessage());
- }
-
- Log.i("Sugar", "script executed");
- }
-}
diff --git a/library/src/com/orm/SugarRecord.java b/library/src/com/orm/SugarRecord.java
deleted file mode 100644
index da414a66..00000000
--- a/library/src/com/orm/SugarRecord.java
+++ /dev/null
@@ -1,443 +0,0 @@
-package com.orm;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteException;
-import android.database.sqlite.SQLiteStatement;
-import android.text.TextUtils;
-import android.util.Log;
-import com.orm.dsl.Ignore;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.sql.Timestamp;
-import java.util.*;
-
-import static com.orm.SugarApp.getSugarContext;
-
-public class SugarRecord{
-
- @Ignore
- String tableName = getSqlName();
-
- protected Long id = null;
-
- public void delete() {
- SQLiteDatabase db = getSugarContext().getDatabase().getDB();
- db.delete(this.tableName, "Id=?", new String[]{getId().toString()});
- }
-
- public static > void deleteAll(Class type) {
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
- sqLiteDatabase.delete(getTableName(type), null, null);
- }
-
- public static > void deleteAll(Class type, String whereClause, String... whereArgs ) {
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
- sqLiteDatabase.delete(getTableName(type), whereClause, whereArgs);
- }
-
- public void save() {
- save(getSugarContext().getDatabase().getDB());
- }
-
- @SuppressWarnings("deprecation")
- public static > void saveInTx(T... objects ) {
- saveInTx(Arrays.asList(objects));
- }
-
- @SuppressWarnings("deprecation")
- public static > void saveInTx(Collection objects ) {
- SQLiteDatabase sqLiteDatabase = getSugarContext().getDatabase().getDB();
-
- try{
- sqLiteDatabase.beginTransaction();
- sqLiteDatabase.setLockingEnabled(false);
- for(T object: objects){
- object.save(sqLiteDatabase);
- }
- sqLiteDatabase.setTransactionSuccessful();
- }catch (Exception e){
- Log.i("Sugar", "Error in saving in transaction " + e.getMessage());
- }finally {
- sqLiteDatabase.endTransaction();
- sqLiteDatabase.setLockingEnabled(true);
- }
-
- }
-
- void save(SQLiteDatabase db) {
-
- List columns = getTableFields();
- ContentValues values = new ContentValues(columns.size());
- for (Field column : columns) {
- column.setAccessible(true);
- Class> columnType = column.getType();
- try {
- String columnName = StringUtil.toSQLName(column.getName());
- Object columnValue = column.get(this);
- if (SugarRecord.class.isAssignableFrom(columnType)) {
- values.put(columnName,
- (columnValue != null)
- ? String.valueOf(((SugarRecord) columnValue).id)
- : "0");
- } else {
- if (!"id".equalsIgnoreCase(column.getName())) {
- if (columnType.equals(Short.class) || columnType.equals(short.class)) {
- values.put(columnName, (Short) columnValue);
- }
- else if (columnType.equals(Integer.class) || columnType.equals(int.class)) {
- values.put(columnName, (Integer) columnValue);
- }
- else if (columnType.equals(Long.class) || columnType.equals(long.class)) {
- values.put(columnName, (Long) columnValue);
- }
- else if (columnType.equals(Float.class) || columnType.equals(float.class)) {
- values.put(columnName, (Float) columnValue);
- }
- else if (columnType.equals(Double.class) || columnType.equals(double.class)) {
- values.put(columnName, (Double) columnValue);
- }
- else if (columnType.equals(Boolean.class) || columnType.equals(boolean.class)) {
- values.put(columnName, (Boolean) columnValue);
- }
- else if (Date.class.equals(columnType)) {
- values.put(columnName, ((Date) column.get(this)).getTime());
- }
- else if (Calendar.class.equals(columnType)) {
- values.put(columnName, ((Calendar) column.get(this)).getTimeInMillis());
- }else{
- values.put(columnName, String.valueOf(columnValue));
- }
-
- }
- }
-
- } catch (IllegalAccessException e) {
- Log.e("Sugar", e.getMessage());
- }
- }
-
- if (id == null)
- id = db.insert(getSqlName(), null, values);
- else
- db.update(getSqlName(), values, "ID = ?", new String[]{String.valueOf(id)});
-
- Log.i("Sugar", getClass().getSimpleName() + " saved : " + id);
- }
-
- public static > List listAll(Class type) {
- return find(type, null, null, null, null, null);
- }
-
- public static > T findById(Class type, Long id) {
- List list = find( type, "id=?", new String[]{String.valueOf(id)}, null, null, "1");
- if (list.isEmpty()) return null;
- return list.get(0);
- }
-
- public static > Iterator findAll(Class type) {
- return findAsIterator(type, null, null, null, null, null);
- }
-
- public static > Iterator findAsIterator(Class type,
- String whereClause, String... whereArgs) {
- return findAsIterator(type, whereClause, whereArgs, null, null, null);
- }
-
- public static > Iterator findWithQueryAsIterator(Class type, String query, String... arguments) {
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
- Cursor c = sqLiteDatabase.rawQuery(query, arguments);
- return new CursorIterator(type, c);
- }
-
- public static > Iterator findAsIterator(Class type,
- String whereClause, String[] whereArgs,
- String groupBy, String orderBy, String limit) {
-
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
- Cursor c = sqLiteDatabase.query(getTableName(type), null,
- whereClause, whereArgs, groupBy, null, orderBy, limit);
- return new CursorIterator(type, c);
- }
-
- public static > List find(Class type,
- String whereClause, String... whereArgs) {
- return find(type, whereClause, whereArgs, null, null, null);
- }
-
- public static > List findWithQuery(Class type, String query, String... arguments){
-
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
- T entity;
- List toRet = new ArrayList();
- Cursor c = sqLiteDatabase.rawQuery(query, arguments);
-
- try {
- while (c.moveToNext()) {
- entity = type.getDeclaredConstructor().newInstance();
- entity.inflate(c);
- toRet.add(entity);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- c.close();
- }
- return toRet;
- }
-
- public static void executeQuery(String query, String... arguments){
- getSugarContext().getDatabase().getDB().execSQL(query, arguments);
- }
-
- public static > List find(Class type,
- String whereClause, String[] whereArgs,
- String groupBy, String orderBy, String limit) {
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
- T entity;
- List toRet = new ArrayList();
- Cursor c = sqLiteDatabase.query(getTableName(type), null,
- whereClause, whereArgs, groupBy, null, orderBy, limit);
- try {
- while (c.moveToNext()) {
- entity = type.getDeclaredConstructor().newInstance();
- entity.inflate(c);
- toRet.add(entity);
- }
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- c.close();
- }
- return toRet;
- }
-
- public static > long count(Class> type,
- String whereClause, String[] whereArgs) {
- return count(type, whereClause, whereArgs, null, null, null);
- }
-
- public static > long count(Class> type,
- String whereClause, String[] whereArgs,
- String groupBy, String orderBy, String limit) {
-
- Database db = getSugarContext().getDatabase();
- SQLiteDatabase sqLiteDatabase = db.getDB();
-
- long toRet = -1;
- String filter = (!TextUtils.isEmpty(whereClause)) ? " where " + whereClause : "";
- SQLiteStatement sqLiteStatament = sqLiteDatabase.compileStatement("SELECT count(*) FROM " + getTableName(type) + filter);
-
- if (whereArgs != null) {
- for (int i = whereArgs.length; i != 0; i--) {
- sqLiteStatament.bindString(i, whereArgs[i - 1]);
- }
- }
-
- try {
- toRet = sqLiteStatament.simpleQueryForLong();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- sqLiteStatament.close();
- }
-
- return toRet;
- }
-
- @SuppressWarnings("unchecked")
- void inflate(Cursor cursor) {
- Map entities = new HashMap();
- List columns = getTableFields();
- for (Field field : columns) {
- field.setAccessible(true);
- try {
- Class fieldType = field.getType();
- String colName = StringUtil.toSQLName(field.getName());
-
- int columnIndex = cursor.getColumnIndex(colName);
-
- if (cursor.isNull(columnIndex)) {
- continue;
- }
-
- if(colName.equalsIgnoreCase("id")){
- long cid = cursor.getLong(columnIndex);
- field.set(this, Long.valueOf(cid));
- }else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) {
- field.set(this,
- cursor.getLong(columnIndex));
- } else if (fieldType.equals(String.class)) {
- String val = cursor.getString(columnIndex);
- field.set(this, val != null && val.equals("null") ? null : val);
- } else if (fieldType.equals(double.class) || fieldType.equals(Double.class)) {
- field.set(this,
- cursor.getDouble(columnIndex));
- } else if (fieldType.equals(boolean.class) || fieldType.equals(Boolean.class)) {
- field.set(this,
- cursor.getString(columnIndex).equals("1"));
- } else if (field.getType().getName().equals("[B")) {
- field.set(this,
- cursor.getBlob(columnIndex));
- } else if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) {
- field.set(this,
- cursor.getInt(columnIndex));
- } else if (fieldType.equals(float.class) || fieldType.equals(Float.class)) {
- field.set(this,
- cursor.getFloat(columnIndex));
- } else if (fieldType.equals(short.class) || fieldType.equals(Short.class)) {
- field.set(this,
- cursor.getShort(columnIndex));
- } else if (fieldType.equals(Timestamp.class)) {
- long l = cursor.getLong(columnIndex);
- field.set(this, new Timestamp(l));
- } else if (fieldType.equals(Date.class)) {
- long l = cursor.getLong(columnIndex);
- field.set(this, new Date(l));
- } else if (fieldType.equals(Calendar.class)) {
- long l = cursor.getLong(columnIndex);
- Calendar c = Calendar.getInstance();
- c.setTimeInMillis(l);
- field.set(this, c);
- } else if (Enum.class.isAssignableFrom(fieldType)) {
- try {
- Method valueOf = field.getType().getMethod("valueOf", String.class);
- String strVal = cursor.getString(columnIndex);
- Object enumVal = valueOf.invoke(field.getType(), strVal);
- field.set(this, enumVal);
- } catch (Exception e) {
- Log.e("Sugar", "Enum cannot be read from Sqlite3 database. Please check the type of field " + field.getName());
- }
- } else if (SugarRecord.class.isAssignableFrom(fieldType)) {
- long id = cursor.getLong(columnIndex);
- if (id > 0)
- entities.put(field, id);
- else
- field.set(this, null);
- } else
- Log.e("Sugar", "Class cannot be read from Sqlite3 database. Please check the type of field " + field.getName() + "(" + field.getType().getName() + ")");
- } catch (IllegalArgumentException e) {
- Log.e("field set error", e.getMessage());
- } catch (IllegalAccessException e) {
- Log.e("field set error", e.getMessage());
- }
-
- }
-
- for (Field f : entities.keySet()) {
- try {
- f.set(this, findById((Class extends SugarRecord>>) f.getType(),
- entities.get(f)));
- } catch (SQLiteException e) {
- } catch (IllegalArgumentException e) {
- } catch (IllegalAccessException e) {
- }
- }
- }
-
- public List getTableFields() {
- List fieldList = SugarConfig.getFields(getClass());
- if(fieldList != null) return fieldList;
-
- Log.d("Sugar", "Fetching properties");
- List typeFields = new ArrayList();
-
- getAllFields(typeFields, getClass());
-
- List toStore = new ArrayList();
- for (Field field : typeFields) {
- if (!field.isAnnotationPresent(Ignore.class) && !Modifier.isStatic(field.getModifiers())&& !Modifier.isTransient(field.getModifiers())) {
- toStore.add(field);
- }
- }
-
- SugarConfig.setFields(getClass(), toStore);
- return toStore;
- }
-
- private static List getAllFields(List fields, Class> type) {
- Collections.addAll(fields, type.getDeclaredFields());
-
- if (type.getSuperclass() != null) {
- fields = getAllFields(fields, type.getSuperclass());
- }
-
- return fields;
- }
-
- public String getSqlName() {
- return getTableName(getClass());
- }
-
-
- public static String getTableName(Class> type) {
- return StringUtil.toSQLName(type.getSimpleName());
- }
-
- public Long getId() {
- return id;
- }
-
- public void setId(Long id) {
- this.id = id;
- }
-
- static class CursorIterator> implements Iterator {
- Class type;
- Cursor cursor;
-
- public CursorIterator(Class type, Cursor cursor) {
- this.type = type;
- this.cursor = cursor;
- }
-
- @Override
- public boolean hasNext() {
- return cursor != null && !cursor.isClosed() && !cursor.isAfterLast();
- }
-
- @Override
- public E next() {
- E entity = null;
- if (cursor == null || cursor.isAfterLast()) {
- throw new NoSuchElementException();
- }
-
- if (cursor.isBeforeFirst()) {
- cursor.moveToFirst();
- }
-
- try {
- entity = type.getDeclaredConstructor().newInstance();
- entity.inflate(cursor);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- cursor.moveToNext();
- if (cursor.isAfterLast()) {
- cursor.close();
- }
- }
- return entity;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
-
- }
-
-}
diff --git a/library/src/com/orm/SugarTransactionHelper.java b/library/src/com/orm/SugarTransactionHelper.java
deleted file mode 100644
index 505547df..00000000
--- a/library/src/com/orm/SugarTransactionHelper.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.orm;
-
-import android.database.sqlite.SQLiteDatabase;
-import android.util.Log;
-
-public class SugarTransactionHelper {
-
- public static void doInTansaction(SugarTransactionHelper.Callback callback) {
-
- SQLiteDatabase database = SugarApp.getSugarContext().getDatabase().getDB();
-
- database.beginTransaction();
-
- try {
- Log.d(SugarTransactionHelper.class.getSimpleName(), "callback executing within transaction");
- callback.manipulateInTransaction();
- database.setTransactionSuccessful();
- Log.d(SugarTransactionHelper.class.getSimpleName(), "callback successfully executed within transaction");
- } catch (Throwable e) {
- Log.d(SugarTransactionHelper.class.getSimpleName(), "could execute callback within transaction", e);
- } finally {
- database.endTransaction();
- }
- }
-
- public static interface Callback {
- void manipulateInTransaction();
- }
-}
diff --git a/library/src/com/orm/dsl/Collection.java b/library/src/com/orm/dsl/Collection.java
deleted file mode 100644
index 6f1b5075..00000000
--- a/library/src/com/orm/dsl/Collection.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.orm.dsl;
-import java.util.*;
-
-public class Collection {
-
- public static List list(T... args) {
- return Arrays.asList(args);
- }
-
- public static Set set(T... args) {
- Set result = new HashSet(args.length);
- result.addAll(Arrays.asList(args));
- return result;
- }
-
- public static Map map(Entry extends K, ? extends V>... entries) {
- Map result = new HashMap(entries.length);
-
- for (Entry extends K, ? extends V> entry : entries)
- if (entry.value != null)
- result.put(entry.key, entry.value);
-
- return result;
- }
-
- public static Entry entry(K key, V value) {
- return new Entry(key, value);
- }
-
- public static class Entry {
- K key;
- V value;
-
- public Entry(K key, V value) {
- this.key = key;
- this.value = value;
- }
- }
-}
diff --git a/library/src/com/orm/query/Condition.java b/library/src/com/orm/query/Condition.java
deleted file mode 100644
index 6838b843..00000000
--- a/library/src/com/orm/query/Condition.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.orm.query;
-
-public class Condition {
- private String property;
- private Object value;
- private Check check;
-
- enum Check {
- EQUALS(" = "), GREATER_THAN(" > "), LESSER_THAN(" < "), NOT_EQUALS (" != "), LIKE(" LIKE "), NOT_LIKE(" NOT LIKE ");
- private String symbol;
-
- Check(String symbol) {
-
- this.symbol = symbol;
- }
-
- public String getSymbol() {
- return symbol;
- }
- }
-
- enum Type {
- AND, OR, NOT
- }
-
- public Condition(String property) {
- this.property = property;
- }
-
- public static Condition prop(String property){
- return new Condition(property);
- }
-
- public Condition eq(Object value){
- this.value = value;
- check = Check.EQUALS;
- return this;
- }
-
- public Condition like(Object value){
- this.value = value;
- check = Check.LIKE;
- return this;
- }
-
- public Condition notLike(Object value){
- this.value = value;
- check = Check.NOT_LIKE;
- return this;
- }
-
- public Condition notEq(Object value){
- this.value = value;
- check = Check.NOT_EQUALS;
- return this;
- }
-
- public Condition gt(Object value){
- this.value = value;
- check = Check.GREATER_THAN;
- return this;
- }
-
- public Condition lt(Object value){
- this.value = value;
- check = Check.LESSER_THAN;
- return this;
- }
-
- public String getProperty() {
- return property;
- }
-
- public Object getValue() {
- return value;
- }
-
- public Check getCheck() {
- return check;
- }
-
- public String getCheckSymbol(){
- return check.getSymbol();
- }
-}
diff --git a/library/src/com/orm/query/Select.java b/library/src/com/orm/query/Select.java
deleted file mode 100644
index ceaac65c..00000000
--- a/library/src/com/orm/query/Select.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.orm.query;
-
-import com.orm.SugarRecord;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class Select> implements Iterable {
-
- private Class record;
- private String[] arguments;
- private String whereClause = "";
- private String orderBy;
- private String groupBy;
- private String limit;
- private String offset;
-
- private List