use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager in project openmq by eclipse-ee4j.
the class DBTool method doCommand.
void doCommand(String[] args) throws SQLException, BrokerException, IOException {
// print all
if (args.length == 0) {
System.out.println(version.getBanner(true));
System.out.println(br.getString(BrokerResources.M_DBMGR_USAGE));
exit(0);
}
// print help
if (printHelp(args)) {
System.out.println(br.getString(BrokerResources.M_DBMGR_USAGE));
exit(0);
}
// print version
if (printVersion(args)) {
System.out.println(version.getBanner(true));
System.out.println(br.getString(BrokerResources.I_JAVA_VERSION) + System.getProperty("java.version") + " " + System.getProperty("java.vendor") + " " + System.getProperty("java.home"));
System.out.println(br.getString(BrokerResources.I_JAVA_CLASSPATH) + System.getProperty("java.class.path"));
exit(0);
}
Properties props = null;
try {
props = parseArgs(args);
} catch (ParserException e) {
handleParserException(e);
exit(1);
}
props.getProperty(DBManager.JDBC_PROP_PREFIX + DBConnectionPool.NUM_CONN_PROP_SUFFIX, "2");
if (cliPasswdSpecified) {
System.err.println(br.getString(BrokerResources.W_PASSWD_OPTION_DEPRECATED, OPT_PW));
System.err.println("");
}
// 1st check existence of broker instance because Globals.init()
// method will create an instance if it does not exist!
String configName = props.getProperty(Globals.IMQ + ".instancename");
if (configName != null && configName.length() > 0) {
Globals.pathinit(null);
String topname = Globals.getJMQ_INSTANCES_HOME() + File.separator + configName;
if (!(new File(topname)).exists()) {
System.err.println(br.getString(BrokerResources.E_INSTANCE_NOT_EXIST, configName));
System.exit(1);
}
}
Globals.init(props, false, false);
config = Globals.getConfig();
logger = Globals.getLogger();
// Password in passfile override broker's properties object
parsePassfile();
// User/Password passed in from command line option take precedence.
// Inorder to override the User/Password we need to construct the
// correct property based on the dbVendor value; we do this after
// calling Globals.init() so we can determine the dbVendor value.
String dbVendor = config.getProperty(DBManager.JDBC_PROP_PREFIX + ".dbVendor");
String vendorPropPrefix = DBManager.JDBC_PROP_PREFIX + "." + dbVendor;
String user = props.getProperty(DBManager.FALLBACK_USER_PROP);
if (user != null && user.length() > 0) {
config.put(vendorPropPrefix + ".user", user);
}
String pwd = props.getProperty(DBManager.FALLBACK_PWD_PROP);
if (pwd != null && pwd.length() > 0) {
config.put(vendorPropPrefix + ".password", pwd);
}
String cmd = props.getProperty(CMD_NAME);
CommDBManager mgr = null;
if (DELETE_SHARECCTBL_CMD.equals(cmd) || RECREATE_SHARECCTBL_CMD.equals(cmd) || CREATE_SHARECCTBL_CMD.equals(cmd) || DUMP_SHARECCTBL_CMD.equals(cmd) || BACKUP_SHARECCTBL_CMD.equals(cmd) || RESTORE_SHARECCTBL_CMD.equals(cmd)) {
if (debugSpecified) {
System.out.println("cmd=" + cmd + ", use sharecc");
}
if (!Globals.useSharedConfigRecord()) {
if (Globals.getHAEnabled()) {
logger.logToAll(Logger.ERROR, br.getKString(BrokerResources.E_CONFIGURED_HA_MODE));
} else {
logger.logToAll(Logger.ERROR, br.getKString(BrokerResources.E_NOT_CONFIGURED_USE_SHARECC, Globals.NO_MASTERBROKER_PROP));
}
exit(1);
}
mgr = ShareConfigChangeDBManager.getDBManager();
} else {
dbmgr = DBManager.getDBManager();
mgr = dbmgr;
}
// print out info messages
String brokerid = null;
if (mgr instanceof DBManager) {
brokerid = ((DBManager) mgr).getBrokerID();
}
String url;
if (CREATE_ALL_CMD.equals(cmd)) {
url = mgr.getCreateDBURL();
} else {
url = mgr.getOpenDBURL();
}
if (url == null) {
url = "not specified";
}
user = mgr.getUser();
if (user == null) {
user = "not specified";
}
if (!(mgr instanceof ShareConfigChangeDBManager)) {
String[] msgArgs = { String.valueOf(JDBCStore.STORE_VERSION), brokerid, url, user };
logger.logToAll(Logger.INFO, br.getString(BrokerResources.I_JDBC_STORE_INFO, msgArgs));
} else {
String[] msgArgs = { "", String.valueOf(JDBCShareConfigChangeStore.SCHEMA_VERSION), Globals.getClusterID(), url, user };
logger.logToAll(Logger.INFO, br.getKString(BrokerResources.I_SHARECC_JDBCSTORE_INFO, msgArgs));
}
if (debugSpecified) {
System.out.println("cmd=" + cmd);
}
if (CREATE_ALL_CMD.equals(cmd)) {
// create database as well
doCreate(true);
} else if (CREATE_TBL_CMD.equals(cmd)) {
// just tables
doCreate(false);
} else if (CREATE_SHARECCTBL_CMD.equals(cmd)) {
doCreate(false, ShareConfigChangeDBManager.getDBManager());
} else if (DELETE_TBL_CMD.equals(cmd)) {
doDelete(props.getProperty(ARG_NAME), null, null);
} else if (DELETE_SHARECCTBL_CMD.equals(cmd)) {
doDelete(props.getProperty(ARG_NAME), ShareConfigChangeDBManager.getDBManager(), null);
} else if (RECREATE_TBL_CMD.equals(cmd)) {
doRecreate();
} else if (RECREATE_SHARECCTBL_CMD.equals(cmd)) {
doRecreate(ShareConfigChangeDBManager.getDBManager());
} else if (REMOVE_BKR_CMD.equals(cmd)) {
doRemoveBkr();
} else if (REMOVE_JMSBRIDGE_CMD.equals(cmd)) {
doRemoveJMSBridge(props.getProperty(JMSBRIDGE_NAME_PROPERTY));
} else if (DUMP_CMD.equals(cmd)) {
String arg = props.getProperty(ARG_NAME);
doDump(arg, null);
} else if (DUMP_SHARECCTBL_CMD.equals(cmd)) {
doDump(null, ShareConfigChangeDBManager.getDBManager());
} else if (DROPTBL_CMD.equals(cmd)) {
String arg = props.getProperty(ARG_NAME);
doDropTablesByPattern(arg);
} else if (RESET_CMD.equals(cmd)) {
doReset();
} else if (BACKUP_CMD.equals(cmd)) {
doBackup();
} else if (BACKUP_SHARECCTBL_CMD.equals(cmd)) {
doBackupSharecc();
} else if (RESTORE_CMD.equals(cmd)) {
doRestore();
} else if (RESTORE_SHARECCTBL_CMD.equals(cmd)) {
doRestoreSharecc();
} else if (UPGRADE_STORE_CMD.equals(cmd)) {
doUpgrade(false);
} else if (UPGRADE_HASTORE_CMD.equals(cmd)) {
doUpgrade(true);
} else if (QUERY_CMD.equals(cmd)) {
doQuery();
} else if (cmd == null) {
System.out.println(br.getString(BrokerResources.E_MISSING_DBMGR_CMD));
} else {
System.out.println(br.getString(BrokerResources.E_INVALID_DBMGR_CMD, cmd));
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager in project openmq by eclipse-ee4j.
the class DBTool method dropTables.
public static boolean dropTables(Connection conn, String[] oldnames, boolean oldsupplementck, boolean continueOnError, CommDBManager mgrArg) throws SQLException, BrokerException {
if (oldnames == null || oldnames.length == 0) {
return true;
}
CommDBManager mgr = (mgrArg == null ? DBManager.getDBManager() : mgrArg);
boolean deleted = false;
Exception myex = null;
Statement stmt = null;
try {
for (int i = 0, len = oldnames.length; i < len; i++) {
try {
String oldname = oldnames[i];
stmt = conn.createStatement();
Globals.getLogger().logToAll(Logger.INFO, br.getString(BrokerResources.I_DROP_TABLE, oldname));
mgr.executeUpdateStatement(stmt, "DROP TABLE " + oldname);
if (oldsupplementck && mgr.hasSupplementForCreateDrop(oldname)) {
mgr.dropOldTableSupplement(stmt, oldname, false);
}
} catch (Exception e) {
if (continueOnError) {
Globals.getLogger().log(Logger.WARNING, e.toString(), e.getCause());
} else {
myex = e;
throw e;
}
}
}
deleted = true;
} catch (Exception e) {
Object[] args = { Arrays.asList(oldnames), e.getMessage() };
String emsg = Globals.getBrokerResources().getKString(BrokerResources.X_DELETE_DATABASE_TABLES, args);
Globals.getLogger().logStack(Logger.ERROR, emsg, e);
if (e instanceof SQLException) {
throw (SQLException) e;
}
if (e instanceof BrokerException) {
throw (BrokerException) e;
}
throw new BrokerException(e.getMessage(), e);
} finally {
Util.close(null, stmt, null, myex, mgr);
}
return deleted;
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager in project openmq by eclipse-ee4j.
the class ShareConfigRecordDAOImpl method checkLastUKeyHasSeq.
private Integer checkLastUKeyHasSeq(Connection conn, String ukey, long expectedSeq) throws BrokerException {
boolean myConn = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
Exception myex = null;
String sql = selectMaxSeqFlagUKeySQL;
try {
// Get a connection
CommDBManager mgr = getDBManager();
if (conn == null) {
conn = mgr.getConnection(true);
myConn = true;
}
pstmt = mgr.createPreparedStatement(conn, sql);
pstmt.setString(1, ukey);
pstmt.setString(2, ukey);
rs = pstmt.executeQuery();
if (!rs.next()) {
return null;
}
long s = rs.getLong(1);
int flag = rs.getInt(2);
if (s == expectedSeq) {
return null;
}
return Integer.valueOf(flag);
} catch (Exception e) {
myex = e;
try {
if ((conn != null) && !conn.getAutoCommit()) {
conn.rollback();
}
} catch (SQLException rbe) {
logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = getDBManager().wrapSQLException("[" + sql + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(br.X_SHARECC_QUERY_MAX_SEQ_UKEY, ukey + "[" + expectedSeq + "]") + ": " + ex.toString(), ex);
} finally {
if (myConn) {
closeSQLObjects(rs, pstmt, conn, myex);
} else {
closeSQLObjects(rs, pstmt, null, myex);
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager in project openmq by eclipse-ee4j.
the class ShareConfigRecordDAOImpl method setResetRecordUUID.
/**
* @param conn database connection
*/
public void setResetRecordUUID(Connection conn, String uuid) throws BrokerException {
boolean myConn = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
Exception myex = null;
try {
// Get a connection
CommDBManager mgr = getDBManager();
if (conn == null) {
conn = mgr.getConnection(true);
myConn = true;
}
pstmt = mgr.createPreparedStatement(conn, updateResetRecordUUIDSQL);
pstmt.setString(1, uuid);
if (pstmt.executeUpdate() < 1) {
throw new BrokerException("Unexpected affected row count for " + updateResetRecordUUIDSQL);
}
} catch (Exception e) {
myex = e;
try {
if ((conn != null) && !conn.getAutoCommit()) {
conn.rollback();
}
} catch (SQLException rbe) {
logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = getDBManager().wrapSQLException("[" + updateResetRecordUUIDSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(br.X_SHARECC_SET_RESET_RECORD_UUID_FAIL, uuid, ex.getMessage()), ex);
} finally {
if (myConn) {
closeSQLObjects(rs, pstmt, conn, myex);
} else {
closeSQLObjects(rs, pstmt, null, myex);
}
}
}
use of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager in project openmq by eclipse-ee4j.
the class ShareConfigRecordDAOImpl method hasResetRecord.
/**
* @param conn database connection
* @throws BrokerException if locked or other error
*/
public boolean hasResetRecord(Connection conn) throws BrokerException {
boolean myConn = false;
PreparedStatement pstmt = null;
ResultSet rs = null;
Exception myex = null;
try {
// Get a connection
CommDBManager mgr = getDBManager();
if (conn == null) {
conn = mgr.getConnection(true);
myConn = true;
}
pstmt = mgr.createPreparedStatement(conn, selectAllSQL);
rs = pstmt.executeQuery();
if (rs.next()) {
int typ = rs.getInt(4);
if (typ == ChangeRecordInfo.TYPE_RESET_PERSISTENCE) {
String lock = rs.getString(6);
if (lock != null) {
getDBManager().throwTableLockedException(lock);
}
return true;
}
throw new BrokerException("Unexpected 1st record type " + typ + " for first record in database table " + getTableName());
} else {
return false;
}
} catch (Exception e) {
myex = e;
try {
if ((conn != null) && !conn.getAutoCommit()) {
conn.rollback();
}
} catch (SQLException rbe) {
logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
}
Exception ex;
if (e instanceof BrokerException) {
throw (BrokerException) e;
} else if (e instanceof SQLException) {
ex = getDBManager().wrapSQLException("[" + selectAllSQL + "]", (SQLException) e);
} else {
ex = e;
}
throw new BrokerException(br.getKString(br.X_SHARECC_QUERY_RESET_RECORD_FAIL, ex.getMessage()), ex);
} finally {
if (myConn) {
closeSQLObjects(null, pstmt, conn, myex);
} else {
closeSQLObjects(null, pstmt, null, myex);
}
}
}
Aggregations