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 |
} |