use of org.obeonetwork.dsl.database.AbstractTable in project InformationSystem by ObeoNetwork.
the class DatabaseServices method allReferencedTables.
/**
* Retrieve all referenced Tables.
* @param context the Table Container
* @return list of Tables
*/
public List<Table> allReferencedTables(TableContainer context) {
// Retrieve all tables
List<AbstractTable> abstractTables = context.getTables();
List<Table> tables = new ArrayList<Table>();
List<Table> tablesFKtarget = new ArrayList<Table>();
// Retrieve all tables instance of Table
for (AbstractTable abstractTable : abstractTables) {
if (abstractTable instanceof Table) {
tables.add((Table) abstractTable);
}
}
// Retrieve all foreigns keys for the tables
for (Table table : tables) {
for (ForeignKey fk : table.getForeignKeys()) {
if (!tablesFKtarget.contains(fk.getTarget())) {
// retrieve all table from target of foreigns keys
tablesFKtarget.add(fk.getTarget());
}
}
}
Set<Table> allReferencedTables = new HashSet<Table>();
// Remove duplicates
allReferencedTables.addAll(tablesFKtarget);
return new ArrayList<Table>(allReferencedTables);
}
use of org.obeonetwork.dsl.database.AbstractTable in project InformationSystem by ObeoNetwork.
the class DatabaseServices method getForeignKeys.
/**
* Return ForeignKeys from tables.
* @param tableContainer
* @return foreignKeys
*/
public List<ForeignKey> getForeignKeys(TableContainer tableContainer, DSemanticDiagram diagram) {
List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
List<AbstractTable> tables = tableContainer.getTables();
for (AbstractTable abstractTable : tables) {
if (abstractTable instanceof Table) {
foreignKeys.addAll(((Table) abstractTable).getForeignKeys());
}
}
// Foreign keys from external tables on diagram
for (DDiagramElement diagramElement : diagram.getDiagramElements()) {
EObject semanticElt = diagramElement.getTarget();
if (semanticElt instanceof Table) {
foreignKeys.addAll(((Table) semanticElt).getForeignKeys());
}
}
return foreignKeys;
}
use of org.obeonetwork.dsl.database.AbstractTable in project InformationSystem by ObeoNetwork.
the class DefaultDataBaseBuilder method buildForeignKeys.
@Override
public void buildForeignKeys() {
ArrayList<AbstractTable> tables = new ArrayList<AbstractTable>();
tables.addAll(tableContainer.getTables());
for (AbstractTable table : tables) {
if (table instanceof Table) {
buildForeignKeys((Table) table);
}
}
}
use of org.obeonetwork.dsl.database.AbstractTable in project InformationSystem by ObeoNetwork.
the class H2DataBaseBuilder method buildSequences.
private void buildSequences(DatabaseMetaData metaData, TableContainer owner) {
ResultSet rs = null;
PreparedStatement pstmt = null;
try {
// TODO récupérer cycle avec IS_CYCLE
// TODO récupérer Cache
PreparedStatement psmt = metaData.getConnection().prepareStatement("SELECT SEQUENCE_NAME, INCREMENT, MIN_VALUE, MAX_VALUE, CURRENT_VALUE " + "FROM INFORMATION_SCHEMA.SEQUENCES");
rs = psmt.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
BigInteger increment = getBigIntValueForColumn(rs, 2);
BigInteger minValue = getBigIntValueForColumn(rs, 3);
BigInteger maxValue = getBigIntValueForColumn(rs, 4);
BigInteger start = getBigIntValueForColumn(rs, 5);
Sequence sequence = CreationUtils.createSequence(owner, name, increment, minValue, maxValue, start, false, null);
// Look for a table that could correspond to the sequence
if (name.endsWith("_SEQ")) {
String tableName = name.substring(0, name.length() - "_SEQ".length());
AbstractTable abstractTable = queries.getTable(tableName);
if (abstractTable != null && abstractTable instanceof Table) {
Table table = (Table) abstractTable;
if (table.getPrimaryKey() != null && table.getPrimaryKey().getColumns().size() == 1) {
Column column = table.getPrimaryKey().getColumns().get(0);
column.setSequence(sequence);
}
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
JdbcUtils.closeStatement(pstmt);
JdbcUtils.closeResultSet(rs);
}
}
use of org.obeonetwork.dsl.database.AbstractTable in project InformationSystem by ObeoNetwork.
the class MySQLDataBaseBuilder method removeIndexForFK.
private void removeIndexForFK(TableContainer owner) {
HashSet<String> fkNames = new HashSet<String>();
for (AbstractTable table : owner.getTables()) {
if (table instanceof Table) {
for (ForeignKey foreignKey : ((Table) table).getForeignKeys()) {
fkNames.add(foreignKey.getName());
}
}
}
for (AbstractTable t : owner.getTables()) {
if (t instanceof Table) {
Table table = (Table) t;
ArrayList<Index> indices = new ArrayList<Index>();
if (table.getIndexes().size() > 0) {
for (Index index : table.getIndexes()) {
if (!fkNames.contains(index.getName())) {
indices.add(index);
} else {
for (IndexElement indexElt : index.getElements()) {
indexElt.getColumn().getIndexElements().remove(indexElt);
}
}
}
table.getIndexes().clear();
table.getIndexes().addAll(indices);
}
}
}
}
Aggregations