当前位置: 首页>>代码示例>>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;未经允许,请勿转载。