Search in sources :

Example 1 with TableDefinition

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

Example 2 with TableDefinition

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

the class XSqliteModelScopeProvider method scopeForViewDefinitionsBeforeStatement.

public IScope scopeForViewDefinitionsBeforeStatement(final DDLStatement stmt, final boolean inclusive) {
    ArrayList<CreateViewStatement> refs = ModelUtil.<CreateViewStatement>findPreviousStatementsOfType(stmt, CreateViewStatement.class, inclusive);
    final HashMap<String, EObject> map = new HashMap<String, EObject>();
    List<CreateViewStatement> _reverse = ListExtensions.<CreateViewStatement>reverse(refs);
    for (final CreateViewStatement ref : _reverse) {
        {
            String _name = ref.getName();
            boolean _equals = Objects.equal(_name, null);
            if (_equals) {
                return IScope.NULLSCOPE;
            }
            String _name_1 = ref.getName();
            boolean _containsKey = map.containsKey(_name_1);
            boolean _not = (!_containsKey);
            if (_not) {
                String _name_2 = ref.getName();
                map.put(_name_2, ref);
            }
        }
    }
    Collection<EObject> _values = map.values();
    final Function<EObject, QualifiedName> _function = new Function<EObject, QualifiedName>() {

        public QualifiedName apply(final EObject it) {
            return NameHelper.getName(((TableDefinition) it));
        }
    };
    return Scopes.<EObject>scopeFor(_values, _function, IScope.NULLSCOPE);
}
Also used : Function(com.google.common.base.Function) CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) HashMap(java.util.HashMap) EObject(org.eclipse.emf.ecore.EObject) QualifiedName(org.eclipse.xtext.naming.QualifiedName) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)

Example 3 with TableDefinition

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

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

the class StatementSequenceValidator method _sequence.

protected void _sequence(final DropTableStatement stmt) {
    TableDefinition _table = stmt.getTable();
    String _name = _table.getName();
    this.tables.remove(_name);
}
Also used : TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)

Example 5 with TableDefinition

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

the class StatementSequenceValidator method validateTablesInExpression.

public void validateTablesInExpression(final StatementSequenceValidatorResult result, final SelectCoreExpression expr) {
    ArrayList<EObject> sources = ModelUtil.getAllReferenceableSingleSources(expr);
    for (final EObject source : sources) {
        if ((source instanceof SingleSourceTable)) {
            SingleSourceTable table = ((SingleSourceTable) source);
            TableDefinition _tableReference = table.getTableReference();
            String _name = _tableReference.getName();
            boolean _sourceExists = this.sourceExists(_name);
            boolean _not = (!_sourceExists);
            if (_not) {
                result.source = table;
                result.valid = false;
                result.message = "No such reference";
                result.feature = SqliteModelPackage.Literals.SINGLE_SOURCE_TABLE__TABLE_REFERENCE;
                return;
            }
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) SingleSourceTable(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)

Aggregations

TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)33 EObject (org.eclipse.emf.ecore.EObject)16 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)9 DDLStatement (com.robotoworks.mechanoid.db.sqliteModel.DDLStatement)7 SingleSourceTable (com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable)5 Function (com.google.common.base.Function)3 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)3 HashMap (java.util.HashMap)3 QualifiedName (org.eclipse.xtext.naming.QualifiedName)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 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)2 CreateTriggerStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTriggerStatement)2 Consumer (java.util.function.Consumer)2 AlterTableRenameStatement (com.robotoworks.mechanoid.db.sqliteModel.AlterTableRenameStatement)1 ColumnDef (com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)1 ResultColumn (com.robotoworks.mechanoid.db.sqliteModel.ResultColumn)1 SelectCoreExpression (com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression)1 SelectList (com.robotoworks.mechanoid.db.sqliteModel.SelectList)1