clean up some code duplication!

cc @beikov
This commit is contained in:
Gavin 2022-11-11 15:53:28 +01:00 committed by Gavin King
parent f0ea66b872
commit 53d9935237
2 changed files with 33 additions and 101 deletions

View File

@ -556,6 +556,22 @@ public class SqlTypes {
} }
} }
/**
* Does the given JDBC type code represent some sort of
* variable-length binary string or BLOB type?
* @param typeCode a JDBC type code from {@link Types}
*/
public static boolean isBinaryType(int typeCode) {
switch ( typeCode ) {
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BLOB:
return true;
}
return false;
}
/** /**
* Does the given typecode represent one of the two SQL decimal types? * Does the given typecode represent one of the two SQL decimal types?
* @param typeCode a JDBC type code from {@link Types} * @param typeCode a JDBC type code from {@link Types}
@ -598,6 +614,13 @@ public class SqlTypes {
|| typeCode == TIMESTAMP_UTC; || typeCode == TIMESTAMP_UTC;
} }
/**
* Does the given typecode represent a SQL {@code interval} type?
*/
public static boolean isIntervalType(int typeCode) {
return typeCode == INTERVAL_SECOND;
}
/** /**
* Does the given typecode represent a SQL date or timestamp type? * Does the given typecode represent a SQL date or timestamp type?
* @param typeCode a JDBC type code from {@link Types} * @param typeCode a JDBC type code from {@link Types}

View File

@ -120,128 +120,37 @@ public interface JdbcType extends Serializable {
} }
default boolean isInteger() { default boolean isInteger() {
return isInteger( getJdbcTypeCode() ); int typeCode = getJdbcTypeCode();
} return SqlTypes.isIntegral(typeCode)
|| typeCode == Types.BIT; //HIGHLY DUBIOUS!
static boolean isInteger(int typeCode) {
switch ( typeCode ) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
return true;
}
return false;
} }
default boolean isFloat() { default boolean isFloat() {
return isFloat( getJdbcTypeCode() ); return SqlTypes.isFloatOrRealOrDouble( getJdbcTypeCode() );
}
static boolean isFloat(int typeCode) {
switch ( typeCode ) {
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
return true;
}
return false;
} }
default boolean isDecimal() { default boolean isDecimal() {
return isDecimal( getJdbcTypeCode() ); return SqlTypes.isNumericOrDecimal( getJdbcTypeCode() );
}
static boolean isDecimal(int typeCode) {
switch ( typeCode ) {
case Types.DECIMAL:
case Types.NUMERIC:
return true;
}
return false;
} }
default boolean isNumber() { default boolean isNumber() {
return isNumber( getJdbcTypeCode() ); return SqlTypes.isNumericType( getJdbcTypeCode() );
}
static boolean isNumber(int typeCode) {
switch ( typeCode ) {
case Types.BIT:
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
case Types.DECIMAL:
case Types.NUMERIC:
return true;
}
return false;
} }
default boolean isBinary() { default boolean isBinary() {
return isBinary( getJdbcTypeCode() ); return SqlTypes.isBinaryType( getJdbcTypeCode() );
}
static boolean isBinary(int typeCode) {
switch ( typeCode ) {
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BLOB:
return true;
}
return false;
} }
default boolean isString() { default boolean isString() {
return isString( getJdbcTypeCode() ); return SqlTypes.isCharacterOrClobType( getJdbcTypeCode() );
}
static boolean isString(int typeCode) {
switch ( typeCode ) {
case Types.CHAR:
case Types.NCHAR:
case Types.VARCHAR:
case Types.NVARCHAR:
case Types.LONGVARCHAR:
case Types.LONGNVARCHAR:
case Types.CLOB:
case Types.NCLOB:
return true;
}
return false;
} }
default boolean isTemporal() { default boolean isTemporal() {
return isTemporal( getDefaultSqlTypeCode() ); return SqlTypes.isTemporalType( getDefaultSqlTypeCode() );
}
static boolean isTemporal(int typeCode) {
switch ( typeCode ) {
case Types.DATE:
case Types.TIME:
case Types.TIMESTAMP:
case Types.TIMESTAMP_WITH_TIMEZONE:
return true;
}
return false;
} }
default boolean isInterval() { default boolean isInterval() {
return isInterval( getDefaultSqlTypeCode() ); return SqlTypes.isIntervalType( getDefaultSqlTypeCode() );
}
static boolean isInterval(int typeCode) {
switch ( typeCode ) {
case SqlTypes.INTERVAL_SECOND:
return true;
}
return false;
} }
default CastType getCastType() { default CastType getCastType() {