001    package org.apache.ojb.broker.accesslayer;
002    
003    /* Copyright 2002-2005 The Apache Software Foundation
004     *
005     * Licensed under the Apache License, Version 2.0 (the "License");
006     * you may not use this file except in compliance with the License.
007     * You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    
018    import java.sql.PreparedStatement;
019    import java.sql.ResultSet;
020    import java.sql.SQLException;
021    import java.sql.Statement;
022    
023    import org.apache.ojb.broker.Identity;
024    import org.apache.ojb.broker.PersistenceBrokerException;
025    import org.apache.ojb.broker.PersistenceBrokerSQLException;
026    import org.apache.ojb.broker.core.ValueContainer;
027    import org.apache.ojb.broker.metadata.ClassDescriptor;
028    import org.apache.ojb.broker.query.Query;
029    
030    /**
031     * @version $Id: StatementManagerIF.java,v 1.1 2007-08-24 22:17:30 ewestfal Exp $
032     */
033    public interface StatementManagerIF
034    {
035    
036        /** fetchSize hint marking that setting fetch size for current statement is N/A. */
037        int FETCH_SIZE_NOT_APPLICABLE = -1;
038        /** fetchSize hint marking that there is no statement-level explicit override. */
039        int FETCH_SIZE_NOT_EXPLICITLY_SET = 0;
040    
041        /**
042         * Binds the Identities Primary key values to the statement.
043         * @param stmt
044         * @param oid
045         * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
046         */
047        void bindDelete(PreparedStatement stmt, Identity oid, ClassDescriptor cld) throws java.sql.SQLException;
048        /**
049         * binds the objects primary key and locking values to the statement, BRJ
050         */
051        void bindDelete(PreparedStatement stmt, ClassDescriptor cld, Object obj)
052            throws java.sql.SQLException;
053    
054        /**
055         * bind a Query based Select Statement
056         */
057        int bindStatement(PreparedStatement stmt, Query query, ClassDescriptor cld, int param)
058            throws SQLException;
059    
060        /**
061         * binds the values of the object obj to the statements parameters
062         */
063        void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj)
064                    throws SQLException;
065        /**
066         * binds the Identities Primary key values to the statement
067         * @param stmt
068         * @param oid
069         * @param cld ClassDescriptor for the Object, if <i>null</i> will be lookup automatic
070         * @param callableStmt Indicate if the specified {@link java.sql.PreparedStatement}
071         * is a {@link java.sql.CallableStatement} supporting stored procedures.
072         */
073        void bindSelect(PreparedStatement stmt, Identity oid, ClassDescriptor cld, boolean callableStmt) throws SQLException;
074        /**
075         * binds the values of the object obj to the statements parameters
076         */
077        void bindUpdate(PreparedStatement stmt, ClassDescriptor cld, Object obj)
078            throws SQLException;
079    
080        /**
081         * binds the given array of values (if not null) starting from the given
082         * parameter index
083         * @return the next parameter index
084         */
085        int bindValues(PreparedStatement stmt, ValueContainer[] valueContainer, int index) throws SQLException;
086    
087        /**
088         * return a prepared DELETE Statement fitting for the given ClassDescriptor
089         */
090        PreparedStatement getDeleteStatement(ClassDescriptor cds)
091            throws PersistenceBrokerSQLException;
092        /**
093         * return a generic Statement for the given ClassDescriptor
094         */
095        Statement getGenericStatement(ClassDescriptor cds, boolean scrollable) throws PersistenceBrokerException;
096        /**
097         * return a prepared Insert Statement fitting for the given ClassDescriptor
098         */
099        PreparedStatement getInsertStatement(ClassDescriptor cds)
100            throws PersistenceBrokerSQLException;
101        /**
102         * Return a PreparedStatement for selecting against the given ClassDescriptor.
103         */
104        PreparedStatement getPreparedStatement(ClassDescriptor cds, String sql,
105                                               boolean scrollable, int explicitFetchSizeHint, boolean callableStmt)
106            throws PersistenceBrokerException;
107        /**
108         * return a prepared Select Statement for the given ClassDescriptor
109         */
110        PreparedStatement getSelectByPKStatement(ClassDescriptor cds)
111            throws PersistenceBrokerSQLException;
112        /**
113         * return a prepared Update Statement fitting to the given ClassDescriptor
114         */
115        PreparedStatement getUpdateStatement(ClassDescriptor cds)
116            throws PersistenceBrokerSQLException;
117    
118        public void closeResources(Statement stmt, ResultSet rs);
119    
120    }