Search in sources :

Example 1 with HardCacheWeakIdentityMap

use of org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap in project eclipselink by eclipse-ee4j.

the class HardCacheWeakIdentityMapTest method test.

@Override
public void test() {
    // insert and store two employees in a predictable order
    UnitOfWork uow = getSession().acquireUnitOfWork();
    firstEmployee = new Employee();
    firstEmployee.setFirstName("Test0");
    firstEmployee.setLastName("Employee");
    uow.registerObject(firstEmployee);
    uow.commit();
    uow = getSession().acquireUnitOfWork();
    Employee secondEmployee = new Employee();
    secondEmployee.setFirstName("Test1");
    secondEmployee.setLastName("Employee");
    uow.registerObject(secondEmployee);
    uow.commit();
    // insert 9 more employees to fill the subcache
    for (int i = 2; i < (REFERENCE_CACHE_SIZE + 1); i++) {
        uow = getSession().acquireUnitOfWork();
        Employee employee = (Employee) uow.registerObject(new Employee());
        employee.setFirstName("Test" + i);
        employee.setLastName("Employee");
        uow.commit();
    }
    HardCacheWeakIdentityMap map = (HardCacheWeakIdentityMap) getAbstractSession().getIdentityMapAccessorInstance().getIdentityMap(Employee.class);
    referenceCacheSizeMaintained = (map.getReferenceCache().size() == REFERENCE_CACHE_SIZE);
    firstEmployeeDropped = !map.getReferenceCache().contains(firstEmployee);
    // query the first employee to put him back in the sub cache
    ReadObjectQuery query = new ReadObjectQuery();
    query.setReferenceClass(Employee.class);
    ExpressionBuilder employee = new ExpressionBuilder();
    Expression exp = employee.get("firstName").equal("Test0");
    query.setSelectionCriteria(exp);
    Employee queryResult = (Employee) getSession().executeQuery(query);
    referenceCacheSizeMaintained = (referenceCacheSizeMaintained && (map.getReferenceCache().size() == REFERENCE_CACHE_SIZE));
}
Also used : HardCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap)

Example 2 with HardCacheWeakIdentityMap

use of org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap in project eclipselink by eclipse-ee4j.

the class RuntimeServices method getNumberOfObjectsInIdentityMapSubCache.

/**
 * This method is used to return the number of objects in a particular Identity Map's
 * subcache.  Only works for those identity Maps with a sub cache (ie Hard Cache Weak Identity Map)
 * @param className the fully qualified name of the class to get number of instances of.
 * @exception ClassNotFoundException thrown then the IdentityMap for that class name could not be found
 */
public Integer getNumberOfObjectsInIdentityMapSubCache(String className) throws ClassNotFoundException {
    // This needs to use the Session's active class loader (not implemented yet)
    Integer result = 0;
    Class<?> classToChange = getSession().getDatasourcePlatform().getConversionManager().convertObject(className, ClassConstants.CLASS);
    IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(classToChange);
    if (map.getClass().isAssignableFrom(ClassConstants.HardCacheWeakIdentityMap_Class)) {
        List subCache = ((HardCacheWeakIdentityMap) map).getReferenceCache();
        result = subCache.size();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) HardCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap) WeakIdentityMap(org.eclipse.persistence.internal.identitymaps.WeakIdentityMap) SoftIdentityMap(org.eclipse.persistence.internal.identitymaps.SoftIdentityMap) FullIdentityMap(org.eclipse.persistence.internal.identitymaps.FullIdentityMap) HardCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap) NoIdentityMap(org.eclipse.persistence.internal.identitymaps.NoIdentityMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) SoftCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.SoftCacheWeakIdentityMap) CacheIdentityMap(org.eclipse.persistence.internal.identitymaps.CacheIdentityMap)

Example 3 with HardCacheWeakIdentityMap

use of org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap in project eclipselink by eclipse-ee4j.

the class RuntimeServices method getObjectsInIdentityMapSubCacheAsMap.

/**
 * This method is used to return a Map of the objects in a particular Identity Map's
 * subcache.  Only works for those identity Maps with a sub cache (ie Hard Cache Weak Identity Map)
 * This method replaces getObjectsInIdentityMapSubCache(className) which returns a list instead
 * of a Map
 * @param className the fully qualified name of the class to get number of instances of.
 * @exception ClassNotFoundException thrown then the IdentityMap for that class name could not be found
 */
public List getObjectsInIdentityMapSubCacheAsMap(String className) throws ClassNotFoundException {
    Class<?> classToChange = getSession().getDatasourcePlatform().getConversionManager().convertObject(className, ClassConstants.CLASS);
    IdentityMap map = getSession().getIdentityMapAccessorInstance().getIdentityMap(classToChange);
    // CR3855
    List subCache = new ArrayList(0);
    if (ClassConstants.HardCacheWeakIdentityMap_Class.isAssignableFrom(map.getClass())) {
        subCache = ((HardCacheWeakIdentityMap) map).getReferenceCache();
    }
    return subCache;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) WeakIdentityMap(org.eclipse.persistence.internal.identitymaps.WeakIdentityMap) SoftIdentityMap(org.eclipse.persistence.internal.identitymaps.SoftIdentityMap) FullIdentityMap(org.eclipse.persistence.internal.identitymaps.FullIdentityMap) HardCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap) NoIdentityMap(org.eclipse.persistence.internal.identitymaps.NoIdentityMap) IdentityMap(org.eclipse.persistence.internal.identitymaps.IdentityMap) SoftCacheWeakIdentityMap(org.eclipse.persistence.internal.identitymaps.SoftCacheWeakIdentityMap) CacheIdentityMap(org.eclipse.persistence.internal.identitymaps.CacheIdentityMap)

Aggregations

HardCacheWeakIdentityMap (org.eclipse.persistence.internal.identitymaps.HardCacheWeakIdentityMap)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CacheIdentityMap (org.eclipse.persistence.internal.identitymaps.CacheIdentityMap)2 FullIdentityMap (org.eclipse.persistence.internal.identitymaps.FullIdentityMap)2 IdentityMap (org.eclipse.persistence.internal.identitymaps.IdentityMap)2 NoIdentityMap (org.eclipse.persistence.internal.identitymaps.NoIdentityMap)2 SoftCacheWeakIdentityMap (org.eclipse.persistence.internal.identitymaps.SoftCacheWeakIdentityMap)2 SoftIdentityMap (org.eclipse.persistence.internal.identitymaps.SoftIdentityMap)2 WeakIdentityMap (org.eclipse.persistence.internal.identitymaps.WeakIdentityMap)2