ConnectionResource.java revision 747
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/**
* Class that manages the resources associated with a database connection.
* This includes a cache of {@code PreparedStatement}s.
*/
public class ConnectionResource {
/** The connection to the database. */
private final Connection conn;
/** Statement cache. */
/**
* Create a new {@code ConnectionResource} instance.
* @param manager the {@code ConnectionManager} that created this object
* @throws SQLException if an error occurs when connecting to the database
*/
conn.setAutoCommit(false);
}
/**
* Commit the transaction.
* @throws SQLException if a database error occurs
*/
public void commit() throws SQLException {
}
/**
* Abort the transaction.
* @throws SQLException if a database error occurs
*/
public void rollback() throws SQLException {
}
/**
* Get a {@code PreparedStatement} as defined by the specified
* {@code StatementCreator}. If it is the first time the statement
* creator is used on this {@code ConnectionResource}, the creator's
* {@link StatementCreator#create(Connection)} method is called to
* create a new {@code PreparedStatement}. This statement is cached,
* so that on subsequent calls with the same statement creator, the same
* {@code PreparedStatement} will be returned.
*
* @param creator object that specifies how to create the statement if
* necessary
* @return a {@code PreparedStatement} object
* @throws SQLException if a database error occurs
*/
throws SQLException {
// Should also check isClosed() here, but it's only available in
// JDK 6, so we can't. Anyway, callers shouldn't close the
// statements they get from this method.
}
return ps;
}
/**
* Create a new {@code Statement} object.
* @return a {@code Statement} object
* @throws java.sql.SQLException
*/
return conn.createStatement();
}
/**
* Prepare a statement. This method should only be used to prepare
* statements that are used infrequently. If a statement is likely to
* be used frequently, a {@code StatementCreator} object should be
* created for it, and the method {@link #getStatement(StatementCreator)}
* should be used instead.
*
* @param sql the SQL text to compile
* @return a prepared statement
* @throws SQLException if a database error occurs
*/
}
/**
* Get a meta-data object for the underlying connection.
*
* @return a {@code DatabaseMetaData} object
* @throws SQLException if a database error occurs
*/
return conn.getMetaData();
}
}