[TRAFODION-2740]add property to set the LOB chunk size

Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/835a4894
Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/835a4894
Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/835a4894

Branch: refs/heads/master
Commit: 835a48945afe3cc19ec58ac94e22b323db69d5cf
Parents: ea80ab3
Author: Weiqing Xu <weiqing...@esgyn.cn>
Authored: Sat Sep 23 17:47:33 2017 +0000
Committer: Weiqing Xu <weiqing...@esgyn.cn>
Committed: Sat Sep 23 17:47:33 2017 +0000

----------------------------------------------------------------------
 .../org/trafodion/jdbc/t4/T4Properties.java     | 28 +++++++++++++++++++-
 .../java/org/trafodion/jdbc/t4/TrafT4Lob.java   |  4 +--
 .../org/trafodion/jdbc/t4/T4DriverTest.java     | 28 ++++++++++++++++++++
 3 files changed, 57 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/835a4894/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
----------------------------------------------------------------------
diff --git 
a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java 
b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
index 917cf45..202bc27 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/T4Properties.java
@@ -119,7 +119,9 @@ public class T4Properties {
        String clobTableName_;
        String blobTableName_;
 
-       // private short transportBufferSize_;
+    private int lobChunkSize_ = 10; // default 10M
+
+    // private short transportBufferSize_;
        private boolean useArrayBinding_;
        private boolean batchRecovery_;
        private final String propPrefix_ = "t4jdbc.";
@@ -425,6 +427,8 @@ public class T4Properties {
                setKeepAlive(getProperty("keepAlive"));
                setTokenAuth(getProperty("tokenAuth"));
         setTcpNoDelay(getProperty("tcpNoDelay"));
+
+        setLobChunkSize(getProperty("lobChunkSize"));
        }
 
        T4Properties getT4Properties() {
@@ -518,6 +522,8 @@ public class T4Properties {
                props.setProperty("tokenAuth", String.valueOf(_tokenAuth));
         props.setProperty("tcpNoDelay", String.valueOf(_tcpNoDelay));
         
+        props.setProperty("lobChunkSize", String.valueOf(lobChunkSize_));
+
                return props;
        }
 
@@ -1884,6 +1890,26 @@ public class T4Properties {
                return reserveDataLocator_;
        }
 
+    public int getLobChunkSize() {
+        return lobChunkSize_;
+    }
+
+    public void setLobChunkSize(int lobChunkSize_) {
+        this.lobChunkSize_ = lobChunkSize_;
+    }
+
+    public void setLobChunkSize(String val) {
+        this.lobChunkSize_ = 10;
+        if (val != null) {
+            try {
+                this.lobChunkSize_ = Integer.parseInt(val);
+            } catch (NumberFormatException ex) {
+                sqlExceptionMessage_ = "Incorrect value for setLobChunkSize 
set: " + val + ex.getMessage();
+                this.lobChunkSize_ = 10;
+            }
+        }
+    }
+
        /**
         * Returns the rounding mode set for the driver as an Integer value 
with one
         * of the following values. static int ROUND_CEILING Rounding mode to 
round

http://git-wip-us.apache.org/repos/asf/trafodion/blob/835a4894/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
----------------------------------------------------------------------
diff --git 
a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java 
b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
index f18377b..0643173 100644
--- a/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
+++ b/core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Lob.java
@@ -103,7 +103,7 @@ public abstract class TrafT4Lob {
 
                try {
                        int pos = 0;
-                       int chunkSize = 100 * 1024 * 1024;
+            int chunkSize = connection_.props_.getLobChunkSize() * 1024 * 1024;
                        while (pos < length) {
                                int remainSize = (int) (length - pos);
                                int fecthSize = remainSize < chunkSize ? 
remainSize : chunkSize;
@@ -153,7 +153,7 @@ public abstract class TrafT4Lob {
                    return ;
                T4Connection t4connection = 
this.connection_.getServerHandle().getT4Connection();
 
-               final long chunkSize = 100 * 1024 * 1024;
+        final long chunkSize = connection_.props_.getLobChunkSize() * 1024 * 
1024;
                LogicalByteArray wbuffer = null;
 
                byte[] valueBuffer = null;

http://git-wip-us.apache.org/repos/asf/trafodion/blob/835a4894/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java
----------------------------------------------------------------------
diff --git 
a/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java 
b/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java
index e44c97a..e158e7b 100644
--- a/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java
+++ b/core/conn/jdbcT4/src/test/java/org/trafodion/jdbc/t4/T4DriverTest.java
@@ -23,7 +23,12 @@
 
 package org.trafodion.jdbc.t4;
 
+import java.sql.Blob;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Statement;
 
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -39,6 +44,29 @@ public class T4DriverTest {
 
 
        @Test
+       public void readLob() throws SQLException {
+               Connection conn = null;
+               try {
+                       conn = 
DriverManager.getConnection("jdbc:t4jdbc://192.168.0.36:23400/:", "zz", "zz");
+                       Statement stmt = conn.createStatement();
+                       ResultSet rs = stmt.executeQuery("select c2 from tlob");
+                       while (rs.next()) {
+                               Blob blob = rs.getBlob(1);
+                               System.out.println("LOB length " + 
blob.length());
+                               System.out.println(new String(blob.getBytes(1, 
(int)blob.length())));
+                       }
+                       conn.close();
+                       conn = null;
+               }
+               catch (SQLException se) { 
+                       System.out.println(se.getMessage());
+               }
+               finally {
+                       if (conn != null)
+                               conn.close();
+               }
+       }
+       @Test
        public void acceptsURL() throws SQLException {
                String url = "jdbc:t4jdbc://localhost:23400/:";
                Assert.assertTrue(driver.acceptsURL(url));

Reply via email to