Search in sources :

Example 1 with ColumnDef

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

the class IndexedColumnImpl method setColumnReference.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setColumnReference(ColumnDef newColumnReference) {
    ColumnDef oldColumnReference = columnReference;
    columnReference = newColumnReference;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, SqliteModelPackage.INDEXED_COLUMN__COLUMN_REFERENCE, oldColumnReference, columnReference));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ColumnDef(com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)

Example 2 with ColumnDef

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

the class UpdateColumnExpressionImpl method setColumnName.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setColumnName(ColumnDef newColumnName) {
    ColumnDef oldColumnName = columnName;
    columnName = newColumnName;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, SqliteModelPackage.UPDATE_COLUMN_EXPRESSION__COLUMN_NAME, oldColumnName, columnName));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ColumnDef(com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)

Example 3 with ColumnDef

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

the class ModelUtil method getInferredColumnType.

public static ColumnType getInferredColumnType(final ResultColumn col) {
    Expression expr = col.getExpression();
    boolean _matched = false;
    if (!_matched) {
        if (expr instanceof CastExpression) {
            _matched = true;
            SqliteDataType _type = ((CastExpression) expr).getType();
            return ModelUtil.toColumnType(_type);
        }
    }
    if (!_matched) {
        if (expr instanceof ColumnSourceRef) {
            _matched = true;
            ColumnSource _column = ((ColumnSourceRef) expr).getColumn();
            if ((_column instanceof ResultColumn)) {
                ColumnSource _column_1 = ((ColumnSourceRef) expr).getColumn();
                ColumnType _inferredColumnType = ModelUtil.getInferredColumnType(((ResultColumn) _column_1));
                return ((ColumnType) _inferredColumnType);
            } else {
                ColumnSource _column_2 = ((ColumnSourceRef) expr).getColumn();
                return ((ColumnDef) _column_2).getType();
            }
        }
    }
    if (!_matched) {
        if (expr instanceof ExprConcat) {
            _matched = true;
            return ColumnType.TEXT;
        }
    }
    if (!_matched) {
        if (expr instanceof Function) {
            _matched = true;
            boolean _or = false;
            boolean _or_1 = false;
            boolean _or_2 = false;
            boolean _or_3 = false;
            boolean _or_4 = false;
            String _name = ((Function) expr).getName();
            boolean _equalsIgnoreCase = _name.equalsIgnoreCase("count");
            if (_equalsIgnoreCase) {
                _or_4 = true;
            } else {
                String _name_1 = ((Function) expr).getName();
                boolean _equalsIgnoreCase_1 = _name_1.equalsIgnoreCase("length");
                _or_4 = _equalsIgnoreCase_1;
            }
            if (_or_4) {
                _or_3 = true;
            } else {
                String _name_2 = ((Function) expr).getName();
                boolean _equalsIgnoreCase_2 = _name_2.equalsIgnoreCase("random");
                _or_3 = _equalsIgnoreCase_2;
            }
            if (_or_3) {
                _or_2 = true;
            } else {
                String _name_3 = ((Function) expr).getName();
                boolean _equalsIgnoreCase_3 = _name_3.equalsIgnoreCase("last_insert_rowid");
                _or_2 = _equalsIgnoreCase_3;
            }
            if (_or_2) {
                _or_1 = true;
            } else {
                String _name_4 = ((Function) expr).getName();
                boolean _equalsIgnoreCase_4 = _name_4.equalsIgnoreCase("changes");
                _or_1 = _equalsIgnoreCase_4;
            }
            if (_or_1) {
                _or = true;
            } else {
                String _name_5 = ((Function) expr).getName();
                boolean _equalsIgnoreCase_5 = _name_5.equalsIgnoreCase("total_changes");
                _or = _equalsIgnoreCase_5;
            }
            if (_or) {
                return ColumnType.INTEGER;
            } else {
                boolean _or_5 = false;
                boolean _or_6 = false;
                boolean _or_7 = false;
                boolean _or_8 = false;
                boolean _or_9 = false;
                String _name_6 = ((Function) expr).getName();
                boolean _equalsIgnoreCase_6 = _name_6.equalsIgnoreCase("abs");
                if (_equalsIgnoreCase_6) {
                    _or_9 = true;
                } else {
                    String _name_7 = ((Function) expr).getName();
                    boolean _equalsIgnoreCase_7 = _name_7.equalsIgnoreCase("avg");
                    _or_9 = _equalsIgnoreCase_7;
                }
                if (_or_9) {
                    _or_8 = true;
                } else {
                    String _name_8 = ((Function) expr).getName();
                    boolean _equalsIgnoreCase_8 = _name_8.equalsIgnoreCase("round");
                    _or_8 = _equalsIgnoreCase_8;
                }
                if (_or_8) {
                    _or_7 = true;
                } else {
                    String _name_9 = ((Function) expr).getName();
                    boolean _equalsIgnoreCase_9 = _name_9.equalsIgnoreCase("sum");
                    _or_7 = _equalsIgnoreCase_9;
                }
                if (_or_7) {
                    _or_6 = true;
                } else {
                    String _name_10 = ((Function) expr).getName();
                    boolean _equalsIgnoreCase_10 = _name_10.equalsIgnoreCase("total");
                    _or_6 = _equalsIgnoreCase_10;
                }
                if (_or_6) {
                    _or_5 = true;
                } else {
                    String _name_11 = ((Function) expr).getName();
                    boolean _equalsIgnoreCase_11 = _name_11.equalsIgnoreCase("likelihood");
                    _or_5 = _equalsIgnoreCase_11;
                }
                if (_or_5) {
                    return ColumnType.REAL;
                } else {
                    boolean _or_10 = false;
                    String _name_12 = ((Function) expr).getName();
                    boolean _equalsIgnoreCase_12 = _name_12.equalsIgnoreCase("randomblob");
                    if (_equalsIgnoreCase_12) {
                        _or_10 = true;
                    } else {
                        String _name_13 = ((Function) expr).getName();
                        boolean _equalsIgnoreCase_13 = _name_13.equalsIgnoreCase("zeroblob");
                        _or_10 = _equalsIgnoreCase_13;
                    }
                    if (_or_10) {
                        return ColumnType.BLOB;
                    }
                }
            }
            return ColumnType.TEXT;
        }
    }
    return ColumnType.TEXT;
}
Also used : SqliteDataType(com.robotoworks.mechanoid.db.sqliteModel.SqliteDataType) ColumnSourceRef(com.robotoworks.mechanoid.db.sqliteModel.ColumnSourceRef) Function(com.robotoworks.mechanoid.db.sqliteModel.Function) ColumnType(com.robotoworks.mechanoid.db.sqliteModel.ColumnType) ExprConcat(com.robotoworks.mechanoid.db.sqliteModel.ExprConcat) SelectCoreExpression(com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression) SelectExpression(com.robotoworks.mechanoid.db.sqliteModel.SelectExpression) Expression(com.robotoworks.mechanoid.db.sqliteModel.Expression) CastExpression(com.robotoworks.mechanoid.db.sqliteModel.CastExpression) ResultColumn(com.robotoworks.mechanoid.db.sqliteModel.ResultColumn) ColumnDef(com.robotoworks.mechanoid.db.sqliteModel.ColumnDef) CastExpression(com.robotoworks.mechanoid.db.sqliteModel.CastExpression) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 4 with ColumnDef

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

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

