From 891c6f0b5ef531d35648969b807282c31a2bb336 Mon Sep 17 00:00:00 2001 From: rkv Date: Mon, 26 Nov 2012 08:42:46 +0000 Subject: [PATCH] SaveOrUpdate is introduced in DAO and is used for user creation. --- .../splat/dal/dao/kernel/AbstractGenericDAOImpl.java | 11 +++++++++++ .../src/org/splat/dal/dao/kernel/GenericDAO.java | 8 ++++++++ .../src/org/splat/service/UserServiceImpl.java | 4 ++-- .../src/test/splat/service/TestScenarioService.java | 4 ++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java index b1276d2..c30ed28 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/AbstractGenericDAOImpl.java @@ -47,6 +47,17 @@ public abstract class AbstractGenericDAOImpl extends return (PK) getSession().save(newInstance); } + /** + * Persist the newInstance object into database. + * + * @param newInstance + * new object as a transient instance + */ + @SuppressWarnings(UNCHECKED) + public void saveOrUpdate(final T newInstance) { + getSession().saveOrUpdate(newInstance); + } + /** * Retrieve an object that was previously persisted to the database using the indicated id as primary key. * diff --git a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java index 415ec25..fef4140 100644 --- a/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java +++ b/Workspace/Siman-Common/src/org/splat/dal/dao/kernel/GenericDAO.java @@ -37,6 +37,14 @@ public interface GenericDAO { */ PK create(T newInstance); + /** + * Persist the newInstance object into database. + * + * @param newInstance + * new object as a transient instance + */ + public void saveOrUpdate(final T newInstance); + /** * Retrieve an object that was previously persisted to the database using the indicated id as primary key. * diff --git a/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java b/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java index 5b7848f..6c67231 100644 --- a/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java +++ b/Workspace/Siman-Common/src/org/splat/service/UserServiceImpl.java @@ -72,9 +72,9 @@ public class UserServiceImpl implements UserService { // and to avoid th exception: // org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the // session: [org.splat.dal.bo.kernel.Role#simer] - getUserDAO().merge(nuser); + getUserDAO().saveOrUpdate(nuser); - getUserDAO().create(nuser); + //getUserDAO().create(nuser); return nuser; } diff --git a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java index 4be2632..39d000f 100644 --- a/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java +++ b/Workspace/Siman-Common/src/test/splat/service/TestScenarioService.java @@ -19,11 +19,11 @@ import java.util.List; import org.splat.dal.bo.kernel.User; import org.splat.dal.bo.som.Document; +import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.Publication; import org.splat.dal.bo.som.Scenario; import org.splat.dal.bo.som.Study; -import org.splat.dal.bo.som.Document.Properties; import org.splat.dal.dao.som.Database; import org.splat.dal.dao.som.ScenarioDAO; import org.splat.kernel.InvalidPropertyException; @@ -40,8 +40,8 @@ import org.splat.service.dto.DocumentDTO; import org.splat.service.dto.FileDTO; import org.splat.service.dto.StepDTO; import org.splat.service.technical.ProjectSettingsService; -import org.splat.service.technical.RepositoryService; import org.splat.service.technical.ProjectSettingsService.Step; +import org.splat.service.technical.RepositoryService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.orm.hibernate3.HibernateTemplate; -- 2.39.2