use of org.bimserver.database.RollbackListener in project BIMserver by opensourceBIM.
the class LongGenericAction method execute.
public void execute() {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
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();
}
}
use of org.bimserver.database.RollbackListener in project BIMserver by opensourceBIM.
the class LongStreamingCheckinAction method execute.
public void execute() {
DatabaseSession session = getBimServer().getDatabase().createSession(OperationType.POSSIBLY_WRITE);
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);
}
}
});
this.roid = checkinDatabaseAction.getRevision().getOid();
} catch (Exception e) {
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);
}
if (e instanceof UserException) {
if (e.getCause() instanceof DeserializeException) {
this.deserializerException = (DeserializeException) e.getCause();
}
} 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();
}
}
Aggregations