final DbOpReplicationContext repContext =
new DbOpReplicationContext(wireRecord.getVLSN(), nameLNEntry);
DbOperationType opType = repContext.getDbOperationType();
DatabaseImpl dbImpl = null;
try {
switch (opType) {
case CREATE:
{
DatabaseConfig dbConfig =
repContext.getCreateConfig().getReplicaConfig(repImpl);
dbImpl = repImpl.getDbTree().createReplicaDb
(repTxn, databaseName, dbConfig, nameLN, repContext);
/*
* We rely on the RepGroupDB.DB_ID value, so make sure
* it's what we expect for this internal replicated
* database.
*/
if ((dbImpl.getId().getId() == RepGroupDB.DB_ID) &&
!DbType.REP_GROUP.getInternalName().equals
(databaseName)) {
throw EnvironmentFailureException.unexpectedState
("Database: " +
DbType.REP_GROUP.getInternalName() +
" is associated with id: " +
dbImpl.getId().getId() +
" and not the reserved database id: " +
RepGroupDB.DB_ID);
}
TriggerManager.runOpenTriggers(repTxn, dbImpl, true);
break;
}
case REMOVE: {
dbImpl = repImpl.getDbTree().getDb(nameLN.getId());
try {
repImpl.getDbTree().removeReplicaDb
(repTxn, databaseName, nameLN.getId(), repContext);
TriggerManager.runRemoveTriggers(repTxn, dbImpl);
} catch (DatabaseNotFoundException e) {
throw EnvironmentFailureException.unexpectedState
("Database: " + dbImpl.getName() +
" Id: " + nameLN.getId() +
" not found on the Replica.");
}
break;
}
case TRUNCATE: {
dbImpl = repImpl.getDbTree().getDb
(repContext.getTruncateOldDbId());
try {
TruncateDbResult result =
repImpl.getDbTree().truncateReplicaDb
(repTxn, databaseName, false, nameLN, repContext);
TriggerManager.runTruncateTriggers(repTxn, result.newDb);
} catch (DatabaseNotFoundException e) {
throw EnvironmentFailureException.unexpectedState
("Database: " + dbImpl.getName() +
" Id: " + nameLN.getId() +
" not found on the Replica.");
}
break;
}
case RENAME: {
dbImpl = repImpl.getDbTree().getDb(nameLN.getId());
try {
dbImpl =
repImpl.getDbTree().renameReplicaDb
(repTxn, dbImpl.getName(), databaseName, nameLN,
repContext);
TriggerManager.runRenameTriggers(repTxn, dbImpl,
databaseName);
} catch (DatabaseNotFoundException e) {
throw EnvironmentFailureException.unexpectedState
("Database rename from: " + dbImpl.getName() +
" to " + databaseName +
" failed, name not found on the Replica.");
}
break;
}
case UPDATE_CONFIG: {
/* Get the replicated database configurations. */
DatabaseConfig dbConfig =
repContext.getCreateConfig().getReplicaConfig(repImpl);
/* Update the NameLN and write it to the log. */
dbImpl = repImpl.getDbTree().getDb(nameLN.getId());
final String dbName = dbImpl.getName();
repImpl.getDbTree().updateNameLN
(repTxn, dbName, repContext);
/* Set the new configurations to DatabaseImpl. */
dbImpl.setConfigProperties
(repTxn, dbName, dbConfig, repImpl);
repImpl.getDbTree().modifyDbRoot(dbImpl);
break;