KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > hajdbc > Dialect


1 /*
2  * HA-JDBC: High-Availability JDBC
3  * Copyright (c) 2004-2006 Paul Ferraro
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by the
7  * Free Software Foundation; either version 2.1 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: ferraro@users.sourceforge.net
20  */

21 package net.sf.hajdbc;
22
23 import java.sql.DatabaseMetaData JavaDoc;
24 import java.sql.ResultSetMetaData JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27
28 /**
29  * Encapsulates database vendor specific SQL syntax.
30  *
31  * @author Paul Ferraro
32  * @since 1.1
33  */

34 public interface Dialect
35 {
36     /**
37      * Returns a simple SQL statement used to validate whether a database is alive or not.
38      * @return a SQL statement
39      */

40     public String JavaDoc getSimpleSQL();
41     
42     /**
43      * Returns a SQL statement to be executed within a running transaction that will effectively lock the specified table for writing.
44      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
45      * @param schema the name of a database schema, possibly null.
46      * @param table the name of a database table.
47      * @return a SQL statement
48      * @throws SQLException if there was an error fetching meta data.
49      */

50     public String JavaDoc getLockTableSQL(DatabaseMetaData JavaDoc metaData, String JavaDoc schema, String JavaDoc table) throws SQLException;
51     
52     /**
53      * Returns a SQL statement used to truncate a table.
54      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
55      * @param schema the name of a database schema, or null, if this database does not support schemas.
56      * @param table the name of a database table.
57      * @return a SQL statement
58      * @throws SQLException if there was an error fetching meta data.
59      */

60     public String JavaDoc getTruncateTableSQL(DatabaseMetaData JavaDoc metaData, String JavaDoc schema, String JavaDoc table) throws SQLException;
61     
62     /**
63      * Returns a SQL statement used to create a foreign key constraint.
64      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
65      * @param constraint a foreign key constraint
66      * @return a SQL statement
67      * @throws SQLException if there was an error fetching meta data.
68      */

69     public String JavaDoc getCreateForeignKeyConstraintSQL(DatabaseMetaData JavaDoc metaData, ForeignKeyConstraint constraint) throws SQLException;
70
71     /**
72      * Returns a SQL statement used to drop a foreign key constraint.
73      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
74      * @param constraint a foreign key constraint
75      * @return a SQL statement
76      * @throws SQLException if there was an error fetching meta data.
77      */

78     public String JavaDoc getDropForeignKeyConstraintSQL(DatabaseMetaData JavaDoc metaData, ForeignKeyConstraint constraint) throws SQLException;
79
80     /**
81      * Returns a SQL statement used to create a unique constraint.
82      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
83      * @param constraint a unique constraint
84      * @return a SQL statement
85      * @throws SQLException if there was an error fetching meta data.
86      */

87     public String JavaDoc getCreateUniqueConstraintSQL(DatabaseMetaData JavaDoc metaData, UniqueConstraint constraint) throws SQLException;
88
89     /**
90      * Returns a SQL statement used to drop a unique constraint.
91      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
92      * @param constraint a unique constraint
93      * @return a SQL statement
94      * @throws SQLException if there was an error fetching meta data.
95      */

96     public String JavaDoc getDropUniqueConstraintSQL(DatabaseMetaData JavaDoc metaData, UniqueConstraint constraint) throws SQLException;
97     
98     /**
99      * Returns the quoted name of the specified table qualified with the specified schema.
100      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
101      * @param schema the name of a database schema, or null, if this database does not support schemas.
102      * @param table the name of a database table.
103      * @return a quoted schema qualified table name
104      * @throws SQLException if there was an error fetching meta data.
105      */

106     public String JavaDoc qualifyTable(DatabaseMetaData JavaDoc metaData, String JavaDoc schema, String JavaDoc table) throws SQLException;
107     
108     /**
109      * Quotes the specified identifier.
110      * @param metaData a <code>DatabaseMetaData</code> object for a given database.
111      * @param identifier a database identifier
112      * @return a quoted identifier name
113      * @throws SQLException if there was an error fetching meta data.
114      */

115     public String JavaDoc quote(DatabaseMetaData JavaDoc metaData, String JavaDoc identifier) throws SQLException;
116     
117     /**
118      * Determines whether the specified SQL is a SELECT ... FOR UPDATE statement
119      * @return true if this is a SELECT ... FOR UPDATE statement, false if it is not or if SELECT...FOR UPDATE is not supported
120      */

121     public boolean isSelectForUpdate(DatabaseMetaData JavaDoc metaData, String JavaDoc sql) throws SQLException;
122     
123     /**
124      * Returns the JDBC type of the specified column.
125      * @param metaData a <code>ResultSetMetaData</code> object for a given database.
126      * @param column a column index
127      * @return a JDBC type
128      * @throws SQLException if there was an error accessing meta data
129      */

130     public int getColumnType(ResultSetMetaData JavaDoc metaData, int column) throws SQLException;
131 }
132
Popular Tags