Search in sources :

Example 1 with MissingTableException

use of org.datanucleus.store.rdbms.exceptions.MissingTableException in project datanucleus-rdbms by datanucleus.

the class ViewImpl method validate.

/**
 * Method to validate the view in the datastore. Validates the existence of the table, and then the specifications of the Columns.
 * @param conn The JDBC Connection
 * @param validateColumnStructure Whether to validate down to column structure, or just their existence
 * @param autoCreate Whether to update the view to fix errors (not used).
 * @param autoCreateErrors Errors found during 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 (// TODO Allow "MATERIALIZED VIEW" that some RDBMS support (e.g PostgreSQL)
    !tableType.equals("VIEW")) {
        throw new NotAViewException(this.toString(), tableType);
    }
    long startTime = System.currentTimeMillis();
    if (NucleusLogger.DATASTORE.isDebugEnabled()) {
        NucleusLogger.DATASTORE.debug(Localiser.msg("031004", this));
    }
    // Validate the column(s)
    Map<DatastoreIdentifier, Column> unvalidated = new HashMap(columnsByIdentifier);
    Iterator i = storeMgr.getColumnInfoForTable(this, conn).iterator();
    while (i.hasNext()) {
        RDBMSColumnInfo ci = (RDBMSColumnInfo) i.next();
        DatastoreIdentifier colIdentifier = storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN, ci.getColumnName());
        Column col = unvalidated.get(colIdentifier);
        if (col == null) {
            if (!hasColumnName(colIdentifier)) {
                throw new UnexpectedColumnException(this.toString(), ci.getColumnName(), this.getSchemaName(), this.getCatalogName());
            }
        // Otherwise it's a duplicate column name in the metadata and we ignore it.  Cloudscape is known to do this, although I think that's probably a bug.
        } else {
            if (validateColumnStructure) {
                col.validate(ci);
                unvalidated.remove(colIdentifier);
            } else {
                unvalidated.remove(colIdentifier);
            }
        }
    }
    if (unvalidated.size() > 0) {
        throw new MissingColumnException(this, unvalidated.values());
    }
    state = TABLE_STATE_VALIDATED;
    if (NucleusLogger.DATASTORE.isDebugEnabled()) {
        NucleusLogger.DATASTORE.debug(Localiser.msg("045000", (System.currentTimeMillis() - startTime)));
    }
    return false;
}
Also used : RDBMSColumnInfo(org.datanucleus.store.rdbms.schema.RDBMSColumnInfo) NotAViewException(org.datanucleus.store.rdbms.exceptions.NotAViewException) HashMap(java.util.HashMap) MissingColumnException(org.datanucleus.store.rdbms.exceptions.MissingColumnException) RDBMSSchemaHandler(org.datanucleus.store.rdbms.schema.RDBMSSchemaHandler) DatastoreIdentifier(org.datanucleus.store.rdbms.identifier.DatastoreIdentifier) Iterator(java.util.Iterator) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) UnexpectedColumnException(org.datanucleus.store.rdbms.exceptions.UnexpectedColumnException)

Example 2 with MissingTableException

use of org.datanucleus.store.rdbms.exceptions.MissingTableException 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;
}
Also used : NotATableException(org.datanucleus.store.rdbms.exceptions.NotATableException) WrongPrimaryKeyException(org.datanucleus.store.rdbms.exceptions.WrongPrimaryKeyException) RDBMSSchemaHandler(org.datanucleus.store.rdbms.schema.RDBMSSchemaHandler) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException)

Example 3 with MissingTableException

use of org.datanucleus.store.rdbms.exceptions.MissingTableException in project hive by apache.

the class ObjectStore method getMSchemaVersion.

private MVersionTable getMSchemaVersion() throws NoSuchObjectException, MetaException {
    boolean committed = false;
    Query query = null;
    List<MVersionTable> mVerTables = new ArrayList<>();
    try {
        openTransaction();
        query = pm.newQuery(MVersionTable.class);
        try {
            mVerTables = (List<MVersionTable>) query.execute();
            pm.retrieveAll(mVerTables);
        } catch (JDODataStoreException e) {
            if (e.getCause() instanceof MissingTableException) {
                throw new MetaException("Version table not found. " + "The metastore is not upgraded to " + MetaStoreSchemaInfoFactory.get(getConf()).getHiveSchemaVersion());
            } else {
                throw e;
            }
        }
        committed = commitTransaction();
        if (mVerTables.isEmpty()) {
            throw new NoSuchObjectException("No matching version found");
        }
        if (mVerTables.size() > 1) {
            String msg = "Metastore contains multiple versions (" + mVerTables.size() + ") ";
            for (MVersionTable version : mVerTables) {
                msg += "[ version = " + version.getSchemaVersion() + ", comment = " + version.getVersionComment() + " ] ";
            }
            throw new MetaException(msg.trim());
        }
        return mVerTables.get(0);
    } finally {
        rollbackAndCleanup(committed, query);
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MVersionTable(org.apache.hadoop.hive.metastore.model.MVersionTable) ArrayList(java.util.ArrayList) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) JDODataStoreException(javax.jdo.JDODataStoreException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

MissingTableException (org.datanucleus.store.rdbms.exceptions.MissingTableException)3 RDBMSSchemaHandler (org.datanucleus.store.rdbms.schema.RDBMSSchemaHandler)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 Query (javax.jdo.Query)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)1 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)1 MVersionTable (org.apache.hadoop.hive.metastore.model.MVersionTable)1 MissingColumnException (org.datanucleus.store.rdbms.exceptions.MissingColumnException)1 NotATableException (org.datanucleus.store.rdbms.exceptions.NotATableException)1 NotAViewException (org.datanucleus.store.rdbms.exceptions.NotAViewException)1 UnexpectedColumnException (org.datanucleus.store.rdbms.exceptions.UnexpectedColumnException)1 WrongPrimaryKeyException (org.datanucleus.store.rdbms.exceptions.WrongPrimaryKeyException)1 DatastoreIdentifier (org.datanucleus.store.rdbms.identifier.DatastoreIdentifier)1 RDBMSColumnInfo (org.datanucleus.store.rdbms.schema.RDBMSColumnInfo)1