當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheStoreSession類代碼示例

本文整理匯總了Java中org.apache.ignite.cache.store.CacheStoreSession的典型用法代碼示例。如果您正苦於以下問題:Java CacheStoreSession類的具體用法?Java CacheStoreSession怎麽用?Java CacheStoreSession使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CacheStoreSession類屬於org.apache.ignite.cache.store包,在下文中一共展示了CacheStoreSession類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSessionEnd

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
    if (ses.isWithinTransaction()) {
        TransactionStatus tx = ses.attach(null);

        if (tx != null) {
            try {
                if (commit)
                    txMgr.commit(tx);
                else
                    txMgr.rollback(tx);
            }
            catch (TransactionException e) {
                throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
            }
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:19,代碼來源:CacheSpringStoreSessionListener.java

示例2: onSessionStart

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** {@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);
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:17,代碼來源:CacheHibernateStoreSessionListener.java

示例3: onSessionEnd

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
    Session hibSes = ses.attach(null);

    if (hibSes != null) {
        try {
            Transaction tx = hibSes.getTransaction();

            if (commit) {
                if (hibSes.isDirty())
                    hibSes.flush();

                if (tx.getStatus() == TransactionStatus.ACTIVE)
                    tx.commit();
            }
            else if (tx.getStatus().canRollback())
                tx.rollback();
        }
        catch (HibernateException e) {
            throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
        }
        finally {
            hibSes.close();
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:27,代碼來源:CacheHibernateStoreSessionListener.java

示例4: onSessionEnd

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
    Session hibSes = ses.attach(null);

    if (hibSes != null) {
        try {
            Transaction tx = hibSes.getTransaction();

            if (commit) {
                hibSes.flush();

                if (tx.isActive())
                    tx.commit();
            }
            else if (tx.isActive())
                tx.rollback();
        }
        catch (HibernateException e) {
            throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
        }
        finally {
            hibSes.close();
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:26,代碼來源:CacheHibernateStoreSessionListener.java

示例5: createCacheStore

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** */
public static CacheStore createCacheStore(String cacheName, Resource persistenceSettings, DataSource conn,
    CacheStoreSession session, Logger log) {
    CassandraCacheStore<Integer, Integer> cacheStore =
        new CassandraCacheStore<>(conn, new KeyValuePersistenceSettings(persistenceSettings),
            Runtime.getRuntime().availableProcessors());

    try {
        Field sesField = CassandraCacheStore.class.getDeclaredField("storeSes");
        Field logField = CassandraCacheStore.class.getDeclaredField("log");

        sesField.setAccessible(true);
        logField.setAccessible(true);

        sesField.set(cacheStore, session != null ? session : new TestCacheSession(cacheName));
        logField.set(cacheStore, new Log4JLogger(log));
    }
    catch (Throwable e) {
        throw new RuntimeException("Failed to initialize test Ignite cache store", e);
    }

    return cacheStore;
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:24,代碼來源:CacheStoreHelper.java

示例6: connection

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/**
 * @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;
    }
    // Transaction can be null in case of simple load operation.
    else
        return openConnection(true);
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:26,代碼來源:CacheAbstractJdbcStore.java

示例7: onSessionEnd

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void onSessionEnd(CacheStoreSession ses, boolean commit) {
    Connection conn = ses.attach(null);

    if (conn != null) {
        try {
            if (commit)
                conn.commit();
            else
                conn.rollback();
        }
        catch (SQLException e) {
            throw new CacheWriterException("Failed to end store session [tx=" + ses.transaction() + ']', e);
        }
        finally {
            U.closeQuiet(conn);
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:20,代碼來源:CacheJdbcStoreSessionListener.java

示例8: checkTx

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/**
 * @param ses Session.
 * @param load {@code True} if {@link #loadAll} method is called.
 */
private void checkTx(@Nullable CacheStoreSession ses, boolean load) {
    Transaction tx = ses != null ? ses.transaction() : null;

    if (tx == null)
        return;

    txs.add(tx);

    IgniteInternalTx tx0 = GridTestUtils.getFieldValue(tx, "tx");

    if (!tx0.local())
        throw new IgniteException("Tx is not local: " + tx);

    if (tx0.dht() && !load)
        throw new IgniteException("Tx is DHT: " + tx);
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:21,代碼來源:GridCacheTestStore.java

示例9: testWriteWithoutTransaction

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
@Test
public void testWriteWithoutTransaction() {
    CacheStoreSession session = mock(CacheStoreSession.class);
    doReturn(null).when(session).transaction();

    IdSequencer idSequencer = mock(IdSequencer.class);
    doReturn(1L).when(idSequencer).getNextId();

    ModificationListener listener = mock(ModificationListener.class);
    Map<Long, Map<String, Collection<Cache.Entry<?, ?>>>> calls = new HashMap<>();
    doAnswer(answer -> {
        calls.put(answer.<Long>getArgument(0), answer.getArgument(1));
        return null;
    }).when(listener).handle(anyLong(), anyMap());

    DataCapturerBus<Integer, Integer> cacheStore = create(session, CACHE_NAME, Collections.singletonList(listener), idSequencer);
    cacheStore.write(new CacheEntryImpl<>(1, 1));

    verify(idSequencer, times(1)).getNextId();

    assertEquals(1, calls.size());
    assertTrue(calls.containsKey(1L));
    Map<String, Collection<Cache.Entry<?, ?>>> map = calls.get(1L);
    assertNotNull(map);
    assertEquals(1, map.size());
    assertTrue(map.containsKey(CACHE_NAME));
    Collection<Cache.Entry<?, ?>> entries = map.get(CACHE_NAME);
    assertEquals(1, entries.size());
    Cache.Entry<?, ?> entry = entries.iterator().next();
    assertNotNull(entry);
    assertEquals(1, entry.getKey());
    assertEquals(1, entry.getValue());
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:34,代碼來源:DataCaptureBusUnitTest.java

示例10: create

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
private DataCapturerBus<Integer, Integer> create(
        CacheStoreSession session,
        String cacheName,
        List<ModificationListener> allListeners,
        IdSequencer sequencer
) {
    DataCapturerBus<Integer, Integer> result = new DataCapturerBus<>();
    result.session = session;
    result.cacheName = cacheName;
    result.allListeners = allListeners;
    result.sequencer = sequencer;
    return result;
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:14,代碼來源:DataCaptureBusUnitTest.java

示例11: onSessionEnd

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
@Override
public void onSessionEnd(CacheStoreSession ses, boolean commit) {
  Table table = ses.attach(null);

  if (table != null) {
    try {
      table.close();
    } catch (IOException e) {
      String msg = "Failed to close table connection";
      logger.warning(msg, e);
      throw new CacheException(msg, e);
    }
  }

}
 
開發者ID:bakdata,項目名稱:ignite-hbase,代碼行數:16,代碼來源:HBaseCacheStoreSessionListener.java

示例12: onSessionStart

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
@Override
public void onSessionStart(CacheStoreSession ses) {
  if (ses.attachment() == null) {
    String familyName = ses.cacheName();
    verifyIntegrity(familyName);
    try {
      Table table = conn.getTable(TableName.valueOf(tableName));
      ses.attach(table);
    } catch (IOException e) {
      logger.warning("Error preparing session", e);
      throw new CacheException(e);
    }
  }
}
 
開發者ID:bakdata,項目名稱:ignite-hbase,代碼行數:15,代碼來源:HBaseCacheStoreSessionListener.java

示例13: onSessionStart

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/** {@inheritDoc} */
@Override public void onSessionStart(CacheStoreSession ses) {
    if (ses.isWithinTransaction() && ses.attachment() == null) {
        try {
            TransactionDefinition def = definition(ses.transaction(), ses.cacheName());

            ses.attach(txMgr.getTransaction(def));
        }
        catch (TransactionException e) {
            throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e);
        }
    }
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:14,代碼來源:CacheSpringStoreSessionListener.java

示例14: injectStoreSession

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/**
 * Injects cache store session into given object.
 *
 * @param obj Object.
 * @param ses Session to inject.
 * @return {@code True} if session was injected.
 * @throws IgniteCheckedException If failed to inject.
 */
public boolean injectStoreSession(Object obj, CacheStoreSession ses) throws IgniteCheckedException {
    assert obj != null;

    if (log.isDebugEnabled())
        log.debug("Injecting cache store session: " + obj);

    // Unwrap Proxy object.
    obj = unwrapTarget(obj);

    return inject(obj, GridResourceIoc.ResourceAnnotation.CACHE_STORE_SESSION, null, null, ses);
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:20,代碼來源:GridResourceProcessor.java

示例15: closeConnection

import org.apache.ignite.cache.store.CacheStoreSession; //導入依賴的package包/類
/**
 * Closes connection.
 *
 * @param conn Connection to close.
 */
protected void closeConnection(@Nullable Connection conn) {
    CacheStoreSession ses = session();

    // Close connection right away if there is no transaction.
    if (ses.transaction() == null)
        U.closeQuiet(conn);
}
 
開發者ID:apache,項目名稱:ignite,代碼行數:13,代碼來源:CacheAbstractJdbcStore.java


注:本文中的org.apache.ignite.cache.store.CacheStoreSession類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。