HHH-9110 make it easier to set ResultCheckType from TypeBinder

This was already possible, but not very comfortable when not also
setting custom SQL.
This commit is contained in:
Gavin King 2024-03-10 00:09:36 +01:00
parent 30b8cdeb84
commit 17f1221db2
6 changed files with 122 additions and 52 deletions

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.engine.spi;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.ResultCheckStyle;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -28,7 +29,7 @@ public enum ExecuteUpdateResultCheckStyle {
* checks are being performed explicitly and failures are handled through
* propagation of {@link java.sql.SQLException}s.
*/
NONE( "none" ),
NONE,
/**
* Perform row count checking. Row counts are the int values returned by both
@ -36,7 +37,7 @@ public enum ExecuteUpdateResultCheckStyle {
* {@link java.sql.Statement#executeBatch()}. These values are checked
* against some expected count.
*/
COUNT( "rowcount" ),
COUNT,
/**
* Essentially the same as {@link #COUNT} except that the row count actually
@ -44,16 +45,19 @@ public enum ExecuteUpdateResultCheckStyle {
* {@link java.sql.CallableStatement}. This style explicitly prohibits
* statement batching from being used...
*/
PARAM( "param" );
private final String name;
ExecuteUpdateResultCheckStyle(String name) {
this.name = name;
}
PARAM;
public String externalName() {
return name;
switch (this) {
case NONE:
return "none";
case COUNT:
return "rowcount";
case PARAM:
return "param";
default:
throw new AssertionFailure("Unrecognized ExecuteUpdateResultCheckStyle");
}
}
public static @Nullable ExecuteUpdateResultCheckStyle fromResultCheckStyle(ResultCheckStyle style) {
@ -70,18 +74,12 @@ public enum ExecuteUpdateResultCheckStyle {
}
public static @Nullable ExecuteUpdateResultCheckStyle fromExternalName(String name) {
if ( name.equalsIgnoreCase( NONE.name ) ) {
return NONE;
}
else if ( name.equalsIgnoreCase( COUNT.name ) ) {
return COUNT;
}
else if ( name.equalsIgnoreCase( PARAM.name ) ) {
return PARAM;
}
else {
return null;
for ( ExecuteUpdateResultCheckStyle style : values() ) {
if ( style.externalName().equalsIgnoreCase(name) ) {
return style;
}
}
return null;
}
public static ExecuteUpdateResultCheckStyle determineDefault(@Nullable String customSql, boolean callable) {

View File

@ -143,6 +143,18 @@ public class Join implements AttributeContainer, Serializable {
return customInsertCallable;
}
public void setInsertCheckStyle(ExecuteUpdateResultCheckStyle insertCheckStyle) {
this.insertCheckStyle = insertCheckStyle;
}
public ExecuteUpdateResultCheckStyle getInsertCheckStyle() {
return insertCheckStyle;
}
/**
* @deprecated use {@link #getInsertCheckStyle()}
*/
@Deprecated(since = "6.5", forRemoval = true)
public ExecuteUpdateResultCheckStyle getCustomSQLInsertCheckStyle() {
return insertCheckStyle;
}
@ -161,6 +173,18 @@ public class Join implements AttributeContainer, Serializable {
return customUpdateCallable;
}
public void setUpdateCheckStyle(ExecuteUpdateResultCheckStyle updateCheckStyle) {
this.updateCheckStyle = updateCheckStyle;
}
public ExecuteUpdateResultCheckStyle getUpdateCheckStyle() {
return updateCheckStyle;
}
/**
* @deprecated use {@link #getUpdateCheckStyle()}
*/
@Deprecated(since = "6.5", forRemoval = true)
public ExecuteUpdateResultCheckStyle getCustomSQLUpdateCheckStyle() {
return updateCheckStyle;
}
@ -179,6 +203,18 @@ public class Join implements AttributeContainer, Serializable {
return customDeleteCallable;
}
public void setDeleteCheckStyle(ExecuteUpdateResultCheckStyle deleteCheckStyle) {
this.deleteCheckStyle = deleteCheckStyle;
}
public ExecuteUpdateResultCheckStyle getDeleteCheckStyle() {
return deleteCheckStyle;
}
/**
* @deprecated use {@link #getDeleteCheckStyle()}
*/
@Deprecated(since = "6.5", forRemoval = true)
public ExecuteUpdateResultCheckStyle getCustomSQLDeleteCheckStyle() {
return deleteCheckStyle;
}

View File

@ -232,7 +232,7 @@ public abstract class PersistentClass implements IdentifiableTypeClass, Attribut
}
public boolean hasSubclasses() {
return subclasses.size() > 0;
return !subclasses.isEmpty();
}
public int getSubclassSpan() {
@ -817,6 +817,18 @@ public abstract class PersistentClass implements IdentifiableTypeClass, Attribut
return customInsertCallable;
}
public void setInsertCheckStyle(ExecuteUpdateResultCheckStyle insertCheckStyle) {
this.insertCheckStyle = insertCheckStyle;
}
public ExecuteUpdateResultCheckStyle getInsertCheckStyle() {
return insertCheckStyle;
}
/**
* @deprecated use {@link #getInsertCheckStyle()}
*/
@Deprecated(since = "6.5", forRemoval = true)
public ExecuteUpdateResultCheckStyle getCustomSQLInsertCheckStyle() {
return insertCheckStyle;
}
@ -845,6 +857,18 @@ public abstract class PersistentClass implements IdentifiableTypeClass, Attribut
return customUpdateCallable;
}
public void setUpdateCheckStyle(ExecuteUpdateResultCheckStyle updateCheckStyle) {
this.updateCheckStyle = updateCheckStyle;
}
public ExecuteUpdateResultCheckStyle getUpdateCheckStyle() {
return updateCheckStyle;
}
/**
* @deprecated use {@link #getUpdateCheckStyle()}
*/
@Deprecated(since = "6.5", forRemoval = true)
public ExecuteUpdateResultCheckStyle getCustomSQLUpdateCheckStyle() {
return updateCheckStyle;
}
@ -873,6 +897,18 @@ public abstract class PersistentClass implements IdentifiableTypeClass, Attribut
return customDeleteCallable;
}
public void setDeleteCheckStyle(ExecuteUpdateResultCheckStyle deleteCheckStyle) {
this.deleteCheckStyle = deleteCheckStyle;
}
public ExecuteUpdateResultCheckStyle getDeleteCheckStyle() {
return deleteCheckStyle;
}
/**
* @deprecated use {@link #getDeleteCheckStyle()}
*/
@Deprecated(since = "6.5", forRemoval = true)
public ExecuteUpdateResultCheckStyle getCustomSQLDeleteCheckStyle() {
return deleteCheckStyle;
}

View File

@ -411,25 +411,25 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
customSQLInsert[jk] = currentClass.getCustomSQLInsert();
insertCallable[jk] = customSQLInsert[jk] != null && currentClass.isCustomInsertCallable();
insertExpectations[jk] = appropriateExpectation(
currentClass.getCustomSQLInsertCheckStyle() == null
currentClass.getInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[jk], insertCallable[jk] )
: currentClass.getCustomSQLInsertCheckStyle()
: currentClass.getInsertCheckStyle()
);
customSQLUpdate[jk] = currentClass.getCustomSQLUpdate();
updateCallable[jk] = customSQLUpdate[jk] != null && currentClass.isCustomUpdateCallable();
updateExpectations[jk] = appropriateExpectation(
currentClass.getCustomSQLUpdateCheckStyle() == null
currentClass.getUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[jk], updateCallable[jk] )
: currentClass.getCustomSQLUpdateCheckStyle()
: currentClass.getUpdateCheckStyle()
);
customSQLDelete[jk] = currentClass.getCustomSQLDelete();
deleteCallable[jk] = customSQLDelete[jk] != null && currentClass.isCustomDeleteCallable();
deleteExpectations[jk] = appropriateExpectation(
currentClass.getCustomSQLDeleteCheckStyle() == null
currentClass.getDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[jk], deleteCallable[jk] )
: currentClass.getCustomSQLDeleteCheckStyle()
: currentClass.getDeleteCheckStyle()
);
jk--;
@ -448,25 +448,25 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
customSQLInsert[j] = join.getCustomSQLInsert();
insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable();
insertExpectations[j] = appropriateExpectation(
join.getCustomSQLInsertCheckStyle() == null
join.getInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] )
: join.getCustomSQLInsertCheckStyle()
: join.getInsertCheckStyle()
);
customSQLUpdate[j] = join.getCustomSQLUpdate();
updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable();
updateExpectations[j] = appropriateExpectation(
join.getCustomSQLUpdateCheckStyle() == null
join.getUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] )
: join.getCustomSQLUpdateCheckStyle()
: join.getUpdateCheckStyle()
);
customSQLDelete[j] = join.getCustomSQLDelete();
deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable();
deleteExpectations[j] = appropriateExpectation(
join.getCustomSQLDeleteCheckStyle() == null
join.getDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] )
: join.getCustomSQLDeleteCheckStyle()
: join.getDeleteCheckStyle()
);
j++;

