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 LocalDateTime[] mappings #407
- Loading branch information
1 parent
d9c19e6
commit d11ad93
Showing
14 changed files
with
273 additions
and
15 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...-types-52/src/main/java/com/vladmihalcea/hibernate/type/array/LocalDateTimeArrayType.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.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 String getName() { | ||
return "localdatetime-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
...java/com/vladmihalcea/hibernate/type/array/internal/LocalDateTimeArrayTypeDescriptor.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 LocalDateTimeArrayTypeDescriptor | ||
extends AbstractArrayTypeDescriptor<java.time.LocalDateTime[]> { | ||
|
||
public LocalDateTimeArrayTypeDescriptor() { | ||
super(java.time.LocalDateTime[].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
54 changes: 54 additions & 0 deletions
54
...-types-55/src/main/java/com/vladmihalcea/hibernate/type/array/LocalDateTimeArrayType.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.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"; | ||
} | ||
} |
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
...java/com/vladmihalcea/hibernate/type/array/internal/LocalDateTimeArrayTypeDescriptor.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 LocalDateTimeArrayTypeDescriptor | ||
extends AbstractArrayTypeDescriptor<java.time.LocalDateTime[]> { | ||
|
||
public LocalDateTimeArrayTypeDescriptor() { | ||
super(java.time.LocalDateTime[].class); | ||
} | ||
|
||
@Override | ||
protected String getSqlArrayType() { | ||
return "timestamp"; | ||
} | ||
} |
Oops, something went wrong.