-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add Oracle connection pool #3770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,13 +14,20 @@ | |
|
|
||
| <properties> | ||
| <air.main.basedir>${project.parent.basedir}</air.main.basedir> | ||
| <dep.oracle.version>19.3.0.0</dep.oracle.version> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.oracle.ojdbc</groupId> | ||
| <artifactId>ojdbc8</artifactId> | ||
| <version>19.3.0.0</version> | ||
| <version>${dep.oracle.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.oracle.ojdbc</groupId> | ||
| <artifactId>ucp</artifactId> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is being added in (Not sure why would you want to separate this btw, but maybe this was agreed upon)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was asked here #3770 (comment)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that at the time i suggested extracting the commit there was just one use of Anyway.
I am slightly toward former one. |
||
| <version>${dep.oracle.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * 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 io.prestosql.plugin.oracle; | ||
|
|
||
| import io.prestosql.plugin.jdbc.ConnectionFactory; | ||
| import io.prestosql.plugin.jdbc.JdbcIdentity; | ||
| import io.prestosql.plugin.jdbc.credential.CredentialProvider; | ||
| import oracle.jdbc.pool.OracleDataSource; | ||
| import oracle.ucp.jdbc.PoolDataSource; | ||
| import oracle.ucp.jdbc.PoolDataSourceFactory; | ||
|
|
||
| import java.sql.Connection; | ||
| import java.sql.SQLException; | ||
| import java.util.Optional; | ||
| import java.util.Properties; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkArgument; | ||
|
|
||
| public class OraclePoolConnectorFactory | ||
| implements ConnectionFactory | ||
| { | ||
| private final PoolDataSource dataSource; | ||
| private final CredentialProvider credentialProvider; | ||
|
|
||
| public OraclePoolConnectorFactory( | ||
| String connectionUrl, | ||
| Properties connectionProperties, | ||
| CredentialProvider credentialProvider, | ||
| int connectionPoolMinSize, | ||
| int connectionPoolMaxSize) | ||
| throws SQLException | ||
| { | ||
| this.credentialProvider = credentialProvider; | ||
| this.dataSource = PoolDataSourceFactory.getPoolDataSource(); | ||
|
|
||
| //Setting connection properties of the data source | ||
| this.dataSource.setConnectionFactoryClassName(OracleDataSource.class.getName()); | ||
| this.dataSource.setURL(connectionUrl); | ||
|
|
||
| //Setting pool properties | ||
| this.dataSource.setInitialPoolSize(connectionPoolMinSize); | ||
| this.dataSource.setMinPoolSize(connectionPoolMinSize); | ||
| this.dataSource.setMaxPoolSize(connectionPoolMaxSize); | ||
| this.dataSource.setValidateConnectionOnBorrow(true); | ||
| this.dataSource.setConnectionProperties(connectionProperties); | ||
| } | ||
|
|
||
| @Override | ||
| public Connection openConnection(JdbcIdentity identity) | ||
| throws SQLException | ||
| { | ||
| Optional<String> user = credentialProvider.getConnectionUser(Optional.of(identity)); | ||
| Optional<String> password = credentialProvider.getConnectionPassword(Optional.of(identity)); | ||
|
|
||
| checkArgument(user.isPresent(), "Credentials returned null user"); | ||
| checkArgument(password.isPresent(), "Credentials returned null password"); | ||
|
|
||
| return dataSource.getConnection(user.get(), password.get()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| * 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 io.prestosql.plugin.oracle; | ||
|
|
||
| import io.prestosql.testing.AbstractTestIntegrationSmokeTest; | ||
| import io.prestosql.testing.MaterializedResult; | ||
| import io.prestosql.testing.QueryRunner; | ||
| import io.prestosql.tpch.TpchTable; | ||
| import org.testcontainers.shaded.com.google.common.collect.ImmutableList; | ||
| import org.testng.annotations.AfterClass; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import static io.prestosql.spi.type.VarcharType.VARCHAR; | ||
| import static io.prestosql.testing.assertions.Assert.assertEquals; | ||
| import static io.prestosql.tpch.TpchTable.CUSTOMER; | ||
| import static io.prestosql.tpch.TpchTable.NATION; | ||
| import static io.prestosql.tpch.TpchTable.ORDERS; | ||
| import static io.prestosql.tpch.TpchTable.REGION; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| abstract class BaseOracleIntegrationSmokeTest | ||
| extends AbstractTestIntegrationSmokeTest | ||
| { | ||
| private TestingOracleServer oracleServer; | ||
|
|
||
| @Override | ||
| protected QueryRunner createQueryRunner() | ||
| throws Exception | ||
| { | ||
| oracleServer = new TestingOracleServer(); | ||
| return createOracleQueryRunner(oracleServer, ImmutableList.of(CUSTOMER, NATION, ORDERS, REGION)); | ||
| } | ||
|
|
||
| protected abstract QueryRunner createOracleQueryRunner(TestingOracleServer server, Iterable<TpchTable<?>> tables) | ||
| throws Exception; | ||
|
|
||
| @AfterClass(alwaysRun = true) | ||
| public final void destroy() | ||
| { | ||
| oracleServer.close(); | ||
| } | ||
|
|
||
| @Test | ||
| @Override | ||
| public void testDescribeTable() | ||
| { | ||
| MaterializedResult expectedColumns = MaterializedResult.resultBuilder(getQueryRunner().getDefaultSession(), VARCHAR, VARCHAR, VARCHAR, VARCHAR) | ||
| .row("orderkey", "decimal(19,0)", "", "") | ||
| .row("custkey", "decimal(19,0)", "", "") | ||
| .row("orderstatus", "varchar(1)", "", "") | ||
| .row("totalprice", "double", "", "") | ||
| .row("orderdate", "timestamp(3)", "", "") | ||
| .row("orderpriority", "varchar(15)", "", "") | ||
| .row("clerk", "varchar(15)", "", "") | ||
| .row("shippriority", "decimal(10,0)", "", "") | ||
| .row("comment", "varchar(79)", "", "") | ||
| .build(); | ||
| MaterializedResult actualColumns = computeActual("DESCRIBE orders"); | ||
| assertEquals(actualColumns, expectedColumns); | ||
| } | ||
|
|
||
| @Test | ||
| @Override | ||
| public void testShowCreateTable() | ||
| { | ||
| assertThat((String) computeActual("SHOW CREATE TABLE orders").getOnlyValue()) | ||
| // If the connector reports additional column properties, the expected value needs to be adjusted in the test subclass | ||
| .matches("CREATE TABLE \\w+\\.\\w+\\.orders \\Q(\n" + | ||
| " orderkey decimal(19, 0),\n" + | ||
| " custkey decimal(19, 0),\n" + | ||
| " orderstatus varchar(1),\n" + | ||
| " totalprice double,\n" + | ||
| " orderdate timestamp(3),\n" + | ||
| " orderpriority varchar(15),\n" + | ||
| " clerk varchar(15),\n" + | ||
| " shippriority decimal(10, 0),\n" + | ||
| " comment varchar(79)\n" + | ||
| ")"); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.