View File

@ -172,25 +172,25 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
customSQLInsert[0] = persistentClass.getCustomSQLInsert();
insertCallable[0] = customSQLInsert[0] != null && persistentClass.isCustomInsertCallable();
insertExpectations[0] = appropriateExpectation(
persistentClass.getCustomSQLInsertCheckStyle() == null
persistentClass.getInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[0], insertCallable[0] )
: persistentClass.getCustomSQLInsertCheckStyle()
: persistentClass.getInsertCheckStyle()
);
customSQLUpdate[0] = persistentClass.getCustomSQLUpdate();
updateCallable[0] = customSQLUpdate[0] != null && persistentClass.isCustomUpdateCallable();
updateExpectations[0] = appropriateExpectation(
persistentClass.getCustomSQLUpdateCheckStyle() == null
persistentClass.getUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[0], updateCallable[0] )
: persistentClass.getCustomSQLUpdateCheckStyle()
: persistentClass.getUpdateCheckStyle()
);
customSQLDelete[0] = persistentClass.getCustomSQLDelete();
deleteCallable[0] = customSQLDelete[0] != null && persistentClass.isCustomDeleteCallable();
deleteExpectations[0] = appropriateExpectation(
persistentClass.getCustomSQLDeleteCheckStyle() == null
persistentClass.getDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[0], deleteCallable[0] )
: persistentClass.getCustomSQLDeleteCheckStyle()
: persistentClass.getDeleteCheckStyle()
);
// JOINS
@ -209,25 +209,25 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
customSQLInsert[j] = join.getCustomSQLInsert();
insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable();
insertExpectations[j] = appropriateExpectation(
join.getCustomSQLInsertCheckStyle() == null
join.getInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLInsert[j], insertCallable[j] )
: join.getCustomSQLInsertCheckStyle()
: join.getInsertCheckStyle()
);
customSQLUpdate[j] = join.getCustomSQLUpdate();
updateCallable[j] = customSQLUpdate[j] != null && join.isCustomUpdateCallable();
updateExpectations[j] = appropriateExpectation(
join.getCustomSQLUpdateCheckStyle() == null
join.getUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLUpdate[j], updateCallable[j] )
: join.getCustomSQLUpdateCheckStyle()
: join.getUpdateCheckStyle()
);
customSQLDelete[j] = join.getCustomSQLDelete();
deleteCallable[j] = customSQLDelete[j] != null && join.isCustomDeleteCallable();
deleteExpectations[j] = appropriateExpectation(
join.getCustomSQLDeleteCheckStyle() == null
join.getDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( customSQLDelete[j], deleteCallable[j] )
: join.getCustomSQLDeleteCheckStyle()
: join.getDeleteCheckStyle()
);
keyColumnNames[j] = new String[join.getKey().getColumnSpan()];

