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;
}
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;
}
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;
}
Aggregations