KickJava   Java API By Example, From Geeks To Geeks.

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


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.map.DbEntity;
23
24
25 /**
26  * A flavor of HSQLDBAdapter that implements workarounds for some old driver limitations.
27  *
28  * @since 1.2
29  * @author Mike Kienenberger
30  */

31 public class HSQLDBNoSchemaAdapter extends HSQLDBAdapter {
32     /**
33      * Generate unqualified name without schema.
34      *
35      * @since 1.2
36      */

37     protected String JavaDoc getTableName(DbEntity entity)
38     {
39         return entity.getName();
40     }
41
42     /**
43      * Generate unqualified name.
44      *
45      * @since 1.2
46      */

47     protected String JavaDoc getSchemaName(DbEntity entity) {
48         return "";
49     }
50
51     /**
52      * Returns a SQL string to drop a table corresponding to <code>ent</code> DbEntity.
53      *
54      * @since 1.2
55      */

56     public String JavaDoc dropTable(DbEntity ent) {
57         // hsqldb doesn't support schema namespaces, so remove if found
58
return "DROP TABLE " + getTableName(ent);
59     }
60
61     /**
62      * Uses unqualified entity names.
63      *
64      * @since 1.2
65      */

66     public String JavaDoc createTable(DbEntity ent) {
67         String JavaDoc sql = super.createTable(ent);
68
69         // hsqldb doesn't support schema namespaces, so remove if found
70
String JavaDoc fqnCreate = "CREATE CACHED TABLE " + super.getTableName(ent) + " (";
71         if (sql != null && sql.toUpperCase().startsWith(fqnCreate)) {
72             sql = "CREATE CACHED TABLE "
73                     + getTableName(ent)
74                     + " ("
75                     + sql.substring(fqnCreate.length());
76         }
77
78         return sql;
79     }
80 }
81
Popular Tags