From 78a3caea21bdd5475007b958d59b23b1d3deccfb Mon Sep 17 00:00:00 2001 From: Gerwin Gsenger Date: Fri, 30 Jan 2015 12:27:45 +0100 Subject: small DAO code review from Thomas --- .../process/dao/ProcessInstanceStoreDAOImpl.java | 50 ++++++++++++---------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'id/server/idserverlib/src/main/java/at') diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java index f5fb71145..4b7468013 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/process/dao/ProcessInstanceStoreDAOImpl.java @@ -46,24 +46,26 @@ public class ProcessInstanceStoreDAOImpl implements ProcessInstanceStoreDAO { ProcessInstanceStore result = null; Transaction tx = null; - try { - synchronized (session) { + synchronized (session) { + try { + tx = session.beginTransaction(); // select all where processInstanceId equals processInstanceId Criteria criteria = session.createCriteria(ProcessInstanceStore.class); criteria.add(Restrictions.eq("processInstanceId", processInstanceId)); result = (ProcessInstanceStore) criteria.uniqueResult(); tx.commit(); + + } catch (Exception e) { + log.error("There are multiple persisted processes with the same process instance id '{}'", + processInstanceId); + if (tx != null) { + tx.rollback(); + } + throw e; + } finally { + MOASessionDBUtils.closeSession(); } - } catch (Exception e) { - log.error("There are multiple persisted processes with the same process instance id '{}'", - processInstanceId); - if (tx != null) { - tx.rollback(); - } - throw e; - } finally { - MOASessionDBUtils.closeSession(); } return result; } @@ -74,8 +76,8 @@ public class ProcessInstanceStoreDAOImpl implements ProcessInstanceStoreDAO { log.debug("Delete the ProcessInstanceStore for id='{}' from the database.", processInstanceId); ProcessInstanceStore toBeDeleted = load(processInstanceId); - boolean result = MOASessionDBUtils.delete(toBeDeleted); - if (result == false) { + boolean deleted = MOASessionDBUtils.delete(toBeDeleted); + if (!deleted) { log.warn("Could not delete the ProcessInstanceStore with process instance id '{}'", processInstanceId); throw new MOADatabaseException("Could not delete the ProcessInstanceStore with process instance id '" + processInstanceId + "'."); @@ -90,21 +92,23 @@ public class ProcessInstanceStoreDAOImpl implements ProcessInstanceStoreDAO { List result = Collections.emptyList(); Transaction tx = null; - try { - synchronized (session) { + synchronized (session) { + try { + tx = session.beginTransaction(); // select all result = session.createCriteria(ProcessInstanceStore.class).list(); tx.commit(); + + } catch (Exception e) { + log.error("A problem occured while retrieving all stored ProcessInstanceStores."); + if (tx != null) { + tx.rollback(); + } + throw e; + } finally { + MOASessionDBUtils.closeSession(); } - } catch (Exception e) { - log.error("A problem occured while retrieving all stored ProcessInstanceStores."); - if (tx != null) { - tx.rollback(); - } - throw e; - } finally { - MOASessionDBUtils.closeSession(); } return result; } -- cgit v1.2.3