View Javadoc

1   /*$Id: StdSqlMaker.java,v 1.1 2005/03/10 16:42:55 mch Exp $
2    * Created on 27-Nov-2003
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid
7    * Software License version 1.2, a copy of which has been included
8    * with this distribution in the LICENSE.txt file.
9    *
10   **/
11  package org.astrogrid.tableserver.jdbc;
12  
13  import java.io.IOException;
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.astrogrid.tableserver.jdbc.SqlMaker;
17  import org.astrogrid.query.Query;
18  
19  /***
20   * A 'standard' translator that creates 'standard' SQL. Uses the 'StdSqlWriter'
21   */
22  public class StdSqlMaker implements SqlMaker  {
23  
24     
25     private static final Log log = LogFactory.getLog(StdSqlMaker.class);
26     
27     /***
28      * Constructs an SQL statement for the given ADQL document by getting the
29      * (super) ADQL/sql and replacing the region
30      */
31     public String makeSql(Query query) throws IOException {
32        
33        StdSqlWriter sqlMaker = new StdSqlWriter();
34        query.acceptVisitor(sqlMaker);
35        
36        return sqlMaker.getSql();
37     }
38     
39     /***
40      * Constructs an SQL count statement for the given Query.
41      */
42     public String makeCountSql(Query query) throws IOException {
43  
44        //get ordinary SQL
45        String sql = makeSql(query);
46        
47        //remove anything between SELECT and FROM and replace with COUNT(*)
48        int selectIdx = sql.indexOf("SELECT");
49        int fromIdx = sql.indexOf("FROM");
50        String countSql = sql.substring(0,selectIdx+6)+" COUNT(*) "+sql.substring(fromIdx);
51        return countSql;
52     }
53     
54  }
55  
56  
57  /*
58   $Log: StdSqlMaker.java,v $
59   Revision 1.1  2005/03/10 16:42:55  mch
60   Split fits, sql and xdb
61  
62   Revision 1.1.1.1  2005/02/17 18:37:35  mch
63   Initial checkin
64  
65   Revision 1.2  2005/02/17 18:17:46  mch
66   Moved SqlWriters back into server as they need metadata information
67  
68   Revision 1.1.1.1  2005/02/16 17:11:24  mch
69   Initial checkin
70  
71   Revision 1.6.12.4  2004/12/08 23:23:37  mch
72   Made SqlWriter and AdqlWriter implement QueryVisitor
73  
74   Revision 1.6.12.3  2004/12/08 18:36:40  mch
75   Added Vizier, rationalised SqlWriters etc, separated out TableResults from QueryResults
76  
77   Revision 1.6.12.2  2004/11/25 00:30:56  mch
78   that fiddly sky package
79  
80   Revision 1.6.12.1  2004/11/22 00:57:16  mch
81   New interfaces for SIAP etc and new slinger package
82  
83   Revision 1.6  2004/11/03 01:35:18  mch
84   PAL_MCH_Candidate2 merge Part II
85  
86   Revision 1.2.2.4  2004/11/01 12:25:29  mch
87   Fix for dec -90 to +90
88  
89   Revision 1.2.2.3  2004/10/27 00:43:39  mch
90   Started adding getCount, some resource fixes, some jsps
91  
92   Revision 1.2.2.2  2004/10/22 14:34:56  mch
93   fixes for limiting sql on ms sql server
94  
95   Revision 1.2.2.1  2004/10/22 09:05:15  mch
96   Moved SqlMakers back to server
97  
98   Revision 1.7.6.1  2004/10/21 16:14:21  mch
99   Changes to take home
100 
101  Revision 1.7  2004/10/18 13:11:30  mch
102  Lumpy Merge
103 
104  Revision 1.6.2.1  2004/10/15 19:59:05  mch
105  Lots of changes during trip to CDS to improve int test pass rate
106 
107  Revision 1.6  2004/10/13 01:30:58  mch
108  Added adqlsql (keeps CIRCLE)
109 
110  Revision 1.5  2004/10/12 22:45:45  mch
111  Added spaces around operators so SqlParser can work with it
112 
113  Revision 1.4  2004/10/08 15:19:36  mch
114  Removed unnecessary imports
115 
116  Revision 1.3  2004/10/07 10:34:44  mch
117  Fixes to Cone maker functions and reading/writing String comparisons from Query
118 
119  Revision 1.2  2004/10/06 22:24:58  mch
120  Fixed wrong brackets in replaceRegion
121 
122  Revision 1.1  2004/10/06 21:12:16  mch
123  Big Lump of changes to pass Query OM around instead of Query subclasses, and TargetIndicator mixed into Slinger
124 
125  Revision 1.1  2004/09/28 15:02:13  mch
126  Merged PAL and server packages
127 
128  Revision 1.24  2004/09/08 21:55:14  mch
129  Uncommented SQL/ADQL tests
130 
131  Revision 1.23  2004/09/07 13:22:26  mch
132  Throws better error if ADQL 0.5 is submitted
133 
134  Revision 1.22  2004/09/07 02:28:29  mch
135  Removed ADQL 0.5 tests
136 
137  Revision 1.21  2004/09/07 00:54:20  mch
138  Tidied up Querier/Plugin/Results, and removed deprecated SPI-visitor-SQL-translator
139 
140  Revision 1.20  2004/08/27 09:31:16  mch
141  Added limit, order by, some page tidying, etc
142 
143  Revision 1.19  2004/08/24 20:08:31  mch
144  Moved xslts to classpaths to fix ADQL-SQL translation problems, slightly improved query builder pages
145 
146  Revision 1.18  2004/08/24 19:06:44  mch
147  Improvements to JSP pages, lots to query building and translating
148 
149  Revision 1.17  2004/08/24 12:55:09  mch
150  Minor fixes to xslt translator
151 
152  Revision 1.16  2004/08/06 12:04:19  mch
153  Added unit description to conesearch columns to cope with ESO milliarcseconds (& others in future)
154 
155  Revision 1.6.10.1  2004/08/05 17:57:08  mch
156  Merging Itn06 fixes into Itn05
157 
158  Revision 1.15  2004/08/05 10:56:56  mch
159  Fix for negative dec
160 
161  Revision 1.14  2004/08/05 09:52:59  mch
162  Removed aql073 and added 08
163 
164  Revision 1.13  2004/08/02 11:35:03  mch
165  Commented out incorrect square bounds maker
166 
167  Revision 1.12  2004/07/14 18:04:25  mch
168  Fixed SQL/Angles
169 
170  Revision 1.11  2004/07/12 23:26:51  mch
171  Fixed (somewhat) SQL for cone searches, added tests to Dummy DB
172 
173  Revision 1.10  2004/07/12 14:12:04  mch
174  Fixed ADQL 0.7.4 xslt
175 
176  Revision 1.9  2004/07/07 19:33:59  mch
177  Fixes to get Dummy db working and xslt sheets working both for unit tests and deployed
178 
179  Revision 1.8  2004/07/06 18:48:34  mch
180  Series of unit test fixes
181 
182  Revision 1.7  2004/07/01 23:07:14  mch
183  Introduced metadata generator
184 
185  Revision 1.6  2004/03/17 21:03:20  mch
186  Added SQL transformation tests
187 
188  Revision 1.5  2004/03/17 18:03:20  mch
189  Added v0.8 ADQL
190 
191  Revision 1.4  2004/03/17 01:47:26  mch
192  Added v05 Axis web interface
193 
194  Revision 1.3  2004/03/14 16:55:48  mch
195  Added XSLT ADQL->SQL support
196 
197  Revision 1.2  2004/03/12 20:04:57  mch
198  It05 Refactor (Client)
199 
200  Revision 1.1  2004/03/12 04:45:26  mch
201  It05 MCH Refactor
202 
203  
204  */
205 
206 
207