diff --git a/.idea/gradle.xml b/.idea/gradle.xml index b2d9b0d..22d33fa 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -6,6 +6,7 @@ + diff --git a/.idea/libraries/support_annotations_21_0_3.xml b/.idea/libraries/support_annotations_21_0_3.xml deleted file mode 100644 index dba27e4..0000000 --- a/.idea/libraries/support_annotations_21_0_3.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_v4_21_0_3.xml b/.idea/libraries/support_v4_21_0_3.xml deleted file mode 100644 index e93f494..0000000 --- a/.idea/libraries/support_v4_21_0_3.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 8e4ea72..5d2aa1b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,39 +1,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -46,114 +37,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml index 5677e5f..3bccbb8 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,6 @@ - - - diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index be09186..a8e8858 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,8 +2,16 @@ - - + + + + + + + + + + @@ -21,25 +29,49 @@ - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -51,55 +83,19 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + @@ -113,34 +109,34 @@ - + - + - + - + - + - + - + - + - + - + - + - + @@ -153,45 +149,50 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + + @@ -208,7 +209,7 @@ - + @@ -225,14 +226,18 @@ + + + + - - - - + + + + @@ -257,40 +262,68 @@ - + + - + + + - + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + - + + @@ -313,19 +346,33 @@ - - - - - - - - - - + - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -347,18 +394,29 @@ + + + + + + + + + - - - - - - - - - + + + + + + + + + + + @@ -378,101 +436,75 @@ - + + + + + + + + + + - - - + - - - + - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - + + + + + + + + + + - + + - + + + + + - - - - - - - - - - - - - - - - - - - - - + + @@ -493,6 +525,15 @@ + + + + + + + + + @@ -521,6 +562,9 @@ + + + @@ -531,36 +575,38 @@ - + + - - - - - - + + - - + + + + + + + @@ -575,13 +621,10 @@ - - - - - - + + + @@ -591,11 +634,44 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 538f013..8f5ec4b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Mon Mar 02 10:34:35 GMT 2015 +#Tue Sep 08 18:21:43 EEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/rushcore.iml b/rushcore.iml index d21cdc6..fe8cb4d 100644 --- a/rushcore.iml +++ b/rushcore.iml @@ -1,5 +1,5 @@ - + @@ -25,8 +25,7 @@ - + - \ No newline at end of file diff --git a/src/main/java/co/uk/rushorm/core/RushCore.java b/src/main/java/co/uk/rushorm/core/RushCore.java index 558f07b..32eae44 100644 --- a/src/main/java/co/uk/rushorm/core/RushCore.java +++ b/src/main/java/co/uk/rushorm/core/RushCore.java @@ -2,6 +2,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -173,6 +174,9 @@ public void save(Rush rush) { } public void save(List extends Rush> objects) { + if(isEmpty(objects)){ + return; + } RushQue que = queProvider.blockForNextQue(); save(objects, que); } @@ -184,6 +188,9 @@ public void save(final Rush rush, final RushCallback callback) { } public void save(final List extends Rush> objects, final RushCallback callback) { + if(isEmpty(objects)){ + return; + } queProvider.waitForNextQue(new RushQueProvider.RushQueCallback() { @Override public void callback(RushQue rushQue) { @@ -196,11 +203,17 @@ public void callback(RushQue rushQue) { } public void join(List objects) { + if(isEmpty(objects)){ + return; + } RushQue que = queProvider.blockForNextQue(); join(objects, que); } public void join(final List objects, final RushCallback callback) { + if(isEmpty(objects)){ + return; + } queProvider.waitForNextQue(new RushQueProvider.RushQueCallback() { @Override public void callback(RushQue rushQue) { @@ -213,11 +226,17 @@ public void callback(RushQue rushQue) { } public void deleteJoin(List objects) { + if(isEmpty(objects)){ + return; + } RushQue que = queProvider.blockForNextQue(); deleteJoin(objects, que); } public void deleteJoin(final List objects, final RushCallback callback) { + if(isEmpty(objects)){ + return; + } queProvider.waitForNextQue(new RushQueProvider.RushQueCallback() { @Override public void callback(RushQue rushQue) { @@ -501,6 +520,7 @@ public void createClasses(List> missingClasses) { private static final int SAVE_GROUP_SIZE = 1000; private void save(List extends Rush> objects, final RushQue que) { + for (int i = 0; i < Math.ceil(objects.size() / ((float)SAVE_GROUP_SIZE)); i ++) { int start = i * SAVE_GROUP_SIZE; @@ -537,6 +557,9 @@ public RushMetaData getMetaData(Rush rush) { } private List saveOnlyWithoutConflict(List extends Rush> objects, final RushQue que) { + if(isEmpty(objects)){ + throw new IllegalArgumentException("List is null or empty!"); + } final List conflicts = new ArrayList<>(); statementRunner.startTransition(que); rushConflictSaveStatementGenerator.conflictsFromGenerateSaveOrUpdate(objects, annotationCache, rushStringSanitizer, rushColumns, new RushConflictSaveStatementGenerator.Callback() { @@ -579,6 +602,9 @@ public RushMetaData getMetaData(Rush rush) { } private void delete(List extends Rush> objects, final RushQue que) { + if(isEmpty(objects)){ + return; + } statementRunner.startTransition(que); deleteStatementGenerator.generateDelete(objects, annotationCache, new RushDeleteStatementGenerator.Callback() { @@ -630,6 +656,9 @@ private void removeRush(Rush rush) { } private void join(List objects, final RushQue que) { + if(isEmpty(objects)){ + return; + } statementRunner.startTransition(que); rushJoinStatementGenerator.createJoins(objects, new RushJoinStatementGenerator.Callback() { @Override @@ -643,6 +672,9 @@ public void runSql(String sql) { } private void deleteJoin(List objects, final RushQue que) { + if(isEmpty(objects)){ + return; + } statementRunner.startTransition(que); rushJoinStatementGenerator.deleteJoins(objects, new RushJoinStatementGenerator.Callback() { @Override @@ -654,4 +686,15 @@ public void runSql(String sql) { statementRunner.endTransition(que); queProvider.queComplete(que); } + + /** + * checks if the collection is null or empty and returns true if it is. + * @param collection + * @return + */ + private boolean isEmpty(Collection collection) {//I hesitated to use Apache Collections library or creating a util class with static method for this method + logger.log("Collection is null or empty, no action performed."); + return collection == null || collection.isEmpty(); + } } +