Skip to content

Support for Id generation in Oracle using quoted identifiers #1667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-nulls-first-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data Relational Parent</name>
Expand Down
2 changes: 1 addition & 1 deletion spring-data-jdbc-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-nulls-first-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
4 changes: 2 additions & 2 deletions spring-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-jdbc</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-nulls-first-SNAPSHOT</version>

<name>Spring Data JDBC</name>
<description>Spring Data module for JDBC repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-nulls-first-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public Object[] execute(String sql, SqlParameterSource[] sqlParameterSources) {
IdGeneration idGeneration = dialect.getIdGeneration();
if (idGeneration.driverRequiresKeyColumnNames()) {

String[] keyColumnNames = getKeyColumnNames();
String[] keyColumnNames = getKeyColumnNames(idGeneration);
if (keyColumnNames.length == 0) {
jdbcOperations.batchUpdate(sql, sqlParameterSources, holder);
} else {
Expand All @@ -94,10 +94,10 @@ public Object[] execute(String sql, SqlParameterSource[] sqlParameterSources) {
return ids;
}

private String[] getKeyColumnNames() {
private String[] getKeyColumnNames(IdGeneration idGeneration) {

return Optional.ofNullable(idColumn)
.map(idColumn -> new String[] { idColumn.getReference() })
.map(idColumn -> new String[] {idGeneration.getKeyColumnName( idColumn) })
.orElse(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Object execute(String sql, SqlParameterSource sqlParameterSource) {

if (idGeneration.driverRequiresKeyColumnNames()) {

String[] keyColumnNames = getKeyColumnNames();
String[] keyColumnNames = getKeyColumnNames(idGeneration);
if (keyColumnNames.length == 0) {
jdbcOperations.update(sql, sqlParameterSource, holder);
} else {
Expand All @@ -84,8 +84,8 @@ public Object execute(String sql, SqlParameterSource sqlParameterSource) {
}
}

private String[] getKeyColumnNames() {
return Optional.ofNullable(idColumn).map(idColumn -> new String[] { idColumn.getReference() })
private String[] getKeyColumnNames(IdGeneration idGeneration) {
return Optional.ofNullable(idColumn).map(idColumn -> new String[] { idGeneration.getKeyColumnName(idColumn) })
.orElse(new String[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ void findOneByQueryToManyResults() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithReferencedEntityById() {

template.save(legoSet);
Expand All @@ -304,7 +303,6 @@ void saveAndLoadAnEntityWithReferencedEntityById() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadManyEntitiesWithReferencedEntity() {

template.save(legoSet);
Expand All @@ -317,7 +315,6 @@ void saveAndLoadManyEntitiesWithReferencedEntity() {
}

@Test // DATAJDBC-101
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadManyEntitiesWithReferencedEntitySorted() {

template.save(createLegoSet("Lava"));
Expand All @@ -332,7 +329,6 @@ void saveAndLoadManyEntitiesWithReferencedEntitySorted() {
}

@Test // DATAJDBC-101
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadManyEntitiesWithReferencedEntitySortedAndPaged() {

template.save(createLegoSet("Lava"));
Expand All @@ -347,7 +343,7 @@ void saveAndLoadManyEntitiesWithReferencedEntitySortedAndPaged() {
}

@Test // GH-821
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS, SUPPORTS_NULL_PRECEDENCE })
@EnabledOnFeature(SUPPORTS_NULL_PRECEDENCE)
void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullPrecedence() {

template.save(createLegoSet(null));
Expand All @@ -363,15 +359,13 @@ void saveAndLoadManyEntitiesWithReferencedEntitySortedWithNullPrecedence() {
}

@Test //
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS })
void findByNonPropertySortFails() {

assertThatThrownBy(() -> template.findAll(LegoSet.class, Sort.by("somethingNotExistant")))
.isInstanceOf(InvalidPersistentPropertyPath.class);
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadManyEntitiesByIdWithReferencedEntity() {

template.save(legoSet);
Expand All @@ -383,7 +377,6 @@ void saveAndLoadManyEntitiesByIdWithReferencedEntity() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithReferencedNullEntity() {

legoSet.manual = null;
Expand All @@ -396,7 +389,6 @@ void saveAndLoadAnEntityWithReferencedNullEntity() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndDeleteAnEntityWithReferencedEntity() {

template.save(legoSet);
Expand All @@ -408,7 +400,6 @@ void saveAndDeleteAnEntityWithReferencedEntity() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndDeleteAllWithReferencedEntity() {

template.save(legoSet);
Expand All @@ -420,7 +411,6 @@ void saveAndDeleteAllWithReferencedEntity() {
}

@Test // GH-537
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndDeleteAllByAggregateRootsWithReferencedEntity() {

LegoSet legoSet1 = template.save(legoSet);
Expand All @@ -434,7 +424,6 @@ void saveAndDeleteAllByAggregateRootsWithReferencedEntity() {
}

@Test // GH-537
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndDeleteAllByIdsWithReferencedEntity() {

LegoSet legoSet1 = template.save(legoSet);
Expand Down Expand Up @@ -494,7 +483,7 @@ void insertAndUpdateAllByAggregateRootsWithVersion() {
}

@Test // DATAJDBC-112
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS, SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES })
@EnabledOnFeature(SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES)
void updateReferencedEntityFromNull() {

legoSet.manual = (null);
Expand All @@ -513,7 +502,6 @@ void updateReferencedEntityFromNull() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void updateReferencedEntityToNull() {

template.save(legoSet);
Expand Down Expand Up @@ -541,7 +529,6 @@ void updateFailedRootDoesNotExist() {
}

@Test // DATAJDBC-112
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void replaceReferencedEntity() {

template.save(legoSet);
Expand All @@ -559,7 +546,7 @@ void replaceReferencedEntity() {
}

@Test // DATAJDBC-112
@EnabledOnFeature({ SUPPORTS_QUOTED_IDS, TestDatabaseFeatures.Feature.SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES })
@EnabledOnFeature(TestDatabaseFeatures.Feature.SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES)
void changeReferencedEntity() {

template.save(legoSet);
Expand All @@ -574,7 +561,6 @@ void changeReferencedEntity() {
}

@Test // DATAJDBC-266
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void oneToOneChildWithoutId() {

OneToOneParent parent = new OneToOneParent();
Expand All @@ -591,7 +577,6 @@ void oneToOneChildWithoutId() {
}

@Test // DATAJDBC-266
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void oneToOneNullChildWithoutId() {

OneToOneParent parent = new OneToOneParent();
Expand All @@ -607,7 +592,6 @@ void oneToOneNullChildWithoutId() {
}

@Test // DATAJDBC-266
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void oneToOneNullAttributes() {

OneToOneParent parent = new OneToOneParent();
Expand All @@ -623,7 +607,6 @@ void oneToOneNullAttributes() {
}

@Test // DATAJDBC-125
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithSecondaryReferenceNull() {

template.save(legoSet);
Expand All @@ -636,7 +619,6 @@ void saveAndLoadAnEntityWithSecondaryReferenceNull() {
}

@Test // DATAJDBC-125
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithSecondaryReferenceNotNull() {

legoSet.alternativeInstructions = new Manual();
Expand All @@ -655,7 +637,6 @@ void saveAndLoadAnEntityWithSecondaryReferenceNotNull() {
}

@Test // DATAJDBC-276
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithListOfElementsWithoutId() {

ListParent entity = new ListParent();
Expand All @@ -674,7 +655,6 @@ void saveAndLoadAnEntityWithListOfElementsWithoutId() {
}

@Test // GH-498 DATAJDBC-273
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadAnEntityWithListOfElementsInConstructor() {

ElementNoId element = new ElementNoId();
Expand Down Expand Up @@ -815,7 +795,6 @@ void saveAndLoadAnEntityWithByteArray() {
}

@Test // DATAJDBC-340
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadLongChain() {

Chain4 chain4 = new Chain4();
Expand Down Expand Up @@ -844,7 +823,6 @@ void saveAndLoadLongChain() {
}

@Test // DATAJDBC-359
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void saveAndLoadLongChainWithoutIds() {

NoIdChain4 chain4 = new NoIdChain4();
Expand Down Expand Up @@ -1084,7 +1062,6 @@ void saveAndUpdateAggregateWithIdAndNullVersion() {
}

@Test // DATAJDBC-462
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
void resavingAnUnversionedEntity() {

LegoSet legoSet = new LegoSet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class JdbcAggregateTemplateSchemaIntegrationTests {
@Autowired NamedParameterJdbcOperations jdbcTemplate;

@Test
@EnabledOnFeature(SUPPORTS_QUOTED_IDS)
public void insertFindUpdateDelete() {

DummyEntity entity = new DummyEntity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.jdbc.testing.DatabaseType;
import org.springframework.data.jdbc.testing.EnabledOnDatabase;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.repository.CrudRepository;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
Expand All @@ -34,6 +36,7 @@
* @author Diego Krupitza
* @since 2.4
*/
@EnabledOnDatabase(DatabaseType.HSQL)
abstract class AbstractJdbcRepositoryLookUpStrategyTests {

@Autowired protected OnesRepository onesRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public TestDatabaseFeatures(JdbcOperations jdbcTemplate) {
String productName = jdbcTemplate.execute(
(ConnectionCallback<String>) c -> c.getMetaData().getDatabaseProductName().toLowerCase(Locale.ENGLISH));

database = Arrays.stream(Database.values()).filter(db -> db.matches(productName)).findFirst().get();
database = Arrays.stream(Database.values()).filter(db -> db.matches(productName)).findFirst().orElseThrow();
}

/**
Expand All @@ -50,15 +50,6 @@ private void supportsHugeNumbers() {
assumeThat(database).isNotIn(Database.Oracle, Database.SqlServer);
}

/**
* Oracles JDBC driver seems to have a bug that makes it impossible to acquire generated keys when the column is
* quoted. See
* https://stackoverflow.com/questions/62263576/how-to-get-the-generated-key-for-a-column-with-lowercase-characters-from-oracle
*/
private void supportsQuotedIds() {
assumeThat(database).isNotEqualTo(Database.Oracle);
}

/**
* Microsoft SqlServer does not allow explicitly setting ids in columns where the value gets generated by the
* database. Such columns therefore must not be used in referenced entities, since we do a delete and insert, which
Expand Down Expand Up @@ -115,7 +106,6 @@ boolean matches(String productName) {
public enum Feature {

SUPPORTS_MULTIDIMENSIONAL_ARRAYS(TestDatabaseFeatures::supportsMultiDimensionalArrays), //
SUPPORTS_QUOTED_IDS(TestDatabaseFeatures::supportsQuotedIds), //
SUPPORTS_HUGE_NUMBERS(TestDatabaseFeatures::supportsHugeNumbers), //
SUPPORTS_ARRAYS(TestDatabaseFeatures::supportsArrays), //
SUPPORTS_GENERATED_IDS_IN_REFERENCED_ENTITIES(TestDatabaseFeatures::supportsGeneratedIdsInReferencedEntities), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CREATE TABLE MANUAL
(
"id2" NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY,
LEGO_SET NUMBER,
ALTERNATIVE NUMBER,
"alternative" NUMBER,
CONTENT VARCHAR(2000)
);

Expand All @@ -67,7 +67,7 @@ CREATE TABLE ONE_TO_ONE_PARENT
CREATE TABLE Child_No_Id
(
ONE_TO_ONE_PARENT INTEGER PRIMARY KEY,
"content" VARCHAR(30)
CONTENT VARCHAR(30)
);

CREATE TABLE LIST_PARENT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
DROP USER OTHER CASCADE;


CREATE USER OTHER;

ALTER USER OTHER QUOTA UNLIMITED ON USERS;

CREATE TABLE OTHER.DUMMY_ENTITY
(
ID NUMBER GENERATED by default on null as IDENTITY PRIMARY KEY,
Expand Down
4 changes: 2 additions & 2 deletions spring-data-r2dbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>spring-data-r2dbc</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-nulls-first-SNAPSHOT</version>

<name>Spring Data R2DBC</name>
<description>Spring Data module for R2DBC</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-relational-parent</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-nulls-first-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Loading