View | Details | Raw Unified | Return to bug 51264
Collapse All | Expand All

(-)a/java/org/apache/catalina/session/JDBCStore.java (-25 / +48 lines)
Lines 711-726 public class JDBCStore extends StoreBase { Link Here
711
                }
711
                }
712
712
713
                try {
713
                try {
714
                    if (preparedRemoveSql == null) {
714
                    remove(id, _conn);
715
                        String removeSql = "DELETE FROM " + sessionTable
716
                                + " WHERE " + sessionIdCol + " = ?  AND "
717
                                + sessionAppCol + " = ?";
718
                        preparedRemoveSql = _conn.prepareStatement(removeSql);
719
                    }
720
721
                    preparedRemoveSql.setString(1, id);
722
                    preparedRemoveSql.setString(2, getName());
723
                    preparedRemoveSql.execute();
724
                    // Break out after the finally block
715
                    // Break out after the finally block
725
                    numberOfTries = 0;
716
                    numberOfTries = 0;
726
                } catch (SQLException e) {
717
                } catch (SQLException e) {
Lines 740-745 public class JDBCStore extends StoreBase { Link Here
740
    }
731
    }
741
732
742
    /**
733
    /**
734
     * Remove the Session with the specified session identifier from
735
     * this Store, if present.  If no such Session is present, this method
736
     * takes no action.
737
     * 
738
     * @param id Session identifier of the Session to be removed
739
     * @param _conn open connection to be used
740
     * @throws SQLException if an error occurs while talking to the database
741
     */
742
    private void remove(String id, Connection _conn) throws SQLException {
743
        if (preparedRemoveSql == null) {
744
            String removeSql = "DELETE FROM " + sessionTable
745
                    + " WHERE " + sessionIdCol + " = ?  AND "
746
                    + sessionAppCol + " = ?";
747
            preparedRemoveSql = _conn.prepareStatement(removeSql);
748
        }
749
750
        preparedRemoveSql.setString(1, id);
751
        preparedRemoveSql.setString(2, getName());
752
        preparedRemoveSql.execute();
753
    }
754
755
    /**
743
     * Remove all of the Sessions in this Store.
756
     * Remove all of the Sessions in this Store.
744
     *
757
     *
745
     * @exception IOException if an input/output error occurs
758
     * @exception IOException if an input/output error occurs
Lines 799-810 public class JDBCStore extends StoreBase { Link Here
799
                    return;
812
                    return;
800
                }
813
                }
801
814
802
                // If sessions already exist in DB, remove and insert again.
803
                // TODO:
804
                // * Check if ID exists in database and if so use UPDATE.
805
                remove(session.getIdInternal());
806
807
                try {
815
                try {
816
                    // If sessions already exist in DB, remove and insert again.
817
                    // TODO:
818
                    // * Check if ID exists in database and if so use UPDATE.
819
                    remove(session.getIdInternal(), _conn);
820
                    
808
                    bos = new ByteArrayOutputStream();
821
                    bos = new ByteArrayOutputStream();
809
                    oos = new ObjectOutputStream(new BufferedOutputStream(bos));
822
                    oos = new ObjectOutputStream(new BufferedOutputStream(bos));
810
823
Lines 874-884 public class JDBCStore extends StoreBase { Link Here
874
     * @return <code>Connection</code> if the connection succeeded
887
     * @return <code>Connection</code> if the connection succeeded
875
     */
888
     */
876
    protected Connection getConnection() {
889
    protected Connection getConnection() {
890
        Connection _conn = null;
877
        try {
891
        try {
878
            if (dbConnection == null || dbConnection.isClosed()) {
892
            _conn = open();
893
            if (_conn == null || _conn.isClosed()) {
879
                manager.getContainer().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBClosed"));
894
                manager.getContainer().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBClosed"));
880
                open();
895
                _conn = open();
881
                if (dbConnection == null || dbConnection.isClosed()) {
896
                if (_conn == null || _conn.isClosed()) {
882
                    manager.getContainer().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBReOpenFail"));
897
                    manager.getContainer().getLogger().info(sm.getString(getStoreName() + ".checkConnectionDBReOpenFail"));
883
                }
898
                }
884
            }
899
            }
Lines 887-893 public class JDBCStore extends StoreBase { Link Here
887
                    ex.toString()));
902
                    ex.toString()));
888
        }
903
        }
