Skip to content

Commit 4eb92ab

Browse files
schaudermp911de
authored andcommitted
DATAJDBC-256 - Run integration tests with Oracle.
An Oracle database is started in Docker using Testcontainers. Tests that don't work yet are skipped using the TestDatabaseFeatures which allows central control, which database supports which feature. A suitable oracle image is deployed on DockerHub as "springci/spring-data-oracle-xe-prebuild:18.4.0". The official Oracle docker images as described here https://github.com/oracle/docker-images/blob/master/OracleDatabase/SingleInstance/README.md are not suitable since it needs about 15min to start and also TestContainers seems to break it by trying to us it to early. The referenced image was created based on these instructions: https://github.com/oracle/docker-images/tree/master/OracleDatabase/SingleInstance/samples/prebuiltdb The following features don't yet work for Oracle: * Loading of date like properties. * Ids with custom names. * Array support. * Boolean properties. * BigDecimals and BigInteger is limited to what fits into Oracles NUMBER data type. * Entities that use a join during load time, i.e. with a one to one relationship. Original pull request: spring-projects#232.
1 parent 4238f44 commit 4eb92ab

File tree

46 files changed

+1242
-441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1242
-441
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
<exclude>**/*HsqlIntegrationTests.java</exclude>
205205
</excludes>
206206
<systemPropertyVariables>
207-
<spring.profiles.active>orcacle</spring.profiles.active>
207+
<spring.profiles.active>oracle</spring.profiles.active>
208208
</systemPropertyVariables>
209209
</configuration>
210210
</execution>

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class JdbcAggregateChangeExecutionContext {
7272
}
7373

7474
<T> void executeInsertRoot(DbAction.InsertRoot<T> insert) {
75+
7576
RelationalPersistentEntity<T> persistentEntity = getRequiredPersistentEntity(insert.getEntityType());
7677

7778
Object id;

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.springframework.data.mapping.PersistentPropertyAccessor;
3838
import org.springframework.data.mapping.PersistentPropertyPath;
3939
import org.springframework.data.mapping.PropertyHandler;
40-
import org.springframework.data.relational.core.dialect.LockClause;
40+
import org.springframework.data.relational.core.dialect.IdGeneration;
4141
import org.springframework.data.relational.core.mapping.PersistentPropertyPathExtension;
4242
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
4343
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
@@ -122,11 +122,20 @@ public <T> Object insert(T instance, Class<T> domainType, Identifier identifier)
122122

123123
KeyHolder holder = new GeneratedKeyHolder();
124124

125-
operations.update( //
126-
sqlGenerator.getInsert(new HashSet<>(parameterSource.getIdentifiers())), //
127-
parameterSource, //
128-
holder //
129-
);
125+
IdGeneration idGeneration = sqlGeneratorSource.getDialect().getIdGeneration();
126+
String insertSql = sqlGenerator.getInsert(new HashSet<>(parameterSource.getIdentifiers()));
127+
128+
if (idGeneration.driverRequiresKeyColumnNames()) {
129+
130+
String[] keyColumnNames = getKeyColumnNames(domainType);
131+
if (keyColumnNames.length == 0) {
132+
operations.update(insertSql, parameterSource, holder);
133+
} else {
134+
operations.update(insertSql, parameterSource, holder, keyColumnNames);
135+
}
136+
} else {
137+
operations.update(insertSql, parameterSource, holder);
138+
}
130139

131140
return getIdFromHolder(holder, persistentEntity);
132141
}
@@ -567,6 +576,19 @@ private SqlGenerator sql(Class<?> domainType) {
567576
return sqlGeneratorSource.getSqlGenerator(domainType);
568577
}
569578

579+
private <T> String[] getKeyColumnNames(Class<T> domainType) {
580+
581+
RelationalPersistentEntity<?> requiredPersistentEntity = context.getRequiredPersistentEntity(domainType);
582+
583+
if (!requiredPersistentEntity.hasIdProperty()) {
584+
return new String[0];
585+
}
586+
587+
SqlIdentifier idColumn = requiredPersistentEntity.getIdColumn();
588+
589+
return new String[] { idColumn.getReference(getIdentifierProcessing()) };
590+
}
591+
570592
/**
571593
* Utility to create {@link Predicate}s.
572594
*/

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/config/DialectResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.data.relational.core.dialect.H2Dialect;
3434
import org.springframework.data.relational.core.dialect.HsqlDbDialect;
3535
import org.springframework.data.relational.core.dialect.MySqlDialect;
36+
import org.springframework.data.relational.core.dialect.OracleDialect;
3637
import org.springframework.data.relational.core.dialect.PostgresDialect;
3738
import org.springframework.data.relational.core.dialect.SqlServerDialect;
3839
import org.springframework.data.relational.core.sql.IdentifierProcessing;
@@ -131,6 +132,9 @@ private static Dialect getDialect(Connection connection) throws SQLException {
131132
if (name.contains("db2")) {
132133
return Db2Dialect.INSTANCE;
133134
}
135+
if (name.contains("oracle")) {
136+
return OracleDialect.INSTANCE;
137+
}
134138

135139
LOG.info(String.format("Couldn't determine Dialect for \"%s\"", name) );
136140
return null;

0 commit comments

Comments
 (0)