use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.
the class XSqliteModelScopeProvider method scope_UpdateColumnExpression_columnName.
public IScope scope_UpdateColumnExpression_columnName(final UpdateStatement context, final EReference reference) {
DDLStatement containingStmt = ModelUtil.<DDLStatement>getAncestorOfType(context, DDLStatement.class);
TableDefinition _table = context.getTable();
ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(containingStmt, _table);
return Scopes.scopeFor(_findColumnDefs, IScope.NULLSCOPE);
}
use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.
the class XSqliteModelScopeProvider method scope_ColumnSourceRef_source.
public IScope scope_ColumnSourceRef_source(final DeleteStatement context, final EReference reference) {
DDLStatement ddl = ModelUtil.<DDLStatement>getAncestorOfType(context, DDLStatement.class);
TableDefinition _table = context.getTable();
ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(ddl, _table);
return Scopes.scopeFor(_findColumnDefs, IScope.NULLSCOPE);
}
use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.
the class XSqliteModelScopeProvider method scope_SingleSourceTable_tableReference.
public IScope scope_SingleSourceTable_tableReference(final SingleSourceTable tbl, final EReference reference) {
DDLStatement stmt = ModelUtil.<DDLStatement>getAncestorOfType(tbl, DDLStatement.class);
boolean _notEquals = (!Objects.equal(stmt, null));
if (_notEquals) {
return this.scopeForTableDefinitionsBeforeStatement(stmt, false);
}
DatabaseBlock db = ModelUtil.<DatabaseBlock>getAncestorOfType(tbl, DatabaseBlock.class);
return this.scopeForTableDefinitionsBeforeStatement(db, stmt, true);
}
use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.
the class ModelUtil method forEachPreviousStatement.
/**
* walks back and visits each previous statement from the given statement, returning
* false will cancel the process
*/
public static void forEachPreviousStatement(final DDLStatement stmt, final Function1<DDLStatement, Boolean> delegate) {
EObject current = ((EObject) stmt);
MigrationBlock migration = null;
do {
{
while ((!Objects.equal(EcoreUtil2.getPreviousSibling(current), null))) {
{
EObject _previousSibling = EcoreUtil2.getPreviousSibling(current);
current = _previousSibling;
Boolean _apply = delegate.apply(((DDLStatement) current));
boolean _not = (!(_apply).booleanValue());
if (_not) {
return;
}
}
}
EObject _eContainer = current.eContainer();
EObject previousContainer = EcoreUtil2.getPreviousSibling(_eContainer);
boolean _and = false;
boolean _notEquals = (!Objects.equal(previousContainer, null));
if (!_notEquals) {
_and = false;
} else {
_and = (previousContainer instanceof MigrationBlock);
}
if (_and) {
migration = ((MigrationBlock) previousContainer);
EList<DDLStatement> _statements = migration.getStatements();
DDLStatement _last = IterableExtensions.<DDLStatement>last(_statements);
current = _last;
boolean _equals = Objects.equal(current, null);
if (_equals) {
return;
}
Boolean _apply = delegate.apply(((DDLStatement) current));
boolean _not = (!(_apply).booleanValue());
if (_not) {
return;
}
} else {
migration = null;
}
}
} while ((!Objects.equal(migration, null)));
}
use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.
the class SqliteMigrationGenerator method generate.
public CharSequence generate(final Model model, final MigrationBlock migration, final int version) {
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(".migrations;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import android.database.sqlite.SQLiteDatabase;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.db.SQLiteMigration;");
_builder.newLine();
_builder.newLine();
_builder.append("public class Default");
DatabaseBlock _database = model.getDatabase();
String _name = _database.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("MigrationV");
_builder.append(version, "");
_builder.append(" extends SQLiteMigration {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void onBeforeUp(SQLiteDatabase db) {}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void up(SQLiteDatabase db) {");
_builder.newLine();
_builder.append("\t\t");
EList<DDLStatement> _statements = migration.getStatements();
CharSequence _generateStatements = this._sqliteDatabaseStatementGenerator.generateStatements(_statements);
_builder.append(_generateStatements, "\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 void onAfterUp(SQLiteDatabase db) {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
Aggregations