Search in sources :

Example 1 with AlterTableAddColumnStatement

use of com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement 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)

Example 2 with AlterTableAddColumnStatement

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

the class SqliteModelProposalProvider method getDisplayString.

@Override
protected String getDisplayString(EObject element, String qualifiedNameAsString, String shortName) {
    if (element instanceof ColumnDef) {
        ColumnDef def = (ColumnDef) element;
        EObject container = def.eContainer();
        if (container instanceof TableDefinition) {
            return def.getName() + ":" + def.getType().getName() + " - " + ((TableDefinition) def.eContainer()).getName();
        } else if (container instanceof AlterTableAddColumnStatement) {
            return def.getName() + ":" + def.getType().getName() + " - " + ((AlterTableAddColumnStatement) def.eContainer()).getTable().getName();
        } else {
            return def.getName() + ":" + def.getType().getName();
        }
    } else if (element instanceof SingleSourceTable) {
        SingleSourceTable t = (SingleSourceTable) element;
        return (t.getName() == null ? t.getTableReference().getName() : t.getName() + " - " + t.getTableReference().getName());
    } else if (element instanceof CreateTableStatement) {
        CreateTableStatement t = (CreateTableStatement) element;
        return t.getName();
    } else if (element instanceof ResultColumn) {
        ResultColumn r = (ResultColumn) element;
        if (r.getName() != null) {
            return r.getName() + ":" + ModelUtil.getInferredColumnType(r).getName();
        }
    }
    return super.getDisplayString(element, qualifiedNameAsString, shortName);
}
Also used : AlterTableAddColumnStatement(com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement) EObject(org.eclipse.emf.ecore.EObject) CreateTableStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement) ResultColumn(com.robotoworks.mechanoid.db.sqliteModel.ResultColumn) ColumnDef(com.robotoworks.mechanoid.db.sqliteModel.ColumnDef) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition) SingleSourceTable(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable)

Aggregations

AlterTableAddColumnStatement (com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement)2 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)2 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)2 EObject (org.eclipse.emf.ecore.EObject)2 ColumnDef (com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)1 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)1 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)1 ResultColumn (com.robotoworks.mechanoid.db.sqliteModel.ResultColumn)1 SingleSourceTable (com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable)1 ArrayList (java.util.ArrayList)1 Consumer (java.util.function.Consumer)1 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)1