/** * @param cacheName Cache name. * @param typeId Type id. * @return Entry mapping. * @throws CacheException If mapping for key was not found. */ private EntryMapping entryMapping(String cacheName, Object typeId) throws CacheException { Map<Object, EntryMapping> mappings = getOrCreateCacheMappings(cacheName); EntryMapping em = mappings.get(typeId); if (em == null) { String maskedCacheName = U.maskName(cacheName); throw new CacheException("Failed to find mapping description [cache=" + maskedCacheName + ", typeId=" + typeId + "]. Please configure JdbcType to associate cache '" + maskedCacheName + "' with JdbcPojoStore."); } return em; }
/** {@inheritDoc} */ @Override public Map<K, V> loadAll(Iterable<? extends K> keys) throws CacheLoaderException { assert keys != null; Connection conn = null; try { conn = connection(); String cacheName = session().cacheName(); Map<Object, LoadWorker<K, V>> workers = U.newHashMap(getOrCreateCacheMappings(cacheName).size()); Map<K, V> res = new HashMap<>(); for (K key : keys) { Object keyTypeId = typeIdForObject(key); EntryMapping em = entryMapping(cacheName, keyTypeId); LoadWorker<K, V> worker = workers.get(keyTypeId); if (worker == null) workers.put(keyTypeId, worker = new LoadWorker<>(conn, em)); worker.keys.add(key); if (worker.keys.size() == em.maxKeysPerStmt) res.putAll(workers.remove(keyTypeId).call()); } for (LoadWorker<K, V> worker : workers.values()) res.putAll(worker.call()); return res; } catch (Exception e) { throw new CacheWriterException("Failed to load entries from database", e); } finally { closeConnection(conn); } }
Map<Object, EntryMapping> mappings = getOrCreateCacheMappings(cacheName);
/** * @param cacheName Cache name. * @param typeId Type id. * @return Entry mapping. * @throws CacheException If mapping for key was not found. */ private EntryMapping entryMapping(String cacheName, Object typeId) throws CacheException { Map<Object, EntryMapping> mappings = getOrCreateCacheMappings(cacheName); EntryMapping em = mappings.get(typeId); if (em == null) { String maskedCacheName = U.maskName(cacheName); throw new CacheException("Failed to find mapping description [cache=" + maskedCacheName + ", typeId=" + typeId + "]. Please configure JdbcType to associate cache '" + maskedCacheName + "' with JdbcPojoStore."); } return em; }
/** {@inheritDoc} */ @Override public Map<K, V> loadAll(Iterable<? extends K> keys) throws CacheLoaderException { assert keys != null; Connection conn = null; try { conn = connection(); String cacheName = session().cacheName(); Map<Object, LoadWorker<K, V>> workers = U.newHashMap(getOrCreateCacheMappings(cacheName).size()); Map<K, V> res = new HashMap<>(); for (K key : keys) { Object keyTypeId = typeIdForObject(key); EntryMapping em = entryMapping(cacheName, keyTypeId); LoadWorker<K, V> worker = workers.get(keyTypeId); if (worker == null) workers.put(keyTypeId, worker = new LoadWorker<>(conn, em)); worker.keys.add(key); if (worker.keys.size() == em.maxKeysPerStmt) res.putAll(workers.remove(keyTypeId).call()); } for (LoadWorker<K, V> worker : workers.values()) res.putAll(worker.call()); return res; } catch (Exception e) { throw new CacheWriterException("Failed to load entries from database", e); } finally { closeConnection(conn); } }
Map<Object, EntryMapping> mappings = getOrCreateCacheMappings(cacheName);