@Override public boolean isLoaded(Object entity, String attributeName) { LoadState state = PersistenceUtilHelper.isLoadedWithoutReference(entity, attributeName, this.cache); if (state == LoadState.LOADED) { return true; } if (state == LoadState.NOT_LOADED) { return false; } return (PersistenceUtilHelper.isLoadedWithReference(entity, attributeName, this.cache) != LoadState.NOT_LOADED); }
@Override public boolean isLoaded(Object entity, String attributeName) { LoadState state = PersistenceUtilHelper.isLoadedWithoutReference(entity, attributeName, this.cache); if (state == LoadState.LOADED) { return true; } if (state == LoadState.NOT_LOADED) { return false; } return (PersistenceUtilHelper.isLoadedWithReference(entity, attributeName, this.cache) != LoadState.NOT_LOADED); }
/** * If the provider determines that the entity has been provided by itself * and that the state of the specified attribute has been loaded, this * method returns LoadState.LOADED. If a provider determines that the entity * has been provided by itself and that either the entity attributes with * FetchType EAGER have not been loaded or that the state of the specified * attribute has not been loaded, this method returns LoadState.NOT_LOADED. * If the provider cannot determine the load state, this method returns * LoadState.UNKNOWN. The provider's implementation of this method is * permitted to obtain a reference to the attribute value. (This access is * safe because providers which might trigger the loading of the attribute * state will have already been determined by isLoadedWithoutReference. ) * * @param entity * @param attributeName * name of attribute whose load status is to be determined * @return load status of the attribute */ @Override public LoadState isLoadedWithReference(Object paramObject, String paramString) { return PersistenceUtilHelper.isLoadedWithReference(paramObject, paramString, provider.getCache()); }
@Test public void testisLoadedWithReferenceAsNull() { LoadState state = PersistenceUtilHelper.isLoadedWithReference(null, null, cache); Assert.assertNotNull(state); Assert.assertEquals(LoadState.NOT_LOADED, state); }
@Test public void testisLoadedWithReferenceAsKunderaProxy() throws NoSuchMethodException, SecurityException { CglibLazyInitializerFactory factory = new CglibLazyInitializerFactory(); KunderaProxy proxy = factory.getProxy("Person", Person.class, Person.class.getDeclaredMethod("getPersonId", null), Person.class.getDeclaredMethod("setPersonId", String.class), "personId", null); LoadState state = PersistenceUtilHelper.isLoadedWithReference(proxy, "personId", cache); Assert.assertNotNull(state); Assert.assertEquals(LoadState.UNKNOWN, state); }
@Test public void testisLoadedWithReferenceAsLoaded() { Person p = new Person(); p.setPersonName("Vivek"); LoadState state = PersistenceUtilHelper.isLoadedWithReference(p, "personName", cache); Assert.assertNotNull(state); Assert.assertEquals(LoadState.UNKNOWN, state); }