Search in sources :

Example 1 with DDLStatement

use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement 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;
}
Also used : DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) InitBlock(com.robotoworks.mechanoid.db.sqliteModel.InitBlock) ArrayList(java.util.ArrayList) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)

Example 2 with DDLStatement

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

Example 3 with DDLStatement

use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.

the class ModelUtil method findPreviousStatementsOfType.

public static <T extends DDLStatement> ArrayList<T> findPreviousStatementsOfType(final DatabaseBlock db, final DDLStatement stmt, final Class<T> statementType, final boolean inclusive) {
    ArrayList<T> list = new ArrayList<T>();
    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 _init = db.getInit();
    boolean _notEquals = (!Objects.equal(_init, null));
    if (_notEquals) {
        InitBlock _init_1 = db.getInit();
        EList<DDLStatement> _statements_1 = _init_1.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;
}
Also used : DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) InitBlock(com.robotoworks.mechanoid.db.sqliteModel.InitBlock) ArrayList(java.util.ArrayList) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)

Example 4 with DDLStatement

use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement 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;
}
Also used : DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) ArrayList(java.util.ArrayList) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)

Example 5 with DDLStatement

use of com.robotoworks.mechanoid.db.sqliteModel.DDLStatement in project mechanoid by robotoworks.

the class XSqliteModelScopeProvider method scope_InsertStatement_columnNames.

public IScope scope_InsertStatement_columnNames(final InsertStatement context, final EReference reference) {
    DDLStatement stmt = ModelUtil.<DDLStatement>getAncestorOfType(context, DDLStatement.class);
    TableDefinition _table = context.getTable();
    ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(stmt, _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)

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