use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheHibernatePersonStore method load.
/**
* {@inheritDoc}
*/
@Override
public Person load(Long key) {
System.out.println(">>> Store load [key=" + key + ']');
Session hibSes = ses.attachment();
try {
return (Person) hibSes.get(Person.class, key);
} catch (HibernateException e) {
throw new CacheLoaderException("Failed to load value from cache store [key=" + key + ']', e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheHibernatePersonStore method loadCache.
/**
* {@inheritDoc}
*/
@Override
public void loadCache(IgniteBiInClosure<Long, Person> clo, Object... args) {
if (args == null || args.length == 0 || args[0] == null)
throw new CacheLoaderException("Expected entry count parameter is not provided.");
final int entryCnt = (Integer) args[0];
Session hibSes = ses.attachment();
try {
int cnt = 0;
List list = hibSes.createCriteria(Person.class).setMaxResults(entryCnt).list();
if (list != null) {
for (Object obj : list) {
Person person = (Person) obj;
clo.apply(person.id, person);
cnt++;
}
}
System.out.println(">>> Loaded " + cnt + " values into cache.");
} catch (HibernateException e) {
throw new CacheLoaderException("Failed to load values from cache store.", e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheAbstractJdbcStore method load.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public V load(K key) throws CacheLoaderException {
assert key != null;
EntryMapping em = entryMapping(session().cacheName(), typeIdForObject(key));
if (log.isDebugEnabled())
log.debug("Load value from db [table= " + em.fullTableName() + ", key=" + key + ']');
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = connection();
stmt = conn.prepareStatement(em.loadQrySingle);
fillKeyParameters(stmt, em, key);
ResultSet rs = stmt.executeQuery();
if (rs.next())
return buildObject(em.cacheName, em.valueType(), em.valueKind(), em.valueColumns(), em.loadColIdxs, rs);
} catch (SQLException e) {
throw new CacheLoaderException("Failed to load object [table=" + em.fullTableName() + ", key=" + key + "]", e);
} finally {
end(conn, stmt);
}
return null;
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheJdbcPojoStore method extractPojoParameter.
/**
* Get field value from POJO for use as query parameter.
*
* @param cacheName Cache name.
* @param typeName Type name.
* @param fldName Field name.
* @param obj Cache object.
* @return Field value from object.
* @throws CacheException in case of error.
*/
@Nullable
private Object extractPojoParameter(@Nullable String cacheName, String typeName, String fldName, Object obj) throws CacheException {
try {
Map<String, PojoPropertiesCache> cacheProps = pojosProps.get(cacheName);
if (cacheProps == null)
throw new CacheException("Failed to find POJO type metadata for cache: " + U.maskName(cacheName));
PojoPropertiesCache ppc = cacheProps.get(typeName);
if (ppc == null)
throw new CacheException("Failed to find POJO type metadata for type: " + typeName);
ClassProperty prop = ppc.props.get(fldName);
if (prop == null)
throw new CacheLoaderException("Failed to find property in POJO class [class=" + typeName + ", prop=" + fldName + "]");
return prop.get(obj);
} catch (Exception e) {
throw new CacheException("Failed to read object property [cache=" + U.maskName(cacheName) + ", type=" + typeName + ", prop=" + fldName + "]", e);
}
}
use of javax.cache.integration.CacheLoaderException in project ignite by apache.
the class CacheStoreBalancingWrapper method loadAll.
/**
* @param keys Keys to load.
* @param c Closure for loaded values.
*/
public void loadAll(Collection<? extends K> keys, final IgniteBiInClosure<K, V> c) {
assert keys.size() <= loadAllThreshold : loadAllThreshold;
Collection<K> needLoad = null;
Map<K, LoadFuture> pending = null;
LoadFuture span = null;
for (K key : keys) {
LoadFuture fut = pendingLoads.get(key);
if (fut != null) {
if (pending == null)
pending = new HashMap<>();
pending.put(key, fut);
} else {
// Try to concurrently add pending future.
if (span == null)
span = new LoadFuture();
LoadFuture old = pendingLoads.putIfAbsent(key, span);
if (old != null) {
if (pending == null)
pending = new HashMap<>();
pending.put(key, old);
} else {
if (needLoad == null)
needLoad = new ArrayList<>(keys.size());
needLoad.add(key);
}
}
}
if (needLoad != null) {
assert !needLoad.isEmpty();
assert span != null;
try {
Map<K, V> loaded = delegate.loadAll(needLoad);
if (loaded != null) {
for (Map.Entry<K, V> e : loaded.entrySet()) c.apply(e.getKey(), e.getValue());
}
span.onComplete(needLoad, loaded);
} catch (Throwable e) {
span.onError(needLoad, e);
if (e instanceof Error)
throw e;
throw e;
}
}
if (pending != null) {
try {
for (Map.Entry<K, LoadFuture> e : pending.entrySet()) {
K key = e.getKey();
c.apply(key, e.getValue().get(key));
}
} catch (IgniteCheckedException e) {
throw new CacheLoaderException(e);
}
}
}
Aggregations