use of org.datanucleus.store.rdbms.key.Index in project datanucleus-rdbms by datanucleus.
the class TableImpl method isIndexReallyNeeded.
/**
* Utility to check if an index is necessary.
* @param requiredIdx The index
* @param actualIndices The actual indexes
* @return Whether the index is needed (i.e not present in the actual indexes)
*/
private boolean isIndexReallyNeeded(Index requiredIdx, Collection actualIndices) {
Iterator i = actualIndices.iterator();
if (requiredIdx.getName() != null) {
// Compare the index name since it is defined
IdentifierFactory idFactory = requiredIdx.getTable().getStoreManager().getIdentifierFactory();
// Allow for user input in incorrect case
String reqdName = idFactory.getIdentifierInAdapterCase(requiredIdx.getName());
while (i.hasNext()) {
Index actualIdx = (Index) i.next();
// Allow for DB returning no quotes
String actualName = idFactory.getIdentifierInAdapterCase(actualIdx.getName());
if (actualName.equals(reqdName) && actualIdx.getTable().getIdentifier().toString().equals(requiredIdx.getTable().getIdentifier().toString())) {
// There already is an index of that name for the same table in the actual list so not needed
return false;
}
}
} else {
// Compare against the index table and columns since we have no index name yet
while (i.hasNext()) {
Index actualIdx = (Index) i.next();
if (actualIdx.toString().equals(requiredIdx.toString()) && actualIdx.getTable().getIdentifier().toString().equals(requiredIdx.getTable().getIdentifier().toString())) {
// There already is an index of that name for the same table in the actual list so not needed
return false;
}
}
}
return true;
}
use of org.datanucleus.store.rdbms.key.Index in project datanucleus-rdbms by datanucleus.
the class SAPDBAdapter method getAddCandidateKeyStatement.
public String getAddCandidateKeyStatement(CandidateKey ck, IdentifierFactory factory) {
Index idx = new Index(ck);
idx.setName(ck.getName());
return getCreateIndexStatement(idx, factory);
}
use of org.datanucleus.store.rdbms.key.Index in project datanucleus-rdbms by datanucleus.
the class TimesTenAdapter method getAddCandidateKeyStatement.
/**
* Returns the appropriate SQL to add a candidate key to its table.
* It should return something like:
* <pre>
* ALTER TABLE FOO ADD CONSTRAINT FOO_CK (BAZ)
* ALTER TABLE FOO ADD (BAZ)
* </pre>
*
* @param ck An object describing the candidate key.
* @param factory Identifier factory
* @return The text of the SQL statement.
*/
public String getAddCandidateKeyStatement(CandidateKey ck, IdentifierFactory factory) {
Index idx = new Index(ck);
idx.setName(ck.getName());
return getCreateIndexStatement(idx, factory);
}
Aggregations