forked from hibernate/hibernate-orm
-
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.
HHH-14358 - Added test and fix to support null binding for PostgreSQL
Signed-off-by: Jan Schatteman <[email protected]>
- Loading branch information
Showing
7 changed files
with
95 additions
and
15 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
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
57 changes: 57 additions & 0 deletions
57
hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLUUIDJdbcType.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,57 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html | ||
*/ | ||
package org.hibernate.dialect; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
import java.util.UUID; | ||
|
||
import org.hibernate.type.descriptor.ValueBinder; | ||
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.UUIDJdbcType; | ||
|
||
/** | ||
* @author Jan Schatteman | ||
*/ | ||
public class PostgreSQLUUIDJdbcType extends UUIDJdbcType { | ||
|
||
/** | ||
* Singleton access | ||
*/ | ||
public static final PostgreSQLUUIDJdbcType INSTANCE = new PostgreSQLUUIDJdbcType(); | ||
|
||
@Override | ||
public <X> ValueBinder<X> getBinder(JavaType<X> javaType) { | ||
return new BasicBinder<>( javaType, this ) { | ||
@Override | ||
protected void doBindNull(PreparedStatement st, int index, WrapperOptions options) throws SQLException { | ||
st.setNull( index, getJdbcType().getJdbcTypeCode(), "uuid" ); | ||
} | ||
|
||
@Override | ||
protected void doBindNull(CallableStatement st, String name, WrapperOptions options) throws SQLException { | ||
st.setNull( name, getJdbcType().getJdbcTypeCode(), "uuid" ); | ||
} | ||
|
||
@Override | ||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) | ||
throws SQLException { | ||
st.setObject( index, getJavaType().unwrap( value, UUID.class, options ) ); | ||
} | ||
|
||
@Override | ||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) | ||
throws SQLException { | ||
st.setObject( name, getJavaType().unwrap( value, UUID.class, options ) ); | ||
} | ||
}; | ||
} | ||
} |
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