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));
}
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;
}
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;
}
Aggregations