]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/StatementImpl.java
DB-client fixes
[simantics/platform.git] / bundles / org.simantics.db.procore / src / fi / vtt / simantics / procore / internal / StatementImpl.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package fi.vtt.simantics.procore.internal;\r
13 \r
14 import org.simantics.db.Resource;\r
15 import org.simantics.db.Statement;\r
16 import org.simantics.db.impl.ResourceImpl;\r
17 import org.simantics.db.procore.protocol.Constants;\r
18 \r
19 \r
20 public abstract class StatementImpl implements Statement {\r
21     public final static StatementImpl[] NONE = new StatementImpl[0];\r
22     public final ResourceImpl subject;\r
23     public final ResourceImpl predicate;\r
24     protected ResourceImpl object;\r
25     public StatementImpl(ResourceImpl subject, ResourceImpl predicate) {\r
26         if (null == subject)\r
27             throw new IllegalArgumentException();\r
28         if(null == predicate)\r
29             throw new IllegalArgumentException();\r
30         this.subject = (ResourceImpl)subject;\r
31         this.predicate = (ResourceImpl)predicate;\r
32     }\r
33     \r
34     public ResourceImpl getObjectImpl() {\r
35         return object;\r
36     }\r
37     @Override\r
38     public Resource getObject() {\r
39         return object;\r
40     }\r
41 \r
42     @Override\r
43     final public Resource getPredicate() {\r
44         return predicate;\r
45     }\r
46 \r
47     @Override\r
48     final public Resource getSubject() {\r
49         return subject;\r
50     }\r
51 \r
52     @Override\r
53     public boolean isAsserted(Resource testSubject) {\r
54         return !subject.equals(testSubject);\r
55     }\r
56     \r
57     public abstract boolean equals(long s, long p, long o);\r
58     \r
59   }\r
60 \r
61 final class StatementImplOld extends StatementImpl {\r
62     \r
63     public StatementImplOld(ResourceImpl subject, ResourceImpl predicate, ResourceImpl object) {\r
64         super(subject, predicate);\r
65         this.object = (ResourceImpl)object;\r
66     }\r
67     @Override\r
68     public int hashCode() {\r
69         return subject.hashCode() + (int)object.id; \r
70     }\r
71 \r
72     @Override\r
73     public boolean equals(long s, long p, long o) {\r
74         return (subject.id == s) && (predicate.id == p) && (object.id == o);\r
75     }\r
76 \r
77     @Override\r
78     public boolean equals(Object obj) {\r
79         if (this == obj)\r
80             return true;\r
81         else if (!(obj instanceof StatementImpl))\r
82             return false;\r
83         StatementImpl r = (StatementImpl)obj;\r
84         return r.equals(subject.id, predicate.id, object.id);\r
85     }\r
86 }\r
87 \r
88 final class StatementImplNew extends StatementImpl {\r
89     public final long objectResourceId;\r
90     public final long objectClusterId;\r
91     public final GraphSession graphSession;\r
92     public StatementImplNew(ResourceImpl subject, ResourceImpl predicate, long id, long cluster, GraphSession graphSession) {\r
93         super(subject, predicate);\r
94         this.object = null;\r
95         this.objectResourceId = id;\r
96         if (Constants.ReservedClusterId == cluster)\r
97             throw new IllegalArgumentException("Argh!");\r
98         this.objectClusterId = cluster;\r
99         this.graphSession = graphSession;\r
100     }\r
101 \r
102     @Override\r
103     final public Resource getObject() {\r
104 //        if (null == object)\r
105 //            try {\r
106 //                object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);\r
107 //            } catch (ResourceNotFoundException e) {\r
108 //                e.printStackTrace();\r
109 //                return null;\r
110 //            }\r
111 //        return object;\r
112         throw new Error("No can do.");\r
113     }\r
114 \r
115     @Override\r
116     public ResourceImpl getObjectImpl() {\r
117 //        if (null == object)\r
118 //            try {\r
119 //                object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);\r
120 //            } catch (ResourceNotFoundException e) {\r
121 //                e.printStackTrace();\r
122 //                return null;\r
123 //            }\r
124 //        return object;\r
125         throw new Error("No can do.");\r
126     }\r
127 \r
128     @Override\r
129     public int hashCode() {\r
130         return subject.hashCode() + (int)objectResourceId; \r
131     }\r
132 \r
133     @Override\r
134     public boolean equals(long s, long p, long o) {\r
135         return (subject.id == s) && (predicate.id == p) && (objectResourceId == o);\r
136     }\r
137 \r
138     @Override\r
139     public boolean equals(Object obj) {\r
140         if (this == obj)\r
141             return true;\r
142         else if (obj == null)\r
143             return false;\r
144         else if (StatementImpl.class != obj.getClass())\r
145             return false;\r
146         StatementImpl r = (StatementImpl)obj;\r
147         return r.equals(subject.id, predicate.id, objectResourceId);\r
148     }\r
149 }\r