Search in sources :

Example 1 with PrimaryKey

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

the class PrimaryKeyPropertiesEditionComponent 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 PrimaryKey primaryKey = (PrimaryKey) elt;
        final PrimaryKeyPropertiesEditionPart primaryKeyPart = (PrimaryKeyPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.name))
            primaryKeyPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, primaryKey.getName()));
        if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.columns)) {
            columnsSettings = new ReferencesTableSettings(primaryKey, DatabasePackage.eINSTANCE.getPrimaryKey_Columns());
            primaryKeyPart.initColumns(columnsSettings);
        }
        if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.comments))
            primaryKeyPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, primaryKey.getComments()));
        if (isAccessible(DatabaseViewsRepository.PrimaryKey.Properties.columns)) {
            primaryKeyPart.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) {
                    if (element instanceof EObject)
                        return (!primaryKeyPart.isContainedInColumnsTable((EObject) element));
                    return element instanceof String && element.equals("");
                }
            });
            primaryKeyPart.addFilterToColumns(new EObjectStrictFilter(DatabasePackage.Literals.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 : EObjectStrictFilter(org.eclipse.emf.eef.runtime.impl.filters.EObjectStrictFilter) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) EObject(org.eclipse.emf.ecore.EObject) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) PrimaryKeyPropertiesEditionPart(org.obeonetwork.dsl.database.parts.PrimaryKeyPropertiesEditionPart)

Example 2 with PrimaryKey

use of org.obeonetwork.dsl.database.PrimaryKey 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)

Example 3 with PrimaryKey

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

the class UpdatePrimaryKeyItemProvider 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) {
    UpdatePrimaryKey updatePrimaryKey = (UpdatePrimaryKey) object;
    PrimaryKey primaryKey = updatePrimaryKey.getPrimaryKey();
    return getString("_UI_UpdatePrimaryKey_type") + " " + primaryKey.getName();
}
Also used : UpdatePrimaryKey(org.obeonetwork.dsl.database.dbevolution.UpdatePrimaryKey) UpdatePrimaryKey(org.obeonetwork.dsl.database.dbevolution.UpdatePrimaryKey) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey)

Example 4 with PrimaryKey

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

the class AddPrimaryKeyItemProvider 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) {
    AddPrimaryKey addPrimaryKey = (AddPrimaryKey) object;
    PrimaryKey primaryKey = addPrimaryKey.getPrimaryKey();
    if (primaryKey != null) {
        return getString("_UI_AddPrimaryKey_type") + " " + primaryKey.getName();
    } else {
        return getString("_UI_AddPrimaryKey_type");
    }
}
Also used : PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey) AddPrimaryKey(org.obeonetwork.dsl.database.dbevolution.AddPrimaryKey) AddPrimaryKey(org.obeonetwork.dsl.database.dbevolution.AddPrimaryKey)

Example 5 with PrimaryKey

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

the class ColumnSpec method addToPrimaryKey.

@Override
public void addToPrimaryKey() {
    // Do nothing if the column is already a PK column or if it does not belong to a table
    if (isInPrimaryKey() == false && getOwner() != null && getOwner() instanceof Table) {
        Table table = (Table) getOwner();
        // First, ensure there is a Primary Key defined on this table
        PrimaryKey pk = table.getPrimaryKey();
        if (pk == null) {
            // Create a new PK
            pk = DatabaseFactory.eINSTANCE.createPrimaryKey();
            pk.setName(table.getName() + "_PK");
            table.setPrimaryKey(pk);
        }
        // Then attach the column to the primary key
        pk.getColumns().add(this);
    }
}
Also used : Table(org.obeonetwork.dsl.database.Table) PrimaryKey(org.obeonetwork.dsl.database.PrimaryKey)

Aggregations

PrimaryKey (org.obeonetwork.dsl.database.PrimaryKey)15 Table (org.obeonetwork.dsl.database.Table)3 UpdatePrimaryKey (org.obeonetwork.dsl.database.dbevolution.UpdatePrimaryKey)3 ArrayList (java.util.ArrayList)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Column (org.obeonetwork.dsl.database.Column)2 AddPrimaryKey (org.obeonetwork.dsl.database.dbevolution.AddPrimaryKey)2 RemovePrimaryKey (org.obeonetwork.dsl.database.dbevolution.RemovePrimaryKey)2 BigInteger (java.math.BigInteger)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 EObject (org.eclipse.emf.ecore.EObject)1 EObjectStrictFilter (org.eclipse.emf.eef.runtime.impl.filters.EObjectStrictFilter)1 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)1 DataBase (org.obeonetwork.dsl.database.DataBase)1 Schema (org.obeonetwork.dsl.database.Schema)1 Sequence (org.obeonetwork.dsl.database.Sequence)1