889
904
890
        return dbConnection;
905
        return _conn;
891
    }
906
    }
892
907
893
    /**
908
    /**
Lines 916-923 public class JDBCStore extends StoreBase { Link Here
916
        }
931
        }
917
        
932
        
918
        if (dataSource != null) {
933
        if (dataSource != null) {
919
            dbConnection = dataSource.getConnection();
934
            Connection _conn = dataSource.getConnection();
920
            return dbConnection;
935
            return _conn;
921
        }
936
        }
922
937
923
        // Instantiate our database driver if necessary
938
        // Instantiate our database driver if necessary
Lines 1014-1026 public class JDBCStore extends StoreBase { Link Here
1014
    }
1029
    }
1015
1030
1016
    /**
1031
    /**
1017
     * Release the connection, not needed here since the
1032
     * Release the connection, if it
1018
     * connection is not associated with a connection pool.
1033
     * is associated with a connection pool.
1019
     *
1034
     *
1020
     * @param conn The connection to be released
1035
     * @param conn The connection to be released
1021
     */
1036
     */
1022
    protected void release(Connection conn) {
1037
    protected void release(Connection conn) {
1023
        // NOOP
1038
        if (dataSource != null) {
1039
            close(conn); 
1040
        }
1024
    }
1041
    }
1025
1042
1026
    /**
1043
    /**
Lines 1034-1040 public class JDBCStore extends StoreBase { Link Here
1034
    protected synchronized void startInternal() throws LifecycleException {
1051
    protected synchronized void startInternal() throws LifecycleException {
1035
1052
1036
        // Open connection to the database
1053
        // Open connection to the database
1037
        this.dbConnection = getConnection();
1054
        Connection _conn = getConnection();
1055
        if (dataSource != null) {
1056
            // if connection was created by a dataSource, we will release it
1057
            close(_conn);
1058
        } else {
1059
            this.dbConnection = _conn;
1060
        }
1038
        
1061
        
1039
        super.startInternal();
1062
        super.startInternal();
1040
    }
1063
    }
(-)a/java/org/apache/catalina/session/LocalStrings.properties (-1 / +1 lines)
Lines 27-33 JDBCStore.checkConnectionDBClosed=The database connection is null or was found t Link Here
27
JDBCStore.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.
27
JDBCStore.checkConnectionDBReOpenFail=The re-open on the database failed. The database could be down.
28
JDBCStore.checkConnectionSQLException=A SQL exception occurred {0}
28
JDBCStore.checkConnectionSQLException=A SQL exception occurred {0}
29
JDBCStore.checkConnectionClassNotFoundException=JDBC driver class not found {0}
29
JDBCStore.checkConnectionClassNotFoundException=JDBC driver class not found {0}
30
JDBCStore.wrongDataSource=Can't open JNDI DataSource [{0}]
30
JDBCStore.wrongDataSource=Can not open JNDI DataSource [{0}]
31
JDBCStore.missingDataSourceName=No valid JNDI name was given.
31
JDBCStore.missingDataSourceName=No valid JNDI name was given.
32
managerBase.createRandom=Created random number generator for session ID generation in {0}ms.
32
managerBase.createRandom=Created random number generator for session ID generation in {0}ms.
33
managerBase.createSession.ise=createSession: Too many active sessions
33
managerBase.createSession.ise=createSession: Too many active sessions
(-)a/webapps/docs/config/manager.xml (-1 / +4 lines)
Lines 360-366 Link Here
360
      <p>Name of the JNDI resource for a JDBC DataSource-factory. If this option
360
      <p>Name of the JNDI resource for a JDBC DataSource-factory. If this option
361
      is given and a valid JDBC resource can be found, it will be used and any
361
      is given and a valid JDBC resource can be found, it will be used and any
362
      direct configuration of a JDBC connection via <code>connectionURL</code>
362
      direct configuration of a JDBC connection via <code>connectionURL</code>
363
      and <code>driverName</code> will be ignored.</p>
363
      and <code>driverName</code> will be ignored. Since this code uses prepared
364
      statements, you might want to configure pooled prepared statements as
365
      shown in <a href="../jndi-resources-howto.html">the JNDI resources
366
      HOW-TO</a>.</p>
364
    </attribute>
367
    </attribute>
365
368
366
    <attribute name="driverName" required="true">
369
    <attribute name="driverName" required="true">

Return to bug 51264