use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class XSqliteModelScopeProvider method scope_SingleSourceTable_tableReference.
public IScope scope_SingleSourceTable_tableReference(final SingleSourceTable tbl, final EReference reference) {
DDLStatement stmt = ModelUtil.<DDLStatement>getAncestorOfType(tbl, DDLStatement.class);
boolean _notEquals = (!Objects.equal(stmt, null));
if (_notEquals) {
return this.scopeForTableDefinitionsBeforeStatement(stmt, false);
}
DatabaseBlock db = ModelUtil.<DatabaseBlock>getAncestorOfType(tbl, DatabaseBlock.class);
return this.scopeForTableDefinitionsBeforeStatement(db, stmt, true);
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ContentProviderContractGenerator method generateContractItemsForActions.
public CharSequence generateContractItemsForActions(final Model model, final SqliteDatabaseSnapshot snapshot) {
StringConcatenation _builder = new StringConcatenation();
{
DatabaseBlock _database = model.getDatabase();
ConfigBlock _config = _database.getConfig();
boolean _notEquals = (!Objects.equal(_config, null));
if (_notEquals) {
{
DatabaseBlock _database_1 = model.getDatabase();
ConfigBlock _config_1 = _database_1.getConfig();
EList<ConfigurationStatement> _statements = _config_1.getStatements();
Iterable<ActionStatement> _filter = Iterables.<ActionStatement>filter(_statements, ActionStatement.class);
final Function1<ActionStatement, Boolean> _function = new Function1<ActionStatement, Boolean>() {
public Boolean apply(final ActionStatement it) {
ContentUri _uri = it.getUri();
String _type = _uri.getType();
boolean _containsDefinition = snapshot.containsDefinition(_type);
return Boolean.valueOf((!_containsDefinition));
}
};
Iterable<ActionStatement> _filter_1 = IterableExtensions.<ActionStatement>filter(_filter, _function);
for (final ActionStatement action : _filter_1) {
_builder.append("public static class ");
ContentUri _uri = action.getUri();
String _type = _uri.getType();
String _pascalize = Strings.pascalize(_type);
_builder.append(_pascalize, "");
_builder.append(" {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
CharSequence _createActionUriBuilderMethod = this.createActionUriBuilderMethod(action);
_builder.append(_createActionUriBuilderMethod, "\t");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("public static final String CONTENT_TYPE =");
_builder.newLine();
_builder.append("\t ");
_builder.append("\"vnd.android.cursor.dir/vnd.");
DatabaseBlock _database_2 = model.getDatabase();
String _name = _database_2.getName();
String _lowerCase = _name.toLowerCase();
_builder.append(_lowerCase, "\t ");
_builder.append(".");
ContentUri _uri_1 = action.getUri();
String _type_1 = _uri_1.getType();
_builder.append(_type_1, "\t ");
_builder.append("\";");
_builder.newLineIfNotEmpty();
_builder.append("}");
_builder.newLine();
_builder.newLine();
}
}
}
}
return _builder;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class SqliteMigrationGenerator method generate.
public CharSequence generate(final Model model, final MigrationBlock migration, final int version) {
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(".migrations;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import android.database.sqlite.SQLiteDatabase;");
_builder.newLine();
_builder.append("import com.robotoworks.mechanoid.db.SQLiteMigration;");
_builder.newLine();
_builder.newLine();
_builder.append("public class Default");
DatabaseBlock _database = model.getDatabase();
String _name = _database.getName();
String _pascalize = Strings.pascalize(_name);
_builder.append(_pascalize, "");
_builder.append("MigrationV");
_builder.append(version, "");
_builder.append(" extends SQLiteMigration {");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void onBeforeUp(SQLiteDatabase db) {}");
_builder.newLine();
_builder.append("\t");
_builder.newLine();
_builder.append("\t");
_builder.append("@Override");
_builder.newLine();
_builder.append("\t");
_builder.append("public void up(SQLiteDatabase db) {");
_builder.newLine();
_builder.append("\t\t");
EList<DDLStatement> _statements = migration.getStatements();
CharSequence _generateStatements = this._sqliteDatabaseStatementGenerator.generateStatements(_statements);
_builder.append(_generateStatements, "\t\t");
_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("public void onAfterUp(SQLiteDatabase db) {}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class ModelUtil method getConfigInitViews.
public static Collection<CreateViewStatement> getConfigInitViews(final Model model) {
final ArrayList<CreateViewStatement> items = Lists.<CreateViewStatement>newArrayList();
DatabaseBlock _database = model.getDatabase();
InitBlock _init = _database.getInit();
boolean _notEquals = (!Objects.equal(_init, null));
if (_notEquals) {
DatabaseBlock _database_1 = model.getDatabase();
InitBlock _init_1 = _database_1.getInit();
EList<DDLStatement> _statements = _init_1.getStatements();
Iterable<CreateViewStatement> _filter = Iterables.<CreateViewStatement>filter(_statements, CreateViewStatement.class);
Iterables.<CreateViewStatement>addAll(items, _filter);
}
return items;
}
use of com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock in project mechanoid by robotoworks.
the class NewMechanoidDBFileWizard method createElementResource.
@Override
protected IResource createElementResource(IProgressMonitor monitor, IPath path) {
try {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(Messages.NewMechanoidDBFileWizard_Progress_Message, 2);
URI newEmfResourceURI = URI.createURI(//$NON-NLS-1$
"platform:/resource" + path.toPortableString());
Resource emfResource = mResourceSet.createResource(newEmfResourceURI);
Model model = SqliteModelFactory.eINSTANCE.createModel();
model.setPackageName(mSelectedPackageName);
emfResource.getContents().add(model);
DatabaseBlock database = (DatabaseBlock) SqliteModelFactory.eINSTANCE.createDatabaseBlock();
database.setName(mSelectedElementName);
model.setDatabase(database);
MigrationBlock migration = (MigrationBlock) SqliteModelFactory.eINSTANCE.createMigrationBlock();
database.getMigrations().add(migration);
emfResource.save(Collections.EMPTY_MAP);
monitor.worked(1);
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(newEmfResourceURI.toPlatformString(true));
monitor.worked(2);
return resource;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations