use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager in project openmq by eclipse-ee4j.
the class DBTool method doBackupSharecc.
/**
* Backup the shared table for cluster config change record to a file
*/
private void doBackupSharecc() throws BrokerException {
Properties props = System.getProperties();
String clusterID = Globals.getClusterID();
String backupfile = (String) props.get(ShareConfigChangeStore.CLUSTER_SHARECC_PROP_PREFIX + ".backupfile");
logger.logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP, clusterID, backupfile));
ShareConfigChangeDBManager mgr = ShareConfigChangeDBManager.getDBManager();
ShareConfigRecordDAO dao = mgr.getDAOFactory().getShareConfigRecordDAO();
try {
List<ChangeRecordInfo> records = null;
Util.RetryStrategy retry = null;
do {
try {
records = dao.getAllRecords(null, null);
break;
} catch (Exception e) {
if (retry == null) {
retry = new Util.RetryStrategy(mgr);
}
retry.assertShouldRetry(e);
}
} while (true);
Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP_RECORDS, String.valueOf(records.size()), dao.getTableName()));
ChangeRecord.backupRecords(records, backupfile, true);
Globals.getLogger().logToAll(Logger.INFO, br.getKString(br.I_SHARECC_BACKUP_RECORDS_SUCCESS, Globals.getClusterID(), backupfile));
} catch (BrokerException e) {
String emsg = br.getKString(br.E_SHARECC_BACKUP_RECORDS_FAIL, e.getMessage());
Globals.getLogger().logToAll(Logger.ERROR, emsg, e);
throw e;
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager in project openmq by eclipse-ee4j.
the class DBTool method doDump.
/**
* dump info about the database. for debugging purpose
*/
private void doDump(String arg, CommDBManager mgrArg) throws SQLException, BrokerException {
CommDBManager mgr = (mgrArg == null ? dbmgr : mgrArg);
String[] names = null;
if (!(mgr instanceof ShareConfigChangeDBManager)) {
int storeVersion = JDBCStore.STORE_VERSION;
if (arg != null) {
try {
storeVersion = Integer.parseInt(arg);
} catch (NumberFormatException e) {
storeVersion = 0;
}
}
if (storeVersion != JDBCStore.STORE_VERSION) {
// Old store
names = mgr.getTableNames(storeVersion);
if (names == null || names.length == 0) {
throw new BrokerException("version " + arg + " not supported");
}
}
}
Connection conn = null;
Exception myex = null;
try {
conn = mgr.getConnection(true);
doDump(conn, names, mgr);
} catch (SQLException | BrokerException e) {
myex = e;
throw e;
} finally {
Util.close(null, null, conn, myex, mgr);
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager in project openmq by eclipse-ee4j.
the class DBTool method doDelete.
private void doDelete(String arg, CommDBManager mgrArg, DeleteStatus deleteStatus) 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) {
if (mgr instanceof ShareConfigChangeDBManager) {
String[] oldnames = mgr.getAllOldTableNames();
if (oldnames != null && oldnames.length > 0) {
dropTables(conn, mgr.getAllOldTableNames(), true, true, mgr);
}
}
// 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 {
// the tables will be dropped when we are done
if (!forceSpecified) {
// true = lock
mgr.lockTables(conn, true);
}
} 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)) {
} 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 (deleteStatus == null) {
if (!(mgr instanceof ShareConfigChangeDBManager)) {
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()));
}
} else {
deleteStatus.deleted = true;
}
}
if (deleteStatus == null || !deleteStatus.deleted) {
deleted = dropTables(conn, continueOnError, mgrArg);
if (deleted && deleteStatus != null) {
deleteStatus.deleted = true;
}
}
} else if (arg.equals(ARGU_OLDTBL)) {
int oldStoreVersion = -1;
if (checkVersion(conn, VERSION_TBL_37 + dbmgr.getBrokerID(), dbmgr)) {
oldStoreVersion = JDBCStore.OLD_STORE_VERSION_370;
} else if (checkVersion(conn, VERSION_TBL_35 + dbmgr.getBrokerID(), dbmgr)) {
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), false, false, dbmgr);
} else {
// not possible since argument is checked already
}
if (standalone && deleted && deleteStatus == null) {
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);
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager in project openmq by eclipse-ee4j.
the class DBTool method dropTables.
public static boolean dropTables(Connection conn, boolean continueOnError, CommDBManager mgrArg) throws SQLException, BrokerException {
CommDBManager mgr = (mgrArg == null ? DBManager.getDBManager() : mgrArg);
boolean deleted = false;
try {
Iterator itr = mgr.allDAOIterator();
while (itr.hasNext()) {
BaseDAO dao = (BaseDAO) itr.next();
try {
Util.RetryStrategy retry = null;
do {
try {
dao.dropTable(conn);
if (mgr instanceof DBManager) {
dao.dropStoredProc(conn);
}
break;
} catch (Exception e) {
if (retry == null) {
retry = new Util.RetryStrategy(mgr);
}
retry.assertShouldRetry(e);
}
} while (true);
} catch (BrokerException be) {
if (continueOnError) {
Globals.getLogger().log(Logger.WARNING, be.toString(), be.getCause());
} else {
throw be;
}
}
}
deleted = true;
} catch (Exception e) {
if (!(mgr instanceof ShareConfigChangeDBManager)) {
Globals.getLogger().log(Logger.ERROR, BrokerResources.E_DELETE_DATABASE_TABLE_FAILED, e.toString(), e);
} else {
Globals.getLogger().log(Logger.ERROR, BrokerResources.E_SHARECC_FAIL_DELETE_TABLE, Globals.getClusterID(), e.toString(), e);
}
if (e instanceof SQLException) {
throw (SQLException) e;
}
if (e instanceof BrokerException) {
throw (BrokerException) e;
}
throw new BrokerException(e.getMessage(), e);
}
return deleted;
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.sharecc.ShareConfigChangeDBManager in project openmq by eclipse-ee4j.
the class DBTool method doRecreate.
private void doRecreate(CommDBManager mgrArg) throws BrokerException {
CommDBManager mgr = (mgrArg == null ? dbmgr : mgrArg);
Connection conn = null;
Throwable myex = null;
try {
DeleteStatus deleteStatus = new DeleteStatus();
doDelete(null, mgr, deleteStatus);
conn = mgr.getConnection(true);
createTables(conn, false, mgrArg);
if (standalone) {
if (Globals.getHAEnabled()) {
System.out.println(br.getString(BrokerResources.I_DATABASE_TABLE_HA_CREATED, Globals.getClusterID()));
} else if (mgr instanceof ShareConfigChangeDBManager) {
System.out.println(br.getString(BrokerResources.I_SHARECC_DATABASE_TABLE_CREATED, Globals.getClusterID()));
} else {
System.out.println(br.getString(BrokerResources.I_DATABASE_TABLE_CREATED));
}
}
} catch (Throwable t) {
myex = t;
if (!(mgr instanceof ShareConfigChangeDBManager)) {
throw new BrokerException(br.getKString(BrokerResources.E_RECREATE_DATABASE_TABLE_FAILED, mgr.getOpenDBURL()), t);
} else {
throw new BrokerException(br.getKString(BrokerResources.E_SHARECC_FAIL_RECREATE_TABLE, Globals.getClusterID(), mgr.getOpenDBURL()), t);
}
} finally {
Util.close(null, null, conn, myex, mgrArg);
}
}
Aggregations