use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO in project openmq by eclipse-ee4j.
the class DBTool method dropStoredProcs.
private static void dropStoredProcs(Connection conn, ArrayList<BaseDAO> daos) throws BrokerException {
CommDBManager mgr = DBManager.getDBManager();
Iterator<BaseDAO> itr = null;
if (daos == null) {
itr = mgr.allDAOIterator();
} else {
itr = daos.iterator();
}
while (itr.hasNext()) {
BaseDAO dao = itr.next();
try {
Util.RetryStrategy retry = null;
do {
try {
dao.dropStoredProc(conn);
// table created so break from retry loop
break;
} catch (Exception e) {
// Exception will be log & re-throw if operation cannot be retry
if (retry == null) {
retry = new Util.RetryStrategy(mgr);
}
retry.assertShouldRetry(e);
}
} while (true);
} catch (BrokerException be) {
Globals.getLogger().logStack(Logger.WARNING, be.getMessage(), be);
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO 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.comm.BaseDAO in project openmq by eclipse-ee4j.
the class JDBCStore method clearAll.
@Override
public void clearAll(boolean sync) throws BrokerException {
if (DEBUG) {
logger.log(Logger.INFO, "JDBCStore.clearAll() called");
}
// make sure store is not closed then increment in progress count
checkClosedAndSetInProgress();
Connection conn = null;
Exception myex = null;
try {
conn = dbmgr.getConnection(false);
Util.RetryStrategy retry = null;
do {
try {
if (Globals.getHAEnabled()) {
// In HA mode, only reset txns, dsts, states, and msgs
// in the specified order
daoFactory.getTransactionDAO().deleteAll(conn);
daoFactory.getDestinationDAO().deleteAll(conn);
daoFactory.getConsumerStateDAO().deleteAll(conn);
daoFactory.getMessageDAO().deleteAll(conn);
daoFactory.getTMLogRecordDAOJMSBG().deleteAll(conn);
daoFactory.getJMSBGDAO().deleteAll(conn);
} else {
List daos = daoFactory.getAllDAOs();
Iterator itr = daos.iterator();
while (itr.hasNext()) {
BaseDAO dao = (BaseDAO) itr.next();
if (!(dao instanceof VersionDAO || dao instanceof BrokerDAO || dao instanceof StoreSessionDAO)) {
dao.deleteAll(conn);
}
}
}
conn.commit();
return;
} catch (Exception e) {
// Exception will be log & re-throw if operation cannot be retry
if (retry == null) {
retry = new Util.RetryStrategy();
}
retry.assertShouldRetry(e);
}
} while (true);
} catch (Exception e) {
myex = e;
throw new BrokerException(br.getKString(BrokerResources.X_CLEAR_ALL_FAILED), e);
} finally {
try {
Util.close(null, null, conn, myex);
} finally {
// decrement in progress count
setInProgress(false);
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO in project openmq by eclipse-ee4j.
the class DBTool method doDump.
static void doDump(Connection dbconn, String[] tables, CommDBManager mgrArg) throws BrokerException, SQLException {
CommDBManager mgr = mgrArg;
if (tables != null && tables.length > 0) {
Statement stmt = null;
Exception myex = null;
try {
stmt = dbconn.createStatement();
for (int i = 0; i < tables.length; i++) {
ResultSet r = null;
String tname = tables[i];
String sql = "SELECT COUNT(*) FROM " + tname;
try {
r = mgr.executeQueryStatement(stmt, sql);
if (r.next()) {
System.out.println(tname + ": number of row=" + r.getInt(1));
}
r.close();
} catch (SQLException e) {
SQLException ex = mgr.wrapSQLException("[" + sql + "]", e);
logger.log(Logger.ERROR, "failed to dump tables", ex);
}
}
} catch (SQLException e) {
myex = e;
throw e;
} finally {
Util.close(null, stmt, null, myex, mgr);
}
} else {
// Starting in 4.0, use info from BaseDAO.getDebugInfo()
Iterator itr = mgr.allDAOIterator();
while (itr.hasNext()) {
BaseDAO dao = (BaseDAO) itr.next();
System.out.println(dao.getDebugInfo(dbconn).toString());
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.BaseDAO in project openmq by eclipse-ee4j.
the class DBTool method createStoredProcs.
private static void createStoredProcs(Connection conn) throws BrokerException {
ArrayList<BaseDAO> daos = new ArrayList<>();
CommDBManager mgr = DBManager.getDBManager();
Iterator itr = mgr.allDAOIterator();
while (itr.hasNext()) {
BaseDAO dao = (BaseDAO) itr.next();
try {
Util.RetryStrategy retry = null;
do {
try {
dao.createStoredProc(conn);
break;
} catch (Exception e) {
// Exception will be log & re-throw if operation cannot be retry
if (retry == null) {
retry = new Util.RetryStrategy(mgr);
}
retry.assertShouldRetry(e);
}
} while (true);
daos.add(dao);
} catch (BrokerException be) {
try {
dropStoredProcs(conn, daos);
} catch (Exception e) {
Globals.getLogger().logStack(Logger.WARNING, be.getMessage(), be);
}
throw be;
}
}
}
Aggregations