List of usage examples for org.hibernate.type CharacterType INSTANCE
CharacterType INSTANCE
To view the source code for org.hibernate.type CharacterType INSTANCE.
Click Source Link
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;// w w w . j a v a 2 s .c om 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:com.timesoft.kaitoo.ws.common.CoreContent.java
public static void fildHibernateParameter(final SQLQuery sqlQuery, final Map<String, Object> paramMap) throws HibernateException { Set<String> set = paramMap.keySet(); for (Iterator<String> iter = set.iterator(); iter.hasNext();) { String paramName = iter.next(); Object paramValue = paramMap.get(paramName); if (paramValue != null) { if (paramValue instanceof java.lang.String) { sqlQuery.setParameter(paramName, paramValue.toString().trim(), StringType.INSTANCE); } else if (paramValue instanceof java.lang.Character) { sqlQuery.setParameter(paramName, paramValue, CharacterType.INSTANCE); } else if (paramValue instanceof java.lang.Integer) { sqlQuery.setParameter(paramName, paramValue, IntegerType.INSTANCE); } else if (paramValue instanceof java.util.Date) { sqlQuery.setParameter(paramName, paramValue, DateType.INSTANCE); } else if (paramValue instanceof java.lang.Long) { sqlQuery.setParameter(paramName, paramValue, LongType.INSTANCE); } else if (paramValue instanceof java.sql.Timestamp) { sqlQuery.setParameter(paramName, paramValue, TimestampType.INSTANCE); } else if (paramValue instanceof java.lang.Boolean) { sqlQuery.setParameter(paramName, paramValue, BooleanType.INSTANCE); } else if (paramValue instanceof java.lang.Float) { sqlQuery.setParameter(paramName, paramValue, FloatType.INSTANCE); } else if (paramValue instanceof java.lang.Double) { sqlQuery.setParameter(paramName, paramValue, DoubleType.INSTANCE); } else if (paramValue instanceof java.lang.Byte) { sqlQuery.setParameter(paramName, paramValue, ByteType.INSTANCE); } else if (paramValue instanceof java.util.Calendar) { sqlQuery.setParameter(paramName, paramValue, CalendarType.INSTANCE); }/*from w ww. j a va 2 s . c o m*/ } } }
From source file:org.opennms.netmgt.model.NodeLabelSourceUserType.java
License:Open Source License
@Override public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) throws HibernateException, SQLException { Character c = CharacterType.INSTANCE.nullSafeGet(rs, names[0]); if (c == null) { return null; }/*www. j ava2 s .com*/ for (NodeLabelSource type : NodeLabelSource.values()) { if (type.toString().equals(c.toString())) { return type; } } throw new HibernateException("Invalid value for NodeUserType: " + c); }
From source file:org.opennms.netmgt.model.NodeLabelSourceUserType.java
License:Open Source License
@Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index) throws HibernateException, SQLException { if (value == null) { StringType.INSTANCE.nullSafeSet(st, null, index); } else if (value instanceof NodeLabelSource) { CharacterType.INSTANCE.nullSafeSet(st, ((NodeLabelSource) value).toString().charAt(0), index); } else if (value instanceof String) { for (NodeLabelSource type : NodeLabelSource.values()) { if (type.toString().equals(value)) { CharacterType.INSTANCE.nullSafeSet(st, type.toString().charAt(0), index); }/*ww w. ja v a 2s. c o m*/ } } }
From source file:org.opennms.netmgt.model.NodeTypeUserType.java
License:Open Source License
@Override public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) throws HibernateException, SQLException { Character c = CharacterType.INSTANCE.nullSafeGet(rs, names[0]); if (c == null) { return null; }//from ww w . ja va2 s . c om for (NodeType type : NodeType.values()) { if (type.toString().equals(c.toString())) { return type; } } throw new HibernateException("Invalid value for NodeUserType: " + c); }
From source file:org.opennms.netmgt.model.NodeTypeUserType.java
License:Open Source License
@Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index) throws HibernateException, SQLException { if (value == null) { StringType.INSTANCE.nullSafeSet(st, null, index); } else if (value instanceof NodeType) { CharacterType.INSTANCE.nullSafeSet(st, ((NodeType) value).toString().charAt(0), index); } else if (value instanceof String) { for (NodeType type : NodeType.values()) { if (type.toString().equals(value)) { CharacterType.INSTANCE.nullSafeSet(st, type.toString().charAt(0), index); }/*from w w w . j a v a2s.co m*/ } } }
From source file:org.opennms.netmgt.model.StatusTypeUserType.java
License:Open Source License
@Override public Object nullSafeGet(final ResultSet rs, final String[] names, final Object owner) throws HibernateException, SQLException { return StatusType.get(CharacterType.INSTANCE.nullSafeGet(rs, names[0]).toString()); }
From source file:org.opennms.netmgt.model.StatusTypeUserType.java
License:Open Source License
@Override public void nullSafeSet(final PreparedStatement st, final Object value, final int index) throws HibernateException, SQLException { if (value == null) { CharacterType.INSTANCE.nullSafeSet(st, null, index); } else if (value instanceof StatusType) { CharacterType.INSTANCE.nullSafeSet(st, new Character(((StatusType) value).getCharCode()), index); } else if (value instanceof String) { try {// www .j a va 2s . co m CharacterType.INSTANCE.nullSafeSet(st, new Character(StatusType.get((String) value).getCharCode()), index); } catch (final IllegalArgumentException e) { CharacterType.INSTANCE.nullSafeSet(st, new Character(((String) value).charAt(0)), index); } } }