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

SSDM-13575: Revert - Fetch parent/children using dao to pe

parent 0c377526
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.shared.dto;
import java.io.Serializable;
......@@ -21,6 +22,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -42,12 +44,6 @@ import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import ch.systemsx.cisd.openbis.generic.server.CommonServiceProvider;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.ISampleDAO;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.SampleRelationshipDAO;
import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant;
import ch.systemsx.cisd.openbis.generic.shared.basic.IIdHolder;
import ch.systemsx.cisd.openbis.generic.shared.basic.IIdentityHolder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
......@@ -66,6 +62,9 @@ import ch.rinn.restrictions.Private;
import ch.systemsx.cisd.common.collection.UnmodifiableSetDecorator;
import ch.systemsx.cisd.common.reflection.ModifiedShortPrefixToStringStyle;
import ch.systemsx.cisd.openbis.generic.shared.IServer;
import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant;
import ch.systemsx.cisd.openbis.generic.shared.basic.IIdHolder;
import ch.systemsx.cisd.openbis.generic.shared.basic.IIdentityHolder;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.AttachmentHolderKind;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.IdentifierHelper;
import ch.systemsx.cisd.openbis.generic.shared.dto.identifier.SampleIdentifier;
......@@ -75,7 +74,7 @@ import ch.systemsx.cisd.openbis.generic.shared.util.HibernateUtils;
/**
* <i>Persistent Entity</i> object of an entity 'sample'.
*
*
* @author Christian Ribeaud
*/
......@@ -130,26 +129,28 @@ public class SamplePE extends AttachmentHolderPE implements IIdAndCodeHolder, Co
private String permId;
protected Set<SampleRelationshipPE> parentRelationships;
protected Set<SampleRelationshipPE> parentRelationships = new LinkedHashSet<SampleRelationshipPE>();
protected Set<SampleRelationshipPE> childRelationships;
protected Set<SampleRelationshipPE> childRelationships = new LinkedHashSet<SampleRelationshipPE>();
private Set<MetaprojectAssignmentPE> metaprojectAssignments =
new HashSet<MetaprojectAssignmentPE>();
@Transient
protected Set<SampleRelationshipPE> getSampleChildRelationships()
@OptimisticLock(excluded = true)
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parentSample")
@Fetch(FetchMode.SUBSELECT)
private Set<SampleRelationshipPE> getSampleChildRelationships()
{
if (childRelationships == null) {
if (id == null) {
childRelationships = new HashSet<>();
} else {
childRelationships = new HashSet<>(CommonServiceProvider.getDAOFactory().getSampleRelationshipDAO().listSampleChildren(List.of(id)));
}
}
return childRelationships;
}
// Required by Hibernate.
@SuppressWarnings("unused")
private void setSampleChildRelationships(final Set<SampleRelationshipPE> childRelationships)
{
this.childRelationships = childRelationships;
}
@Transient
public Set<SampleRelationshipPE> getChildRelationships()
{
......@@ -169,22 +170,23 @@ public class SamplePE extends AttachmentHolderPE implements IIdAndCodeHolder, Co
{
relationship.setParentSample(this);
getSampleChildRelationships().add(relationship);
CommonServiceProvider.getDAOFactory().getSampleRelationshipDAO().persist(List.of(relationship));
}
@Transient
protected Set<SampleRelationshipPE> getSampleParentRelationships()
@OptimisticLock(excluded = true)
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "childSample", orphanRemoval = true)
@Fetch(FetchMode.SUBSELECT)
private Set<SampleRelationshipPE> getSampleParentRelationships()
{
if (parentRelationships == null) {
if (id == null) {
parentRelationships = new HashSet<>();
} else {
parentRelationships = new HashSet<>(CommonServiceProvider.getDAOFactory().getSampleRelationshipDAO().listSampleParents(List.of(id)));
}
}
return parentRelationships;
}
// Required by Hibernate.
@SuppressWarnings("unused")
private void setSampleParentRelationships(final Set<SampleRelationshipPE> parentRelationships)
{
this.parentRelationships = parentRelationships;
}
@Transient
public Set<SampleRelationshipPE> getParentRelationships()
{
......@@ -202,7 +204,6 @@ public class SamplePE extends AttachmentHolderPE implements IIdAndCodeHolder, Co
public void setParentRelationships(final Set<SampleRelationshipPE> parentRelationships)
{
CommonServiceProvider.getDAOFactory().getSampleRelationshipDAO().delete(getSampleParentRelationships());
getSampleParentRelationships().clear();
for (final SampleRelationshipPE sampleRelationship : parentRelationships)
{
......@@ -219,7 +220,6 @@ public class SamplePE extends AttachmentHolderPE implements IIdAndCodeHolder, Co
{
relationship.setChildSample(this);
getSampleParentRelationships().add(relationship);
CommonServiceProvider.getDAOFactory().getSampleRelationshipDAO().persist(List.of(relationship));
}
public void removeParentRelationship(final SampleRelationshipPE relationship)
......@@ -228,7 +228,6 @@ public class SamplePE extends AttachmentHolderPE implements IIdAndCodeHolder, Co
relationship.getParentSample().getSampleChildRelationships().remove(relationship);
relationship.setChildSample(null);
relationship.setParentSample(null);
CommonServiceProvider.getDAOFactory().getSampleRelationshipDAO().delete(List.of(relationship));
}
/**
......
......@@ -29,33 +29,33 @@ import java.util.Set;
* This abstraction allows them to avoid using the introduced DAO behaving as naively as before introducing it.
*/
public class SamplePENoDAO extends SamplePE {
@Override
protected Set<SampleRelationshipPE> getSampleChildRelationships() {
if (childRelationships == null) {
childRelationships = new HashSet<>();
}
return childRelationships;
}
@Override
protected Set<SampleRelationshipPE> getSampleParentRelationships() {
if(parentRelationships == null) {
parentRelationships = new HashSet<>();
}
return parentRelationships;
}
@Override
public void addChildRelationship(final SampleRelationshipPE relationship)
{
relationship.setParentSample(this);
getSampleChildRelationships().add(relationship);
}
@Override
public void addParentRelationship(final SampleRelationshipPE relationship)
{
relationship.setChildSample(this);
getSampleParentRelationships().add(relationship);
}
// @Override
// protected Set<SampleRelationshipPE> getSampleChildRelationships() {
// if (childRelationships == null) {
// childRelationships = new HashSet<>();
// }
// return childRelationships;
// }
//
// @Override
// protected Set<SampleRelationshipPE> getSampleParentRelationships() {
// if(parentRelationships == null) {
// parentRelationships = new HashSet<>();
// }
// return parentRelationships;
// }
//
// @Override
// public void addChildRelationship(final SampleRelationshipPE relationship)
// {
// relationship.setParentSample(this);
// getSampleChildRelationships().add(relationship);
// }
//
// @Override
// public void addParentRelationship(final SampleRelationshipPE relationship)
// {
// relationship.setChildSample(this);
// getSampleParentRelationships().add(relationship);
// }
}
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