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?
* @param typeCode a JDBC type code from {@link Types}
@ -598,6 +614,13 @@ public class SqlTypes {
|| 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?
* @param typeCode a JDBC type code from {@link Types}

View File

@ -120,128 +120,37 @@ public interface JdbcType extends Serializable {
}
default boolean isInteger() {
return isInteger( getJdbcTypeCode() );
}
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;
int typeCode = getJdbcTypeCode();
return SqlTypes.isIntegral(typeCode)
|| typeCode == Types.BIT; //HIGHLY DUBIOUS!
}
default boolean isFloat() {
return isFloat( getJdbcTypeCode() );
}
static boolean isFloat(int typeCode) {
switch ( typeCode ) {
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
return true;
}
return false;
return SqlTypes.isFloatOrRealOrDouble( getJdbcTypeCode() );
}
default boolean isDecimal() {
return isDecimal( getJdbcTypeCode() );
}
static boolean isDecimal(int typeCode) {
switch ( typeCode ) {
case Types.DECIMAL:
case Types.NUMERIC:
return true;
}
return false;
return SqlTypes.isNumericOrDecimal( getJdbcTypeCode() );
}
default boolean isNumber() {
return isNumber( 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;
return SqlTypes.isNumericType( getJdbcTypeCode() );
}
default boolean isBinary() {
return isBinary( getJdbcTypeCode() );
}
static boolean isBinary(int typeCode) {
switch ( typeCode ) {
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case Types.BLOB:
return true;
}
return false;
return SqlTypes.isBinaryType( getJdbcTypeCode() );
}
default boolean isString() {
return isString( 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;
return SqlTypes.isCharacterOrClobType( getJdbcTypeCode() );
}
default boolean isTemporal() {
return isTemporal( 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;
return SqlTypes.isTemporalType( getDefaultSqlTypeCode() );
}
default boolean isInterval() {
return isInterval( getDefaultSqlTypeCode() );
}
static boolean isInterval(int typeCode) {
switch ( typeCode ) {
case SqlTypes.INTERVAL_SECOND:
return true;
}
return false;
return SqlTypes.isIntervalType( getDefaultSqlTypeCode() );
}
default CastType getCastType() {