@Test public void testUncacheEntity() throws SQLException { HibernateDBConnection dbConnection = (HibernateDBConnection) context.getDBConnection(); EPerson person = context.getCurrentUser(); assertTrue("Current user should be cached in session", dbConnection.getSession() .contains(person)); dbConnection.uncacheEntity(person); assertFalse("Current user should be gone from cache", dbConnection.getSession() .contains(person)); person = dbConnection.reloadEntity(person); assertTrue("Current user should be cached back in session", dbConnection.getSession() .contains(person)); }
@Override public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException { if (entity != null) { if (entity instanceof DSpaceObject) { DSpaceObject dso = (DSpaceObject) entity; if (Hibernate.isInitialized(dso.getHandles())) { for (Handle handle : Utils.emptyIfNull(dso.getHandles())) { uncacheEntity(handle); } } if (Hibernate.isInitialized(dso.getResourcePolicies())) { for (ResourcePolicy policy : Utils.emptyIfNull(dso.getResourcePolicies())) { uncacheEntity(policy); } } } if (entity instanceof Item) { Item item = (Item) entity; if (Hibernate.isInitialized(item.getBundles())) { for (Bundle bundle : Utils.emptyIfNull(item.getBundles())) { uncacheEntity(bundle); } } } else if (entity instanceof Bundle) { Bundle bundle = (Bundle) entity; if (Hibernate.isInitialized(bundle.getBitstreams())) { for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) { uncacheEntity(bitstream); } } } else if (entity instanceof Community) { Community community = (Community) entity; if (Hibernate.isInitialized(community.getLogo())) { uncacheEntity(community.getLogo()); } } else if (entity instanceof Collection) { Collection collection = (Collection) entity; if (Hibernate.isInitialized(collection.getLogo())) { uncacheEntity(collection.getLogo()); } if (Hibernate.isInitialized(collection.getTemplateItem())) { uncacheEntity(collection.getTemplateItem()); } } if (getSession().contains(entity)) { if (!readOnlyEnabled && getSession().isDirty()) { getSession().flush(); } getSession().evict(entity); } } }
HibernateDBConnection implements DBConnection<Session> { @Override public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException { if (entity != null) { if (entity instanceof DSpaceObject) { DSpaceObject dso = (DSpaceObject) entity; if (Hibernate.isInitialized(dso.getHandles())) { for (Handle handle : Utils.emptyIfNull(dso.getHandles())) { uncacheEntity(handle); } } if (Hibernate.isInitialized(dso.getResourcePolicies())) { for (ResourcePolicy policy : Utils.emptyIfNull(dso.getResourcePolicies())) { uncacheEntity(policy); } } } if (entity instanceof Item) { Item item = (Item) entity; if (Hibernate.isInitialized(item.getBundles())) { for (Bundle bundle : Utils.emptyIfNull(item.getBundles())) { uncacheEntity(bundle); } } } else if (entity instanceof Bundle) { Bundle bundle = (Bundle) entity; if (Hibernate.isInitialized(bundle.getBitstreams())) { for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) { uncacheEntity(bitstream); } } } else if (entity instanceof Community) { Community community = (Community) entity; if (Hibernate.isInitialized(community.getLogo())) { uncacheEntity(community.getLogo()); } } else if (entity instanceof Collection) { Collection collection = (Collection) entity; if (Hibernate.isInitialized(collection.getLogo())) { uncacheEntity(collection.getLogo()); } if (Hibernate.isInitialized(collection.getTemplateItem())) { uncacheEntity(collection.getTemplateItem()); } } if (getSession().contains(entity)) { if (!readOnlyEnabled && getSession().isDirty()) { getSession().flush(); } getSession().evict(entity); } } } }
HibernateDBConnection implements DBConnection<Session> { @Override public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException { if (entity != null) { if (entity instanceof DSpaceObject) { DSpaceObject dso = (DSpaceObject) entity; if (Hibernate.isInitialized(dso.getHandles())) { for (Handle handle : Utils.emptyIfNull(dso.getHandles())) { uncacheEntity(handle); } } if (Hibernate.isInitialized(dso.getResourcePolicies())) { for (ResourcePolicy policy : Utils.emptyIfNull(dso.getResourcePolicies())) { uncacheEntity(policy); } } } if (entity instanceof Item) { Item item = (Item) entity; if (Hibernate.isInitialized(item.getBundles())) { for (Bundle bundle : Utils.emptyIfNull(item.getBundles())) { uncacheEntity(bundle); } } } else if (entity instanceof Bundle) { Bundle bundle = (Bundle) entity; if (Hibernate.isInitialized(bundle.getBitstreams())) { for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) { uncacheEntity(bitstream); } } } else if (entity instanceof Community) { Community community = (Community) entity; if (Hibernate.isInitialized(community.getLogo())) { uncacheEntity(community.getLogo()); } } else if (entity instanceof Collection) { Collection collection = (Collection) entity; if (Hibernate.isInitialized(collection.getLogo())) { uncacheEntity(collection.getLogo()); } if (Hibernate.isInitialized(collection.getTemplateItem())) { uncacheEntity(collection.getTemplateItem()); } } if (getSession().contains(entity)) { if (!readOnlyEnabled && getSession().isDirty()) { getSession().flush(); } getSession().evict(entity); } } }  }
HibernateDBConnection implements DBConnection<Session> { @Override public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException { if (entity != null) { if (entity instanceof DSpaceObject) { DSpaceObject dso = (DSpaceObject) entity; if (Hibernate.isInitialized(dso.getHandles())) { for (Handle handle : Utils.emptyIfNull(dso.getHandles())) { uncacheEntity(handle); } } if (Hibernate.isInitialized(dso.getResourcePolicies())) { for (ResourcePolicy policy : Utils.emptyIfNull(dso.getResourcePolicies())) { uncacheEntity(policy); } } } if (entity instanceof Item) { Item item = (Item) entity; if (Hibernate.isInitialized(item.getBundles())) { for (Bundle bundle : Utils.emptyIfNull(item.getBundles())) { uncacheEntity(bundle); } } } else if (entity instanceof Bundle) { Bundle bundle = (Bundle) entity; if (Hibernate.isInitialized(bundle.getBitstreams())) { for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) { uncacheEntity(bitstream); } } } else if (entity instanceof Community) { Community community = (Community) entity; if (Hibernate.isInitialized(community.getLogo())) { uncacheEntity(community.getLogo()); } } else if (entity instanceof Collection) { Collection collection = (Collection) entity; if (Hibernate.isInitialized(collection.getLogo())) { uncacheEntity(collection.getLogo()); } if (Hibernate.isInitialized(collection.getTemplateItem())) { uncacheEntity(collection.getTemplateItem()); } } if (getSession().contains(entity)) { if (!readOnlyEnabled && getSession().isDirty()) { getSession().flush(); } getSession().evict(entity); } } }  @Override Session getSession(); @Override boolean isTransActionAlive(); @Override boolean isSessionAlive(); @Override void rollback(); @Override void closeDBConnection(); @Override void commit(); @Override synchronized void shutdown(); @Override String getType(); @Override DataSource getDataSource(); @Override DatabaseConfigVO getDatabaseConfig(); @Override long getCacheSize(); @Override @SuppressWarnings("unchecked") E reloadEntity(final E entity); @Override void setConnectionMode(final boolean batchOptimized, final boolean readOnlyOptimized); @Override boolean isOptimizedForBatchProcessing(); @Override void uncacheEntity(E entity); }
HibernateDBConnection implements DBConnection<Session> { @Override public <E extends ReloadableEntity> void uncacheEntity(E entity) throws SQLException { if (entity != null) { if (entity instanceof DSpaceObject) { DSpaceObject dso = (DSpaceObject) entity; if (Hibernate.isInitialized(dso.getHandles())) { for (Handle handle : Utils.emptyIfNull(dso.getHandles())) { uncacheEntity(handle); } } if (Hibernate.isInitialized(dso.getResourcePolicies())) { for (ResourcePolicy policy : Utils.emptyIfNull(dso.getResourcePolicies())) { uncacheEntity(policy); } } } if (entity instanceof Item) { Item item = (Item) entity; if (Hibernate.isInitialized(item.getBundles())) { for (Bundle bundle : Utils.emptyIfNull(item.getBundles())) { uncacheEntity(bundle); } } } else if (entity instanceof Bundle) { Bundle bundle = (Bundle) entity; if (Hibernate.isInitialized(bundle.getBitstreams())) { for (Bitstream bitstream : Utils.emptyIfNull(bundle.getBitstreams())) { uncacheEntity(bitstream); } } } else if (entity instanceof Community) { Community community = (Community) entity; if (Hibernate.isInitialized(community.getLogo())) { uncacheEntity(community.getLogo()); } } else if (entity instanceof Collection) { Collection collection = (Collection) entity; if (Hibernate.isInitialized(collection.getLogo())) { uncacheEntity(collection.getLogo()); } if (Hibernate.isInitialized(collection.getTemplateItem())) { uncacheEntity(collection.getTemplateItem()); } } if (getSession().contains(entity)) { if (!readOnlyEnabled && getSession().isDirty()) { getSession().flush(); } getSession().evict(entity); } } }  @Override Session getSession(); @Override boolean isTransActionAlive(); @Override boolean isSessionAlive(); @Override void rollback(); @Override void closeDBConnection(); @Override void commit(); @Override synchronized void shutdown(); @Override String getType(); @Override DataSource getDataSource(); @Override DatabaseConfigVO getDatabaseConfig(); @Override long getCacheSize(); @Override @SuppressWarnings("unchecked") E reloadEntity(final E entity); @Override void setConnectionMode(final boolean batchOptimized, final boolean readOnlyOptimized); @Override boolean isOptimizedForBatchProcessing(); @Override void uncacheEntity(E entity);  }