Package jp.co.ntt.oss.data

Examples of jp.co.ntt.oss.data.DatabaseResource


    if (showHelp) {
      showHelp();
      return;
    }

    DatabaseResource replicaDB = null;
    DatabaseResource masterDB = null;
    Connection replicaConn = null;
    Connection masterConn = null;
    UserTransaction utx = null;
    RefreshMode executeMode;
    String result;
    boolean refreshed = false;

    try {
      Subscription subs = null;
      Subscriber suber = null;
      long maxMlogID = SyncDatabaseDAO.MLOG_RECORD_NOT_FOUND;

      // get replica server connection
      replicaDB = new DatabaseResource(server);
      replicaConn = replicaDB.getConnection();

      // begin transaction
      utx = replicaDB.getUserTransaction();
      utx.begin();

      // get subscription data
      subs = SyncDatabaseDAO.getSubscription(replicaConn, schema, table);
      if (subs.getSchema() == null || subs.getTable() == null) {
        throw new SyncDatabaseException("error.replica.dropped",
            SyncDatabaseDAO.getTablePrint(schema, table));
      }

      // get master server connection
      masterDB = new DatabaseResource(subs.getSrvname());
      masterConn = masterDB.getConnection();

      if (subs.getSubsID() != Subscription.NOT_HAVE_SUBSCRIBER) {
        Connection masterLockConn = null;

        // get subscriber data
        suber = SyncDatabaseDAO.getSubscriber(masterConn, subs
            .getSubsID());

        if (suber.getNspName() == null || suber.getRelName() == null) {
          throw new SyncDatabaseException("error.master.dropped",
              suber.getSubsID());
        }

        try {
          masterLockConn = SyncDatabaseDAO.lockTable(subs
              .getSrvname(), suber.getMasterTableName());

          // reset transaction
          utx.rollback();
          utx.setTransactionTimeout(DatabaseResource.DEFAULT_TIMEOUT);
          utx.begin();

          masterConn
              .setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);

          // first query
          maxMlogID = SyncDatabaseDAO.getMaxMlogID(masterConn, suber
              .getMlogName());

          masterLockConn.rollback();
        } finally {
          // close connection
          if (masterLockConn != null) {
            masterLockConn.close();
          }
        }

        if (maxMlogID == SyncDatabaseDAO.MLOG_RECORD_NOT_FOUND) {
          if (suber.getLastMlogID() == Subscriber.NO_REFRESH) {
            maxMlogID = 0;
          } else {
            maxMlogID = suber.getLastMlogID();
          }
        }

        if (maxMlogID < suber.getLastMlogID()) {
          log.debug("max mlog ID:" + maxMlogID + " / last mlog ID:"
              + suber.getLastMlogID());
          throw new SyncDatabaseException("error.mlog_illegal");
        }
      }

      // get execute refresh mode
      executeMode = getExecuteMode(masterConn, suber, subs, mode);

      if (executeMode == RefreshMode.FULL) {
        // full-refresh
        result = fullRefresh(masterConn, replicaConn, suber, subs,
            concurrent);
      } else {
        // incremental-refresh
        result = incrementalRefresh(masterConn, replicaConn, suber,
            subs);
      }

      /* update subscription */
      SyncDatabaseDAO.setSubscription(replicaConn, subs);

      /* update subscriber */
      if (suber != null) {
        suber.setLastMlogID(maxMlogID);
        SyncDatabaseDAO.setSubscriber(masterConn, suber);
      }

      // commit transaction
      utx.commit();
      log.info(result);
      refreshed = true;

      // purge
      if (suber != null) {
        utx.setTransactionTimeout(DatabaseResource.DEFAULT_TIMEOUT);
        utx.begin();
        SyncDatabaseDAO.purgeMlog(masterConn, suber.getNspName(), suber
            .getRelName());

        // commit transaction
        utx.commit();
      }

    } catch (final Exception e) {
      // rollback transaction
      if (utx != null && utx.getStatus() != Status.STATUS_NO_TRANSACTION) {
        utx.rollback();
      }

      if (!refreshed) {
        throw e;
      }

      log.warn(e.getMessage());
    } finally {
      // release resources
      if (replicaConn != null) {
        replicaConn.close();
      }
      if (replicaDB != null) {
        replicaDB.stop();
      }
      if (masterConn != null) {
        masterConn.close();
      }
      if (masterDB != null) {
        masterDB.stop();
      }
    }
  }
View Full Code Here


  protected static String newLine;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // need connection test
    masterDB = new DatabaseResource("postgres1");
    replicaDB = new DatabaseResource("postgres2");
    masterConn = masterDB.getConnection();
    replicaConn = replicaDB.getConnection();
    oraDB = new DatabaseResource("oracle");
    oraConn = oraDB.getConnection();

    // stdout test
    newLine = System.getProperty("line.separator");
View Full Code Here

    if (showHelp) {
      showHelp();
      return;
    }

    DatabaseResource masterDB = null;
    Connection masterConn = null;
    UserTransaction utx = null;

    try {
      // get master server connection
      masterDB = new DatabaseResource(master);
      masterConn = masterDB.getConnection();

      // begin transaction
      utx = masterDB.getUserTransaction();
      utx.begin();

      // drop
      SyncDatabaseDAO.dropMlog(masterConn, schema, table);

      // commit transaction
      utx.commit();

    } catch (Exception e) {
      // rollback transaction
      if (utx != null && utx.getStatus() != Status.STATUS_NO_TRANSACTION) {
        utx.rollback();
      }

      throw e;
    } finally {
      // release resources
      if (masterConn != null) {
        masterConn.close();
      }
      if (masterDB != null) {
        masterDB.stop();
      }
    }

    log.info(mProperty.getMessage("info.drop.success"));
  }
View Full Code Here

  protected static String newLine;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // need connection test
    masterDB = new DatabaseResource("postgres1");
    replicaDB = new DatabaseResource("postgres2");
    masterConn = masterDB.getConnection();
    replicaConn = replicaDB.getConnection();
    oraDB = new DatabaseResource("oracle");
    oraConn = oraDB.getConnection();

    // stdout test
    newLine = System.getProperty("line.separator");
View Full Code Here

  protected static String newLine;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // need connection test
    masterDB = new DatabaseResource("postgres1");
    masterConn = masterDB.getConnection();
    oraDB = new DatabaseResource("oracle");
    oraConn = oraDB.getConnection();

    // stdout test
    newLine = System.getProperty("line.separator");
View Full Code Here

  protected static String newLine;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // need connection test
    masterDB = new DatabaseResource("postgres1");
    replicaDB = new DatabaseResource("postgres2");
    masterConn = masterDB.getConnection();
    replicaConn = replicaDB.getConnection();
    oraDB = new DatabaseResource("oracle");
    oraConn = oraDB.getConnection();

    // stdout test
    newLine = System.getProperty("line.separator");
View Full Code Here

  private static DatabaseResource masterDB = null;
  private static Connection masterConn = null;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    masterDB = new DatabaseResource("postgres1");
    masterConn = masterDB.getConnection();
  }
View Full Code Here

  protected static String newLine;

  @BeforeClass
  public static void setUpBeforeClass() throws Exception {
    // need connection test
    masterDB = new DatabaseResource("postgres1");
    masterConn = masterDB.getConnection();
    oraDB = new DatabaseResource("oracle");
    oraConn = oraDB.getConnection();

    // stdout test
    newLine = System.getProperty("line.separator");
View Full Code Here

TOP

Related Classes of jp.co.ntt.oss.data.DatabaseResource

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.