|
111 | 111 | import org.hibernate.type.descriptor.ValueBinder;
|
112 | 112 | import org.hibernate.type.descriptor.ValueExtractor;
|
113 | 113 | import org.hibernate.type.descriptor.WrapperOptions;
|
114 |
| -import org.hibernate.type.descriptor.java.DataHelper; |
115 | 114 | import org.hibernate.type.descriptor.java.DoubleJavaType;
|
116 | 115 | import org.hibernate.type.descriptor.java.JavaType;
|
117 | 116 | import org.hibernate.type.descriptor.jdbc.BasicBinder;
|
|
163 | 162 | import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
|
164 | 163 | import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
|
165 | 164 | import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
|
| 165 | +import static org.hibernate.type.descriptor.java.DataHelper.extractBytes; |
| 166 | +import static org.hibernate.type.descriptor.java.DataHelper.extractString; |
166 | 167 |
|
167 | 168 | /**
|
168 | 169 | * An SQL dialect for legacy versions of the SAP HANA Platform up tu and including 2.0 SPS 04.
|
@@ -1497,7 +1498,7 @@ public OutputStream setAsciiStream(long pos) throws SQLException {
|
1497 | 1498 |
|
1498 | 1499 | @Override
|
1499 | 1500 | public long position(Clob searchstr, long start) throws SQLException {
|
1500 |
| - return this.data.indexOf( DataHelper.extractString( searchstr ), (int) ( start - 1 ) ); |
| 1501 | + return this.data.indexOf( extractString( searchstr ), (int) ( start - 1 ) ); |
1501 | 1502 | }
|
1502 | 1503 |
|
1503 | 1504 | @Override
|
@@ -1536,6 +1537,47 @@ public void free() throws SQLException {
|
1536 | 1537 | }
|
1537 | 1538 | }
|
1538 | 1539 |
|
| 1540 | + private static class BlobExtractor<X> extends BasicExtractor<X> { |
| 1541 | + private final int maxLobPrefetchSize; |
| 1542 | + |
| 1543 | + public BlobExtractor(JavaType<X> javaType, JdbcType jdbcType, int maxLobPrefetchSize) { |
| 1544 | + super( javaType, jdbcType ); |
| 1545 | + this.maxLobPrefetchSize = maxLobPrefetchSize; |
| 1546 | + } |
| 1547 | + |
| 1548 | + private X doExtract(Blob blob, WrapperOptions options) throws SQLException { |
| 1549 | + final X result; |
| 1550 | + if ( blob == null ) { |
| 1551 | + result = getJavaType().wrap( null, options ); |
| 1552 | + } |
| 1553 | + else if ( blob.length() < maxLobPrefetchSize ) { |
| 1554 | + result = getJavaType().wrap( blob, options ); |
| 1555 | + blob.free(); |
| 1556 | + } |
| 1557 | + else { |
| 1558 | + final MaterializedBlob materialized = new MaterializedBlob( extractBytes( blob.getBinaryStream() ) ); |
| 1559 | + blob.free(); |
| 1560 | + result = getJavaType().wrap( materialized, options ); |
| 1561 | + } |
| 1562 | + return result; |
| 1563 | + } |
| 1564 | + |
| 1565 | + @Override |
| 1566 | + protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException { |
| 1567 | + return doExtract( rs.getBlob( paramIndex ), options ); |
| 1568 | + } |
| 1569 | + |
| 1570 | + @Override |
| 1571 | + protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { |
| 1572 | + return doExtract( statement.getBlob( index ), options ); |
| 1573 | + } |
| 1574 | + |
| 1575 | + @Override |
| 1576 | + protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException { |
| 1577 | + return doExtract( statement.getBlob( name ), options ); |
| 1578 | + } |
| 1579 | + } |
| 1580 | + |
1539 | 1581 | private static class HANAStreamBlobType implements JdbcType {
|
1540 | 1582 |
|
1541 | 1583 | private static final long serialVersionUID = -2476600722093442047L;
|
@@ -1601,38 +1643,8 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
|
1601 | 1643 |
|
1602 | 1644 | @Override
|
1603 | 1645 | public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
|
1604 |
| - return new BasicExtractor<>( javaType, this ) { |
1605 |
| - private X extract(Blob blob, WrapperOptions options) throws SQLException { |
1606 |
| - if ( blob == null ) { |
1607 |
| - return null; |
1608 |
| - } |
1609 |
| - if ( blob.length() < HANALegacyDialect.HANAStreamBlobType.this.maxLobPrefetchSize ) { |
1610 |
| - X result = javaType.wrap( blob, options ); |
1611 |
| - blob.free(); |
1612 |
| - return result; |
1613 |
| - } |
1614 |
| - Blob materializedBlob = new MaterializedBlob( DataHelper.extractBytes( blob.getBinaryStream() ) ); |
1615 |
| - blob.free(); |
1616 |
| - return javaType.wrap( materializedBlob, options ); |
1617 |
| - } |
1618 |
| - |
1619 |
| - @Override |
1620 |
| - protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException { |
1621 |
| - return extract( rs.getBlob( paramIndex ), options ); |
1622 |
| - } |
1623 |
| - |
1624 |
| - @Override |
1625 |
| - protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { |
1626 |
| - return extract( statement.getBlob( index ), options ); |
1627 |
| - } |
1628 |
| - |
1629 |
| - @Override |
1630 |
| - protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException { |
1631 |
| - return extract( statement.getBlob( name ), options ); |
1632 |
| - } |
1633 |
| - }; |
| 1646 | + return new BlobExtractor<>( javaType, this, maxLobPrefetchSize ); |
1634 | 1647 | }
|
1635 |
| - |
1636 | 1648 | }
|
1637 | 1649 |
|
1638 | 1650 | // the ClobTypeDescriptor and NClobTypeDescriptor for HANA are slightly
|
@@ -1704,55 +1716,39 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
|
1704 | 1716 | @Override
|
1705 | 1717 | public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
|
1706 | 1718 | return new BasicExtractor<>( javaType, this ) {
|
1707 |
| - private X extract(Clob clob, WrapperOptions options) throws SQLException { |
| 1719 | + private X doExtract(Clob clob, WrapperOptions options) throws SQLException { |
| 1720 | + final X result; |
1708 | 1721 | if ( clob == null ) {
|
1709 |
| - return null; |
| 1722 | + result = getJavaType().wrap( null, options ); |
1710 | 1723 | }
|
1711 |
| - |
1712 |
| - if ( clob.length() < HANALegacyDialect.HANAClobJdbcType.this.maxLobPrefetchSize ) { |
1713 |
| - X retVal = javaType.wrap(clob, options); |
| 1724 | + else if ( clob.length() < maxLobPrefetchSize ) { |
| 1725 | + result = getJavaType().wrap(clob, options); |
1714 | 1726 | clob.free();
|
1715 |
| - return retVal; |
1716 | 1727 | }
|
1717 |
| - NClob materializedNClob = new MaterializedNClob( DataHelper.extractString( clob ) ); |
1718 |
| - clob.free(); |
1719 |
| - return javaType.wrap( materializedNClob, options ); |
| 1728 | + else { |
| 1729 | + final MaterializedNClob materialized = new MaterializedNClob( extractString( clob ) ); |
| 1730 | + clob.free(); |
| 1731 | + result = getJavaType().wrap( materialized, options ); |
| 1732 | + } |
| 1733 | + return result; |
1720 | 1734 | }
|
1721 | 1735 |
|
1722 | 1736 | @Override
|
1723 | 1737 | protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
1724 |
| - Clob rsClob; |
1725 |
| - if ( HANALegacyDialect.HANAClobJdbcType.this.useUnicodeStringTypes ) { |
1726 |
| - rsClob = rs.getNClob( paramIndex ); |
1727 |
| - } |
1728 |
| - else { |
1729 |
| - rsClob = rs.getClob( paramIndex ); |
1730 |
| - } |
1731 |
| - return extract( rsClob, options ); |
| 1738 | + final Clob clob = useUnicodeStringTypes ? rs.getNClob( paramIndex ) : rs.getClob( paramIndex ); |
| 1739 | + return doExtract( clob, options ); |
1732 | 1740 | }
|
1733 | 1741 |
|
1734 | 1742 | @Override
|
1735 | 1743 | protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
1736 |
| - Clob rsClob; |
1737 |
| - if ( HANALegacyDialect.HANAClobJdbcType.this.useUnicodeStringTypes ) { |
1738 |
| - rsClob = statement.getNClob( index ); |
1739 |
| - } |
1740 |
| - else { |
1741 |
| - rsClob = statement.getClob( index ); |
1742 |
| - } |
1743 |
| - return extract( rsClob, options ); |
| 1744 | + final Clob clob = useUnicodeStringTypes ? statement.getNClob( index ) : statement.getClob( index ); |
| 1745 | + return doExtract( clob, options ); |
1744 | 1746 | }
|
1745 | 1747 |
|
1746 | 1748 | @Override
|
1747 | 1749 | protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
|
1748 |
| - Clob rsClob; |
1749 |
| - if ( HANALegacyDialect.HANAClobJdbcType.this.useUnicodeStringTypes ) { |
1750 |
| - rsClob = statement.getNClob( name ); |
1751 |
| - } |
1752 |
| - else { |
1753 |
| - rsClob = statement.getClob( name ); |
1754 |
| - } |
1755 |
| - return extract( rsClob, options ); |
| 1750 | + final Clob clob = useUnicodeStringTypes ? statement.getNClob( name ) : statement.getClob( name ); |
| 1751 | + return doExtract( clob, options ); |
1756 | 1752 | }
|
1757 | 1753 | };
|
1758 | 1754 | }
|
@@ -1826,32 +1822,36 @@ protected void doBind(CallableStatement st, X value, String name, WrapperOptions
|
1826 | 1822 | @Override
|
1827 | 1823 | public <X> ValueExtractor<X> getExtractor(JavaType<X> javaType) {
|
1828 | 1824 | return new BasicExtractor<>( javaType, this ) {
|
1829 |
| - private X extract(NClob nclob, WrapperOptions options) throws SQLException { |
| 1825 | + private X doExtract(NClob nclob, WrapperOptions options) throws SQLException { |
| 1826 | + final X result; |
1830 | 1827 | if ( nclob == null ) {
|
1831 |
| - return null; |
| 1828 | + result = getJavaType().wrap( null, options ); |
| 1829 | + } |
| 1830 | + else if ( nclob.length() < maxLobPrefetchSize ) { |
| 1831 | + result = javaType.wrap(nclob, options); |
| 1832 | + nclob.free(); |
1832 | 1833 | }
|
1833 |
| - if ( nclob.length() < maxLobPrefetchSize ) { |
1834 |
| - X retVal = javaType.wrap(nclob, options); |
| 1834 | + else { |
| 1835 | + final MaterializedNClob materialized = new MaterializedNClob( extractString( nclob ) ); |
1835 | 1836 | nclob.free();
|
1836 |
| - return retVal; |
| 1837 | + result = getJavaType().wrap( materialized, options ); |
1837 | 1838 | }
|
1838 |
| - NClob materializedNClob = new MaterializedNClob( DataHelper.extractString( nclob ) ); |
1839 |
| - nclob.free(); |
1840 |
| - return javaType.wrap( materializedNClob, options ); |
| 1839 | + return result; |
1841 | 1840 | }
|
| 1841 | + |
1842 | 1842 | @Override
|
1843 | 1843 | protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException {
|
1844 |
| - return extract( rs.getNClob( paramIndex ), options ); |
| 1844 | + return doExtract( rs.getNClob( paramIndex ), options ); |
1845 | 1845 | }
|
1846 | 1846 |
|
1847 | 1847 | @Override
|
1848 | 1848 | protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException {
|
1849 |
| - return extract( statement.getNClob( index ), options ); |
| 1849 | + return doExtract( statement.getNClob( index ), options ); |
1850 | 1850 | }
|
1851 | 1851 |
|
1852 | 1852 | @Override
|
1853 | 1853 | protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException {
|
1854 |
| - return extract( statement.getNClob( name ), options ); |
| 1854 | + return doExtract( statement.getNClob( name ), options ); |
1855 | 1855 | }
|
1856 | 1856 | };
|
1857 | 1857 | }
|
@@ -1892,35 +1892,7 @@ public String toString() {
|
1892 | 1892 |
|
1893 | 1893 | @Override
|
1894 | 1894 | public <X> ValueExtractor<X> getExtractor(final JavaType<X> javaType) {
|
1895 |
| - return new BasicExtractor<>( javaType, this ) { |
1896 |
| - private X extract(Blob blob, WrapperOptions options) throws SQLException { |
1897 |
| - if ( blob == null ) { |
1898 |
| - return null; |
1899 |
| - } |
1900 |
| - if ( blob.length() < maxLobPrefetchSize ) { |
1901 |
| - X retVal = javaType.wrap(blob, options); |
1902 |
| - blob.free(); |
1903 |
| - return retVal; |
1904 |
| - } |
1905 |
| - Blob materializedBlob = new MaterializedBlob( DataHelper.extractBytes( blob.getBinaryStream() ) ); |
1906 |
| - blob.free(); |
1907 |
| - return javaType.wrap( materializedBlob, options ); |
1908 |
| - } |
1909 |
| - @Override |
1910 |
| - protected X doExtract(ResultSet rs, int paramIndex, WrapperOptions options) throws SQLException { |
1911 |
| - return extract( rs.getBlob( paramIndex ) , options ); |
1912 |
| - } |
1913 |
| - |
1914 |
| - @Override |
1915 |
| - protected X doExtract(CallableStatement statement, int index, WrapperOptions options) throws SQLException { |
1916 |
| - return extract( statement.getBlob( index ), options ); |
1917 |
| - } |
1918 |
| - |
1919 |
| - @Override |
1920 |
| - protected X doExtract(CallableStatement statement, String name, WrapperOptions options) throws SQLException { |
1921 |
| - return extract( statement.getBlob( name ), options ); |
1922 |
| - } |
1923 |
| - }; |
| 1895 | + return new BlobExtractor<>( javaType, this, maxLobPrefetchSize ); |
1924 | 1896 | }
|
1925 | 1897 |
|
1926 | 1898 | @Override
|
|
0 commit comments