| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package org.elasticsearch.jdbc;
- import java.sql.Connection;
- import java.sql.SQLException;
- import java.util.Properties;
- public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
- private String url;
- private String username;
- private String password;
- private Properties connectionProperties;
- public void setUrl(String url) {
- this.url = url.trim();
- }
- public String getUrl() {
- return this.url;
- }
- public void setUsername(String username) {
- this.username = username;
- }
- public String getUsername() {
- return this.username;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getPassword() {
- return this.password;
- }
- public void setConnectionProperties(Properties connectionProperties) {
- this.connectionProperties = connectionProperties;
- }
- public Properties getConnectionProperties() {
- return this.connectionProperties;
- }
- public Connection getConnection() throws SQLException {
- return getConnectionFromDriver(getUsername(), getPassword());
- }
- public Connection getConnection(String username, String password) throws SQLException {
- return getConnectionFromDriver(username, password);
- }
- protected Connection getConnectionFromDriver(String username, String password) throws SQLException {
- Properties mergedProps = new Properties();
- Properties connProps = getConnectionProperties();
- if (connProps != null) {
- mergedProps.putAll(connProps);
- }
- if (username != null) {
- mergedProps.setProperty("user", username);
- }
- if (password != null) {
- mergedProps.setProperty("password", password);
- }
- return getConnectionFromDriver(mergedProps);
- }
- protected abstract Connection getConnectionFromDriver(Properties props) throws SQLException;
- }
|