private void drop_database_core(RawStore ms,
final String name, final boolean deleteData, final boolean cascade)
throws NoSuchObjectException, InvalidOperationException, MetaException,
IOException {
boolean success = false;
Database db = null;
try {
ms.openTransaction();
db = ms.getDatabase(name);
List<String> allTables = get_all_tables(db.getName());
if (!cascade && !allTables.isEmpty()) {
throw new InvalidOperationException("Database " + db.getName() + " is not empty");
}
Path path = new Path(db.getLocationUri()).getParent();
if (!wh.isWritable(path)) {
throw new MetaException("Database not dropped since " +
path + " is not writable by " +
hiveConf.getUser());
}
if (ms.dropDatabase(name)) {
success = ms.commitTransaction();
}
} finally {
if (!success) {
ms.rollbackTransaction();
} else if (deleteData) {
wh.deleteDir(new Path(db.getLocationUri()), true);
// it is not a terrible thing even if the data is not deleted
}
for (MetaStoreEventListener listener : listeners) {
listener.onDropDatabase(new DropDatabaseEvent(db, success, this));
}