Search in sources :

Example 1 with TypeDropStatement

use of org.apache.asterix.lang.common.statement.TypeDropStatement in project asterixdb by apache.

the class QueryTranslator method handleTypeDropStatement.

protected void handleTypeDropStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
    TypeDropStatement stmtTypeDrop = (TypeDropStatement) stmt;
    String dataverseName = getActiveDataverse(stmtTypeDrop.getDataverseName());
    String typeName = stmtTypeDrop.getTypeName().getValue();
    MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
    metadataProvider.setMetadataTxnContext(mdTxnCtx);
    MetadataLockManager.INSTANCE.dropTypeBegin(metadataProvider.getLocks(), dataverseName, dataverseName + "." + typeName);
    try {
        Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, dataverseName, typeName);
        if (dt == null) {
            if (!stmtTypeDrop.getIfExists()) {
                throw new AlgebricksException("There is no datatype with this name " + typeName + ".");
            }
        } else {
            MetadataManager.INSTANCE.dropDatatype(mdTxnCtx, dataverseName, typeName);
        }
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (Exception e) {
        abort(e, e, mdTxnCtx);
        throw e;
    } finally {
        metadataProvider.getLocks().unlock();
    }
}
Also used : AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) TypeDropStatement(org.apache.asterix.lang.common.statement.TypeDropStatement) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) Datatype(org.apache.asterix.metadata.entities.Datatype)

Aggregations

IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 CompilationException (org.apache.asterix.common.exceptions.CompilationException)1 TypeDropStatement (org.apache.asterix.lang.common.statement.TypeDropStatement)1 MetadataException (org.apache.asterix.metadata.MetadataException)1 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)1 Datatype (org.apache.asterix.metadata.entities.Datatype)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1