use of org.apache.ignite.cache.store.CacheStoreSession in project ignite by apache.
the class CacheAbstractJdbcStore method sessionEnd.
/**
* {@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 + ']');
}
}
use of org.apache.ignite.cache.store.CacheStoreSession in project ignite by apache.
the class CacheAbstractJdbcStore method connection.
/**
* @return Connection.
* @throws SQLException In case of error.
*/
protected Connection connection() throws SQLException {
CacheStoreSession ses = session();
if (ses.transaction() != null) {
Map<String, Connection> prop = ses.properties();
Connection conn = prop.get(ATTR_CONN_PROP);
if (conn == null) {
conn = openConnection(false);
// Store connection in session to used it for other operations in the same session.
prop.put(ATTR_CONN_PROP, conn);
}
return conn;
} else
return openConnection(true);
}
use of org.apache.ignite.cache.store.CacheStoreSession in project ignite by apache.
the class CacheHibernateStoreSessionListener method onSessionStart.
/**
* {@inheritDoc}
*/
@Override
public void onSessionStart(CacheStoreSession ses) {
if (ses.attachment() == null) {
try {
Session hibSes = sesFactory.openSession();
ses.attach(hibSes);
if (ses.isWithinTransaction())
hibSes.beginTransaction();
} catch (HibernateException e) {
throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
}
}
}
Aggregations