Skip to content
Snippets Groups Projects
Commit c0cf89ad authored by juanf's avatar juanf
Browse files

SSDM-13195 : Hibernate fixes, modifying PE layer to use DAO for parents/children

parent 5172b31f
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -97,7 +97,7 @@ public class AuthorizationDAOFactory implements IAuthorizationDAOFactory ...@@ -97,7 +97,7 @@ public class AuthorizationDAOFactory implements IAuthorizationDAOFactory
experimentDAO = new ExperimentDAO(persistencyResources, historyCreator); experimentDAO = new ExperimentDAO(persistencyResources, historyCreator);
projectDAO = new ProjectDAO(sessionFactory, historyCreator); projectDAO = new ProjectDAO(sessionFactory, historyCreator);
sampleDAO = new SampleDAO(persistencyResources, historyCreator); sampleDAO = new SampleDAO(persistencyResources, historyCreator);
sampleRelationshipDAO = new SampleRelationshipDAO(sessionFactory, relationshipTypeDAO, historyCreator); sampleRelationshipDAO = new SampleRelationshipDAO(sessionFactory, historyCreator);
gridCustomFilterDAO = new GridCustomFilterDAO(sessionFactory, historyCreator); gridCustomFilterDAO = new GridCustomFilterDAO(sessionFactory, historyCreator);
gridCustomColumnDAO = new GridCustomColumnDAO(sessionFactory, historyCreator); gridCustomColumnDAO = new GridCustomColumnDAO(sessionFactory, historyCreator);
queryDAO = new QueryDAO(sessionFactory, historyCreator); queryDAO = new QueryDAO(sessionFactory, historyCreator);
......
package ch.systemsx.cisd.openbis.generic.server.dataaccess.db; package ch.systemsx.cisd.openbis.generic.server.dataaccess.db;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.IRelationshipTypeDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.deletion.EntityHistoryCreator; import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.deletion.EntityHistoryCreator;
import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant;
import ch.systemsx.cisd.openbis.generic.shared.dto.ISampleRelationshipDAO; import ch.systemsx.cisd.openbis.generic.shared.dto.ISampleRelationshipDAO;
...@@ -15,15 +14,47 @@ import java.util.List; ...@@ -15,15 +14,47 @@ import java.util.List;
public class SampleRelationshipDAO extends AbstractGenericEntityDAO<SampleRelationshipPE> implements ISampleRelationshipDAO { public class SampleRelationshipDAO extends AbstractGenericEntityDAO<SampleRelationshipPE> implements ISampleRelationshipDAO {
private final IRelationshipTypeDAO relationshipTypeDAO; private Long parentChildRelationshipId = null;
protected SampleRelationshipDAO(SessionFactory sessionFactory, IRelationshipTypeDAO relationshipTypeDAO, EntityHistoryCreator historyCreator) { protected SampleRelationshipDAO(SessionFactory sessionFactory, EntityHistoryCreator historyCreator)
{
super(sessionFactory, SampleRelationshipPE.class, historyCreator); super(sessionFactory, SampleRelationshipPE.class, historyCreator);
this.relationshipTypeDAO = relationshipTypeDAO;
} }
public void persist(Collection<SampleRelationshipPE> sampleRelationships) { //
RelationshipTypePE relationshipType = relationshipTypeDAO.tryFindRelationshipTypeByCode(BasicConstant.PARENT_CHILD_INTERNAL_RELATIONSHIP); // Helper Methods to obtain relationship ID "fast" and using detached criteria that should not require a session
//
private Long getParentChildRelationshipId()
{
if (parentChildRelationshipId == null)
{
synchronized(SampleRelationshipDAO.class)
{
if (parentChildRelationshipId == null)
{
parentChildRelationshipId = getParentChildRelationship().getId();
}
}
}
return parentChildRelationshipId;
}
private RelationshipTypePE getParentChildRelationship()
{
final DetachedCriteria criteria = DetachedCriteria.forClass(RelationshipTypePE.class);
criteria.add(Restrictions.eq("code", BasicConstant.PARENT_CHILD_INTERNAL_RELATIONSHIP));
List<RelationshipTypePE> cast = cast(getHibernateTemplate().findByCriteria(criteria));
return cast.get(0);
}
//
// DAO Methods
//
public void persist(Collection<SampleRelationshipPE> sampleRelationships)
{
RelationshipTypePE relationshipType = getParentChildRelationship();
for (SampleRelationshipPE sampleRelationship : sampleRelationships) for (SampleRelationshipPE sampleRelationship : sampleRelationships)
{ {
sampleRelationship.setRelationship(relationshipType); sampleRelationship.setRelationship(relationshipType);
...@@ -31,22 +62,23 @@ public class SampleRelationshipDAO extends AbstractGenericEntityDAO<SampleRelati ...@@ -31,22 +62,23 @@ public class SampleRelationshipDAO extends AbstractGenericEntityDAO<SampleRelati
} }
} }
public void delete(Collection<SampleRelationshipPE> sampleRelationships) { public void delete(Collection<SampleRelationshipPE> sampleRelationships)
{
getHibernateTemplate().deleteAll(sampleRelationships); getHibernateTemplate().deleteAll(sampleRelationships);
} }
public List<SampleRelationshipPE> listSampleParents(List<Long> childrenTechIds) { public List<SampleRelationshipPE> listSampleParents(List<Long> childrenTechIds)
Long typeId = relationshipTypeDAO.getRelationshipTypeId(BasicConstant.PARENT_CHILD_INTERNAL_RELATIONSHIP); {
final DetachedCriteria criteria = DetachedCriteria.forClass(SampleRelationshipPE.class); final DetachedCriteria criteria = DetachedCriteria.forClass(SampleRelationshipPE.class);
criteria.add(Restrictions.eq("relationship.id", typeId)); criteria.add(Restrictions.eq("relationship.id", getParentChildRelationshipId()));
criteria.add(Restrictions.in("childSample.id", childrenTechIds)); criteria.add(Restrictions.in("childSample.id", childrenTechIds));
return cast(getHibernateTemplate().findByCriteria(criteria)); return cast(getHibernateTemplate().findByCriteria(criteria));
} }
public List<SampleRelationshipPE> listSampleChildren(List<Long> parentTechIds) { public List<SampleRelationshipPE> listSampleChildren(List<Long> parentTechIds)
Long typeId = relationshipTypeDAO.getRelationshipTypeId(BasicConstant.PARENT_CHILD_INTERNAL_RELATIONSHIP); {
final DetachedCriteria criteria = DetachedCriteria.forClass(SampleRelationshipPE.class); final DetachedCriteria criteria = DetachedCriteria.forClass(SampleRelationshipPE.class);
criteria.add(Restrictions.eq("relationship.id", typeId)); criteria.add(Restrictions.eq("relationship.id", getParentChildRelationshipId()));
criteria.add(Restrictions.in("parentSample.id", parentTechIds)); criteria.add(Restrictions.in("parentSample.id", parentTechIds));
return cast(getHibernateTemplate().findByCriteria(criteria)); return cast(getHibernateTemplate().findByCriteria(criteria));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment