1 /*
2 *
3 * The DbUnit Database Testing Framework
4 * Copyright (C)2002-2009, DbUnit.org
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21 package org.dbunit.database;
22
23 import java.sql.DatabaseMetaData;
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
26
27 /**
28 * Handler to specify the behavior for a lookup of column metadata using database metadata.
29 *
30 * @author gommma (gommma AT users.sourceforge.net)
31 * @author Last changed by: $Author$
32 * @version $Revision$ $Date$
33 * @since 2.4.4
34 */
35 public interface IMetadataHandler
36 {
37
38 /**
39 * Returns the result set for an invocation of {@link DatabaseMetaData#getColumns(String, String, String, String)}.
40 * @param databaseMetaData The database metadata to be used for retrieving the columns
41 * @param schemaName The schema name
42 * @param tableName The table name
43 * @return The result set containing all columns
44 * @throws SQLException
45 * @since 2.4.4
46 */
47 ResultSet getColumns(DatabaseMetaData databaseMetaData, String schemaName, String tableName)
48 throws SQLException;
49
50 /**
51 * Checks if the given <code>resultSet</code> matches the given schema and table name.
52 * The comparison is <b>case sensitive</b>.
53 * @param resultSet A result set produced via {@link DatabaseMetaData#getColumns(String, String, String, String)}
54 * @param schema
55 * @param table
56 * @param caseSensitive Whether or not the comparison should be case sensitive
57 * @return <code>true</code> if the column metadata of the given <code>resultSet</code> matches
58 * the given schema and table parameters.
59 * @throws SQLException
60 * @see #matches(ResultSet, String, String, String, String, boolean)
61 * @since 2.4.4
62 */
63 public boolean matches(ResultSet resultSet, String schema, String table, boolean caseSensitive)
64 throws SQLException;
65
66 /**
67 * Checks if the given <code>resultSet</code> matches the given schema and table name.
68 * The comparison is <b>case sensitive</b>.
69 * @param resultSet A result set produced via {@link DatabaseMetaData#getColumns(String, String, String, String)}
70 * @param catalog The name of the catalog to check. If <code>null</code> it is ignored in the comparison
71 * @param schema The name of the schema to check. If <code>null</code> it is ignored in the comparison
72 * @param table The name of the table to check. If <code>null</code> it is ignored in the comparison
73 * @param column The name of the column to check. If <code>null</code> it is ignored in the comparison
74 * @param caseSensitive Whether or not the comparison should be case sensitive
75 * @return <code>true</code> if the column metadata of the given <code>resultSet</code> matches
76 * the given schema and table parameters.
77 * @throws SQLException
78 * @since 2.4.4
79 */
80 boolean matches(ResultSet resultSet, String catalog, String schema,
81 String table, String column, boolean caseSensitive) throws SQLException;
82
83 /**
84 * Returns the schema name to which the table of the current result set index belongs.
85 * @param resultSet The result set pointing to a valid record in the database that was returned
86 * by {@link DatabaseMetaData#getTables(String, String, String, String[])}.
87 * @return The name of the schema from the given result set
88 * @since 2.4.4
89 */
90 String getSchema(ResultSet resultSet) throws SQLException;
91
92 /**
93 * Checks if the given table exists.
94 * @param databaseMetaData The database meta data
95 * @param schemaName The schema in which the table should be searched. If <code>null</code>
96 * the schema is not used to narrow the table name.
97 * @param tableName The table name to be searched
98 * @return Returns <code>true</code> if the given table exists in the given schema.
99 * Else returns <code>false</code>.
100 * @throws SQLException
101 * @since 2.4.5
102 */
103 boolean tableExists(DatabaseMetaData databaseMetaData, String schemaName, String tableName)
104 throws SQLException;
105
106 /**
107 * Returns the tables in the given schema that matches one of the given tableTypes.
108 * @param databaseMetaData The database meta data
109 * @param schemaName schema for which the tables should be retrieved; <code>null</code> returns all schemas
110 * @param tableTypes a list of table types to include; <code>null</code> returns all types
111 * @return The ResultSet which is retrieved using {@link DatabaseMetaData#getTables(String, String, String, String[])}
112 * @throws SQLException
113 * @since 2.4.5
114 */
115 ResultSet getTables(DatabaseMetaData databaseMetaData, String schemaName, String[] tableTypes)
116 throws SQLException;
117
118 /**
119 * @param databaseMetaData The database meta data
120 * @param schemaName schema for which the tables should be retrieved; <code>null</code> returns all schemas
121 * @param tableName table for which the primary keys are retrieved
122 * @return The ResultSet which is retrieved using {@link DatabaseMetaData#getPrimaryKeys(String, String, String)}
123 * @throws SQLException
124 * @since 2.4.5
125 */
126 public ResultSet getPrimaryKeys(DatabaseMetaData databaseMetaData, String schemaName, String tableName)
127 throws SQLException;
128
129
130 }