List of usage examples for javax.transaction.xa XAResource TMNOFLAGS
int TMNOFLAGS
To view the source code for javax.transaction.xa XAResource TMNOFLAGS.
Click Source Link
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public boolean dropAuthInDbByDistributeTransaction(String who) throws MetaException { boolean success = false; Set<String> slaveURLSet = getAllSegments(); int size = slaveURLSet.size(); PGXADataSource[] slaveDSArray = new PGXADataSource[size]; XAConnection[] slaveDSXaConnArray = new XAConnection[size]; XAResource[] slaveSaResArray = new XAResource[size]; Connection[] slaveConArray = new Connection[size]; Statement[] slaveStmtArray = new Statement[size]; Xid[] slaveXidArray = new Xid[size]; who = who.toLowerCase();/*w ww. java 2s . co m*/ int index = 0; for (String slaveURL : slaveURLSet) { slaveDSArray[index] = getXADataSource(slaveURL, user, passwd); index++; } int formatID = genFormatID(); try { for (int i = 0; i < size; i++) { slaveDSXaConnArray[i] = slaveDSArray[i].getXAConnection(); slaveSaResArray[i] = slaveDSXaConnArray[i].getXAResource(); slaveConArray[i] = slaveDSXaConnArray[i].getConnection(); slaveStmtArray[i] = slaveConArray[i].createStatement(); byte id1 = (byte) ((i + 2) * 2); byte id2 = (byte) (id1 + 1); slaveXidArray[i] = new MyXid(formatID, new byte[] { id1 }, new byte[] { id2 }); } try { for (int i = 0; i < size; i++) { slaveSaResArray[i].start(slaveXidArray[i], XAResource.TMNOFLAGS); slaveStmtArray[i] .executeUpdate("delete from dbpriv where user_name='" + who.toLowerCase() + "'"); slaveSaResArray[i].end(slaveXidArray[i], XAResource.TMSUCCESS); } boolean isAllPred = true; int[] slaveRetArray = new int[size]; for (int i = 0; i < size; i++) { slaveRetArray[i] = slaveSaResArray[i].prepare(slaveXidArray[i]); if (slaveRetArray[i] == XAResource.XA_OK) { continue; } else { isAllPred = false; break; } } if (isAllPred) { for (int i = 0; i < size; i++) { slaveSaResArray[i].commit(slaveXidArray[i], false); } success = true; } } catch (XAException e) { LOG.error("drop auth in db error, who=" + who + ", msg=" + e.getMessage()); } } catch (SQLException e) { LOG.error("drop auth in db error, who=" + who + ", msg=" + e.getMessage()); throw new MetaException(e.getMessage()); } finally { for (int i = 0; i < size; i++) { closeConnection(slaveConArray[i]); closeXAConnection(slaveDSXaConnArray[i]); } } return success; }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public List<TblPriv> getAuthOnTblsByDistributeTransaction(String who) throws MetaException { boolean success = false; List<TblPriv> tblPrivs = new ArrayList<TblPriv>(); Set<String> slaveURLSet = getAllSegments(); int size = slaveURLSet.size(); PGXADataSource[] slaveDSArray = new PGXADataSource[size]; XAConnection[] slaveDSXaConnArray = new XAConnection[size]; XAResource[] slaveSaResArray = new XAResource[size]; Connection[] slaveConArray = new Connection[size]; Statement[] slaveStmtArray = new Statement[size]; Xid[] slaveXidArray = new Xid[size]; who = who.toLowerCase();/*from w w w. ja v a 2 s . com*/ int index = 0; for (String slaveURL : slaveURLSet) { slaveDSArray[index] = getXADataSource(slaveURL, user, passwd); index++; } int formatID = genFormatID(); try { for (int i = 0; i < size; i++) { slaveDSXaConnArray[i] = slaveDSArray[i].getXAConnection(); slaveSaResArray[i] = slaveDSXaConnArray[i].getXAResource(); slaveConArray[i] = slaveDSXaConnArray[i].getConnection(); slaveStmtArray[i] = slaveConArray[i].createStatement(); byte id1 = (byte) ((i + 2) * 2); byte id2 = (byte) (id1 + 1); slaveXidArray[i] = new MyXid(formatID, new byte[] { id1 }, new byte[] { id2 }); } try { for (int i = 0; i < size; i++) { slaveSaResArray[i].start(slaveXidArray[i], XAResource.TMNOFLAGS); ResultSet tblPrivSet = slaveStmtArray[i] .executeQuery("select alter_priv, create_priv, delete_priv " + ",drop_priv, index_priv, insert_priv, select_priv, update_priv, db_name, tbl_name" + " from tblpriv where user_name='" + who.toLowerCase() + "'"); while (tblPrivSet.next()) { TblPriv tblPriv = new TblPriv(); tblPriv.setAlterPriv(tblPrivSet.getBoolean(1)); tblPriv.setCreatePriv(tblPrivSet.getBoolean(2)); tblPriv.setDeletePriv(tblPrivSet.getBoolean(3)); tblPriv.setDropPriv(tblPrivSet.getBoolean(4)); tblPriv.setIndexPriv(tblPrivSet.getBoolean(5)); tblPriv.setInsertPriv(tblPrivSet.getBoolean(6)); tblPriv.setSelectPriv(tblPrivSet.getBoolean(7)); tblPriv.setUpdatePriv(tblPrivSet.getBoolean(8)); tblPriv.setDb(tblPrivSet.getString(9)); tblPriv.setTbl(tblPrivSet.getString(10)); tblPriv.setUser(who); tblPrivs.add(tblPriv); } slaveSaResArray[i].end(slaveXidArray[i], XAResource.TMSUCCESS); } boolean isAllPred = true; int[] slaveRetArray = new int[size]; for (int i = 0; i < size; i++) { slaveRetArray[i] = slaveSaResArray[i].prepare(slaveXidArray[i]); if (slaveRetArray[i] == XAResource.XA_OK) { continue; } else { isAllPred = false; break; } } if (isAllPred) { for (int i = 0; i < size; i++) { slaveSaResArray[i].commit(slaveXidArray[i], false); } success = true; } } catch (XAException e) { LOG.error("get user auth on tbls error, user=" + who + ", msg=" + e.getMessage()); throw new MetaException(e.getMessage()); } } catch (SQLException e) { LOG.error("get user auth on tbls error, user=" + who + ", msg=" + e.getMessage()); throw new MetaException(e.getMessage()); } finally { for (int i = 0; i < size; i++) { closeConnection(slaveConArray[i]); closeXAConnection(slaveDSXaConnArray[i]); } } if (success) { return tblPrivs; } else { return null; } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public List<TblPriv> getAuthOnAllTblsByDistributeTransaction() throws MetaException { boolean success = false; List<TblPriv> tblPrivs = new ArrayList<TblPriv>(); Set<String> slaveURLSet = getAllSegments(); int size = slaveURLSet.size(); PGXADataSource[] slaveDSArray = new PGXADataSource[size]; XAConnection[] slaveDSXaConnArray = new XAConnection[size]; XAResource[] slaveSaResArray = new XAResource[size]; Connection[] slaveConArray = new Connection[size]; Statement[] slaveStmtArray = new Statement[size]; Xid[] slaveXidArray = new Xid[size]; int index = 0; for (String slaveURL : slaveURLSet) { slaveDSArray[index] = getXADataSource(slaveURL, user, passwd); index++;// w w w . j a v a2s. c o m } int formatID = genFormatID(); try { for (int i = 0; i < size; i++) { slaveDSXaConnArray[i] = slaveDSArray[i].getXAConnection(); slaveSaResArray[i] = slaveDSXaConnArray[i].getXAResource(); slaveConArray[i] = slaveDSXaConnArray[i].getConnection(); slaveStmtArray[i] = slaveConArray[i].createStatement(); byte id1 = (byte) ((i + 2) * 2); byte id2 = (byte) (id1 + 1); slaveXidArray[i] = new MyXid(formatID, new byte[] { id1 }, new byte[] { id2 }); } try { for (int i = 0; i < size; i++) { slaveSaResArray[i].start(slaveXidArray[i], XAResource.TMNOFLAGS); ResultSet tblPrivSet = slaveStmtArray[i] .executeQuery("select alter_priv, create_priv, delete_priv " + ",drop_priv, index_priv, insert_priv, select_priv, update_priv, user_name, db_name, tbl_name" + " from tblpriv"); while (tblPrivSet.next()) { TblPriv tblPriv = new TblPriv(); tblPriv.setAlterPriv(tblPrivSet.getBoolean(1)); tblPriv.setCreatePriv(tblPrivSet.getBoolean(2)); tblPriv.setDeletePriv(tblPrivSet.getBoolean(3)); tblPriv.setDropPriv(tblPrivSet.getBoolean(4)); tblPriv.setIndexPriv(tblPrivSet.getBoolean(5)); tblPriv.setInsertPriv(tblPrivSet.getBoolean(6)); tblPriv.setSelectPriv(tblPrivSet.getBoolean(7)); tblPriv.setUpdatePriv(tblPrivSet.getBoolean(8)); tblPriv.setUser(tblPrivSet.getString(9)); tblPriv.setDb(tblPrivSet.getString(10)); tblPriv.setTbl(tblPrivSet.getString(11)); tblPrivs.add(tblPriv); } slaveSaResArray[i].end(slaveXidArray[i], XAResource.TMSUCCESS); } boolean isAllPred = true; int[] slaveRetArray = new int[size]; for (int i = 0; i < size; i++) { slaveRetArray[i] = slaveSaResArray[i].prepare(slaveXidArray[i]); if (slaveRetArray[i] == XAResource.XA_OK) { continue; } else { isAllPred = false; break; } } if (isAllPred) { for (int i = 0; i < size; i++) { slaveSaResArray[i].commit(slaveXidArray[i], false); } success = true; } } catch (XAException e) { LOG.error("get user auth on all tbls error, msg=" + e.getMessage()); throw new MetaException(e.getMessage()); } } catch (SQLException e) { LOG.error("get user auth on all tbls error, msg=" + e.getMessage()); throw new MetaException(e.getMessage()); } finally { for (int i = 0; i < size; i++) { closeConnection(slaveConArray[i]); closeXAConnection(slaveDSXaConnArray[i]); } } if (success) { return tblPrivs; } else { return null; } }
From source file:org.apache.hadoop.hive.metastore.MyXid.java
public boolean dropAuthInTblByDistributeTransaction(String who) throws MetaException { boolean success = false; Set<String> slaveURLSet = getAllSegments(); int size = slaveURLSet.size(); PGXADataSource[] slaveDSArray = new PGXADataSource[size]; XAConnection[] slaveDSXaConnArray = new XAConnection[size]; XAResource[] slaveSaResArray = new XAResource[size]; Connection[] slaveConArray = new Connection[size]; Statement[] slaveStmtArray = new Statement[size]; Xid[] slaveXidArray = new Xid[size]; who = who.toLowerCase();// w w w. ja v a 2 s . c om int index = 0; for (String slaveURL : slaveURLSet) { slaveDSArray[index] = getXADataSource(slaveURL, user, passwd); index++; } int formatID = genFormatID(); try { for (int i = 0; i < size; i++) { slaveDSXaConnArray[i] = slaveDSArray[i].getXAConnection(); slaveSaResArray[i] = slaveDSXaConnArray[i].getXAResource(); slaveConArray[i] = slaveDSXaConnArray[i].getConnection(); slaveStmtArray[i] = slaveConArray[i].createStatement(); byte id1 = (byte) ((i + 2) * 2); byte id2 = (byte) (id1 + 1); slaveXidArray[i] = new MyXid(formatID, new byte[] { id1 }, new byte[] { id2 }); } try { for (int i = 0; i < size; i++) { slaveSaResArray[i].start(slaveXidArray[i], XAResource.TMNOFLAGS); slaveStmtArray[i] .executeUpdate("delete from tblpriv where user_name='" + who.toLowerCase() + "'"); slaveSaResArray[i].end(slaveXidArray[i], XAResource.TMSUCCESS); } boolean isAllPred = true; int[] slaveRetArray = new int[size]; for (int i = 0; i < size; i++) { slaveRetArray[i] = slaveSaResArray[i].prepare(slaveXidArray[i]); if (slaveRetArray[i] == XAResource.XA_OK) { continue; } else { isAllPred = false; break; } } if (isAllPred) { for (int i = 0; i < size; i++) { slaveSaResArray[i].commit(slaveXidArray[i], false); } success = true; } } catch (XAException e) { LOG.error("drop auth in tbl error, who=" + who + ", msg=" + e.getMessage()); } } catch (SQLException e) { LOG.error("drop auth in tbl error, who=" + who + ", msg=" + e.getMessage()); throw new MetaException(e.getMessage()); } finally { for (int i = 0; i < size; i++) { closeConnection(slaveConArray[i]); closeXAConnection(slaveDSXaConnArray[i]); } } return success; }
From source file:org.apache.synapse.commons.transaction.TranscationManger.java
public static void endTransaction(boolean insideSynapse, long key) throws Exception { int xaResourceStatus = XAResource.TMNOFLAGS; try {/*from w w w . j a v a2 s. com*/ if (insideSynapse && transactions.get() == null) { log.warn(" END Thread Local null "); return; } if (insideSynapse && transactions.get().get(key) == null) { log.warn(" END Some How TX null "); return; } if (transactions.get().get(key) != null && javax.transaction.Status.STATUS_ACTIVE == transactions.get().get(key).getStatus()) { txManagers.get().get(key).commit(); xaResourceStatus = XAResource.TMSUCCESS; } } catch (Exception ex) { xaResourceStatus = XAResource.TMFAIL; log.error(" END ERROR : " + txManagers.get().get(key).getStatus()); throw ex; } finally { // delist delistResource(xaResourceStatus, key); } }
From source file:org.eclipse.ecr.core.storage.sql.LockManager.java
/** * Calls the callable, inside a transaction if in cluster mode. * <p>/*from w w w. java 2 s . c o m*/ * Called under {@link #serializationLock}. */ protected Lock callInTransaction(Callable<Lock> callable) throws StorageException { Xid xid = null; boolean txStarted = false; boolean txSuccess = false; try { if (clusteringEnabled) { xid = new XidImpl( "nuxeolockmanager." + System.currentTimeMillis() + "." + txCounter.incrementAndGet()); try { mapper.start(xid, XAResource.TMNOFLAGS); } catch (XAException e) { throw new StorageException(e); } txStarted = true; } // else no need to process invalidations, // only this mapper writes locks // actual call Lock result; try { result = callable.call(); } catch (StorageException e) { throw e; } catch (Exception e) { throw new StorageException(e); } txSuccess = true; return result; } finally { if (txStarted) { try { if (txSuccess) { mapper.end(xid, XAResource.TMSUCCESS); mapper.commit(xid, true); } else { mapper.end(xid, XAResource.TMFAIL); mapper.rollback(xid); } } catch (XAException e) { throw new StorageException(e); } } } }
From source file:org.eclipse.ecr.core.storage.sql.TestSQLBackend.java
public void testRollback() throws Exception { Session session = repository.getConnection(); XAResource xaresource = ((SessionImpl) session).getXAResource(); Node root = session.getRootNode(); Node nodea = session.addChildNode(root, "foo", null, "TestDoc", false); nodea.setSimpleProperty("tst:title", "old"); assertEquals("old", nodea.getSimpleProperty("tst:title").getString()); session.save();/*from w ww. ja va 2s . c o m*/ /* * rollback before save (underlying XAResource saw no updates) */ Xid xid = new XidImpl("1"); xaresource.start(xid, XAResource.TMNOFLAGS); nodea = session.getNodeByPath("/foo", null); nodea.setSimpleProperty("tst:title", "new"); xaresource.end(xid, XAResource.TMSUCCESS); xaresource.prepare(xid); xaresource.rollback(xid); nodea = session.getNodeByPath("/foo", null); assertEquals("old", nodea.getSimpleProperty("tst:title").getString()); /* * rollback after save (underlying XAResource does a rollback too) */ xid = new XidImpl("2"); xaresource.start(xid, XAResource.TMNOFLAGS); nodea = session.getNodeByPath("/foo", null); nodea.setSimpleProperty("tst:title", "new"); session.save(); xaresource.end(xid, XAResource.TMSUCCESS); xaresource.prepare(xid); xaresource.rollback(xid); nodea = session.getNodeByPath("/foo", null); assertEquals("old", nodea.getSimpleProperty("tst:title").getString()); }
From source file:org.eclipse.ecr.core.storage.sql.TestSQLBackend.java
public void testSaveOnCommit() throws Exception { Session session = repository.getConnection(); // init session.save();//from w w w . j a va 2 s .c o m XAResource xaresource = ((SessionImpl) session).getXAResource(); // first transaction Xid xid = new XidImpl("1"); xaresource.start(xid, XAResource.TMNOFLAGS); Node root = session.getRootNode(); assertNotNull(root); session.addChildNode(root, "foo", null, "TestDoc", false); // let end do an implicit save xaresource.end(xid, XAResource.TMSUCCESS); xaresource.prepare(xid); xaresource.commit(xid, false); // should have saved, clearing caches should be harmless ((SessionImpl) session).clearCaches(); // second transaction xid = new XidImpl("2"); xaresource.start(xid, XAResource.TMNOFLAGS); Node foo = session.getNodeByPath("/foo", null); assertNotNull(foo); xaresource.end(xid, XAResource.TMSUCCESS); int outcome = xaresource.prepare(xid); if (outcome == XAResource.XA_OK) { // Derby doesn't allow rollback if prepare returned XA_RDONLY xaresource.rollback(xid); } }
From source file:org.nuxeo.ecm.core.storage.sql.TestSQLBackend.java
protected static Xid begin(Session session) throws XAException { XAResource xaresource = ((SessionImpl) session).getXAResource(); Xid xid = new XidImpl(UUID.randomUUID().toString()); xaresource.start(xid, XAResource.TMNOFLAGS); return xid;//from w w w .j a v a 2s . c om }
From source file:org.nuxeo.ecm.core.storage.sql.TestSQLBackend.java
@Test public void testRollback() throws Exception { if (!DatabaseHelper.DATABASE.supportsXA()) { return;// w ww . ja v a 2 s . com } Session session = repository.getConnection(); XAResource xaresource = ((SessionImpl) session).getXAResource(); Node root = session.getRootNode(); Node nodea = session.addChildNode(root, "foo", null, "TestDoc", false); nodea.setSimpleProperty("tst:title", "old"); assertEquals("old", nodea.getSimpleProperty("tst:title").getString()); session.save(); /* * rollback before save (underlying XAResource saw no updates) */ Xid xid = new XidImpl("11111111111111111111111111111111"); xaresource.start(xid, XAResource.TMNOFLAGS); nodea = session.getNodeByPath("/foo", null); nodea.setSimpleProperty("tst:title", "new"); xaresource.end(xid, XAResource.TMSUCCESS); xaresource.prepare(xid); xaresource.rollback(xid); nodea = session.getNodeByPath("/foo", null); assertEquals("old", nodea.getSimpleProperty("tst:title").getString()); /* * rollback after save (underlying XAResource does a rollback too) */ xid = new XidImpl("22222222222222222222222222222222"); xaresource.start(xid, XAResource.TMNOFLAGS); nodea = session.getNodeByPath("/foo", null); nodea.setSimpleProperty("tst:title", "new"); session.save(); xaresource.end(xid, XAResource.TMSUCCESS); xaresource.prepare(xid); xaresource.rollback(xid); nodea = session.getNodeByPath("/foo", null); assertEquals("old", nodea.getSimpleProperty("tst:title").getString()); }