Skip to content

Commit

Permalink
Merge pull request #1 from oracle/modular-jar
Browse files Browse the repository at this point in the history
Build Oracle R2DBC as a modular jar
  • Loading branch information
jeandelavarene authored Mar 12, 2021
2 parents 33e21d3 + 28879f2 commit ea2bd60
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 216 deletions.
31 changes: 30 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,35 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifestEntries>
<Implementation-Title>Oracle R2DBC</Implementation-Title>
<Implementation-Version>
${project.version}
</Implementation-Version>
<Implementation-Vendor>Oracle Corporation</Implementation-Vendor>
<Specification-Title>
R2DBC - Reactive Relational Database Connectivity
</Specification-Title>
<Specification-Version>${r2dbc.version}</Specification-Version>
<Specification-Vendor>
Pivotal Software, Inc
</Specification-Vendor>
<Build-Info>
Oracle R2DBC ${project.version} compiled with JDK ${java.vm.version} from ${java.vm.vendor} on ${maven.build.timestamp}
</Build-Info>
<Main-Class>
oracle.r2dbc.impl.Main
</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
Expand All @@ -77,7 +106,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<header>Oracle R2DBC ${version}</header>
<header>Oracle R2DBC ${project.version}</header>
<footer>
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
</footer>
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
This software is dual-licensed to you under the Universal Permissive License
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
either license.
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
https://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.
*/
/**
* Implements the R2DBC SPI for Oracle Database.
*
* @provides io.r2dbc.spi.ConnectionFactoryProvider
* @since 0.1.1
*/
module com.oracle.database.r2dbc {

provides io.r2dbc.spi.ConnectionFactoryProvider
with oracle.r2dbc.impl.OracleConnectionFactoryProviderImpl;

requires java.sql;

requires ojdbc11;
requires org.reactivestreams;
requires reactor.core;
requires r2dbc.spi;
}
84 changes: 84 additions & 0 deletions src/main/java/oracle/r2dbc/impl/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
This software is dual-licensed to you under the Universal Permissive License
(UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License
2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
either license.
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
https://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 oracle.r2dbc.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.jar.Manifest;

/**
* <p>
* A public class implementing a main method that may be executed from a
* command line. This class is specified as the Main-Class attribute in
* the META-INF/MANIFEST.MF of the Oracle R2DBC jar.
* </p><p><i>
* The behavior implemented by this class may change between minor and patch
* version release updates.
* </i></p><p>
* The following command, in
* which "x.y.z" is the semantic version number of the jar,
* executes the main method of this class:
* </p><pre>
* java -jar oracle-r2dbc-x.y.z.jar
* </pre><p>
* Since version 0.1.1, the main method is implemented to exit after printing
* a message to the standard output stream. The message includes the version
* numbers of the Oracle R2DBC Driver along with the JDK that compiled it. A
* timestamp captured at the moment when the jar was compiled is also included.
* </p>
*
* @since 0.1.1
* @author Michael-A-McMahon
*/
public final class Main {

private Main() {/*This class has no instance fields*/}

/**
* Prints information about this build of Oracle R2DBC. This method attempts
* to read a "Build-Info" attribute from META-INF/MANIFEST.MF. If the
* manifest is not available to the class loader, or if the manifest does
* not contain a Build-Info attribute, then this method prints a message
* indicating that build information can not be located.
* @param args ignored
* @throws IOException If the META-INF/MANIFEST.MF resource can not be read.
*/
public static void main(String[] args) throws IOException {

InputStream manifestStream =
Main.class.getModule().getResourceAsStream("META-INF/MANIFEST.MF");

if (manifestStream == null) {
System.out.println("META-INF/MANIFEST.MF not found");
return;
}

try (manifestStream) {
System.out.println(Objects.requireNonNullElse(
new Manifest(manifestStream)
.getMainAttributes()
.getValue("Build-Info"),
"Build-Info is missing from the manifest"));
}
}
}
2 changes: 0 additions & 2 deletions src/main/java/oracle/r2dbc/impl/OracleConnectionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import reactor.core.publisher.Mono;

import static java.sql.Connection.TRANSACTION_READ_COMMITTED;
import static java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
import static java.sql.Connection.TRANSACTION_REPEATABLE_READ;
import static java.sql.Connection.TRANSACTION_SERIALIZABLE;
import static oracle.r2dbc.impl.OracleR2dbcExceptions.requireNonNull;
import static oracle.r2dbc.impl.OracleR2dbcExceptions.getOrHandleSQLException;
Expand Down
12 changes: 3 additions & 9 deletions src/main/java/oracle/r2dbc/impl/OracleReactiveJdbcAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import io.r2dbc.spi.Option;
import io.r2dbc.spi.R2dbcException;
import io.r2dbc.spi.R2dbcTimeoutException;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Row;
import oracle.jdbc.OracleBlob;
import oracle.jdbc.OracleClob;
import oracle.jdbc.OracleConnection;
Expand All @@ -49,17 +47,12 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.sql.Wrapper;
import java.time.Duration;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Flow;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
Expand Down Expand Up @@ -426,10 +419,11 @@ static OracleReactiveJdbcAdapter getInstance() {
@Override
public DataSource createDataSource(ConnectionFactoryOptions options) {

oracle.jdbc.pool.OracleDataSource oracleDataSource =
OracleDataSource oracleDataSource =
getOrHandleSQLException(oracle.jdbc.pool.OracleDataSource::new);

oracleDataSource.setURL(composeJdbcUrl(options));
runOrHandleSQLException(() ->
oracleDataSource.setURL(composeJdbcUrl(options)));
configureStandardOptions(oracleDataSource, options);
configureExtendedOptions(oracleDataSource, options);
configureJdbcDefaults(oracleDataSource);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/oracle/r2dbc/impl/OracleResultImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BiFunction;

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/oracle/r2dbc/impl/OracleRowImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,10 @@
import io.r2dbc.spi.Clob;
import io.r2dbc.spi.R2dbcException;
import io.r2dbc.spi.Row;
import oracle.jdbc.OracleType;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.sql.JDBCType;
import java.sql.ResultSet;
import java.sql.SQLType;
import java.sql.Types;
import java.util.Objects;

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

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/oracle/r2dbc/impl/OracleStatementImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import io.r2dbc.spi.R2dbcException;
import io.r2dbc.spi.Result;
import io.r2dbc.spi.Statement;
import oracle.r2dbc.impl.OracleR2dbcExceptions.ThrowingRunnable;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand Down Expand Up @@ -547,6 +546,7 @@ private Publisher<Result> createResultPublisher(
* signal.
* </p>
* @param jdbcStatement A JDBC statement
* @param bindValues A set of bind values
* @return A publisher that emits the {@code Result} of executing the JDBC
* statement.
*/
Expand Down Expand Up @@ -625,7 +625,7 @@ private Publisher<Result> executeBatch(
* {@link PreparedStatement#addBatch()},
*
* @param jdbcStatement A JDBC statement
* @param batch A batch of bind values
* @param bindValues A set of bind values
* @return A publisher that emits the {@code Results} of executing the
* JDBC statement for each set of bind values in the {@code batch}
*/
Expand Down
1 change: 0 additions & 1 deletion src/main/java/oracle/r2dbc/impl/ReactiveJdbcAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.function.Function;

Expand Down
69 changes: 49 additions & 20 deletions src/test/java/oracle/r2dbc/OracleTestKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@

import io.r2dbc.spi.*;
import io.r2dbc.spi.test.TestKit;
import oracle.r2dbc.util.OracleTestKitSupport;
import oracle.jdbc.datasource.OracleDataSource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.AbstractLobCreatingPreparedStatementCallback;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator;
Expand All @@ -46,7 +47,17 @@
import java.util.Collection;
import java.util.function.Function;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE;
import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER;
import static io.r2dbc.spi.ConnectionFactoryOptions.HOST;
import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD;
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;
import static io.r2dbc.spi.ConnectionFactoryOptions.USER;
import static oracle.r2dbc.DatabaseConfig.host;
import static oracle.r2dbc.DatabaseConfig.password;
import static oracle.r2dbc.DatabaseConfig.port;
import static oracle.r2dbc.DatabaseConfig.serviceName;
import static oracle.r2dbc.DatabaseConfig.user;

/**
* <p>
Expand All @@ -73,13 +84,38 @@
* @author harayuanwang, Michael-A-McMahon
* @since 0.1.0
*/
public class OracleTestKit
extends OracleTestKitSupport implements TestKit<Integer> {
public class OracleTestKit implements TestKit<Integer> {

private final JdbcOperations jdbcOperations;
{
try {
OracleDataSource dataSource = new oracle.jdbc.pool.OracleDataSource();
dataSource.setURL(String.format("jdbc:oracle:thin:@%s:%d/%s",
host(), port(), serviceName()));
dataSource.setUser(user());
dataSource.setPassword(password());
this.jdbcOperations = new JdbcTemplate(dataSource);
}
catch (SQLException sqlException) {
throw new RuntimeException(sqlException);
}
}

static <T> Mono<T> close(Connection connection) {
return Mono.from(connection
.close())
.then(Mono.empty());
private final ConnectionFactory connectionFactory;
{
connectionFactory = ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(DRIVER, "oracle")
.option(DATABASE, serviceName())
.option(HOST, host())
.option(PORT, port())
.option(PASSWORD, password())
.option(USER, user())
.build());
}

public JdbcOperations getJdbcOperations() {
return jdbcOperations;
}

@Override
Expand Down Expand Up @@ -108,17 +144,6 @@ public Integer getIdentifier(int index) {
return index;
}

@Override
public JdbcOperations getJdbcOperations() {
JdbcOperations jdbcOperations = CONFIG.getJDBCOperations();

if (jdbcOperations == null) {
throw new IllegalStateException("JdbcOperations not yet initialized");
}

return jdbcOperations;
}

/**
* {@inheritDoc}
* <p>
Expand Down Expand Up @@ -402,7 +427,6 @@ protected void setValues(PreparedStatement ps, LobCreator lobCreator) throws SQL
.verifyComplete();
}


@Disabled("Compound statements are not supported by Oracle Database")
@Test
@Override
Expand All @@ -418,6 +442,11 @@ public void savePoint() {}
@Override
public void savePointStartsTransaction() {}

static <T> Mono<T> close(Connection connection) {
return Mono.from(connection.close())
.then(Mono.empty());
}

}

/*
Expand Down
Loading

0 comments on commit ea2bd60

Please sign in to comment.