Search in sources :

Example 1 with SqliteDatabaseSnapshot

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

Aggregations

SqliteDatabaseSnapshot (com.robotoworks.mechanoid.db.generator.SqliteDatabaseSnapshot)1 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)1 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)1 DatabaseBlock (com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock)1 MigrationBlock (com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)1 Model (com.robotoworks.mechanoid.db.sqliteModel.Model)1 Consumer (java.util.function.Consumer)1 EObject (org.eclipse.emf.ecore.EObject)1 Procedure2 (org.eclipse.xtext.xbase.lib.Procedures.Procedure2)1