@Override public void removeFromCache(final Collection<T> cacheables) throws IllegalAccessException, InvocationTargetException { for (final T cacheable : cacheables) { removeFromCache(cacheable); } }
/** * Fills the cache with the listed cacheables * * @param cacheables list of cacheables */ @Override public void fillCache(final List<T> cacheables) throws IllegalAccessException, InvocationTargetException { for (final T cacheable : cacheables) { fillCache(cacheable); } }
@Test public void testProduce01Test() throws Exception { Assert.assertNotNull(cache); final CachedClass cachedClass = new CachedClass(); cachedClass.setTxt("001"); cachedClass.setValue(1L); cache.fillCache(cachedClass); final Collection forKey = cache.findForKey("txt", "001"); Assert.assertNotNull(forKey); Assert.assertFalse(forKey.isEmpty()); for (final Object o : forKey) { Assert.assertEquals(cachedClass, o); } } }
@Cacheable(className = CachedClass.class, primaryKeyAttributeName = "txt") public class CachedClass {
public Collection<C> findForKey(final T value) { return cache.findForKey(attributeName, value); }
public Collection<T> toReferents() { expungeStaleEntries(); final Set<T> result = new HashSet<>(); for (final GcReference<T> ref : set) { final T referent = ref.get(); if (referent != null) { result.add(referent); } } return result; }
@Override public int hashCode() { final T referent = get(); return referent == null ? 0 : referent.hashCode(); }
@Override public int hashCode() { final T referent = get(); return referent == null ? 0 : referent.hashCode(); }
public void remove(final T toRemove) { final GcReference<T> ref = createReference(toRemove); set.remove(ref); }
@Override public Collection<T> findForKey(final String attributeName, final Object key) { final Index<T> index = attribName2Index.get(attributeName); return index == null ? new ArrayList<T>() : index.get(key); }
@Override public <C> CacheFinder<T, C> createCacheFinder(final String attributeName) { assert attributeName != null : "attributeName must not be null"; return new CacheFinder<>(this, attributeName); }
public Collection<C> findForKeys(final Collection<T> values) { return cache.findForKeys(attributeName, values); } }
@Override public Collection<T> getAllFromCache() { if (primaryKeyAttributeName == null) { return Collections.emptyList(); } final Index<T> index = attribName2Index.get(primaryKeyAttributeName); return index.getAllValues(); }
@Override public void removeFromCache(final T cacheable2Remove) throws IllegalAccessException, InvocationTargetException { for (final Map.Entry<String, Method> entry : attribName2Method.entrySet()) { final String attrName = entry.getKey(); final Method readMethod = entry.getValue(); final Object key = readMethod.invoke(cacheable2Remove); final Index<T> index = attribName2Index.get(attrName); index.remove(key, cacheable2Remove); } }
@Named @Cacheable(primaryKeyAttributeName = "version", className = DemoClassA.class) @CDITransactionScope public class DemoClassA { private String version = System.nanoTime() + ""; public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } @Override public String toString() { final StringBuilder sb = new StringBuilder("DemoClassA{"); sb.append("version='").append(version).append('\''); sb.append('}'); return sb.toString(); } }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final GcWeakRef<T> ref = (GcWeakRef<T>) o; final T referent = get(); final T otherReferent = ref.get(); return (referent == null && otherReferent == null) || referent.equals(otherReferent); } }
@Override public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final GcSoftRef<T> ref = (GcSoftRef<T>) o; final T referent = get(); final T otherReferent = ref.get(); return (referent == null && otherReferent == null) || referent.equals(otherReferent); } }
public void add(final T object) { set.add(createReference(object)); }
@Override public Collection<T> findForKeys(final String attributeName, final Collection<? extends Object> keys) { final Index<T> index = attribName2Index.get(attributeName); if (index == null) { return Collections.emptyList(); } final Set<T> result = new HashSet<>(); for (final Object key : keys) { result.addAll(index.get(key)); } return result; }