Skip to content

Commit a7571cf

Browse files
committed
Use different default database names for Oracle XE and Oracle Free
Closes gh-38476
1 parent 2323c7a commit a7571cf

14 files changed

+234
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docker.compose.service.connection.oracle;
18+
19+
/**
20+
* Enumeration of supported Oracle containers.
21+
*
22+
* @author Andy Wilkinson
23+
*/
24+
enum OracleContainer {
25+
26+
FREE("gvenzl/oracle-free", "freepdb1"),
27+
28+
XE("gvenzl/oracle-xe", "xepdb1");
29+
30+
private final String imageName;
31+
32+
private final String defaultDatabase;
33+
34+
OracleContainer(String imageName, String defaultDatabase) {
35+
this.imageName = imageName;
36+
this.defaultDatabase = defaultDatabase;
37+
}
38+
39+
String getImageName() {
40+
return this.imageName;
41+
}
42+
43+
String getDefaultDatabase() {
44+
return this.defaultDatabase;
45+
}
46+
47+
}

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/oracle/OracleEnvironment.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,16 @@
2828
*/
2929
class OracleEnvironment {
3030

31-
static final String[] CONTAINER_NAMES = { "gvenzl/oracle-xe", "gvenzl/oracle-free" };
32-
3331
private final String username;
3432

3533
private final String password;
3634

3735
private final String database;
3836

39-
OracleEnvironment(Map<String, String> env) {
37+
OracleEnvironment(Map<String, String> env, String defaultDatabase) {
4038
this.username = env.getOrDefault("APP_USER", "system");
4139
this.password = extractPassword(env);
42-
this.database = env.getOrDefault("ORACLE_DATABASE", "xepdb1");
40+
this.database = env.getOrDefault("ORACLE_DATABASE", defaultDatabase);
4341
}
4442

4543
private String extractPassword(Map<String, String> env) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docker.compose.service.connection.oracle;
18+
19+
import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
20+
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
21+
22+
/**
23+
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
24+
* for an {@link OracleContainer#FREE} service.
25+
*
26+
* @author Andy Wilkinson
27+
*/
28+
class OracleFreeJdbcDockerComposeConnectionDetailsFactory extends OracleJdbcDockerComposeConnectionDetailsFactory {
29+
30+
protected OracleFreeJdbcDockerComposeConnectionDetailsFactory() {
31+
super(OracleContainer.FREE);
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docker.compose.service.connection.oracle;
18+
19+
import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
20+
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
21+
22+
/**
23+
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
24+
* for an {@link OracleContainer#FREE} service.
25+
*
26+
* @author Andy Wilkinson
27+
*/
28+
class OracleFreeR2dbcDockerComposeConnectionDetailsFactory extends OracleR2dbcDockerComposeConnectionDetailsFactory {
29+
30+
protected OracleFreeR2dbcDockerComposeConnectionDetailsFactory() {
31+
super(OracleContainer.FREE);
32+
}
33+
34+
}

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/oracle/OracleJdbcDockerComposeConnectionDetailsFactory.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,30 @@
2323
import org.springframework.util.StringUtils;
2424

2525
/**
26-
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
27-
* for an {@code oracle-xe} service.
26+
* Base class for a {@link DockerComposeConnectionDetailsFactory} to create
27+
* {@link JdbcConnectionDetails} for an {@code oracle-free} or {@code oracle-xe} service.
2828
*
2929
* @author Moritz Halbritter
3030
* @author Andy Wilkinson
3131
* @author Phillip Webb
3232
*/
33-
class OracleJdbcDockerComposeConnectionDetailsFactory
33+
abstract class OracleJdbcDockerComposeConnectionDetailsFactory
3434
extends DockerComposeConnectionDetailsFactory<JdbcConnectionDetails> {
3535

36-
protected OracleJdbcDockerComposeConnectionDetailsFactory() {
37-
super(OracleEnvironment.CONTAINER_NAMES);
36+
private final String defaultDatabase;
37+
38+
protected OracleJdbcDockerComposeConnectionDetailsFactory(OracleContainer container) {
39+
super(container.getImageName());
40+
this.defaultDatabase = container.getDefaultDatabase();
3841
}
3942

4043
@Override
4144
protected JdbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
42-
return new OracleJdbcDockerComposeConnectionDetails(source.getRunningService());
45+
return new OracleJdbcDockerComposeConnectionDetails(source.getRunningService(), this.defaultDatabase);
4346
}
4447

4548
/**
46-
* {@link JdbcConnectionDetails} backed by an {@code oracle-xe}
49+
* {@link JdbcConnectionDetails} backed by an {@code oracle-xe} or {@code oracle-free}
4750
* {@link RunningService}.
4851
*/
4952
static class OracleJdbcDockerComposeConnectionDetails extends DockerComposeConnectionDetails
@@ -55,9 +58,9 @@ static class OracleJdbcDockerComposeConnectionDetails extends DockerComposeConne
5558

5659
private final String jdbcUrl;
5760

58-
OracleJdbcDockerComposeConnectionDetails(RunningService service) {
61+
OracleJdbcDockerComposeConnectionDetails(RunningService service, String defaultDatabase) {
5962
super(service);
60-
this.environment = new OracleEnvironment(service.env());
63+
this.environment = new OracleEnvironment(service.env(), defaultDatabase);
6164
this.jdbcUrl = "jdbc:oracle:thin:@" + service.host() + ":" + service.ports().get(1521) + "/"
6265
+ this.environment.getDatabase() + getParameters(service);
6366
}

spring-boot-project/spring-boot-docker-compose/src/main/java/org/springframework/boot/docker/compose/service/connection/oracle/OracleR2dbcDockerComposeConnectionDetailsFactory.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,26 @@
2525
import org.springframework.boot.docker.compose.service.connection.r2dbc.ConnectionFactoryOptionsBuilder;
2626

2727
/**
28-
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
29-
* for an {@code oracle-xe} service.
28+
* Base class for a {@link DockerComposeConnectionDetailsFactory} to create
29+
* {@link R2dbcConnectionDetails} for an {@code oracle-free} or {@code oracle-xe} service.
3030
*
3131
* @author Moritz Halbritter
3232
* @author Andy Wilkinson
3333
* @author Phillip Webb
3434
*/
35-
class OracleR2dbcDockerComposeConnectionDetailsFactory
35+
abstract class OracleR2dbcDockerComposeConnectionDetailsFactory
3636
extends DockerComposeConnectionDetailsFactory<R2dbcConnectionDetails> {
3737

38-
OracleR2dbcDockerComposeConnectionDetailsFactory() {
39-
super(OracleEnvironment.CONTAINER_NAMES, "io.r2dbc.spi.ConnectionFactoryOptions");
38+
private final String defaultDatabase;
39+
40+
OracleR2dbcDockerComposeConnectionDetailsFactory(OracleContainer container) {
41+
super(container.getImageName(), "io.r2dbc.spi.ConnectionFactoryOptions");
42+
this.defaultDatabase = container.getDefaultDatabase();
4043
}
4144

4245
@Override
4346
protected R2dbcConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
44-
return new OracleDbR2dbcDockerComposeConnectionDetails(source.getRunningService());
47+
return new OracleDbR2dbcDockerComposeConnectionDetails(source.getRunningService(), this.defaultDatabase);
4548
}
4649

4750
/**
@@ -56,9 +59,9 @@ static class OracleDbR2dbcDockerComposeConnectionDetails extends DockerComposeCo
5659

5760
private final ConnectionFactoryOptions connectionFactoryOptions;
5861

59-
OracleDbR2dbcDockerComposeConnectionDetails(RunningService service) {
62+
OracleDbR2dbcDockerComposeConnectionDetails(RunningService service, String defaultDatabase) {
6063
super(service);
61-
OracleEnvironment environment = new OracleEnvironment(service.env());
64+
OracleEnvironment environment = new OracleEnvironment(service.env(), defaultDatabase);
6265
this.connectionFactoryOptions = connectionFactoryOptionsBuilder.build(service, environment.getDatabase(),
6366
environment.getUsername(), environment.getPassword());
6467
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docker.compose.service.connection.oracle;
18+
19+
import org.springframework.boot.autoconfigure.jdbc.JdbcConnectionDetails;
20+
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
21+
22+
/**
23+
* {@link DockerComposeConnectionDetailsFactory} to create {@link JdbcConnectionDetails}
24+
* for an {@link OracleContainer#XE} service.
25+
*
26+
* @author Andy Wilkinson
27+
*/
28+
class OracleXeJdbcDockerComposeConnectionDetailsFactory extends OracleJdbcDockerComposeConnectionDetailsFactory {
29+
30+
protected OracleXeJdbcDockerComposeConnectionDetailsFactory() {
31+
super(OracleContainer.XE);
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.docker.compose.service.connection.oracle;
18+
19+
import org.springframework.boot.autoconfigure.r2dbc.R2dbcConnectionDetails;
20+
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
21+
22+
/**
23+
* {@link DockerComposeConnectionDetailsFactory} to create {@link R2dbcConnectionDetails}
24+
* for an {@link OracleContainer#XE} service.
25+
*
26+
* @author Andy Wilkinson
27+
*/
28+
class OracleXeR2dbcDockerComposeConnectionDetailsFactory extends OracleR2dbcDockerComposeConnectionDetailsFactory {
29+
30+
protected OracleXeR2dbcDockerComposeConnectionDetailsFactory() {
31+
super(OracleContainer.XE);
32+
}
33+
34+
}

spring-boot-project/spring-boot-docker-compose/src/main/resources/META-INF/spring.factories

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ org.springframework.boot.docker.compose.service.connection.mongo.MongoDockerComp
1616
org.springframework.boot.docker.compose.service.connection.mysql.MySqlJdbcDockerComposeConnectionDetailsFactory,\
1717
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
1818
org.springframework.boot.docker.compose.service.connection.neo4j.Neo4jDockerComposeConnectionDetailsFactory,\
19-
org.springframework.boot.docker.compose.service.connection.oracle.OracleJdbcDockerComposeConnectionDetailsFactory,\
20-
org.springframework.boot.docker.compose.service.connection.oracle.OracleR2dbcDockerComposeConnectionDetailsFactory,\
19+
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeJdbcDockerComposeConnectionDetailsFactory,\
20+
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeJdbcDockerComposeConnectionDetailsFactory,\
21+
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeR2dbcDockerComposeConnectionDetailsFactory,\
22+
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeR2dbcDockerComposeConnectionDetailsFactory,\
2123
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryMetricsDockerComposeConnectionDetailsFactory,\
2224
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryTracingDockerComposeConnectionDetailsFactory,\
2325
org.springframework.boot.docker.compose.service.connection.postgres.PostgresJdbcDockerComposeConnectionDetailsFactory,\

0 commit comments

Comments
 (0)