@Test public void testCommit() throws SQLException, AuthorizeException, IOException { Context instance = new Context(); assertThat("HibernateDBConnection should exist", instance.getDBConnection(), notNullValue()); assertTrue("Context should be valid", instance.isValid()); assertTrue("Transaction should be open", instance.isTransactionAlive()); when(authorizeServiceSpy.isAdmin(instance)).thenReturn(true); String createdEmail = "myfakeemail@example.com"; EPerson newUser = ePersonService.create(instance); newUser.setFirstName(instance, "Tim"); newUser.setLastName(instance, "Smith"); newUser.setEmail(createdEmail); newUser.setCanLogIn(true); newUser.setLanguage(instance, I18nUtil.getDefaultLocale().getLanguage()); instance.commit(); assertThat("HibernateDBConnection should still be open", instance.getDBConnection(), notNullValue()); assertTrue("Context should still be valid", instance.isValid()); assertFalse("DB transaction should be closed", instance.isTransactionAlive()); newUser = instance.reloadEntity(newUser); assertEquals("New user should be created", newUser.getEmail(), createdEmail); String newEmail = "myrealemail@example.com"; newUser.setEmail(newEmail); instance.commit(); newUser = instance.reloadEntity(newUser); assertEquals("New email address should be saved", newUser.getEmail(), newEmail); ePersonService.delete(instance, newUser); cleanupContext(instance); }
public void commit() throws SQLException { if (!isValid()) { log.info("commit() was called on a closed Context object. No changes to commit."); return; } if (isReadOnly()) { throw new UnsupportedOperationException("You cannot commit a read-only context"); } try { dispatchEvents(); } finally { if (log.isDebugEnabled()) { log.debug("Cache size on commit is " + getCacheSize()); } if (dbConnection != null) { dbConnection.commit(); reloadContextBoundEntities(); } } }
Context implements AutoCloseable { public void commit() throws SQLException { if (!isValid()) { log.info("commit() was called on a closed Context object. No changes to commit."); return; } if (isReadOnly()) { throw new UnsupportedOperationException("You cannot commit a read-only context"); } try { dispatchEvents(); } finally { if (log.isDebugEnabled()) { log.debug("Cache size on commit is " + getCacheSize()); } if (dbConnection != null) { dbConnection.commit(); reloadContextBoundEntities(); } } } }
Context implements AutoCloseable { public void commit() throws SQLException { if (!isValid()) { log.info("commit() was called on a closed Context object. No changes to commit."); return; } if (isReadOnly()) { throw new UnsupportedOperationException("You cannot commit a read-only context"); } try { dispatchEvents(); } finally { if (log.isDebugEnabled()) { log.debug("Cache size on commit is " + getCacheSize()); } if (dbConnection != null) { dbConnection.commit(); reloadContextBoundEntities(); } } } protected  Context(EventService eventService, DBConnection dbConnection);  Context();  Context(Mode mode); }
Context implements AutoCloseable { public void commit() throws SQLException { if (!isValid()) { log.info("commit() was called on a closed Context object. No changes to commit."); return; } if (isReadOnly()) { throw new UnsupportedOperationException("You cannot commit a read-only context"); } try { dispatchEvents(); } finally { if (log.isDebugEnabled()) { log.debug("Cache size on commit is " + getCacheSize()); } if (dbConnection != null) { dbConnection.commit(); reloadContextBoundEntities(); } } } protected  Context(EventService eventService, DBConnection dbConnection);  Context();  Context(Mode mode); static synchronized boolean updateDatabase(); DatabaseConfigVO getDBConfig(); String getDbType(); void setCurrentUser(EPerson user); EPerson getCurrentUser(); Locale getCurrentLocale(); void setCurrentLocale(Locale locale); boolean ignoreAuthorization(); void turnOffAuthorisationSystem(); void restoreAuthSystemState(); void setExtraLogInfo(String info); String getExtraLogInfo(); void complete(); void commit(); void dispatchEvents(); void setDispatcher(String dispatcher); void addEvent(Event event); LinkedList<Event> getEvents(); boolean hasEvents(); Event pollEvent(); void abort(); @Override void close(); boolean isValid(); boolean isReadOnly(); void setSpecialGroup(UUID groupID); boolean inSpecialGroup(UUID groupID); List<Group> getSpecialGroups(); void switchContextUser(EPerson newUser); void restoreContextUser(); void shutDownDatabase(); long getCacheSize(); void setMode(Mode newMode); Mode getCurrentMode(); @Deprecated void enableBatchMode(boolean batchModeEnabled); @Deprecated boolean isBatchModeEnabled(); @SuppressWarnings("unchecked") E reloadEntity(E entity); @SuppressWarnings("unchecked") void uncacheEntity(E entity); Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson); void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result,
                                      ResourcePolicy rp); Boolean getCachedGroupMembership(Group group, EPerson eperson); void cacheGroupMembership(Group group, EPerson eperson, Boolean isMember); void cacheAllMemberGroupsSet(EPerson ePerson, Set<Group> groups); Set<Group> getCachedAllMemberGroupsSet(EPerson ePerson); }
Context implements AutoCloseable { public void commit() throws SQLException { if (!isValid()) { log.info("commit() was called on a closed Context object. No changes to commit."); return; } if (isReadOnly()) { throw new UnsupportedOperationException("You cannot commit a read-only context"); } try { dispatchEvents(); } finally { if (log.isDebugEnabled()) { log.debug("Cache size on commit is " + getCacheSize()); } if (dbConnection != null) { dbConnection.commit(); reloadContextBoundEntities(); } } } protected  Context(EventService eventService, DBConnection dbConnection);  Context();  Context(Mode mode); static synchronized boolean updateDatabase(); DatabaseConfigVO getDBConfig(); String getDbType(); void setCurrentUser(EPerson user); EPerson getCurrentUser(); Locale getCurrentLocale(); void setCurrentLocale(Locale locale); boolean ignoreAuthorization(); void turnOffAuthorisationSystem(); void restoreAuthSystemState(); void setExtraLogInfo(String info); String getExtraLogInfo(); void complete(); void commit(); void dispatchEvents(); void setDispatcher(String dispatcher); void addEvent(Event event); LinkedList<Event> getEvents(); boolean hasEvents(); Event pollEvent(); void abort(); @Override void close(); boolean isValid(); boolean isReadOnly(); void setSpecialGroup(UUID groupID); boolean inSpecialGroup(UUID groupID); List<Group> getSpecialGroups(); void switchContextUser(EPerson newUser); void restoreContextUser(); void shutDownDatabase(); long getCacheSize(); void setMode(Mode newMode); Mode getCurrentMode(); @Deprecated void enableBatchMode(boolean batchModeEnabled); @Deprecated boolean isBatchModeEnabled(); @SuppressWarnings("unchecked") E reloadEntity(E entity); @SuppressWarnings("unchecked") void uncacheEntity(E entity); Boolean getCachedAuthorizationResult(DSpaceObject dspaceObject, int action, EPerson eperson); void cacheAuthorizedAction(DSpaceObject dspaceObject, int action, EPerson eperson, Boolean result,
                                      ResourcePolicy rp); Boolean getCachedGroupMembership(Group group, EPerson eperson); void cacheGroupMembership(Group group, EPerson eperson, Boolean isMember); void cacheAllMemberGroupsSet(EPerson ePerson, Set<Group> groups); Set<Group> getCachedAllMemberGroupsSet(EPerson ePerson);  }