KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > adapter > DBDerby


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

21
22 import java.sql.Connection JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.sql.Statement JavaDoc;
25
26 /**
27  * This is used to connect to an embedded Apache Derby Database using
28  * the supplied JDBC driver.
29  *
30  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
31  * @version $Id: DBDerby.java 473821 2006-11-11 22:37:25Z tv $
32  */

33 public class DBDerby extends AbstractDBAdapter
34 {
35     /**
36      * Serial version
37      */

38     private static final long serialVersionUID = 6265962681516206415L;
39
40     /**
41      * Empty constructor.
42      */

43     protected DBDerby()
44     {
45     }
46
47     /**
48      * This method is used to ignore case.
49      *
50      * @param str The string to transform to upper case.
51      * @return The upper case string.
52      */

53     public String JavaDoc toUpperCase(String JavaDoc str)
54     {
55         return new StringBuffer JavaDoc("UPPER(")
56                 .append(str)
57                 .append(")")
58                 .toString();
59     }
60
61     /**
62      * This method is used to ignore case.
63      *
64      * @param str The string whose case to ignore.
65      * @return The string in a case that can be ignored.
66      */

67     public String JavaDoc ignoreCase(String JavaDoc str)
68     {
69         return toUpperCase(str);
70     }
71
72     /**
73      * @see org.apache.torque.adapter.DB#getIDMethodType()
74      */

75     public String JavaDoc getIDMethodType()
76     {
77         return AUTO_INCREMENT;
78     }
79
80     /**
81      * Returns the SQL to get the database key of the last row
82      * inserted, which in this case is
83      * <code>VALUES IDENTITY_VAL_LOCAL()</code>.
84      *
85      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
86      */

87     public String JavaDoc getIDMethodSQL(Object JavaDoc obj)
88     {
89         return "VALUES IDENTITY_VAL_LOCAL()";
90     }
91
92     /**
93      * Locks the specified table.
94      *
95      * @param con The JDBC connection to use.
96      * @param table The name of the table to lock.
97      * @exception SQLException No Statement could be created or executed.
98      */

99     public void lockTable(Connection JavaDoc con, String JavaDoc table)
100             throws SQLException JavaDoc
101     {
102         Statement JavaDoc statement = con.createStatement();
103         StringBuffer JavaDoc stmt = new StringBuffer JavaDoc();
104         stmt.append("LOCK TABLE ")
105                 .append(table).append(" IN EXCLUSIVE MODE");
106         statement.executeUpdate(stmt.toString());
107     }
108
109     /**
110      * Unlocks the specified table.
111      *
112      * @param con The JDBC connection to use.
113      * @param table The name of the table to unlock.
114      * @exception SQLException No Statement could be created or executed.
115      */

116     public void unlockTable(Connection JavaDoc con, String JavaDoc table)
117             throws SQLException JavaDoc
118     {
119     }
120
121     /**
122      * Whether backslashes (\) should be escaped in explicit SQL strings.
123      * If true is returned, a BACKSLASH will be changed to "\\". If false
124      * is returned, a BACKSLASH will be left as "\".
125      *
126      * As derby does not need escaping of Backslashes, this method always
127      * returns false.
128      *
129      * @return true if the database needs to escape backslashes
130      * in SqlExpressions.
131      */

132
133      public boolean escapeText()
134      {
135          return false;
136      }
137
138      /**
139      * Whether an escape clause in like should be used.
140      * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
141      *
142      * Derby needs this, so this implementation always returns
143      * <code>true</code>.
144      *
145      * @return whether the escape clause should be appended or not.
146      */

147     public boolean useEscapeClauseForLike()
148     {
149         return true;
150     }
151 }
152
Popular Tags