Search in sources :

Example 11 with DDLStatement

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);
}
Also used : DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) EObject(org.eclipse.emf.ecore.EObject) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)

Example 12 with DDLStatement

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);
}
Also used : DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) EObject(org.eclipse.emf.ecore.EObject) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)

Example 13 with DDLStatement

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);
}
Also used : DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement)

Example 14 with DDLStatement

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)));
}
Also used : EList(org.eclipse.emf.common.util.EList) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) EObject(org.eclipse.emf.ecore.EObject) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)

Example 15 with DDLStatement

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;
}
Also used : DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

DDLStatement (com.robotoworks.mechanoid.db.sqliteModel.DDLStatement)16 EObject (org.eclipse.emf.ecore.EObject)8 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)7 DatabaseBlock (com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock)6 MigrationBlock (com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)5 InitBlock (com.robotoworks.mechanoid.db.sqliteModel.InitBlock)4 ArrayList (java.util.ArrayList)3 SingleSourceTable (com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable)2 EList (org.eclipse.emf.common.util.EList)2 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)1 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)1 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)1 SelectCoreExpression (com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression)1 SelectList (com.robotoworks.mechanoid.db.sqliteModel.SelectList)1 SelectSource (com.robotoworks.mechanoid.db.sqliteModel.SelectSource)1 SelectStatement (com.robotoworks.mechanoid.db.sqliteModel.SelectStatement)1 SingleSource (com.robotoworks.mechanoid.db.sqliteModel.SingleSource)1 SingleSourceSelectStatement (com.robotoworks.mechanoid.db.sqliteModel.SingleSourceSelectStatement)1 UpdateStatement (com.robotoworks.mechanoid.db.sqliteModel.UpdateStatement)1 StatementSequenceValidatorResult (com.robotoworks.mechanoid.db.validation.StatementSequenceValidatorResult)1