]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/UnsupportedRelation.java
Merge "Documented difference of RuntimeEnvironmentRequest and Runti...quest2" into...
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / UnsupportedRelation.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.layer0.genericrelation;
13
14 import java.util.List;
15
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;
20
21 /**
22  * Default implementation for some methods of IRelation interface.
23  */
24 public class UnsupportedRelation implements GenericRelation {
25
26         @Override
27         public boolean contains(ReadGraph graph, Object[] tuple) throws DatabaseException {
28                 throw new UnsupportedOperationException();
29         }
30
31         @Override
32         public boolean isRealizable() {
33                 throw new UnsupportedOperationException();
34         }
35
36         @Override
37         public List<Object[]> realize(ReadGraph graph) throws DatabaseException {
38                 throw new UnsupportedOperationException();
39         }
40
41         @Override
42         public GenericRelation select(String bindingPattern, Object[] constants) {
43                 throw new UnsupportedOperationException();
44         }
45
46         @Override
47         public GenericRelation selectByRelation(String bindingPattern,
48                         GenericRelation constraint) {
49                 throw new UnsupportedOperationException();
50         }
51
52         @Override
53         public Pair<String, String>[] getFields() {
54                 throw new UnsupportedOperationException();
55         }
56
57         private Class<?> getClass(String clazz) {
58                 if("Long".equals(clazz)) return Long.class;
59                 else return String.class;
60         }
61         
62         protected void checkSelectionArguments(String bindingPattern, Object[] constants, String[] allowedPatterns) {
63
64         boolean allowed = false;
65         for(String allow : allowedPatterns) {
66                 if(allow.equals(bindingPattern)) {
67                 allowed = true;
68                 break;
69             }
70         }
71         
72         if(!allowed) throw new IllegalArgumentException("Select does not support binding pattern '" + bindingPattern + "'");
73
74                 Pair<String, String>[] fields = getFields();
75
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)) {
81                         case 'b':
82                                 if(!clazz.isInstance(constants[constantIndex++])) throw new IllegalArgumentException("Invalid constant.");
83                                 break;
84                         case 'f':
85                                 break;
86                         default:
87                                 throw new IllegalArgumentException("Invalid binding character '" + bindingPattern.charAt(i) + "'");
88                         }
89                 }
90
91         }
92
93 }