use of org.obeonetwork.dsl.environment.Attribute in project InformationSystem by ObeoNetwork.
the class AbstractTransformation method removeOldObjects.
private void removeOldObjects() {
// Traverse the whole target resource to remove objects which have not been reused or created by this transformation
Collection<EObject> objectsToKeep = new ArrayList<EObject>();
objectsToKeep.addAll(outputTraceabilityMap.values());
objectsToKeep.addAll(objectsToBeKept);
Collection<EObject> objectsToBeDeleted = new ArrayList<EObject>();
for (Iterator<EObject> it = getResult().getAllContents(); it.hasNext(); ) {
EObject object = it.next();
if (object instanceof Entity || object instanceof Attribute || object instanceof Reference || object instanceof Table || object instanceof Column || object instanceof ForeignKey || object instanceof Index || object instanceof Constraint) {
if (!objectsToKeep.contains(object)) {
objectsToBeDeleted.add(object);
}
}
}
// Remove objects
Session session = SessionManager.INSTANCE.getSession(scaffoldInfo);
for (EObject objectToBeDeleted : objectsToBeDeleted) {
deleteObject(objectToBeDeleted, session);
}
}
use of org.obeonetwork.dsl.environment.Attribute 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.environment.Attribute in project InformationSystem by ObeoNetwork.
the class MLDToEntity method createAttribute.
private void createAttribute(Column column, Entity entity) {
// Try to retrieve existing attribute
Attribute attribute = getFromInputTraceabilityMap(column, EnvironmentPackage.Literals.ATTRIBUTE);
if (attribute != null) {
// Ensure the attribute is in the right entity
if (!EcoreUtil.equals(entity, attribute.getContainingType())) {
entity.getOwnedAttributes().add(attribute);
}
} else {
// The attribute does not already exist, we have to create one
attribute = EnvironmentFactory.eINSTANCE.createAttribute();
entity.getOwnedAttributes().add(attribute);
attribute.setName(LabelProvider.getAttributeNameFromColumn(column));
}
// Add to new traceability map
addToOutputTraceability(column, attribute);
// The following properties are modified even if they already existed
AnnotationHelper.setPhysicalNameAnnotation(attribute, LabelProvider.getAttributePhysicalNameFromColumn(column));
attribute.setDescription(column.getComments());
AnnotationHelper.setPhysicalDefaultAnnotation(attribute, column.getDefaultValue());
TypeInstance typeInstance = (TypeInstance) column.getType();
attribute.setType(resolveType(typeInstance));
AnnotationHelper.setPhysicalSize(attribute, typeInstance);
if (column.isNullable()) {
attribute.setMultiplicity(MultiplicityKind.ZERO_ONE_LITERAL);
} else {
attribute.setMultiplicity(MultiplicityKind.ONE_LITERAL);
}
AnnotationHelper.removePhysicalUniqueAnnotations(attribute);
attribute.setIsIdentifier(column.isInPrimaryKey());
}
use of org.obeonetwork.dsl.environment.Attribute in project InformationSystem by ObeoNetwork.
the class AttributeAttributePropertiesEditionComponent method initPart.
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
* org.eclipse.emf.ecore.resource.ResourceSet)
*/
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
setInitializing(true);
if (editingPart != null && key == partKey) {
editingPart.setContext(elt, allResource);
final Attribute attribute = (Attribute) elt;
final AttributePropertiesEditionPart attributePart = (AttributePropertiesEditionPart) editingPart;
// init values
if (isAccessible(EnvironmentViewsRepository.Attribute.Properties.name))
attributePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, attribute.getName()));
if (isAccessible(EnvironmentViewsRepository.Attribute.Properties.type)) {
attributePart.initType(EEFUtils.choiceOfValues(attribute, EnvironmentPackage.eINSTANCE.getAttribute_Type()), attribute.getType());
}
if (isAccessible(EnvironmentViewsRepository.Attribute.Properties.multiplicity)) {
attributePart.initMultiplicity(EEFUtils.choiceOfValues(attribute, EnvironmentPackage.eINSTANCE.getProperty_Multiplicity()), attribute.getMultiplicity());
}
if (isAccessible(EnvironmentViewsRepository.Attribute.Properties.identifier)) {
attributePart.setIdentifier(attribute.isIsIdentifier());
}
if (isAccessible(EnvironmentViewsRepository.Attribute.Properties.description))
attributePart.setDescription(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, attribute.getDescription()));
// init filters
// Start of user code for additional businessfilters for type
// End of user code
// init values for referenced views
// init filters for referenced views
}
setInitializing(false);
}
use of org.obeonetwork.dsl.environment.Attribute in project InformationSystem by ObeoNetwork.
the class EntityToMLD method createIndices.
private void createIndices(Entity entity) {
Table table = getFromOutputTraceabilityMap(entity, DatabasePackage.Literals.TABLE);
// We collect unique and non unique indices, all indices will be kept unchanged
Collection<Index> existingUniqueIndices = new ArrayList<Index>();
Collection<Index> existingNonUniqueIndices = new ArrayList<Index>();
for (Index index : table.getIndexes()) {
if (index.isUnique()) {
existingUniqueIndices.add(index);
} else {
existingNonUniqueIndices.add(index);
}
}
// Handle indexes on attributes
for (Attribute attribute : entity.getOwnedAttributes()) {
String unicity = AnnotationHelper.getPhysicalUnique(attribute);
if (unicity != null) {
List<Column> columns = new ArrayList<Column>();
Column column = getFromOutputTraceabilityMap(attribute, DatabasePackage.Literals.COLUMN);
columns.add(column);
Index index = findIndex(existingUniqueIndices, columns);
if (index != null) {
// We reuse the existing index
index.getElements().get(0).setAsc(isIndexAsc(unicity));
} else {
// We have to create a new index
index = DatabaseFactory.eINSTANCE.createIndex();
table.getIndexes().add(index);
existingUniqueIndices.add(index);
index.setUnique(true);
IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
index.getElements().add(indexElement);
indexElement.setAsc(isIndexAsc(unicity));
indexElement.setColumn(column);
}
index.setName(getUniqueIndexName(index));
index.setComments(getUniqueIndexComments(index));
addToObjectsToBeKept(index);
}
}
// Handle indexes on entity
String tableUnicity = AnnotationHelper.getPhysicalUnique(entity);
if (tableUnicity != null) {
List<Map<String, Boolean>> listOfIndexInfos = getInfosFromTableUnicity(tableUnicity);
for (Map<String, Boolean> indexInfos : listOfIndexInfos) {
List<Column> columns = new ArrayList<Column>();
for (String columnName : indexInfos.keySet()) {
for (Column column : table.getColumns()) {
if (column.getName().equalsIgnoreCase(columnName)) {
columns.add(column);
break;
}
}
}
// Check if all columns were found
if (columns.size() != indexInfos.size()) {
String msg = "Could not understand PHYSICAL_UNIQUE annotation for Entity: " + entity.getName() + " - annotation: \"" + tableUnicity + "\"";
Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, msg));
}
// Try to retrieve an existing index on these columns
Index index = findIndex(existingUniqueIndices, columns);
if (index != null) {
// Update sort orders
for (IndexElement element : index.getElements()) {
element.setAsc(indexInfos.get(element.getColumn().getName().toUpperCase()));
}
} else {
// We have to create a new index
index = DatabaseFactory.eINSTANCE.createIndex();
table.getIndexes().add(index);
existingUniqueIndices.add(index);
index.setUnique(true);
for (Column targetColumn : columns) {
IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
index.getElements().add(indexElement);
String s = targetColumn.getName();
indexElement.setAsc(indexInfos.get(targetColumn.getName().toUpperCase()));
indexElement.setColumn(targetColumn);
}
}
index.setName(getUniqueIndexName(index));
index.setComments(getUniqueIndexComments(index));
addToObjectsToBeKept(index);
}
}
// Handle indexes on references
for (Reference reference : getReferencesForIndexCreation(entity)) {
boolean indexShouldBeUnique = false;
// if (isMultiplicitySimple(reference)) {
// indexShouldBeUnique = true;
// } else if (isMultiplicityMany(reference)) {
// indexShouldBeUnique = false;
// }
String unicity = AnnotationHelper.getPhysicalUnique(reference);
if (unicity == null) {
unicity = "ASC";
} else {
indexShouldBeUnique = true;
}
List<Column> columns = new ArrayList<Column>();
ForeignKey fk = getFromOutputTraceabilityMap(reference, DatabasePackage.Literals.FOREIGN_KEY);
// Get columns for FK
if (fk != null) {
for (ForeignKeyElement fkElt : fk.getElements()) {
columns.add(fkElt.getFkColumn());
}
Index index = null;
if (indexShouldBeUnique) {
index = findIndex(existingUniqueIndices, columns);
} else {
index = findIndex(existingNonUniqueIndices, columns);
}
if (index != null) {
// Ensure the index is of the right kind
index.setUnique(indexShouldBeUnique);
// We reuse the existing index
for (IndexElement indexElt : index.getElements()) {
indexElt.setAsc(isIndexAsc(unicity));
}
} else {
// We have to create a new index
index = DatabaseFactory.eINSTANCE.createIndex();
table.getIndexes().add(index);
if (indexShouldBeUnique) {
existingUniqueIndices.add(index);
} else {
existingNonUniqueIndices.add(index);
}
index.setUnique(indexShouldBeUnique);
for (ForeignKeyElement fkElt : fk.getElements()) {
IndexElement indexElement = DatabaseFactory.eINSTANCE.createIndexElement();
index.getElements().add(indexElement);
indexElement.setAsc(isIndexAsc(unicity));
indexElement.setColumn(fkElt.getFkColumn());
}
}
index.setName(fk.getName());
index.setComments(getFKIndexComments(index));
addToObjectsToBeKept(index);
}
}
}
Aggregations