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