use of org.obeonetwork.dsl.database.TableContainer in project InformationSystem by ObeoNetwork.
the class EntityToMLD method prepare.
@Override
protected boolean prepare(EObject sourceObject, EObject targetObject) {
if (targetObject instanceof TableContainer) {
sourceNamespaces = new ArrayList<Namespace>();
if (sourceObject instanceof Root) {
Root sourceRoot = (Root) sourceObject;
sourceNamespaces.addAll(sourceRoot.getOwnedNamespaces());
} else if (sourceObject instanceof Namespace) {
sourceNamespaces.add((Namespace) sourceObject);
}
targetResource = targetObject.eResource();
defaultTarget = targetObject;
nativeTypesMap = loadTypesLibrary();
return (!nativeTypesMap.isEmpty());
}
return false;
}
use of org.obeonetwork.dsl.database.TableContainer in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createTable.
private void createTable(Entity entity) {
// Retrieve the existing table
Table table = getFromInputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
Namespace namespace = EntityUtils.getContainingNamespace(entity);
if (table == null) {
// The table does not already exist we have to create a new one
table = DatabaseFactory.eINSTANCE.createTable();
TableContainer targetTableContainer = getTargetTableContainer(namespace);
targetTableContainer.getTables().add(table);
} else {
// We have to ensure the schema name is correct
String realSchemaName = getSchemaNameFromNamespace(namespace);
TableContainer tableContainer = table.getOwner();
if (!realSchemaName.equals(tableContainer.getName())) {
tableContainer.setName(realSchemaName);
}
}
// Add to traceability map
addToOutputTraceability(entity, table);
// The following properties are modified even if they already existed
table.setName(LabelProvider.getTableNameFromEntity(entity));
table.setComments(entity.getDescription());
// Handle attributes
boolean hasPKAttribute = false;
Collection<Attribute> allAttributes = new ArrayList<Attribute>();
// Attributes from the entity and its supertypes
allAttributes.addAll(entity.getAttributes());
// Attributes from associated DTOs
for (StructuredType associatedType : entity.getAssociatedTypes()) {
allAttributes.addAll(associatedType.getAttributes());
}
for (Attribute attribute : allAttributes) {
createColumn(attribute, table);
if (attribute.isIsIdentifier()) {
hasPKAttribute = true;
}
}
// Create an ID column if no attribute was set as "primary key"
if (hasPKAttribute == false) {
createDefaultIdColumn(table);
}
// Update comments on PK
PrimaryKey primaryKey = table.getPrimaryKey();
if (primaryKey != null) {
primaryKey.setName(table.getName() + "_PK");
primaryKey.setComments(getPKComments(primaryKey));
}
// Create constraints
createConstraints(entity, table);
}
use of org.obeonetwork.dsl.database.TableContainer in project InformationSystem by ObeoNetwork.
the class GenerateSQLFromDatabaseHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
// We have to compute an emfdiff file from a comparison with an empty database
// ---
// First let's create an empty model containing only
Resource resource = new DatabaseResourceImpl(URI.createURI("memory:/empty_database"));
TableContainer rootContainer = getFirstTableContainer(selection);
TableContainer newContainer = null;
if (rootContainer instanceof DataBase) {
newContainer = copyDatabase((DataBase) rootContainer);
resource.getContents().add(newContainer);
} else if (rootContainer instanceof Schema) {
newContainer = copySchema((Schema) rootContainer);
resource.getContents().add(newContainer);
}
// Then compare the two models
Comparison comparison = null;
try {
comparison = DatabaseCompareService.compare(rootContainer, newContainer);
} catch (Exception e) {
}
// The diff model can now be used to generate the SQL script
if (comparison != null) {
ExportAsSQLScriptsAction action = new ExportAsSQLScriptsAction();
action.exportComparison(comparison);
}
return null;
}
use of org.obeonetwork.dsl.database.TableContainer in project InformationSystem by ObeoNetwork.
the class DataBaseServices method allSequences.
/**
* Returns all the sequences contained and referenced by the database (including the sequences associated to tables of external
* databases referenced through foreign
* keys).
*
* @param database
* @return the set of all sequences contained and referenced by the database.
*/
public Set<Sequence> allSequences(DataBase database) {
Set<Sequence> result = new HashSet<Sequence>();
result.addAll(database.getSequences());
Set<Table> tables = allTables(database);
for (Table table : tables) {
if (table.eContainer() instanceof TableContainer) {
result.addAll(((TableContainer) table.eContainer()).getSequences());
}
}
return result;
}
use of org.obeonetwork.dsl.database.TableContainer in project InformationSystem by ObeoNetwork.
the class AbstractDatabaseCompareTest method testDatabaseCompare.
public void testDatabaseCompare(String folder) {
TableContainer tableContainer1 = (TableContainer) loadRootObject(folder, INPUT_DATABASE_1, TableContainer.class);
TableContainer tableContainer2 = (TableContainer) loadRootObject(folder, INPUT_DATABASE_2, TableContainer.class);
// Comparison expectedSnapshot = (Comparison)loadRootObject(folder, EXPECTED_COMPARISON, Comparison.class);
Comparison actualSnapshot = null;
try {
actualSnapshot = DatabaseCompareService.compare(tableContainer1, tableContainer2);
} catch (Exception e) {
Assert.fail("Exception during comparison : " + e.getMessage());
}
try {
Generate generate = new Generate(actualSnapshot, new File("models/" + folder), new ArrayList<Object>());
generate.doGenerate(new BasicMonitor());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations