Search in sources :

Example 1 with ProgressHandler

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

the class LongBranchAction method execute.

@Override
public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        action.setDatabaseSession(session);
        session.executeAndCommitAction(action, new ProgressHandler() {

            private int count;

            @Override
            public void progress(int current, int max) {
                if (count == 0) {
                    updateProgress("Storing data...", current * 100 / max);
                } else {
                    updateProgress("Storing data (" + (count + 1) + ")...", 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();
        done();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, "Done", 100);
        }
    }
}
Also used : DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Example 2 with ProgressHandler

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

the class LongCheckinAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        checkinDatabaseAction.setDatabaseSession(session);
        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 : DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException)

Example 3 with ProgressHandler

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

the class LongGenericAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        action.setDatabaseSession(session);
        session.executeAndCommitAction(action, 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;
            }
        }, new RollbackListener() {

            @Override
            public void rollback() {
                try {
                    action.rollback();
                } catch (BimserverDatabaseException e) {
                    LOGGER.error("", e);
                }
            }
        });
    } catch (Exception e) {
        if (e instanceof UserException) {
        } else if (e instanceof BimserverConcurrentModificationDatabaseException) {
        // Ignore
        } else {
            LOGGER.error("", e);
        }
        error(e);
    } finally {
        try {
            action.close();
        } catch (Exception e) {
            LOGGER.error("", e);
        }
        session.close();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, action.doneMessage(), 100);
        }
        done();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) RollbackListener(org.bimserver.database.RollbackListener) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Example 4 with ProgressHandler

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

the class LongStreamingCheckinAction method execute.

public void execute() {
    DatabaseSession session = getBimServer().getDatabase().createSession();
    try {
        checkinDatabaseAction.setDatabaseSession(session);
        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;
            }
        }, new RollbackListener() {

            @Override
            public void rollback() {
                try {
                    checkinDatabaseAction.rollback();
                } catch (BimserverDatabaseException e) {
                    LOGGER.error("", e);
                }
            }
        });
    } catch (Exception e) {
        if (e instanceof UserException) {
        } else if (e instanceof BimserverConcurrentModificationDatabaseException) {
        // Ignore
        } else {
            LOGGER.error("", e);
        }
        error(e);
    } finally {
        try {
            checkinDatabaseAction.close();
        } catch (IOException e) {
            LOGGER.error("", e);
        }
        session.close();
        if (getActionState() != ActionState.AS_ERROR) {
            changeActionState(ActionState.FINISHED, "Checkin of " + fileName, 100);
        }
        done();
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) DatabaseSession(org.bimserver.database.DatabaseSession) ProgressHandler(org.bimserver.database.ProgressHandler) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) RollbackListener(org.bimserver.database.RollbackListener) IOException(java.io.IOException) BimserverConcurrentModificationDatabaseException(org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException) UserException(org.bimserver.shared.exceptions.UserException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException)

Aggregations

DatabaseSession (org.bimserver.database.DatabaseSession)4 ProgressHandler (org.bimserver.database.ProgressHandler)4 BimserverConcurrentModificationDatabaseException (org.bimserver.database.berkeley.BimserverConcurrentModificationDatabaseException)4 UserException (org.bimserver.shared.exceptions.UserException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2 RollbackListener (org.bimserver.database.RollbackListener)2 IOException (java.io.IOException)1