ItEr15S04ArquitecturaServidorItEr14S04: Refactoring to use @Repository in DAOs and @Service in services and models.
The source code has been refactorized to use @Repository in DAOs and @Service in services and models. This way, DAOs, services and models do not need to be defined in the Spring configuration file.
This commit is contained in:
parent
e5e506c3c2
commit
a369e294a3
11 changed files with 44 additions and 29 deletions
|
|
@ -10,14 +10,15 @@ import org.navalplanner.business.orders.entities.Order;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link IOrderService} <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@Component
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
@Transactional
|
||||
public class OrderService implements IOrderService {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,19 @@ import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
|||
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.navalplanner.business.resources.daos.ICriterionDAO;
|
||||
import org.navalplanner.business.resources.entities.Criterion;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* DAO implementation for Criterion. <br />
|
||||
*
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Diego Pino García <dpino@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class CriterionDAO extends GenericDaoHibernate<Criterion, Long>
|
||||
implements ICriterionDAO {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,17 @@ package org.navalplanner.business.resources.daos.impl;
|
|||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
import org.navalplanner.business.resources.daos.ICriterionSatisfactionDAO;
|
||||
import org.navalplanner.business.resources.entities.CriterionSatisfaction;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Implementation <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class CriterionSatisfactionDAO extends
|
||||
GenericDaoHibernate<CriterionSatisfaction, Long> implements
|
||||
ICriterionSatisfactionDAO {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package org.navalplanner.business.resources.daos.impl;
|
|||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
import org.navalplanner.business.resources.daos.IResourceDao;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Hibernate DAO for the <code>Resource</code> entity.
|
||||
|
|
@ -10,5 +13,7 @@ import org.navalplanner.business.resources.entities.Resource;
|
|||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class ResourceDaoHibernate extends GenericDaoHibernate<Resource, Long>
|
||||
implements IResourceDao {}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package org.navalplanner.business.resources.daos.impl;
|
|||
import org.navalplanner.business.common.daos.impl.GenericDaoHibernate;
|
||||
import org.navalplanner.business.resources.daos.IWorkerDao;
|
||||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* Hibernate DAO for the <code>Worker</code> entity.
|
||||
|
|
@ -10,5 +13,7 @@ import org.navalplanner.business.resources.entities.Worker;
|
|||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class WorkerDaoHibernate extends GenericDaoHibernate<Worker, Long>
|
||||
implements IWorkerDao {}
|
||||
|
|
|
|||
|
|
@ -22,13 +22,19 @@ import org.navalplanner.business.resources.entities.Resource;
|
|||
import org.navalplanner.business.resources.services.CriterionService;
|
||||
import org.navalplanner.business.resources.services.ResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Implementation of {@link CriterionService} using {@link CriterionDAO} <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
@Transactional
|
||||
public class CriterionServiceImpl implements CriterionService {
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ import org.navalplanner.business.resources.entities.Resource;
|
|||
import org.navalplanner.business.resources.entities.Worker;
|
||||
import org.navalplanner.business.resources.services.ResourceService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -20,6 +23,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* autowired.
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
@Transactional
|
||||
public class ResourceServiceImpl implements ResourceService {
|
||||
|
||||
|
|
|
|||
|
|
@ -49,30 +49,11 @@
|
|||
|
||||
<context:component-scan base-package="org.navalplanner.business"/>
|
||||
|
||||
<!--
|
||||
======================== Business Objects ========================
|
||||
-->
|
||||
|
||||
<!-- Resource DAOs and registry -->
|
||||
<bean id="resourceDao"
|
||||
class="org.navalplanner.business.resources.daos.impl.ResourceDaoHibernate" />
|
||||
|
||||
<bean id="workerDao"
|
||||
class="org.navalplanner.business.resources.daos.impl.WorkerDaoHibernate" />
|
||||
|
||||
<bean id="criterionDao"
|
||||
class="org.navalplanner.business.resources.daos.impl.CriterionDAO" />
|
||||
|
||||
<bean id="criterionSatisfactionDao"
|
||||
class="org.navalplanner.business.resources.daos.impl.CriterionSatisfactionDAO" />
|
||||
<!-- DAO registries (to be used from non-Spring managed objects
|
||||
(e.g. entities) -->
|
||||
|
||||
<bean id="resourcesDaoRegistry"
|
||||
class="org.navalplanner.business.resources.daos.ResourcesDaoRegistry"
|
||||
factory-method="getInstance" />
|
||||
|
||||
<!-- Service layer -->
|
||||
<bean id="resourceService"
|
||||
class="org.navalplanner.business.resources.services.impl.ResourceServiceImpl" />
|
||||
<bean id="criterionService" class="org.navalplanner.business.resources.services.impl.CriterionServiceImpl" />
|
||||
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ import org.navalplanner.business.resources.services.CriterionService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class OrderElementModel implements IOrderElementModel {
|
||||
|
||||
|
|
|
|||
|
|
@ -15,14 +15,14 @@ import org.navalplanner.business.orders.services.IOrderService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Model for UI operations related to {@link Order}. <br />
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
@Component
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class OrderModel implements IOrderModel {
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ import org.navalplanner.business.resources.services.ResourceService;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +36,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Fernando Bellas Permuy <fbellas@udc.es>
|
||||
*/
|
||||
@Component
|
||||
@Service
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class WorkerModel implements IWorkerModel {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue