forked from quarkusio/quarkus
-
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.
Fix test by adding ad-hoc
LocalDate
support
Fixes quarkusio#37659. A follow-up issue will be filed to revert this commit once ORM 7.x is integrated.
- Loading branch information
Showing
2 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
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
104 changes: 104 additions & 0 deletions
104
...panache/src/main/java/io/quarkus/it/hibertnate/orm/graphql/panache/LocalDateJdbcType.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,104 @@ | ||
package io.quarkus.it.hibertnate.orm.graphql.panache; | ||
|
||
import java.io.Serial; | ||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
import java.time.LocalDate; | ||
|
||
import jakarta.persistence.TemporalType; | ||
|
||
import org.hibernate.type.descriptor.ValueBinder; | ||
import org.hibernate.type.descriptor.ValueExtractor; | ||
import org.hibernate.type.descriptor.WrapperOptions; | ||
import org.hibernate.type.descriptor.java.JavaType; | ||
import org.hibernate.type.descriptor.jdbc.BasicBinder; | ||
import org.hibernate.type.descriptor.jdbc.BasicExtractor; | ||
import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter; | ||
import org.hibernate.type.descriptor.jdbc.JdbcType; | ||
import org.hibernate.type.descriptor.jdbc.internal.JdbcLiteralFormatterTemporal; | ||
import org.hibernate.type.spi.TypeConfiguration; | ||
|
||
/** | ||
* A "correct" local date JDBC type. | ||
*/ | ||
public final class LocalDateJdbcType implements JdbcType { | ||
@Serial | ||
private static final long serialVersionUID = -3375371178728213643L; | ||
|
||
public static final LocalDateJdbcType INSTANCE = new LocalDateJdbcType(); | ||
|
||
private LocalDateJdbcType() { | ||
} | ||
|
||
@Override | ||
public int getJdbcTypeCode() { | ||
return Types.DATE; | ||
} | ||
|
||
@Override | ||
public String getFriendlyName() { | ||
return "DATE"; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "LocalDateTypeDescriptor"; | ||
} | ||
|
||
@Override | ||
public <T> JavaType<T> getJdbcRecommendedJavaTypeMapping( | ||
Integer length, | ||
Integer scale, | ||
TypeConfiguration typeConfiguration) { | ||
return typeConfiguration.getJavaTypeRegistry().getDescriptor(LocalDate.class); | ||
} | ||
|
||
@Override | ||
public <T> JdbcLiteralFormatter<T> getJdbcLiteralFormatter(JavaType<T> javaType) { | ||
return new JdbcLiteralFormatterTemporal<>(javaType, TemporalType.DATE); | ||
} | ||
|
||
@Override | ||
public Class<?> getPreferredJavaTypeClass(WrapperOptions options) { | ||
return LocalDate.class; | ||
} | ||
|
||
@Override | ||
public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) { | ||
return new BasicBinder<>(javaType, this) { | ||
@Override | ||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { | ||
st.setObject(index, javaType.unwrap(value, LocalDate.class, options)); | ||
} | ||
|
||
@Override | ||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) | ||
throws SQLException { | ||
st.setObject(name, javaType.unwrap(value, LocalDate.class, options)); | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) { | ||
return new BasicExtractor<>(javaType, this) { | ||
@Override | ||
protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException { | ||
return javaType.wrap(rs.getObject(paramIndex, LocalDate.class), options); | ||
} | ||
|
||
@Override | ||
protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { | ||
return javaType.wrap(statement.getObject(index, LocalDate.class), options); | ||
} | ||
|
||
@Override | ||
protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException { | ||
return javaType.wrap(statement.getObject(name, LocalDate.class), options); | ||
} | ||
}; | ||
} | ||
} |