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