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.db.layer0.genericrelation;
14 import java.util.List;
16 import org.simantics.db.ReadGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.layer0.adapter.GenericRelation;
19 import org.simantics.utils.datastructures.Pair;
22 * Default implementation for some methods of IRelation interface.
24 public class UnsupportedRelation implements GenericRelation {
27 public boolean contains(ReadGraph graph, Object[] tuple) throws DatabaseException {
28 throw new UnsupportedOperationException();
32 public boolean isRealizable() {
33 throw new UnsupportedOperationException();
37 public List<Object[]> realize(ReadGraph graph) throws DatabaseException {
38 throw new UnsupportedOperationException();
42 public GenericRelation select(String bindingPattern, Object[] constants) {
43 throw new UnsupportedOperationException();
47 public GenericRelation selectByRelation(String bindingPattern,
48 GenericRelation constraint) {
49 throw new UnsupportedOperationException();
53 public Pair<String, String>[] getFields() {
54 throw new UnsupportedOperationException();
57 private Class<?> getClass(String clazz) {
58 if("Long".equals(clazz)) return Long.class;
59 else return String.class;
62 protected void checkSelectionArguments(String bindingPattern, Object[] constants, String[] allowedPatterns) {
64 boolean allowed = false;
65 for(String allow : allowedPatterns) {
66 if(allow.equals(bindingPattern)) {
72 if(!allowed) throw new IllegalArgumentException("Select does not support binding pattern '" + bindingPattern + "'");
74 Pair<String, String>[] fields = getFields();
76 assert(bindingPattern.length() == fields.length);
77 int constantIndex = 0;
78 for(int i=0;i<bindingPattern.length();++i) {
79 Class<?> clazz = getClass(fields[i].second);
80 switch(bindingPattern.charAt(i)) {
82 if(!clazz.isInstance(constants[constantIndex++])) throw new IllegalArgumentException("Invalid constant.");
87 throw new IllegalArgumentException("Invalid binding character '" + bindingPattern.charAt(i) + "'");