首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在olingo v2中处理BLOB和CLOB?

问如何在olingo v2中处理BLOB和CLOB?
EN

Stack Overflow用户
提问于 2020-07-09 18:52:07
回答 1查看 64关注 0票数 1

Here在olingo jpa中有关于如何处理BLOB和CLOB的伪代码。我将所需的导入添加到伪代码中:

代码语言:javascript
复制
package me;

import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;

import javax.sql.rowset.serial.SerialException;

import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;

public class OnDBWriteContent implements OnJPAWriteContent {

    @Override
    public Blob getJPABlob(byte[] binaryData) throws ODataJPARuntimeException {
        try {
            return new JDBCBlob(binaryData);
        } catch (SerialException e) {
            ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
        } catch (SQLException e) {
            ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
        }
        return null;
    }

    @Override
    public Clob getJPAClob(char[] characterData) throws ODataJPARuntimeException {
        try {
            return new JDBCClob(new String(characterData));
        } catch (SQLException e) {
            ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
        }
        return null;
    }
}

唯一的问题是我找不到任何用于JDBCBlob和JDBCClob的实现。关于如何实现它们或使用某些类,有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-20 04:45:04

如果您使用的是MySQL,那么它需要一个额外的ExceptionInterceptor以及Blob实现。您可以拥有一个自定义的ExceptionInterceptor实现,并使用它来初始化Blob字段。

实现该目标的代码如下所示

代码语言:javascript
复制
import java.sql.Blob;
import java.sql.Clob;
import java.util.Properties;

import org.apache.olingo.odata2.jpa.processor.api.OnJPAWriteContent;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;

import com.mysql.cj.exceptions.ExceptionInterceptor;
import com.mysql.cj.log.Log;

public class CustomOnJPAWriteContent implements OnJPAWriteContent {

    @Override
    public Blob getJPABlob(byte[] binaryData) throws ODataJPARuntimeException {
        return new com.mysql.cj.jdbc.Blob(binaryData, exceptionInterceptor);
    }

    @Override
    public Clob getJPAClob(char[] characterData) throws ODataJPARuntimeException {
        
        return new com.mysql.cj.jdbc.Clob(new String(characterData), exceptionInterceptor);

    }

    ExceptionInterceptor exceptionInterceptor = new ExceptionInterceptor() {

        @Override
        public Exception interceptException(Exception sqlEx) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public ExceptionInterceptor init(Properties props, Log log) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void destroy() {
            // TODO Auto-generated method stub

        }
    };

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62813234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档