Search in sources :

Example 1 with Column

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

the class DatabaseServices method createForeignKey.

public ForeignKey createForeignKey(Table source, Table target) {
    ForeignKey fk = DatabaseFactory.eINSTANCE.createForeignKey();
    source.getForeignKeys().add(fk);
    fk.setTarget(target);
    // Initialize with columns
    if (target.getPrimaryKey() != null) {
        for (Column pkColumn : target.getPrimaryKey().getColumns()) {
            Column fkColumn = getOrCreateColumn(source, pkColumn);
            if (pkColumn != null && fkColumn != null) {
                ForeignKeyElement fke = DatabaseFactory.eINSTANCE.createForeignKeyElement();
                fke.setPkColumn(pkColumn);
                fke.setFkColumn(fkColumn);
                fk.getElements().add(fke);
            }
        }
    }
    return fk;
}
Also used : ForeignKeyElement(org.obeonetwork.dsl.database.ForeignKeyElement) Column(org.obeonetwork.dsl.database.Column) ForeignKey(org.obeonetwork.dsl.database.ForeignKey)

Example 2 with Column

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

the class IndexElementPropertiesEditionComponent 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 IndexElement indexElement = (IndexElement) elt;
        final IndexElementPropertiesEditionPart indexElementPart = (IndexElementPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.IndexElement.Properties.column)) {
            // init part
            columnSettings = new EObjectFlatComboSettings(indexElement, DatabasePackage.eINSTANCE.getIndexElement_Column());
            indexElementPart.initColumn(columnSettings);
            // set the button mode
            indexElementPart.setColumnButtonMode(ButtonsModeEnum.BROWSE);
        }
        if (isAccessible(DatabaseViewsRepository.IndexElement.Properties.asc)) {
            indexElementPart.setAsc(indexElement.isAsc());
        }
        if (isAccessible(DatabaseViewsRepository.IndexElement.Properties.comments))
            indexElementPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, indexElement.getComments()));
        // init filters
        if (isAccessible(DatabaseViewsRepository.IndexElement.Properties.column)) {
            indexElementPart.addFilterToColumn(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 column
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : IndexElementPropertiesEditionPart(org.obeonetwork.dsl.database.parts.IndexElementPropertiesEditionPart) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Column(org.obeonetwork.dsl.database.Column) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) EObjectFlatComboSettings(org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings) IndexElement(org.obeonetwork.dsl.database.IndexElement)

Example 3 with Column

use of org.obeonetwork.dsl.database.Column 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 4 with Column

use of org.obeonetwork.dsl.database.Column 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 5 with Column

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

the class EntityToMLD method createColumn.

private void createColumn(Attribute attribute, Table table) {
    // Try to retrieve existing column
    Column column = getFromInputTraceabilityMap(attribute, DatabasePackage.Literals.COLUMN);
    if (column != null) {
        // Ensure the column is in the right table
        if (!EcoreUtil.equals(table, column.getOwner())) {
            table.getColumns().add(column);
        }
    } else {
        // The column does not already exist, we have to create a new one
        column = DatabaseFactory.eINSTANCE.createColumn();
        table.getColumns().add(column);
    }
    // Add to the new traceability map
    addToOutputTraceability(attribute, column);
    // The following properties are modified even if they were already valued
    column.setName(LabelProvider.getColumnNameFromAttribute(attribute));
    column.setComments(attribute.getDescription());
    column.setDefaultValue(AnnotationHelper.getPhysicalDefault(attribute));
    boolean nullable = hasZeroAsLowerMultiplicityBound(attribute);
    column.setNullable(nullable);
    // Add to PK when needed
    if (attribute.isIsIdentifier()) {
        column.addToPrimaryKey();
        if (column.getComments() == null || column.getComments().length() == 0) {
            column.setComments(getPKColumnComment(column));
        }
    }
    if (attribute.getType() instanceof Enumeration) {
        handleEnumType(column, (Enumeration) attribute.getType(), table);
    } else {
        column.setType(resolveType(attribute.getType(), AnnotationHelper.getPhysicalSize(attribute)));
    }
}
Also used : Enumeration(org.obeonetwork.dsl.environment.Enumeration) Column(org.obeonetwork.dsl.database.Column)

Aggregations

Column (org.obeonetwork.dsl.database.Column)83 Table (org.obeonetwork.dsl.database.Table)41 Test (org.junit.Test)31 AbstractTest (org.obeonetwork.database.m2doc.services.common.AbstractTest)31 TypeInstance (org.obeonetwork.dsl.typeslibrary.TypeInstance)11 EObject (org.eclipse.emf.ecore.EObject)9 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)8 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)7 ArrayList (java.util.ArrayList)6 Constraint (org.obeonetwork.dsl.database.Constraint)6 ForeignKeyElement (org.obeonetwork.dsl.database.ForeignKeyElement)6 Sequence (org.obeonetwork.dsl.database.Sequence)6 BigInteger (java.math.BigInteger)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 NativeType (org.obeonetwork.dsl.typeslibrary.NativeType)5 PreparedStatement (java.sql.PreparedStatement)4 Viewer (org.eclipse.jface.viewers.Viewer)4 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)4 IndexElement (org.obeonetwork.dsl.database.IndexElement)4