Search in sources :

Example 6 with Table

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

the class TableForeignKeysPropertiesEditionComponent 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) {
    Table table = (Table) semanticObject;
    if (DatabaseViewsRepository.ForeignKeys.Properties.foreignKeys_ == event.getAffectedEditor()) {
        if (event.getKind() == PropertiesEditionEvent.ADD) {
            EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, foreignKeysSettings, 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) {
            foreignKeysSettings.removeFromReference((EObject) event.getNewValue());
        } else if (event.getKind() == PropertiesEditionEvent.MOVE) {
            foreignKeysSettings.move(event.getNewIndex(), (ForeignKey) event.getNewValue());
        }
    }
}
Also used : EObjectPropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext) Table(org.obeonetwork.dsl.database.Table) PropertiesEditingProvider(org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider) EObject(org.eclipse.emf.ecore.EObject) PropertiesEditingPolicy(org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy) CreateEditingPolicy(org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) EReferencePropertiesEditionContext(org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)

Example 7 with Table

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

the class TableTablePropertiesEditionComponent 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 Table table = (Table) elt;
        final TablePropertiesEditionPart tablePart = (TablePropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Table.Properties.name))
            tablePart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, table.getName()));
        if (isAccessible(DatabaseViewsRepository.Table.Properties.columns)) {
            columnsSettings = new ReferencesTableSettings(table, DatabasePackage.eINSTANCE.getTable_Columns());
            tablePart.initColumns(columnsSettings);
        }
        if (isAccessible(DatabaseViewsRepository.Table.Properties.comments))
            tablePart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, table.getComments()));
        if (isAccessible(DatabaseViewsRepository.Table.Properties.columns)) {
            tablePart.addFilterToColumns(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof Column);
                }
            });
        // Start of user code for additional businessfilters for columns
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Table(org.obeonetwork.dsl.database.Table) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Column(org.obeonetwork.dsl.database.Column) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) TablePropertiesEditionPart(org.obeonetwork.dsl.database.parts.TablePropertiesEditionPart)

Example 8 with Table

use of org.obeonetwork.dsl.database.Table 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);
    }
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Table(org.obeonetwork.dsl.database.Table) Attribute(org.obeonetwork.dsl.environment.Attribute) Constraint(org.obeonetwork.dsl.database.Constraint) Reference(org.obeonetwork.dsl.environment.Reference) ArrayList(java.util.ArrayList) Index(org.obeonetwork.dsl.database.Index) ForeignKey(org.obeonetwork.dsl.database.ForeignKey) Column(org.obeonetwork.dsl.database.Column) EObject(org.eclipse.emf.ecore.EObject) Session(org.eclipse.sirius.business.api.session.Session)

Example 9 with Table

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

the class EntityToMLD method createJoinTable.

private void createJoinTable(Reference reference, Table sourceTable, Table targetTable) {
    if (getFromOutputTraceabilityMap(reference, DatabasePackage.Literals.TABLE) != null || getFromOutputTraceabilityMap(reference.getOppositeOf(), DatabasePackage.Literals.TABLE) != null) {
        // Do nothing, already handled
        return;
    }
    // Try to retrieve existing join table
    Table joinTable = getFromInputTraceabilityMap(reference, DatabasePackage.Literals.TABLE);
    if (joinTable == null) {
        joinTable = getFromInputTraceabilityMap(reference.getOppositeOf(), DatabasePackage.Literals.TABLE);
    }
    if (joinTable == null) {
        // The join table does not already exist, we have to create a new one
        joinTable = DatabaseFactory.eINSTANCE.createTable();
        sourceTable.getOwner().getTables().add(joinTable);
    }
    addToOutputTraceability(reference, joinTable);
    addToOutputTraceability(reference.getOppositeOf(), joinTable);
    // The following properties are modified even if they already existed
    joinTable.setName(LabelProvider.getJoinTableName(sourceTable, targetTable));
    joinTable.setComments("Table de jointure entre " + sourceTable.getName() + " et " + targetTable.getName());
    createJoinTableForeignKey(joinTable, sourceTable);
    createJoinTableForeignKey(joinTable, targetTable);
    String pkComments = "Contrainte PK pour les colonnes ";
    pkComments += joinTable.getPrimaryKey().getColumns().get(0).getName();
    pkComments += " et ";
    pkComments += joinTable.getPrimaryKey().getColumns().get(1).getName();
    joinTable.getPrimaryKey().setComments(pkComments);
    createAdditionalFields(joinTable);
}
Also used : Table(org.obeonetwork.dsl.database.Table)

Example 10 with Table

use of org.obeonetwork.dsl.database.Table 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);
}
Also used : Table(org.obeonetwork.dsl.database.Table) Attribute(org.obeonetwork.dsl.environment.Attribute) TableContainer(org.obeonetwork.dsl.database.TableContainer) ArrayList(java.util.ArrayList) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) Namespace(org.obeonetwork.dsl.environment.Namespace) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Aggregations

Table (org.obeonetwork.dsl.database.Table)86 Column (org.obeonetwork.dsl.database.Column)41 Test (org.junit.Test)31 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)31 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)22 EObject (org.eclipse.emf.ecore.EObject)17 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)16 ArrayList (java.util.ArrayList)11 ForeignKeyElement (org.obeonetwork.dsl.database.ForeignKeyElement)7 Index (org.obeonetwork.dsl.database.Index)7 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)6 Viewer (org.eclipse.jface.viewers.Viewer)6 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)6 Constraint (org.obeonetwork.dsl.database.Constraint)6 Sequence (org.obeonetwork.dsl.database.Sequence)6 BigInteger (java.math.BigInteger)5 PreparedStatement (java.sql.PreparedStatement)5 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)5