1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jadira.usertype.dateandtime.joda;
17
18 import org.hibernate.usertype.ParameterizedType;
19 import org.jadira.usertype.dateandtime.joda.columnmapper.TimestampColumnDateTimeMapper;
20 import org.jadira.usertype.spi.shared.AbstractParameterizedTemporalMultiColumnUserType;
21 import org.jadira.usertype.spi.shared.IntegratorConfiguredType;
22 import org.jadira.usertype.spi.utils.reflection.ArrayUtils;
23 import org.joda.time.DateTime;
24 import org.joda.time.Interval;
25
26
27
28
29
30
31
32
33
34
35
36
37 public class PersistentInterval extends AbstractParameterizedTemporalMultiColumnUserType<Interval> implements ParameterizedType, IntegratorConfiguredType {
38
39 private static final long serialVersionUID = 1364221029392346011L;
40
41 private static final TimestampColumnDateTimeMapper[] COLUMN_MAPPERS = new TimestampColumnDateTimeMapper[] { new TimestampColumnDateTimeMapper(), new TimestampColumnDateTimeMapper() };
42
43 private static final String[] PROPERTY_NAMES = new String[]{ "begin", "end" };
44
45 @Override
46 protected Interval fromConvertedColumns(Object[] convertedColumns) {
47
48 DateTime begin = (DateTime) convertedColumns[0];
49 DateTime end = (DateTime) convertedColumns[1];
50
51 return new Interval(begin, end);
52 }
53
54 @Override
55 protected TimestampColumnDateTimeMapper[] getColumnMappers() {
56 return COLUMN_MAPPERS;
57 }
58
59 @Override
60 protected Object[] toConvertedColumns(Interval value) {
61
62 return new Object[] { value.getStart(), value.getEnd() };
63 }
64
65 @Override
66 public String[] getPropertyNames() {
67
68 return ArrayUtils.copyOf(PROPERTY_NAMES);
69 }
70 }