Package com.sun.messaging.jmq.jmsserver.persist.jdbc.comm

Examples of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager


    }

    private void doCreate(boolean createdb, CommDBManager mgrArg)
  throws BrokerException {

    CommDBManager mgr = (mgrArg == null ? dbmgr:mgrArg);
  Connection conn = null;
  try {
            if (createdb) {
                conn = mgr.connectToCreate();
                conn.setAutoCommit( true );
            } else {
                conn = mgr.newConnection( true ); // set autoCommit to true
            }

            // Check if store exist
            boolean continueOnError = false;
            int status = mgr.checkStoreExists( conn );
            if (status > 0) {
                if (!(mgr instanceof ShareConfigChangeDBManager)) {
                // All tables have already been created
                throw new BrokerException(br.getKString(
                    BrokerResources.E_DATABASE_TABLE_ALREADY_CREATED));
                } else {
                throw new BrokerException(br.getKString(
                    BrokerResources.E_SHARECC_TABLE_ALREADY_CREATED,
                    Globals.getClusterID()));
                }
            } else if (status < 0) {
                // Some tables are missings so try to create the tables
                // but ignore error if table already exists
                continueOnError = true;
            }

            createTables( conn, continueOnError, mgr );

      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) {
      String url;
      if (createdb)
    url = mgr.getCreateDBURL();
      else
    url = mgr.getOpenDBURL();

      throw new BrokerException(br.getKString(
                BrokerResources.E_CREATE_DATABASE_TABLE_FAILED, url), t);
  } finally {
            if ( createdb && conn != null ) {
View Full Code Here


    //else create current version of persist store
    static void createTables( Connection conn, boolean continueOnError,
                              ArrayList tableDAOs, CommDBManager mgrArg)
        throws BrokerException {

        CommDBManager mgr = mgrArg;
        if (mgr == null) {
            mgr = DBManager.getDBManager();
        }
        Iterator itr = null;
        if (tableDAOs != null) {
            itr = tableDAOs.iterator();
        } else {
            itr = mgr.allDAOIterator();
        }
        while ( itr.hasNext() ) {
            BaseDAO dao = (BaseDAO)itr.next();
            try {
                Util.RetryStrategy retry = null;
                do {
                    try {
                        dao.createTable( conn );
                        break; // table created so break from retry loop
                    } 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) {
                if ( Globals.getHAEnabled() ||
                     (mgr instanceof ShareConfigChangeDBManager) ) {
                    // Paused for a few secs to prevent race condition when two
                    // or more brokers try to create the tables at the same time
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {}
                }

                // Verify if the store has already been created
                if ( mgr.checkStoreExists( conn ) > 0 ) {
                    if (tableDAOs == null) {
                    Globals.getLogger().log(Logger.WARNING,
                        BrokerResources.E_CREATE_DATABASE_TABLE_FAILED,
                        Globals.getBrokerResources().getString(
                            BrokerResources.E_DATABASE_TABLE_ALREADY_CREATED));
View Full Code Here

    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 );
  }
    }
View Full Code Here

    static boolean dropTables(Connection conn, String names[],
                              boolean continueOnError, CommDBManager mgrArg)
                              throws SQLException, BrokerException {

        CommDBManager mgr = (mgrArg == null ? DBManager.getDBManager():mgrArg);
        boolean deleted = false;
        Exception myex = null;
        try {
            if ( names != null && names.length > 0 ) {
                // Removing old tables, i.e. 3.5
                Statement stmt = null;
                try {
                    stmt = conn.createStatement();
                    for ( int i = 0, len = names.length; i < len; i++ ) {
                        String oldTableName = names[i];
                        Globals.getLogger().logToAll( Logger.INFO,
                            br.getString( BrokerResources.I_DROP_TABLE,
                                oldTableName ) );
                        stmt.executeUpdate( "DROP TABLE " + oldTableName );

                        if ( mgr.hasSupplementForCreateDrop(oldTableName) ) {
                             TableSchema schema = mgr.getTableSchema(oldTableName);
                             mgr.dropTableSupplement(stmt, schema, oldTableName, true);
                        }
                    }
                } catch (SQLException e) {
                    myex = e;
                    throw e;
                } finally {
                    Util.close( null, stmt, null, myex, mgr );
                }
            } else {
                Iterator itr = mgr.allDAOIterator();
                while ( itr.hasNext() ) {
                    BaseDAO dao = (BaseDAO)itr.next();
                    try {
                        Util.RetryStrategy retry = null;
                        do {
View Full Code Here

        doRecreate(null);
    }

    private void doRecreate(CommDBManager mgrArg) throws BrokerException {

    CommDBManager mgr = (mgrArg == null ? dbmgr : mgrArg)
  Connection conn = null;
    Throwable myex = null;
  try {
            conn = mgr.getConnection(true);

            boolean deleted = false;
            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 recreated 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 {
                        // unable to get the lock
                        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 {
                deleted = true;
            }

            if ( !deleted ) {
                dropTables( conn, null, continueOnError, mgrArg );
            }

      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 );
  }
    }
View Full Code Here

     * 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 e) {
            myex = e;
            throw e;
        } catch (BrokerException e) {
View Full Code Here

    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 = stmt.executeQuery(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() );

            }
View Full Code Here

            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)) {
View Full Code Here

        boolean myConn = false;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Exception myex = null;
        try {
            CommDBManager mgr = getDBManager();
            if ( conn == null ) {
                conn = mgr.getConnection( (mgr.isDerby() ? true:false) );
                myConn = true;
            }
            String resetUUID = rec.getResetUUID();

            if (clearFlag) {
                setResetRecordFLAGNULL( conn );
            }

            if (mgr.isOracle()) {
                sql = insertSQLOracle;
            } else {
                sql = insertSQL;
            }
            if (mgr.supportsGetGeneratedKey()) {
                pstmt = conn.prepareStatement( sql, new String[]{SEQ_COLUMN} );
            } else {
                pstmt = conn.prepareStatement( sql );
            }
            pstmt.setString( 1, rec.getUUID() );
            Util.setBytes( pstmt, 2, rec.getRecord() );
            pstmt.setInt( 3, rec.getType() );
            pstmt.setLong( 4, rec.getTimestamp() );
            pstmt.executeUpdate();
            Long seq = null;
            if (mgr.supportsGetGeneratedKey()) {
                rs = pstmt.getGeneratedKeys();
                if (rs.next()) {
                    seq = new Long(rs.getLong( 1 ));
                }
            } else if (mgr.isOracle()) {
                Statement st = conn.createStatement()
                rs = st.executeQuery( selectSeqSQLOracle );
                if (rs.next()) {
                    seq = new Long(rs.getLong( 1 ));
                }
View Full Code Here

TOP

Related Classes of com.sun.messaging.jmq.jmsserver.persist.jdbc.comm.CommDBManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.