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 LocalDate[] mappings #406
- Loading branch information
1 parent
d05c208
commit d9c19e6
Showing
14 changed files
with
292 additions
and
36 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...nate-types-52/src/main/java/com/vladmihalcea/hibernate/type/array/LocalDateArrayType.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,50 @@ | ||
package com.vladmihalcea.hibernate.type.array; | ||
|
||
import com.vladmihalcea.hibernate.type.array.internal.AbstractArrayType; | ||
import com.vladmihalcea.hibernate.type.array.internal.LocalDateArrayTypeDescriptor; | ||
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.LocalDate[]} array on a PostgreSQL date[] 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 Andrew Lazarus, based on DateArrayType by Guillaume Briand | ||
*/ | ||
|
||
public class LocalDateArrayType extends AbstractArrayType<java.time.LocalDate[]> { | ||
|
||
public static final LocalDateArrayType INSTANCE = | ||
new LocalDateArrayType(); | ||
|
||
public LocalDateArrayType() { | ||
super( | ||
new LocalDateArrayTypeDescriptor() | ||
); | ||
} | ||
|
||
public LocalDateArrayType(Configuration configuration) { | ||
super( | ||
new LocalDateArrayTypeDescriptor(), configuration | ||
); | ||
} | ||
|
||
public LocalDateArrayType(Class arrayClass) { | ||
this(); | ||
Properties parameters = new Properties(); | ||
parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass)); | ||
setParameterValues(parameters); | ||
} | ||
|
||
public String getName() { | ||
return "localdate-array"; | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...ain/java/com/vladmihalcea/hibernate/type/array/internal/LocalDateArrayTypeDescriptor.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,17 @@ | ||
package com.vladmihalcea.hibernate.type.array.internal; | ||
|
||
/** | ||
* @author Vlad Mihalcea | ||
*/ | ||
public class LocalDateArrayTypeDescriptor | ||
extends AbstractArrayTypeDescriptor<java.time.LocalDate[]> { | ||
|
||
public LocalDateArrayTypeDescriptor() { | ||
super(java.time.LocalDate[].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
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
54 changes: 54 additions & 0 deletions
54
...nate-types-55/src/main/java/com/vladmihalcea/hibernate/type/array/LocalDateArrayType.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,54 @@ | ||
package com.vladmihalcea.hibernate.type.array; | ||
|
||
import com.vladmihalcea.hibernate.type.array.internal.AbstractArrayType; | ||
import com.vladmihalcea.hibernate.type.array.internal.LocalDateArrayTypeDescriptor; | ||
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.LocalDate[]} array on a PostgreSQL date[] 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 Andrew Lazarus, based on DateArrayType by Guillaume Briand | ||
*/ | ||
|
||
public class LocalDateArrayType extends AbstractArrayType<java.time.LocalDate[]> { | ||
|
||
public static final com.vladmihalcea.hibernate.type.array.LocalDateArrayType INSTANCE = | ||
new com.vladmihalcea.hibernate.type.array.LocalDateArrayType(); | ||
|
||
public LocalDateArrayType() { | ||
super( | ||
new LocalDateArrayTypeDescriptor() | ||
); | ||
} | ||
|
||
public LocalDateArrayType(Configuration configuration) { | ||
super( | ||
new LocalDateArrayTypeDescriptor(), configuration | ||
); | ||
} | ||
|
||
public LocalDateArrayType(Class arrayClass) { | ||
this(); | ||
Properties parameters = new Properties(); | ||
parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass)); | ||
setParameterValues(parameters); | ||
} | ||
|
||
public LocalDateArrayType(org.hibernate.type.spi.TypeBootstrapContext typeBootstrapContext) { | ||
this(new Configuration(typeBootstrapContext.getConfigurationSettings())); | ||
} | ||
|
||
public String getName() { | ||
return "localdate-array"; | ||
} | ||
} |
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.