Search in sources :

Example 11 with Constraint

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

the class AddConstraintItemProvider 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) {
    AddConstraint addConstraint = (AddConstraint) object;
    Constraint constraint = addConstraint.getConstraint();
    return getString("_UI_AddConstraint_type") + " " + constraint.getName();
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint) AddConstraint(org.obeonetwork.dsl.database.dbevolution.AddConstraint) AddConstraint(org.obeonetwork.dsl.database.dbevolution.AddConstraint)

Example 12 with Constraint

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

the class ConstraintChangeBuilder method createUpdateConstraint.

protected UpdateConstraint createUpdateConstraint(Match change) {
    UpdateConstraint updateConstraint = DbevolutionFactory.eINSTANCE.createUpdateConstraint();
    Constraint constraint = (Constraint) change.getRight();
    updateConstraint.setConstraint(constraint);
    Object leftElement = change.getLeft();
    updateConstraint.setNewConstraint((Constraint) leftElement);
    fillDBDiff(updateConstraint, change);
    return updateConstraint;
}
Also used : UpdateConstraint(org.obeonetwork.dsl.database.dbevolution.UpdateConstraint) Constraint(org.obeonetwork.dsl.database.Constraint) AddConstraint(org.obeonetwork.dsl.database.dbevolution.AddConstraint) UpdateConstraint(org.obeonetwork.dsl.database.dbevolution.UpdateConstraint) RemoveConstraint(org.obeonetwork.dsl.database.dbevolution.RemoveConstraint)

Example 13 with Constraint

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

the class ConstraintChangeImpl method setConstraint.

/**
 * <!-- begin-user-doc --> <!-- end-user-doc -->
 * @generated
 */
public void setConstraint(Constraint newConstraint) {
    Constraint oldConstraint = constraint;
    constraint = newConstraint;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, DbevolutionPackage.CONSTRAINT_CHANGE__CONSTRAINT, oldConstraint, constraint));
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 14 with Constraint

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

the class UpdateConstraintImpl method setNewConstraint.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setNewConstraint(Constraint newNewConstraint) {
    Constraint oldNewConstraint = newConstraint;
    newConstraint = newNewConstraint;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, DbevolutionPackage.UPDATE_CONSTRAINT__NEW_CONSTRAINT, oldNewConstraint, newConstraint));
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint) UpdateConstraint(org.obeonetwork.dsl.database.dbevolution.UpdateConstraint) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 15 with Constraint

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

the class EntityToMLD method handleEnumType.

private void handleEnumType(Column column, Enumeration enumeration, Table table) {
    // For an enumeration
    // Column has type Texte
    TypeInstance typeInstance = TypesLibraryFactory.eINSTANCE.createTypeInstance();
    typeInstance.setNativeType(nativeTypesMap.get(ENUM_COLUMN_TYPE));
    column.setType(typeInstance);
    // Column size is the maximum length of the literals
    int maxSize = 0;
    List<String> literalValues = new ArrayList<String>();
    for (Literal literal : enumeration.getLiterals()) {
        String value = literal.getName();
        if (value != null) {
            literalValues.add("''" + value + "''");
            int length = value.length();
            if (maxSize < length) {
                maxSize = length;
            }
        }
    }
    if (maxSize > 0) {
        typeInstance.setLength(maxSize);
    }
    // A check constraint is added with all literals
    String expression = MessageFormat.format("{0} in ({1})", column.getName(), Joiner.on(",").join(literalValues));
    Constraint validityConstraint = findOrCreateConstraint(table, expression);
    validityConstraint.setName("ENUM_CONSTRAINT");
    validityConstraint.setComments(MessageFormat.format(ENUM_CONSTRAINTS_COMMENTS, column.getName()));
    addToObjectsToBeKept(validityConstraint);
    // A default value is added, it is the first literal
    if (!enumeration.getLiterals().isEmpty()) {
        column.setDefaultValue(enumeration.getLiterals().get(0).getName());
    }
}
Also used : Constraint(org.obeonetwork.dsl.database.Constraint) Literal(org.obeonetwork.dsl.environment.Literal) ArrayList(java.util.ArrayList) TypeInstance(org.obeonetwork.dsl.typeslibrary.TypeInstance) 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