Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. @Bean
  2. public HibernateJpaVendorAdapter getHibernateJPAVendorAdapter() {
  3. return new CustomHibernateJpaVendorAdaptor();
  4. }
  5.  
  6. @NoArgsConstructor
  7. public static class CustomOracleDialect extends Oracle12cDialect {
  8.  
  9. private final OracleChar INSTANCE = new OracleChar();
  10.  
  11. @Override
  12. public void contributeTypes(final TypeContributions typeContributions, final ServiceRegistry serviceRegistry) {
  13. super.contributeTypes(typeContributions, serviceRegistry);
  14. typeContributions.contributeSqlTypeDescriptor(INSTANCE);
  15. }
  16. }
  17.  
  18. public static class OracleChar extends CharTypeDescriptor {
  19.  
  20. @Override
  21. public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
  22. return new BasicBinder<>(javaTypeDescriptor, this) {
  23. @Override
  24. protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options)
  25. throws SQLException {
  26. if (st.isWrapperFor(OraclePreparedStatement.class)) {
  27. st.unwrap(OraclePreparedStatement.class)
  28. .setFixedCHAR(index, javaTypeDescriptor.unwrap(value, String.class, options));
  29. } else {
  30. st.setString(index, javaTypeDescriptor.unwrap(value, String.class, options));
  31. }
  32. }
  33.  
  34. @Override
  35. protected void doBind(CallableStatement st, X value, String name, WrapperOptions options)
  36. throws SQLException {
  37. if (st.isWrapperFor(OraclePreparedStatement.class)) {
  38. st.unwrap(OraclePreparedStatement.class)
  39. .setFixedCHARAtName(name, javaTypeDescriptor.unwrap(value, String.class, options));
  40. } else {
  41. st.setString(name, javaTypeDescriptor.unwrap(value, String.class, options));
  42. }
  43. }
  44. };
  45. }
  46.  
  47. @Override
  48. public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
  49. return new BasicExtractor<>(javaTypeDescriptor, this) {
  50. @Override
  51. protected X doExtract(ResultSet rs, String name, WrapperOptions options)
  52. throws SQLException {
  53. String val = rs.getString(name);
  54. return javaTypeDescriptor
  55. .wrap(val == null ? null : val.trim(), options);
  56. }
  57.  
  58. @Override
  59. protected X doExtract(CallableStatement statement, int index, WrapperOptions options)
  60. throws SQLException {
  61. String val = statement.getString(index);
  62. return javaTypeDescriptor
  63. .wrap(val == null ? null : val.trim(), options);
  64. }
  65.  
  66. @Override
  67. protected X doExtract(CallableStatement statement, String name, WrapperOptions options)
  68. throws SQLException {
  69. String val = statement.getString(name);
  70. return javaTypeDescriptor
  71. .wrap(val == null ? null : val.trim(), options);
  72. }
  73. };
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement