Skip to content

Commit

Permalink
very minor cleanups in Dialect
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin King <gavin@hibernate.org>
  • Loading branch information
gavinking committed Oct 20, 2024
1 parent 0ba7aec commit ed7ba22
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,9 @@ protected String castType(int sqlTypeCode) {
* @see AnsiSqlKeywords
*/
protected void registerDefaultKeywords() {
AnsiSqlKeywords keywords = new AnsiSqlKeywords();
//Not using #registerKeyword as:
// # these are already lowercase
// # better efficiency of addAll as it can pre-size the collections
sqlKeywords.addAll( keywords.sql2003() );
// Not using #registerKeyword() since these are already lowercase,
// better efficiency with addAll() as it can pre-size the collection
sqlKeywords.addAll( new AnsiSqlKeywords().sql2003() );
}

/**
Expand Down Expand Up @@ -673,13 +671,10 @@ protected DatabaseVersion getMinimumSupportedVersion() {
*/
protected Integer resolveSqlTypeCode(String columnTypeName, TypeConfiguration typeConfiguration) {
final int parenthesisIndex = columnTypeName.lastIndexOf( '(' );
final String baseTypeName;
if ( parenthesisIndex == -1 ) {
baseTypeName = columnTypeName;
}
else {
baseTypeName = columnTypeName.substring( 0, parenthesisIndex ).trim();
}
final String baseTypeName =
parenthesisIndex == -1
? columnTypeName
: columnTypeName.substring( 0, parenthesisIndex ).trim();
return resolveSqlTypeCode( columnTypeName, baseTypeName, typeConfiguration );
}

Expand Down Expand Up @@ -793,7 +788,7 @@ public String[] getDropEnumTypeCommand(Class<? extends Enum<?>> enumType) {
* @return a SQL expression that will occur in a {@code check} constraint
*/
public String getCheckCondition(String columnName, String[] values) {
StringBuilder check = new StringBuilder();
final StringBuilder check = new StringBuilder();
check.append( columnName ).append( " in (" );
String separator = "";
boolean nullIsValid = false;
Expand Down Expand Up @@ -835,7 +830,7 @@ public String getCheckCondition(String columnName, long min, long max) {
*/
@Deprecated(since="6.5", forRemoval = true)
public String getCheckCondition(String columnName, long[] values) {
Long[] boxedValues = new Long[values.length];
final Long[] boxedValues = new Long[values.length];
for ( int i = 0; i<values.length; i++ ) {
boxedValues[i] = values[i];
}
Expand All @@ -850,7 +845,7 @@ public String getCheckCondition(String columnName, long[] values) {
* @return a SQL expression that will occur in a {@code check} constraint
*/
public String getCheckCondition(String columnName, Long[] values) {
StringBuilder check = new StringBuilder();
final StringBuilder check = new StringBuilder();
check.append( columnName ).append( " in (" );
String separator = "";
boolean nullIsValid = false;
Expand Down Expand Up @@ -878,7 +873,7 @@ public String getCheckCondition(String columnName, Set<?> valueSet, JdbcType jdb
final boolean isCharacterJdbcType = isCharacterType( jdbcType.getJdbcTypeCode() );
assert isCharacterJdbcType || isIntegral( jdbcType.getJdbcTypeCode() );

StringBuilder check = new StringBuilder();
final StringBuilder check = new StringBuilder();
check.append( columnName ).append( " in (" );
String separator = "";
boolean nullIsValid = false;
Expand Down Expand Up @@ -1679,18 +1674,24 @@ public String getFromDualForSelectOnly() {
* for the trim character if {@code isWhitespace}
* was false.
*
* @param specification {@linkplain TrimSpec#LEADING leading}, {@linkplain TrimSpec#TRAILING trailing}
* @param specification
* {@linkplain TrimSpec#LEADING leading},
* {@linkplain TrimSpec#TRAILING trailing},
* or {@linkplain TrimSpec#BOTH both}
* @param isWhitespace {@code true} if the trim character is a whitespace and can be omitted,
* {@code false} if it must be explicit and a ?2 placeholder should be included in the pattern
*
* @param isWhitespace
* {@code true} if trimming whitespace, and the ?2
* placeholder for the trim character should be omitted,
* {@code false} if the trim character is explicit and
* the ?2 placeholder must be included in the pattern
*/
public String trimPattern(TrimSpec specification, boolean isWhitespace) {
return "trim(" + specification + ( isWhitespace ? "" : " ?2" ) + " from ?1)";
}

/**
* Whether the database supports adding a fractional interval to a timestamp,
* for example {@code timestamp + 0.5 second}.
* Whether the database supports adding a fractional interval
* to a timestamp, for example {@code timestamp + 0.5 second}.
*/
public boolean supportsFractionalTimestampArithmetic() {
return true;
Expand Down

0 comments on commit ed7ba22

Please sign in to comment.