Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Bean
- public HibernateJpaVendorAdapter getHibernateJPAVendorAdapter() {
- return new CustomHibernateJpaVendorAdaptor();
- }
- @NoArgsConstructor
- public static class CustomOracleDialect extends Oracle12cDialect {
- private final OracleChar INSTANCE = new OracleChar();
- @Override
- public void contributeTypes(final TypeContributions typeContributions, final ServiceRegistry serviceRegistry) {
- super.contributeTypes(typeContributions, serviceRegistry);
- typeContributions.contributeSqlTypeDescriptor(INSTANCE);
- }
- }
- public static class OracleChar extends CharTypeDescriptor {
- @Override
- public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
- return new BasicBinder<>(javaTypeDescriptor, this) {
- @Override
- protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
- throws SQLException {
- if (st.isWrapperFor(OraclePreparedStatement.class)) {
- st.unwrap(OraclePreparedStatement.class)
- .setFixedCHAR(index, javaTypeDescriptor.unwrap(value, String.class, options));
- } else {
- st.setString(index, javaTypeDescriptor.unwrap(value, String.class, options));
- }
- }
- @Override
- protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
- throws SQLException {
- if (st.isWrapperFor(OraclePreparedStatement.class)) {
- st.unwrap(OraclePreparedStatement.class)
- .setFixedCHARAtName(name, javaTypeDescriptor.unwrap(value, String.class, options));
- } else {
- st.setString(name, javaTypeDescriptor.unwrap(value, String.class, options));
- }
- }
- };
- }
- @Override
- public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
- return new BasicExtractor<>(javaTypeDescriptor, this) {
- @Override
- protected X doExtract(ResultSet rs, String name, WrapperOptions options)
- throws SQLException {
- String val = rs.getString(name);
- return javaTypeDescriptor
- .wrap(val == null ? null : val.trim(), options);
- }
- @Override
- protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
- throws SQLException {
- String val = statement.getString(index);
- return javaTypeDescriptor
- .wrap(val == null ? null : val.trim(), options);
- }
- @Override
- protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
- throws SQLException {
- String val = statement.getString(name);
- return javaTypeDescriptor
- .wrap(val == null ? null : val.trim(), options);
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement