Search in sources :

Example 1 with CleanupListener

use of org.bimserver.database.CleanupListener in project BIMserver by opensourceBIM.

the class LongCheckinAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
    try {
        checkinDatabaseAction.setDatabaseSession(session);
        session.setCleanupListener(new CleanupListener() {

            @Override
            public void cleanup() {
                try (DatabaseSession tmpSession = getBimServer().getDatabase().createSession(OperationType.READ_WRITE)) {
                    Project project = tmpSession.get(checkinDatabaseAction.getPoid(), OldQuery.getDefault());
                    project.setCheckinInProgress(0);
                    tmpSession.store(project);
                    try {
                        tmpSession.commit();
                    } catch (ServiceException e2) {
                        LOGGER.error("", e2);
                    }
                } catch (BimserverDatabaseException e1) {
                    LOGGER.error("", e1);
                }
            }
        });
        session.executeAndCommitAction(checkinDatabaseAction, new ProgressHandler() {

            private int count;

            @Override
            public void progress(int current, int max) {
                if (count == 0) {
                    updateProgress("Saving to database (" + fileName + ")", current * 100 / max);
                } else {
                    updateProgress("Saving to database (" + fileName + ", " + count + " try)", current * 100 / max);
                }
            }

            @Override
            public void retry(int count) {
                this.count = count;
            }
        });
    } catch (Exception e) {
        if (e instanceof UserException) {
        } else if (e instanceof BimserverConcurrentModificationDatabaseException) {
        // Ignore
        } else {
            LOGGER.error("", e);
        }
        error(e);
    } finally {
        session.close();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, "Checkin of " + fileName, 100);
        }
        done();
    }
}
Also used : Project(org.bimserver.models.store.Project) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) CleanupListener(org.bimserver.database.CleanupListener) ServiceException(org.bimserver.shared.exceptions.ServiceException) DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Aggregations

BimserverDatabaseException (org.bimserver.BimserverDatabaseException)1 CleanupListener (org.bimserver.database.CleanupListener)1 DatabaseSession (org.bimserver.database.DatabaseSession)1 ProgressHandler (org.bimserver.database.ProgressHandler)1 BimserverConcurrentModificationDatabaseException (org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException)1 Project (org.bimserver.models.store.Project)1 ServiceException (org.bimserver.shared.exceptions.ServiceException)1 UserException (org.bimserver.shared.exceptions.UserException)1