the class ActiveRecordGenerator method _generateSetFromCursorStatements.

protected CharSequence _generateSetFromCursorStatements(final CreateTableStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    {
        EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
        final Function1<ColumnSource, Boolean> _function = new Function1<ColumnSource, Boolean>() {

            public Boolean apply(final ColumnSource it) {
                String _name = it.getName();
                boolean _equals = _name.equals("_id");
                return Boolean.valueOf((!_equals));
            }
        };
        Iterable<ColumnSource> _filter = IterableExtensions.<ColumnSource>filter(_columnDefs, _function);
        for (final ColumnSource item : _filter) {
            ColumnDef col = ((ColumnDef) item);
            _builder.newLineIfNotEmpty();
            {
                ColumnType _type = col.getType();
                boolean _equals = Objects.equal(_type, ColumnType.BOOLEAN);
                if (_equals) {
                    _builder.append("set");
                    String _name = col.getName();
                    String _pascalize = Strings.pascalize(_name);
                    _builder.append(_pascalize, "");
                    _builder.append("(c.getInt(Indices.");
                    String _name_1 = col.getName();
                    String _underscore = Strings.underscore(_name_1);
                    String _upperCase = _underscore.toUpperCase();
                    _builder.append(_upperCase, "");
                    _builder.append(") > 0);");
                    _builder.newLineIfNotEmpty();
                } else {
                    ColumnType _type_1 = col.getType();
                    boolean _equals_1 = Objects.equal(_type_1, ColumnType.BLOB);
                    if (_equals_1) {
                        _builder.append("set");
                        String _name_2 = col.getName();
                        String _pascalize_1 = Strings.pascalize(_name_2);
                        _builder.append(_pascalize_1, "");
                        _builder.append("(c.getBlob(Indices.");
                        String _name_3 = col.getName();
                        String _underscore_1 = Strings.underscore(_name_3);
                        String _upperCase_1 = _underscore_1.toUpperCase();
                        _builder.append(_upperCase_1, "");
                        _builder.append("));");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("set");
                        String _name_4 = col.getName();
                        String _pascalize_2 = Strings.pascalize(_name_4);
                        _builder.append(_pascalize_2, "");
                        _builder.append("(c.get");
                        ColumnType _type_2 = col.getType();
                        String _javaTypeName = ModelUtil.toJavaTypeName(_type_2);
                        String _pascalize_3 = Strings.pascalize(_javaTypeName);
                        _builder.append(_pascalize_3, "");
                        _builder.append("(Indices.");
                        String _name_5 = col.getName();
                        String _underscore_2 = Strings.underscore(_name_5);
                        String _upperCase_2 = _underscore_2.toUpperCase();
                        _builder.append(_upperCase_2, "");
                        _builder.append("));");
                        _builder.newLineIfNotEmpty();
                    }
                }
            }
        }
    }
    return _builder;
}
Also used : EList(org.eclipse.emf.common.util.EList) ColumnType(com.robotoworks.mechanoid.db.sqliteModel.ColumnType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ColumnDef(com.robotoworks.mechanoid.db.sqliteModel.ColumnDef) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Aggregations

ColumnDef (com.robotoworks.mechanoid.db.sqliteModel.ColumnDef)7 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)4 ColumnType (com.robotoworks.mechanoid.db.sqliteModel.ColumnType)4 EList (org.eclipse.emf.common.util.EList)3 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)3 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)3 ResultColumn (com.robotoworks.mechanoid.db.sqliteModel.ResultColumn)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)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 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)1 ExprConcat (com.robotoworks.mechanoid.db.sqliteModel.ExprConcat)1 Expression (com.robotoworks.mechanoid.db.sqliteModel.Expression)1 Function (com.robotoworks.mechanoid.db.sqliteModel.Function)1 SelectCoreExpression (com.robotoworks.mechanoid.db.sqliteModel.SelectCoreExpression)1 SelectExpression (com.robotoworks.mechanoid.db.sqliteModel.SelectExpression)1 SingleSourceTable (com.robotoworks.mechanoid.db.sqliteModel.SingleSourceTable)1 SqliteDataType (com.robotoworks.mechanoid.db.sqliteModel.SqliteDataType)1 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)1