}
if (!createdSchemas.contains(schemaName) && !StringUtils.isEmpty(adminPassword)) {
String adminProfile = profile + "Admin";
logger.info("Admin-Profile defined: {}. Creating Schema '{}' if necessary", adminProfile, schemaName);
JuConnUtil adminConnUtil = JuConnUtils.build()
.profile(adminProfile)
.create();
// Check if the Schema exists and if we should delete it if so
boolean createSchema = true;
if (adminConnUtil.getMetaDataInfo().getSchemaInfos().getSchemaNames().contains(schemaName)) {
boolean dropExistingSchema = JuUtils.getJuPropertyChain().get(
String.format("ju-dbutil-test.%s.dropExistingSchema", adminProfile), Boolean.class, "false");
if (dropExistingSchema) {
logger.info("Schema {} already exists. Dropping and recreating.", schemaName);
List<SchemaInfo> schemaInfos = adminConnUtil.getMetaDataInfo().getSchemaInfos()
.getSchemaInfos(schemaName, null);
Assert.assertEquals("Catalogs not supported yet", 1, schemaInfos.size());
if (adminConnUtil.getDbType() == DbType.MYSQL) {
// For MySQL, drop the user as well
adminConnUtil.getDbHandler().dropSchema(schemaInfos.get(0), userName);
} else {
adminConnUtil.getDbHandler().dropSchema(schemaInfos.get(0));
}
} else {
createSchema = false;
logger.info(
"Schema {} already exists. Skipping creation. Set dropExistingSchema for adminProfile to true if Schema should be dropped and recreated.",
schemaName);
}
}
if (createSchema) {
logger.info("Creating Schema {}", schemaName);
String schemaPassword = JuUtils.getJuPropertyChain().get(String.format("ju-dbutil-test.%s.password", profile), false);
boolean jtaRecoveryGrants = JuUtils.getJuPropertyChain().get(
String.format("ju-dbutil-test.%s.jtaRecoveryGrants", profile), Boolean.class, "false");
adminConnUtil.getDbHandler().createSchema()
.name(schemaName)
.user(userName) // Ignored for DBs that don't have users
.password(schemaPassword)
.jtaRecoveryGrants(jtaRecoveryGrants)
.create();