Search in sources :

Example 1 with CreateViewStatement

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

the class ContentProviderGenerator method generate.

public CharSequence generate(final Model model, final SqliteDatabaseSnapshot snapshot) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* Generated by Robotoworks Mechanoid");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("package ");
    String _packageName = model.getPackageName();
    _builder.append(_packageName, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import android.content.Context;");
    _builder.newLine();
    _builder.append("import android.content.UriMatcher;");
    _builder.newLine();
    _builder.append("import android.net.Uri;");
    _builder.newLine();
    _builder.append("import java.util.Set;");
    _builder.newLine();
    _builder.append("import com.robotoworks.mechanoid.db.MechanoidContentProvider;");
    _builder.newLine();
    _builder.append("import com.robotoworks.mechanoid.db.MechanoidSQLiteOpenHelper;");
    _builder.newLine();
    _builder.append("import com.robotoworks.mechanoid.db.DefaultContentProviderActions;");
    _builder.newLine();
    _builder.append("import com.robotoworks.mechanoid.db.ContentProviderActions;");
    _builder.newLine();
    _builder.append("import ");
    String _packageName_1 = model.getPackageName();
    _builder.append(_packageName_1, "");
    _builder.append(".Abstract");
    DatabaseBlock _database = model.getDatabase();
    String _name = _database.getName();
    String _pascalize = Strings.pascalize(_name);
    _builder.append(_pascalize, "");
    _builder.append("OpenHelper.Sources;");
    _builder.newLineIfNotEmpty();
    {
        Collection<CreateTableStatement> _tables = snapshot.getTables();
        final Function1<CreateTableStatement, Boolean> _function = new Function1<CreateTableStatement, Boolean>() {

            public Boolean apply(final CreateTableStatement it) {
                return Boolean.valueOf(ModelUtil.hasAndroidPrimaryKey(it));
            }
        };
        Iterable<CreateTableStatement> _filter = IterableExtensions.<CreateTableStatement>filter(_tables, _function);
        for (final CreateTableStatement tbl : _filter) {
            _builder.append("import ");
            String _packageName_2 = model.getPackageName();
            _builder.append(_packageName_2, "");
            _builder.append(".");
            String _name_1 = tbl.getName();
            String _pascalize_1 = Strings.pascalize(_name_1);
            _builder.append(_pascalize_1, "");
            _builder.append("Record;");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.newLine();
    _builder.append("public abstract class Abstract");
    DatabaseBlock _database_1 = model.getDatabase();
    String _name_2 = _database_1.getName();
    String _pascalize_2 = Strings.pascalize(_name_2);
    _builder.append(_pascalize_2, "");
    _builder.append("ContentProvider extends MechanoidContentProvider {");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    int counter = (-1);
    _builder.newLineIfNotEmpty();
    {
        Collection<CreateTableStatement> _tables_1 = snapshot.getTables();
        for (final CreateTableStatement tbl_1 : _tables_1) {
            _builder.append("\t");
            _builder.append("public static final int ");
            String _name_3 = tbl_1.getName();
            String _underscore = Strings.underscore(_name_3);
            String _upperCase = _underscore.toUpperCase();
            _builder.append(_upperCase, "\t");
            _builder.append(" = ");
            _builder.append(counter = (counter + 1), "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey = ModelUtil.hasAndroidPrimaryKey(tbl_1);
                if (_hasAndroidPrimaryKey) {
                    _builder.append("\t");
                    _builder.append("public static final int ");
                    String _name_4 = tbl_1.getName();
                    String _underscore_1 = Strings.underscore(_name_4);
                    String _upperCase_1 = _underscore_1.toUpperCase();
                    _builder.append(_upperCase_1, "\t");
                    _builder.append("_ID = ");
                    _builder.append(counter = (counter + 1), "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.newLine();
    {
        Collection<CreateViewStatement> _views = snapshot.getViews();
        for (final CreateViewStatement vw : _views) {
            _builder.append("\t");
            _builder.append("public static final int ");
            String _name_5 = vw.getName();
            String _underscore_2 = Strings.underscore(_name_5);
            String _upperCase_2 = _underscore_2.toUpperCase();
            _builder.append(_upperCase_2, "\t");
            _builder.append(" = ");
            _builder.append(counter = (counter + 1), "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_1 = ModelUtil.hasAndroidPrimaryKey(vw);
                if (_hasAndroidPrimaryKey_1) {
                    _builder.append("\t");
                    _builder.append("public static final int ");
                    String _name_6 = vw.getName();
                    String _underscore_3 = Strings.underscore(_name_6);
                    String _upperCase_3 = _underscore_3.toUpperCase();
                    _builder.append(_upperCase_3, "\t");
                    _builder.append("_ID = ");
                    _builder.append(counter = (counter + 1), "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("\t");
    _builder.newLine();
    {
        Collection<CreateTableStatement> _configInitTables = ModelUtil.getConfigInitTables(model);
        for (final CreateTableStatement tbl_2 : _configInitTables) {
            _builder.append("\t");
            _builder.append("public static final int ");
            String _name_7 = tbl_2.getName();
            String _underscore_4 = Strings.underscore(_name_7);
            String _upperCase_4 = _underscore_4.toUpperCase();
            _builder.append(_upperCase_4, "\t");
            _builder.append(" = ");
            _builder.append(counter = (counter + 1), "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_2 = ModelUtil.hasAndroidPrimaryKey(tbl_2);
                if (_hasAndroidPrimaryKey_2) {
                    _builder.append("\t");
                    _builder.append("public static final int ");
                    String _name_8 = tbl_2.getName();
                    String _underscore_5 = Strings.underscore(_name_8);
                    String _upperCase_5 = _underscore_5.toUpperCase();
                    _builder.append(_upperCase_5, "\t");
                    _builder.append("_ID = ");
                    _builder.append(counter = (counter + 1), "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.newLine();
    {
        Collection<CreateViewStatement> _configInitViews = ModelUtil.getConfigInitViews(model);
        for (final CreateViewStatement vw_1 : _configInitViews) {
            _builder.append("\t");
            _builder.append("public static final int ");
            String _name_9 = vw_1.getName();
            String _underscore_6 = Strings.underscore(_name_9);
            String _upperCase_6 = _underscore_6.toUpperCase();
            _builder.append(_upperCase_6, "\t");
            _builder.append(" = ");
            _builder.append(counter = (counter + 1), "\t");
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_3 = ModelUtil.hasAndroidPrimaryKey(vw_1);
                if (_hasAndroidPrimaryKey_3) {
                    _builder.append("\t");
                    _builder.append("public static final int ");
                    String _name_10 = vw_1.getName();
                    String _underscore_7 = Strings.underscore(_name_10);
                    String _upperCase_7 = _underscore_7.toUpperCase();
                    _builder.append(_upperCase_7, "\t");
                    _builder.append("_ID = ");
                    _builder.append(counter = (counter + 1), "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("\t");
    _builder.newLine();
    {
        DatabaseBlock _database_2 = model.getDatabase();
        ConfigBlock _config = _database_2.getConfig();
        boolean _notEquals = (!Objects.equal(_config, null));
        if (_notEquals) {
            {
                DatabaseBlock _database_3 = model.getDatabase();
                ConfigBlock _config_1 = _database_3.getConfig();
                EList<ConfigurationStatement> _statements = _config_1.getStatements();
                final Function1<ConfigurationStatement, Boolean> _function_1 = new Function1<ConfigurationStatement, Boolean>() {

                    public Boolean apply(final ConfigurationStatement it) {
                        return Boolean.valueOf((it instanceof ActionStatement));
                    }
                };
                Iterable<ConfigurationStatement> _filter_1 = IterableExtensions.<ConfigurationStatement>filter(_statements, _function_1);
                for (final ConfigurationStatement a : _filter_1) {
                    _builder.append("\t");
                    _builder.append("public static final int ");
                    ContentUri _uri = ((ActionStatement) a).getUri();
                    String _type = _uri.getType();
                    String _underscore_8 = Strings.underscore(_type);
                    String _upperCase_8 = _underscore_8.toUpperCase();
                    _builder.append(_upperCase_8, "\t");
                    _builder.append("_");
                    String _name_11 = ((ActionStatement) a).getName();
                    String _underscore_9 = Strings.underscore(_name_11);
                    String _upperCase_9 = _underscore_9.toUpperCase();
                    _builder.append(_upperCase_9, "\t");
                    _builder.append(" = ");
                    _builder.append(counter = (counter + 1), "\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("\t");
    _builder.append("public static final int NUM_URI_MATCHERS = ");
    _builder.append((counter + 1), "\t");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("protected UriMatcher createUriMatcher() {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("final String authority = ");
    DatabaseBlock _database_4 = model.getDatabase();
    String _name_12 = _database_4.getName();
    String _pascalize_3 = Strings.pascalize(_name_12);
    _builder.append(_pascalize_3, "        ");
    _builder.append("Contract.CONTENT_AUTHORITY;");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
        Collection<CreateTableStatement> _tables_2 = snapshot.getTables();
        for (final CreateTableStatement tbl_3 : _tables_2) {
            _builder.append("\t\t");
            _builder.append("matcher.addURI(authority, \"");
            String _name_13 = tbl_3.getName();
            _builder.append(_name_13, "\t\t");
            _builder.append("\", ");
            String _name_14 = tbl_3.getName();
            String _underscore_10 = Strings.underscore(_name_14);
            String _upperCase_10 = _underscore_10.toUpperCase();
            _builder.append(_upperCase_10, "\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_4 = ModelUtil.hasAndroidPrimaryKey(tbl_3);
                if (_hasAndroidPrimaryKey_4) {
                    _builder.append("\t\t");
                    _builder.append("matcher.addURI(authority, \"");
                    String _name_15 = tbl_3.getName();
                    _builder.append(_name_15, "\t\t");
                    _builder.append("/#\", ");
                    String _name_16 = tbl_3.getName();
                    String _underscore_11 = Strings.underscore(_name_16);
                    String _upperCase_11 = _underscore_11.toUpperCase();
                    _builder.append(_upperCase_11, "\t\t");
                    _builder.append("_ID);");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateViewStatement> _views_1 = snapshot.getViews();
        for (final CreateViewStatement vw_2 : _views_1) {
            _builder.append("\t\t");
            _builder.append("matcher.addURI(authority, \"");
            String _name_17 = vw_2.getName();
            _builder.append(_name_17, "\t\t");
            _builder.append("\", ");
            String _name_18 = vw_2.getName();
            String _underscore_12 = Strings.underscore(_name_18);
            String _upperCase_12 = _underscore_12.toUpperCase();
            _builder.append(_upperCase_12, "\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_5 = ModelUtil.hasAndroidPrimaryKey(vw_2);
                if (_hasAndroidPrimaryKey_5) {
                    _builder.append("\t\t");
                    _builder.append("matcher.addURI(authority, \"");
                    String _name_19 = vw_2.getName();
                    _builder.append(_name_19, "\t\t");
                    _builder.append("/#\", ");
                    String _name_20 = vw_2.getName();
                    String _underscore_13 = Strings.underscore(_name_20);
                    String _upperCase_13 = _underscore_13.toUpperCase();
                    _builder.append(_upperCase_13, "\t\t");
                    _builder.append("_ID);");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateTableStatement> _configInitTables_1 = ModelUtil.getConfigInitTables(model);
        for (final CreateTableStatement tbl_4 : _configInitTables_1) {
            _builder.append("\t\t");
            _builder.append("matcher.addURI(authority, \"");
            String _name_21 = tbl_4.getName();
            _builder.append(_name_21, "\t\t");
            _builder.append("\", ");
            String _name_22 = tbl_4.getName();
            String _underscore_14 = Strings.underscore(_name_22);
            String _upperCase_14 = _underscore_14.toUpperCase();
            _builder.append(_upperCase_14, "\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_6 = ModelUtil.hasAndroidPrimaryKey(tbl_4);
                if (_hasAndroidPrimaryKey_6) {
                    _builder.append("\t\t");
                    _builder.append("matcher.addURI(authority, \"");
                    String _name_23 = tbl_4.getName();
                    _builder.append(_name_23, "\t\t");
                    _builder.append("/#\", ");
                    String _name_24 = tbl_4.getName();
                    String _underscore_15 = Strings.underscore(_name_24);
                    String _upperCase_15 = _underscore_15.toUpperCase();
                    _builder.append(_upperCase_15, "\t\t");
                    _builder.append("_ID);");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateViewStatement> _configInitViews_1 = ModelUtil.getConfigInitViews(model);
        for (final CreateViewStatement vw_3 : _configInitViews_1) {
            _builder.append("\t\t");
            _builder.append("matcher.addURI(authority, \"");
            String _name_25 = vw_3.getName();
            _builder.append(_name_25, "\t\t");
            _builder.append("\", ");
            String _name_26 = vw_3.getName();
            String _underscore_16 = Strings.underscore(_name_26);
            String _upperCase_16 = _underscore_16.toUpperCase();
            _builder.append(_upperCase_16, "\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_7 = ModelUtil.hasAndroidPrimaryKey(vw_3);
                if (_hasAndroidPrimaryKey_7) {
                    _builder.append("\t\t");
                    _builder.append("matcher.addURI(authority, \"");
                    String _name_27 = vw_3.getName();
                    _builder.append(_name_27, "\t\t");
                    _builder.append("/#\", ");
                    String _name_28 = vw_3.getName();
                    String _underscore_17 = Strings.underscore(_name_28);
                    String _upperCase_17 = _underscore_17.toUpperCase();
                    _builder.append(_upperCase_17, "\t\t");
                    _builder.append("_ID);");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("// User Actions");
    _builder.newLine();
    {
        DatabaseBlock _database_5 = model.getDatabase();
        ConfigBlock _config_2 = _database_5.getConfig();
        boolean _notEquals_1 = (!Objects.equal(_config_2, null));
        if (_notEquals_1) {
            {
                DatabaseBlock _database_6 = model.getDatabase();
                ConfigBlock _config_3 = _database_6.getConfig();
                EList<ConfigurationStatement> _statements_1 = _config_3.getStatements();
                final Function1<ConfigurationStatement, Boolean> _function_2 = new Function1<ConfigurationStatement, Boolean>() {

                    public Boolean apply(final ConfigurationStatement it) {
                        return Boolean.valueOf((it instanceof ActionStatement));
                    }
                };
                Iterable<ConfigurationStatement> _filter_2 = IterableExtensions.<ConfigurationStatement>filter(_statements_1, _function_2);
                for (final ConfigurationStatement a_1 : _filter_2) {
                    _builder.append("\t\t");
                    ActionStatement stmt = ((ActionStatement) a_1);
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("matcher.addURI(authority, \"");
                    ContentUri _uri_1 = stmt.getUri();
                    String _asString = this.asString(_uri_1);
                    _builder.append(_asString, "\t\t");
                    _builder.append("\", ");
                    ContentUri _uri_2 = ((ActionStatement) a_1).getUri();
                    String _type_1 = _uri_2.getType();
                    String _underscore_18 = Strings.underscore(_type_1);
                    String _upperCase_18 = _underscore_18.toUpperCase();
                    _builder.append(_upperCase_18, "\t\t");
                    _builder.append("_");
                    String _name_29 = ((ActionStatement) a_1).getName();
                    String _underscore_19 = Strings.underscore(_name_29);
                    String _upperCase_19 = _underscore_19.toUpperCase();
                    _builder.append(_upperCase_19, "\t\t");
                    _builder.append("); ");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("        ");
    _builder.append("return matcher;");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("protected String[] createContentTypes() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("String[] contentTypes = new String[NUM_URI_MATCHERS];");
    _builder.newLine();
    _builder.newLine();
    {
        Collection<CreateTableStatement> _tables_3 = snapshot.getTables();
        for (final CreateTableStatement tbl_5 : _tables_3) {
            _builder.append("\t\t");
            _builder.append("contentTypes[");
            String _name_30 = tbl_5.getName();
            String _underscore_20 = Strings.underscore(_name_30);
            String _upperCase_20 = _underscore_20.toUpperCase();
            _builder.append(_upperCase_20, "\t\t");
            _builder.append("] = ");
            DatabaseBlock _database_7 = model.getDatabase();
            String _name_31 = _database_7.getName();
            String _pascalize_4 = Strings.pascalize(_name_31);
            _builder.append(_pascalize_4, "\t\t");
            _builder.append("Contract.");
            String _name_32 = tbl_5.getName();
            String _pascalize_5 = Strings.pascalize(_name_32);
            _builder.append(_pascalize_5, "\t\t");
            _builder.append(".CONTENT_TYPE;");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_8 = ModelUtil.hasAndroidPrimaryKey(tbl_5);
                if (_hasAndroidPrimaryKey_8) {
                    _builder.append("\t\t");
                    _builder.append("contentTypes[");
                    String _name_33 = tbl_5.getName();
                    String _underscore_21 = Strings.underscore(_name_33);
                    String _upperCase_21 = _underscore_21.toUpperCase();
                    _builder.append(_upperCase_21, "\t\t");
                    _builder.append("_ID] = ");
                    DatabaseBlock _database_8 = model.getDatabase();
                    String _name_34 = _database_8.getName();
                    String _pascalize_6 = Strings.pascalize(_name_34);
                    _builder.append(_pascalize_6, "\t\t");
                    _builder.append("Contract.");
                    String _name_35 = tbl_5.getName();
                    String _pascalize_7 = Strings.pascalize(_name_35);
                    _builder.append(_pascalize_7, "\t\t");
                    _builder.append(".ITEM_CONTENT_TYPE;");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateViewStatement> _views_2 = snapshot.getViews();
        for (final CreateViewStatement vw_4 : _views_2) {
            _builder.append("\t\t");
            _builder.append("contentTypes[");
            String _name_36 = vw_4.getName();
            String _underscore_22 = Strings.underscore(_name_36);
            String _upperCase_22 = _underscore_22.toUpperCase();
            _builder.append(_upperCase_22, "\t\t");
            _builder.append("] = ");
            DatabaseBlock _database_9 = model.getDatabase();
            String _name_37 = _database_9.getName();
            String _pascalize_8 = Strings.pascalize(_name_37);
            _builder.append(_pascalize_8, "\t\t");
            _builder.append("Contract.");
            String _name_38 = vw_4.getName();
            String _pascalize_9 = Strings.pascalize(_name_38);
            _builder.append(_pascalize_9, "\t\t");
            _builder.append(".CONTENT_TYPE;");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_9 = ModelUtil.hasAndroidPrimaryKey(vw_4);
                if (_hasAndroidPrimaryKey_9) {
                    _builder.append("\t\t");
                    _builder.append("contentTypes[");
                    String _name_39 = vw_4.getName();
                    String _underscore_23 = Strings.underscore(_name_39);
                    String _upperCase_23 = _underscore_23.toUpperCase();
                    _builder.append(_upperCase_23, "\t\t");
                    _builder.append("_ID] = ");
                    DatabaseBlock _database_10 = model.getDatabase();
                    String _name_40 = _database_10.getName();
                    String _pascalize_10 = Strings.pascalize(_name_40);
                    _builder.append(_pascalize_10, "\t\t");
                    _builder.append("Contract.");
                    String _name_41 = vw_4.getName();
                    String _pascalize_11 = Strings.pascalize(_name_41);
                    _builder.append(_pascalize_11, "\t\t");
                    _builder.append(".ITEM_CONTENT_TYPE;");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateTableStatement> _configInitTables_2 = ModelUtil.getConfigInitTables(model);
        for (final CreateTableStatement tbl_6 : _configInitTables_2) {
            _builder.append("\t\t");
            _builder.append("contentTypes[");
            String _name_42 = tbl_6.getName();
            String _underscore_24 = Strings.underscore(_name_42);
            String _upperCase_24 = _underscore_24.toUpperCase();
            _builder.append(_upperCase_24, "\t\t");
            _builder.append("] = ");
            DatabaseBlock _database_11 = model.getDatabase();
            String _name_43 = _database_11.getName();
            String _pascalize_12 = Strings.pascalize(_name_43);
            _builder.append(_pascalize_12, "\t\t");
            _builder.append("Contract.");
            String _name_44 = tbl_6.getName();
            String _pascalize_13 = Strings.pascalize(_name_44);
            _builder.append(_pascalize_13, "\t\t");
            _builder.append(".CONTENT_TYPE;");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_10 = ModelUtil.hasAndroidPrimaryKey(tbl_6);
                if (_hasAndroidPrimaryKey_10) {
                    _builder.append("\t\t");
                    _builder.append("contentTypes[");
                    String _name_45 = tbl_6.getName();
                    String _underscore_25 = Strings.underscore(_name_45);
                    String _upperCase_25 = _underscore_25.toUpperCase();
                    _builder.append(_upperCase_25, "\t\t");
                    _builder.append("_ID] = ");
                    DatabaseBlock _database_12 = model.getDatabase();
                    String _name_46 = _database_12.getName();
                    String _pascalize_14 = Strings.pascalize(_name_46);
                    _builder.append(_pascalize_14, "\t\t");
                    _builder.append("Contract.");
                    String _name_47 = tbl_6.getName();
                    String _pascalize_15 = Strings.pascalize(_name_47);
                    _builder.append(_pascalize_15, "\t\t");
                    _builder.append(".ITEM_CONTENT_TYPE;");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateViewStatement> _configInitViews_2 = ModelUtil.getConfigInitViews(model);
        for (final CreateViewStatement vw_5 : _configInitViews_2) {
            _builder.append("\t\t");
            _builder.append("contentTypes[");
            String _name_48 = vw_5.getName();
            String _underscore_26 = Strings.underscore(_name_48);
            String _upperCase_26 = _underscore_26.toUpperCase();
            _builder.append(_upperCase_26, "\t\t");
            _builder.append("] = ");
            DatabaseBlock _database_13 = model.getDatabase();
            String _name_49 = _database_13.getName();
            String _pascalize_16 = Strings.pascalize(_name_49);
            _builder.append(_pascalize_16, "\t\t");
            _builder.append("Contract.");
            String _name_50 = vw_5.getName();
            String _pascalize_17 = Strings.pascalize(_name_50);
            _builder.append(_pascalize_17, "\t\t");
            _builder.append(".CONTENT_TYPE;");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_11 = ModelUtil.hasAndroidPrimaryKey(vw_5);
                if (_hasAndroidPrimaryKey_11) {
                    _builder.append("\t\t");
                    _builder.append("contentTypes[");
                    String _name_51 = vw_5.getName();
                    String _underscore_27 = Strings.underscore(_name_51);
                    String _upperCase_27 = _underscore_27.toUpperCase();
                    _builder.append(_upperCase_27, "\t\t");
                    _builder.append("_ID] = ");
                    DatabaseBlock _database_14 = model.getDatabase();
                    String _name_52 = _database_14.getName();
                    String _pascalize_18 = Strings.pascalize(_name_52);
                    _builder.append(_pascalize_18, "\t\t");
                    _builder.append("Contract.");
                    String _name_53 = vw_5.getName();
                    String _pascalize_19 = Strings.pascalize(_name_53);
                    _builder.append(_pascalize_19, "\t\t");
                    _builder.append(".ITEM_CONTENT_TYPE;");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        DatabaseBlock _database_15 = model.getDatabase();
        ConfigBlock _config_4 = _database_15.getConfig();
        boolean _notEquals_2 = (!Objects.equal(_config_4, null));
        if (_notEquals_2) {
            {
                DatabaseBlock _database_16 = model.getDatabase();
                ConfigBlock _config_5 = _database_16.getConfig();
                EList<ConfigurationStatement> _statements_2 = _config_5.getStatements();
                final Function1<ConfigurationStatement, Boolean> _function_3 = new Function1<ConfigurationStatement, Boolean>() {

                    public Boolean apply(final ConfigurationStatement it) {
                        return Boolean.valueOf((it instanceof ActionStatement));
                    }
                };
                Iterable<ConfigurationStatement> _filter_3 = IterableExtensions.<ConfigurationStatement>filter(_statements_2, _function_3);
                for (final ConfigurationStatement a_2 : _filter_3) {
                    _builder.append("\t\t");
                    _builder.append("contentTypes[");
                    ContentUri _uri_3 = ((ActionStatement) a_2).getUri();
                    String _type_2 = _uri_3.getType();
                    String _underscore_28 = Strings.underscore(_type_2);
                    String _upperCase_28 = _underscore_28.toUpperCase();
                    _builder.append(_upperCase_28, "\t\t");
                    _builder.append("_");
                    String _name_54 = ((ActionStatement) a_2).getName();
                    String _underscore_29 = Strings.underscore(_name_54);
                    String _upperCase_29 = _underscore_29.toUpperCase();
                    _builder.append(_upperCase_29, "\t\t");
                    _builder.append("] = ");
                    String _generateContentTypeConstantReference = this.generateContentTypeConstantReference(((ActionStatement) a_2), model);
                    _builder.append(_generateContentTypeConstantReference, "\t\t");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return contentTypes;");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected MechanoidSQLiteOpenHelper createOpenHelper(Context context) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("return new ");
    DatabaseBlock _database_17 = model.getDatabase();
    String _name_55 = _database_17.getName();
    String _pascalize_20 = Strings.pascalize(_name_55);
    _builder.append(_pascalize_20, "        ");
    _builder.append("OpenHelper(context);");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected Set<Uri> getRelatedUris(Uri uri) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return ");
    DatabaseBlock _database_18 = model.getDatabase();
    String _name_56 = _database_18.getName();
    String _pascalize_21 = Strings.pascalize(_name_56);
    _builder.append(_pascalize_21, "\t\t");
    _builder.append("Contract.REFERENCING_VIEWS.get(uri);");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("protected ContentProviderActions createActions(int id) {");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("switch(id) {");
    _builder.newLine();
    {
        Collection<CreateTableStatement> _tables_4 = snapshot.getTables();
        for (final CreateTableStatement tbl_7 : _tables_4) {
            _builder.append("\t\t\t");
            _builder.append("case ");
            String _name_57 = tbl_7.getName();
            String _underscore_30 = Strings.underscore(_name_57);
            String _upperCase_30 = _underscore_30.toUpperCase();
            _builder.append(_upperCase_30, "\t\t\t");
            _builder.append(": ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("return create");
            String _name_58 = tbl_7.getName();
            String _pascalize_22 = Strings.pascalize(_name_58);
            _builder.append(_pascalize_22, "\t\t\t\t");
            _builder.append("Actions();");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_12 = ModelUtil.hasAndroidPrimaryKey(tbl_7);
                if (_hasAndroidPrimaryKey_12) {
                    _builder.append("\t\t\t");
                    _builder.append("case ");
                    String _name_59 = tbl_7.getName();
                    String _underscore_31 = Strings.underscore(_name_59);
                    String _upperCase_31 = _underscore_31.toUpperCase();
                    _builder.append(_upperCase_31, "\t\t\t");
                    _builder.append("_ID:");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("return create");
                    String _name_60 = tbl_7.getName();
                    String _pascalize_23 = Strings.pascalize(_name_60);
                    _builder.append(_pascalize_23, "\t\t\t\t");
                    _builder.append("ByIdActions();");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateViewStatement> _views_3 = snapshot.getViews();
        for (final CreateViewStatement vw_6 : _views_3) {
            _builder.append("\t\t\t");
            _builder.append("case ");
            String _name_61 = vw_6.getName();
            String _underscore_32 = Strings.underscore(_name_61);
            String _upperCase_32 = _underscore_32.toUpperCase();
            _builder.append(_upperCase_32, "\t\t\t");
            _builder.append(":");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("return create");
            String _name_62 = vw_6.getName();
            String _pascalize_24 = Strings.pascalize(_name_62);
            _builder.append(_pascalize_24, "\t\t\t\t");
            _builder.append("Actions();");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_13 = ModelUtil.hasAndroidPrimaryKey(vw_6);
                if (_hasAndroidPrimaryKey_13) {
                    _builder.append("\t\t\t");
                    _builder.append("case ");
                    String _name_63 = vw_6.getName();
                    String _underscore_33 = Strings.underscore(_name_63);
                    String _upperCase_33 = _underscore_33.toUpperCase();
                    _builder.append(_upperCase_33, "\t\t\t");
                    _builder.append("_ID: ");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("return create");
                    String _name_64 = vw_6.getName();
                    String _pascalize_25 = Strings.pascalize(_name_64);
                    _builder.append(_pascalize_25, "\t\t\t\t");
                    _builder.append("ByIdActions();");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateTableStatement> _configInitTables_3 = ModelUtil.getConfigInitTables(model);
        for (final CreateTableStatement tbl_8 : _configInitTables_3) {
            _builder.append("\t\t\t");
            _builder.append("case ");
            String _name_65 = tbl_8.getName();
            String _underscore_34 = Strings.underscore(_name_65);
            String _upperCase_34 = _underscore_34.toUpperCase();
            _builder.append(_upperCase_34, "\t\t\t");
            _builder.append(": ");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("return create");
            String _name_66 = tbl_8.getName();
            String _pascalize_26 = Strings.pascalize(_name_66);
            _builder.append(_pascalize_26, "\t\t\t\t");
            _builder.append("Actions();");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_14 = ModelUtil.hasAndroidPrimaryKey(tbl_8);
                if (_hasAndroidPrimaryKey_14) {
                    _builder.append("\t\t\t");
                    _builder.append("case ");
                    String _name_67 = tbl_8.getName();
                    String _underscore_35 = Strings.underscore(_name_67);
                    String _upperCase_35 = _underscore_35.toUpperCase();
                    _builder.append(_upperCase_35, "\t\t\t");
                    _builder.append("_ID:");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("return create");
                    String _name_68 = tbl_8.getName();
                    String _pascalize_27 = Strings.pascalize(_name_68);
                    _builder.append(_pascalize_27, "\t\t\t\t");
                    _builder.append("ByIdActions();");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        Collection<CreateViewStatement> _configInitViews_3 = ModelUtil.getConfigInitViews(model);
        for (final CreateViewStatement vw_7 : _configInitViews_3) {
            _builder.append("\t\t\t");
            _builder.append("case ");
            String _name_69 = vw_7.getName();
            String _underscore_36 = Strings.underscore(_name_69);
            String _upperCase_36 = _underscore_36.toUpperCase();
            _builder.append(_upperCase_36, "\t\t\t");
            _builder.append(":");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t\t");
            _builder.append("\t");
            _builder.append("return create");
            String _name_70 = vw_7.getName();
            String _pascalize_28 = Strings.pascalize(_name_70);
            _builder.append(_pascalize_28, "\t\t\t\t");
            _builder.append("Actions();");
            _builder.newLineIfNotEmpty();
            {
                boolean _hasAndroidPrimaryKey_15 = ModelUtil.hasAndroidPrimaryKey(vw_7);
                if (_hasAndroidPrimaryKey_15) {
                    _builder.append("\t\t\t");
                    _builder.append("case ");
                    String _name_71 = vw_7.getName();
                    String _underscore_37 = Strings.underscore(_name_71);
                    String _upperCase_37 = _underscore_37.toUpperCase();
                    _builder.append(_upperCase_37, "\t\t\t");
                    _builder.append("_ID: ");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("return create");
                    String _name_72 = vw_7.getName();
                    String _pascalize_29 = Strings.pascalize(_name_72);
                    _builder.append(_pascalize_29, "\t\t\t\t");
                    _builder.append("ByIdActions();");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    {
        DatabaseBlock _database_19 = model.getDatabase();
        ConfigBlock _config_6 = _database_19.getConfig();
        boolean _notEquals_3 = (!Objects.equal(_config_6, null));
        if (_notEquals_3) {
            {
                DatabaseBlock _database_20 = model.getDatabase();
                ConfigBlock _config_7 = _database_20.getConfig();
                EList<ConfigurationStatement> _statements_3 = _config_7.getStatements();
                final Function1<ConfigurationStatement, Boolean> _function_4 = new Function1<ConfigurationStatement, Boolean>() {

                    public Boolean apply(final ConfigurationStatement it) {
                        return Boolean.valueOf((it instanceof ActionStatement));
                    }
                };
                Iterable<ConfigurationStatement> _filter_4 = IterableExtensions.<ConfigurationStatement>filter(_statements_3, _function_4);
                for (final ConfigurationStatement a_3 : _filter_4) {
                    _builder.append("\t\t\t");
                    _builder.append("case ");
                    ContentUri _uri_4 = ((ActionStatement) a_3).getUri();
                    String _type_3 = _uri_4.getType();
                    String _underscore_38 = Strings.underscore(_type_3);
                    String _upperCase_38 = _underscore_38.toUpperCase();
                    _builder.append(_upperCase_38, "\t\t\t");
                    _builder.append("_");
                    String _name_73 = ((ActionStatement) a_3).getName();
                    String _underscore_39 = Strings.underscore(_name_73);
                    String _upperCase_39 = _underscore_39.toUpperCase();
                    _builder.append(_upperCase_39, "\t\t\t");
                    _builder.append(":");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("return create");
                    String _name_74 = ((ActionStatement) a_3).getName();
                    String _pascalize_30 = Strings.pascalize(_name_74);
                    _builder.append(_pascalize_30, "\t\t\t\t");
                    _builder.append("Actions();");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.append("\t\t\t");
    _builder.append("default:");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("throw new UnsupportedOperationException(\"Unknown id: \" + id);");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.newLine();
    {
        Collection<CreateTableStatement> _tables_5 = snapshot.getTables();
        for (final CreateTableStatement tbl_9 : _tables_5) {
            {
                boolean _hasAndroidPrimaryKey_16 = ModelUtil.hasAndroidPrimaryKey(tbl_9);
                if (_hasAndroidPrimaryKey_16) {
                    _builder.append("    ");
                    _builder.append("protected ContentProviderActions create");
                    String _name_75 = tbl_9.getName();
                    String _pascalize_31 = Strings.pascalize(_name_75);
                    _builder.append(_pascalize_31, "    ");
                    _builder.append("ByIdActions() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("\t");
                    _builder.append("return new DefaultContentProviderActions(Sources.");
                    String _name_76 = tbl_9.getName();
                    String _underscore_40 = Strings.underscore(_name_76);
                    String _upperCase_40 = _underscore_40.toUpperCase();
                    _builder.append(_upperCase_40, "    \t");
                    _builder.append(", true, ");
                    {
                        boolean _hasAndroidPrimaryKey_17 = ModelUtil.hasAndroidPrimaryKey(tbl_9);
                        if (_hasAndroidPrimaryKey_17) {
                            String _name_77 = tbl_9.getName();
                            String _pascalize_32 = Strings.pascalize(_name_77);
                            _builder.append(_pascalize_32, "    \t");
                            _builder.append("Record.getFactory()");
                        } else {
                            _builder.append("null");
                        }
                    }
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("    ");
                    _builder.newLine();
                }
            }
            _builder.append("    ");
            _builder.append("protected ContentProviderActions create");
            String _name_78 = tbl_9.getName();
            String _pascalize_33 = Strings.pascalize(_name_78);
            _builder.append(_pascalize_33, "    ");
            _builder.append("Actions() {");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("\t");
            _builder.append("return new DefaultContentProviderActions(Sources.");
            String _name_79 = tbl_9.getName();
            String _underscore_41 = Strings.underscore(_name_79);
            String _upperCase_41 = _underscore_41.toUpperCase();
            _builder.append(_upperCase_41, "    \t");
            _builder.append(", false, ");
            {
                boolean _hasAndroidPrimaryKey_18 = ModelUtil.hasAndroidPrimaryKey(tbl_9);
                if (_hasAndroidPrimaryKey_18) {
                    String _name_80 = tbl_9.getName();
                    String _pascalize_34 = Strings.pascalize(_name_80);
                    _builder.append(_pascalize_34, "    \t");
                    _builder.append("Record.getFactory()");
                } else {
                    _builder.append("null");
                }
            }
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("}");
            _builder.newLine();
            _builder.append("    ");
            _builder.newLine();
        }
    }
    {
        Collection<CreateViewStatement> _views_4 = snapshot.getViews();
        for (final CreateViewStatement view : _views_4) {
            {
                boolean _hasAndroidPrimaryKey_19 = ModelUtil.hasAndroidPrimaryKey(view);
                if (_hasAndroidPrimaryKey_19) {
                    _builder.append("    ");
                    _builder.append("protected ContentProviderActions create");
                    String _name_81 = view.getName();
                    String _pascalize_35 = Strings.pascalize(_name_81);
                    _builder.append(_pascalize_35, "    ");
                    _builder.append("ByIdActions() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("\t");
                    _builder.append("return new DefaultContentProviderActions(Sources.");
                    String _name_82 = view.getName();
                    String _underscore_42 = Strings.underscore(_name_82);
                    String _upperCase_42 = _underscore_42.toUpperCase();
                    _builder.append(_upperCase_42, "    \t");
                    _builder.append(", true, ");
                    {
                        boolean _hasAndroidPrimaryKey_20 = ModelUtil.hasAndroidPrimaryKey(view);
                        if (_hasAndroidPrimaryKey_20) {
                            String _name_83 = view.getName();
                            String _pascalize_36 = Strings.pascalize(_name_83);
                            _builder.append(_pascalize_36, "    \t");
                            _builder.append("Record.getFactory()");
                        } else {
                            _builder.append("null");
                        }
                    }
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("    ");
                    _builder.newLine();
                }
            }
            _builder.append("    ");
            _builder.append("protected ContentProviderActions create");
            String _name_84 = view.getName();
            String _pascalize_37 = Strings.pascalize(_name_84);
            _builder.append(_pascalize_37, "    ");
            _builder.append("Actions() {");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("\t");
            _builder.append("return new DefaultContentProviderActions(Sources.");
            String _name_85 = view.getName();
            String _underscore_43 = Strings.underscore(_name_85);
            String _upperCase_43 = _underscore_43.toUpperCase();
            _builder.append(_upperCase_43, "    \t");
            _builder.append(", false, ");
            {
                boolean _hasAndroidPrimaryKey_21 = ModelUtil.hasAndroidPrimaryKey(view);
                if (_hasAndroidPrimaryKey_21) {
                    String _name_86 = view.getName();
                    String _pascalize_38 = Strings.pascalize(_name_86);
                    _builder.append(_pascalize_38, "    \t");
                    _builder.append("Record.getFactory()");
                } else {
                    _builder.append("null");
                }
            }
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("}");
            _builder.newLine();
            _builder.append("    ");
            _builder.newLine();
        }
    }
    {
        Collection<CreateTableStatement> _configInitTables_4 = ModelUtil.getConfigInitTables(model);
        for (final CreateTableStatement tbl_10 : _configInitTables_4) {
            {
                boolean _hasAndroidPrimaryKey_22 = ModelUtil.hasAndroidPrimaryKey(tbl_10);
                if (_hasAndroidPrimaryKey_22) {
                    _builder.append("    ");
                    _builder.append("protected ContentProviderActions create");
                    String _name_87 = tbl_10.getName();
                    String _pascalize_39 = Strings.pascalize(_name_87);
                    _builder.append(_pascalize_39, "    ");
                    _builder.append("ByIdActions() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("\t");
                    _builder.append("return new DefaultContentProviderActions(Sources.");
                    String _name_88 = tbl_10.getName();
                    String _underscore_44 = Strings.underscore(_name_88);
                    String _upperCase_44 = _underscore_44.toUpperCase();
                    _builder.append(_upperCase_44, "    \t");
                    _builder.append(", true, ");
                    {
                        boolean _hasAndroidPrimaryKey_23 = ModelUtil.hasAndroidPrimaryKey(tbl_10);
                        if (_hasAndroidPrimaryKey_23) {
                            String _name_89 = tbl_10.getName();
                            String _pascalize_40 = Strings.pascalize(_name_89);
                            _builder.append(_pascalize_40, "    \t");
                            _builder.append("Record.getFactory()");
                        } else {
                            _builder.append("null");
                        }
                    }
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("    ");
                    _builder.newLine();
                }
            }
            _builder.append("    ");
            _builder.append("protected ContentProviderActions create");
            String _name_90 = tbl_10.getName();
            String _pascalize_41 = Strings.pascalize(_name_90);
            _builder.append(_pascalize_41, "    ");
            _builder.append("Actions() {");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("\t");
            _builder.append("return new DefaultContentProviderActions(Sources.");
            String _name_91 = tbl_10.getName();
            String _underscore_45 = Strings.underscore(_name_91);
            String _upperCase_45 = _underscore_45.toUpperCase();
            _builder.append(_upperCase_45, "    \t");
            _builder.append(", false, ");
            {
                boolean _hasAndroidPrimaryKey_24 = ModelUtil.hasAndroidPrimaryKey(tbl_10);
                if (_hasAndroidPrimaryKey_24) {
                    String _name_92 = tbl_10.getName();
                    String _pascalize_42 = Strings.pascalize(_name_92);
                    _builder.append(_pascalize_42, "    \t");
                    _builder.append("Record.getFactory()");
                } else {
                    _builder.append("null");
                }
            }
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("}");
            _builder.newLine();
            _builder.append("    ");
            _builder.newLine();
        }
    }
    {
        Collection<CreateViewStatement> _configInitViews_4 = ModelUtil.getConfigInitViews(model);
        for (final CreateViewStatement view_1 : _configInitViews_4) {
            {
                boolean _hasAndroidPrimaryKey_25 = ModelUtil.hasAndroidPrimaryKey(view_1);
                if (_hasAndroidPrimaryKey_25) {
                    _builder.append("    ");
                    _builder.append("protected ContentProviderActions create");
                    String _name_93 = view_1.getName();
                    String _pascalize_43 = Strings.pascalize(_name_93);
                    _builder.append(_pascalize_43, "    ");
                    _builder.append("ByIdActions() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("\t");
                    _builder.append("return new DefaultContentProviderActions(Sources.");
                    String _name_94 = view_1.getName();
                    String _underscore_46 = Strings.underscore(_name_94);
                    String _upperCase_46 = _underscore_46.toUpperCase();
                    _builder.append(_upperCase_46, "    \t");
                    _builder.append(", true, ");
                    {
                        boolean _hasAndroidPrimaryKey_26 = ModelUtil.hasAndroidPrimaryKey(view_1);
                        if (_hasAndroidPrimaryKey_26) {
                            String _name_95 = view_1.getName();
                            String _pascalize_44 = Strings.pascalize(_name_95);
                            _builder.append(_pascalize_44, "    \t");
                            _builder.append("Record.getFactory()");
                        } else {
                            _builder.append("null");
                        }
                    }
                    _builder.append(");");
                    _builder.newLineIfNotEmpty();
                    _builder.append("    ");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("    ");
                    _builder.newLine();
                }
            }
            _builder.append("    ");
            _builder.append("protected ContentProviderActions create");
            String _name_96 = view_1.getName();
            String _pascalize_45 = Strings.pascalize(_name_96);
            _builder.append(_pascalize_45, "    ");
            _builder.append("Actions() {");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("\t");
            _builder.append("return new DefaultContentProviderActions(Sources.");
            String _name_97 = view_1.getName();
            String _underscore_47 = Strings.underscore(_name_97);
            String _upperCase_47 = _underscore_47.toUpperCase();
            _builder.append(_upperCase_47, "    \t");
            _builder.append(", false, ");
            {
                boolean _hasAndroidPrimaryKey_27 = ModelUtil.hasAndroidPrimaryKey(view_1);
                if (_hasAndroidPrimaryKey_27) {
                    String _name_98 = view_1.getName();
                    String _pascalize_46 = Strings.pascalize(_name_98);
                    _builder.append(_pascalize_46, "    \t");
                    _builder.append("Record.getFactory()");
                } else {
                    _builder.append("null");
                }
            }
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("    ");
            _builder.append("}");
            _builder.newLine();
            _builder.append("    ");
            _builder.newLine();
        }
    }
    {
        DatabaseBlock _database_21 = model.getDatabase();
        ConfigBlock _config_8 = _database_21.getConfig();
        boolean _notEquals_4 = (!Objects.equal(_config_8, null));
        if (_notEquals_4) {
            {
                DatabaseBlock _database_22 = model.getDatabase();
                ConfigBlock _config_9 = _database_22.getConfig();
                EList<ConfigurationStatement> _statements_4 = _config_9.getStatements();
                Iterable<ActionStatement> _filter_5 = Iterables.<ActionStatement>filter(_statements_4, ActionStatement.class);
                for (final ActionStatement a_4 : _filter_5) {
                    _builder.append("\t");
                    _builder.append("protected ContentProviderActions create");
                    String _name_99 = a_4.getName();
                    String _pascalize_47 = Strings.pascalize(_name_99);
                    _builder.append(_pascalize_47, "\t");
                    _builder.append("Actions() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return new ContentProviderActions();");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
        }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : ActionStatement(com.robotoworks.mechanoid.db.sqliteModel.ActionStatement) DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) ContentUri(com.robotoworks.mechanoid.db.sqliteModel.ContentUri) CreateTableStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ConfigurationStatement(com.robotoworks.mechanoid.db.sqliteModel.ConfigurationStatement) ConfigBlock(com.robotoworks.mechanoid.db.sqliteModel.ConfigBlock) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Collection(java.util.Collection)

Example 2 with CreateViewStatement

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

the class SqliteModelGenerator method doGenerate.

public void doGenerate(final Resource resource, final IFileSystemAccess fsa) {
    EList<EObject> _contents = resource.getContents();
    EObject _head = IterableExtensions.<EObject>head(_contents);
    Model model = ((Model) _head);
    SqliteDatabaseSnapshot.Builder _get = this.mDbSnapshotBuilderProvider.get();
    final SqliteDatabaseSnapshot snapshot = _get.build(model);
    String _packageName = model.getPackageName();
    DatabaseBlock _database = model.getDatabase();
    String _name = _database.getName();
    String _pascalize = Strings.pascalize(_name);
    String _concat = "Abstract".concat(_pascalize);
    String _concat_1 = _concat.concat("OpenHelper");
    String _resolveFileName = Strings.resolveFileName(_packageName, _concat_1);
    CharSequence _generate = this.mOpenHelperGenerator.generate(model, snapshot);
    fsa.generateFile(_resolveFileName, _generate);
    String _packageName_1 = model.getPackageName();
    DatabaseBlock _database_1 = model.getDatabase();
    String _name_1 = _database_1.getName();
    String _pascalize_1 = Strings.pascalize(_name_1);
    String _concat_2 = _pascalize_1.concat("OpenHelper");
    String _resolveFileName_1 = Strings.resolveFileName(_packageName_1, _concat_2);
    CharSequence _generateStub = this.mOpenHelperGenerator.generateStub(model, snapshot);
    fsa.generateFile(_resolveFileName_1, MechanoidOutputConfigurationProvider.DEFAULT_STUB_OUTPUT, _generateStub);
    String _packageName_2 = model.getPackageName();
    DatabaseBlock _database_2 = model.getDatabase();
    String _name_2 = _database_2.getName();
    String _pascalize_2 = Strings.pascalize(_name_2);
    String _concat_3 = _pascalize_2.concat("Contract");
    String _resolveFileName_2 = Strings.resolveFileName(_packageName_2, _concat_3);
    CharSequence _generate_1 = this.mContentProviderContractGenerator.generate(model, snapshot);
    fsa.generateFile(_resolveFileName_2, _generate_1);
    String _packageName_3 = model.getPackageName();
    DatabaseBlock _database_3 = model.getDatabase();
    String _name_3 = _database_3.getName();
    String _pascalize_3 = Strings.pascalize(_name_3);
    String _concat_4 = "Abstract".concat(_pascalize_3);
    String _concat_5 = _concat_4.concat("ContentProvider");
    String _resolveFileName_3 = Strings.resolveFileName(_packageName_3, _concat_5);
    CharSequence _generate_2 = this.mContentProviderGenerator.generate(model, snapshot);
    fsa.generateFile(_resolveFileName_3, _generate_2);
    String _packageName_4 = model.getPackageName();
    DatabaseBlock _database_4 = model.getDatabase();
    String _name_4 = _database_4.getName();
    String _pascalize_4 = Strings.pascalize(_name_4);
    String _concat_6 = _pascalize_4.concat("ContentProvider");
    String _resolveFileName_4 = Strings.resolveFileName(_packageName_4, _concat_6);
    CharSequence _generateStub_1 = this.mContentProviderGenerator.generateStub(model, snapshot);
    fsa.generateFile(_resolveFileName_4, MechanoidOutputConfigurationProvider.DEFAULT_STUB_OUTPUT, _generateStub_1);
    Collection<CreateTableStatement> _tables = snapshot.getTables();
    final Consumer<CreateTableStatement> _function = new Consumer<CreateTableStatement>() {

        public void accept(final CreateTableStatement statement) {
            SqliteModelGenerator.this.generateActiveRecordEntity(resource, fsa, ((CreateTableStatement) statement));
        }
    };
    _tables.forEach(_function);
    Collection<CreateViewStatement> _views = snapshot.getViews();
    final Consumer<CreateViewStatement> _function_1 = new Consumer<CreateViewStatement>() {

        public void accept(final CreateViewStatement statement) {
            SqliteModelGenerator.this.generateActiveRecordEntity(resource, fsa, ((CreateViewStatement) statement));
        }
    };
    _views.forEach(_function_1);
    Collection<CreateTableStatement> _configInitTables = ModelUtil.getConfigInitTables(model);
    final Consumer<CreateTableStatement> _function_2 = new Consumer<CreateTableStatement>() {

        public void accept(final CreateTableStatement statement) {
            SqliteModelGenerator.this.generateActiveRecordEntity(resource, fsa, ((CreateTableStatement) statement));
        }
    };
    _configInitTables.forEach(_function_2);
    Collection<CreateViewStatement> _configInitViews = ModelUtil.getConfigInitViews(model);
    final Consumer<CreateViewStatement> _function_3 = new Consumer<CreateViewStatement>() {

        public void accept(final CreateViewStatement statement) {
            SqliteModelGenerator.this.generateActiveRecordEntity(resource, fsa, ((CreateViewStatement) statement));
        }
    };
    _configInitViews.forEach(_function_3);
    DatabaseBlock _database_5 = model.getDatabase();
    EList<MigrationBlock> _migrations = _database_5.getMigrations();
    final Procedure2<MigrationBlock, Integer> _function_4 = new Procedure2<MigrationBlock, Integer>() {

        public void apply(final MigrationBlock item, final Integer index) {
            SqliteModelGenerator.this.generateMigration(resource, fsa, item, ((index).intValue() + 1));
        }
    };
    IterableExtensions.<MigrationBlock>forEach(_migrations, _function_4);
}
Also used : SqliteDatabaseSnapshot(com.robotoworks.mechanoid.db.generator.SqliteDatabaseSnapshot) DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) CreateTableStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock) Consumer(java.util.function.Consumer) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) EObject(org.eclipse.emf.ecore.EObject) Model(com.robotoworks.mechanoid.db.sqliteModel.Model)

Example 3 with CreateViewStatement

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

the class SqliteOpenHelperGenerator method generate.

public CharSequence generate(final Model model, final SqliteDatabaseSnapshot snapshot) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/*");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* Generated by Robotoworks Mechanoid");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("package ");
    String _packageName = model.getPackageName();
    _builder.append(_packageName, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("import android.content.Context;");
    _builder.newLine();
    _builder.append("import android.database.sqlite.SQLiteDatabase;");
    _builder.newLine();
    _builder.append("import com.robotoworks.mechanoid.db.MechanoidSQLiteOpenHelper;");
    _builder.newLine();
    _builder.append("import com.robotoworks.mechanoid.db.SQLiteMigration;");
    _builder.newLine();
    _builder.newLine();
    {
        DatabaseBlock _database = model.getDatabase();
        EList<MigrationBlock> _migrations = _database.getMigrations();
        int _size = _migrations.size();
        boolean _greaterThan = (_size > 0);
        if (_greaterThan) {
            int version = 0;
            _builder.newLineIfNotEmpty();
            {
                DatabaseBlock _database_1 = model.getDatabase();
                EList<MigrationBlock> _migrations_1 = _database_1.getMigrations();
                for (final MigrationBlock migration : _migrations_1) {
                    _builder.append("import ");
                    String _packageName_1 = model.getPackageName();
                    _builder.append(_packageName_1, "");
                    _builder.append(".migrations.Default");
                    DatabaseBlock _database_2 = model.getDatabase();
                    String _name = _database_2.getName();
                    String _pascalize = Strings.pascalize(_name);
                    _builder.append(_pascalize, "");
                    _builder.append("MigrationV");
                    _builder.append(version = (version + 1), "");
                    _builder.append(";");
                    _builder.newLineIfNotEmpty();
                }
            }
        }
    }
    _builder.newLine();
    _builder.append("public abstract class Abstract");
    DatabaseBlock _database_3 = model.getDatabase();
    String _name_1 = _database_3.getName();
    String _pascalize_1 = Strings.pascalize(_name_1);
    _builder.append(_pascalize_1, "");
    _builder.append("OpenHelper extends MechanoidSQLiteOpenHelper {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("private static final String DATABASE_NAME = \"");
    DatabaseBlock _database_4 = model.getDatabase();
    String _name_2 = _database_4.getName();
    _builder.append(_name_2, "\t");
    _builder.append(".db\";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static final int VERSION = ");
    DatabaseBlock _database_5 = model.getDatabase();
    EList<MigrationBlock> _migrations_2 = _database_5.getMigrations();
    int _size_1 = _migrations_2.size();
    _builder.append(_size_1, "\t");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public interface Sources {");
    _builder.newLine();
    {
        Collection<CreateTableStatement> _tables = snapshot.getTables();
        for (final CreateTableStatement table : _tables) {
            _builder.append("\t\t");
            _builder.append("String ");
            String _name_3 = table.getName();
            String _underscore = Strings.underscore(_name_3);
            String _upperCase = _underscore.toUpperCase();
            _builder.append(_upperCase, "\t\t");
            _builder.append(" = \"");
            String _name_4 = table.getName();
            _builder.append(_name_4, "\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        Collection<CreateViewStatement> _views = snapshot.getViews();
        for (final CreateViewStatement view : _views) {
            _builder.append("\t\t");
            _builder.append("String ");
            String _name_5 = view.getName();
            String _underscore_1 = Strings.underscore(_name_5);
            String _upperCase_1 = _underscore_1.toUpperCase();
            _builder.append(_upperCase_1, "\t\t");
            _builder.append(" = \"");
            String _name_6 = view.getName();
            _builder.append(_name_6, "\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        Collection<CreateTableStatement> _configInitTables = ModelUtil.getConfigInitTables(model);
        for (final CreateTableStatement table_1 : _configInitTables) {
            _builder.append("\t\t");
            _builder.append("String ");
            String _name_7 = table_1.getName();
            String _underscore_2 = Strings.underscore(_name_7);
            String _upperCase_2 = _underscore_2.toUpperCase();
            _builder.append(_upperCase_2, "\t\t");
            _builder.append(" = \"");
            String _name_8 = table_1.getName();
            _builder.append(_name_8, "\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        Collection<CreateViewStatement> _configInitViews = ModelUtil.getConfigInitViews(model);
        for (final CreateViewStatement view_1 : _configInitViews) {
            _builder.append("\t\t");
            _builder.append("String ");
            String _name_9 = view_1.getName();
            String _underscore_3 = Strings.underscore(_name_9);
            String _upperCase_3 = _underscore_3.toUpperCase();
            _builder.append(_upperCase_3, "\t\t");
            _builder.append(" = \"");
            String _name_10 = view_1.getName();
            _builder.append(_name_10, "\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Abstract");
    DatabaseBlock _database_6 = model.getDatabase();
    String _name_11 = _database_6.getName();
    String _pascalize_2 = Strings.pascalize(_name_11);
    _builder.append(_pascalize_2, "\t");
    _builder.append("OpenHelper(Context context) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("super(context, DATABASE_NAME, null, VERSION);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public Abstract");
    DatabaseBlock _database_7 = model.getDatabase();
    String _name_12 = _database_7.getName();
    String _pascalize_3 = Strings.pascalize(_name_12);
    _builder.append(_pascalize_3, "\t");
    _builder.append("OpenHelper(Context context, String name) {");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("super(context, name, null, VERSION);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public void onCreate(SQLiteDatabase db) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("applyMigrations(db, 0, VERSION);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    {
        DatabaseBlock _database_8 = model.getDatabase();
        InitBlock _init = _database_8.getInit();
        boolean _notEquals = (!Objects.equal(_init, null));
        if (_notEquals) {
            _builder.append("\t");
            _builder.append("@Override");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public void onOpen(SQLiteDatabase db) {");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("super.onOpen(db);");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            DatabaseBlock _database_9 = model.getDatabase();
            InitBlock _init_1 = _database_9.getInit();
            EList<DDLStatement> _statements = _init_1.getStatements();
            CharSequence _generateStatements = this._sqliteDatabaseStatementGenerator.generateStatements(_statements);
            _builder.append(_generateStatements, "\t\t");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append("}");
            _builder.newLine();
        }
    }
    _builder.newLine();
    _builder.append("\t");
    _builder.append("@Override");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("protected SQLiteMigration createMigration(int version) {");
    _builder.newLine();
    {
        DatabaseBlock _database_10 = model.getDatabase();
        EList<MigrationBlock> _migrations_3 = _database_10.getMigrations();
        int _size_2 = _migrations_3.size();
        boolean _greaterThan_1 = (_size_2 > 0);
        if (_greaterThan_1) {
            _builder.append("\t\t");
            int version_1 = (-1);
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("switch(version) {");
            _builder.newLine();
            {
                DatabaseBlock _database_11 = model.getDatabase();
                EList<MigrationBlock> _migrations_4 = _database_11.getMigrations();
                for (final MigrationBlock migration_1 : _migrations_4) {
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("case ");
                    _builder.append(version_1 = (version_1 + 1), "\t\t\t");
                    _builder.append(":");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return create");
                    DatabaseBlock _database_12 = model.getDatabase();
                    String _name_13 = _database_12.getName();
                    String _pascalize_4 = Strings.pascalize(_name_13);
                    _builder.append(_pascalize_4, "\t\t\t\t");
                    _builder.append("MigrationV");
                    _builder.append((version_1 + 1), "\t\t\t\t");
                    _builder.append("();");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("default:");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("throw new IllegalStateException(\"No migration for version \" + version);");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
        } else {
            _builder.append("\t\t");
            _builder.append("throw new IllegalStateException(\"No migrations for any version\");");
            _builder.newLine();
        }
    }
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    {
        DatabaseBlock _database_13 = model.getDatabase();
        EList<MigrationBlock> _migrations_5 = _database_13.getMigrations();
        int _size_3 = _migrations_5.size();
        boolean _greaterThan_2 = (_size_3 > 0);
        if (_greaterThan_2) {
            _builder.append("\t");
            int version_2 = 0;
            _builder.newLineIfNotEmpty();
            {
                DatabaseBlock _database_14 = model.getDatabase();
                EList<MigrationBlock> _migrations_6 = _database_14.getMigrations();
                for (final MigrationBlock migration_2 : _migrations_6) {
                    _builder.append("\t");
                    _builder.append("protected SQLiteMigration create");
                    DatabaseBlock _database_15 = model.getDatabase();
                    String _name_14 = _database_15.getName();
                    String _pascalize_5 = Strings.pascalize(_name_14);
                    _builder.append(_pascalize_5, "\t");
                    _builder.append("MigrationV");
                    _builder.append(version_2 = (version_2 + 1), "\t");
                    _builder.append("() {");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("\t");
                    _builder.append("return new Default");
                    DatabaseBlock _database_16 = model.getDatabase();
                    String _name_15 = _database_16.getName();
                    String _pascalize_6 = Strings.pascalize(_name_15);
                    _builder.append(_pascalize_6, "\t\t");
                    _builder.append("MigrationV");
                    _builder.append(version_2, "\t\t");
                    _builder.append("();");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.append("}");
                    _builder.newLine();
                }
            }
        }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) EList(org.eclipse.emf.common.util.EList) CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) CreateTableStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement) InitBlock(com.robotoworks.mechanoid.db.sqliteModel.InitBlock) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Collection(java.util.Collection) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)

Example 4 with CreateViewStatement

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

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

the class ContentProviderContractGenerator method generateContractItem.

public CharSequence generateContractItem(final Model model, final SqliteDatabaseSnapshot snapshot, final TableDefinition stmt) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("/**");
    _builder.newLine();
    _builder.append(" ");
    _builder.append("* <p>Column definitions and helper methods to work with the ");
    String _name = stmt.getName();
    String _pascalize = Strings.pascalize(_name);
    _builder.append(_pascalize, " ");
    _builder.append(".</p>");
    _builder.newLineIfNotEmpty();
    _builder.append(" ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("public static class ");
    String _name_1 = stmt.getName();
    String _pascalize_1 = Strings.pascalize(_name_1);
    _builder.append(_pascalize_1, "");
    _builder.append(" implements ");
    String _name_2 = stmt.getName();
    String _pascalize_2 = Strings.pascalize(_name_2);
    _builder.append(_pascalize_2, "");
    _builder.append("Columns");
    {
        boolean _hasAndroidPrimaryKey = this.hasAndroidPrimaryKey(stmt);
        if (_hasAndroidPrimaryKey) {
            _builder.append(", BaseColumns");
        }
    }
    _builder.append(" {");
    _builder.newLineIfNotEmpty();
    _builder.append("    ");
    _builder.append("public static final Uri CONTENT_URI = ");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("BASE_CONTENT_URI.buildUpon().appendPath(\"");
    String _name_3 = stmt.getName();
    _builder.append(_name_3, "\t\t\t");
    _builder.append("\").build();");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* <p>The content type for a cursor that contains many ");
    String _name_4 = stmt.getName();
    String _pascalize_3 = Strings.pascalize(_name_4);
    _builder.append(_pascalize_3, "\t ");
    _builder.append(" rows.</p>");
    _builder.newLineIfNotEmpty();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public static final String CONTENT_TYPE =");
    _builder.newLine();
    _builder.append("            ");
    _builder.append("\"vnd.android.cursor.dir/vnd.");
    DatabaseBlock _database = model.getDatabase();
    String _name_5 = _database.getName();
    String _lowerCase = _name_5.toLowerCase();
    _builder.append(_lowerCase, "            ");
    _builder.append(".");
    String _name_6 = stmt.getName();
    _builder.append(_name_6, "            ");
    _builder.append("\";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
        boolean _hasAndroidPrimaryKey_1 = this.hasAndroidPrimaryKey(stmt);
        if (_hasAndroidPrimaryKey_1) {
            _builder.append("\t");
            _builder.append("/**");
            _builder.newLine();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("* <p>The content type for a cursor that contains a single ");
            String _name_7 = stmt.getName();
            String _pascalize_4 = Strings.pascalize(_name_7);
            _builder.append(_pascalize_4, "\t ");
            _builder.append(" row.</p>");
            _builder.newLineIfNotEmpty();
            _builder.append("\t");
            _builder.append(" ");
            _builder.append("*/");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("public static final String ITEM_CONTENT_TYPE =");
            _builder.newLine();
            _builder.append("\t");
            _builder.append("\t");
            _builder.append("\"vnd.android.cursor.item/vnd.");
            DatabaseBlock _database_1 = model.getDatabase();
            String _name_8 = _database_1.getName();
            String _lowerCase_1 = _name_8.toLowerCase();
            _builder.append(_lowerCase_1, "\t\t");
            _builder.append(".");
            String _name_9 = stmt.getName();
            _builder.append(_name_9, "\t\t");
            _builder.append("\";");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* <p>Builds a Uri with appended id for a row in ");
    String _name_10 = stmt.getName();
    String _pascalize_5 = Strings.pascalize(_name_10);
    _builder.append(_pascalize_5, "\t ");
    _builder.append(", ");
    _builder.newLineIfNotEmpty();
    _builder.append("\t ");
    _builder.append("* eg:- content://");
    String _packageName = model.getPackageName();
    _builder.append(_packageName, "\t ");
    _builder.append(".");
    DatabaseBlock _database_2 = model.getDatabase();
    String _name_11 = _database_2.getName();
    String _lowerCase_2 = _name_11.toLowerCase();
    _builder.append(_lowerCase_2, "\t ");
    _builder.append("/");
    String _name_12 = stmt.getName();
    String _lowerCase_3 = _name_12.toLowerCase();
    _builder.append(_lowerCase_3, "\t ");
    _builder.append("/123.</p>");
    _builder.newLineIfNotEmpty();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("public static Uri buildUriWithId(long id) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("return CONTENT_URI.buildUpon().appendPath(String.valueOf(id)).build();");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    String _name_13 = stmt.getName();
    Iterable<ActionStatement> actions = this.findActionsForDefinition(model, _name_13);
    _builder.newLineIfNotEmpty();
    {
        boolean _notEquals = (!Objects.equal(actions, null));
        if (_notEquals) {
            {
                for (final ActionStatement action : actions) {
                    _builder.append("\t");
                    CharSequence _createActionUriBuilderMethod = this.createActionUriBuilderMethod(action);
                    _builder.append(_createActionUriBuilderMethod, "\t");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t");
                    _builder.newLine();
                }
            }
        }
    }
    _builder.append("\t");
    _builder.append("public static int delete() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return Mechanoid.getContentResolver().delete(");
    String _name_14 = stmt.getName();
    String _pascalize_6 = Strings.pascalize(_name_14);
    _builder.append(_pascalize_6, "\t\t");
    _builder.append(".CONTENT_URI, null, null);");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static int delete(String where, String[] selectionArgs) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return Mechanoid.getContentResolver().delete(");
    String _name_15 = stmt.getName();
    String _pascalize_7 = Strings.pascalize(_name_15);
    _builder.append(_pascalize_7, "\t\t");
    _builder.append(".CONTENT_URI, where, selectionArgs);");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* <p>Create a new Builder for ");
    String _name_16 = stmt.getName();
    String _pascalize_8 = Strings.pascalize(_name_16);
    _builder.append(_pascalize_8, "\t ");
    _builder.append("</p>");
    _builder.newLineIfNotEmpty();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static Builder newBuilder() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return new Builder();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("/**");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* <p>Build and execute insert or update statements for ");
    String _name_17 = stmt.getName();
    String _pascalize_9 = Strings.pascalize(_name_17);
    _builder.append(_pascalize_9, "\t ");
    _builder.append(".</p>");
    _builder.newLineIfNotEmpty();
    _builder.append("\t ");
    _builder.append("*");
    _builder.newLine();
    _builder.append("\t ");
    _builder.append("* <p>Use {@link ");
    String _name_18 = stmt.getName();
    String _pascalize_10 = Strings.pascalize(_name_18);
    _builder.append(_pascalize_10, "\t ");
    _builder.append("#newBuilder()} to create new builder</p>");
    _builder.newLineIfNotEmpty();
    _builder.append("\t ");
    _builder.append("*/");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("public static class Builder extends AbstractValuesBuilder {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("private Builder() {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("super(Mechanoid.getApplicationContext(), ");
    String _name_19 = stmt.getName();
    String _pascalize_11 = Strings.pascalize(_name_19);
    _builder.append(_pascalize_11, "\t\t\t");
    _builder.append(".CONTENT_URI);");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    CharSequence _generateBuilderSetters = this.generateBuilderSetters(stmt);
    _builder.append(_generateBuilderSetters, "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static final Set<Uri> VIEW_URIS;");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("HashSet<Uri> viewUris =  new HashSet<Uri>();");
    _builder.newLine();
    _builder.newLine();
    {
        HashSet<CreateViewStatement> _allViewsReferencingTable = ModelUtil.getAllViewsReferencingTable(snapshot, stmt);
        final Function1<CreateViewStatement, String> _function = new Function1<CreateViewStatement, String>() {

            public String apply(final CreateViewStatement x) {
                return x.getName();
            }
        };
        List<CreateViewStatement> _sortBy = IterableExtensions.<CreateViewStatement, String>sortBy(_allViewsReferencingTable, _function);
        for (final CreateViewStatement ref : _sortBy) {
            _builder.append("\t\t");
            _builder.append("viewUris.add(");
            String _name_20 = ref.getName();
            String _pascalize_12 = Strings.pascalize(_name_20);
            _builder.append(_pascalize_12, "\t\t");
            _builder.append(".CONTENT_URI);");
            _builder.newLineIfNotEmpty();
        }
    }
    {
        HashSet<CreateViewStatement> _allViewsInConfigInitReferencingTable = ModelUtil.getAllViewsInConfigInitReferencingTable(model, stmt);
        final Function1<CreateViewStatement, String> _function_1 = new Function1<CreateViewStatement, String>() {

            public String apply(final CreateViewStatement x) {
                return x.getName();
            }
        };
        List<CreateViewStatement> _sortBy_1 = IterableExtensions.<CreateViewStatement, String>sortBy(_allViewsInConfigInitReferencingTable, _function_1);
        for (final CreateViewStatement ref_1 : _sortBy_1) {
            _builder.append("\t\t");
            _builder.append("viewUris.add(");
            String _name_21 = ref_1.getName();
            String _pascalize_13 = Strings.pascalize(_name_21);
            _builder.append(_pascalize_13, "\t\t");
            _builder.append(".CONTENT_URI);");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("VIEW_URIS = Collections.unmodifiableSet(viewUris);");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : ActionStatement(com.robotoworks.mechanoid.db.sqliteModel.ActionStatement) DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) CreateViewStatement(com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)15 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)6 DatabaseBlock (com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock)6 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)5 EObject (org.eclipse.emf.ecore.EObject)4 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 TableDefinition (com.robotoworks.mechanoid.db.sqliteModel.TableDefinition)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 EList (org.eclipse.emf.common.util.EList)3 ActionStatement (com.robotoworks.mechanoid.db.sqliteModel.ActionStatement)2 ColumnSource (com.robotoworks.mechanoid.db.sqliteModel.ColumnSource)2 InitBlock (com.robotoworks.mechanoid.db.sqliteModel.InitBlock)2 MigrationBlock (com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Function (com.google.common.base.Function)1 SqliteDatabaseSnapshot (com.robotoworks.mechanoid.db.generator.SqliteDatabaseSnapshot)1 AlterTableAddColumnStatement (com.robotoworks.mechanoid.db.sqliteModel.AlterTableAddColumnStatement)1