Search in sources :

Example 6 with MigrationBlock

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;
}
Also used : EList(org.eclipse.emf.common.util.EList) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock) StatementSequenceValidatorResult(com.robotoworks.mechanoid.db.validation.StatementSequenceValidatorResult)

Example 7 with MigrationBlock

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);
        }
    });
}
Also used : IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Model(com.robotoworks.mechanoid.db.sqliteModel.Model) XtextResource(org.eclipse.xtext.resource.XtextResource) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 8 with MigrationBlock

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DatabaseBlock(com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) Model(com.robotoworks.mechanoid.db.sqliteModel.Model) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock) URI(org.eclipse.emf.common.util.URI) IResource(org.eclipse.core.resources.IResource)

Example 9 with MigrationBlock

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)));
}
Also used : EList(org.eclipse.emf.common.util.EList) DDLStatement(com.robotoworks.mechanoid.db.sqliteModel.DDLStatement) EObject(org.eclipse.emf.ecore.EObject) MigrationBlock(com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)

Aggregations

MigrationBlock (com.robotoworks.mechanoid.db.sqliteModel.MigrationBlock)9 DDLStatement (com.robotoworks.mechanoid.db.sqliteModel.DDLStatement)5 DatabaseBlock (com.robotoworks.mechanoid.db.sqliteModel.DatabaseBlock)5 InitBlock (com.robotoworks.mechanoid.db.sqliteModel.InitBlock)3 Model (com.robotoworks.mechanoid.db.sqliteModel.Model)3 ArrayList (java.util.ArrayList)3 EList (org.eclipse.emf.common.util.EList)3 CreateTableStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateTableStatement)2 CreateViewStatement (com.robotoworks.mechanoid.db.sqliteModel.CreateViewStatement)2 EObject (org.eclipse.emf.ecore.EObject)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 SqliteDatabaseSnapshot (com.robotoworks.mechanoid.db.generator.SqliteDatabaseSnapshot)1 StatementSequenceValidatorResult (com.robotoworks.mechanoid.db.validation.StatementSequenceValidatorResult)1 Collection (java.util.Collection)1 Consumer (java.util.function.Consumer)1 IResource (org.eclipse.core.resources.IResource)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1