1 package org.apache.torque.adapter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 {
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 toUpperCase(String str)
54 {
55 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 return toUpperCase(str);
70 }
71
72 /***
73 * @see org.apache.torque.adapter.DB#getIDMethodType()
74 */
75 public String 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 getIDMethodSQL(Object 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 con, String table)
100 throws SQLException
101 {
102 Statement statement = con.createStatement();
103 StringBuffer stmt = new StringBuffer();
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 con, String table)
117 throws SQLException
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 }