KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > dba > DbAdapter


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 package org.apache.cayenne.dba;
20
21 import java.sql.PreparedStatement JavaDoc;
22 import java.sql.SQLException JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 import org.apache.cayenne.access.DataNode;
26 import org.apache.cayenne.access.trans.QualifierTranslator;
27 import org.apache.cayenne.access.trans.QueryAssembler;
28 import org.apache.cayenne.access.types.ExtendedTypeMap;
29 import org.apache.cayenne.map.DbAttribute;
30 import org.apache.cayenne.map.DbEntity;
31 import org.apache.cayenne.map.DbRelationship;
32 import org.apache.cayenne.query.Query;
33 import org.apache.cayenne.query.SQLAction;
34
35 /**
36  * Defines API needed to handle differences between various databases accessed via JDBC.
37  * Implementing classed are intended to be pluggable database-specific adapters.
38  * DbAdapter-based architecture is introduced to solve the following problems:
39  * <ul>
40  * <li>Make Cayenne code independent from SQL syntax differences between different RDBMS.
41  * <li>Allow for vendor-specific tuning of JDBC access.
42  * </ul>
43  *
44  * @author Andrus Adamchik
45  */

46 public interface DbAdapter {
47
48     /**
49      * Returns a String used to terminate a batch in command-line tools. E.g. ";" on
50      * Oracle or "go" on Sybase.
51      *
52      * @since 1.0.4
53      */

54     public String JavaDoc getBatchTerminator();
55
56     // TODO: deprecate and move into SQLAction implementation
57
public QualifierTranslator getQualifierTranslator(QueryAssembler queryAssembler);
58
59     /**
60      * Returns an instance of SQLAction that should handle the query.
61      *
62      * @since 1.2
63      */

64     public SQLAction getAction(Query query, DataNode node);
65
66     /**
67      * Returns true if a target database supports FK constraints.
68      *
69      * @deprecated since 3.0 - almost all DB's support FK's now and also this flag is less
70      * relevant for Cayenne now.
71      */

72     public boolean supportsFkConstraints();
73
74     /**
75      * Returns true if a target database supports UNIQUE constraints.
76      *
77      * @since 1.1
78      */

79     public boolean supportsUniqueConstraints();
80
81     /**
82      * Returns true if a target database supports key autogeneration. This feature also
83      * requires JDBC3-compliant driver.
84      *
85      * @since 1.2
86      */

87     public boolean supportsGeneratedKeys();
88
89     /**
90      * Returns <code>true</code> if the target database supports batch updates.
91      */

92     public boolean supportsBatchUpdates();
93
94     /**
95      * Returns a SQL string that can be used to drop a database table corresponding to
96      * <code>ent</code> parameter.
97      */

98     public String JavaDoc dropTable(DbEntity entity);
99
100     /**
101      * Returns a SQL string that can be used to create database table corresponding to
102      * <code>ent</code> parameter.
103      */

104     public String JavaDoc createTable(DbEntity entity);
105
106     /**
107      * Returns a DDL string to create a unique constraint over a set of columns.
108      *
109      * @since 1.1
110      */

111     public String JavaDoc createUniqueConstraint(DbEntity source, Collection JavaDoc columns);
112
113     /**
114      * Returns a SQL string that can be used to create a foreign key constraint for the
115      * relationship, or null if foreign keys are not supported.
116      */

117     public String JavaDoc createFkConstraint(DbRelationship rel);
118
119     /**
120      * Returns an array of RDBMS types that can be used with JDBC <code>type</code>.
121      * Valid JDBC types are defined in java.sql.Types.
122      */

123     public String JavaDoc[] externalTypesForJdbcType(int type);
124
125     /**
126      * Returns a map of ExtendedTypes that is used to translate values between Java and
127      * JDBC layer.
128      *
129      * @see org.apache.cayenne.access.types.ExtendedType
130      */

131     public ExtendedTypeMap getExtendedTypes();
132
133     /**
134      * Returns primary key generator associated with this DbAdapter.
135      */

136     public PkGenerator getPkGenerator();
137
138     /**
139      * Creates and returns a DbAttribute based on supplied parameters (usually obtained
140      * from database meta data).
141      *
142      * @param name database column name
143      * @param typeName database specific type name, may be used as a hint to determine the
144      * right JDBC type.
145      * @param type JDBC column type
146      * @param size database column size (ignored if less than zero)
147      * @param scale database column scale, i.e. the number of decimal digits (ignored if
148      * less than zero)
149      * @param allowNulls database column nullable parameter
150      */

151     public DbAttribute buildAttribute(
152             String JavaDoc name,
153             String JavaDoc typeName,
154             int type,
155             int size,
156             int scale,
157             boolean allowNulls);
158
159     /**
160      * Binds an object value to PreparedStatement's numbered parameter.
161      */

162     public void bindParameter(
163             PreparedStatement JavaDoc statement,
164             Object JavaDoc object,
165             int pos,
166             int sqlType,
167             int scale) throws SQLException JavaDoc, Exception JavaDoc;
168
169     /**
170      * Returns the name of the table type (as returned by
171      * <code>DatabaseMetaData.getTableTypes</code>) for a simple user table.
172      */

173     public String JavaDoc tableTypeForTable();
174
175     /**
176      * Returns the name of the table type (as returned by
177      * <code>DatabaseMetaData.getTableTypes</code>) for a view table.
178      */

179     public String JavaDoc tableTypeForView();
180 }
181
Popular Tags