public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { String value = rs.getString(names[0]); if (!rs.wasNull()) { return units.fromdbvalue(value); } return null; }
public void nullSafeSet(PreparedStatement ps, Object obj, int index) throws HibernateException, SQLException { if (obj == null) { // Note: units.sqlType shouldn't be used since this // doesn't actually get registered with the PG driver // (apparently). Instead we use the official Types.OTHER ps.setObject(index, null, Types.OTHER); } else { ps.setObject(index, units.todbvalue(obj), Types.OTHER); } }
@Override public void setParameterValues(Properties parameters) { String units = parameters.getProperty("unit"); this.units = UNITS.valueOf(units); }
public static Map<String, Integer> listSqlTypes() { try { Map<String, Integer> rv = new HashMap<String, Integer>(); for (UNITS u : values()) { rv.put(u.enumType.getSimpleName(), u.sqlType); } return rv; } catch (Exception e) { throw new RuntimeException("Failed to load sql types", e); } }
public PostgresqlDialect() { super(); registerFunction("temp_ids_cursor", new SQLFunctionTemplate(Hibernate.LONG, "select id from table(temp_ids_cursor(?1))")); for (Map.Entry<String, Integer> entry : UNITS.listSqlTypes().entrySet()) { registerColumnType(entry.getValue(), entry.getKey()); } }