public int compareTo(SQLTypeMapping other) { if(other==null) return 1; if(this.jdbcType==other.jdbcType) { if(this.length==other.length) { if(this.precision==other.precision) { if(this.scale==other.scale) { return compare(this.nullable, other.nullable); } else { return compare(this.scale, other.scale); } } else { return compare(this.precision,other.precision); } } else { return compare(this.length,other.length); } } else { return compare(this.jdbcType,other.jdbcType); } }
public String toString() { return getJDBCType() + " l:" + getLength() + " p:" + getPrecision() + " s:" + getScale() + " n:" + getNullable() + " ht:" + getHibernateType(); }
TypeMappingKey(SQLTypeMapping mpa) { type = mpa.getJDBCType(); length = mpa.getLength(); }
private static void bindTypeMappings(Element typeMapping, OverrideRepository repository) { Iterator<?> iterator = typeMapping.elements("sql-type").iterator(); while (iterator.hasNext() ) { Element element = (Element) iterator.next(); int jdbcType = JDBCToHibernateTypeHelper.getJDBCType(element.attributeValue("jdbc-type") ); SQLTypeMapping mapping = new SQLTypeMapping(jdbcType ); mapping.setHibernateType( getHibernateType( element ) ); mapping.setLength(getInteger(element.attributeValue("length"), SQLTypeMapping.UNKNOWN_LENGTH) ); mapping.setPrecision(getInteger(element.attributeValue("precision"), SQLTypeMapping.UNKNOWN_PRECISION) ); mapping.setScale(getInteger(element.attributeValue("scale"), SQLTypeMapping.UNKNOWN_SCALE) ); String notNull = element.attributeValue("not-null"); if(notNull==null) { mapping.setNullable(null); } else { boolean nullable = notNull.equals( "false" ); mapping.setNullable( Boolean.valueOf(nullable) ); } if(StringHelper.isEmpty(mapping.getHibernateType())) { throw new MappingException("No hibernate-type specified for " + element.attributeValue("jdbc-type") + " at " + element.getUniquePath()); } repository.addTypeMapping(mapping); } }
private String scanForMatch(int sqlType, int length, int precision, int scale, boolean nullable, List<SQLTypeMapping> l) { if(l!=null) { Iterator<SQLTypeMapping> iterator = l.iterator(); while (iterator.hasNext() ) { SQLTypeMapping element = iterator.next(); if(element.getJDBCType()!=sqlType) return null; if(element.match(sqlType, length, precision, scale, nullable) ) { return element.getHibernateType(); } } } return null; }
public boolean equals(Object obj) { if (getClass().isAssignableFrom(obj.getClass())) { SQLTypeMapping other = getClass().cast(obj); return compareTo(other)==0; } else { return false; } }