1 package org.simantics.db.common.request;
3 import org.simantics.db.ReadGraph;
4 import org.simantics.db.Resource;
5 import org.simantics.db.exception.AdaptionException;
6 import org.simantics.db.exception.ServiceException;
7 import org.simantics.db.exception.ValidationException;
10 * @author Tuukka Lehtonen
12 * @param <T> the adaption target interface
14 public class Adapt<T> extends ResourceRead<T> {
16 final protected Class<T> target;
17 final protected boolean allowNull;
18 final protected boolean uniqueResult;
20 public Adapt(Resource resource, Class<T> target) {
21 this(resource, target, false, false);
24 public Adapt(Resource resource, Class<T> target, boolean allowNull) {
25 this(resource, target, allowNull, false);
28 public Adapt(Resource resource, Class<T> target, boolean allowNull, boolean uniqueResult) {
30 assert target != null;
32 this.allowNull = allowNull;
33 this.uniqueResult = uniqueResult;
37 public T perform(ReadGraph graph) throws AdaptionException, ValidationException, ServiceException {
40 return graph.getPossibleUniqueAdapter(resource, target);
41 return graph.getPossibleAdapter(resource, target);
44 return graph.adaptUnique(resource, target);
45 return graph.adapt(resource, target);
49 public int hashCode() {
51 int result = super.hashCode();
52 result = prime * result + (allowNull ? 1231 : 1237);
53 result = prime * result + (target.hashCode());
54 result = prime * result + (uniqueResult ? 1303 : 1319);
59 public boolean equals(Object obj) {
64 if (getClass() != obj.getClass())
66 Adapt<?> other = (Adapt<?>) obj;
67 if (!resource.equals(other.resource))
69 if (allowNull != other.allowNull)
71 if (!target.equals(other.target))
73 if (uniqueResult != other.uniqueResult)