Skip to content

Commit ea2bd60

Browse files
Merge pull request #1 from oracle/modular-jar
Build Oracle R2DBC as a modular jar
2 parents 33e21d3 + 28879f2 commit ea2bd60

14 files changed

+217
-216
lines changed

pom.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,35 @@
5656
<target>${java.version}</target>
5757
</configuration>
5858
</plugin>
59+
<plugin>
60+
<groupId>org.apache.maven.plugins</groupId>
61+
<artifactId>maven-jar-plugin</artifactId>
62+
<version>2.1</version>
63+
<configuration>
64+
<archive>
65+
<manifestEntries>
66+
<Implementation-Title>Oracle R2DBC</Implementation-Title>
67+
<Implementation-Version>
68+
${project.version}
69+
</Implementation-Version>
70+
<Implementation-Vendor>Oracle Corporation</Implementation-Vendor>
71+
<Specification-Title>
72+
R2DBC - Reactive Relational Database Connectivity
73+
</Specification-Title>
74+
<Specification-Version>${r2dbc.version}</Specification-Version>
75+
<Specification-Vendor>
76+
Pivotal Software, Inc
77+
</Specification-Vendor>
78+
<Build-Info>
79+
Oracle R2DBC ${project.version} compiled with JDK ${java.vm.version} from ${java.vm.vendor} on ${maven.build.timestamp}
80+
</Build-Info>
81+
<Main-Class>
82+
oracle.r2dbc.impl.Main
83+
</Main-Class>
84+
</manifestEntries>
85+
</archive>
86+
</configuration>
87+
</plugin>
5988
<plugin>
6089
<groupId>org.apache.maven.plugins</groupId>
6190
<artifactId>maven-deploy-plugin</artifactId>
@@ -77,7 +106,7 @@
77106
<artifactId>maven-javadoc-plugin</artifactId>
78107
<version>3.2.0</version>
79108
<configuration>
80-
<header>Oracle R2DBC ${version}</header>
109+
<header>Oracle R2DBC ${project.version}</header>
81110
<footer>
82111
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
83112
</footer>

src/main/java/module-info.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
3+
4+
This software is dual-licensed to you under the Universal Permissive License
5+
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
6+
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
either license.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
*/
21+
/**
22+
* Implements the R2DBC SPI for Oracle Database.
23+
*
24+
* @provides io.r2dbc.spi.ConnectionFactoryProvider
25+
* @since 0.1.1
26+
*/
27+
module com.oracle.database.r2dbc {
28+
29+
provides io.r2dbc.spi.ConnectionFactoryProvider
30+
with oracle.r2dbc.impl.OracleConnectionFactoryProviderImpl;
31+
32+
requires java.sql;
33+
34+
requires ojdbc11;
35+
requires org.reactivestreams;
36+
requires reactor.core;
37+
requires r2dbc.spi;
38+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
3+
4+
This software is dual-licensed to you under the Universal Permissive License
5+
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
6+
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
7+
either license.
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
https://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+
*/
21+
22+
package oracle.r2dbc.impl;
23+
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.util.Objects;
27+
import java.util.jar.Manifest;
28+
29+
/**
30+
* <p>
31+
* A public class implementing a main method that may be executed from a
32+
* command line. This class is specified as the Main-Class attribute in
33+
* the META-INF/MANIFEST.MF of the Oracle R2DBC jar.
34+
* </p><p><i>
35+
* The behavior implemented by this class may change between minor and patch
36+
* version release updates.
37+
* </i></p><p>
38+
* The following command, in
39+
* which "x.y.z" is the semantic version number of the jar,
40+
* executes the main method of this class:
41+
* </p><pre>
42+
* java -jar oracle-r2dbc-x.y.z.jar
43+
* </pre><p>
44+
* Since version 0.1.1, the main method is implemented to exit after printing
45+
* a message to the standard output stream. The message includes the version
46+
* numbers of the Oracle R2DBC Driver along with the JDK that compiled it. A
47+
* timestamp captured at the moment when the jar was compiled is also included.
48+
* </p>
49+
*
50+
* @since 0.1.1
51+
* @author Michael-A-McMahon
52+
*/
53+
public final class Main {
54+
55+
private Main() {/*This class has no instance fields*/}
56+
57+
/**
58+
* Prints information about this build of Oracle R2DBC. This method attempts
59+
* to read a "Build-Info" attribute from META-INF/MANIFEST.MF. If the
60+
* manifest is not available to the class loader, or if the manifest does
61+
* not contain a Build-Info attribute, then this method prints a message
62+
* indicating that build information can not be located.
63+
* @param args ignored
64+
* @throws IOException If the META-INF/MANIFEST.MF resource can not be read.
65+
*/
66+
public static void main(String[] args) throws IOException {
67+
68+
InputStream manifestStream =
69+
Main.class.getModule().getResourceAsStream("META-INF/MANIFEST.MF");
70+
71+
if (manifestStream == null) {
72+
System.out.println("META-INF/MANIFEST.MF not found");
73+
return;
74+
}
75+
76+
try (manifestStream) {
77+
System.out.println(Objects.requireNonNullElse(
78+
new Manifest(manifestStream)
79+
.getMainAttributes()
80+
.getValue("Build-Info"),
81+
"Build-Info is missing from the manifest"));
82+
}
83+
}
84+
}

src/main/java/oracle/r2dbc/impl/OracleConnectionImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import reactor.core.publisher.Mono;
3333

3434
import static java.sql.Connection.TRANSACTION_READ_COMMITTED;
35-
import static java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
36-
import static java.sql.Connection.TRANSACTION_REPEATABLE_READ;
3735
import static java.sql.Connection.TRANSACTION_SERIALIZABLE;
3836
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireNonNull;
3937
import static oracle.r2dbc.impl.OracleR2dbcExceptions.getOrHandleSQLException;

src/main/java/oracle/r2dbc/impl/OracleReactiveJdbcAdapter.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import io.r2dbc.spi.Option;
2626
import io.r2dbc.spi.R2dbcException;
2727
import io.r2dbc.spi.R2dbcTimeoutException;
28-
import io.r2dbc.spi.Result;
29-
import io.r2dbc.spi.Row;
3028
import oracle.jdbc.OracleBlob;
3129
import oracle.jdbc.OracleClob;
3230
import oracle.jdbc.OracleConnection;
@@ -49,17 +47,12 @@
4947
import java.sql.Connection;
5048
import java.sql.PreparedStatement;
5149
import java.sql.ResultSet;
52-
import java.sql.RowId;
5350
import java.sql.SQLException;
54-
import java.sql.Statement;
55-
import java.sql.Types;
5651
import java.sql.Wrapper;
5752
import java.time.Duration;
58-
import java.util.Map;
5953
import java.util.Objects;
6054
import java.util.Set;
6155
import java.util.concurrent.CompletableFuture;
62-
import java.util.concurrent.ConcurrentHashMap;
6356
import java.util.concurrent.Flow;
6457
import java.util.concurrent.atomic.AtomicBoolean;
6558
import java.util.concurrent.locks.ReentrantLock;
@@ -426,10 +419,11 @@ static OracleReactiveJdbcAdapter getInstance() {
426419
@Override
427420
public DataSource createDataSource(ConnectionFactoryOptions options) {
428421

429-
oracle.jdbc.pool.OracleDataSource oracleDataSource =
422+
OracleDataSource oracleDataSource =
430423
getOrHandleSQLException(oracle.jdbc.pool.OracleDataSource::new);
431424

432-
oracleDataSource.setURL(composeJdbcUrl(options));
425+
runOrHandleSQLException(() ->
426+
oracleDataSource.setURL(composeJdbcUrl(options)));
433427
configureStandardOptions(oracleDataSource, options);
434428
configureExtendedOptions(oracleDataSource, options);
435429
configureJdbcDefaults(oracleDataSource);

src/main/java/oracle/r2dbc/impl/OracleResultImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import java.sql.PreparedStatement;
2525
import java.sql.ResultSet;
26-
import java.sql.SQLException;
2726
import java.util.concurrent.atomic.AtomicBoolean;
2827
import java.util.function.BiFunction;
2928

src/main/java/oracle/r2dbc/impl/OracleRowImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@
2525
import io.r2dbc.spi.Clob;
2626
import io.r2dbc.spi.R2dbcException;
2727
import io.r2dbc.spi.Row;
28-
import oracle.jdbc.OracleType;
2928

30-
import java.io.IOException;
3129
import java.nio.ByteBuffer;
32-
import java.sql.JDBCType;
3330
import java.sql.ResultSet;
34-
import java.sql.SQLType;
3531
import java.sql.Types;
36-
import java.util.Objects;
3732

3833
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireNonNull;
3934

src/main/java/oracle/r2dbc/impl/OracleStatementImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.r2dbc.spi.R2dbcException;
2525
import io.r2dbc.spi.Result;
2626
import io.r2dbc.spi.Statement;
27-
import oracle.r2dbc.impl.OracleR2dbcExceptions.ThrowingRunnable;
2827
import org.reactivestreams.Publisher;
2928
import reactor.core.publisher.Flux;
3029
import reactor.core.publisher.Mono;
@@ -547,6 +546,7 @@ private Publisher<Result> createResultPublisher(
547546
* signal.
548547
* </p>
549548
* @param jdbcStatement A JDBC statement
549+
* @param bindValues A set of bind values
550550
* @return A publisher that emits the {@code Result} of executing the JDBC
551551
* statement.
552552
*/
@@ -625,7 +625,7 @@ private Publisher<Result> executeBatch(
625625
* {@link PreparedStatement#addBatch()},
626626
*
627627
* @param jdbcStatement A JDBC statement
628-
* @param batch A batch of bind values
628+
* @param bindValues A set of bind values
629629
* @return A publisher that emits the {@code Results} of executing the
630630
* JDBC statement for each set of bind values in the {@code batch}
631631
*/

src/main/java/oracle/r2dbc/impl/ReactiveJdbcAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.sql.DriverManager;
3838
import java.sql.PreparedStatement;
3939
import java.sql.ResultSet;
40-
import java.sql.ResultSetMetaData;
4140
import java.sql.SQLException;
4241
import java.util.function.Function;
4342

src/test/java/oracle/r2dbc/OracleTestKit.java

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626

2727
import io.r2dbc.spi.*;
2828
import io.r2dbc.spi.test.TestKit;
29-
import oracle.r2dbc.util.OracleTestKitSupport;
29+
import oracle.jdbc.datasource.OracleDataSource;
3030
import org.junit.jupiter.api.Disabled;
3131
import org.junit.jupiter.api.Test;
3232
import org.springframework.jdbc.core.JdbcOperations;
33+
import org.springframework.jdbc.core.JdbcTemplate;
3334
import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
3435
import org.springframework.jdbc.support.lob.DefaultLobHandler;
3536
import org.springframework.jdbc.support.lob.LobCreator;
@@ -46,7 +47,17 @@
4647
import java.util.Collection;
4748
import java.util.function.Function;
4849

49-
import static org.junit.jupiter.api.Assertions.assertThrows;
50+
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
51+
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
52+
import static io.r2dbc.spi.ConnectionFactoryOptions.HOST;
53+
import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD;
54+
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;
55+
import static io.r2dbc.spi.ConnectionFactoryOptions.USER;
56+
import static oracle.r2dbc.DatabaseConfig.host;
57+
import static oracle.r2dbc.DatabaseConfig.password;
58+
import static oracle.r2dbc.DatabaseConfig.port;
59+
import static oracle.r2dbc.DatabaseConfig.serviceName;
60+
import static oracle.r2dbc.DatabaseConfig.user;
5061

5162
/**
5263
* <p>
@@ -73,13 +84,38 @@
7384
* @author harayuanwang, Michael-A-McMahon
7485
* @since 0.1.0
7586
*/
76-
public class OracleTestKit
77-
extends OracleTestKitSupport implements TestKit<Integer> {
87+
public class OracleTestKit implements TestKit<Integer> {
88+
89+
private final JdbcOperations jdbcOperations;
90+
{
91+
try {
92+
OracleDataSource dataSource = new oracle.jdbc.pool.OracleDataSource();
93+
dataSource.setURL(String.format("jdbc:oracle:thin:@%s:%d/%s",
94+
host(), port(), serviceName()));
95+
dataSource.setUser(user());
96+
dataSource.setPassword(password());
97+
this.jdbcOperations = new JdbcTemplate(dataSource);
98+
}
99+
catch (SQLException sqlException) {
100+
throw new RuntimeException(sqlException);
101+
}
102+
}
78103

79-
static <T> Mono<T> close(Connection connection) {
80-
return Mono.from(connection
81-
.close())
82-
.then(Mono.empty());
104+
private final ConnectionFactory connectionFactory;
105+
{
106+
connectionFactory = ConnectionFactories.get(
107+
ConnectionFactoryOptions.builder()
108+
.option(DRIVER, "oracle")
109+
.option(DATABASE, serviceName())
110+
.option(HOST, host())
111+
.option(PORT, port())
112+
.option(PASSWORD, password())
113+
.option(USER, user())
114+
.build());
115+
}
116+
117+
public JdbcOperations getJdbcOperations() {
118+
return jdbcOperations;
83119
}
84120

85121
@Override
@@ -108,17 +144,6 @@ public Integer getIdentifier(int index) {
108144
return index;
109145
}
110146

111-
@Override
112-
public JdbcOperations getJdbcOperations() {
113-
JdbcOperations jdbcOperations = CONFIG.getJDBCOperations();
114-
115-
if (jdbcOperations == null) {
116-
throw new IllegalStateException("JdbcOperations not yet initialized");
117-
}
118-
119-
return jdbcOperations;
120-
}
121-
122147
/**
123148
* {@inheritDoc}
124149
* <p>
@@ -402,7 +427,6 @@ protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQL
402427
.verifyComplete();
403428
}
404429

405-
406430
@Disabled("Compound statements are not supported by Oracle Database")
407431
@Test
408432
@Override
@@ -418,6 +442,11 @@ public void savePoint() {}
418442
@Override
419443
public void savePointStartsTransaction() {}
420444

445+
static <T> Mono<T> close(Connection connection) {
446+
return Mono.from(connection.close())
447+
.then(Mono.empty());
448+
}
449+
421450
}
422451

423452
/*

0 commit comments

Comments
 (0)