javax.cache.integration.CacheWriterException Java Examples
The following examples show how to use
javax.cache.integration.CacheWriterException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CacheHibernateStoreSessionListener.java From ignite with Apache License 2.0 | 6 votes |
/** {@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(); } } }
Example #2
Source File: CompositeCacheWriter.java From commons-jcs with Apache License 2.0 | 6 votes |
@Override public void writeAll(final Collection<Cache.Entry<? extends K, ? extends V>> entries) throws CacheWriterException { CacheWriterException e = null; for (final CacheWriter<K, V> writer : writers) { try { writer.writeAll(entries); } catch (final CacheWriterException ex) { if (e == null) { e = ex; } } } if (e != null) { throw e; } }
Example #3
Source File: CacheHibernateStoreSessionListener.java From ignite with Apache License 2.0 | 6 votes |
/** {@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); } } }
Example #4
Source File: PutAction.java From triava with Apache License 2.0 | 6 votes |
@Override W writeThroughImpl(ActionRunner<K,V> actionRunner, Object arg) { if (!writeThrough) return null; try { actionRunner.cacheWriter.write(new TCacheJSR107Entry<K,V>(key, value)); } catch (Exception exc) { writeThroughException = new CacheWriterException(exc); } return null; }
Example #5
Source File: CacheHibernateStoreSessionListener.java From ignite with Apache License 2.0 | 6 votes |
/** {@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); } } }
Example #6
Source File: CacheHibernateStoreSessionListener.java From ignite with Apache License 2.0 | 6 votes |
/** {@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(); } } }
Example #7
Source File: CacheHibernateStoreSessionListener.java From ignite with Apache License 2.0 | 6 votes |
/** {@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(); } } }
Example #8
Source File: PlatformDotNetCacheStore.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void write(final Cache.Entry<? extends K, ? extends V> entry) { try { doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() { @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException { writer.writeByte(OP_PUT); writer.writeLong(session()); writer.writeString(ses.cacheName()); writer.writeObject(entry.getKey()); writer.writeObject(entry.getValue()); } }, null); } catch (IgniteCheckedException e) { throw new CacheWriterException(U.convertExceptionNoWrap(e)); } }
Example #9
Source File: PlatformDotNetCacheStore.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void delete(final Object key) { try { doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() { @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException { writer.writeByte(OP_RMV); writer.writeLong(session()); writer.writeString(ses.cacheName()); writer.writeObject(key); } }, null); } catch (IgniteCheckedException e) { throw new CacheWriterException(U.convertExceptionNoWrap(e)); } }
Example #10
Source File: CacheHibernateStoreSessionListener.java From ignite with Apache License 2.0 | 6 votes |
/** {@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); } } }
Example #11
Source File: PlatformDotNetCacheStore.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void deleteAll(final Collection<?> keys) { try { doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() { @Override public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException { writer.writeByte(OP_RMV_ALL); writer.writeLong(session()); writer.writeString(ses.cacheName()); writer.writeInt(keys.size()); for (Object o : keys) writer.writeObject(o); } }, null); } catch (IgniteCheckedException e) { throw new CacheWriterException(U.convertExceptionNoWrap(e)); } }
Example #12
Source File: CacheWriterTest.java From cache2k with Apache License 2.0 | 6 votes |
/** * Test constraint that cache is not mutated when CacheWriterException is thrown by * {@link javax.cache.integration.CacheWriter#delete(Object)} */ @Test public void shouldNotRemoveWhenWriteThroughFails() { cache.put(1, "Gudday World"); assertTrue(cache.containsKey(1)); cacheWriterServer.setCacheWriter(new FailingCacheWriter<Integer, String>()); try { cache.remove(1); assertTrue("expected exception on write-through", false); } catch (CacheWriterException e) { // ignore expected exception. } assertTrue(cache.containsKey(1)); }
Example #13
Source File: IgniteCacheStoreSessionAbstractTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void sessionEnd(boolean commit) throws CacheWriterException { if (session().isWithinTransaction()) { log.info("Tx end [commit=" + commit + ", tx=" + session().transaction() + ']'); checkSession("sessionEnd"); } }
Example #14
Source File: TestJdbcPojoStoreFactoryWithHangWriteAll.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> entries) throws CacheWriterException { try { super.writeAll(entries); Thread.sleep(10000); count += entries.size(); log.info("Count of load data: " + count); } catch (Exception e) { log.error("Failed to write entries to cache store: " + entries, e); } }
Example #15
Source File: PostgresDBStore.java From ignite-book-code-samples with GNU General Public License v3.0 | 5 votes |
@Override public void write(Cache.Entry<? extends String, ? extends Post> entry) throws CacheWriterException { com.blu.imdg.jdbc.model.Post post = entry.getValue(); Map<String, Object> parameterMap = new HashMap<>(); parameterMap.put("ID", post.getId()); parameterMap.put("TITLE", post.getTitle()); parameterMap.put("DESCRIPTION", post.getDescription()); parameterMap.put("CREATIONDATE", post.getCreationDate()); parameterMap.put("AUTHOR", post.getAuthor()); jdbcTemplate.update("INSERT INTO POSTS(ID,TITLE,DESCRIPTION,CREATIONDATE,AUTHOR) VALUES (:ID,:TITLE,:DESCRIPTION,:CREATIONDATE,:AUTHOR);", parameterMap); }
Example #16
Source File: NoWriter.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public void deleteAll(final Collection<?> keys) throws CacheWriterException { for (final Object k : keys) { delete(k); } }
Example #17
Source File: CacheSpringStoreSessionListenerSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void delete(Object key) throws CacheWriterException { deleteCnt.incrementAndGet(); checkTransaction(); checkConnection(); }
Example #18
Source File: CacheHibernateBlobStore.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void write(javax.cache.Cache.Entry<? extends K, ? extends V> entry) { init(); Transaction tx = transaction(); K key = entry.getKey(); V val = entry.getValue(); if (log.isDebugEnabled()) log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']'); if (val == null) { delete(key); return; } Session ses = session(tx); try { CacheHibernateBlobStoreEntry entry0 = new CacheHibernateBlobStoreEntry(toBytes(key), toBytes(val)); ses.saveOrUpdate(entry0); } catch (IgniteCheckedException | HibernateException e) { rollback(ses, tx); throw new CacheWriterException("Failed to put value to cache store [key=" + key + ", val" + val + "]", e); } finally { end(ses, tx); } }
Example #19
Source File: CacheSpringStoreSessionListenerSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) throws CacheWriterException { writeCnt.incrementAndGet(); checkTransaction(); checkConnection(); if (write.get()) { String table; switch (ses.cacheName()) { case "cache1": table = "Table1"; break; case "cache2": if (fail.get()) throw new CacheWriterException("Expected failure."); table = "Table2"; break; default: throw new CacheWriterException("Wring cache: " + ses.cacheName()); } jdbc.update("INSERT INTO " + table + " (key, value) VALUES (?, ?)", entry.getKey(), entry.getValue()); } }
Example #20
Source File: CacheJdbcStoreSessionListener.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void onSessionStart(CacheStoreSession ses) { if (ses.attachment() == null) { try { Connection conn = dataSrc.getConnection(); conn.setAutoCommit(false); ses.attach(conn); } catch (SQLException e) { throw new CacheWriterException("Failed to start store session [tx=" + ses.transaction() + ']', e); } } }
Example #21
Source File: CacheSpringStoreSessionListener.java From ignite with Apache License 2.0 | 5 votes |
/** {@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); } } }
Example #22
Source File: CacheWriterAdapter.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public void writeAll(final Collection<Cache.Entry<? extends K, ? extends V>> entries) throws CacheWriterException { for (final Cache.Entry<? extends K, ? extends V> entry : entries) { write(entry); } }
Example #23
Source File: H2CacheStoreStrategy.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void write(Cache.Entry<?, ?> entry) throws CacheWriterException { try { Connection conn = ses.attachment(); putToDb(conn, entry.getKey(), entry.getValue()); updateStats("writes"); } catch (SQLException e) { throw new CacheWriterException("Failed to write object [key=" + entry.getKey() + ", " + "val=" + entry.getValue() + ']', e); } }
Example #24
Source File: TestJdbcPojoStoreFactoryWithHangWriteAll.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void delete(Object key) throws CacheWriterException { try { super.delete(key); } catch (Exception e) { log.error("Failed to delete entry from cache store: " + key, e); } }
Example #25
Source File: GridCacheWriteBehindStore.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void write(Entry<? extends K, ? extends V> entry) { try { if (log.isDebugEnabled()) log.debug(S.toString("Store put", "key", entry.getKey(), true, "val", entry.getValue(), true)); updateCache(entry.getKey(), entry, StoreOperation.PUT); } catch (IgniteInterruptedCheckedException e) { throw new CacheWriterException(U.convertExceptionNoWrap(e)); } }
Example #26
Source File: CacheAsyncOperationsTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) { CountDownLatch latch0 = latch; if (latch0 != null) U.awaitQuiet(latch0); Integer key = entry.getKey(); if (key.equals(0)) { System.out.println(Thread.currentThread().getName() + ": fail operation for key: " + key); throw new CacheWriterException("Test error."); } }
Example #27
Source File: AsyncCacheWriter.java From commons-jcs with Apache License 2.0 | 5 votes |
@Override public void deleteAll(final Collection<?> keys) throws CacheWriterException { pool.submit(new ExceptionProtectionRunnable() { @Override public void doRun() { writer.deleteAll(keys); } }); }
Example #28
Source File: GridCacheWriteBehindStore.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void delete(Object key) { try { if (log.isDebugEnabled()) log.debug(S.toString("Store remove", "key", key, true)); updateCache((K)key, null, StoreOperation.RMV); } catch (IgniteInterruptedCheckedException e) { throw new CacheWriterException(U.convertExceptionNoWrap(e)); } }
Example #29
Source File: CacheHibernateBlobStore.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @SuppressWarnings({"JpaQueryApiInspection", "JpaQlInspection"}) @Override public void delete(Object key) { init(); Transaction tx = transaction(); if (log.isDebugEnabled()) log.debug("Store remove [key=" + key + ", tx=" + tx + ']'); Session ses = session(tx); try { Object obj = ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key)); if (obj != null) ses.delete(obj); } catch (IgniteCheckedException | HibernateException e) { rollback(ses, tx); throw new CacheWriterException("Failed to remove value from cache store with key: " + key, e); } finally { end(ses, tx); } }
Example #30
Source File: CacheWriterTest.java From blazingcache with Apache License 2.0 | 4 votes |
@Override public void write(Cache.Entry<? extends String, ? extends String> entry) throws CacheWriterException { database.put(entry.getKey(), entry.getValue()); }