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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations