Example usage for org.hibernate.type BigIntegerType INSTANCE

List of usage examples for org.hibernate.type BigIntegerType INSTANCE

Introduction

In this page you can find the example usage for org.hibernate.type BigIntegerType INSTANCE.

Prototype

BigIntegerType INSTANCE

To view the source code for org.hibernate.type BigIntegerType INSTANCE.

Click Source Link

Usage

From source file:com.manydesigns.portofino.persistence.hibernate.HibernateConfig.java

License:Open Source License

public boolean setHibernateType(@Nullable SimpleValue value,
        com.manydesigns.portofino.model.database.Column column, Class javaType, final int jdbcType) {
    String typeName;/*from   w  ww  .  java2 s  .com*/
    Properties typeParams = null;
    if (javaType == null) {
        return false;
    }
    if (javaType == Long.class) {
        typeName = LongType.INSTANCE.getName();
    } else if (javaType == Short.class) {
        typeName = ShortType.INSTANCE.getName();
    } else if (javaType == Integer.class) {
        typeName = IntegerType.INSTANCE.getName();
    } else if (javaType == Byte.class) {
        typeName = ByteType.INSTANCE.getName();
    } else if (javaType == Float.class) {
        typeName = FloatType.INSTANCE.getName();
    } else if (javaType == Double.class) {
        typeName = DoubleType.INSTANCE.getName();
    } else if (javaType == Character.class) {
        typeName = CharacterType.INSTANCE.getName();
    } else if (javaType == String.class) {
        typeName = StringType.INSTANCE.getName();
    } else if (java.util.Date.class.isAssignableFrom(javaType)) {
        switch (jdbcType) {
        case Types.DATE:
            typeName = DateType.INSTANCE.getName();
            break;
        case Types.TIME:
            typeName = TimeType.INSTANCE.getName();
            break;
        case Types.TIMESTAMP:
            typeName = TimestampType.INSTANCE.getName();
            break;
        default:
            typeName = null;
        }
    } else if (javaType == Boolean.class) {
        if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) {
            typeName = BooleanType.INSTANCE.getName();
        } else if (jdbcType == Types.NUMERIC || jdbcType == Types.DECIMAL || jdbcType == Types.INTEGER
                || jdbcType == Types.SMALLINT || jdbcType == Types.TINYINT || jdbcType == Types.BIGINT) {
            typeName = NumericBooleanType.INSTANCE.getName();
        } else if (jdbcType == Types.CHAR || jdbcType == Types.VARCHAR) {
            typeName = StringBooleanType.class.getName();
            typeParams = new Properties();
            typeParams.setProperty("true", trueString != null ? trueString : StringBooleanType.NULL);
            typeParams.setProperty("false", falseString != null ? falseString : StringBooleanType.NULL);
            typeParams.setProperty("sqlType", String.valueOf(jdbcType));
        } else {
            typeName = null;
        }
    } else if (javaType == BigDecimal.class) {
        typeName = BigDecimalType.INSTANCE.getName();
    } else if (javaType == BigInteger.class) {
        typeName = BigIntegerType.INSTANCE.getName();
    } else if (javaType == byte[].class) {
        typeName = BlobType.INSTANCE.getName();
    } else {
        typeName = null;
    }

    if (typeName == null) {
        logger.error("Unsupported type (java type: {}, jdbc type: {}) " + "for column '{}'.",
                new Object[] { javaType, jdbcType, column.getColumnName() });
        return false;
    }

    if (value != null) {
        value.setTypeName(typeName);
        if (typeParams != null) {
            value.setTypeParameters(typeParams);
        }
    }
    return true;
}

From source file:org.babyfish.hibernate.cfg.Configuration.java

License:Open Source License

@SuppressWarnings("unchecked")
private void addNativeFunctions() {
    Map<String, SQLFunction> map = this.getSqlFunctions();

    map.put("nativeInteger", new AbstractNativeFunction() {
        @Override/*from   w w  w .ja va  2 s . c  om*/
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return IntegerType.INSTANCE;
        }
    });
    map.put("nativeLong", new AbstractNativeFunction() {
        @Override
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return LongType.INSTANCE;
        }
    });
    map.put("nativeFloat", new AbstractNativeFunction() {
        @Override
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return FloatType.INSTANCE;
        }
    });
    map.put("nativeDouble", new AbstractNativeFunction() {
        @Override
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return DoubleType.INSTANCE;
        }
    });
    map.put("nativeBigInteger", new AbstractNativeFunction() {
        @Override
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return BigIntegerType.INSTANCE;
        }
    });
    map.put("nativeBigDecimal", new AbstractNativeFunction() {
        @Override
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return BigDecimalType.INSTANCE;
        }
    });
    map.put("nativeString", new AbstractNativeFunction() {
        @Override
        public Type getReturnType(Type firstArgumentType, Mapping mapping) throws QueryException {
            return StringType.INSTANCE;
        }
    });
    //TODO: more types, all the derived types of org.hibernate.type.AbstractSingleColumnStandardBasicType
}