726N/A/*
726N/A * CDDL HEADER START
726N/A *
726N/A * The contents of this file are subject to the terms of the
726N/A * Common Development and Distribution License (the "License").
726N/A * You may not use this file except in compliance with the License.
726N/A *
726N/A * See LICENSE.txt included in this distribution for the specific
726N/A * language governing permissions and limitations under the License.
726N/A *
726N/A * When distributing Covered Code, include this CDDL HEADER in each
726N/A * file and include the License file at LICENSE.txt.
726N/A * If applicable, add the following below this CDDL HEADER, with the
726N/A * fields enclosed by brackets "[]" replaced with your own identifying
726N/A * information: Portions Copyright [yyyy] [name of copyright owner]
726N/A *
726N/A * CDDL HEADER END
726N/A */
726N/A
726N/A/*
726N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
726N/A * Use is subject to license terms.
726N/A */
726N/A
726N/Apackage org.opensolaris.opengrok.jdbc;
726N/A
726N/Aimport java.sql.Connection;
726N/Aimport java.sql.PreparedStatement;
726N/Aimport java.sql.ResultSet;
726N/Aimport java.sql.SQLException;
726N/A
726N/A/**
726N/A * A {@code StatementCreator} for statements that create {@code ResultSet}s
726N/A * with specified type, concurrency and holdability.
726N/A */
726N/Apublic final class PreparedQuery extends StatementCreator {
726N/A private final String sql;
726N/A private final int resultSetType;
726N/A private final int resultSetConcurrency;
726N/A private final int resultSetHoldability;
726N/A
726N/A /**
726N/A * Creator for a statement which returns forward-only, read-only,
726N/A * non-holdable result sets.
726N/A *
726N/A * @param sql the SQL text for the statement
726N/A */
726N/A public PreparedQuery(String sql) {
726N/A this(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
726N/A }
726N/A
726N/A /**
726N/A * Creator for a statement which returns non-holdable result sets with
726N/A * the specified type and concurrency.
726N/A *
726N/A * @param sql the SQL text for the statement
726N/A * @param resultSetType the type of the result set
726N/A * @param resultSetConcurrency the concurrency of the result set
726N/A */
726N/A public PreparedQuery(String sql, int resultSetType,
726N/A int resultSetConcurrency) {
726N/A this(sql, resultSetType, resultSetConcurrency,
726N/A ResultSet.CLOSE_CURSORS_AT_COMMIT);
726N/A }
726N/A
726N/A /**
726N/A * Creator for a statement which returns result sets with the specified
726N/A * type, concurrency and holdability.
726N/A *
726N/A * @param sql the SQL text for the statement
726N/A * @param resultSetType the type of the result set
726N/A * @param resultSetConcurrency the concurrency of the result set
726N/A * @param resultSetHoldability the holdability of the result set
726N/A */
726N/A public PreparedQuery(String sql, int resultSetType,
726N/A int resultSetConcurrency, int resultSetHoldability) {
726N/A this.sql = sql;
726N/A this.resultSetType = resultSetType;
726N/A this.resultSetConcurrency = resultSetConcurrency;
726N/A this.resultSetHoldability = resultSetHoldability;
726N/A }
726N/A
726N/A @Override
726N/A PreparedStatement create(Connection conn) throws SQLException {
726N/A return conn.prepareStatement(
726N/A sql, resultSetType, resultSetConcurrency, resultSetHoldability);
726N/A }
726N/A}