use of com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock in project mechanoid by robotoworks.
the class StatementSequenceValidator method validate.
public StatementSequenceValidatorResult validate(final DatabaseBlock db) {
this.tables.clear();
this.views.clear();
this.triggers.clear();
this.indexes.clear();
StatementSequenceValidatorResult result = new StatementSequenceValidatorResult();
result.valid = true;
EList<MigrationBlock> _migrations = db.getMigrations();
for (final MigrationBlock migration : _migrations) {
{
EList<DDLStatement> statements = migration.getStatements();
for (final DDLStatement stmt : statements) {
{
result.source = stmt;
this.validateStatement(result, stmt);
if (result.valid) {
this.sequence(stmt);
} else {
return result;
}
}
}
}
}
return result;
}
use of com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock in project mechanoid by robotoworks.
the class NewMechanoidDBFileWizard method onNewResourceEditorOpened.
@Override
protected void onNewResourceEditorOpened(IEditorPart editor) {
final XtextEditor xeditor = (XtextEditor) editor;
final IXtextDocument document = xeditor.getDocument();
xeditor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
Model model = (Model) state.getContents().get(0);
MigrationBlock migrationBlock = model.getDatabase().getMigrations().get(0);
//$NON-NLS-1$
ILeafNode node = findFirstLeafNodeForKeyword(migrationBlock, "{");
int position = node.getOffset() + 1;
//$NON-NLS-1$
document.replace(position, 0, "\n\t\t");
xeditor.selectAndReveal(position + 3, 0);
}
});
}
use of com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock 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;
}
use of com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock in project mechanoid by robotoworks.
the class ModelUtil method forEachPreviousStatement.
/**
* walks back and visits each previous statement from the given statement, returning
* false will cancel the process
*/
public static void forEachPreviousStatement(final DDLStatement stmt, final Function1<DDLStatement, Boolean> delegate) {
EObject current = ((EObject) stmt);
MigrationBlock migration = null;
do {
{
while ((!Objects.equal(EcoreUtil2.getPreviousSibling(current), null))) {
{
EObject _previousSibling = EcoreUtil2.getPreviousSibling(current);
current = _previousSibling;
Boolean _apply = delegate.apply(((DDLStatement) current));
boolean _not = (!(_apply).booleanValue());
if (_not) {
return;
}
}
}
EObject _eContainer = current.eContainer();
EObject previousContainer = EcoreUtil2.getPreviousSibling(_eContainer);
boolean _and = false;
boolean _notEquals = (!Objects.equal(previousContainer, null));
if (!_notEquals) {
_and = false;
} else {
_and = (previousContainer instanceof MigrationBlock);
}
if (_and) {
migration = ((MigrationBlock) previousContainer);
EList<DDLStatement> _statements = migration.getStatements();
DDLStatement _last = IterableExtensions.<DDLStatement>last(_statements);
current = _last;
boolean _equals = Objects.equal(current, null);
if (_equals) {
return;
}
Boolean _apply = delegate.apply(((DDLStatement) current));
boolean _not = (!(_apply).booleanValue());
if (_not) {
return;
}
} else {
migration = null;
}
}
} while ((!Objects.equal(migration, null)));
}
Aggregations