use of org.obeonetwork.dsl.database.Index in project InformationSystem by ObeoNetwork.
the class IndexChangeImpl method setIndex.
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
public void setIndex(Index newIndex) {
Index oldIndex = index;
index = newIndex;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, DbevolutionPackage.INDEX_CHANGE__INDEX, oldIndex, index));
}
use of org.obeonetwork.dsl.database.Index 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);
}
}
}
use of org.obeonetwork.dsl.database.Index in project InformationSystem by ObeoNetwork.
the class IndexItemProvider method getText.
/**
* This returns the label text for the adapted class.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated NOT
*/
@Override
public String getText(Object object) {
Index index = (Index) object;
String label = index.getName();
if (index.isUnique()) {
label += " " + getString("_UI_Index_Unique_Suffix");
}
return label == null || label.length() == 0 ? getString("_UI_Index_type") : getString("_UI_Index_type") + " " + label;
}
use of org.obeonetwork.dsl.database.Index in project InformationSystem by ObeoNetwork.
the class ColumnSpec method addToUniqueIndex.
@Override
public void addToUniqueIndex() {
if (isUnique() == false && getOwner() != null && getOwner() instanceof Table) {
Table table = (Table) getOwner();
// Check if there is a unique index defined on the table
Index uniqueIndex = null;
for (Index index : table.getIndexes()) {
if (index.isUnique()) {
uniqueIndex = index;
break;
}
}
if (uniqueIndex == null) {
// Create a new unique index
uniqueIndex = DatabaseFactory.eINSTANCE.createIndex();
uniqueIndex.setName(table.getName() + "_UNIQUE_INDEX");
uniqueIndex.setUnique(true);
table.getIndexes().add(uniqueIndex);
}
// We are sure we have a unique index here
IndexElement indexElt = DatabaseFactory.eINSTANCE.createIndexElement();
uniqueIndex.getElements().add(indexElt);
indexElt.setAsc(true);
indexElt.setColumn(this);
}
}
use of org.obeonetwork.dsl.database.Index in project InformationSystem by ObeoNetwork.
the class IndexPropertiesEditionComponent method updateSemanticModel.
/**
* {@inheritDoc}
* @see org.eclipse.emf.eef.runtime.impl.components.StandardPropertiesEditionComponent#updateSemanticModel(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
*/
public void updateSemanticModel(final IPropertiesEditionEvent event) {
Index index = (Index) semanticObject;
if (DatabaseViewsRepository.Index.Properties.name == event.getAffectedEditor()) {
index.setName((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
}
if (DatabaseViewsRepository.Index.Properties.qualifier == event.getAffectedEditor()) {
index.setQualifier((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
}
if (DatabaseViewsRepository.Index.Properties.unique == event.getAffectedEditor()) {
index.setUnique((Boolean) event.getNewValue());
}
if (DatabaseViewsRepository.Index.Properties.cardinality == event.getAffectedEditor()) {
index.setCardinality((EEFConverterUtil.createIntFromString(EcorePackage.Literals.EINT, (String) event.getNewValue())));
}
if (DatabaseViewsRepository.Index.Properties.indexType == event.getAffectedEditor()) {
index.setIndexType((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
}
if (DatabaseViewsRepository.Index.Properties.comments == event.getAffectedEditor()) {
index.setComments((java.lang.String) EEFConverterUtil.createFromString(EcorePackage.Literals.ESTRING, (String) event.getNewValue()));
}
if (DatabaseViewsRepository.Index.Properties.elements == event.getAffectedEditor()) {
if (event.getKind() == PropertiesEditionEvent.ADD) {
EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, elementsSettings, editingContext.getAdapterFactory());
PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt(semanticObject, PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy policy = provider.getPolicy(context);
if (policy instanceof CreateEditingPolicy) {
policy.execute();
}
}
} else if (event.getKind() == PropertiesEditionEvent.EDIT) {
EObjectPropertiesEditionContext context = new EObjectPropertiesEditionContext(editingContext, this, (EObject) event.getNewValue(), editingContext.getAdapterFactory());
PropertiesEditingProvider provider = (PropertiesEditingProvider) editingContext.getAdapterFactory().adapt((EObject) event.getNewValue(), PropertiesEditingProvider.class);
if (provider != null) {
PropertiesEditingPolicy editionPolicy = provider.getPolicy(context);
if (editionPolicy != null) {
editionPolicy.execute();
}
}
} else if (event.getKind() == PropertiesEditionEvent.REMOVE) {
elementsSettings.removeFromReference((EObject) event.getNewValue());
} else if (event.getKind() == PropertiesEditionEvent.MOVE) {
elementsSettings.move(event.getNewIndex(), (IndexElement) event.getNewValue());
}
}
}
Aggregations