forked from vladmihalcea/hypersistence-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for mapping java.util.Date ARRAY or List to PostgreSQL DA…
…TE[] and TIMESTAMP[] vladmihalcea#150
- Loading branch information
1 parent
0895840
commit 9b07dd6
Showing
32 changed files
with
892 additions
and
114 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
hibernate-types-4/src/main/java/com/vladmihalcea/hibernate/type/array/DateArrayType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.vladmihalcea.hibernate.type.array; | ||
|
||
import com.vladmihalcea.hibernate.type.AbstractHibernateType; | ||
import com.vladmihalcea.hibernate.type.array.internal.ArraySqlTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.array.internal.DateArrayTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.util.Configuration; | ||
import org.hibernate.usertype.DynamicParameterizedType; | ||
|
||
import java.util.Date; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Maps an {@code Date[]} array on a PostgreSQL ARRAY type. | ||
* <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 Guillaume Briand | ||
*/ | ||
public class DateArrayType | ||
extends AbstractHibernateType<Date[]> | ||
implements DynamicParameterizedType { | ||
|
||
public static final DateArrayType INSTANCE = new DateArrayType(); | ||
|
||
public DateArrayType() { | ||
super( | ||
ArraySqlTypeDescriptor.INSTANCE, | ||
new DateArrayTypeDescriptor() | ||
); | ||
} | ||
|
||
public DateArrayType(Configuration configuration) { | ||
super( | ||
ArraySqlTypeDescriptor.INSTANCE, | ||
new DateArrayTypeDescriptor(), configuration | ||
); | ||
} | ||
|
||
public String getName() { | ||
return "date-array"; | ||
} | ||
|
||
@Override | ||
protected boolean registerUnderJavaType() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setParameterValues(Properties parameters) { | ||
((DateArrayTypeDescriptor) getJavaTypeDescriptor()).setParameterValues(parameters); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...rnate-types-4/src/main/java/com/vladmihalcea/hibernate/type/array/TimestampArrayType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.vladmihalcea.hibernate.type.array; | ||
|
||
import com.vladmihalcea.hibernate.type.array.internal.AbstractArrayType; | ||
import com.vladmihalcea.hibernate.type.array.internal.TimestampArrayTypeDescriptor; | ||
import com.vladmihalcea.hibernate.type.util.Configuration; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* Maps an {@code Date[]} array on a PostgreSQL timestamp[] ARRAY type. | ||
* <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 TimestampArrayType extends AbstractArrayType<Date[]> { | ||
|
||
public static final TimestampArrayType INSTANCE = new TimestampArrayType(); | ||
|
||
public TimestampArrayType() { | ||
super( | ||
new TimestampArrayTypeDescriptor() | ||
); | ||
} | ||
|
||
public TimestampArrayType(Configuration configuration) { | ||
super( | ||
new TimestampArrayTypeDescriptor(), configuration | ||
); | ||
} | ||
|
||
public String getName() { | ||
return "timestamp-array"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...src/main/java/com/vladmihalcea/hibernate/type/array/internal/DateArrayTypeDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vladmihalcea.hibernate.type.array.internal; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* @author Guillaume Briand | ||
*/ | ||
public class DateArrayTypeDescriptor | ||
extends AbstractArrayTypeDescriptor<Date[]> { | ||
|
||
public DateArrayTypeDescriptor() { | ||
super(Date[].class); | ||
} | ||
|
||
@Override | ||
protected String getSqlArrayType() { | ||
return "date"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ain/java/com/vladmihalcea/hibernate/type/array/internal/TimestampArrayTypeDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.vladmihalcea.hibernate.type.array.internal; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class TimestampArrayTypeDescriptor extends AbstractArrayTypeDescriptor<Date[]> { | ||
|
||
public TimestampArrayTypeDescriptor() { | ||
super(Date[].class); | ||
} | ||
|
||
@Override | ||
protected String getSqlArrayType() { | ||
return "timestamp"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.