Search in sources :

Example 1 with SingleSourceTable

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

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

Example 3 with SingleSourceTable

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

the class XSqliteModelScopeProvider method scope_ColumnSourceRef_column.

public IScope scope_ColumnSourceRef_column(final ColumnSourceRef context, final EReference reference) {
    SelectSource _source = context.getSource();
    boolean _equals = Objects.equal(_source, null);
    if (_equals) {
        IScope scope = this.buildScopeForColumnSourceRef_column(context, context);
        return scope;
    } else {
        SelectSource _source_1 = context.getSource();
        if ((_source_1 instanceof SingleSourceTable)) {
            SelectSource _source_2 = context.getSource();
            SingleSourceTable tableSource = ((SingleSourceTable) _source_2);
            DDLStatement _ancestorOfType = ModelUtil.<DDLStatement>getAncestorOfType(tableSource, DDLStatement.class);
            TableDefinition _tableReference = tableSource.getTableReference();
            ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(_ancestorOfType, _tableReference);
            return Scopes.scopeFor(_findColumnDefs);
        } else {
            SelectSource _source_3 = context.getSource();
            if ((_source_3 instanceof SingleSourceSelectStatement)) {
                SelectSource _source_4 = context.getSource();
                SingleSourceSelectStatement selectStmtSource = ((SingleSourceSelectStatement) _source_4);
                SelectStatement _selectStatement = selectStmtSource.getSelectStatement();
                SelectCoreExpression _core = _selectStatement.getCore();
                ArrayList<EObject> _allReferenceableColumns = ModelUtil.getAllReferenceableColumns(_core);
                return Scopes.scopeFor(_allReferenceableColumns);
            }
        }
    }
    return IScope.NULLSCOPE;
}
Also used : SelectStatement(com.robotoworks.mechanoid.db.sqliteModel.SelectStatement) SingleSourceSelectStatement(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceSelectStatement) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) SingleSourceSelectStatement(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceSelectStatement) SelectCoreExpression(com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) SingleSourceTable(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition) SelectSource(com.robotoworks.mechanoid.db.sqliteModel.SelectSource)

Example 4 with SingleSourceTable

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

the class ModelUtil method getAllReferenceableColumns.

public static ArrayList<EObject> getAllReferenceableColumns(final SelectExpression expr, final boolean includeAliases) {
    final ArrayList<EObject> items = Lists.<EObject>newArrayList();
    boolean _and = false;
    SelectList _selectList = expr.getSelectList();
    boolean _notEquals = (!Objects.equal(_selectList, null));
    if (!_notEquals) {
        _and = false;
    } else {
        _and = includeAliases;
    }
    if (_and) {
        SelectList _selectList_1 = expr.getSelectList();
        EList<ColumnSource> _resultColumns = _selectList_1.getResultColumns();
        final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {

            public Boolean apply(final ColumnSource it) {
                String _name = it.getName();
                return Boolean.valueOf((!Objects.equal(_name, null)));
            }
        };
        Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(_resultColumns, _function);
        Iterables.<EObject>addAll(items, _filter);
    }
    ArrayList<SingleSource> _findAllSingleSources = ModelUtil.findAllSingleSources(expr);
    final Function1<SingleSource, Boolean> _function_1 = new Function1<SingleSource, Boolean>() {

        public Boolean apply(final SingleSource item) {
            if ((item instanceof SingleSourceTable)) {
                String _name = ((SingleSourceTable) item).getName();
                return Boolean.valueOf(Objects.equal(_name, null));
            }
            return Boolean.valueOf(false);
        }
    };
    Iterable<SingleSource> _filter_1 = IterableExtensions.<SingleSource>filter(_findAllSingleSources, _function_1);
    final Consumer<SingleSource> _function_2 = new Consumer<SingleSource>() {

        public void accept(final SingleSource item) {
            SingleSourceTable source = ((SingleSourceTable) item);
            DDLStatement _ancestorOfType = ModelUtil.<DDLStatement>getAncestorOfType(item, DDLStatement.class);
            TableDefinition _tableReference = source.getTableReference();
            ArrayList<EObject> _findColumnDefs = ModelUtil.findColumnDefs(_ancestorOfType, _tableReference);
            items.addAll(_findColumnDefs);
        }
    };
    _filter_1.forEach(_function_2);
    return items;
}
Also used : SelectList(com.robotoworks.mechanoid.db.sqliteModel.SelectList) SingleSource(com.robotoworks.mechanoid.db.sqliteModel.SingleSource) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) SingleSourceTable(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable) 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 5 with SingleSourceTable

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

the class ModelUtil method isDefinitionReferencedByView.

public static boolean isDefinitionReferencedByView(final TableDefinition tableDef, final CreateViewStatement view) {
    TreeIterator<EObject> _eAllContents = view.eAllContents();
    final Function1<EObject, Boolean> _function = new Function1<EObject, Boolean>() {

        public Boolean apply(final EObject obj) {
            if ((obj instanceof SingleSourceTable)) {
                SingleSourceTable sourceTable = ((SingleSourceTable) obj);
                TableDefinition _tableReference = sourceTable.getTableReference();
                if ((!(_tableReference instanceof CreateViewStatement))) {
                    TableDefinition _tableReference_1 = sourceTable.getTableReference();
                    String _name = _tableReference_1.getName();
                    String _name_1 = tableDef.getName();
                    boolean _equals = _name.equals(_name_1);
                    if (_equals) {
                        return Boolean.valueOf(true);
                    }
                } else {
                    TableDefinition _tableReference_2 = sourceTable.getTableReference();
                    return Boolean.valueOf(ModelUtil.isDefinitionReferencedByView(tableDef, ((CreateViewStatement) _tableReference_2)));
                }
            }
            return Boolean.valueOf(false);
        }
    };
    return IteratorExtensions.<EObject>exists(_eAllContents, _function);
}
Also used : CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) EObject(org.eclipse.emf.ecore.EObject) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) SingleSourceTable(com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable) TableDefinition(com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)

Aggregations

SingleSourceTable (com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable)5 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)5 EObject (org.eclipse.emf.ecore.EObject)5 DDLStatement (com.robotoworks.mechanoid.db.sqliteModel.DDLStatement)2 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)2 AlterTableAddColumnStatement (com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement)1 ColumnDef (com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)1 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)1 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)1 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)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 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 Consumer (java.util.function.Consumer)1 IScope (org.eclipse.xtext.scoping.IScope)1