ItEr20S04ArquitecturaServidorItEr19S04: Erasing remove method on Resource instance. ResourcesDAORegistry no longer needed.

This commit is contained in:
Óscar González Fernández 2009-08-07 18:09:31 +02:00
parent 078009217b
commit fe5a957f50
4 changed files with 1 additions and 64 deletions

View file

@ -1,41 +0,0 @@
package org.navalplanner.business.resources.daos;
import org.springframework.beans.factory.annotation.Autowired;
// FIXME: Improve with
// http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom???
// (I think it is not necessary).
/**
* A registry of resource DAOs. Classes in which dependency injection (DI) is
* not directly supported by Spring (e.g. entities) must use this class to
* access resource DAOs. For the rest of classes (e.g. services, tests, etc.),
* Spring DI is a more convenient option.
* @author Fernando Bellas Permuy <fbellas@udc.es>
*/
public final class ResourcesDAORegistry {
private static ResourcesDAORegistry instance = new ResourcesDAORegistry();
@Autowired
private IResourceDAO resourceDao;
@Autowired
private IWorkerDAO workerDao;
private ResourcesDAORegistry() {
}
public static ResourcesDAORegistry getInstance() {
return instance;
}
public static IResourceDAO getResourceDao() {
return getInstance().resourceDao;
}
public static IWorkerDAO getWorkerDao() {
return getInstance().workerDao;
}
}

View file

@ -14,8 +14,6 @@ import java.util.Set;
import org.apache.commons.lang.Validate;
import org.navalplanner.business.common.BaseEntity;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
import org.navalplanner.business.resources.daos.ResourcesDAORegistry;
// FIXME: Alternatively, Resource can be modeled with the style:
// Resource.getParent() & Resource.getChilds(). This way, Resource does not
@ -172,21 +170,6 @@ public abstract class Resource extends BaseEntity {
public abstract int getDailyCapacity();
/**
* It removes the resource from the database and updates references. The
* default implementation removes the resource from the resource group it
* belongs to (if it belongs to someone) and from the database. This
* implementation should be valid for simple resources.
*/
public void remove() {
/* Remove from the database. */
try {
ResourcesDAORegistry.getResourceDao().remove(getId());
} catch (InstanceNotFoundException e) {
throw new RuntimeException(e);
}
}
public Set<CriterionSatisfaction> getAllSatisfactions() {
return new HashSet<CriterionSatisfaction>(criterionSatisfactions);
}

View file

@ -71,8 +71,7 @@ public class ResourceServiceImpl implements IResourceService {
public void removeResource(Long resourceId)
throws InstanceNotFoundException {
resourceDao.find(resourceId).remove();
resourceDao.remove(resourceId);
}
@Override

View file

@ -67,10 +67,6 @@
entities)
-->
<bean id="resourcesDaoRegistry"
class="org.navalplanner.business.resources.daos.ResourcesDAORegistry"
factory-method="getInstance" />
<bean id="plannerDaoRegistry"
class="org.navalplanner.business.planner.daos.PlannerDAORegistry"
factory-method="getInstance" />