use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ModelUtil method findPreviousStatementsOfType.
public static <T extends DDLStatement> ArrayList<T> findPreviousStatementsOfType(final DDLStatement stmt, final Class<T> statementType, final boolean inclusive) {
ArrayList<T> list = new ArrayList<T>();
DatabaseBlock db = ModelUtil.<DatabaseBlock>getAncestorOfType(stmt, DatabaseBlock.class);
EList<MigrationBlock> _migrations = db.getMigrations();
for (final MigrationBlock migration : _migrations) {
EList<DDLStatement> _statements = migration.getStatements();
for (final DDLStatement ddl : _statements) {
{
if ((!inclusive)) {
boolean _equals = Objects.equal(ddl, stmt);
if (_equals) {
return list;
}
}
Class<? extends DDLStatement> _class = ddl.getClass();
boolean _isAssignableFrom = statementType.isAssignableFrom(_class);
if (_isAssignableFrom) {
list.add(((T) ddl));
}
boolean _equals_1 = Objects.equal(ddl, stmt);
if (_equals_1) {
return list;
}
}
}
}
InitBlock _ancestorOfType = ModelUtil.<InitBlock>getAncestorOfType(stmt, InitBlock.class);
boolean _notEquals = (!Objects.equal(_ancestorOfType, null));
if (_notEquals) {
InitBlock _init = db.getInit();
EList<DDLStatement> _statements_1 = _init.getStatements();
for (final DDLStatement ddl_1 : _statements_1) {
{
if ((!inclusive)) {
boolean _equals = Objects.equal(ddl_1, stmt);
if (_equals) {
return list;
}
}
Class<? extends DDLStatement> _class = ddl_1.getClass();
boolean _isAssignableFrom = statementType.isAssignableFrom(_class);
if (_isAssignableFrom) {
list.add(((T) ddl_1));
}
boolean _equals_1 = Objects.equal(ddl_1, stmt);
if (_equals_1) {
return list;
}
}
}
}
return list;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ModelUtil method getConfigInitTables.
public static Collection<CreateTableStatement> getConfigInitTables(final Model model) {
final ArrayList<CreateTableStatement> items = Lists.<CreateTableStatement>newArrayList();
DatabaseBlock _database = model.getDatabase();
InitBlock _init = _database.getInit();
boolean _notEquals = (!Objects.equal(_init, null));
if (_notEquals) {
DatabaseBlock _database_1 = model.getDatabase();
InitBlock _init_1 = _database_1.getInit();
EList<DDLStatement> _statements = _init_1.getStatements();
Iterable<CreateTableStatement> _filter = Iterables.<CreateTableStatement>filter(_statements, CreateTableStatement.class);
Iterables.<CreateTableStatement>addAll(items, _filter);
}
return items;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ModelUtil method findStatementsOfTypeBetween.
public static <T extends DDLStatement> ArrayList<T> findStatementsOfTypeBetween(final Class<T> statementType, final DDLStatement from, final DDLStatement to) {
ArrayList<T> list = new ArrayList<T>();
boolean between = false;
DatabaseBlock db = ModelUtil.<DatabaseBlock>getAncestorOfType(from, DatabaseBlock.class);
EList<MigrationBlock> _migrations = db.getMigrations();
for (final MigrationBlock migration : _migrations) {
EList<DDLStatement> _statements = migration.getStatements();
for (final DDLStatement ddl : _statements) {
{
boolean _equals = Objects.equal(ddl, to);
if (_equals) {
return list;
}
Class<? extends DDLStatement> _class = ddl.getClass();
boolean _isAssignableFrom = statementType.isAssignableFrom(_class);
if (_isAssignableFrom) {
if (between) {
list.add(((T) ddl));
}
}
boolean _equals_1 = Objects.equal(ddl, from);
if (_equals_1) {
between = true;
}
}
}
}
return list;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ModelImpl method basicSetDatabase.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetDatabase(DatabaseBlock newDatabase, NotificationChain msgs) {
DatabaseBlock oldDatabase = database;
database = newDatabase;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SqliteModelPackage.MODEL__DATABASE, oldDatabase, newDatabase);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ActiveRecordGenerator method generate.
public CharSequence generate(final Model model, final TableDefinition stmt) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/*");
_builder.newLine();
_builder.append(" ");
_builder.append("* Generated by Robotoworks Mechanoid");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("package ");
String _packageName = model.getPackageName();
_builder.append(_packageName, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import android.content.ContentResolver;");
_builder.newLine();
_builder.append("import android.database.Cursor;");
_builder.newLine();
_builder.append("import android.os.Bundle;");
_builder.newLine();
_builder.append("import android.os.Parcel;");
_builder.newLine();
_builder.append("import android.os.Parcelable;");
_builder.newLine();
_builder.append("import android.net.Uri;");
_builder.newLine();
_builder.append("import ");
String _packageName_1 = model.getPackageName();
_builder.append(_packageName_1, "");
_builder.append(".");
DatabaseBlock _database = model.getDatabase();
String _name = _database.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("Contract.");
String _name_1 = stmt.getName();
String _pascalize_1 = Strings.pascalize(_name_1);
_builder.append(_pascalize_1, "");
_builder.append(";");
_builder.newLineIfNotEmpty();
_builder.append("import ");
String _packageName_2 = model.getPackageName();
_builder.append(_packageName_2, "");
_builder.append(".");
DatabaseBlock _database_1 = model.getDatabase();
String _name_2 = _database_1.getName();
String _pascalize_2 = Strings.pascalize(_name_2);
_builder.append(_pascalize_2, "");
_builder.append("Contract.");
String _name_3 = stmt.getName();
String _pascalize_3 = Strings.pascalize(_name_3);
_builder.append(_pascalize_3, "");
_builder.append(".Builder;");
_builder.newLineIfNotEmpty();
_builder.append("import com.robotoworks.mechanoid.util.Closeables;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.db.ActiveRecord;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.db.ActiveRecordFactory;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.Mechanoid;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.db.AbstractValuesBuilder;");
_builder.newLine();
_builder.newLine();
_builder.append("public class ");
String _name_4 = stmt.getName();
String _pascalize_4 = Strings.pascalize(_name_4);
_builder.append(_pascalize_4, "");
_builder.append("Record extends ActiveRecord implements Parcelable {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("private static ActiveRecordFactory<");
String _name_5 = stmt.getName();
String _pascalize_5 = Strings.pascalize(_name_5);
_builder.append(_pascalize_5, "\t");
_builder.append("Record> sFactory = new ActiveRecordFactory<");
String _name_6 = stmt.getName();
String _pascalize_6 = Strings.pascalize(_name_6);
_builder.append(_pascalize_6, "\t");
_builder.append("Record>() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public ");
String _name_7 = stmt.getName();
String _pascalize_7 = Strings.pascalize(_name_7);
_builder.append(_pascalize_7, "\t\t");
_builder.append("Record create(Cursor c) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append("return fromCursor(c);");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t\t");
_builder.append("public String[] getProjection() {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("return PROJECTION;");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("public Uri getContentUri() {");
_builder.newLine();
_builder.append(" ");
_builder.append("return ");
String _name_8 = stmt.getName();
String _pascalize_8 = Strings.pascalize(_name_8);
_builder.append(_pascalize_8, " ");
_builder.append(".CONTENT_URI;");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("};");
_builder.newLine();
_builder.newLine();
_builder.append(" \t\t\t");
_builder.append("public static ActiveRecordFactory<");
String _name_9 = stmt.getName();
String _pascalize_9 = Strings.pascalize(_name_9);
_builder.append(_pascalize_9, " \t\t\t");
_builder.append("Record> getFactory() {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return sFactory;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("public static final Parcelable.Creator<");
String _name_10 = stmt.getName();
String _pascalize_10 = Strings.pascalize(_name_10);
_builder.append(_pascalize_10, " ");
_builder.append("Record> CREATOR ");
_builder.newLineIfNotEmpty();
_builder.append(" \t");
_builder.append("= new Parcelable.Creator<");
String _name_11 = stmt.getName();
String _pascalize_11 = Strings.pascalize(_name_11);
_builder.append(_pascalize_11, " \t");
_builder.append("Record>() {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("public ");
String _name_12 = stmt.getName();
String _pascalize_12 = Strings.pascalize(_name_12);
_builder.append(_pascalize_12, " ");
_builder.append("Record createFromParcel(Parcel in) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("return new ");
String _name_13 = stmt.getName();
String _pascalize_13 = Strings.pascalize(_name_13);
_builder.append(_pascalize_13, " ");
_builder.append("Record(in);");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append(" ");
_builder.append("public ");
String _name_14 = stmt.getName();
String _pascalize_14 = Strings.pascalize(_name_14);
_builder.append(_pascalize_14, " ");
_builder.append("Record[] newArray(int size) {");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("return new ");
String _name_15 = stmt.getName();
String _pascalize_15 = Strings.pascalize(_name_15);
_builder.append(_pascalize_15, " ");
_builder.append("Record[size];");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.append("};");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("public static String[] PROJECTION = {");
_builder.newLine();
_builder.append(" \t");
CharSequence _generateProjectionArrayMembers = this.generateProjectionArrayMembers(stmt);
_builder.append(_generateProjectionArrayMembers, " \t");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("};");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("public interface Indices {");
_builder.newLine();
_builder.append(" \t");
CharSequence _generateProjectionIndicesMembers = this.generateProjectionIndicesMembers(stmt);
_builder.append(_generateProjectionIndicesMembers, " \t");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
CharSequence _generateFields = this.generateFields(stmt);
_builder.append(_generateFields, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append(" ");
_builder.append("protected String[] _getProjection() {");
_builder.newLine();
_builder.append(" \t");
_builder.append("return PROJECTION;");
_builder.newLine();
_builder.append(" ");
_builder.append("}");
_builder.newLine();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
CharSequence _generateAccessors = this.generateAccessors(stmt);
_builder.append(_generateAccessors, " ");
_builder.newLineIfNotEmpty();
_builder.append(" ");
_builder.newLine();
_builder.append(" ");
_builder.append("public ");
String _name_16 = stmt.getName();
String _pascalize_16 = Strings.pascalize(_name_16);
_builder.append(_pascalize_16, " ");
_builder.append("Record() {");
_builder.newLineIfNotEmpty();
_builder.append(" \t");
_builder.append("super(");
String _name_17 = stmt.getName();
String _pascalize_17 = Strings.pascalize(_name_17);
_builder.append(_pascalize_17, " \t");
_builder.append(".CONTENT_URI);");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("private ");
String _name_18 = stmt.getName();
String _pascalize_18 = Strings.pascalize(_name_18);
_builder.append(_pascalize_18, "\t");
_builder.append("Record(Parcel in) {");
_builder.newLineIfNotEmpty();
_builder.append(" \t");
_builder.append("super(");
String _name_19 = stmt.getName();
String _pascalize_19 = Strings.pascalize(_name_19);
_builder.append(_pascalize_19, " \t");
_builder.append(".CONTENT_URI);");
_builder.newLineIfNotEmpty();
_builder.append(" \t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("setId(in.readLong());");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateParcelDeserializationStatements = this.generateParcelDeserializationStatements(stmt);
_builder.append(_generateParcelDeserializationStatements, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public int describeContents() {");
_builder.newLine();
_builder.append("\t ");
_builder.append("return 0;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void writeToParcel(Parcel dest, int flags) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("dest.writeLong(getId());");
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateParcelSerializationStatements = this.generateParcelSerializationStatements(stmt);
_builder.append(_generateParcelSerializationStatements, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected AbstractValuesBuilder createBuilder() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Builder builder = ");
String _name_20 = stmt.getName();
String _pascalize_20 = Strings.pascalize(_name_20);
_builder.append(_pascalize_20, "\t\t");
_builder.append(".newBuilder();");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateBuilderStatements = this.generateBuilderStatements(stmt);
_builder.append(_generateBuilderStatements, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return builder;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append(" ");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void makeDirty(boolean dirty){");
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateMakeDirtyStatements = this.generateMakeDirtyStatements(stmt);
_builder.append(_generateMakeDirtyStatements, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("protected void setPropertiesFromCursor(Cursor c) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("setId(c.getLong(Indices._ID));");
_builder.newLine();
_builder.append("\t\t");
CharSequence _generateSetFromCursorStatements = this.generateSetFromCursorStatements(stmt);
_builder.append(_generateSetFromCursorStatements, "\t\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static ");
String _name_21 = stmt.getName();
String _pascalize_21 = Strings.pascalize(_name_21);
_builder.append(_pascalize_21, "\t");
_builder.append("Record fromCursor(Cursor c) {");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
String _name_22 = stmt.getName();
String _pascalize_22 = Strings.pascalize(_name_22);
_builder.append(_pascalize_22, "\t ");
_builder.append("Record item = new ");
String _name_23 = stmt.getName();
String _pascalize_23 = Strings.pascalize(_name_23);
_builder.append(_pascalize_23, "\t ");
_builder.append("Record();");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.newLine();
_builder.append("\t\t");
_builder.append("item.setPropertiesFromCursor(c);");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t\t");
_builder.append("item.makeDirty(false);");
_builder.newLine();
_builder.append("\t\t");
_builder.newLine();
_builder.append("\t ");
_builder.append("return item;");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static ");
String _name_24 = stmt.getName();
String _pascalize_24 = Strings.pascalize(_name_24);
_builder.append(_pascalize_24, "\t");
_builder.append("Record fromBundle(Bundle bundle, String key) {");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("bundle.setClassLoader(");
String _name_25 = stmt.getName();
String _pascalize_25 = Strings.pascalize(_name_25);
_builder.append(_pascalize_25, "\t\t");
_builder.append("Record.class.getClassLoader());");
_builder.newLineIfNotEmpty();
_builder.append("\t\t");
_builder.append("return bundle.getParcelable(key);");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("public static ");
String _name_26 = stmt.getName();
String _pascalize_26 = Strings.pascalize(_name_26);
_builder.append(_pascalize_26, "\t");
_builder.append("Record get(long id) {");
_builder.newLineIfNotEmpty();
_builder.append("\t ");
_builder.append("Cursor c = null;");
_builder.newLine();
_builder.append("\t ");
_builder.newLine();
_builder.append("\t ");
_builder.append("ContentResolver resolver = Mechanoid.getContentResolver();");
_builder.newLine();
_builder.append("\t ");
_builder.newLine();
_builder.append("\t ");
_builder.append("try {");
_builder.newLine();
_builder.append("\t ");
_builder.append("c = resolver.query(");
String _name_27 = stmt.getName();
String _pascalize_27 = Strings.pascalize(_name_27);
_builder.append(_pascalize_27, "\t ");
_builder.append(".CONTENT_URI.buildUpon()");
_builder.newLineIfNotEmpty();
_builder.append("\t\t\t");
_builder.append(".appendPath(String.valueOf(id)).build(), PROJECTION, null, null, null);");
_builder.newLine();
_builder.append("\t ");
_builder.newLine();
_builder.append("\t ");
_builder.append("if(!c.moveToFirst()) {");
_builder.newLine();
_builder.append("\t ");
_builder.append("return null;");
_builder.newLine();
_builder.append("\t ");
_builder.append("}");
_builder.newLine();
_builder.append("\t ");
_builder.newLine();
_builder.append("\t ");
_builder.append("return fromCursor(c);");
_builder.newLine();
_builder.append("\t ");
_builder.append("} finally {");
_builder.newLine();
_builder.append("\t ");
_builder.append("Closeables.closeSilently(c);");
_builder.newLine();
_builder.append("\t ");
_builder.append("}");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
Aggregations