Search in sources :

Example 11 with ColumnSource

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

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

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

the class OldColumnImpl method setColumn.

/**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
public void setColumn(ColumnSource newColumn) {
    ColumnSource oldColumn = column;
    column = newColumn;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, SqliteModelPackage.OLD_COLUMN__COLUMN, oldColumn, column));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 14 with ColumnSource

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

the class ColumnSourceRefImpl method setColumn.

/**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
public void setColumn(ColumnSource newColumn) {
    ColumnSource oldColumn = column;
    column = newColumn;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, SqliteModelPackage.COLUMN_SOURCE_REF__COLUMN, oldColumn, column));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 15 with ColumnSource

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

the class NewColumnImpl method setColumn.

/**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
public void setColumn(ColumnSource newColumn) {
    ColumnSource oldColumn = column;
    column = newColumn;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, SqliteModelPackage.NEW_COLUMN__COLUMN, oldColumn, column));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Aggregations

ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)21 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)13 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)12 ColumnType (com.robotoworks.mechanoid.db.sqliteModel.ColumnType)8 ResultColumn (com.robotoworks.mechanoid.db.sqliteModel.ResultColumn)5 EList (org.eclipse.emf.common.util.EList)5 ColumnDef (com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)4 ArrayList (java.util.ArrayList)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)2 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)2 SelectCoreExpression (com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression)2 SelectExpression (com.robotoworks.mechanoid.db.sqliteModel.SelectExpression)2 SelectList (com.robotoworks.mechanoid.db.sqliteModel.SelectList)2 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)2 Consumer (java.util.function.Consumer)2 EObject (org.eclipse.emf.ecore.EObject)2 AlterTableAddColumnStatement (com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement)1 CastExpression (com.robotoworks.mechanoid.db.sqliteModel.CastExpression)1 ColumnSourceRef (com.robotoworks.mechanoid.db.sqliteModel.ColumnSourceRef)1