本文整理汇总了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);
}
}
}
}
示例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);
}
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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());
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}