Search in sources :

Example 1 with Constraint

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

the class ConstraintPropertiesEditionComponent 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 Constraint constraint = (Constraint) elt;
        final ConstraintPropertiesEditionPart constraintPart = (ConstraintPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Constraint.Properties.name))
            constraintPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, constraint.getName()));
        if (isAccessible(DatabaseViewsRepository.Constraint.Properties.expression))
            constraintPart.setExpression(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, constraint.getExpression()));
        if (isAccessible(DatabaseViewsRepository.Constraint.Properties.comments))
            constraintPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, constraint.getComments()));
    // init filters
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint) ConstraintPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ConstraintPropertiesEditionPart)

Example 2 with Constraint

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

the class TableConstraintsPropertiesEditionComponent 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 ConstraintsPropertiesEditionPart constraintsPart = (ConstraintsPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.Constraints.Properties.constraints_)) {
            constraintsSettings = new ReferencesTableSettings(table, DatabasePackage.eINSTANCE.getTable_Constraints());
            constraintsPart.initConstraints(constraintsSettings);
        }
        // init filters
        if (isAccessible(DatabaseViewsRepository.Constraints.Properties.constraints_)) {
            constraintsPart.addFilterToConstraints(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 Constraint);
                }
            });
        // Start of user code for additional businessfilters for constraints
        // 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) ConstraintsPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ConstraintsPropertiesEditionPart) Constraint(org.obeonetwork.dsl.database.Constraint) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject)

Example 3 with Constraint

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

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

the class EntityToMLD method findOrCreateConstraint.

private Constraint findOrCreateConstraint(Table table, String expression) {
    for (Constraint constraint : table.getConstraints()) {
        if (expression.equals(constraint.getExpression())) {
            return constraint;
        }
    }
    // No constraint found, let's create one
    Constraint constraint = DatabaseFactory.eINSTANCE.createConstraint();
    constraint.setExpression(expression);
    table.getConstraints().add(constraint);
    return constraint;
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint)

Example 5 with Constraint

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

the class EntityToMLD method createAdditionalFields.

private void createAdditionalFields(Table table) {
    /*
		 * 1st part : Quick fix for Ministère de l'Education Nationale needs
		 * a metadata DISABLE_ADDITIONAL_FIELDS_KEY = true can be set on an entity, a namespace or entity root
		 * if it is set then the additional fields won't be created
		 */
    if (shouldCreateAdditionalFields(table)) {
        /*
		 * End of 1st part : Quick fix for Ministère de l'Education Nationale needs
		 */
        // Validity column
        String validityColumnName = AdditionalFieldsUtils.getValidityColumnName(table);
        Column validityColumn = createValidityColumn(table, validityColumnName);
        addToObjectsToBeKept(validityColumn);
        // Add constraint on this column
        Constraint validityConstraint = findOrCreateConstraint(table, AdditionalFieldsUtils.getValidityColumnConstraint(table));
        validityConstraint.setName(getConstraintName(validityConstraint));
        validityConstraint.setComments(MessageFormat.format(VALIDITY_CONSTRAINT_COMMENTS, validityColumnName));
        addToObjectsToBeKept(validityConstraint);
        // Date column
        Column dateColumn = createDateColumn(table, AdditionalFieldsUtils.getDateColumnName(table));
        addToObjectsToBeKept(dateColumn);
    /*
		 * 2nd part : Quick fix for Ministère de l'Education Nationale needs
		 */
    }
/*
		 * End of 2nd part : Quick fix for Ministère de l'Education Nationale needs
		 */
}
Also used : Column(org.obeonetwork.dsl.database.Column) Constraint(org.obeonetwork.dsl.database.Constraint)

Aggregations

Constraint (org.obeonetwork.dsl.database.Constraint)21 Table (org.obeonetwork.dsl.database.Table)5 ArrayList (java.util.ArrayList)4 EObject (org.eclipse.emf.ecore.EObject)4 Column (org.obeonetwork.dsl.database.Column)4 AbstractTable (org.obeonetwork.dsl.database.AbstractTable)3 UpdateConstraint (org.obeonetwork.dsl.database.dbevolution.UpdateConstraint)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 Index (org.obeonetwork.dsl.database.Index)2 AddConstraint (org.obeonetwork.dsl.database.dbevolution.AddConstraint)2 RemoveConstraint (org.obeonetwork.dsl.database.dbevolution.RemoveConstraint)2 Entity (org.obeonetwork.dsl.entity.Entity)2 Collection (java.util.Collection)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)1 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)1