%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
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; |
|
23 | import java.sql.SQLException; |
|
24 | import java.sql.Statement; |
|
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 | 0 | { |
45 | 0 | } |
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 toUpperCase(String str) |
|
54 | { |
|
55 | 0 | return new StringBuffer("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 ignoreCase(String str) |
|
68 | { |
|
69 | 0 | return toUpperCase(str); |
70 | } |
|
71 | ||
72 | /** |
|
73 | * @see org.apache.torque.adapter.DB#getIDMethodType() |
|
74 | */ |
|
75 | public String getIDMethodType() |
|
76 | { |
|
77 | 0 | 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 getIDMethodSQL(Object obj) |
|
88 | { |
|
89 | 0 | 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 con, String table) |
|
100 | throws SQLException |
|
101 | { |
|
102 | 0 | Statement statement = con.createStatement(); |
103 | 0 | StringBuffer stmt = new StringBuffer(); |
104 | 0 | stmt.append("LOCK TABLE ") |
105 | .append(table).append(" IN EXCLUSIVE MODE"); |
|
106 | 0 | statement.executeUpdate(stmt.toString()); |
107 | 0 | } |
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 con, String table) |
|
117 | throws SQLException |
|
118 | { |
|
119 | 0 | } |
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 | 0 | 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 | 0 | return true; |
150 | } |
|
151 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |