1
2
3
4
5
6
7 package org.astrogrid.tableserver.jdbc;
8
9 import org.astrogrid.dataservice.metadata.MetadataException;
10 import org.astrogrid.tableserver.metadata.TableMetaDocInterpreter;
11 import org.astrogrid.query.DefaultQueryTraverser;
12 import org.astrogrid.query.condition.ColumnReference;
13
14
15 /***
16 * Checks the query against the rdbms resource
17 */
18
19 public class RdbmsQueryValidator extends DefaultQueryTraverser {
20
21 TableMetaDocInterpreter interpreter = null;
22
23 public RdbmsQueryValidator(TableMetaDocInterpreter reader) {
24 this.interpreter = reader;
25 }
26
27 /*** Assumes only one catalog at the moment, and checks against the first one */
28 public void visitScope(String[] scope) {
29 for (int i = 0; i < scope.length; i++) {
30 if (interpreter.getTable(interpreter.getCatalogs()[0], scope[i]) ==null) {
31 throw new IllegalArgumentException("Table '"+scope[i]+"' is not available in this RDBMS Resource");
32 }
33 }
34 }
35
36 public void visitColumnReference(ColumnReference expression) {
37 try {
38 if (interpreter.getColumn(interpreter.getCatalogs()[0],expression.getTableName(), expression.getColName()) == null) {
39 throw new IllegalArgumentException(expression+" is not in RDBMS Resource and so cannot be queried");
40 }
41 } catch (MetadataException me) {
42 throw new RuntimeException(me);
43 }
44
45 }
46
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86