/** {@inheritDoc} */ @Override public void sessionEnd(boolean commit) throws CacheWriterException { CacheStoreSession ses = session(); Transaction tx = ses.transaction(); if (tx != null) { Map<String, Connection> sesProps = ses.properties(); Connection conn = sesProps.get(ATTR_CONN_PROP); if (conn != null) { sesProps.remove(ATTR_CONN_PROP); try { if (commit) conn.commit(); else conn.rollback(); } catch (SQLException e) { throw new CacheWriterException( "Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e); } finally { U.closeQuiet(conn); } } if (log.isDebugEnabled()) log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']'); } }
/** {@inheritDoc} */ @Override public void sessionEnd(boolean commit) { init(); Transaction tx = transaction(); Map<String, Connection> props = session().properties(); Connection conn = props.remove(ATTR_CONN); if (conn != null) { try { if (commit) conn.commit(); else conn.rollback(); } catch (SQLException e) { throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e); } finally { closeConnection(conn); } } if (log.isDebugEnabled()) log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']'); }
/** * Gets DB transaction isolation level based on ongoing cache transaction isolation. * * @return DB transaction isolation. */ private TransactionDefinition definition(Transaction tx, String cacheName) { assert tx != null; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']'); def.setIsolationLevel(isolationLevel(tx.isolation())); long timeoutSec = (tx.timeout() + 500) / 1000; if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE) def.setTimeout((int)timeoutSec); return def; }
Set<Integer> initAmount = generateCoins(coinsCntr, 5); cache.put(accountId, new AccountState(accountId, tx.xid(), initAmount));
", tx=" + tx.xid() + ']');
/** * Gets Hibernate session. * * @param tx Cache transaction. * @return Session. */ Session session(@Nullable Transaction tx) { Session ses; if (tx != null) { Map<String, Session> props = session().properties(); ses = props.get(ATTR_SES); if (ses == null) { ses = sesFactory.openSession(); ses.beginTransaction(); // Store session in transaction metadata, so it can be accessed // for other operations on the same transaction. props.put(ATTR_SES, ses); if (log.isDebugEnabled()) log.debug("Hibernate session open [ses=" + ses + ", tx=" + tx.xid() + "]"); } } else { ses = sesFactory.openSession(); ses.beginTransaction(); } return ses; }
/** {@inheritDoc} */ @Override public void sessionEnd(boolean commit) throws CacheWriterException { CacheStoreSession ses = session(); Transaction tx = ses.transaction(); if (tx != null) { Map<String, Connection> sesProps = ses.properties(); Connection conn = sesProps.get(ATTR_CONN_PROP); if (conn != null) { sesProps.remove(ATTR_CONN_PROP); try { if (commit) conn.commit(); else conn.rollback(); } catch (SQLException e) { throw new CacheWriterException( "Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e); } finally { U.closeQuiet(conn); } } if (log.isDebugEnabled()) log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']'); } }
/** {@inheritDoc} */ @Override public void sessionEnd(boolean commit) { init(); Transaction tx = transaction(); Map<String, Connection> props = session().properties(); Connection conn = props.remove(ATTR_CONN); if (conn != null) { try { if (commit) conn.commit(); else conn.rollback(); } catch (SQLException e) { throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e); } finally { closeConnection(conn); } } if (log.isDebugEnabled()) log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']'); }
/** {@inheritDoc} */ @Override public void sessionEnd(boolean commit) { init(); Transaction tx = transaction(); Map<String, Session> props = session().properties(); Session ses = props.remove(ATTR_SES); if (ses != null) { org.hibernate.Transaction hTx = ses.getTransaction(); if (hTx != null) { try { if (commit) { ses.flush(); hTx.commit(); } else hTx.rollback(); if (log.isDebugEnabled()) log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']'); } catch (HibernateException e) { throw new CacheWriterException("Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e); } finally { ses.close(); } } } }
/** * Gets DB transaction isolation level based on ongoing cache transaction isolation. * * @return DB transaction isolation. */ private TransactionDefinition definition(Transaction tx, String cacheName) { assert tx != null; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("Ignite Tx [cache=" + (cacheName != null ? cacheName : "<default>") + ", id=" + tx.xid() + ']'); def.setIsolationLevel(isolationLevel(tx.isolation())); long timeoutSec = (tx.timeout() + 500) / 1000; if (timeoutSec > 0 && timeoutSec < Integer.MAX_VALUE) def.setTimeout((int)timeoutSec); return def; }