use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheJdbcPojoStore method buildPojoObject.
/**
* Construct POJO from query result.
*
* @param cacheName Cache name.
* @param typeName Type name.
* @param flds Fields descriptors.
* @param loadColIdxs Select query columns index.
* @param rs ResultSet.
* @return Constructed POJO.
* @throws CacheLoaderException If failed to construct POJO.
*/
private Object buildPojoObject(@Nullable String cacheName, String typeName, JdbcTypeField[] flds, Map<String, Integer> loadColIdxs, ResultSet rs) throws CacheLoaderException {
Map<String, PojoPropertiesCache> cacheProps = pojosProps.get(cacheName);
if (cacheProps == null)
throw new CacheLoaderException("Failed to find POJO types metadata for cache: " + U.maskName(cacheName));
PojoPropertiesCache ppc = cacheProps.get(typeName);
if (ppc == null)
throw new CacheLoaderException("Failed to find POJO type metadata for type: " + typeName);
try {
Object obj = ppc.ctor.newInstance();
for (JdbcTypeField fld : flds) {
String fldJavaName = fld.getJavaFieldName();
ClassProperty prop = ppc.props.get(fldJavaName);
if (prop == null)
throw new IllegalStateException("Failed to find property in POJO class [type=" + typeName + ", prop=" + fldJavaName + "]");
String dbName = fld.getDatabaseFieldName();
Integer colIdx = columnIndex(loadColIdxs, dbName);
try {
Object colVal = transformer.getColumnValue(rs, colIdx, fld.getJavaFieldType());
try {
prop.set(obj, colVal);
} catch (Exception e) {
throw new CacheLoaderException("Failed to set property in POJO class [type=" + typeName + ", colIdx=" + colIdx + ", prop=" + fld + ", dbValCls=" + colVal.getClass().getName() + ", dbVal=" + colVal + "]", e);
}
} catch (SQLException e) {
throw new CacheLoaderException("Failed to read object property [type=" + typeName + ", colIdx=" + colIdx + ", prop=" + fld + "]", e);
}
}
return obj;
} catch (Exception e) {
throw new CacheLoaderException("Failed to construct instance of class: " + typeName, e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class PlatformDotNetCacheStore method loadAll.
/**
* {@inheritDoc}
*/
@Override
public Map<K, V> loadAll(final Iterable<? extends K> keys) {
try {
final Map<K, V> loaded = new HashMap<>();
final Collection keys0 = (Collection) keys;
doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
@Override
public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD_ALL);
writer.writeLong(session());
writer.writeString(ses.cacheName());
writer.writeInt(keys0.size());
for (Object o : keys0) writer.writeObject(o);
}
}, new IgniteInClosureX<BinaryRawReaderEx>() {
@Override
public void applyx(BinaryRawReaderEx reader) {
int cnt = reader.readInt();
for (int i = 0; i < cnt; i++) loaded.put((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
}
});
return loaded;
} catch (IgniteCheckedException e) {
throw new CacheLoaderException(e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class PlatformDotNetCacheStore method load.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public V load(final K key) {
try {
final GridTuple<V> val = new GridTuple<>();
doInvoke(new IgniteInClosureX<BinaryRawWriterEx>() {
@Override
public void applyx(BinaryRawWriterEx writer) throws IgniteCheckedException {
writer.writeByte(OP_LOAD);
writer.writeLong(session());
writer.writeString(ses.cacheName());
writer.writeObject(key);
}
}, new IgniteInClosureX<BinaryRawReaderEx>() {
@Override
public void applyx(BinaryRawReaderEx reader) {
val.set((V) reader.readObjectDetached());
}
});
return val.get();
} catch (IgniteCheckedException e) {
throw new CacheLoaderException(e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheHibernateBlobStore method load.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "unchecked", "RedundantTypeArguments" })
@Override
public V load(K key) {
init();
Transaction tx = transaction();
if (log.isDebugEnabled())
log.debug("Store load [key=" + key + ", tx=" + tx + ']');
Session ses = session(tx);
try {
CacheHibernateBlobStoreEntry entry = ses.get(CacheHibernateBlobStoreEntry.class, toBytes(key));
if (entry == null)
return null;
return fromBytes(entry.getValue());
} catch (IgniteCheckedException | HibernateException e) {
rollback(ses, tx);
throw new CacheLoaderException("Failed to load value from cache store with key: " + key, e);
} finally {
end(ses, tx);
}
}
use of javax.cache.integration.CacheLoaderException in project caffeine by ben-manes.
the class CacheProxy method loadAll.
@Override
public void loadAll(Set<? extends K> keys, boolean replaceExistingValues, CompletionListener completionListener) {
requireNotClosed();
keys.forEach(Objects::requireNonNull);
CompletionListener listener = (completionListener == null) ? NullCompletionListener.INSTANCE : completionListener;
if (!cacheLoader.isPresent()) {
listener.onCompletion();
return;
}
executor.execute(() -> {
try {
if (replaceExistingValues) {
loadAllAndReplaceExisting(keys);
} else {
loadAllAndKeepExisting(keys);
}
listener.onCompletion();
} catch (CacheLoaderException e) {
listener.onException(e);
} catch (Exception e) {
listener.onException(new CacheLoaderException(e));
} finally {
dispatcher.ignoreSynchronous();
}
});
}
Aggregations