Add Docker Compose support for Oracle Database using R2DBC
Closes gh-35143
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.boot.docker.compose.service.connection.oracle;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Oracle Database environment details.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
class OracleEnvironment {
|
||||
|
||||
private final String username;
|
||||
|
||||
private final String password;
|
||||
|
||||
private final String database;
|
||||
|
||||
OracleEnvironment(Map<String, String> env) {
|
||||
this.username = env.getOrDefault("APP_USER", "system");
|
||||
this.password = extractPassword(env);
|
||||
this.database = env.getOrDefault("ORACLE_DATABASE", "xepdb1");
|
||||
}
|
||||
|
||||
private String extractPassword(Map<String, String> env) {
|
||||
if (env.containsKey("APP_USER")) {
|
||||
String password = env.get("APP_PASSWORD");
|
||||
Assert.state(StringUtils.hasLength(password), "No Oracle app password found");
|
||||
return password;
|
||||
}
|
||||
Assert.state(!env.containsKey("ORACLE_RANDOM_PASSWORD"),
|
||||
"ORACLE_RANDOM_PASSWORD is not supported without APP_USER and APP_PASSWORD");
|
||||
String password = env.get("ORACLE_PASSWORD");
|
||||
Assert.state(StringUtils.hasLength(password), "No Oracle password found");
|
||||
return password;
|
||||
}
|
||||
|
||||
String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
String getDatabase() {
|
||||
return this.database;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.boot.docker.compose.service.connection.oracle;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactoryOptions;
|
||||
|
||||
import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
|
||||
* for an {@code oracle-xe} service.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Andy Wilkinson
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class OracleR2dbcDockerComposeConnectionDetailsFactory
|
||||
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
|
||||
|
||||
OracleR2dbcDockerComposeConnectionDetailsFactory() {
|
||||
super("gvenzl/oracle-xe", "io.r2dbc.spi.ConnectionFactoryOptions");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new OracleDbR2dbcDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link R2dbcConnectionDetails} backed by a {@code gvenzl/oracle-xe}
|
||||
* {@link RunningService}.
|
||||
*/
|
||||
static class OracleDbR2dbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements R2dbcConnectionDetails {
|
||||
|
||||
private static final ConnectionFactoryOptionsBuilder connectionFactoryOptionsBuilder = new ConnectionFactoryOptionsBuilder(
|
||||
"oracle", 1521);
|
||||
|
||||
private final ConnectionFactoryOptions connectionFactoryOptions;
|
||||
|
||||
OracleDbR2dbcDockerComposeConnectionDetails(RunningService service) {
|
||||
super(service);
|
||||
OracleEnvironment environment = new OracleEnvironment(service.env());
|
||||
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(),
|
||||
environment.getUsername(), environment.getPassword());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionFactoryOptions getConnectionFactoryOptions() {
|
||||
return this.connectionFactoryOptions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for docker compose MySQL service connections.
|
||||
*/
|
||||
package org.springframework.boot.docker.compose.service.connection.oracle;
|
||||
@@ -12,6 +12,7 @@ org.springframework.boot.docker.compose.service.connection.mariadb.MariaDbR2dbcD
|
||||
org.springframework.boot.docker.compose.service.connection.mongo.MongoDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.mysql.MySqlJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.postgres.PostgresJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.postgres.PostgresR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.rabbit.RabbitDockerComposeConnectionDetailsFactory,\
|
||||
|
||||
Reference in New Issue
Block a user