View File

@ -132,9 +132,9 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
callable = sql != null && persistentClass.isCustomInsertCallable();
checkStyle = sql == null
? ExecuteUpdateResultCheckStyle.COUNT
: persistentClass.getCustomSQLInsertCheckStyle() == null
: persistentClass.getInsertCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable )
: persistentClass.getCustomSQLInsertCheckStyle();
: persistentClass.getInsertCheckStyle();
customSQLInsert = new String[] {sql};
insertCallable = new boolean[] {callable};
insertExpectations = new Expectation[] { appropriateExpectation( checkStyle ) };
@ -143,9 +143,9 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
callable = sql != null && persistentClass.isCustomUpdateCallable();
checkStyle = sql == null
? ExecuteUpdateResultCheckStyle.COUNT
: persistentClass.getCustomSQLUpdateCheckStyle() == null
: persistentClass.getUpdateCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable )
: persistentClass.getCustomSQLUpdateCheckStyle();
: persistentClass.getUpdateCheckStyle();
customSQLUpdate = new String[] {sql};
updateCallable = new boolean[] {callable};
updateExpectations = new Expectation[] { appropriateExpectation( checkStyle ) };
@ -154,9 +154,9 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
callable = sql != null && persistentClass.isCustomDeleteCallable();
checkStyle = sql == null
? ExecuteUpdateResultCheckStyle.COUNT
: persistentClass.getCustomSQLDeleteCheckStyle() == null
: persistentClass.getDeleteCheckStyle() == null
? ExecuteUpdateResultCheckStyle.determineDefault( sql, callable )
: persistentClass.getCustomSQLDeleteCheckStyle();
: persistentClass.getDeleteCheckStyle();
customSQLDelete = new String[] {sql};
deleteCallable = new boolean[] {callable};
deleteExpectations = new Expectation[] { appropriateExpectation( checkStyle ) };