Search in sources :

Example 6 with CreateTableStatement

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

the class SqliteDatabaseSnapshot method containsDefinition.

public boolean containsDefinition(final String name) {
    CreateTableStatement tableStmt = IterableExtensions.findFirst(mTables, new Function1<CreateTableStatement, Boolean>() {

        @Override
        public Boolean apply(CreateTableStatement p) {
            return p.getName().equals(name);
        }
    });
    if (tableStmt != null) {
        return true;
    }
    CreateViewStatement viewStmt = IterableExtensions.findFirst(mViews, new Function1<CreateViewStatement, Boolean>() {

        @Override
        public Boolean apply(CreateViewStatement p) {
            return p.getName().equals(name);
        }
    });
    if (viewStmt != null) {
        return true;
    }
    return false;
}
Also used : CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) CreateTableStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)

Example 7 with CreateTableStatement

use of com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement 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 8 with CreateTableStatement

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

the class ModelUtil method findColumnDefs.

/**
   * Find column definitions from caller going back to the definition
   */
public static ArrayList<EObject> findColumnDefs(final DDLStatement caller, final TableDefinition definition) {
    final ArrayList<EObject> columns = new ArrayList<EObject>();
    LinkedList<TableDefinition> tableHistory = ModelUtil.getHistory(definition);
    TableDefinition last = tableHistory.peekLast();
    if ((last instanceof CreateViewStatement)) {
        CreateViewStatement view = ((CreateViewStatement) last);
        ArrayList<ColumnSource> _viewResultColumns = ModelUtil.getViewResultColumns(view);
        columns.addAll(_viewResultColumns);
        return columns;
    }
    EList<ColumnSource> _columnDefs = ((CreateTableStatement) last).getColumnDefs();
    columns.addAll(_columnDefs);
    while ((!tableHistory.isEmpty())) {
        {
            final TableDefinition stmt = tableHistory.removeLast();
            ArrayList<AlterTableAddColumnStatement> _findStatementsOfTypeBetween = ModelUtil.<AlterTableAddColumnStatement>findStatementsOfTypeBetween(AlterTableAddColumnStatement.class, stmt, caller);
            final Function1<AlterTableAddColumnStatement, Boolean> _function = new Function1<AlterTableAddColumnStatement, Boolean>() {

                public Boolean apply(final AlterTableAddColumnStatement it) {
                    TableDefinition _table = it.getTable();
                    return Boolean.valueOf(Objects.equal(_table, stmt));
                }
            };
            Iterable<AlterTableAddColumnStatement> _filter = IterableExtensions.<AlterTableAddColumnStatement>filter(_findStatementsOfTypeBetween, _function);
            final Consumer<AlterTableAddColumnStatement> _function_1 = new Consumer<AlterTableAddColumnStatement>() {

                public void accept(final AlterTableAddColumnStatement it) {
                    ColumnSource _columnDef = it.getColumnDef();
                    columns.add(_columnDef);
                }
            };
            _filter.forEach(_function_1);
        }
    }
    return columns;
}
Also used : CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) CreateTableStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement) ArrayList(java.util.ArrayList) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) AlterTableAddColumnStatement(com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement) Consumer(java.util.function.Consumer) EObject(org.eclipse.emf.ecore.EObject) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Aggregations

CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)8 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)6 DatabaseBlock (com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock)5 Collection (java.util.Collection)3 EObject (org.eclipse.emf.ecore.EObject)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 AlterTableAddColumnStatement (com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement)2 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)2 InitBlock (com.robotoworks.mechanoid.db.sqliteModel.InitBlock)2 MigrationBlock (com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)2 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)2 ArrayList (java.util.ArrayList)2 Consumer (java.util.function.Consumer)2 EList (org.eclipse.emf.common.util.EList)2 SqliteDatabaseSnapshot (com.robotoworks.mechanoid.db.generator.SqliteDatabaseSnapshot)1 ActionStatement (com.robotoworks.mechanoid.db.sqliteModel.ActionStatement)1 ColumnDef (com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)1 ConfigBlock (com.robotoworks.mechanoid.db.sqliteModel.ConfigBlock)1 ConfigurationStatement (com.robotoworks.mechanoid.db.sqliteModel.ConfigurationStatement)1