Skip to content

Commit

Permalink
HHH-7725 - Make handling multi-table bulk HQL operations more pluggable
Browse files Browse the repository at this point in the history
(cherry picked from commit c94752d)
  • Loading branch information
sebersole committed Oct 31, 2012
1 parent e3239ae commit e32d7f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
Expand Up @@ -312,6 +312,23 @@ public String getCastTypeName(int code) {
return getTypeName( code, Column.DEFAULT_LENGTH, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE );
}

public String cast(String value, int jdbcTypeCode, int length, int precision, int scale) {
if ( jdbcTypeCode == Types.CHAR ) {
return "cast(" + value + " as char(" + length + "))";
}
else {
return "cast(" + value + "as " + getTypeName( jdbcTypeCode, length, precision, scale ) + ")";
}
}

public String cast(String value, int jdbcTypeCode, int length) {
return cast( value, jdbcTypeCode, length, Column.DEFAULT_PRECISION, Column.DEFAULT_SCALE );
}

public String cast(String value, int jdbcTypeCode, int precision, int scale) {
return cast( value, jdbcTypeCode, Column.DEFAULT_LENGTH, precision, scale );
}

/**
* Subclasses register a type name for the given type code and maximum
* column length. <tt>$l</tt> in the type name with be replaced by the
Expand Down
Expand Up @@ -27,6 +27,7 @@
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -212,7 +213,10 @@ public DeleteHandler buildDeleteHandler(SessionFactoryImplementor factory, HqlSq
return new TableBasedDeleteHandlerImpl( factory, walker ) {
@Override
protected String extraIdSelectValues() {
return "cast(? as char)";
final Dialect dialect = factory().getDialect();
return dialect.requiresCastingOfParametersInSelectClause()
? dialect.cast( "?", Types.CHAR, 36 )
: "?";
}

@Override
Expand Down

0 comments on commit e32d7f2

Please sign in to comment.