Search in sources :

Example 11 with DataBase

use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.

the class DatabaseComparisonTestSuite method loadAndProcessInputs.

/**
 * Loads the input models found at the given URIs. Then processes their
 * contents and places the result in a new Resource with the given desired
 * URI. That URI is the same as the URI of the expected output model, so
 * that EMF Compare has no problem matching the resources. This method
 * <i>does not</i> modify the input models.
 *
 * @param inputURI
 *            the URI of the input model.
 * @param desiredSynchronizedInputURI
 *            the desired URI for the result of the processing of the inputs
 *            of this test suite. Should be the same as that of the expected
 *            output.
 * @return the resource containing the result of processing the inputs of
 *         this test suite.
 */
public Resource loadAndProcessInputs(List<URI> inputURIs, URI desiredProcessedInputURI) {
    // Load input data for the test
    final Resource leftDatabaseResource = DatabaseCompareAbstractTestSuite.loadResource(inputURIs.get(0));
    final Resource rightDatabaseResource = DatabaseCompareAbstractTestSuite.loadResource(inputURIs.get(1));
    // Compare the Database models
    final DataBase leftDatabase = (DataBase) leftDatabaseResource.getContents().get(0);
    final DataBase rightDatabase = (DataBase) rightDatabaseResource.getContents().get(0);
    final Comparison comparison = EMFCompareUtils.compare(leftDatabase, rightDatabase);
    // Store the resulting Comparison into an EMF Resource
    final Resource comparisonResource = DatabaseCompareAbstractTestSuite.createResourceSet().createResource(desiredProcessedInputURI);
    comparisonResource.getContents().add(comparison);
    return comparisonResource;
}
Also used : Comparison(org.eclipse.emf.compare.Comparison) Resource(org.eclipse.emf.ecore.resource.Resource) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 12 with DataBase

use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.

the class ImportRunnable method execute.

@Override
protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    ProgressListener progressListener = new ProgressListener() {

        private int stepsToBeDone = 0;

        public void start(int nbSteps) {
            // +2 because there is one more step to save the file
            monitor.beginTask("Importing database", nbSteps + 1);
        }

        public void progressTo(int stepsToBeDone, String message) {
            if (this.stepsToBeDone != 0) {
                monitor.worked(this.stepsToBeDone);
            }
            monitor.subTask(message);
            this.stepsToBeDone = stepsToBeDone;
        }

        public void end(String message) {
            if (this.stepsToBeDone != 0) {
                monitor.worked(this.stepsToBeDone);
            }
        }
    };
    DataBase database = DatabaseReverser.reverse(dataSourceInfos, queries, progressListener);
    if (database != null) {
        // Store the model into a file
        monitor.subTask("Saving model file");
        try {
            saveIntoFile(database, modelFilename);
            result = true;
        } catch (IOException e) {
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while saving database into model file", e));
        }
        monitor.worked(1);
    } else {
        Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error while importing database : No database found."));
    }
    monitor.done();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ProgressListener(org.obeonetwork.dsl.database.reverse.utils.ProgressListener) IOException(java.io.IOException) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 13 with DataBase

use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.

the class EntityToMLD method createSchema.

private Schema createSchema(String name) {
    if (defaultTarget instanceof DataBase) {
        Schema schema = DatabaseFactory.eINSTANCE.createSchema();
        schema.setName(name);
        ((DataBase) defaultTarget).getSchemas().add(schema);
        return schema;
    }
    return null;
}
Also used : Schema(org.obeonetwork.dsl.database.Schema) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 14 with DataBase

use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.

the class EntityToMLD method getTargetTableContainer.

protected TableContainer getTargetTableContainer(Namespace namespace) {
    if (!cacheNamespaceToTableContainer.containsKey(namespace)) {
        TableContainer target = null;
        // First we look for a schema with the right name
        String schemaName = getSchemaNameFromNamespace(namespace);
        // Look for a schema with the right name
        target = getSchemaByName(schemaName);
        if (target == null) {
            if (defaultTarget instanceof Schema) {
                if (((Schema) defaultTarget).getTables().isEmpty()) {
                    // We consider the schema is contained is a newly created model
                    // we can change its name
                    target = (Schema) defaultTarget;
                    target.setName(schemaName);
                }
            } else if (defaultTarget instanceof DataBase) {
                DataBase database = (DataBase) defaultTarget;
                if (database.getSchemas().size() == 1 && database.getSchemas().get(0).getTables().isEmpty()) {
                    target = database.getSchemas().get(0);
                    target.setName(schemaName);
                }
            }
            // We create a schema if the target object is a database
            if (target == null) {
                target = createSchema(schemaName);
            }
            // Last solution
            if (target == null && defaultTarget instanceof TableContainer) {
                target = (TableContainer) defaultTarget;
            }
        }
        cacheNamespaceToTableContainer.put(namespace, target);
    }
    // Ensure schema comments are retrieved from namespace
    TableContainer tableContainer = cacheNamespaceToTableContainer.get(namespace);
    tableContainer.setComments(namespace.getDescription());
    return tableContainer;
}
Also used : TableContainer(org.obeonetwork.dsl.database.TableContainer) Schema(org.obeonetwork.dsl.database.Schema) DataBase(org.obeonetwork.dsl.database.DataBase)

