| 1 | /* Connection.java -- Manage a database connection.
|
|---|
| 2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.sql;
|
|---|
| 40 |
|
|---|
| 41 | import java.util.Map;
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * This interface provides methods for managing a connection to a database.
|
|---|
| 45 | *
|
|---|
| 46 | * @author Aaron M. Renn ([email protected])
|
|---|
| 47 | */
|
|---|
| 48 | public interface Connection
|
|---|
| 49 | {
|
|---|
| 50 |
|
|---|
| 51 | /**
|
|---|
| 52 | * This transaction isolation level indicates that transactions are not
|
|---|
| 53 | * supported.
|
|---|
| 54 | */
|
|---|
| 55 | public static final int TRANSACTION_NONE = 0;
|
|---|
| 56 |
|
|---|
| 57 | /**
|
|---|
| 58 | * This transaction isolation level indicates that one transaction can
|
|---|
| 59 | * read modifications by other transactions before the other transactions
|
|---|
| 60 | * have committed their changes. This could result in invalid reads.
|
|---|
| 61 | */
|
|---|
| 62 | public static final int TRANSACTION_READ_UNCOMMITTED = 1;
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * This transaction isolation leve indicates that only committed data from
|
|---|
| 66 | * other transactions will be read. If a transaction reads a row, then
|
|---|
| 67 | * another transaction commits a change to that row, the first transaction
|
|---|
| 68 | * would retrieve the changed row on subsequent reads of the same row.
|
|---|
| 69 | */
|
|---|
| 70 | public static final int TRANSACTION_READ_COMMITTED = 2;
|
|---|
| 71 |
|
|---|
| 72 | /**
|
|---|
| 73 | * This transaction isolation level indicates that only committed data from
|
|---|
| 74 | * other transactions will be read. It also ensures that data read from
|
|---|
| 75 | * a row will not be different on a subsequent read even if another
|
|---|
| 76 | * transaction commits a change.
|
|---|
| 77 | */
|
|---|
| 78 | public static final int TRANSACTION_REPEATABLE_READ = 4;
|
|---|
| 79 |
|
|---|
| 80 | /**
|
|---|
| 81 | * This transaction isolation level indicates that only committed data from
|
|---|
| 82 | * other transactions will be read. It also ensures that data read from
|
|---|
| 83 | * a row will not be different on a subsequent read even if another
|
|---|
| 84 | * transaction commits a change. Additionally, rows modified by other
|
|---|
| 85 | * transactions will not affect the result set returned during subsequent
|
|---|
| 86 | * executions of the same WHERE clause in this transaction.
|
|---|
| 87 | */
|
|---|
| 88 | public static final int TRANSACTION_SERIALIZABLE = 8;
|
|---|
| 89 |
|
|---|
| 90 | /*************************************************************************/
|
|---|
| 91 |
|
|---|
| 92 | /**
|
|---|
| 93 | * This method creates a new SQL statement. The default result set type
|
|---|
| 94 | * and concurrency will be used.
|
|---|
| 95 | *
|
|---|
| 96 | * @return A new <code>Statement</code> object.
|
|---|
| 97 | *
|
|---|
| 98 | * @exception SQLException If an error occurs.
|
|---|
| 99 | *
|
|---|
| 100 | * @see Statement
|
|---|
| 101 | */
|
|---|
| 102 | public abstract Statement
|
|---|
| 103 | createStatement() throws SQLException;
|
|---|
| 104 |
|
|---|
| 105 | /*************************************************************************/
|
|---|
| 106 |
|
|---|
| 107 | /**
|
|---|
| 108 | * This method creates a new SQL statement with the specified type and
|
|---|
| 109 | * concurrency. Valid values for these parameters are specified in the
|
|---|
| 110 | * <code>ResultSet</code> class.
|
|---|
| 111 | *
|
|---|
| 112 | * @param resultSetType The type of result set to use for this statement.
|
|---|
| 113 | * @param resultSetConcurrency. The type of concurrency to be used in
|
|---|
| 114 | * the result set for this statement.
|
|---|
| 115 | *
|
|---|
| 116 | * @return A new <code>Statement</code> object.
|
|---|
| 117 | *
|
|---|
| 118 | * @exception SQLException If an error occurs.
|
|---|
| 119 | *
|
|---|
| 120 | * @see Statement
|
|---|
| 121 | * @see ResultSet
|
|---|
| 122 | */
|
|---|
| 123 | public abstract Statement
|
|---|
| 124 | createStatement(int resultSetType, int resultSetConcurrency)
|
|---|
| 125 | throws SQLException;
|
|---|
| 126 |
|
|---|
| 127 | /*************************************************************************/
|
|---|
| 128 |
|
|---|
| 129 | /**
|
|---|
| 130 | * This method creates a new <code>PreparedStatement</code> for the specified
|
|---|
| 131 | * SQL string. This method is designed for use with parameterized
|
|---|
| 132 | * statements. The default result set type and concurrency will be used.
|
|---|
| 133 | *
|
|---|
| 134 | * @param The SQL statement to use in creating this
|
|---|
| 135 | * <code>PreparedStatement</code>.
|
|---|
| 136 | *
|
|---|
| 137 | * @return A new <code>PreparedStatement</code>.
|
|---|
| 138 | *
|
|---|
| 139 | * @exception SQLException If an error occurs.
|
|---|
| 140 | *
|
|---|
| 141 | * @see PreparedStatement
|
|---|
| 142 | */
|
|---|
| 143 | public abstract PreparedStatement
|
|---|
| 144 | prepareStatement(String sql) throws SQLException;
|
|---|
| 145 |
|
|---|
| 146 | /*************************************************************************/
|
|---|
| 147 |
|
|---|
| 148 | /**
|
|---|
| 149 | * This method creates a new <code>PreparedStatement</code> for the specified
|
|---|
| 150 | * SQL string. This method is designed for use with parameterized
|
|---|
| 151 | * statements. The specified result set type and concurrency will be used.
|
|---|
| 152 | * Valid values for these parameters are specified in the
|
|---|
| 153 | * <code>ResultSet</code> class.
|
|---|
| 154 | *
|
|---|
| 155 | * @param The SQL statement to use in creating this
|
|---|
| 156 | * <code>PreparedStatement</code>.
|
|---|
| 157 | * @param resultSetType The type of result set to use for this statement.
|
|---|
| 158 | * @param resultSetConcurrency. The type of concurrency to be used in
|
|---|
| 159 | * the result set for this statement.
|
|---|
| 160 | *
|
|---|
| 161 | * @return A new <code>PreparedStatement</code>.
|
|---|
| 162 | *
|
|---|
| 163 | * @exception SQLException If an error occurs.
|
|---|
| 164 | *
|
|---|
| 165 | * @see PreparedStatement
|
|---|
| 166 | * @see ResultSet
|
|---|
| 167 | */
|
|---|
| 168 | public abstract PreparedStatement
|
|---|
| 169 | prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
|
|---|
| 170 | throws SQLException;
|
|---|
| 171 |
|
|---|
| 172 | /*************************************************************************/
|
|---|
| 173 |
|
|---|
| 174 | /**
|
|---|
| 175 | * This method creates a new <code>CallableStatement</code> for the
|
|---|
| 176 | * specified SQL string. Thie method is designed to be used with
|
|---|
| 177 | * stored procedures. The default result set type and concurrency
|
|---|
| 178 | * will be used.
|
|---|
| 179 | *
|
|---|
| 180 | * @param The SQL statement to use in creating this
|
|---|
| 181 | * <code>CallableStatement</code>.
|
|---|
| 182 | *
|
|---|
| 183 | * @return A new <code>CallableStatement</code>.
|
|---|
| 184 | *
|
|---|
| 185 | * @exception SQLException If an error occurs.
|
|---|
| 186 | *
|
|---|
| 187 | * @see CallableStatement
|
|---|
| 188 | */
|
|---|
| 189 | public abstract CallableStatement
|
|---|
| 190 | prepareCall(String sql) throws SQLException;
|
|---|
| 191 |
|
|---|
| 192 | /*************************************************************************/
|
|---|
| 193 |
|
|---|
| 194 | /**
|
|---|
| 195 | * This method creates a new <code>CallableStatement</code> for the
|
|---|
| 196 | * specified SQL string. Thie method is designed to be used with
|
|---|
| 197 | * stored procedures. The specified result set type and concurrency
|
|---|
| 198 | * will be used. Valid values for these parameters are specified in the
|
|---|
| 199 | * <code>ResultSet</code> class.
|
|---|
| 200 | *
|
|---|
| 201 | * @param The SQL statement to use in creating this
|
|---|
| 202 | * <code>PreparedStatement</code>.
|
|---|
| 203 | * @param resultSetType The type of result set to use for this statement.
|
|---|
| 204 | * @param resultSetConcurrency. The type of concurrency to be used in
|
|---|
| 205 | * the result set for this statement.
|
|---|
| 206 | *
|
|---|
| 207 | * @return A new <code>CallableStatement</code>.
|
|---|
| 208 | *
|
|---|
| 209 | * @exception SQLException If an error occurs.
|
|---|
| 210 | *
|
|---|
| 211 | * @see CallableStatement
|
|---|
| 212 | * @see ResultSet
|
|---|
| 213 | */
|
|---|
| 214 | public abstract CallableStatement
|
|---|
| 215 | prepareCall(String sql, int resultSetType, int resultSetConcurrency)
|
|---|
| 216 | throws SQLException;
|
|---|
| 217 |
|
|---|
| 218 | /*************************************************************************/
|
|---|
| 219 |
|
|---|
| 220 | /**
|
|---|
| 221 | * This method converts the specified generic SQL statement into the
|
|---|
| 222 | * native grammer of the database this object is connected to.
|
|---|
| 223 | *
|
|---|
| 224 | * @param The JDBC generic SQL statement.
|
|---|
| 225 | *
|
|---|
| 226 | * @return The native SQL statement.
|
|---|
| 227 | *
|
|---|
| 228 | * @exception SQLException If an error occurs.
|
|---|
| 229 | */
|
|---|
| 230 | public abstract String
|
|---|
| 231 | nativeSQL(String sql) throws SQLException;
|
|---|
| 232 |
|
|---|
| 233 | /*************************************************************************/
|
|---|
| 234 |
|
|---|
| 235 | /**
|
|---|
| 236 | * This method tests whether or not auto commit mode is currently enabled.
|
|---|
| 237 | * In auto commit mode, every SQL statement is committed its own transaction.
|
|---|
| 238 | * Otherwise a transaction must be explicitly committed or rolled back.
|
|---|
| 239 | *
|
|---|
| 240 | * @return <code>true</code> if auto commit mode is enabled,
|
|---|
| 241 | * <code>false</code> otherwise.
|
|---|
| 242 | *
|
|---|
| 243 | * @exception SQLException If an error occurs.
|
|---|
| 244 | *
|
|---|
| 245 | * @see commit
|
|---|
| 246 | * @see rollback
|
|---|
| 247 | */
|
|---|
| 248 | public abstract boolean
|
|---|
| 249 | getAutoCommit() throws SQLException;
|
|---|
| 250 |
|
|---|
| 251 | /*************************************************************************/
|
|---|
| 252 |
|
|---|
| 253 | /**
|
|---|
| 254 | * This method turns auto commit mode on or off. In auto commit mode,
|
|---|
| 255 | * every SQL statement is committed its own transaction. Otherwise a
|
|---|
| 256 | * transaction must be explicitly committed or rolled back.
|
|---|
| 257 | *
|
|---|
| 258 | * @param autoCommit <code>true</code> to enable auto commit mode,
|
|---|
| 259 | * <code>false</code> to disable it.
|
|---|
| 260 | *
|
|---|
| 261 | * @exception SQLException If an error occurs.
|
|---|
| 262 | *
|
|---|
| 263 | * @see commit
|
|---|
| 264 | * @see rollback
|
|---|
| 265 | */
|
|---|
| 266 | public abstract void
|
|---|
| 267 | setAutoCommit(boolean autoCommit) throws SQLException;
|
|---|
| 268 |
|
|---|
| 269 | /*************************************************************************/
|
|---|
| 270 |
|
|---|
| 271 | /**
|
|---|
| 272 | * This method commits any SQL statements executed on this connection since
|
|---|
| 273 | * the last commit or rollback.
|
|---|
| 274 | *
|
|---|
| 275 | * @exception SQLException If an error occurs.
|
|---|
| 276 | */
|
|---|
| 277 | public abstract void
|
|---|
| 278 | commit() throws SQLException;
|
|---|
| 279 |
|
|---|
| 280 | /*************************************************************************/
|
|---|
| 281 |
|
|---|
| 282 | /**
|
|---|
| 283 | * This method rolls back any SQL statements executed on this connection
|
|---|
| 284 | * since the last commit or rollback.
|
|---|
| 285 | *
|
|---|
| 286 | * @exception SQLException If an error occurs.
|
|---|
| 287 | */
|
|---|
| 288 | public abstract void
|
|---|
| 289 | rollback() throws SQLException;
|
|---|
| 290 |
|
|---|
| 291 | /*************************************************************************/
|
|---|
| 292 |
|
|---|
| 293 | /**
|
|---|
| 294 | * This method immediately closes this database connection.
|
|---|
| 295 | *
|
|---|
| 296 | * @exception SQLException If an error occurs.
|
|---|
| 297 | */
|
|---|
| 298 | public abstract void
|
|---|
| 299 | close() throws SQLException;
|
|---|
| 300 |
|
|---|
| 301 | /*************************************************************************/
|
|---|
| 302 |
|
|---|
| 303 | /**
|
|---|
| 304 | * This method tests whether or not this connection has been closed.
|
|---|
| 305 | *
|
|---|
| 306 | * @return <code>true</code> if the connection is closed, <code>false</code>
|
|---|
| 307 | * otherwise.
|
|---|
| 308 | *
|
|---|
| 309 | * @exception SQLException If an error occurs.
|
|---|
| 310 | */
|
|---|
| 311 | public abstract boolean
|
|---|
| 312 | isClosed() throws SQLException;
|
|---|
| 313 |
|
|---|
| 314 | /*************************************************************************/
|
|---|
| 315 |
|
|---|
| 316 | /**
|
|---|
| 317 | * This method returns the meta data for this database connection.
|
|---|
| 318 | *
|
|---|
| 319 | * @return The meta data for this database.
|
|---|
| 320 | *
|
|---|
| 321 | * @exception SQLException If an error occurs.
|
|---|
| 322 | *
|
|---|
| 323 | * @see DatabaseMetaData
|
|---|
| 324 | */
|
|---|
| 325 | public abstract DatabaseMetaData
|
|---|
| 326 | getMetaData() throws SQLException;
|
|---|
| 327 |
|
|---|
| 328 | /*************************************************************************/
|
|---|
| 329 |
|
|---|
| 330 | /**
|
|---|
| 331 | * This method tests whether or not this connection is in read only mode.
|
|---|
| 332 | *
|
|---|
| 333 | * @return <code>true</code> if the connection is read only <code>false</code>
|
|---|
| 334 | * otherwise.
|
|---|
| 335 | *
|
|---|
| 336 | * @exception SQLException If an error occurs.
|
|---|
| 337 | */
|
|---|
| 338 | public abstract boolean
|
|---|
| 339 | isReadOnly() throws SQLException;
|
|---|
| 340 |
|
|---|
| 341 | /*************************************************************************/
|
|---|
| 342 |
|
|---|
| 343 | /**
|
|---|
| 344 | * This method turns read only mode on or off. It may not be called while
|
|---|
| 345 | * a transaction is in progress.
|
|---|
| 346 | *
|
|---|
| 347 | * @param readOnly <code>true</code> if this connection is read only,
|
|---|
| 348 | * <code>false</code> otherwise.
|
|---|
| 349 | *
|
|---|
| 350 | * @exception SQLException If an error occurs.
|
|---|
| 351 | */
|
|---|
| 352 | public abstract void
|
|---|
| 353 | setReadOnly(boolean readOnly) throws SQLException;
|
|---|
| 354 |
|
|---|
| 355 | /*************************************************************************/
|
|---|
| 356 |
|
|---|
| 357 | /**
|
|---|
| 358 | * This method returns the name of the catalog in use by this connection,
|
|---|
| 359 | * if any.
|
|---|
| 360 | *
|
|---|
| 361 | * @return The name of the catalog, or <code>null</code> if one does not
|
|---|
| 362 | * exist or catalogs are not supported by this database.
|
|---|
| 363 | *
|
|---|
| 364 | * @exception SQLException If an error occurs.
|
|---|
| 365 | */
|
|---|
| 366 | public abstract String
|
|---|
| 367 | getCatalog() throws SQLException;
|
|---|
| 368 |
|
|---|
| 369 | /*************************************************************************/
|
|---|
| 370 |
|
|---|
| 371 | /**
|
|---|
| 372 | * This method sets the name of the catalog in use by this connection.
|
|---|
| 373 | * Note that this method does nothing if catalogs are not supported by
|
|---|
| 374 | * this database.
|
|---|
| 375 | *
|
|---|
| 376 | * @param catalog The name of the catalog to use for this connection.
|
|---|
| 377 | *
|
|---|
| 378 | * @exception SQLException If an error occurs.
|
|---|
| 379 | */
|
|---|
| 380 | public abstract void
|
|---|
| 381 | setCatalog(String catalog) throws SQLException;
|
|---|
| 382 |
|
|---|
| 383 | /*************************************************************************/
|
|---|
| 384 |
|
|---|
| 385 | /**
|
|---|
| 386 | * This method returns the current transaction isolation mode. This will
|
|---|
| 387 | * be one of the constants defined in this interface.
|
|---|
| 388 | *
|
|---|
| 389 | * @return The transaction isolation level.
|
|---|
| 390 | *
|
|---|
| 391 | * @exception SQLException If an error occurs.
|
|---|
| 392 | */
|
|---|
| 393 | public abstract int
|
|---|
| 394 | getTransactionIsolation() throws SQLException;
|
|---|
| 395 |
|
|---|
| 396 | /*************************************************************************/
|
|---|
| 397 |
|
|---|
| 398 | /**
|
|---|
| 399 | * This method sets the current transaction isolation mode. This must
|
|---|
| 400 | * be one of the constants defined in this interface.
|
|---|
| 401 | *
|
|---|
| 402 | * @param level The transaction isolation level.
|
|---|
| 403 | *
|
|---|
| 404 | * @exception SQLException If an error occurs.
|
|---|
| 405 | */
|
|---|
| 406 | public abstract void
|
|---|
| 407 | setTransactionIsolation(int level) throws SQLException;
|
|---|
| 408 |
|
|---|
| 409 | /*************************************************************************/
|
|---|
| 410 |
|
|---|
| 411 | /**
|
|---|
| 412 | * This method returns the first warning that occurred on this connection,
|
|---|
| 413 | * if any. If there were any subsequence warnings, they will be chained
|
|---|
| 414 | * to the first one.
|
|---|
| 415 | *
|
|---|
| 416 | * @return The first <code>SQLWarning</code> that occurred, or
|
|---|
| 417 | * <code>null</code> if there have been no warnings.
|
|---|
| 418 | *
|
|---|
| 419 | * @exception SQLException If an error occurs.
|
|---|
| 420 | */
|
|---|
| 421 | public abstract SQLWarning
|
|---|
| 422 | getWarnings() throws SQLException;
|
|---|
| 423 |
|
|---|
| 424 | /*************************************************************************/
|
|---|
| 425 |
|
|---|
| 426 | /**
|
|---|
| 427 | * This method clears all warnings that have occurred on this connection.
|
|---|
| 428 | *
|
|---|
| 429 | * @exception SQLException If an error occurs.
|
|---|
| 430 | */
|
|---|
| 431 | public abstract void
|
|---|
| 432 | clearWarnings() throws SQLException;
|
|---|
| 433 |
|
|---|
| 434 | /*************************************************************************/
|
|---|
| 435 |
|
|---|
| 436 | /**
|
|---|
| 437 | * This method returns the mapping of SQL types to Java classes
|
|---|
| 438 | * currently in use by this connection. This mapping will have no
|
|---|
| 439 | * entries unless they have been manually added.
|
|---|
| 440 | *
|
|---|
| 441 | * @return The SQL type to Java class mapping.
|
|---|
| 442 | *
|
|---|
| 443 | * @exception SQLException If an error occurs.
|
|---|
| 444 | */
|
|---|
| 445 | public abstract Map
|
|---|
| 446 | getTypeMap() throws SQLException;
|
|---|
| 447 |
|
|---|
| 448 | /*************************************************************************/
|
|---|
| 449 |
|
|---|
| 450 | /**
|
|---|
| 451 | * This method sets the mapping table for SQL types to Java classes.
|
|---|
| 452 | * Any entries in this map override the defaults.
|
|---|
| 453 | *
|
|---|
| 454 | * @param map The new SQL mapping table.
|
|---|
| 455 | *
|
|---|
| 456 | * @exception SQLException If an error occurs.
|
|---|
| 457 | */
|
|---|
| 458 | public abstract void
|
|---|
| 459 | setTypeMap(Map map) throws SQLException;
|
|---|
| 460 |
|
|---|
| 461 | } // interface Connection
|
|---|
| 462 |
|
|---|