package at.gv.egovernment.moa.id.process.dao; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException; import at.gv.egovernment.moa.id.storage.ITransactionStorage; /** * Database backed implementation of the {@link ProcessInstanceStoreDAO} * interface. */ @Service("ProcessInstanceStoreage") public class ProcessInstanceStoreDAOImpl implements ProcessInstanceStoreDAO { private Logger log = LoggerFactory.getLogger(getClass()); @Autowired ITransactionStorage transactionStorage; @Override public void saveOrUpdate(ProcessInstanceStore pIStore) throws MOADatabaseException { try { transactionStorage.put(pIStore.getProcessInstanceId(), pIStore); // MOASessionDBUtils.saveOrUpdate(pIStore); log.debug("Store process instance with='{}' in the database.", pIStore.getProcessInstanceId()); } catch (MOADatabaseException e) { log.warn("ProcessInstanceStore could not be persisted to the database."); throw e; } } @Override public ProcessInstanceStore load(String processInstanceId) throws MOADatabaseException { log.debug("Retrieve the ProcessInstanceStore for id='{}' from the database.", processInstanceId); // Session session = MOASessionDBUtils.getCurrentSession(); // ProcessInstanceStore result = null; // Transaction tx = null; // synchronized (session) { try { result = transactionStorage.get(processInstanceId, ProcessInstanceStore.class); // 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(); } // } if (result != null) { log.debug("Found process instance store for instance '{}'.", processInstanceId); } else { log.debug("Unable to find process instance store for instance '{}'.", processInstanceId); } return result; } @Override public void remove(String processInstanceId) throws MOADatabaseException { log.debug("Delete the ProcessInstanceStore for id='{}' from the database.", processInstanceId); //ProcessInstanceStore toBeDeleted = load(processInstanceId); if (transactionStorage.containsKey(processInstanceId)) { transactionStorage.remove(processInstanceId); // if (!MOASessionDBUtils.delete(toBeDeleted)) { // 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 + "'."); // } } else log.trace("ProcessInstanceStore for id='{}' was not found and could therefore not be deleted.", processInstanceId); } }