Example 15 with DataBase

use of org.obeonetwork.dsl.database.DataBase in project InformationSystem by ObeoNetwork.

the class MpdToMldBidiRules method createOrUpdateSequences.

/**
 * Create needed new sequences or update existing ones
 * @param sourceTableContainer
 * @return list of sequences processed so that all other sequences (now useless) could be removed
 */
/**
 * @param sourceTableContainer
 * @return
 */
private Collection<Sequence> createOrUpdateSequences(TableContainer sourceTableContainer) {
    Collection<Sequence> sequences = new ArrayList<Sequence>();
    // for each non-composite PK we create a sequence and associate it with the PK column
    for (AbstractTable sourceAbstractTable : sourceTableContainer.getTables()) {
        if (sourceAbstractTable instanceof Table) {
            Table sourceTable = (Table) sourceAbstractTable;
            // Get associated table
            Table targetTable = getFromOutputTraceabilityMap(sourceTable, DatabasePackage.Literals.TABLE);
            if (targetTable != null) {
                PrimaryKey pk = targetTable.getPrimaryKey();
                // Only for non-composite PK
                if (pk != null && pk.getColumns().size() == 1) {
                    Column targetColumn = pk.getColumns().get(0);
                    // Retrieve the potentially existing sequence
                    Sequence existingSequence = targetColumn.getSequence();
                    String sequenceName = targetTable.getName() + "_SEQ";
                    if (existingSequence != null) {
                        // Update name
                        existingSequence.setName(sequenceName);
                        // Ensure the sequence is in the right container
                        if (!targetTable.getOwner().getSequences().contains(existingSequence)) {
                            targetTable.getOwner().getSequences().add(existingSequence);
                        }
                        sequences.add(existingSequence);
                    } else {
                        // Create a new sequence
                        Sequence newSequence = DatabaseFactory.eINSTANCE.createSequence();
                        newSequence.setName(sequenceName);
                        newSequence.setIncrement(new BigInteger("1"));
                        newSequence.setStart(new BigInteger("1"));
                        newSequence.setComments(String.format(SEQUENCE_INITIAL_COMMENTS, targetTable.getName()));
                        targetTable.getOwner().getSequences().add(newSequence);
                        // Retrieve the associated column and associate it with the sequence
                        targetColumn.setSequence(newSequence);
                        sequences.add(newSequence);
                    }
                }
            }
        }
    }
    if (sourceTableContainer instanceof DataBase) {
        DataBase sourceDataBase = (DataBase) sourceTableContainer;
        for (Schema sourceSchema : sourceDataBase.getSchemas()) {
            sequences.addAll(createOrUpdateSequences(sourceSchema));
        }
    }
    return sequences;
}
Also used : AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Table(org.obeonetwork.dsl.database.Table) AbstractTable(org.obeonetwork.dsl.database.AbstractTable) Column(org.obeonetwork.dsl.database.Column) Schema(org.obeonetwork.dsl.database.Schema) ArrayList(java.util.ArrayList) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) BigInteger(java.math.BigInteger) Sequence(org.obeonetwork.dsl.database.Sequence) DataBase(org.obeonetwork.dsl.database.DataBase)

Aggregations

DataBase (org.obeonetwork.dsl.database.DataBase)26 Schema (org.obeonetwork.dsl.database.Schema)8 Resource (org.eclipse.emf.ecore.resource.Resource)6 Test (org.junit.Test)6 DataSource (org.obeonetwork.dsl.database.reverse.source.DataSource)6 MultiDataBaseQueries (org.obeonetwork.dsl.database.reverse.utils.MultiDataBaseQueries)6 EObject (org.eclipse.emf.ecore.EObject)5 URI (org.eclipse.emf.common.util.URI)3 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 TypesLibrary (org.obeonetwork.dsl.typeslibrary.TypesLibrary)3 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 Comparison (org.eclipse.emf.compare.Comparison)2 ISelection (org.eclipse.jface.viewers.ISelection)2 DAnalysisSessionEObject (org.eclipse.sirius.viewpoint.DAnalysisSessionEObject)2 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)2 Table (org.obeonetwork.dsl.database.Table)2 File (java.io.File)1 IOException (java.io.IOException)1