Lines 38-43
Link Here
|
38 |
import java.sql.SQLException; |
38 |
import java.sql.SQLException; |
39 |
import java.util.ArrayList; |
39 |
import java.util.ArrayList; |
40 |
import java.util.Properties; |
40 |
import java.util.Properties; |
|
|
41 |
import javax.naming.Context; |
42 |
import javax.naming.InitialContext; |
43 |
import javax.naming.NamingException; |
44 |
import javax.sql.DataSource; |
41 |
|
45 |
|
42 |
/** |
46 |
/** |
43 |
* Implementation of the <code>Store</code> interface that stores |
47 |
* Implementation of the <code>Store</code> interface that stores |
Lines 72-77
Link Here
|
72 |
protected String threadName = "JDBCStore"; |
76 |
protected String threadName = "JDBCStore"; |
73 |
|
77 |
|
74 |
/** |
78 |
/** |
|
|
79 |
* The connection datasource |
80 |
*/ |
81 |
private String datasourceName = null; |
82 |
|
83 |
/** |
75 |
* The connection username to use when trying to connect to the database. |
84 |
* The connection username to use when trying to connect to the database. |
76 |
*/ |
85 |
*/ |
77 |
protected String connectionName = null; |
86 |
protected String connectionName = null; |
Lines 101-106
Link Here
|
101 |
* Driver to use. |
110 |
* Driver to use. |
102 |
*/ |
111 |
*/ |
103 |
protected String driverName = null; |
112 |
protected String driverName = null; |
|
|
113 |
|
114 |
/** |
115 |
* Data source to use. |
116 |
*/ |
117 |
private DataSource datasource = null; |
104 |
|
118 |
|
105 |
// ------------------------------------------------------------- Table & cols |
119 |
// ------------------------------------------------------------- Table & cols |
106 |
|
120 |
|
Lines 217-222
Link Here
|
217 |
} |
231 |
} |
218 |
|
232 |
|
219 |
/** |
233 |
/** |
|
|
234 |
* Return the datasource name to use to connect to the database. |
235 |
* |
236 |
*/ |
237 |
public String getDatasourceName() { |
238 |
return datasourceName; |
239 |
} |
240 |
|
241 |
/** |
242 |
* Set the datasource name to use to connect to the database. |
243 |
* |
244 |
* @param datasourceName datasource name |
245 |
*/ |
246 |
public void setDatasourceName(String datasourceName) { |
247 |
this.datasourceName = datasourceName; |
248 |
} |
249 |
|
250 |
/** |
220 |
* Set the driver for this Store. |
251 |
* Set the driver for this Store. |
221 |
* |
252 |
* |
222 |
* @param driverName The new driver |
253 |
* @param driverName The new driver |
Lines 850-857
Link Here
|
850 |
* @exception SQLException if a database error occurs |
881 |
* @exception SQLException if a database error occurs |
851 |
*/ |
882 |
*/ |
852 |
protected Connection open() throws SQLException { |
883 |
protected Connection open() throws SQLException { |
|
|
884 |
if (datasourceName == null) { |
885 |
dbConnection = openDirectConnection(); |
886 |
} else { |
887 |
dbConnection = openJNDIConnection(); |
888 |
} |
889 |
return dbConnection; |
890 |
} |
853 |
|
891 |
|
|
|
892 |
/** |
893 |
* Open (if necessary) and return a database connection for use by |
894 |
* this Realm. |
895 |
* |
896 |
* @exception SQLException if a database error occurs |
897 |
*/ |
898 |
protected Connection openJNDIConnection() throws SQLException { |
899 |
|
854 |
// Do nothing if there is a database connection already open |
900 |
// Do nothing if there is a database connection already open |
|
|
901 |
if (dbConnection != null && !dbConnection.isClosed()) |
902 |
return (dbConnection); |
903 |
|
904 |
try { |
905 |
Context initialContext = new InitialContext(); |
906 |
if (datasource == null) { |
907 |
manager.getContainer().getLogger().info("Lookup datasource " + datasourceName); |
908 |
datasource = (DataSource)initialContext.lookup(datasourceName); |
909 |
} |
910 |
return datasource.getConnection(); |
911 |
} catch (NamingException ex) { |
912 |
throw new SQLException("Unable to get datasource " + |
913 |
datasourceName + " : " + ex.getMessage()); |
914 |
} |
915 |
|
916 |
} |
917 |
|
918 |
|
919 |
/** |
920 |
* Open (if necessary) and return a database connection for use by |
921 |
* this Realm. |
922 |
* |
923 |
* @exception SQLException if a database error occurs |
924 |
*/ |
925 |
protected Connection openDirectConnection() throws SQLException { |
926 |
|
927 |
// Do nothing if there is a database connection already open |
855 |
if (dbConnection != null) |
928 |
if (dbConnection != null) |
856 |
return (dbConnection); |
929 |
return (dbConnection); |
857 |
|
930 |
|
Lines 955-961
Link Here
|
955 |
* @param conn The connection to be released |
1028 |
* @param conn The connection to be released |
956 |
*/ |
1029 |
*/ |
957 |
protected void release(Connection conn) { |
1030 |
protected void release(Connection conn) { |
958 |
; |
1031 |
if (datasourceName != null) { |
|
|
1032 |
close(conn); |
1033 |
} |
959 |
} |
1034 |
} |
960 |
|
1035 |
|
961 |
/** |
1036 |
/** |
Lines 965-971
Link Here
|
965 |
super.start(); |
1040 |
super.start(); |
966 |
|
1041 |
|
967 |
// Open connection to the database |
1042 |
// Open connection to the database |
968 |
this.dbConnection = getConnection(); |
1043 |
if (datasourceName == null) { |
|
|
1044 |
this.dbConnection = getConnection(); |
1045 |
} |
969 |
} |
1046 |
} |
970 |
|
1047 |
|
971 |
/** |
1048 |
/** |