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 org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
019    import org.apache.ojb.broker.platforms.Platform;
020    
021    import java.sql.Connection;
022    
023    /**
024     * The connection manager handles the life cycle of a connection.
025     * Each {@link org.apache.ojb.broker.PersistenceBroker} instance
026     * use it's own connection manager.
027     */
028    public interface ConnectionManagerIF
029    {
030    
031        /**
032         * Return the associated {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}.
033         */
034        JdbcConnectionDescriptor getConnectionDescriptor();
035    
036        /**
037         * Returns the supported {@link org.apache.ojb.broker.platforms.Platform}
038         * determined by the {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}.
039         * @see #getConnectionDescriptor
040         */
041        Platform getSupportedPlatform();
042    
043        /**
044         * checks if Connection conn is still open.
045         * returns true, if connection is open, else false.
046         */
047        boolean isAlive(Connection conn);
048    
049        /**
050         * Return a connection.
051         */
052        Connection getConnection() throws LookupException;
053    
054        /**
055         * Hold connection is in local transaction.
056         */
057        boolean isInLocalTransaction();
058    
059        /**
060         * Begin local transaction on the hold connection
061         * and set autocommit to false.
062         */
063        void localBegin();
064    
065        /**
066         * Commit the local transaction on the hold connection.
067         */
068        void localCommit();
069    
070        /**
071         * Rollback a changes on the hold connection.
072         */
073        void localRollback();
074    
075        /**
076         * Release the hold connection.
077         */
078        void releaseConnection();
079    
080        /**
081         * Sets the batch mode on (<code>true</code>) or
082         * off (<code>false</code>).
083         */
084        void setBatchMode(boolean mode);
085    
086        /**
087         * @return the batch mode.
088         */
089        boolean isBatchMode();
090    
091        /**
092         * Execute batch (if the batch mode where used).
093         */
094        void executeBatch();
095    
096        /**
097         * Execute batch if the number of statements in it
098         * exceeded the limit (if the batch mode where used).
099         */
100        void executeBatchIfNecessary();
101    
102        /**
103         * Clear batch (if the batch mode where used).
104         */
105        void clearBatch();
106    
107    }