diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2008-04-06 03:29:55 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2008-04-06 03:29:55 +0000 |
commit | 1754d1a15b4c49d6c89308697fe7a316b4ab766e (patch) | |
tree | 10a89bc318c2ed892edc3202bd946ff6e680f06f /src/main/java/com/amazon/carbonado/repo | |
parent | 7fb45fe50435142eaf3940e4e2d4ef7df906d640 (diff) |
Add more constructors.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r-- | src/main/java/com/amazon/carbonado/repo/jdbc/SimpleDataSource.java | 73 |
1 files changed, 59 insertions, 14 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/SimpleDataSource.java b/src/main/java/com/amazon/carbonado/repo/jdbc/SimpleDataSource.java index fb01b4b..2179201 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/SimpleDataSource.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/SimpleDataSource.java @@ -37,24 +37,69 @@ public class SimpleDataSource implements DataSource { private PrintWriter mLogWriter;
+ /**
+ * @param driverClass JDBC driver to load; can pass null if already loaded
+ * @param driverURL JDBC driver URL
+ * @param properties optional connection properties
+ * @since 1.2
+ */
+ public SimpleDataSource(String driverClass, String driverURL, Properties properties)
+ throws SQLException
+ {
+ this(driverClass, driverURL, null, null, properties);
+ }
+
+ /**
+ * @param driverClass JDBC driver to load; can pass null if already loaded
+ * @param driverURL JDBC driver URL
+ * @param username optional username to connect with
+ * @param password optional password to connect with
+ */
public SimpleDataSource(String driverClass, String driverURL, String username, String password)
throws SQLException
{
- try {
- Class.forName(driverClass);
- } catch (ClassNotFoundException e) {
- SQLException e2 = new SQLException();
- e2.initCause(e);
- throw e2;
+ this(driverClass, driverURL, username, password, null);
+ }
+
+ /**
+ * @param driverClass JDBC driver to load; can pass null if already loaded
+ * @param driverURL JDBC driver URL
+ * @param username optional username to connect with
+ * @param password optional password to connect with
+ * @param properties optional connection properties
+ * @since 1.2
+ */
+ public SimpleDataSource(String driverClass, String driverURL, String username, String password,
+ Properties properties)
+ throws SQLException
+ {
+ if (driverURL == null) {
+ throw new IllegalArgumentException("Must supply JDBC URL");
}
- mURL = driverURL;
- mProperties = new Properties();
+
+ if (driverClass != null) {
+ try {
+ Class.forName(driverClass);
+ } catch (ClassNotFoundException e) {
+ SQLException e2 = new SQLException();
+ e2.initCause(e);
+ throw e2;
+ }
+ }
+
+ if (properties == null) {
+ properties = new Properties();
+ }
+
if (username != null) {
- mProperties.put("user", username);
+ properties.put("user", username);
}
if (password != null) {
- mProperties.put("password", password);
+ properties.put("password", password);
}
+
+ mURL = driverURL;
+ mProperties = properties;
}
public Connection getConnection() throws SQLException {
@@ -62,14 +107,14 @@ public class SimpleDataSource implements DataSource { }
public Connection getConnection(String username, String password) throws SQLException {
- Properties props = new Properties();
+ Properties properties = new Properties(mProperties);
if (username != null) {
- props.put("user", username);
+ properties.put("user", username);
}
if (password != null) {
- props.put("password", password);
+ properties.put("password", password);
}
- return DriverManager.getConnection(mURL, props);
+ return DriverManager.getConnection(mURL, properties);
}
public PrintWriter getLogWriter() throws SQLException {
|