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.Query;
12
13
14
15
16 /***
17 * Checks the query against the rdbms resource
18 *
19 * @author M Hill
20 * @author K Andrews
21 */
22
23 public class RdbmsQueryValidator
24 {
25 TableMetaDocInterpreter interpreter = null;
26
27 public RdbmsQueryValidator(TableMetaDocInterpreter reader) {
28 this.interpreter = reader;
29 }
30
31 public void validateQuery(Query query)
32 {
33 String[] tableRefs = query.getTableReferences();
34 for (int i = 0; i < tableRefs.length; i++) {
35 String[] catalogNames = interpreter.getCatalogs();
36 if (catalogNames.length == 0) {
37 throw new IllegalArgumentException("Server error: no catalog or table metadata are defined for this DSA/catalog installation; please check your metadoc file and/or configuration!");
38 }
39 if (interpreter.getTable(
40 catalogNames[0], tableRefs[i]) ==null) {
41 throw new IllegalArgumentException( "Table '"+tableRefs[i]+
42 "' is not available in this DSA/catalog installation.");
43 }
44 String[] columnRefs = query.getColumnReferences(tableRefs[i]);
45 for (int j = 0; j < columnRefs.length; j++) {
46 try {
47 if (interpreter.getColumn(
48 catalogNames[0],
49 tableRefs[i], columnRefs[j]) == null) {
50 throw new IllegalArgumentException("Column "+
51 columnRefs[j] +" in table "+
52 tableRefs[i] +
53 " is not available in this DSA/catalog installation");
54 }
55 }
56 catch (MetadataException me) {
57 throw new IllegalArgumentException( "Couldn't validate query, DSA metadata appears to be misconfigured :" + me.getMessage());
58 }
59 }
60 }
61 }
62 }