Example usage for javax.transaction.xa XAResource XA_OK

List of usage examples for javax.transaction.xa XAResource XA_OK

Introduction

In this page you can find the example usage for javax.transaction.xa XAResource XA_OK.

Prototype

int XA_OK

To view the source code for javax.transaction.xa XAResource XA_OK.

Click Source Link

Document

The transaction work has been prepared normally.

Usage

From source file:com.taobao.metamorphosis.server.transaction.XATransaction.java

@Override
public int prepare() throws XAException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("XA Transaction prepare: " + this.xid);
    }/*  w  ww. jav  a  2s  .  co m*/

    switch (this.getState()) {
    case START_STATE:
        // No work done.. no commit/rollback needed.
        this.setStateFinished();
        return XAResource.XA_RDONLY;
    case IN_USE_STATE:
        // We would record prepare here.
        this.doPrePrepare();
        this.setState(Transaction.PREPARED_STATE);
        this.transactionStore.prepare(this.getTransactionId());
        return XAResource.XA_OK;
    default:
        this.illegalStateTransition("prepare");
        return XAResource.XA_RDONLY;
    }
}

From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java

public int prepare(Xid xid) throws XAException {
    // TODO: Track state OK, ReadOnly, Exception (=> rolled back?)
    Map<String, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);

    if (indexers == null) {
        if (suspendedIndexersInGlobalTx.containsKey(xid)) {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        } else {// w  w w .  jav a  2s.  c  o  m
            // nothing to do
            return XAResource.XA_OK;
        }
    }

    boolean isPrepared = true;
    boolean isModified = false;

    for (LuceneIndexer indexer : indexers.values()) {
        try {
            isModified |= indexer.isModified();
            indexer.prepare();
        } catch (IndexerException e) {
            isPrepared = false;
        }
    }

    if (isPrepared) {
        return (isModified) ? XAResource.XA_OK : XAResource.XA_RDONLY;
    } else {
        throw new XAException("Failed to prepare: requires rollback");
    }
}

From source file:it.doqui.index.ecmengine.business.personalization.multirepository.index.lucene.RepositoryAwareAbstractLuceneIndexerAndSearcherFactory.java

/**
 * Prepare the transaction TODO: Store prepare results
 *
 * @return - the tx code/*from   w w w.ja va2 s. c  o m*/
 */
