private void doDelete(String arg) throws BrokerException {
doDelete(arg, null);
}
private void doDelete(String arg, CommDBManager mgrArg) throws BrokerException {
CommDBManager mgr = (mgrArg == null ? dbmgr:mgrArg);
boolean deleted = false;
Connection conn = null;
Exception myex = null;
try {
conn = mgr.getConnection(true);
if (arg == null || arg.length() == 0) {
// Check if store exist
boolean continueOnError = false;
int status = mgr.checkStoreExists( conn );
if (status > 0 && !(mgr instanceof ShareConfigChangeDBManager)) {
// Verify cluster is not active in HA mode
if (!forceSpecified && Globals.getHAEnabled() &&
((DBManager)mgr).isHAClusterActive(conn)) {
throw new BrokerException(br.getKString(
BrokerResources.E_HA_CLUSTER_STILL_ACTIVE, dbmgr.getClusterID()));
}
try {
// lock the tables first (implemented since version 350);
// note that we don't need to unlock the tables since
// the tables will be dropped when we are done
if (!forceSpecified) {
((DBManager)mgr).lockTables(conn, true); // true = lock
}
} catch ( BrokerException e ) {
if ( e.getStatusCode() == Status.NOT_FOUND ) {
// For some reason if version table doesn't exist or
// version data is not found we can just ignore the error!
continueOnError = true;
} else {
throw e;
}
}
} else if (status > 0 && (mgr instanceof ShareConfigChangeDBManager)) {
try {
if (!forceSpecified) {
((ShareConfigChangeDBManager)mgr).lockTable(conn, true);
}
} catch ( BrokerException e ) {
if ( e.getStatusCode() == Status.NOT_FOUND ) {
continueOnError = true;
} else {
throw e;
}
}
} else if (status < 0) {
// Some tables are missings so try to delete the rest
// but ignore error if table does not exists
continueOnError = true;
} else {
if (!(mgr instanceof ShareConfigChangeDBManager)) {
// All tables have already been deleted
throw new BrokerException(br.getKString(
BrokerResources.E_DATABASE_TABLE_ALREADY_DELETED));
} else {
throw new BrokerException(br.getKString(
BrokerResources.E_SHARECC_TABLE_ALREADY_DELETED,
Globals.getClusterID()));
}
}
deleted = dropTables(conn, null, continueOnError, mgrArg);
} else if (arg.equals(ARGU_OLDTBL)) {
int oldStoreVersion = -1;
if ( checkVersion( conn,
VERSION_TBL_37 + dbmgr.getBrokerID() ) ) {
oldStoreVersion = JDBCStore.OLD_STORE_VERSION_370;
} else if ( checkVersion( conn,
VERSION_TBL_35 + dbmgr.getBrokerID() ) ) {
oldStoreVersion = JDBCStore.OLD_STORE_VERSION_350;
} else {
throw new BrokerException("Old persistent store (version " +
JDBCStore.OLD_STORE_VERSION_370 + ") not found");
}
deleted = dropTables(conn, dbmgr.getTableNames(oldStoreVersion));
} else {
// not possible since argument is checked already
}
if (standalone && deleted) {
if ( Globals.getHAEnabled() ) {
System.out.println( br.getString(
BrokerResources.I_DATABASE_TABLE_HA_DELETED,
Globals.getClusterID() ) );
} else if (mgr instanceof ShareConfigChangeDBManager) {
System.out.println( br.getString(
BrokerResources.I_SHARECC_DATABASE_TABLE_DELETED,
Globals.getClusterID() ) );
} else {
System.out.println(br.getString(BrokerResources.I_DATABASE_TABLE_DELETED));
}
}
} catch (Exception e) {
myex = e;
if (debugSpecified) {
e.printStackTrace();
}
if (!(mgr instanceof ShareConfigChangeDBManager)) {
throw new BrokerException(
br.getKString(BrokerResources.E_DELETE_DATABASE_TABLE_FAILED,
mgr.getOpenDBURL()), e);
} else {
throw new BrokerException(
br.getKString(BrokerResources.E_SHARECC_FAIL_DELETE_TABLE,
Globals.getClusterID(), mgr.getOpenDBURL()), e);
}
} finally {
Util.close( null, null, conn, myex, mgrArg );
}
}