Java Code Examples for javax.transaction.xa.XAResource#TMENDRSCAN
The following examples show how to use
javax.transaction.xa.XAResource#TMENDRSCAN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EhcacheXAResource.java From ehcache3 with Apache License 2.0 | 6 votes |
@Override public Xid[] recover(int flags) throws XAException { if (flags != XAResource.TMNOFLAGS && flags != XAResource.TMSTARTRSCAN && flags != XAResource.TMENDRSCAN && flags != (XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN)) { throw new EhcacheXAException("Recover flags not supported : " + xaResourceFlagsToString(flags), XAException.XAER_INVAL); } if ((flags & XAResource.TMSTARTRSCAN) == XAResource.TMSTARTRSCAN) { List<Xid> xids = new ArrayList<>(); Set<TransactionId> transactionIds = journal.recover().keySet(); for (TransactionId transactionId : transactionIds) { // filter-out in-flight tx if (!transactionContextFactory.contains(transactionId)) { xids.add(transactionId.getSerializableXid()); } } return xids.toArray(new Xid[xids.size()]); } return new Xid[0]; }
Example 2
Source File: DataSourceXAResourceRecoveryHelper.java From narayana-spring-boot with Apache License 2.0 | 5 votes |
@Override public Xid[] recover(int flag) throws XAException { try { return getDelegate(true).recover(flag); } finally { if (flag == XAResource.TMENDRSCAN) { disconnect(); } } }
Example 3
Source File: DataSourceXAResourceRecoveryHelper.java From shardingsphere with Apache License 2.0 | 5 votes |
@Override public Xid[] recover(final int flag) throws XAException { try { return getDelegate(true).recover(flag); } finally { if (flag == XAResource.TMENDRSCAN) { disconnect(); } } }
Example 4
Source File: AbstractTransactionAssistanceXAResource.java From genericconnector with Apache License 2.0 | 5 votes |
@Override public Xid[] recover(int flag) throws XAException { List<Xid> xids = new ArrayList<Xid>(); switch(flag) { case (XAResource.TMSTARTRSCAN): log.log(Level.INFO, "RECOVER TMSTARTRSCAN"); UnderlyingConnection callback = getUnderlyingConnection(); if(callback != null){ final String[] unfinishedTxIds; if(isHandleRecoveryInternally()){ unfinishedTxIds = getTransactionsInNeedOfRecovery(); }else{ unfinishedTxIds = callback.getTransactionsInNeedOfRecovery(); } if(unfinishedTxIds != null){ for(String txId : unfinishedTxIds){ log.log(Level.INFO, "recovery required for " + txId); Xid xid = XidImpl.getXid(txId); xids.add(xid); } } } break; case (XAResource.TMENDRSCAN): log.log(Level.INFO, "RECOVER TMENDRSCAN"); break; case (XAResource.TMNOFLAGS): log.log(Level.INFO, "RECOVER TMNOFLAGS"); break; default: log.log(Level.INFO, "RECOVER " + flag); } return xids.toArray(new Xid[0]); }
Example 5
Source File: FBManagedConnection.java From jaybird with GNU Lesser General Public License v2.1 | 4 votes |
/** * Obtain a list of prepared transaction branches from a resource manager. * The transaction manager calls this method during recovery to obtain the * list of transaction branches that are currently in prepared or * heuristically completed states. * * @param flags * One of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS. TMNOFLAGS must be used when no other flags are set in flags. * @return The resource manager returns zero or more XIDs for the transaction branches that are currently in a * prepared or heuristically completed state. If an error occurs during the operation, the resource manager should * throw the appropriate XAException. * @throws XAException * An error has occurred. Possible values are XAER_RMERR, XAER_RMFAIL, XAER_INVAL, and XAER_PROTO. */ private Xid[] recover(int flags) throws javax.transaction.xa.XAException { if (flags != XAResource.TMSTARTRSCAN && flags != XAResource.TMENDRSCAN && flags != XAResource.TMNOFLAGS && flags != (XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN)) { throw new FBXAException("flag not allowed in this context: " + flags + ", valid flags are TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS, TMSTARTRSCAN|TMENDRSCAN", XAException.XAER_PROTO); } try { // if (!((flags & XAResource.TMSTARTRSCAN) == 0)) // if ((flags & XAResource.TMENDRSCAN) == 0 && (flags & XAResource.TMNOFLAGS) == 0) // return new Xid[0]; List<FBXid> xids = new ArrayList<>(); FbTransaction trHandle2 = database.startTransaction(tpb.getTransactionParameterBuffer()); FbStatement stmtHandle2 = database.createStatement(trHandle2); GDSHelper gdsHelper2 = new GDSHelper(database); gdsHelper2.setCurrentTransaction(trHandle2); stmtHandle2.prepare(RECOVERY_QUERY); DataProvider dataProvider0 = new DataProvider(0); stmtHandle2.addStatementListener(dataProvider0); DataProvider dataProvider1 = new DataProvider(1); stmtHandle2.addStatementListener(dataProvider1); stmtHandle2.execute(RowValue.EMPTY_ROW_VALUE); stmtHandle2.fetchRows(10); FBField field0 = FBField.createField(stmtHandle2.getRowDescriptor().getFieldDescriptor(0), dataProvider0, gdsHelper2, false); FBField field1 = FBField.createField(stmtHandle2.getRowDescriptor().getFieldDescriptor(1), dataProvider1, gdsHelper2, false); int row = 0; while (row < dataProvider0.getRowCount()) { dataProvider0.setRow(row); dataProvider1.setRow(row); long inLimboTxId = field0.getLong(); byte[] inLimboMessage = field1.getBytes(); try { FBXid xid = new FBXid(new ByteArrayInputStream(inLimboMessage), inLimboTxId); xids.add(xid); } catch (FBIncorrectXidException ex) { log.warn("ignoring XID stored with invalid format in RDB$TRANSACTIONS for RDB$TRANSACTION_ID=" + inLimboTxId); } row++; } stmtHandle2.close(); trHandle2.commit(); return xids.toArray(new FBXid[0]); } catch (SQLException | IOException e) { throw new FBXAException("can't perform query to fetch xids", XAException.XAER_RMFAIL, e); } }
Example 6
Source File: XASupport.java From jTDS with GNU Lesser General Public License v2.1 | 4 votes |
/** * Invoke the xa_recover routine on the SQL Server. * <p/> * This version of xa_recover will return all XIDs on the first call. * * @param connection JDBC Connection enlisted in the transaction * @param xaConId the connection ID allocated by the server * @param flags XA Flags for start command * @return transactions to recover as a <code>Xid[]</code> * @exception javax.transaction.xa.XAException * if an error condition occurs */ public static Xid[] xa_recover(Connection connection, int xaConId, int flags) throws XAException { JtdsConnection con = (JtdsConnection)connection; if (con.isXaEmulation()) { // // Emulate xa_recover method // // There is no state available all uncommited transactions // will have been rolled back by the server. if (flags != XAResource.TMSTARTRSCAN && flags != XAResource.TMENDRSCAN && flags != ( XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN ) && flags != XAResource.TMNOFLAGS) { raiseXAException(XAException.XAER_INVAL); } return new JtdsXid[0]; } // // Execute xa_recover via MSDTC // int args[] = new int[5]; args[1] = XA_RECOVER; args[2] = xaConId; args[3] = XA_RMID; args[4] = XAResource.TMNOFLAGS; Xid[] list = null; if (flags != XAResource.TMSTARTRSCAN) { return new JtdsXid[0]; } try { byte[][] buffer = ((JtdsConnection) connection).sendXaPacket(args, null); if (args[0] >= 0) { int n = buffer.length; list = new JtdsXid[n]; for (int i = 0; i < n; i++) { list[i] = new JtdsXid(buffer[i], 0); } } } catch (SQLException e) { raiseXAException(e); } if (args[0] < 0) { raiseXAException(args[0]); } if (list == null) { list = new JtdsXid[0]; } return list; }