View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2004, 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  
22  package org.dbunit.database;
23  
24  import org.dbunit.database.statement.IStatementFactory;
25  import org.dbunit.dataset.DataSetException;
26  import org.dbunit.dataset.IDataSet;
27  import org.dbunit.dataset.ITable;
28  
29  import java.sql.Connection;
30  import java.sql.PreparedStatement;
31  import java.sql.SQLException;
32  
33  /**
34   * This interface represents a connection to a specific database.
35   *
36   * @author Manuel Laflamme
37   * @version $Revision$
38   * @since Mar 6, 2002
39   */
40  public interface IDatabaseConnection
41  {
42      /**
43       * Returns a JDBC database connection.
44       */
45      public Connection getConnection() throws SQLException;
46  
47      /**
48       * Returns the database schema name.
49       */
50      public String getSchema();
51  
52      /**
53       * Close this connection.
54       */
55      public void close() throws SQLException;
56  
57      /**
58       * Creates a dataset corresponding to the entire database.
59       */
60      public IDataSet createDataSet() throws SQLException;
61  
62      /**
63       * Creates a dataset containing only the specified tables from
64       * the database.
65       * @param tableNames The tables for which a dataset shall be created
66       * @return The new dataset
67       * @throws SQLException
68       * @throws DataSetException
69       */
70      public IDataSet createDataSet(String[] tableNames) 
71              throws SQLException, DataSetException;
72  
73      /**
74       * Creates a table with the result of the specified SQL statement. The
75       * table can be the result of a join statement.
76       *
77       * @param tableName The name to be returned by {@link org.dbunit.dataset.ITableMetaData#getTableName}.
78       * @param sql The SQL <code>SELECT</code> statement
79       * @return The new table
80       * @throws DataSetException
81       * @throws SQLException
82       */
83      public ITable createQueryTable(String tableName, String sql)
84              throws DataSetException, SQLException;
85  
86      /**
87       * Creates a table using the given PreparedStatement to retrieve a ResultSet.
88       *
89       * @param tableName The name to be returned by {@link org.dbunit.dataset.ITableMetaData#getTableName}.
90       * @param preparedStatement The statement to be executed as query
91       * @return The new table
92       * @throws DataSetException
93       * @throws SQLException
94       * @since 2.4.4
95       */
96      public ITable createTable(String tableName, PreparedStatement preparedStatement)
97              throws DataSetException, SQLException;
98  
99      /**
100      * Creates a table with the result of a <code>select * from <i>tableName</i></code> SQL statement. 
101      *
102      * @param tableName The name of the database table to be queried which is also returned by 
103      * {@link org.dbunit.dataset.ITableMetaData#getTableName}.
104      */
105     public ITable createTable(String tableName)
106             throws DataSetException, SQLException;
107     
108     /**
109      * Returns the specified table row count.
110      *
111      * @param tableName the table name
112      * @return the row count
113      */
114     public int getRowCount(String tableName) throws SQLException;
115 
116     /**
117      * Returns the specified table row count according specified where clause.
118      *
119      * @param tableName the table name
120      * @param whereClause the where clause
121      * @return the row count
122      */
123     public int getRowCount(String tableName, String whereClause) throws SQLException;
124 
125     /**
126      * Returns this connection database configuration
127      */
128     public DatabaseConfig getConfig();
129 
130     /**
131      * @deprecated Use {@link #getConfig}
132      */
133     public IStatementFactory getStatementFactory();
134 }
135 
136 
137 
138 
139 
140 
141 
142