}
private int alterDatabase(AlterDatabaseDesc alterDbDesc) throws HiveException {
String dbName = alterDbDesc.getDatabaseName();
Database database = db.getDatabase(dbName);
if (database == null) {
throw new HiveException(ErrorMsg.DATABASE_NOT_EXISTS, dbName);
}
switch (alterDbDesc.getAlterType()) {
case ALTER_PROPERTY:
Map<String, String> newParams = alterDbDesc.getDatabaseProperties();
if (database != null) {
Map<String, String> params = database.getParameters();
// if both old and new params are not null, merge them
if (params != null && newParams != null) {
params.putAll(newParams);
database.setParameters(params);
} else { // if one of them is null, replace the old params with the new
// one
database.setParameters(newParams);
}
}
break;
case ALTER_OWNER:
database.setOwnerName(alterDbDesc.getOwnerPrincipal().getName());
database.setOwnerType(alterDbDesc.getOwnerPrincipal().getType());
break;
default:
throw new AssertionError("Unsupported alter database type! : " + alterDbDesc.getAlterType());
}
db.alterDatabase(database.getName(), database);
return 0;
}