/
LocalDateTimeArrayType.java
54 lines (44 loc) · 1.92 KB
/
LocalDateTimeArrayType.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.vladmihalcea.hibernate.type.array;
import com.vladmihalcea.hibernate.type.array.internal.AbstractArrayType;
import com.vladmihalcea.hibernate.type.array.internal.LocalDateTimeArrayTypeDescriptor;
import com.vladmihalcea.hibernate.type.util.Configuration;
import com.vladmihalcea.hibernate.type.util.ParameterizedParameterType;
import org.hibernate.usertype.DynamicParameterizedType;
import java.util.Properties;
/**
* Maps a {@code java.Time.LocalDateTime[]} array on a PostgreSQL timestamp[] ARRAY type. Multidimensional arrays are
* supported as well, as
* explained in <a href="https://vladmihalcea.com/multidimensional-array-jpa-hibernate/">this article</a>.
* <p>
* For more details about how to use it, check out
* <a href="https://vladmihalcea.com/how-to-map-java-and-sql-arrays-with-jpa-and-hibernate/">this
* article</a> on <a href="https://vladmihalcea.com/">vladmihalcea.com</a>.
*
* @author Vlad Mihalcea
*/
public class LocalDateTimeArrayType extends AbstractArrayType<java.time.LocalDateTime[]> {
public static final LocalDateTimeArrayType INSTANCE =
new LocalDateTimeArrayType();
public LocalDateTimeArrayType() {
super(
new LocalDateTimeArrayTypeDescriptor()
);
}
public LocalDateTimeArrayType(Configuration configuration) {
super(
new LocalDateTimeArrayTypeDescriptor(), configuration
);
}
public LocalDateTimeArrayType(Class arrayClass) {
this();
Properties parameters = new Properties();
parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
setParameterValues(parameters);
}
public LocalDateTimeArrayType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) {
this(new Configuration(typeBootstrapContext.getConfigurationSettings()));
}
public String getName() {
return "localdatetime-array";
}
}