Search in sources :

Example 1 with CacheStoreSession

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 + ']');
    }
}
Also used : Transaction(org.apache.ignite.transactions.Transaction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CacheStoreSession(org.apache.ignite.cache.store.CacheStoreSession) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 2 with CacheStoreSession

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);
}
Also used : Connection(java.sql.Connection) CacheStoreSession(org.apache.ignite.cache.store.CacheStoreSession)

Example 3 with CacheStoreSession

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);
        }
    }
}
Also used : HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session) CacheStoreSession(org.apache.ignite.cache.store.CacheStoreSession) CacheWriterException(javax.cache.integration.CacheWriterException)

Aggregations

CacheStoreSession (org.apache.ignite.cache.store.CacheStoreSession)3 Connection (java.sql.Connection)2 CacheWriterException (javax.cache.integration.CacheWriterException)2 SQLException (java.sql.SQLException)1 Transaction (org.apache.ignite.transactions.Transaction)1 HibernateException (org.hibernate.HibernateException)1 Session (org.hibernate.Session)1