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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.layer0.utils.predicates;
\r
14 import java.util.Collection;
\r
16 import org.simantics.db.ReadGraph;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.WriteGraph;
\r
19 import org.simantics.db.exception.DatabaseException;
\r
20 import org.simantics.layer0.Layer0;
\r
22 public class SuperRelation extends UnaryPredicate {
\r
24 Resource superrelation;
\r
26 public SuperRelation(Resource superrelation) {
\r
27 this.superrelation = superrelation;
\r
31 public Collection<Resource> getResources(ReadGraph g) {
\r
32 throw new UnsupportedOperationException();
\r
36 public boolean has(ReadGraph g, Resource resource) throws DatabaseException {
\r
37 return g.isSubrelationOf(resource, superrelation);
\r
41 public boolean supportsUnboundedQuery() {
\r
46 public void add(WriteGraph g, Resource r) throws DatabaseException {
\r
47 if(!g.isSubrelationOf(r, superrelation)) {
\r
48 Layer0 b = Layer0.getInstance(g);
\r
49 g.claim(r, b.SubrelationOf, superrelation);
\r
50 if(!g.hasStatement(r, b.InverseOf)) {
\r
51 Resource invR = g.newResource();
\r
52 g.claim(r, b.InverseOf, invR);
\r
53 g.claim(invR, b.SubrelationOf, g.getInverse(superrelation));
\r
59 public void remove(WriteGraph g, Resource r) throws DatabaseException {
\r
60 // FIXME not implemented correctly
\r
61 Layer0 b = Layer0.getInstance(g);
\r
62 if(g.isSubrelationOf(r, superrelation))
\r
63 g.denyStatement(r, b.SubrelationOf, superrelation);
\r
67 public boolean supportsAddition() {
\r
72 public boolean supportsRemoval() {
\r
77 public int hashCode() {
\r
78 final int prime = 31;
\r
80 result = prime * result + ((superrelation == null) ? 0 : superrelation.hashCode());
\r
85 public boolean equals(Object obj) {
\r
90 if (getClass() != obj.getClass())
\r
92 SuperRelation other = (SuperRelation) obj;
\r
93 if (superrelation == null) {
\r
94 if (other.superrelation != null)
\r
96 } else if (!superrelation.equals(other.superrelation))
\r