KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > dba > hsqldb > HSQLDBProcedureTranslator


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.dba.hsqldb;
21
22 import org.apache.cayenne.access.trans.ProcedureTranslator;
23 import org.apache.cayenne.map.Procedure;
24
25 /**
26  * Works around HSQLDB's pickiness about stored procedure syntax.
27  *
28  * @since 1.2
29  * @author Cristopher Daniluk
30  */

31 public class HSQLDBProcedureTranslator extends ProcedureTranslator {
32
33     /**
34      * Creates HSQLDB-compliant SQL to execute a stored procedure.
35      */

36     protected String JavaDoc createSqlString() {
37         Procedure procedure = getProcedure();
38
39         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
40
41         int totalParams = callParams.size();
42
43         // check if procedure returns values
44
if (procedure.isReturningValue()) {
45             totalParams--;
46
47             // HSQL won't accept "? =". The parser only recognizes "?="
48

49             // TODO: Andrus, 12/12/2005 - this is kind of how it is in the
50
// CallableStatement javadocs, so we may need to make "?=" a default ... this
51
// requires testing on Oracle/PostgreSQL/Sybase/SQLServer.
52
buf.append("{?= call ");
53         }
54         else {
55             buf.append("{call ");
56         }
57
58         // HSQLDB requires that procedures with periods (referring to Java packages)
59
// be enclosed in quotes. It is not clear that quotes can always be used, though
60
if (procedure.getFullyQualifiedName().indexOf('.') > -1) {
61             buf.append("\"").append(procedure.getFullyQualifiedName()).append("\"");
62         }
63         else {
64             buf.append(procedure.getFullyQualifiedName());
65         }
66
67         if (totalParams > 0) {
68             // unroll the loop
69
buf.append("(?");
70
71             for (int i = 1; i < totalParams; i++) {
72                 buf.append(", ?");
73             }
74
75             buf.append(")");
76         }
77
78         buf.append("}");
79         return buf.toString();
80     }
81 }
82
Popular Tags