public int prepare() throws IndexerException {
    boolean isPrepared = true;
    boolean isModified = false;
    Map<String, LuceneIndexer> indexers = threadLocalIndexers.get();
    if (indexers != null) {
        for (LuceneIndexer indexer : indexers.values()) {
            try {
                isModified |= indexer.isModified();
                indexer.prepare();
            } catch (IndexerException e) {
                isPrepared = false;
                throw new IndexerException("Failed to prepare: requires rollback", e);
            }
        }
    }
    if (isPrepared) {
        if (isModified) {
            return XAResource.XA_OK;
        } else {
            return XAResource.XA_RDONLY;
        }
    } else {
        throw new IndexerException("Failed to prepare: requires rollback");
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

public int prepare(Xid xid) throws XAException {
    // TODO: Track state OK, ReadOnly, Exception (=> rolled back?)
    Map<StoreRef, LuceneIndexer> indexers = activeIndexersInGlobalTx.get(xid);
    if (indexers == null) {
        if (suspendedIndexersInGlobalTx.containsKey(xid)) {
            throw new XAException("Trying to commit indexes for a suspended transaction.");
        } else {/*w w  w  .j a  va  2  s .c om*/
            // nothing to do
            return XAResource.XA_OK;
        }
    }
    boolean isPrepared = true;
    boolean isModified = false;
    for (LuceneIndexer indexer : indexers.values()) {
        try {
            isModified |= indexer.isModified();
            indexer.prepare();
        } catch (IndexerException e) {
            isPrepared = false;
        }
    }
    if (isPrepared) {
        if (isModified) {
            return XAResource.XA_OK;
        } else {
            return XAResource.XA_RDONLY;
        }
    } else {
        throw new XAException("Failed to prepare: requires rollback");
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerAndSearcherFactory.java

/**
 * Prepare the transaction TODO: Store prepare results
 * /*from   w  w w  . ja  v a 2 s.c o m*/
 * @return - the tx code
 */
@SuppressWarnings("unchecked")
public int prepare() throws IndexerException {
    boolean isPrepared = true;
    boolean isModified = false;
    Map<StoreRef, LuceneIndexer> indexers = (Map<StoreRef, LuceneIndexer>) AlfrescoTransactionSupport
            .getResource(indexersKey);
    if (indexers != null) {
        for (LuceneIndexer indexer : indexers.values()) {
            try {
                isModified |= indexer.isModified();
                indexer.prepare();
            } catch (IndexerException e) {
                isPrepared = false;
                throw new IndexerException("Failed to prepare: requires rollback", e);
            }
        }
    }
    if (isPrepared) {
        if (isModified) {
            return XAResource.XA_OK;
        } else {
            return XAResource.XA_RDONLY;
        }
    } else {
        throw new IndexerException("Failed to prepare: requires rollback");
    }
}

From source file:org.alfresco.repo.search.impl.lucene.AbstractLuceneIndexerImpl.java

/**
 * Prepare to commit At the moment this makes sure we have all the locks TODO: This is not doing proper
 * serialisation against the index as would a data base transaction.
 * /*from w ww  .  j a va  2s .  c  o m*/
 * @return the tx state
 * @throws LuceneIndexException
 */
public int prepare() throws LuceneIndexException {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(Thread.currentThread().getName() + " Starting Prepare");
    }
    switch (getStatus().getStatus()) {
    case Status.STATUS_COMMITTING:
        throw new IndexerException("Unable to prepare: Transaction is committing");
    case Status.STATUS_COMMITTED:
        throw new IndexerException("Unable to prepare: Transaction is commited ");
    case Status.STATUS_ROLLING_BACK:
        throw new IndexerException("Unable to prepare: Transaction is rolling back");
    case Status.STATUS_ROLLEDBACK:
        throw new IndexerException("Unable to prepare: Transaction is aleady rolled back");
    case Status.STATUS_MARKED_ROLLBACK:
        throw new IndexerException("Unable to prepare: Transaction is marked for roll back");
    case Status.STATUS_PREPARING:
        throw new IndexerException("Unable to prepare: Transaction is already preparing");
    case Status.STATUS_PREPARED:
        throw new IndexerException("Unable to prepare: Transaction is already prepared");
    default:
        try {
            setStatus(TransactionStatus.PREPARING);
            if (isModified()) {
                doPrepare();
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug(Thread.currentThread().getName() + " Waiting to Finish Preparing");
                }
            }
            setStatus(TransactionStatus.PREPARED);
            return isModified() ? XAResource.XA_OK : XAResource.XA_RDONLY;
        } catch (LuceneIndexException e) {
            setRollbackOnly();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", e);
            }
            throw new LuceneIndexException("Index failed to prepare", e);
        } catch (Throwable t) {
            // If anything goes wrong we try and do a roll back
            rollback();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Prepare Failed", t);
            }
            throw new LuceneIndexException("Prepared failed", t);
        } finally {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(Thread.currentThread().getName() + " Ending Prepare");
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java

public int prepare(final Xid xid) throws XAException {
    LOG.trace("prepare [" + xid.toString() + "] ");
    TransactionState state = xidToTransactionState.get(xid);
    int status;//w w  w .  j  ava  2 s  . c  o m
    try {
        status = this.transactionManager.prepareCommit(state);
    } catch (CommitUnsuccessfulException e) {
        XAException xae = new XAException(XAException.XA_HEURRB);
        xae.initCause(e);
        throw xae;
    } catch (IOException e) {
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(e);
        throw xae;
    }

    switch (status) {
    case TransactionalReturn.COMMIT_OK:
        return XAResource.XA_OK;
    case TransactionalReturn.COMMIT_OK_READ_ONLY:
        return XAResource.XA_RDONLY;
    default:
        throw new XAException(XAException.XA_RBPROTO);
    }
}

From source file:org.apache.hadoop.hive.metastore.MyXid.java

public boolean createDatabaseByDistributeTransaction(Database db) throws MetaException {
    if (db.getMetastore() == null) {
        String slaveURL = getSegmentUrlByDbNameHashCode(db.getName());
        db.setMetastore(slaveURL);//w w w . ja v  a  2  s  . c o  m
    }
    int hashcode = getHashForDb(db.getName());
    db.setName(db.getName().toLowerCase());

    boolean success = false;

    Connection masterConn = null;
    Connection slaveConn = null;

    PGXADataSource masterDS = null;
    PGXADataSource slaveDS = null;

    masterDS = getXADataSource(globalDbUrl, user, passwd);
    slaveDS = getXADataSource(db.getMetastore(), user, passwd);

    XAConnection masterDSXaConn = null;
    XAConnection slaveDSXaConn = null;

    XAResource masterSaRes = null;
    XAResource slaveSaRes = null;

    int formatID = genFormatID();
    Xid masterXid = new MyXid(formatID, new byte[] { 0x01 }, new byte[] { 0x02 });
    Xid slaveXid = new MyXid(formatID, new byte[] { 0x11 }, new byte[] { 0x12 });

    PreparedStatement masterStmt = null;
    PreparedStatement slaveStmt = null;

    try {
        masterDSXaConn = masterDS.getXAConnection();
        slaveDSXaConn = slaveDS.getXAConnection();

        masterSaRes = masterDSXaConn.getXAResource();
        slaveSaRes = slaveDSXaConn.getXAResource();

        masterConn = masterDSXaConn.getConnection();
        slaveConn = slaveDSXaConn.getConnection();

        masterStmt = masterConn
                .prepareStatement("insert into router(db_name, seg_addr,hashcode, owner) values(?,?,?,?)");
        slaveStmt = slaveConn
                .prepareStatement("insert into dbs(name, hdfs_schema, description, owner) VALUES(?,?,?,?)");

        try {
            masterSaRes.start(masterXid, XAResource.TMNOFLAGS);

            masterStmt.setString(1, db.getName());
            masterStmt.setString(2, db.getMetastore());
            masterStmt.setInt(3, hashcode);
            masterStmt.setString(4, db.getOwner());
            masterStmt.executeUpdate();

            masterSaRes.end(masterXid, XAResource.TMSUCCESS);

            slaveSaRes.start(slaveXid, XAResource.TMNOFLAGS);

            slaveStmt.setString(1, db.getName());
            slaveStmt.setString(2, db.getHdfsscheme());
            slaveStmt.setString(3, db.getDescription());
            slaveStmt.setString(4, db.getOwner());
            slaveStmt.executeUpdate();

            slaveSaRes.end(slaveXid, XAResource.TMSUCCESS);

            int masterRet = masterSaRes.prepare(masterXid);
            int slaveRet = slaveSaRes.prepare(slaveXid);

            Warehouse wh = new Warehouse(hiveConf);
            Path databasePath = wh.getDefaultDatabasePath(db.getName(), db.getHdfsscheme());

            if (masterRet == XAResource.XA_OK && slaveRet == XAResource.XA_OK && wh.mkdirs(databasePath)) {
                masterSaRes.commit(masterXid, false);
                slaveSaRes.commit(slaveXid, false);

                success = true;
            }
        } catch (XAException e) {
            LOG.error("XAException create database error, db=" + db.getName() + ", msg=" + e.getMessage());
            e.printStackTrace();
            throw new MetaException(e.getMessage());
        }
    } catch (SQLException e) {
        LOG.error("SQLException create database error, db=" + db.getName() + ", msg=" + e.getMessage());
        e.printStackTrace();
        throw new MetaException(e.getMessage());
    } finally {
        if (!success) {
            try {
                masterSaRes.rollback(masterXid);
            } catch (Exception x) {

            }

            try {
                slaveSaRes.rollback(slaveXid);
            } catch (Exception x) {

            }
        }

        closeStatement(masterStmt);
        closeStatement(slaveStmt);

        closeConnection(masterConn);
        closeConnection(slaveConn);

        closeXAConnection(masterDSXaConn);
        closeXAConnection(slaveDSXaConn);
    }

    return success;
}

From source file:org.apache.hadoop.hive.metastore.MyXid.java

public boolean dropDatabaseByDistributeTransaction(String name) throws MetaException {
    boolean success = false;
    name = name.toLowerCase();//from w  w w  .  jav a 2 s .  c  om
    Connection masterConn = null;
    Connection slaveConn = null;

    PGXADataSource masterDS = null;
    PGXADataSource slaveDS = null;

    masterDS = getXADataSource(globalDbUrl, user, passwd);

    String slaveURL = getSegmentDBURL(name);
    slaveDS = getXADataSource(slaveURL, user, passwd);

    XAConnection masterDSXaConn = null;
    XAConnection slaveDSXaConn = null;

    int formatID = genFormatID();
    Xid masterXid = new MyXid(formatID, new byte[] { 0x01 }, new byte[] { 0x02 });
    Xid slaveXid = new MyXid(formatID, new byte[] { 0x11 }, new byte[] { 0x12 });

    XAResource masterSaRes = null;
    XAResource slaveSaRes = null;
    Statement masterStmt = null;
    Statement slaveStmt = null;

    try {
        masterDSXaConn = masterDS.getXAConnection();
        slaveDSXaConn = slaveDS.getXAConnection();

        masterSaRes = masterDSXaConn.getXAResource();
        slaveSaRes = slaveDSXaConn.getXAResource();

        masterConn = masterDSXaConn.getConnection();
        slaveConn = slaveDSXaConn.getConnection();

        masterStmt = masterConn.createStatement();
        slaveStmt = slaveConn.createStatement();

        try {
            masterSaRes.start(masterXid, XAResource.TMNOFLAGS);
            masterStmt.executeUpdate("delete from router where db_name='" + name + "'");
            masterStmt.executeUpdate("delete from dbpriv where db_name='" + name + "'");
            masterStmt.executeUpdate("delete from tblpriv where db_name='" + name + "'");
            masterSaRes.end(masterXid, XAResource.TMSUCCESS);

            slaveSaRes.start(slaveXid, XAResource.TMNOFLAGS);
            slaveStmt.executeUpdate("delete from dbs where name='" + name + "'");
            slaveSaRes.end(slaveXid, XAResource.TMSUCCESS);

            int masterRet = masterSaRes.prepare(masterXid);
            int slaveRet = slaveSaRes.prepare(slaveXid);

            Warehouse wh = new Warehouse(hiveConf);

            if (masterRet == XAResource.XA_OK && slaveRet == XAResource.XA_OK
                    && wh.deleteDir(wh.getDefaultDatabasePath(name), true)) {
                masterSaRes.commit(masterXid, false);
                slaveSaRes.commit(slaveXid, false);

                success = true;
            }
        } catch (XAException e) {
            LOG.error("drop database error, db=" + name + ", msg=" + e.getMessage());
            throw new MetaException(e.getMessage());
        }
    } catch (Exception e) {
        LOG.error("create database error, db=" + name + ", msg=" + e.getMessage());
        throw new MetaException(e.getMessage());
    } finally {
        if (!success) {
            try {
                masterSaRes.rollback(masterXid);
            } catch (Exception x) {

            }

            try {
                slaveSaRes.rollback(slaveXid);
            } catch (Exception x) {

            }
        }

        closeStatement(masterStmt);
        closeStatement(slaveStmt);

        closeConnection(masterConn);
        closeConnection(slaveConn);

        closeXAConnection(masterDSXaConn);
        closeXAConnection(slaveDSXaConn);
    }

    if (success) {
        Statement stmt = null;
        Connection con = null;
        try {
            con = getGlobalConnection();
            stmt = con.createStatement();
            String sql = "delete from dbsensitivity where db_name='" + name + "'";
            stmt.executeUpdate(sql);

            sql = "delete from tblsensitivity where db_name='" + name + "'";
            stmt.executeUpdate(sql);
        } catch (Exception e1) {
            LOG.error("update tblsenstivity table error, db=" + name + ", msg=" + e1.getMessage());
        } finally {
            closeStatement(stmt);
            closeConnection(con);
        }
    }

    return success;
}

From source file:org.apache.hadoop.hive.metastore.MyXid.java

public void renameTableByDistributeTrans(String dbName, String tblName, String modifyUser, String newName)
        throws InvalidOperationException, MetaException {
    dbName = dbName.toLowerCase();//from w  w  w. j  a  v a  2  s. c o  m
    tblName = tblName.toLowerCase();
    modifyUser = modifyUser.toLowerCase();
    newName = newName.toLowerCase();

    boolean success = false;

    Connection masterConn = null;
    Connection slaveConn = null;

    PGXADataSource masterDS = null;
    PGXADataSource slaveDS = null;

    String slaveUrl = getSegmentDBURL(dbName);

    masterDS = getXADataSource(globalDbUrl, user, passwd);
    slaveDS = getXADataSource(slaveUrl, user, passwd);

    XAConnection masterDSXaConn = null;
    XAConnection slaveDSXaConn = null;

    XAResource masterSaRes = null;
    XAResource slaveSaRes = null;

    int formatID = genFormatID();
    Xid masterXid = new MyXid(formatID, new byte[] { 0x01 }, new byte[] { 0x02 });
    Xid slaveXid = new MyXid(formatID, new byte[] { 0x11 }, new byte[] { 0x12 });

    Statement masterStmt = null;
    Statement slaveStmt = null;

    boolean isMoved = false;
    Path newPath = null;
    Path oldPath = null;
    FileSystem oldFs = null;
    FileSystem newFs = null;
    Warehouse wh = null;
    String newLocation = null;

    try {
        masterDSXaConn = masterDS.getXAConnection();
        slaveDSXaConn = slaveDS.getXAConnection();

        masterSaRes = masterDSXaConn.getXAResource();
        slaveSaRes = slaveDSXaConn.getXAResource();

        masterConn = masterDSXaConn.getConnection();
        slaveConn = slaveDSXaConn.getConnection();

        masterStmt = masterConn.createStatement();
        slaveStmt = slaveConn.createStatement();

        try {
            masterSaRes.start(masterXid, XAResource.TMNOFLAGS);
            String sql = "update tblpriv set tbl_name='" + newName + "' where db_name='" + dbName
                    + "' and tbl_name='" + tblName + "'";
            masterStmt.executeUpdate(sql);

            masterSaRes.end(masterXid, XAResource.TMSUCCESS);

            slaveSaRes.start(slaveXid, XAResource.TMNOFLAGS);

            sql = "select tbl_id, tbl_type, tbl_location, serde_lib from tbls " + "where db_name='" + dbName
                    + "' and tbl_name='" + tblName + "'";

            boolean isTblFind = false;
            long tblID = 0;
            ResultSet tblSet = slaveStmt.executeQuery(sql);
            String tblType = null;
            String oldLocation = null;
            String serdeLib = null;

            while (tblSet.next()) {
                isTblFind = true;
                tblID = tblSet.getLong(1);
                tblType = tblSet.getString(2);
                oldLocation = tblSet.getString(3);
                serdeLib = tblSet.getString(4);
                break;
            }
            tblSet.close();

            if (!isTblFind) {
                throw new MetaException("can not find table " + dbName + ":" + tblName);
            }

            if (!tblType.equalsIgnoreCase("MANAGED_TABLE")) {
                throw new MetaException("only manage table can rename ");
            }

            if (serdeLib.equals(ProtobufSerDe.class.getName())) {
                throw new MetaException(
                        "Renaming table is not supported for protobuf table. SerDe may be incompatible");
            }

            Map<String, String> tblParamMap = new HashMap<String, String>();
            sql = "select param_key, param_value from table_params where tbl_id=" + tblID
                    + " and param_type='TBL'";
            ResultSet paramSet = slaveStmt.executeQuery(sql);
            while (paramSet.next()) {
                tblParamMap.put(paramSet.getString(1), paramSet.getString(2));
            }
            paramSet.close();

            boolean containTime = false;
            boolean contailUser = false;
            if (tblParamMap.containsKey("last_modified_time"))
                containTime = true;
            if (tblParamMap.containsKey("last_modified_by"))
                contailUser = true;

            if (containTime && contailUser) {
                slaveStmt.executeUpdate("update table_params set param_value='"
                        + String.valueOf(System.currentTimeMillis() / 1000) + "' where tbl_id=" + tblID
                        + " and param_type='TBL' and param_key='last_modified_time'");

                slaveStmt.executeUpdate("update table_params set param_value='" + modifyUser + "' where tbl_id="
                        + tblID + " and param_type='TBL' and param_key='last_modified_by'");
            } else if (!containTime && !contailUser) {
                slaveStmt.executeUpdate(
                        "insert into table_params(tbl_id, param_type, param_key, param_value) values(" + tblID
                                + ", 'TBL', 'last_modified_time', '"
                                + String.valueOf(System.currentTimeMillis() / 1000) + "')");

                slaveStmt.executeUpdate(
                        "insert into table_params(tbl_id, param_type, param_key, param_value) values(" + tblID
                                + ", 'TBL', 'last_modified_by', '" + modifyUser + "')");
            } else if (containTime && !contailUser) {
                slaveStmt.executeUpdate("update table_params set param_value='"
                        + String.valueOf(System.currentTimeMillis() / 1000) + "' where tbl_id=" + tblID
                        + " and param_type='TBL' and param_key='last_modified_time'");

                slaveStmt.executeUpdate(
                        "insert into table_params(tbl_id, param_type, param_key, param_value) values(" + tblID
                                + ", 'TBL', 'last_modified_by', '" + modifyUser + "')");
            } else {
                slaveStmt.executeUpdate(
                        "insert into table_params(tbl_id, param_type, param_key, param_value) values(" + tblID
                                + ", 'TBL', 'last_modified_time', '"
                                + String.valueOf(System.currentTimeMillis() / 1000) + "')");

                slaveStmt.executeUpdate("update table_params set param_value='" + modifyUser + "' where tbl_id="
                        + tblID + " and param_type='TBL' and param_key='last_modified_by'");
            }

            wh = new Warehouse(hiveConf);
            //        newLocation = wh.getDefaultTablePath(dbName, newName).toString();
            newLocation = oldLocation.substring(0, oldLocation.length() - tblName.length()) + newName;

            sql = "update tbls set tbl_name='" + newName + "', tbl_location='" + newLocation + "'"
                    + " where tbl_id=" + tblID;
            slaveStmt.executeUpdate(sql);

            slaveSaRes.end(slaveXid, XAResource.TMSUCCESS);

            int masterRet = masterSaRes.prepare(masterXid);
            int slaveRet = slaveSaRes.prepare(slaveXid);

            oldPath = new Path(oldLocation);
            oldFs = wh.getFs(oldPath);
            newPath = new Path(newLocation);
            newFs = wh.getFs(newPath);

            if (oldFs != newFs) {
                throw new InvalidOperationException(
                        "table new location " + oldFs + " is on a different file system than the old location "
                                + newFs + ". This operation is not supported");
            }

            try {
                oldFs.exists(oldPath);
                if (newFs.exists(newPath)) {
                    throw new InvalidOperationException("New location for this table " + dbName + "." + tblName
                            + " already exists : " + newPath);
                }

            } catch (IOException e) {

                throw new InvalidOperationException(
                        "Unable to access new location " + newPath + " for table " + dbName + "." + tblName);
            }

            try {
                if (oldFs.exists(oldPath)) {
                    oldFs.rename(oldPath, newPath);
                }
                isMoved = true;
            } catch (IOException e) {
                throw new InvalidOperationException(
                        "Unable to access old location " + oldPath + " for table " + dbName + "." + tblName);

            }

            if (masterRet == XAResource.XA_OK && slaveRet == XAResource.XA_OK) {
                masterSaRes.commit(masterXid, false);
                slaveSaRes.commit(slaveXid, false);

                success = true;
            }
        } catch (XAException e) {
            LOG.error("XAException rename table error, db=" + dbName + ", tbl=" + tblName + ", new tbl="
                    + newName + ", msg=" + e.getMessage());
            e.printStackTrace();
            throw new MetaException(e.getMessage());
        }
    } catch (SQLException e) {
        LOG.error("XAException rename table error, db=" + dbName + ", tbl=" + tblName + ", new tbl=" + newName
                + ", msg=" + e.getMessage());
        e.printStackTrace();
        throw new MetaException(e.getMessage());
    } finally {
        if (!success) {
            try {
                masterSaRes.rollback(masterXid);
            } catch (Exception x) {

            }

            try {
                slaveSaRes.rollback(slaveXid);
            } catch (Exception x) {

            }
            if (isMoved) {
                try {
                    if (oldFs.exists(oldPath)) {
                        oldFs.rename(newPath, oldPath);
                    }

                } catch (IOException e) {
                    throw new InvalidOperationException("Unable to access old location " + oldPath
                            + " for table " + dbName + "." + tblName);

                }
            }
        }

        closeStatement(masterStmt);
        closeStatement(slaveStmt);

        closeConnection(masterConn);
        closeConnection(slaveConn);

        closeXAConnection(masterDSXaConn);
        closeXAConnection(slaveDSXaConn);
    }

    if (success) {
        Statement stmt = null;
        Connection con = null;
        try {
            con = getGlobalConnection();
            stmt = con.createStatement();
            String sql = "update tblsensitivity set tbl_name='" + newName + "' where db_name='" + dbName
                    + "' and tbl_name='" + tblName + "'";

            stmt.executeUpdate(sql);
        } catch (Exception e1) {
            LOG.error("update tblsenstivity table error, db=" + dbName + ", tbl=" + tblName + ", msg="
                    + e1.getMessage());
        } finally {
            closeStatement(stmt);
            closeConnection(con);
        }
    }
}