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 @@ - - - - - - - - - -