Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Connection sources other than Driver in BaseJdbcClient
A JDBC connector may want to utilize connection pooling or use `DataSource` as the source of `Connection`s. This change removes `BaseJdbcClient`'s direct dependence on `Driver`, allowing such connectors to extend `BaseJdbcClient`.
- Loading branch information
Showing
9 changed files
with
120 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/ConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.plugin.jdbc; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
public interface ConnectionFactory | ||
{ | ||
Connection openConnection() | ||
throws SQLException; | ||
} |
61 changes: 61 additions & 0 deletions
61
presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/DriverConnectionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.plugin.jdbc; | ||
|
||
import java.sql.Connection; | ||
import java.sql.Driver; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DriverConnectionFactory | ||
implements ConnectionFactory | ||
{ | ||
private final Driver driver; | ||
private final String connectionUrl; | ||
private final Properties connectionProperties; | ||
|
||
public DriverConnectionFactory(Driver driver, BaseJdbcConfig config) | ||
{ | ||
this(driver, config.getConnectionUrl(), basicConnectionProperties(config)); | ||
} | ||
|
||
public static Properties basicConnectionProperties(BaseJdbcConfig config) | ||
{ | ||
Properties connectionProperties = new Properties(); | ||
if (config.getConnectionUser() != null) { | ||
connectionProperties.setProperty("user", config.getConnectionUser()); | ||
} | ||
if (config.getConnectionPassword() != null) { | ||
connectionProperties.setProperty("password", config.getConnectionPassword()); | ||
} | ||
return connectionProperties; | ||
} | ||
|
||
public DriverConnectionFactory(Driver driver, String connectionUrl, Properties connectionProperties) | ||
{ | ||
this.driver = requireNonNull(driver, "driver is null"); | ||
this.connectionUrl = requireNonNull(connectionUrl, "connectionUrl is null"); | ||
this.connectionProperties = new Properties(); | ||
this.connectionProperties.putAll(requireNonNull(connectionProperties, "basicConnectionProperties is null")); | ||
} | ||
|
||
@Override | ||
public Connection openConnection() | ||
throws SQLException | ||
{ | ||
return driver.connect(connectionUrl, connectionProperties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters