Skip to content

Commit 4859a94

Browse files
committed
[#1906] Collect CockroachDB special cases in one method
It makes it easier to remove the hack once the issue in Hibernate ORM is solved: https://hibernate.atlassian.net/browse/HHH-19717
1 parent 41a86a5 commit 4859a94

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/generator/values/internal/ReactiveGeneratedValuesHelper.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ public static GeneratedValuesMutationDelegate getGeneratedValuesDelegate(EntityP
7979
.anyMatch( part -> part instanceof SelectableMapping selectable
8080
&& selectable.isFormula() );
8181

82-
// Cockroach supports insert returning it but the CockroachDb#supportsInsertReturningRowId() wrongly returns false ( https://hibernate.atlassian.net/browse/HHH-19717 )
83-
boolean supportsInsertReturningRowId = dialect.supportsInsertReturningRowId() || dialect instanceof CockroachDialect;
82+
boolean supportsInsertReturningRowId = trueIfCockroach( dialect, dialect.supportsInsertReturningRowId() );
8483
if ( hasRowId
8584
&& supportsInsertReturning( dialect )
8685
&& supportsInsertReturningRowId
@@ -107,27 +106,29 @@ else if ( timing == EventType.INSERT && persister.getNaturalIdentifierProperties
107106
return null;
108107
}
109108

109+
/**
110+
* Cockroach supports returning SQL for insert and update statements, but the dialect wrongly returns false.
111+
* @see <a href="https://hibernate.atlassian.net/browse/HHH-19717">HHH-19717</a>
112+
*/
113+
private static boolean trueIfCockroach(Dialect dialect, boolean predicate) {
114+
return predicate || dialect instanceof CockroachDialect;
115+
}
116+
110117
public static boolean supportReactiveGetGeneratedKey(Dialect dialect, List<? extends ModelPart> generatedProperties) {
111118
return dialect instanceof OracleDialect
112119
|| (dialect instanceof MySQLDialect && generatedProperties.size() == 1 && !(dialect instanceof MariaDBDialect));
113120
}
114121

115122
public static boolean supportsReturning(Dialect dialect, EventType timing) {
116-
if ( dialect instanceof CockroachDialect ) {
117-
// Cockroach supports insert and update returning but the CockroachDb#supportsInsertReturning() wrongly returns false ( https://hibernate.atlassian.net/browse/HHH-19717 )
118-
return true;
119-
}
120-
return timing == EventType.INSERT
121-
? dialect.supportsInsertReturning()
122-
: dialect.supportsUpdateReturning();
123+
return trueIfCockroach(
124+
dialect, timing == EventType.INSERT
125+
? dialect.supportsInsertReturning()
126+
: dialect.supportsUpdateReturning()
127+
);
123128
}
124129

125130
public static boolean supportsInsertReturning(Dialect dialect) {
126-
if ( dialect instanceof CockroachDialect ) {
127-
// Cockroach supports insert returning but the CockroachDb#supportsInsertReturning() wrongly returns false ( https://hibernate.atlassian.net/browse/HHH-19717 )
128-
return true;
129-
}
130-
return dialect.supportsInsertReturning();
131+
return trueIfCockroach( dialect, dialect.supportsInsertReturning() );
131132
}
132133

133134
/**

0 commit comments

Comments
 (0)