use of org.obeonetwork.dsl.database.Constraint in project InformationSystem by ObeoNetwork.
the class MLDToEntity method createEntity.
private void createEntity(Table table) {
Entity entity = getFromInputTraceabilityMap(table, EntityPackage.Literals.ENTITY);
if (entity == null) {
// The entity does not already exist
// We have to create a new one
entity = EntityFactory.eINSTANCE.createEntity();
getTargetNamespace(table.getOwner()).getTypes().add(entity);
entity.setName(LabelProvider.getEntityNameFromTable(table));
}
// Add to new traceability map
addToOutputTraceability(table, entity);
// The following properties are modified even if they already existed
AnnotationHelper.setPhysicalNameAnnotation(entity, LabelProvider.getEntityPhysicalNameFromTable(table));
entity.setDescription(table.getComments());
AnnotationHelper.removePhysicalUniqueAnnotations(entity);
for (Column column : table.getColumns()) {
if (!column.isInForeignKey() && !column.isInPrimaryKey() && !AdditionalFieldsUtils.isAdditionalColumn(column)) {
createAttribute(column, entity);
}
}
AnnotationHelper.removePhysicalCheckAnnotations(entity);
List<Constraint> constraintsToCreate = new ArrayList<Constraint>();
for (Constraint constraint : table.getConstraints()) {
if (!AdditionalFieldsUtils.isAdditionalConstraint(constraint)) {
constraintsToCreate.add(constraint);
}
}
AnnotationHelper.setAllConstraints(entity, constraintsToCreate);
}
use of org.obeonetwork.dsl.database.Constraint in project InformationSystem by ObeoNetwork.
the class MpdToMldBidiRules method createConstraint.
private void createConstraint(Constraint sourceConstraint, Table targetTable) {
Constraint targetConstraint = getFromInputTraceabilityMap(sourceConstraint, DatabasePackage.Literals.CONSTRAINT);
if (targetConstraint != null) {
// ensure it is contained by the right table
if (!EcoreUtil.equals(targetConstraint.getOwner(), targetTable)) {
targetTable.getConstraints().add(targetConstraint);
}
} else {
// We have to create a new constraint
targetConstraint = DatabaseFactory.eINSTANCE.createConstraint();
targetTable.getConstraints().add(targetConstraint);
}
addToOutputTraceability(sourceConstraint, targetConstraint);
targetConstraint.setName(sourceConstraint.getName());
targetConstraint.setExpression(sourceConstraint.getExpression());
targetConstraint.setComments(sourceConstraint.getComments());
}
use of org.obeonetwork.dsl.database.Constraint in project InformationSystem by ObeoNetwork.
the class TableConstraintsPropertiesEditionComponent 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.Constraints.Properties.constraints_ == event.getAffectedEditor()) {
if (event.getKind() == PropertiesEditionEvent.ADD) {
EReferencePropertiesEditionContext context = new EReferencePropertiesEditionContext(editingContext, this, constraintsSettings, 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) {
constraintsSettings.removeFromReference((EObject) event.getNewValue());
} else if (event.getKind() == PropertiesEditionEvent.MOVE) {
constraintsSettings.move(event.getNewIndex(), (Constraint) event.getNewValue());
}
}
}
use of org.obeonetwork.dsl.database.Constraint in project InformationSystem by ObeoNetwork.
the class OracleDataBaseBuilder method buildColumnConstraint.
@Override
protected void buildColumnConstraint(DatabaseMetaData metaData, TableContainer owner, Column column) {
Schema schema = (Schema) owner;
String key = schema.getName() + column.getOwner().getName() + column.getName();
if (cacheConstraints == null) {
cacheConstraints = new HashMap<String, OracleConstraint>();
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
PreparedStatement psmt = metaData.getConnection().prepareStatement(" SELECT dc.constraint_name, dc.search_condition, dcc.table_name, dcc.column_name " + " FROM all_constraints dc, all_cons_columns dcc " + " where dc.owner=?" + " AND dcc.owner=?" + " AND constraint_type='C'" + " AND substr(dc.constraint_name,1,3) <> 'SYS'" + " AND dc.owner=dcc.owner" + " AND dc.constraint_name=dcc.constraint_name" + " ORDER BY dc.constraint_name");
psmt.setString(1, schema.getName());
psmt.setString(2, schema.getName());
rs = psmt.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
// do not reference recyclebin internal name
if (name.startsWith("BIN$")) {
name = "";
}
String expression = rs.getString(2);
String tableName = rs.getString(3);
String columnName = rs.getString(4);
if (!expression.endsWith("IS NOT NULL")) {
OracleConstraint oracleConstraint = new OracleConstraint(tableName, name, expression);
cacheConstraints.put(schema.getName() + tableName + columnName, oracleConstraint);
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
JdbcUtils.closeStatement(pstmt);
JdbcUtils.closeResultSet(rs);
}
}
if (cacheConstraints.containsKey(key)) {
OracleConstraint oracleConstraint = cacheConstraints.get(key);
AbstractTable table = queries.getTable(owner, oracleConstraint.tableName);
Constraint constraint = CreationUtils.createConstraint((Table) table, oracleConstraint.name);
constraint.setExpression(oracleConstraint.expression);
}
}
use of org.obeonetwork.dsl.database.Constraint in project InformationSystem by ObeoNetwork.
the class CreationUtils method createConstraint.
public static Constraint createConstraint(Table owner, String name) {
Constraint constraint = DatabaseFactory.eINSTANCE.createConstraint();
constraint.setName(name);
constraint.setOwner(owner);
return constraint;
}
Aggregations