protected void handleFunctionDropStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
FunctionDropStatement stmtDropFunction = (FunctionDropStatement) stmt;
SourceLocation sourceLoc = stmtDropFunction.getSourceLocation();
FunctionSignature signature = stmtDropFunction.getFunctionSignature();
signature.setNamespace(getActiveDataverseName(signature.getNamespace()));
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockUtil.functionStatementBegin(lockManager, metadataProvider.getLocks(), signature.getNamespace(),
signature.getNamespace() + "." + signature.getName());
try {
Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, signature);
if (function == null && !stmtDropFunction.getIfExists()) {
throw new CompilationException(ErrorCode.UNKNOWN_FUNCTION, sourceLoc, signature);
} else if (function != null) {
if (isFunctionUsed(mdTxnCtx, signature, null)) {
throw new MetadataException(ErrorCode.METADATA_DROP_FUCTION_IN_USE, sourceLoc, signature);
} else {
MetadataManager.INSTANCE.dropFunction(mdTxnCtx, signature);
}
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}