use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class MpdToMldBidiRules method createOrUpdateSequences.
/**
* Create needed new sequences or update existing ones
* @param sourceTableContainer
* @return list of sequences processed so that all other sequences (now useless) could be removed
*/
/**
* @param sourceTableContainer
* @return
*/
private Collection<Sequence> createOrUpdateSequences(TableContainer sourceTableContainer) {
Collection<Sequence> sequences = new ArrayList<Sequence>();
// for each non-composite PK we create a sequence and associate it with the PK column
for (AbstractTable sourceAbstractTable : sourceTableContainer.getTables()) {
if (sourceAbstractTable instanceof Table) {
Table sourceTable = (Table) sourceAbstractTable;
// Get associated table
Table targetTable = getFromOutputTraceabilityMap(sourceTable, DatabasePackage.Literals.TABLE);
if (targetTable != null) {
PrimaryKey pk = targetTable.getPrimaryKey();
// Only for non-composite PK
if (pk != null && pk.getColumns().size() == 1) {
Column targetColumn = pk.getColumns().get(0);
// Retrieve the potentially existing sequence
Sequence existingSequence = targetColumn.getSequence();
String sequenceName = targetTable.getName() + "_SEQ";
if (existingSequence != null) {
// Update name
existingSequence.setName(sequenceName);
// Ensure the sequence is in the right container
if (!targetTable.getOwner().getSequences().contains(existingSequence)) {
targetTable.getOwner().getSequences().add(existingSequence);
}
sequences.add(existingSequence);
} else {
// Create a new sequence
Sequence newSequence = DatabaseFactory.eINSTANCE.createSequence();
newSequence.setName(sequenceName);
newSequence.setIncrement(new BigInteger("1"));
newSequence.setStart(new BigInteger("1"));
newSequence.setComments(String.format(SEQUENCE_INITIAL_COMMENTS, targetTable.getName()));
targetTable.getOwner().getSequences().add(newSequence);
// Retrieve the associated column and associate it with the sequence
targetColumn.setSequence(newSequence);
sequences.add(newSequence);
}
}
}
}
}
if (sourceTableContainer instanceof DataBase) {
DataBase sourceDataBase = (DataBase) sourceTableContainer;
for (Schema sourceSchema : sourceDataBase.getSchemas()) {
sequences.addAll(createOrUpdateSequences(sourceSchema));
}
}
return sequences;
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class DefaultDataBaseBuilder method buildPrimaryKeys.
protected void buildPrimaryKeys(DatabaseMetaData metaData, Table table) {
PrimaryKey primaryKey = null;
ResultSet rs = null;
try {
rs = metaData.getPrimaryKeys(null, schemaName, table.getName());
while (rs.next()) {
if (primaryKey == null) {
String primaryKeyName = rs.getString(6);
primaryKey = CreationUtils.createPrimaryKey(table, primaryKeyName);
}
buildPrimaryKey(table, rs, primaryKey);
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
JdbcUtils.closeResultSet(rs);
}
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class CreationUtils method createPrimaryKey.
public static PrimaryKey createPrimaryKey(Table table, String name) {
PrimaryKey primaryKey = DatabaseFactory.eINSTANCE.createPrimaryKey();
primaryKey.setName(name);
primaryKey.setOwner(table);
table.setPrimaryKey(primaryKey);
return primaryKey;
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class PrimaryKeyChangeItemProvider 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) {
PrimaryKeyChange primaryKeyChange = (PrimaryKeyChange) object;
PrimaryKey primaryKey = primaryKeyChange.getPrimaryKey();
return getString("_UI_PrimaryKeyChange_type") + " " + primaryKey.getName();
}
use of org.obeonetwork.dsl.database.PrimaryKey in project InformationSystem by ObeoNetwork.
the class RemovePrimaryKeyItemProvider 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) {
RemovePrimaryKey removePrimaryKey = (RemovePrimaryKey) object;
PrimaryKey primaryKey = removePrimaryKey.getPrimaryKey();
return getString("_UI_RemovePrimaryKey_type") + " " + primaryKey.getName();
}
Aggregations