use of org.datanucleus.store.rdbms.exceptions.NotATableException in project datanucleus-rdbms by datanucleus.
the class TableImpl method validate.
/**
* Method to validate the table in the datastore.
* @param conn The JDBC Connection
* @param validateColumnStructure Whether to validate the column structure, or just the column existence
* @param autoCreate Whether to update the table to fix any validation errors. Only applies to missing columns.
* @param autoCreateErrors Exceptions found in the "auto-create" process
* @return Whether the database was modified
* @throws SQLException Thrown when an error occurs in the JDBC calls
*/
public boolean validate(Connection conn, boolean validateColumnStructure, boolean autoCreate, Collection autoCreateErrors) throws SQLException {
assertIsInitialized();
// Check existence and validity
RDBMSSchemaHandler handler = (RDBMSSchemaHandler) storeMgr.getSchemaHandler();
String tableType = handler.getTableType(conn, this);
if (tableType == null) {
throw new MissingTableException(getCatalogName(), getSchemaName(), this.toString());
} else if (!tableType.equals("TABLE")) {
throw new NotATableException(this.toString(), tableType);
}
long startTime = System.currentTimeMillis();
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("057032", this));
}
// Validate the column(s)
validateColumns(conn, validateColumnStructure, autoCreate, autoCreateErrors);
// Validate the primary key(s)
try {
validatePrimaryKey(conn);
} catch (WrongPrimaryKeyException wpke) {
if (autoCreateErrors != null) {
autoCreateErrors.add(wpke);
} else {
throw wpke;
}
}
state = TABLE_STATE_VALIDATED;
if (NucleusLogger.DATASTORE_SCHEMA.isDebugEnabled()) {
NucleusLogger.DATASTORE_SCHEMA.debug(Localiser.msg("045000", (System.currentTimeMillis() - startTime)));
}
return false;
}
Aggregations