Search in sources :

Example 1 with ColumnSource

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

the class ActiveRecordGenerator method _generateParcelSerializationStatements.

protected CharSequence _generateParcelSerializationStatements(final CreateViewStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
    _builder.newLineIfNotEmpty();
    {
        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(cols, _function);
        for (final ColumnSource item : _filter) {
            ResultColumn col = ((ResultColumn) item);
            _builder.newLineIfNotEmpty();
            ColumnType type = ModelUtil.getInferredColumnType(col);
            _builder.newLineIfNotEmpty();
            {
                boolean _equals = Objects.equal(type, ColumnType.BOOLEAN);
                if (_equals) {
                    _builder.append("dest.writeInt(m");
                    String _name = col.getName();
                    String _pascalize = Strings.pascalize(_name);
                    _builder.append(_pascalize, "");
                    _builder.append(" ? 1 : 0);");
                    _builder.newLineIfNotEmpty();
                } else {
                    boolean _equals_1 = Objects.equal(type, ColumnType.BLOB);
                    if (_equals_1) {
                        _builder.append("dest.writeByteArray(m");
                        String _name_1 = col.getName();
                        String _pascalize_1 = Strings.pascalize(_name_1);
                        _builder.append(_pascalize_1, "");
                        _builder.append(");");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("dest.write");
                        String _javaTypeName = ModelUtil.toJavaTypeName(type);
                        String _pascalize_2 = Strings.pascalize(_javaTypeName);
                        _builder.append(_pascalize_2, "");
                        _builder.append("(m");
                        String _name_2 = col.getName();
                        String _pascalize_3 = Strings.pascalize(_name_2);
                        _builder.append(_pascalize_3, "");
                        _builder.append(");");
                        _builder.newLineIfNotEmpty();
                    }
                }
            }
        }
    }
    _builder.append("dest.writeBooleanArray(new boolean[] {");
    _builder.newLine();
    {
        final Function1<ColumnSource, Boolean> _function_1 = 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_1 = IterableExtensions.<ColumnSource>filter(cols, _function_1);
        boolean _hasElements = false;
        for (final ColumnSource col_1 : _filter_1) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate(",", "\t");
            }
            _builder.append("\t");
            _builder.append("m");
            String _name_3 = col_1.getName();
            String _pascalize_4 = Strings.pascalize(_name_3);
            _builder.append(_pascalize_4, "\t");
            _builder.append("Dirty");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("});");
    _builder.newLine();
    return _builder;
}
Also used : ColumnType(com.robotoworks.mechanoid.db.sqliteModel.ColumnType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ResultColumn(com.robotoworks.mechanoid.db.sqliteModel.ResultColumn) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 2 with ColumnSource

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

the class ActiveRecordGenerator method _generateProjectionIndicesMembers.

protected CharSequence _generateProjectionIndicesMembers(final CreateTableStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    int counter = (-1);
    _builder.newLineIfNotEmpty();
    {
        EList<ColumnSource> _columnDefs = stmt.getColumnDefs();
        for (final ColumnSource col : _columnDefs) {
            _builder.append("int ");
            String _name = col.getName();
            String _underscore = Strings.underscore(_name);
            String _upperCase = _underscore.toUpperCase();
            _builder.append(_upperCase, "");
            _builder.append(" = ");
            _builder.append(counter = (counter + 1), "");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
        }
    }
    return _builder;
}
Also used : EList(org.eclipse.emf.common.util.EList) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 3 with ColumnSource

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

the class ActiveRecordGenerator method _generateParcelDeserializationStatements.

protected CharSequence _generateParcelDeserializationStatements(final CreateViewStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    int counter = (-1);
    _builder.newLineIfNotEmpty();
    ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
    _builder.newLineIfNotEmpty();
    {
        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(cols, _function);
        for (final ColumnSource item : _filter) {
            ResultColumn col = ((ResultColumn) item);
            _builder.newLineIfNotEmpty();
            ColumnType type = ModelUtil.getInferredColumnType(col);
            _builder.newLineIfNotEmpty();
            {
                boolean _equals = Objects.equal(type, ColumnType.BOOLEAN);
                if (_equals) {
                    _builder.append("m");
                    String _name = col.getName();
                    String _pascalize = Strings.pascalize(_name);
                    _builder.append(_pascalize, "");
                    _builder.append(" = (in.readInt() > 0);");
                    _builder.newLineIfNotEmpty();
                } else {
                    boolean _equals_1 = Objects.equal(type, ColumnType.BLOB);
                    if (_equals_1) {
                        _builder.append("m");
                        String _name_1 = col.getName();
                        String _pascalize_1 = Strings.pascalize(_name_1);
                        _builder.append(_pascalize_1, "");
                        _builder.append(" = in.createByteArray();");
                        _builder.newLineIfNotEmpty();
                    } else {
                        _builder.append("m");
                        String _name_2 = col.getName();
                        String _pascalize_2 = Strings.pascalize(_name_2);
                        _builder.append(_pascalize_2, "");
                        _builder.append(" = in.read");
                        String _javaTypeName = ModelUtil.toJavaTypeName(type);
                        String _pascalize_3 = Strings.pascalize(_javaTypeName);
                        _builder.append(_pascalize_3, "");
                        _builder.append("();");
                        _builder.newLineIfNotEmpty();
                    }
                }
            }
        }
    }
    _builder.newLine();
    _builder.append("boolean[] dirtyFlags = new boolean[");
    int _size = cols.size();
    int _minus = (_size - 1);
    _builder.append(_minus, "");
    _builder.append("];");
    _builder.newLineIfNotEmpty();
    _builder.append("in.readBooleanArray(dirtyFlags);");
    _builder.newLine();
    {
        final Function1<ColumnSource, Boolean> _function_1 = 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_1 = IterableExtensions.<ColumnSource>filter(cols, _function_1);
        for (final ColumnSource col_1 : _filter_1) {
            _builder.append("m");
            String _name_3 = col_1.getName();
            String _pascalize_4 = Strings.pascalize(_name_3);
            _builder.append(_pascalize_4, "");
            _builder.append("Dirty = dirtyFlags[");
            _builder.append(counter = (counter + 1), "");
            _builder.append("];");
            _builder.newLineIfNotEmpty();
        }
    }
    return _builder;
}
Also used : ColumnType(com.robotoworks.mechanoid.db.sqliteModel.ColumnType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ResultColumn(com.robotoworks.mechanoid.db.sqliteModel.ResultColumn) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 4 with ColumnSource

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

the class ActiveRecordGenerator method _generateSetFromCursorStatements.

protected CharSequence _generateSetFromCursorStatements(final CreateViewStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
    _builder.newLineIfNotEmpty();
    {
        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(cols, _function);
        for (final ColumnSource item : _filter) {
            ResultColumn col = ((ResultColumn) item);
            _builder.newLineIfNotEmpty();
            ColumnType type = ModelUtil.getInferredColumnType(col);
            _builder.newLineIfNotEmpty();
            {
                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 {
                    boolean _equals_1 = Objects.equal(type, 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");
                        String _javaTypeName = ModelUtil.toJavaTypeName(type);
                        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 : ColumnType(com.robotoworks.mechanoid.db.sqliteModel.ColumnType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ResultColumn(com.robotoworks.mechanoid.db.sqliteModel.ResultColumn) ColumnSource(com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)

Example 5 with ColumnSource

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

the class ActiveRecordGenerator method _generateBuilderStatements.

protected CharSequence _generateBuilderStatements(final CreateViewStatement stmt) {
    StringConcatenation _builder = new StringConcatenation();
    ArrayList<ColumnSource> cols = ModelUtil.getViewResultColumns(stmt);
    _builder.newLineIfNotEmpty();
    {
        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(cols, _function);
        for (final ColumnSource col : _filter) {
            _builder.append("if(m");
            String _name = col.getName();
            String _pascalize = Strings.pascalize(_name);
            _builder.append(_pascalize, "");
            _builder.append("Dirty) {");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("builder.set");
            String _name_1 = col.getName();
            String _pascalize_1 = Strings.pascalize(_name_1);
            _builder.append(_pascalize_1, "\t");
            _builder.append("(m");
            String _name_2 = col.getName();
            String _pascalize_2 = Strings.pascalize(_name_2);
            _builder.append(_pascalize_2, "\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("}");
            _builder.newLine();
        }
    }
    return _builder;
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) 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