1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package fi.vtt.simantics.procore.internal;
14 import org.simantics.db.Resource;
15 import org.simantics.db.Statement;
16 import org.simantics.db.impl.ResourceImpl;
17 import org.simantics.db.procore.protocol.Constants;
20 public abstract class StatementImpl implements Statement {
21 public final static StatementImpl[] NONE = new StatementImpl[0];
22 public final ResourceImpl subject;
23 public final ResourceImpl predicate;
24 protected ResourceImpl object;
25 public StatementImpl(ResourceImpl subject, ResourceImpl predicate) {
27 throw new IllegalArgumentException();
29 throw new IllegalArgumentException();
30 this.subject = (ResourceImpl)subject;
31 this.predicate = (ResourceImpl)predicate;
34 public ResourceImpl getObjectImpl() {
38 public Resource getObject() {
43 final public Resource getPredicate() {
48 final public Resource getSubject() {
53 public boolean isAsserted(Resource testSubject) {
54 return !subject.equals(testSubject);
57 public abstract boolean equals(long s, long p, long o);
61 final class StatementImplOld extends StatementImpl {
63 public StatementImplOld(ResourceImpl subject, ResourceImpl predicate, ResourceImpl object) {
64 super(subject, predicate);
65 this.object = (ResourceImpl)object;
68 public int hashCode() {
69 return subject.hashCode() + (int)object.id;
73 public boolean equals(long s, long p, long o) {
74 return (subject.id == s) && (predicate.id == p) && (object.id == o);
78 public boolean equals(Object obj) {
81 else if (!(obj instanceof StatementImpl))
83 StatementImpl r = (StatementImpl)obj;
84 return r.equals(subject.id, predicate.id, object.id);
88 final class StatementImplNew extends StatementImpl {
89 public final long objectResourceId;
90 public final long objectClusterId;
91 public final GraphSession graphSession;
92 public StatementImplNew(ResourceImpl subject, ResourceImpl predicate, long id, long cluster, GraphSession graphSession) {
93 super(subject, predicate);
95 this.objectResourceId = id;
96 if (Constants.ReservedClusterId == cluster)
97 throw new IllegalArgumentException("Argh!");
98 this.objectClusterId = cluster;
99 this.graphSession = graphSession;
103 final public Resource getObject() {
104 // if (null == object)
106 // object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);
107 // } catch (ResourceNotFoundException e) {
108 // e.printStackTrace();
112 throw new Error("No can do.");
116 public ResourceImpl getObjectImpl() {
117 // if (null == object)
119 // object = graphSession.getResourceOrThrow(objectResourceId, objectClusterId);
120 // } catch (ResourceNotFoundException e) {
121 // e.printStackTrace();
125 throw new Error("No can do.");
129 public int hashCode() {
130 return subject.hashCode() + (int)objectResourceId;
134 public boolean equals(long s, long p, long o) {
135 return (subject.id == s) && (predicate.id == p) && (objectResourceId == o);
139 public boolean equals(Object obj) {
142 else if (obj == null)
144 else if (StatementImpl.class != obj.getClass())
146 StatementImpl r = (StatementImpl)obj;
147 return r.equals(subject.id, predicate.id, objectResourceId);