forked from agrosner/DBFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request agrosner#307 from Raizlabs/develop
Version 2.2.0
- Loading branch information
Showing
56 changed files
with
1,094 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...piler/src/main/java/com/raizlabs/android/dbflow/processor/writer/OneToManySaveWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.raizlabs.android.dbflow.processor.writer; | ||
|
||
import com.google.common.collect.Sets; | ||
import com.raizlabs.android.dbflow.processor.definition.OneToManyDefinition; | ||
import com.raizlabs.android.dbflow.processor.definition.TableDefinition; | ||
import com.raizlabs.android.dbflow.processor.utils.ModelUtils; | ||
import com.raizlabs.android.dbflow.processor.utils.WriterUtils; | ||
import com.squareup.javawriter.JavaWriter; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.lang.model.element.Modifier; | ||
|
||
/** | ||
* Description: Overrides the save, update, and insert methods if the {@link com.raizlabs.android.dbflow.annotation.OneToMany.Method#SAVE} is used. | ||
*/ | ||
public class OneToManySaveWriter implements FlowWriter { | ||
|
||
private final TableDefinition tableDefinition; | ||
private final boolean isModelContainerAdapter; | ||
|
||
public OneToManySaveWriter(TableDefinition tableDefinition, boolean isModelContainerAdapter) { | ||
this.tableDefinition = tableDefinition; | ||
this.isModelContainerAdapter = isModelContainerAdapter; | ||
} | ||
|
||
@Override | ||
public void write(JavaWriter javaWriter) throws IOException { | ||
|
||
boolean shouldWrite = false; | ||
for (OneToManyDefinition oneToManyDefinition : tableDefinition.oneToManyDefinitions) { | ||
if(oneToManyDefinition.isSave()) { | ||
shouldWrite = true; | ||
break; | ||
} | ||
} | ||
|
||
if(shouldWrite) { | ||
writeMethod("save", javaWriter); | ||
writeMethod("insert", javaWriter); | ||
writeMethod("update", javaWriter); | ||
} | ||
} | ||
|
||
private void writeMethod(final String methodName, JavaWriter javaWriter) { | ||
WriterUtils.emitOverriddenMethod(javaWriter, new FlowWriter() { | ||
@Override | ||
public void write(JavaWriter javaWriter) throws IOException { | ||
for (OneToManyDefinition oneToManyDefinition : tableDefinition.oneToManyDefinitions) { | ||
oneToManyDefinition.writeSave(javaWriter); | ||
} | ||
|
||
javaWriter.emitStatement("super.%1s(%1s)", methodName, ModelUtils.getVariable(isModelContainerAdapter)); | ||
} | ||
}, "void", methodName, Sets.newHashSet(Modifier.PUBLIC, Modifier.FINAL), tableDefinition.getModelClassName(), | ||
ModelUtils.getVariable(isModelContainerAdapter)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ndroidTest/java/com/raizlabs/android/dbflow/test/contentobserver/ContentObserverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/example/Ant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.raizlabs.android.dbflow.test.example; | ||
|
||
import com.raizlabs.android.dbflow.annotation.Column; | ||
import com.raizlabs.android.dbflow.annotation.ForeignKey; | ||
import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; | ||
import com.raizlabs.android.dbflow.annotation.PrimaryKey; | ||
import com.raizlabs.android.dbflow.annotation.Table; | ||
import com.raizlabs.android.dbflow.structure.BaseModel; | ||
import com.raizlabs.android.dbflow.structure.container.ForeignKeyContainer; | ||
|
||
/** | ||
* Description: | ||
*/ | ||
@Table(databaseName = ColonyDatabase.NAME) | ||
public class Ant extends BaseModel { | ||
|
||
@Column | ||
@PrimaryKey(autoincrement = true) | ||
long id; | ||
|
||
@Column | ||
String type; | ||
|
||
@Column | ||
boolean isMale; | ||
|
||
@Column | ||
@ForeignKey(references = {@ForeignKeyReference(columnName = "queen_id", | ||
columnType = Long.class, | ||
foreignColumnName = "id")}, | ||
saveForeignKeyModel = false) | ||
ForeignKeyContainer<Queen> queenForeignKeyContainer; | ||
|
||
public void associateQueen(Queen queen) { | ||
queenForeignKeyContainer = new ForeignKeyContainer<>(Queen.class); | ||
queenForeignKeyContainer.setModel(queen); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/example/Colony.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.raizlabs.android.dbflow.test.example; | ||
|
||
import com.raizlabs.android.dbflow.annotation.Column; | ||
import com.raizlabs.android.dbflow.annotation.PrimaryKey; | ||
import com.raizlabs.android.dbflow.annotation.Table; | ||
import com.raizlabs.android.dbflow.structure.BaseModel; | ||
|
||
/** | ||
* Description: | ||
*/ | ||
@Table(databaseName = ColonyDatabase.NAME) | ||
public class Colony extends BaseModel { | ||
|
||
@Column | ||
@PrimaryKey(autoincrement = true) | ||
long id; | ||
|
||
@Column | ||
String name; | ||
} |
14 changes: 14 additions & 0 deletions
14
DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/example/ColonyDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.raizlabs.android.dbflow.test.example; | ||
|
||
import com.raizlabs.android.dbflow.annotation.Database; | ||
|
||
/** | ||
* Description: | ||
*/ | ||
@Database(name = ColonyDatabase.NAME, version = ColonyDatabase.VERSION) | ||
public class ColonyDatabase { | ||
|
||
public static final String NAME = "Colonies"; | ||
|
||
public static final int VERSION = 1; | ||
} |
Oops, something went wrong.