[ 
https://issues.apache.org/jira/browse/TRAFODION-2308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15635596#comment-15635596
 ] 

ASF GitHub Bot commented on TRAFODION-2308:
-------------------------------------------

Github user kevinxu021 commented on a diff in the pull request:

    https://github.com/apache/incubator-trafodion/pull/799#discussion_r86500702
  
    --- Diff: 
core/conn/jdbcT4/src/main/java/org/trafodion/jdbc/t4/TrafT4Blob.java ---
    @@ -0,0 +1,166 @@
    +// @@@ START COPYRIGHT @@@
    +//
    +// Licensed to the Apache Software Foundation (ASF) under one
    +// or more contributor license agreements.  See the NOTICE file
    +// distributed with this work for additional information
    +// regarding copyright ownership.  The ASF licenses this file
    +// to you under the Apache License, Version 2.0 (the
    +// "License"); you may not use this file except in compliance
    +// with the License.  You may obtain a copy of the License at
    +//
    +//   http://www.apache.org/licenses/LICENSE-2.0
    +//
    +// Unless required by applicable law or agreed to in writing,
    +// software distributed under the License is distributed on an
    +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +// KIND, either express or implied.  See the License for the
    +// specific language governing permissions and limitations
    +// under the License.
    +//
    +// @@@ END COPYRIGHT @@@
    +
    +package org.trafodion.jdbc.t4;
    +
    +import java.io.ByteArrayInputStream;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.io.OutputStream;
    +import java.sql.Blob;
    +import java.sql.SQLException;
    +import java.util.logging.Level;
    +import java.util.logging.LogRecord;
    +
    +public class TrafT4Blob implements Blob {
    +   private byte[] data_;
    +   private boolean isFreed_ = false;
    +   private TrafT4Connection connection_ = null;
    +
    +   public TrafT4Blob(TrafT4Connection connection, String lobHandle) throws 
SQLException {
    +           if (connection_.props_.t4Logger_.isLoggable(Level.FINE) == 
true) {
    +                   Object p[] = 
T4LoggingUtilities.makeParams(connection_.props_, connection, lobHandle);
    +                   connection_.props_.t4Logger_.logp(Level.FINE, 
"TrafT4ResultSet", "getClob", "", p);
    +           }
    +           if (connection_.props_.getLogWriter() != null) {
    +                   LogRecord lr = new LogRecord(Level.FINE, "");
    +                   Object p[] = 
T4LoggingUtilities.makeParams(connection_.props_, connection, lobHandle);
    +                   lr.setParameters(p);
    +                   lr.setSourceClassName("TrafT4ResultSet");
    +                   lr.setSourceMethodName("getClob");
    +                   T4LogFormatter lf = new T4LogFormatter();
    +                   String temp = lf.format(lr);
    +                   connection_.props_.getLogWriter().println(temp);
    +           }
    +   }
    +
    +   public InputStream getBinaryStream() throws SQLException {
    +           testAvailability();
    +           return new ByteArrayInputStream(this.data_);
    +   }
    +
    +   public InputStream getBinaryStream(long pos, long length) throws 
SQLException {
    +           testAvailability();
    +           
TrafT4Messages.throwUnsupportedFeatureException(connection_.props_, 
connection_.getLocale(),
    +                           "getBinaryStream()");
    +           return null;
    +   }
    +
    +   /*
    +    * Retrieves all or part of the BLOB value that this Blob object 
represents,
    +    * as an array of bytes. This byte array contains up to length 
consecutive
    +    * bytes starting at position pos.
    +    *  */
    +   public byte[] getBytes(long pos, int length) throws SQLException {
    +           testAvailability();
    +
    +           byte[] buf = null;
    +           int startPos = (int)pos - 1;
    +           int endPos = startPos + length;
    +
    +           if((startPos > data_.length) || (startPos < 0) || (length < 0))
    +                   throw 
TrafT4Messages.createSQLException(this.connection_.props_, 
this.connection_.getLocale(),
    +                                   "out_of_lob_bound_msg", null);
    +
    +           if((endPos - 1) > data_.length) {
    +                   length = data_.length - startPos;
    +           }
    +           buf = new byte[length];
    +           System.arraycopy(data_, startPos, buf, 0, length);
    +
    +           return buf;
    +   }
    +
    +   public int setBytes(long pos, byte[] bytes) throws SQLException {
    +           testAvailability();
    +
    +           return setBytes(pos, bytes, 0, bytes.length);
    +   }
    +
    +   public int setBytes(long pos, byte[] bytes, int offset, int len) throws 
SQLException {
    +           testAvailability();
    +           OutputStream out = setBinaryStream(pos);
    +
    +           try {
    +                   out.write(bytes, offset, len);
    +           } catch (IOException e) {
    +                   throw 
TrafT4Messages.createSQLException(this.connection_.props_, 
this.connection_.getLocale(),
    +                                   "blob_io_error", null);
    +           } finally {
    +                   try {
    +                           out.close();
    +                   } catch (IOException e2) {
    +
    +                   }
    +           }
    +           return len;
    +   }
    +
    +   public long position(Blob pattern, long start) throws SQLException {
    +           
TrafT4Messages.throwUnsupportedFeatureException(connection_.props_, 
connection_.getLocale(), "position()");
    +           return 0;
    +   }
    +
    +   public long position(byte[] pattern, long start) throws SQLException {
    +           
TrafT4Messages.throwUnsupportedFeatureException(connection_.props_, 
connection_.getLocale(), "position()");
    +           return 0;
    +   }
    +
    +   public OutputStream setBinaryStream(long pos) throws SQLException {
    +           
TrafT4Messages.throwUnsupportedFeatureException(connection_.props_, 
connection_.getLocale(),
    +                           "setBinaryStream()");
    +           return null;
    +   }
    +
    +   public void truncate(long len) throws SQLException {
    +           testAvailability();
    +
    +           if (len < 0 || len > this.data_.length) {
    +                   throw 
TrafT4Messages.createSQLException(this.connection_.props_, 
this.connection_.getLocale(),
    +                                   "out_of_lob_bound_msg", null);
    --- End diff --
    
    out_of_lob_bound


> JDBC T4 support read LOB
> ------------------------
>
>                 Key: TRAFODION-2308
>                 URL: https://issues.apache.org/jira/browse/TRAFODION-2308
>             Project: Apache Trafodion
>          Issue Type: Sub-task
>          Components: client-jdbc-t4, connectivity-mxosrvr
>            Reporter: Weiqing Xu
>            Assignee: Weiqing Xu
>
> JDBC T4 need implement some API to support CLOB and BLOB.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to