UserType _2

<class name="RecordLog">
<id name="id">
<generator class="native"/>
</id>
<property name="description"/>
<property name="interval" type="TimeIntervalType">
<column name="LOWER_LIMIT"/>
<column name="INCLUDES_LOWER_LIMIT"/>
<column name="UPPER_LIMIT"/>
<column name="INCLUDES_UPPER_LIMIT"/>
</property>
</class>


public class RecordLog extends Entity {
private String description;
private TimeInterval interval;
//getters and setters......
}

<class name="RecordLog">
<id name="id">
<generator class="native"/>
</id>
<property name="description"/>
<property name="interval" type="TimeIntervalType">
<column name="LOWER_LIMIT"/>
<column name="INCLUDES_LOWER_LIMIT"/>
<column name="UPPER_LIMIT"/>
<column name="INCLUDES_UPPER_LIMIT"/>
</property>
</class>

assertEquals(nov02, loaded.getInterval().lowerLimit());
assertEquals(nov03, loaded.getInterval().upperLimit());

public class TimeIntervalType implements UserType {

private static final int[] SQL_TYPES = new int[] { Hibernate.TIMESTAMP.sqlType(), Hibernate.BOOLEAN.sqlType(), Hibernate.TIMESTAMP.sqlType(),
Hibernate.BOOLEAN.sqlType() };

public int[] sqlTypes() {
return SQL_TYPES;
}

public Class returnedClass() {
return TimeInterval.class;
}

public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
return true;
if (x == null || y == null)
return false;
return ((TimeInterval) x).compareTo((TimeInterval) y) == 0;
}

public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
TimePoint lower = TimePoint.from((Timestamp) Hibernate.TIMESTAMP.nullSafeGet(rs, names[0]));
boolean lowerIncluded = ((Boolean) Hibernate.BOOLEAN.nullSafeGet(rs, names[1])).booleanValue();
TimePoint upper = TimePoint.from((Timestamp) Hibernate.TIMESTAMP.nullSafeGet(rs, names[2]));
boolean upperIncluded = ((Boolean) Hibernate.BOOLEAN.nullSafeGet(rs, names[3])).booleanValue();
return new TimeInterval(lower, lowerIncluded, upper, upperIncluded);
}

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
TimeInterval interval = (TimeInterval) value;
Hibernate.TIMESTAMP.nullSafeSet(st, new Timestamp(((TimePoint) interval.lowerLimit()).asJavaUtilDate().getTime()), index);
Hibernate.BOOLEAN.nullSafeSet(st, new Boolean(interval.includesLowerLimit()), index + 1);
Hibernate.TIMESTAMP.nullSafeSet(st, new Timestamp(((TimePoint) interval.upperLimit()).asJavaUtilDate().getTime()), index + 2);
Hibernate.BOOLEAN.nullSafeSet(st, new Boolean(interval.includesUpperLimit()), index + 3);
}

public Object deepCopy(Object value) throws HibernateException {
if (value == null)
return null;
TimeInterval interval = (TimeInterval) value;
return new TimeInterval((TimePoint) interval.lowerLimit(), interval.includesLowerLimit(), (TimePoint) interval.upperLimit(), interval
.includesUpperLimit());
}

public boolean isMutable() {
return true;
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值