diff --git a/.travis.yml b/.travis.yml
index dc4c9691..6e0beddd 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,14 +1,30 @@
language: android
+jdk: oraclejdk7
+env:
+ global:
+ - TERM=dumb
android:
components:
- sys-img-armeabi-v7a-android-23
- tools
- - build-tools-23.0.2
+ - 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:
- - gradle clean build connectedCheck coveralls
+ - ./gradlew clean build connectedCheck coveralls
cache:
directories:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3507a180..7015053d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,12 @@
# 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
@@ -11,6 +16,8 @@
* [#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
diff --git a/README.md b/README.md
index f4d129a5..d4d7c79d 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,15 @@
-# Sugar ORM [![Build Status](https://travis-ci.org/satyan/sugar.svg?branch=master)](https://travis-ci.org/satyan/sugar) [![Coverage Status](https://coveralls.io/repos/satyan/sugar/badge.svg?branch=master)](https://coveralls.io/r/satyan/sugar?branch=master)
+# Sugar ORM [![Build Status](https://travis-ci.org/satyan/sugar.svg?branch=master)](https://travis-ci.org/satyan/sugar) [![Coverage Status](https://coveralls.io/repos/satyan/sugar/badge.svg?branch=master)](https://coveralls.io/r/satyan/sugar?branch=master) [![Code Triagers Badge](http://www.codetriage.com/satyan/sugar/badges/users.svg)](http://www.codetriage.com/satyan/sugar)
+
+[![Join the chat at https://gitter.im/satyan/sugar](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/satyan/sugar?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Insanely easy way to work with Android databases.
-Official documentation can be found [here](http://satyan.github.io/sugar). The example application is provided in the **example** folder in the source.
+Official documentation can be found [here](http://satyan.github.io/sugar) - Check some examples below. The example application is provided in the **example** folder in the source.
+
+## Looking for contributors
+We need contributors to help maintain this project, ask @satyan for repo permission
+
+Otherwise you can use another ORM, like https://github.com/requery/requery or https://realm.io/
## Features
@@ -21,7 +28,7 @@ There are four ways to install Sugar:
This is the preferred way. Simply add:
```groovy
-compile 'com.github.satyan:sugar:1.4'
+compile 'com.github.satyan:sugar:1.5'
```
to your project dependencies and run `gradle build` or `gradle assemble`.
@@ -34,7 +41,7 @@ Declare the dependency in Maven:
com.github.satyan
sugar
- 1.4
+ 1.5
```
@@ -46,13 +53,52 @@ Download the source code and import it as a library project in Eclipse. The proj
Visit the [releases](https://github.com/satyan/sugar/releases) page to download jars directly. You can drop them into your `libs` folder and configure the Java build path to include the library. See this [tutorial](http://www.vogella.com/tutorials/AndroidLibraryProjects/article.html) for an excellent guide on how to do this.
+
+### How to use master version
+First, download sugar repository
+```
+git clone git@github.com:satyan/sugar.git
+```
+
+include this in your **settings.gradle**
+```gradle
+include ':app' // your module app
+include ':sugar'
+
+def getLocalProperty(prop) {
+ Properties properties = new Properties()
+ properties.load(new File(rootDir.absolutePath + '/local.properties').newDataInputStream())
+ return properties.getProperty(prop, '')
+}
+
+project(':sugar').projectDir = new File(getLocalProperty('sugar.dir'))
+
+```
+
+include this in your **local.properties**
+```
+sugar.dir=/path/to/sugar/library
+```
+
+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
+
+```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).
+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;
@@ -72,38 +118,49 @@ public class Book extends SugarRecord {
}
```
or
-```
+```java
@Table
public class Book { ... }
```
### Save Entity
-```
+```java
Book book = new Book("isbn123", "Title here", "2nd edition")
book.save();
```
-### Load Entity
+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();
```
-### Update Entity based on Unique values
+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();
@@ -114,8 +171,13 @@ sameBook.update();
book.getId() == sameBook.getId(); // true
```
-### Bulk Insert
+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"))
@@ -123,6 +185,14 @@ 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
index c6970775..030e1cb3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,12 +1,13 @@
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'
+apply plugin: 'java'
buildscript {
repositories {
mavenCentral()
}
dependencies {
- classpath 'com.android.tools.build:gradle:1.3.0'
+ classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.3.1'
}
}
@@ -14,7 +15,11 @@ buildscript {
def isReleaseBuild() {
return version.contains("SNAPSHOT") == false
}
-
+test{
+ testLogging{
+ exceptionFormat = 'full'
+ }
+}
allprojects {
version = VERSION_NAME
group = GROUP
@@ -33,7 +38,7 @@ subprojects { proj ->
version "0.7.1.201405082137"
}
- task jacocoTestReport(type: JacocoReport, dependsOn: "testDebug") {
+ task jacocoTestReport(type: JacocoReport) {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
@@ -45,7 +50,7 @@ subprojects { proj ->
excludes: ['**/R*.class',
'**/BuildConfig*'])
sourceDirectories = files('src/main/java')
- executionData = files('build/jacoco/testDebug.exec')
+ executionData = files('build/jacoco/testDebugUnitTest.exec')
doFirst {
files('build/intermediates/classes/debug').getFiles().each { file ->
if (file.name.contains('$$')) {
@@ -65,9 +70,9 @@ task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
description = 'Generates an aggregate report from all subprojects'
dependsOn(subprojects.jacocoTestReport)
- additionalSourceDirs = files('example/src/main/java') + files('library/src/main/java')
- sourceDirectories = files('example/src/main/java') + files('library/src/main/java')
- classDirectories = files('example/build/intermediates/classes/debug') + files('library/build/intermediates/classes/debug')
+ 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 {
@@ -75,13 +80,17 @@ task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
xml.enabled = true
}
+ onlyIf = {
+ true
+ }
+
doFirst {
executionData = files(executionData.findAll { it.exists() })
}
}
coveralls {
- sourceDirs = files('example/src/main/java').flatten() + files('library/src/main/java').flatten()
+ sourceDirs = files('library/src/main/java').flatten()
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"
}
@@ -91,4 +100,4 @@ tasks.coveralls {
dependsOn jacocoRootReport
onlyIf { System.env.'CI' }
-}
+}
\ No newline at end of file
diff --git a/example/build.gradle b/example/build.gradle
index 129eb11e..a8b90f05 100644
--- a/example/build.gradle
+++ b/example/build.gradle
@@ -2,44 +2,24 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
- buildToolsVersion "23.0.2"
+ 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.1.1'
- testCompile 'org.robolectric:robolectric:3.0'
- testCompile 'junit:junit:4.12'
+ compile 'com.android.support:appcompat-v7:23.3.0'
}
-
-//robolectric {
-// // Configure includes / excludes
-// include '**/*Tests.class'
-// exclude '**/espresso/**/*.class'
-//
-// // Configure max heap size of the test JVM
-// maxHeapSize = '2048m'
-//
-// // Configure the test JVM arguments - Does not apply to Java 8
-// jvmArgs '-XX:MaxPermSize=512m', '-XX:-UseSplitVerifier'
-//
-// // configure whether failing tests should fail the build
-// ignoreFailures true
-//
-// // use afterTest to listen to the test execution results
-// afterTest { descriptor, result ->
-// println "Executing test for ${descriptor.name} with result: ${result.resultType}"
-// }
-//}
diff --git a/example/src/main/java/com/example/activities/SugarActivity.java b/example/src/main/java/com/example/activities/SugarActivity.java
index 197314a0..81044546 100644
--- a/example/src/main/java/com/example/activities/SugarActivity.java
+++ b/example/src/main/java/com/example/activities/SugarActivity.java
@@ -1,7 +1,6 @@
package com.example.activities;
import android.app.Activity;
-import android.content.Intent;
import android.os.Bundle;
import com.example.R;
diff --git a/example/src/test/java/com/example/sugartest/BigDecimalFieldTests.java b/example/src/test/java/com/example/sugartest/BigDecimalFieldTests.java
deleted file mode 100644
index 9e4b36bb..00000000
--- a/example/src/test/java/com/example/sugartest/BigDecimalFieldTests.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.BigDecimalFieldAnnotatedModel;
-import com.example.models.BigDecimalFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import java.math.BigDecimal;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class BigDecimalFieldTests {
- @Test
- public void nullBigDecimalExtendedTest() {
- save(new BigDecimalFieldExtendedModel());
- BigDecimalFieldExtendedModel model =
- SugarRecord.findById(BigDecimalFieldExtendedModel.class, 1);
- assertNull(model.getBigDecimal());
- }
-
- @Test
- public void nullBigDecimalAnnotatedTest() {
- save(new BigDecimalFieldAnnotatedModel());
- BigDecimalFieldAnnotatedModel model =
- SugarRecord.findById(BigDecimalFieldAnnotatedModel.class, 1);
- assertNull(model.getBigDecimal());
- }
-
- @Test
- public void bigDecimalExtendedTest() {
- BigDecimal decimal = new BigDecimal(1234.5678901234567890123456789);
- save(new BigDecimalFieldExtendedModel(decimal));
- BigDecimalFieldExtendedModel model = SugarRecord.findById(BigDecimalFieldExtendedModel.class, 1);
- assertEquals(decimal, model.getBigDecimal());
- }
-
- @Test
- public void bigDecimalAnnotatedTest() {
- BigDecimal decimal = new BigDecimal(1234.5678901234567890123456789);
- save(new BigDecimalFieldAnnotatedModel(decimal));
- BigDecimalFieldAnnotatedModel model =
- SugarRecord.findById(BigDecimalFieldAnnotatedModel.class, 1);
- assertEquals(decimal, model.getBigDecimal());
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/BooleanFieldTests.java b/example/src/test/java/com/example/sugartest/BooleanFieldTests.java
deleted file mode 100644
index a117af6c..00000000
--- a/example/src/test/java/com/example/sugartest/BooleanFieldTests.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.BooleanFieldAnnotatedModel;
-import com.example.models.BooleanFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class BooleanFieldTests {
- @Test
- public void nullBooleanExtendedTest() {
- save(new BooleanFieldExtendedModel());
- BooleanFieldExtendedModel model = SugarRecord.findById(BooleanFieldExtendedModel.class, 1);
- assertNull(model.getBoolean());
- }
-
- @Test
- public void nullRawBooleanExtendedTest() {
- save(new BooleanFieldExtendedModel());
- BooleanFieldExtendedModel model = SugarRecord.findById(BooleanFieldExtendedModel.class, 1);
- assertEquals(false, model.getRawBoolean());
- }
-
- @Test
- public void nullBooleanAnnotatedTest() {
- save(new BooleanFieldAnnotatedModel());
- BooleanFieldAnnotatedModel model = SugarRecord.findById(BooleanFieldAnnotatedModel.class, 1);
- assertNull(model.getBoolean());
- }
-
- @Test
- public void nullRawBooleanAnnotatedTest() {
- save(new BooleanFieldAnnotatedModel());
- BooleanFieldAnnotatedModel model = SugarRecord.findById(BooleanFieldAnnotatedModel.class, 1);
- assertEquals(false, model.getRawBoolean());
- }
-
- @Test
- public void objectBooleanExtendedTest() {
- Boolean objectBoolean = new Boolean(true);
- save(new BooleanFieldExtendedModel(objectBoolean));
- BooleanFieldExtendedModel model = SugarRecord.findById(BooleanFieldExtendedModel.class, 1);
- assertEquals(objectBoolean, model.getBoolean());
- }
-
- @Test
- public void rawBooleanExtendedTest() {
- save(new BooleanFieldExtendedModel(true));
- BooleanFieldExtendedModel model = SugarRecord.findById(BooleanFieldExtendedModel.class, 1);
- assertEquals(true, model.getRawBoolean());
- }
-
- @Test
- public void objectBooleanAnnotatedTest() {
- Boolean objectBoolean = new Boolean(true);
- save(new BooleanFieldAnnotatedModel(objectBoolean));
- BooleanFieldAnnotatedModel model = SugarRecord.findById(BooleanFieldAnnotatedModel.class, 1);
- assertEquals(objectBoolean, model.getBoolean());
- }
-
- @Test
- public void rawBooleanAnnotatedTest() {
- save(new BooleanFieldAnnotatedModel(true));
- BooleanFieldAnnotatedModel model = SugarRecord.findById(BooleanFieldAnnotatedModel.class, 1);
- assertEquals(true, model.getRawBoolean());
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/FirstAndLastTests.java b/example/src/test/java/com/example/sugartest/FirstAndLastTests.java
deleted file mode 100644
index d095578f..00000000
--- a/example/src/test/java/com/example/sugartest/FirstAndLastTests.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.FloatFieldAnnotatedModel;
-import com.example.models.FloatFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class FirstAndLastTests {
- @Test
- public void firstExtendedTest() {
- Float firstObjectFloat = new Float(25F);
- Float lastObjectFloat = new Float(50F);
- save(new FloatFieldExtendedModel(firstObjectFloat));
- save(new FloatFieldExtendedModel(lastObjectFloat));
- FloatFieldExtendedModel model = SugarRecord.first(FloatFieldExtendedModel.class);
- assertEquals(firstObjectFloat, model.getFloat());
- }
-
- @Test
- public void firstDeletedRecordExtendedTest() {
- Float firstObjectFloat = new Float(15F);
- Float secondObjectFloat = new Float(25F);
- Float thirdObjectFloat = new Float(35F);
- Float fourthObjectFloat = new Float(45F);
- save(new FloatFieldExtendedModel(firstObjectFloat));
- save(new FloatFieldExtendedModel(secondObjectFloat));
- save(new FloatFieldExtendedModel(thirdObjectFloat));
- save(new FloatFieldExtendedModel(fourthObjectFloat));
- FloatFieldExtendedModel firstRecord = SugarRecord.findById(FloatFieldExtendedModel.class, 1);
- firstRecord.delete();
- FloatFieldExtendedModel model = SugarRecord.first(FloatFieldExtendedModel.class);
- assertEquals(secondObjectFloat, model.getFloat());
- }
-
- @Test
- public void lastExtendedTest() {
- Float firstObjectFloat = new Float(25F);
- Float lastObjectFloat = new Float(50F);
- save(new FloatFieldExtendedModel(firstObjectFloat));
- save(new FloatFieldExtendedModel(lastObjectFloat));
- FloatFieldExtendedModel model = SugarRecord.last(FloatFieldExtendedModel.class);
- assertEquals(lastObjectFloat, model.getFloat());
- }
-
- @Test
- public void lastDeletedRecordExtendedTest() {
- Float firstObjectFloat = new Float(15F);
- Float secondObjectFloat = new Float(25F);
- Float thirdObjectFloat = new Float(35F);
- Float fourthObjectFloat = new Float(45F);
- save(new FloatFieldExtendedModel(firstObjectFloat));
- save(new FloatFieldExtendedModel(secondObjectFloat));
- save(new FloatFieldExtendedModel(thirdObjectFloat));
- save(new FloatFieldExtendedModel(fourthObjectFloat));
- FloatFieldExtendedModel lastRecord = SugarRecord.findById(FloatFieldExtendedModel.class, 4);
- lastRecord.delete();
- FloatFieldExtendedModel model = SugarRecord.last(FloatFieldExtendedModel.class);
- assertEquals(thirdObjectFloat, model.getFloat());
- }
-
- @Test
- public void nullFirstExtendedTest() {
- assertNull(SugarRecord.first(FloatFieldExtendedModel.class));
- }
-
- @Test
- public void nullLastExtendedTest() {
- assertNull(SugarRecord.last(FloatFieldExtendedModel.class));
- }
-
- @Test
- public void oneItemExtendedTest() {
- save(new FloatFieldExtendedModel(new Float(25F)));
- FloatFieldExtendedModel firstModel = SugarRecord.first(FloatFieldExtendedModel.class);
- FloatFieldExtendedModel lastModel = SugarRecord.last(FloatFieldExtendedModel.class);
- assertEquals(firstModel.getFloat(), lastModel.getFloat());
- }
-
- @Test
- public void firstAnnotatedTest() {
- Float firstObjectFloat = new Float(25F);
- Float lastObjectFloat = new Float(50F);
- save(new FloatFieldAnnotatedModel(firstObjectFloat));
- save(new FloatFieldAnnotatedModel(lastObjectFloat));
- FloatFieldAnnotatedModel model = SugarRecord.first(FloatFieldAnnotatedModel.class);
- assertEquals(firstObjectFloat, model.getFloat());
- }
-
- @Test
- public void firstDeletedRecordAnnotatedTest() {
- Float firstObjectFloat = new Float(15F);
- Float secondObjectFloat = new Float(25F);
- Float thirdObjectFloat = new Float(35F);
- Float fourthObjectFloat = new Float(45F);
- save(new FloatFieldAnnotatedModel(firstObjectFloat));
- save(new FloatFieldAnnotatedModel(secondObjectFloat));
- save(new FloatFieldAnnotatedModel(thirdObjectFloat));
- save(new FloatFieldAnnotatedModel(fourthObjectFloat));
- FloatFieldAnnotatedModel firstRecord = SugarRecord.findById(FloatFieldAnnotatedModel.class, 1);
- SugarRecord.delete(firstRecord);
- FloatFieldAnnotatedModel model = SugarRecord.first(FloatFieldAnnotatedModel.class);
- assertEquals(secondObjectFloat, model.getFloat());
- }
-
- @Test
- public void lastAnnotatedTest() {
- Float firstObjectFloat = new Float(25F);
- Float lastObjectFloat = new Float(50F);
- save(new FloatFieldAnnotatedModel(firstObjectFloat));
- save(new FloatFieldAnnotatedModel(lastObjectFloat));
- FloatFieldAnnotatedModel model = SugarRecord.last(FloatFieldAnnotatedModel.class);
- assertEquals(lastObjectFloat, model.getFloat());
- }
-
- @Test
- public void lastDeletedRecordAnnotatedTest() {
- Float firstObjectFloat = new Float(15F);
- Float secondObjectFloat = new Float(25F);
- Float thirdObjectFloat = new Float(35F);
- Float fourthObjectFloat = new Float(45F);
- save(new FloatFieldAnnotatedModel(firstObjectFloat));
- save(new FloatFieldAnnotatedModel(secondObjectFloat));
- save(new FloatFieldAnnotatedModel(thirdObjectFloat));
- save(new FloatFieldAnnotatedModel(fourthObjectFloat));
- FloatFieldAnnotatedModel lastRecord = SugarRecord.findById(FloatFieldAnnotatedModel.class, 4);
- SugarRecord.delete(lastRecord);
- FloatFieldAnnotatedModel model = SugarRecord.last(FloatFieldAnnotatedModel.class);
- assertEquals(thirdObjectFloat, model.getFloat());
- }
-
- @Test
- public void nullFirstAnnotatedTest() {
- assertNull(SugarRecord.first(FloatFieldAnnotatedModel.class));
- }
-
- @Test
- public void nullLastAnnotatedTest() {
- assertNull(SugarRecord.last(FloatFieldAnnotatedModel.class));
- }
-
- @Test
- public void oneItemAnnotatedTest() {
- save(new FloatFieldAnnotatedModel(new Float(25F)));
- FloatFieldAnnotatedModel firstModel = SugarRecord.first(FloatFieldAnnotatedModel.class);
- FloatFieldAnnotatedModel lastModel = SugarRecord.last(FloatFieldAnnotatedModel.class);
- assertEquals(firstModel.getFloat(), lastModel.getFloat());
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/FloatFieldTests.java b/example/src/test/java/com/example/sugartest/FloatFieldTests.java
deleted file mode 100644
index 16f52bbc..00000000
--- a/example/src/test/java/com/example/sugartest/FloatFieldTests.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.FloatFieldAnnotatedModel;
-import com.example.models.FloatFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class FloatFieldTests {
- @Test
- public void nullFloatExtendedTest() {
- save(new FloatFieldExtendedModel());
- FloatFieldExtendedModel model = SugarRecord.findById(FloatFieldExtendedModel.class, 1);
- assertNull(model.getFloat());
- }
-
- @Test
- public void nullRawFloatExtendedTest() {
- save(new FloatFieldExtendedModel());
- FloatFieldExtendedModel model = SugarRecord.findById(FloatFieldExtendedModel.class, 1);
- assertEquals(0F, model.getRawFloat(), 0.0000000001F);
- }
-
- @Test
- public void nullFloatAnnotatedTest() {
- save(new FloatFieldAnnotatedModel());
- FloatFieldAnnotatedModel model = SugarRecord.findById(FloatFieldAnnotatedModel.class, 1);
- assertNull(model.getFloat());
- }
-
- @Test
- public void nullRawFloatAnnotatedTest() {
- save(new FloatFieldAnnotatedModel());
- FloatFieldAnnotatedModel model = SugarRecord.findById(FloatFieldAnnotatedModel.class, 1);
- assertEquals(0F, model.getRawFloat(), 0.0000000001F);
- }
-
- @Test
- public void objectFloatExtendedTest() {
- Float objectFloat = new Float(25F);
- save(new FloatFieldExtendedModel(objectFloat));
- FloatFieldExtendedModel model = SugarRecord.findById(FloatFieldExtendedModel.class, 1);
- assertEquals(objectFloat, model.getFloat());
- }
-
- @Test
- public void rawFloatExtendedTest() {
- save(new FloatFieldExtendedModel(25F));
- FloatFieldExtendedModel model = SugarRecord.findById(FloatFieldExtendedModel.class, 1);
- assertEquals(25F, model.getRawFloat(), 0.0000000001F);
- }
-
- @Test
- public void objectFloatAnnotatedTest() {
- Float objectFloat = new Float(25F);
- save(new FloatFieldAnnotatedModel(objectFloat));
- FloatFieldAnnotatedModel model = SugarRecord.findById(FloatFieldAnnotatedModel.class, 1);
- assertEquals(objectFloat, model.getFloat());
- }
-
- @Test
- public void rawFloatAnnotatedTest() {
- save(new FloatFieldAnnotatedModel(25F));
- FloatFieldAnnotatedModel model = SugarRecord.findById(FloatFieldAnnotatedModel.class, 1);
- assertEquals(25F, model.getRawFloat(), 0.0000000001F);
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/IntegerFieldTests.java b/example/src/test/java/com/example/sugartest/IntegerFieldTests.java
deleted file mode 100644
index 25dbd0bd..00000000
--- a/example/src/test/java/com/example/sugartest/IntegerFieldTests.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.IntegerFieldAnnotatedModel;
-import com.example.models.IntegerFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class IntegerFieldTests {
- @Test
- public void nullIntegerExtendedTest() {
- save(new IntegerFieldExtendedModel());
- IntegerFieldExtendedModel model = SugarRecord.findById(IntegerFieldExtendedModel.class, 1);
- assertNull(model.getInteger());
- }
-
- @Test
- public void nullIntExtendedTest() {
- save(new IntegerFieldExtendedModel());
- IntegerFieldExtendedModel model = SugarRecord.findById(IntegerFieldExtendedModel.class, 1);
- assertEquals(0, model.getInt());
- }
-
- @Test
- public void nullIntegerAnnotatedTest() {
- save(new IntegerFieldAnnotatedModel());
- IntegerFieldAnnotatedModel model = SugarRecord.findById(IntegerFieldAnnotatedModel.class, 1);
- assertNull(model.getInteger());
- }
-
- @Test
- public void nullIntAnnotatedTest() {
- save(new IntegerFieldAnnotatedModel());
- IntegerFieldAnnotatedModel model = SugarRecord.findById(IntegerFieldAnnotatedModel.class, 1);
- assertEquals(0, model.getInt());
- }
-
- @Test
- public void integerExtendedTest() {
- Integer integer = new Integer(25);
- save(new IntegerFieldExtendedModel(integer));
- IntegerFieldExtendedModel model = SugarRecord.findById(IntegerFieldExtendedModel.class, 1);
- assertEquals(integer, model.getInteger());
- }
-
- @Test
- public void intExtendedTest() {
- save(new IntegerFieldExtendedModel(25));
- IntegerFieldExtendedModel model = SugarRecord.findById(IntegerFieldExtendedModel.class, 1);
- assertEquals(25, model.getInt());
- }
-
- @Test
- public void integerAnnotatedTest() {
- Integer integer = new Integer(25);
- save(new IntegerFieldAnnotatedModel(integer));
- IntegerFieldAnnotatedModel model = SugarRecord.findById(IntegerFieldAnnotatedModel.class, 1);
- assertEquals(integer, model.getInteger());
- }
-
- @Test
- public void intAnnotatedTest() {
- save(new IntegerFieldAnnotatedModel(25));
- IntegerFieldAnnotatedModel model = SugarRecord.findById(IntegerFieldAnnotatedModel.class, 1);
- assertEquals(25, model.getInt());
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/ListAllOrderByTests.java b/example/src/test/java/com/example/sugartest/ListAllOrderByTests.java
deleted file mode 100644
index 014c989d..00000000
--- a/example/src/test/java/com/example/sugartest/ListAllOrderByTests.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.IntegerFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import java.util.List;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class ListAllOrderByTests {
- @Test
- public void listAllOrderByEmptyTest() {
- assertEquals(0L, SugarRecord.listAll(IntegerFieldExtendedModel.class, "id").size());
- }
-
- @Test
- public void listAllOrderByIdTest() {
- for(int i = 1; i <= 100; i++) {
- save(new IntegerFieldExtendedModel(i));
- }
- List models =
- SugarRecord.listAll(IntegerFieldExtendedModel.class, "id");
- assertEquals(100L, models.size());
- Long id = models.get(0).getId();
- for(int i = 1; i < 100; i++) {
- assertTrue(id models =
- SugarRecord.listAll(IntegerFieldExtendedModel.class, "raw_integer");
- assertEquals(100L, models.size());
- int raw = models.get(0).getInt();
- for(int i = 1; i < 100; i++) {
- assertTrue(raw < models.get(i).getInt());
- }
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/LongFieldTests.java b/example/src/test/java/com/example/sugartest/LongFieldTests.java
deleted file mode 100644
index b99e7537..00000000
--- a/example/src/test/java/com/example/sugartest/LongFieldTests.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.LongFieldAnnotatedModel;
-import com.example.models.LongFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class LongFieldTests {
- @Test
- public void nullLongExtendedTest() {
- save(new LongFieldExtendedModel());
- LongFieldExtendedModel model = SugarRecord.findById(LongFieldExtendedModel.class, 1);
- assertNull(model.getLong());
- }
-
- @Test
- public void nullRawLongExtendedTest() {
- save(new LongFieldExtendedModel());
- LongFieldExtendedModel model = SugarRecord.findById(LongFieldExtendedModel.class, 1);
- assertEquals(0L, model.getRawLong());
- }
-
- @Test
- public void nullLongAnnotatedTest() {
- save(new LongFieldAnnotatedModel());
- LongFieldAnnotatedModel model = SugarRecord.findById(LongFieldAnnotatedModel.class, 1);
- assertNull(model.getLong());
- }
-
- @Test
- public void nullRawLongAnnotatedTest() {
- save(new LongFieldAnnotatedModel());
- LongFieldAnnotatedModel model = SugarRecord.findById(LongFieldAnnotatedModel.class, 1);
- assertEquals(0L, model.getRawLong());
- }
-
- @Test
- public void objectLongExtendedTest() {
- Long objectLong = new Long(25L);
- save(new LongFieldExtendedModel(objectLong));
- LongFieldExtendedModel model = SugarRecord.findById(LongFieldExtendedModel.class, 1);
- assertEquals(objectLong, model.getLong());
- }
-
- @Test
- public void rawLongExtendedTest() {
- save(new LongFieldExtendedModel(25L));
- LongFieldExtendedModel model = SugarRecord.findById(LongFieldExtendedModel.class, 1);
- assertEquals(25L, model.getRawLong());
- }
-
- @Test
- public void objectLongAnnotatedTest() {
- Long objectLong = new Long(25L);
- save(new LongFieldAnnotatedModel(objectLong));
- LongFieldAnnotatedModel model = SugarRecord.findById(LongFieldAnnotatedModel.class, 1);
- assertEquals(objectLong, model.getLong());
- }
-
- @Test
- public void rawLongAnnotatedTest() {
- save(new LongFieldAnnotatedModel(25L));
- LongFieldAnnotatedModel model = SugarRecord.findById(LongFieldAnnotatedModel.class, 1);
- assertEquals(25L, model.getRawLong());
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/MultipleSaveTests.java b/example/src/test/java/com/example/sugartest/MultipleSaveTests.java
deleted file mode 100644
index 58c669c5..00000000
--- a/example/src/test/java/com/example/sugartest/MultipleSaveTests.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.StringFieldAnnotatedModel;
-import com.example.models.StringFieldAnnotatedNoIdModel;
-import com.example.models.StringFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class MultipleSaveTests {
- @Test
- public void stringMultipleSaveOriginalExtendedTest() {
- String string = "Test String";
- StringFieldExtendedModel model = new StringFieldExtendedModel(string);
- long id = save(model);
- StringFieldExtendedModel query = SugarRecord.findById(StringFieldExtendedModel.class, id);
- assertEquals(string, query.getString());
- model.setString("Another test");
- assertEquals(id, save(model));
- assertNull(SugarRecord.findById(StringFieldExtendedModel.class, 2));
- }
-
- @Test
- public void stringMultipleSaveQueriedExtendedTest() {
- String string = "Test String";
- StringFieldExtendedModel model = new StringFieldExtendedModel(string);
- long id = save(model);
- StringFieldExtendedModel query = SugarRecord.findById(StringFieldExtendedModel.class, id);
- assertEquals(string, query.getString());
- query.setString("Another test");
- assertEquals(id, save(query));
- assertNull(SugarRecord.findById(StringFieldExtendedModel.class, 2));
- }
-
- @Test
- public void stringMultipleSaveOriginalAnnotatedTest() {
- String string = "Test String";
- StringFieldAnnotatedModel model = new StringFieldAnnotatedModel(string);
- long id = save(model);
- StringFieldAnnotatedModel query = SugarRecord.findById(StringFieldAnnotatedModel.class, id);
- assertEquals(string, query.getString());
- model.setString("Another test");
- assertEquals(id, save(model));
- assertNull(SugarRecord.findById(StringFieldAnnotatedModel.class, 2));
- }
-
- @Test
- public void stringMultipleSaveQueriedAnnotatedTest() {
- String string = "Test String";
- StringFieldAnnotatedModel model = new StringFieldAnnotatedModel(string);
- long id = save(model);
- StringFieldAnnotatedModel query = SugarRecord.findById(StringFieldAnnotatedModel.class, id);
- assertEquals(string, query.getString());
- query.setString("Another test");
- assertEquals(id, save(query));
- assertNull(SugarRecord.findById(StringFieldAnnotatedModel.class, 2));
- }
-
- @Test
- public void stringMultipleSaveOriginalAnnotatedNoIdTest() {
- String string = "Test String";
- StringFieldAnnotatedNoIdModel model = new StringFieldAnnotatedNoIdModel(string);
- long id = save(model);
- StringFieldAnnotatedNoIdModel query =
- SugarRecord.findById(StringFieldAnnotatedNoIdModel.class, id);
- assertEquals(string, query.getString());
- model.setString("Another test");
- assertEquals(id, save(model));
- assertNull(SugarRecord.findById(StringFieldAnnotatedNoIdModel.class, 2));
- }
-
- @Test
- public void stringMultipleSaveQueriedAnnotatedNoIdTest() {
- String string = "Test String";
- StringFieldAnnotatedNoIdModel model = new StringFieldAnnotatedNoIdModel(string);
- long id = save(model);
- StringFieldAnnotatedNoIdModel query =
- SugarRecord.findById(StringFieldAnnotatedNoIdModel.class, id);
- assertEquals(string, query.getString());
- query.setString("Another test");
- assertEquals(id, save(query));
- assertNull(SugarRecord.findById(StringFieldAnnotatedNoIdModel.class, 2));
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/NoSugarModelTests.java b/example/src/test/java/com/example/sugartest/NoSugarModelTests.java
deleted file mode 100644
index dbab8103..00000000
--- a/example/src/test/java/com/example/sugartest/NoSugarModelTests.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.example.sugartest;
-
-import com.example.models.NoSugarModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class NoSugarModelTests {
- @Test
- public void deleteTest() throws Exception {
- NoSugarModel model = new NoSugarModel();
- assertFalse(SugarRecord.delete(model));
- }
-
- @Test
- public void saveInTransactionTest() throws Exception {
- SugarRecord.saveInTx(new NoSugarModel(), new NoSugarModel());
- assertEquals(-1L, SugarRecord.count(NoSugarModel.class));
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/RelationshipMixedATests.java b/example/src/test/java/com/example/sugartest/RelationshipMixedATests.java
deleted file mode 100644
index 7ecb6751..00000000
--- a/example/src/test/java/com/example/sugartest/RelationshipMixedATests.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.example.sugartest;
-
-import com.example.models.RelationshipMixedAModel;
-import com.example.models.SimpleAnnotatedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import java.util.List;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class RelationshipMixedATests {
- @Test
- public void emptyDatabaseTest() throws Exception {
- assertEquals(0L, SugarRecord.count(RelationshipMixedAModel.class));
- assertEquals(0L, SugarRecord.count(SimpleAnnotatedModel.class));
- }
-
- @Test
- public void oneSaveTest() throws Exception {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- save(new RelationshipMixedAModel(simple));
- assertEquals(1L, SugarRecord.count(SimpleAnnotatedModel.class));
- assertEquals(1L, SugarRecord.count(RelationshipMixedAModel.class));
- }
-
- @Test
- public void twoSameSaveTest() throws Exception {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- save(new RelationshipMixedAModel(simple));
- save(new RelationshipMixedAModel(simple));
- assertEquals(1L, SugarRecord.count(SimpleAnnotatedModel.class));
- assertEquals(2L, SugarRecord.count(RelationshipMixedAModel.class));
- }
-
- @Test
- public void twoDifferentSaveTest() throws Exception {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- SimpleAnnotatedModel another_simple = new SimpleAnnotatedModel();
- save(another_simple);
- save(new RelationshipMixedAModel(simple));
- save(new RelationshipMixedAModel(another_simple));
- assertEquals(2L, SugarRecord.count(SimpleAnnotatedModel.class));
- assertEquals(2L, SugarRecord.count(RelationshipMixedAModel.class));
- }
-
- @Test
- public void manySameSaveTest() throws Exception {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- for (int i = 1; i <= 100; i++) {
- save(new RelationshipMixedAModel(simple));
- }
- assertEquals(1L, SugarRecord.count(SimpleAnnotatedModel.class));
- assertEquals(100L, SugarRecord.count(RelationshipMixedAModel.class));
- }
-
- @Test
- public void manyDifferentSaveTest() throws Exception {
- for (int i = 1; i <= 100; i++) {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- save(new RelationshipMixedAModel(simple));
- }
- assertEquals(100L, SugarRecord.count(SimpleAnnotatedModel.class));
- assertEquals(100L, SugarRecord.count(RelationshipMixedAModel.class));
- }
-
- @Test
- public void listAllSameTest() throws Exception {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- for (int i = 1; i <= 100; i++) {
- save(new RelationshipMixedAModel(simple));
- }
- List models =
- SugarRecord.listAll(RelationshipMixedAModel.class);
- assertEquals(100, models.size());
- for (RelationshipMixedAModel model : models) {
- assertEquals(simple.getId(), model.getSimple().getId());
- }
- }
-
- @Test
- public void listAllDifferentTest() throws Exception {
- for (int i = 1; i <= 100; i++) {
- SimpleAnnotatedModel simple = new SimpleAnnotatedModel();
- save(simple);
- save(new RelationshipMixedAModel(simple));
- }
- List models =
- SugarRecord.listAll(RelationshipMixedAModel.class);
- assertEquals(100, models.size());
- for (RelationshipMixedAModel model : models) {
- assertEquals(model.getId(), model.getSimple().getId());
- }
- }
-}
diff --git a/example/src/test/java/com/example/sugartest/RobolectricGradleTestRunner.java b/example/src/test/java/com/example/sugartest/RobolectricGradleTestRunner.java
deleted file mode 100644
index 4f7bc39d..00000000
--- a/example/src/test/java/com/example/sugartest/RobolectricGradleTestRunner.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.example.sugartest;
-
-import com.example.ClientApp;
-
-import org.junit.runners.model.InitializationError;
-import org.robolectric.RobolectricTestRunner;
-import org.robolectric.annotation.Config;
-import org.robolectric.manifest.AndroidManifest;
-import org.robolectric.res.Fs;
-
-public class RobolectricGradleTestRunner extends RobolectricTestRunner {
- public RobolectricGradleTestRunner(Class> testClass) throws InitializationError {
- super(testClass);
- }
-
- @Override protected AndroidManifest getAppManifest(Config config) {
- String myAppPath = ClientApp.class.getProtectionDomain().getCodeSource().getLocation().getPath();
- String manifestPath = myAppPath + "../../../../src/main/AndroidManifest.xml";
- String resPath = myAppPath + "../../../../src/main/res";
- String assetPath = myAppPath + "../../../../src/main/assets";
- String packageName = "com.example";
- return createAppManifest(Fs.fileFromPath(manifestPath), Fs.fileFromPath(resPath), Fs.fileFromPath(assetPath), packageName);
- }
-}
\ No newline at end of file
diff --git a/example/src/test/java/com/example/sugartest/ShortFieldTests.java b/example/src/test/java/com/example/sugartest/ShortFieldTests.java
deleted file mode 100644
index 3c428752..00000000
--- a/example/src/test/java/com/example/sugartest/ShortFieldTests.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.example.sugartest;
-
-
-import com.example.models.ShortFieldAnnotatedModel;
-import com.example.models.ShortFieldExtendedModel;
-import com.orm.SugarRecord;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.annotation.Config;
-
-import static com.orm.SugarRecord.save;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-@RunWith(RobolectricGradleTestRunner.class)
-@Config(sdk=18)
-public class ShortFieldTests {
- @Test
- public void nullShortExtendedTest() {
- save(new ShortFieldExtendedModel());
- ShortFieldExtendedModel model = SugarRecord.findById(ShortFieldExtendedModel.class, 1);
- assertNull(model.getShort());
- }
-
- @Test
- public void nullRawShortExtendedTest() {
- save(new ShortFieldExtendedModel());
- ShortFieldExtendedModel model = SugarRecord.findById(ShortFieldExtendedModel.class, 1);
- assertEquals((short) 0, model.getRawShort());
- }
-
- @Test
- public void nullShortAnnotatedTest() {
- save(new ShortFieldAnnotatedModel());
- ShortFieldAnnotatedModel model = SugarRecord.findById(ShortFieldAnnotatedModel.class, 1);
- assertNull(model.getShort());
- }
-
- @Test
- public void nullRawShortAnnotatedTest() {
- save(new ShortFieldAnnotatedModel());
- ShortFieldAnnotatedModel model = SugarRecord.findById(ShortFieldAnnotatedModel.class, 1);
- assertEquals((short) 0, model.getRawShort());
- }
-
- @Test
- public void objectShortExtendedTest() {
- Short objectShort = new Short((short) 25);
- save(new ShortFieldExtendedModel(objectShort));
- ShortFieldExtendedModel model = SugarRecord.findById(ShortFieldExtendedModel.class, 1);
- assertEquals(objectShort, model.getShort());
- }
-
- @Test
- public void rawShortExtendedTest() {
- save(new ShortFieldExtendedModel((short) 25));
- ShortFieldExtendedModel model = SugarRecord.findById(ShortFieldExtendedModel.class, 1);
- assertEquals((short) 25, model.getRawShort());
- }
-
- @Test
- public void objectShortAnnotatedTest() {
- Short objectShort = new Short((short) 25);
- save(new ShortFieldAnnotatedModel(objectShort));
- ShortFieldAnnotatedModel model = SugarRecord.findById(ShortFieldAnnotatedModel.class, 1);
- assertEquals(objectShort, model.getShort());
- }
-
- @Test
- public void rawShortAnnotatedTest() {
- save(new ShortFieldAnnotatedModel((short) 25));
- ShortFieldAnnotatedModel model = SugarRecord.findById(ShortFieldAnnotatedModel.class, 1);
- assertEquals((short) 25, model.getRawShort());
- }
-}
diff --git a/gradle.properties b/gradle.properties
index b1d9b965..35b4c26f 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -16,6 +16,7 @@
# 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
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 0c71e760..b0bb3ffb 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Apr 10 15:27:10 PDT 2013
+#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.2.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
diff --git a/library/build.gradle b/library/build.gradle
index d9a42c18..907162ee 100644
--- a/library/build.gradle
+++ b/library/build.gradle
@@ -3,22 +3,28 @@ apply from: '../maven_push.gradle'
android {
compileSdkVersion 23
- buildToolsVersion "23.0.2"
+ buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
}
-
buildTypes {
release {
minifyEnabled false
}
}
+ testOptions {
+ unitTests.returnDefaultValues = true
+ }
+ lintOptions {
+ abortOnError false
+ }
}
dependencies {
testCompile 'junit:junit:4.12'
+ testCompile 'org.robolectric:robolectric:3.0'
}
task libraryJar(type: Jar) {
diff --git a/library/src/main/java/com/orm/SchemaGenerator.java b/library/src/main/java/com/orm/SchemaGenerator.java
index 91f80e1b..c25407fc 100644
--- a/library/src/main/java/com/orm/SchemaGenerator.java
+++ b/library/src/main/java/com/orm/SchemaGenerator.java
@@ -1,15 +1,19 @@
package com.orm;
-import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
-import com.orm.dsl.Column;
-import com.orm.dsl.NotNull;
-import com.orm.dsl.Unique;
-import com.orm.util.NamingHelper;
+import com.orm.annotation.Column;
+import com.orm.annotation.MultiUnique;
+import com.orm.annotation.NotNull;
+import com.orm.annotation.Unique;
+import com.orm.dsl.BuildConfig;
+import com.orm.helper.ManifestHelper;
+import com.orm.util.KeyWordUtil;
+import com.orm.util.MigrationFileParser;
+import com.orm.helper.NamingHelper;
import com.orm.util.NumberComparator;
import com.orm.util.QueryBuilder;
import com.orm.util.ReflectionUtil;
@@ -19,48 +23,75 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.orm.util.ReflectionUtil.getDomainClasses;
+import static com.orm.util.ContextUtil.getAssets;
public class SchemaGenerator {
-
- private Context context;
-
public static final String NULL = " NULL";
public static final String NOT_NULL = " NOT NULL";
public static final String UNIQUE = " UNIQUE";
public static final String SUGAR = "Sugar";
- public SchemaGenerator(Context context) {
- this.context = context;
+ //Prevent instantiation
+ private SchemaGenerator() { }
+
+ public static SchemaGenerator getInstance() {
+ return new SchemaGenerator();
}
public void createDatabase(SQLiteDatabase sqLiteDatabase) {
- List domainClasses = getDomainClasses(context);
+ List domainClasses = getDomainClasses();
for (Class domain : domainClasses) {
createTable(domain, sqLiteDatabase);
+ afterTableCreated(domain,sqLiteDatabase);
}
+
+ }
+
+ public void afterTableCreated(Class> table, SQLiteDatabase sqLiteDatabase) {
+ String fileName = table.getSimpleName() + ".sql";
+ executeScript(sqLiteDatabase,"sugar_after_create/" ,fileName);
+
}
public void doUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
- List domainClasses = getDomainClasses(context);
+ List domainClasses = getDomainClasses();
String sql = "select count(*) from sqlite_master where type='table' and name='%s';";
+
for (Class domain : domainClasses) {
- Cursor cursor = sqLiteDatabase.rawQuery(String.format(sql, NamingHelper.toSQLName(domain)), null);
- if (cursor.moveToFirst() && cursor.getInt(0) == 0) {
- createTable(domain, sqLiteDatabase);
+ String tableName = NamingHelper.toTableName(domain);
+ Cursor c = sqLiteDatabase.rawQuery(String.format(sql, tableName), null);
+ if (c.moveToFirst() && c.getInt(0) == 0) {
+ createTable(domain, sqLiteDatabase);
+ } else {
+ addColumns(domain, sqLiteDatabase);
}
}
executeSugarUpgrade(sqLiteDatabase, oldVersion, newVersion);
}
+ protected ArrayList getColumnNames(SQLiteDatabase sqLiteDatabase, String tableName) {
+ Cursor resultsQuery = sqLiteDatabase.query(tableName, null, null, null, null, null, null);
+ //Check if columns match vs the one on the domain class
+ ArrayList columnNames = new ArrayList<>();
+ for (int i = 0; i < resultsQuery.getColumnCount(); i++) {
+ String columnName = resultsQuery.getColumnName(i);
+ columnNames.add(columnName);
+ }
+ resultsQuery.close();
+ return columnNames;
+ }
+
+
public void deleteTables(SQLiteDatabase sqLiteDatabase) {
- List tables = getDomainClasses(context);
+ List tables = getDomainClasses();
for (Class table : tables) {
- sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + NamingHelper.toSQLName(table));
+ sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + NamingHelper.toTableName(table));
}
}
@@ -68,55 +99,125 @@ private boolean executeSugarUpgrade(SQLiteDatabase db, int oldVersion, int newVe
boolean isSuccess = false;
try {
- List files = Arrays.asList(this.context.getAssets().list("sugar_upgrades"));
+ List files = Arrays.asList(getAssets().list("sugar_upgrades"));
Collections.sort(files, new NumberComparator());
for (String file : files) {
- Log.i(SUGAR, "filename : " + file);
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i(SUGAR, "filename : " + file);
+ }
try {
int version = Integer.valueOf(file.replace(".sql", ""));
if ((version > oldVersion) && (version <= newVersion)) {
- executeScript(db, file);
+ executeScript(db,"sugar_upgrades/" ,file);
isSuccess = true;
}
} catch (NumberFormatException e) {
- Log.i(SUGAR, "not a sugar script. ignored." + file);
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i(SUGAR, "not a sugar script. ignored." + file);
+ }
}
}
} catch (IOException e) {
- Log.e(SUGAR, e.getMessage());
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.e(SUGAR, e.getMessage());
+ }
}
return isSuccess;
}
- private void executeScript(SQLiteDatabase db, String file) {
+ private void executeScript(SQLiteDatabase db,String path ,String file) {
try {
- InputStream is = this.context.getAssets().open("sugar_upgrades/" + file);
+ InputStream is = getAssets().open(path + file);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
+ StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
- Log.i("Sugar script", line);
- db.execSQL(line);
+ sb.append(line);
+ }
+ MigrationFileParser migrationFileParser = new MigrationFileParser(sb.toString());
+ for(String statement: migrationFileParser.getStatements()){
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i("Sugar script", statement);
+ }
+ if (!statement.isEmpty()) {
+ db.execSQL(statement);
+ }
}
+
} catch (IOException e) {
- Log.e(SUGAR, e.getMessage());
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.e(SUGAR, e.getMessage());
+ }
}
- Log.i(SUGAR, "Script executed");
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i(SUGAR, "Script executed");
+ }
}
- private void createTable(Class> table, SQLiteDatabase sqLiteDatabase) {
- Log.i(SUGAR, "Create table if not exists");
+ private void addColumns(Class> table, SQLiteDatabase sqLiteDatabase) {
List fields = ReflectionUtil.getTableFields(table);
- String tableName = NamingHelper.toSQLName(table);
+ String tableName = NamingHelper.toTableName(table);
+ ArrayList presentColumns = getColumnNames(sqLiteDatabase, tableName);
+ ArrayList alterCommands = new ArrayList<>();
+
+ for (Field column : fields) {
+ String columnName = NamingHelper.toColumnName(column);
+ String columnType = QueryBuilder.getColumnType(column.getType());
+
+ if (column.isAnnotationPresent(Column.class)) {
+ Column columnAnnotation = column.getAnnotation(Column.class);
+ columnName = columnAnnotation.name();
+ }
+
+ if (!presentColumns.contains(columnName)) {
+ StringBuilder sb = new StringBuilder("ALTER TABLE ");
+ sb.append(tableName).append(" ADD COLUMN ").append(columnName).append(" ").append(columnType);
+ if (column.isAnnotationPresent(NotNull.class)) {
+ if (columnType.endsWith(" NULL")) {
+ sb.delete(sb.length() - 5, sb.length());
+ }
+ sb.append(" NOT NULL");
+ }
+
+ // Unique is not working on ALTER TABLE
+// if (column.isAnnotationPresent(Unique.class)) {
+// sb.append(" UNIQUE");
+// }
+ alterCommands.add(sb.toString());
+ }
+ }
+
+ for (String command : alterCommands) {
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i("Sugar", command);
+ }
+ sqLiteDatabase.execSQL(command);
+ }
+ }
+
+ protected String createTableSQL(Class> table) {
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i(SUGAR, "Create table if not exists");
+ }
+ List fields = ReflectionUtil.getTableFields(table);
+ String tableName = NamingHelper.toTableName(table);
+
+ if(KeyWordUtil.isKeyword(tableName)) {
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i(SUGAR, "ERROR, SQLITE RESERVED WORD USED IN " + tableName);
+ }
+ }
+
StringBuilder sb = new StringBuilder("CREATE TABLE IF NOT EXISTS ");
sb.append(tableName).append(" ( ID INTEGER PRIMARY KEY AUTOINCREMENT ");
for (Field column : fields) {
- String columnName = NamingHelper.toSQLName(column);
+ String columnName = NamingHelper.toColumnName(column);
String columnType = QueryBuilder.getColumnType(column.getType());
if (columnType != null) {
@@ -158,12 +259,38 @@ private void createTable(Class> table, SQLiteDatabase sqLiteDatabase) {
}
}
+ if (table.isAnnotationPresent(MultiUnique.class)) {
+ String constraint = table.getAnnotation(MultiUnique.class).value();
+
+ sb.append(", UNIQUE(");
+
+ String[] constraintFields = constraint.split(",");
+ for(int i = 0; i < constraintFields.length; i++) {
+ String columnName = NamingHelper.toSQLNameDefault(constraintFields[i]);
+ sb.append(columnName);
+
+ if(i < (constraintFields.length -1)) {
+ sb.append(",");
+ }
+ }
+
+ sb.append(") ON CONFLICT REPLACE");
+ }
+
sb.append(" ) ");
- Log.i(SUGAR, "Creating table " + tableName);
+ if(ManifestHelper.isDebugEnabled()) {
+ Log.i(SUGAR, "Creating table " + tableName);
+ }
+
+ return sb.toString();
+ }
+
+ protected void createTable(Class> table, SQLiteDatabase sqLiteDatabase) {
+ String createSQL = createTableSQL(table);
- if (!sb.toString().isEmpty()) {
+ if (!createSQL.isEmpty()) {
try {
- sqLiteDatabase.execSQL(sb.toString());
+ sqLiteDatabase.execSQL(createSQL);
} catch (SQLException e) {
e.printStackTrace();
}
diff --git a/library/src/main/java/com/orm/SugarApp.java b/library/src/main/java/com/orm/SugarApp.java
index 5140e1ee..cab35ca7 100644
--- a/library/src/main/java/com/orm/SugarApp.java
+++ b/library/src/main/java/com/orm/SugarApp.java
@@ -1,7 +1,5 @@
package com.orm;
-import com.orm.SugarContext;
-
import android.app.Application;
public class SugarApp extends Application {
diff --git a/library/src/main/java/com/orm/SugarContext.java b/library/src/main/java/com/orm/SugarContext.java
index 6190b1aa..61609986 100644
--- a/library/src/main/java/com/orm/SugarContext.java
+++ b/library/src/main/java/com/orm/SugarContext.java
@@ -2,20 +2,21 @@
import android.content.Context;
+import com.orm.util.ContextUtil;
+
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
public class SugarContext {
+ private static SugarDbConfiguration dbConfiguration = null;
private static SugarContext instance = null;
private SugarDb sugarDb;
- private Context context;
private Map