jpa 中的大型二进制文件

发布于 2024-10-03 04:46:43 字数 108 浏览 0 评论 0原文

我在 GF3 服务器和远程 swing 客户端上有 ejb + JPA 应用程序。我想通过无状态会话 bean 将大文件从客户端上传到服务器的数据库。 如何从远程 Swing 客户端上传大型二进制数据?

I have ejb + JPA app on GF3 server and remote swing client. I want upload large files from client to server's database over stateless session bean.
how to upload large binary data from remote swing client?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2024-10-10 04:46:43

在Entity Bean中,可以使用Blob字段类型&通过@Lob注释它可以将这些数据直接保存到数据库中。

//-- 编辑部分

对于如此大的文件,您可以将文件内容提取到固定大小的字节数组中,这样客户端就不会耗尽内存。

客户端:

//-------------    

    remoteInterface.initializeArraySize(ARRAY_SIZE);

    double splitIterations = ARRAY_SIZE/PERMISSIBLE_SIZE;

    for(int i=0; i < splitIterations; i++){

    // Get next byte[PERMISSIBLE_SIZE] from File

        remoteInterface.appendToArray(splittedArray);
    }

    // Finally uploading after processing

        remoteInterface.uploadFile

//---------------

服务器端:

    @Stateless
    public class FileUploadSessionBean implements FileUploadSessionBeanRemote {

    private byte[] byteArray;

    public void initializeArraySize(double arraySize){

         // Initilialized only once
         byteArray = new byteArray[arraySize];
    }

    public void appendToArray(byte[] splittedByteArray){

    /* Append the splittedByteArray at end to byteArray each time
       to build the original array
    */
    }

    public void uploadFile(){

      // Convert byteArray to Blob & persist
    }
}

In Entity Bean, you can use Blob field type & annotate it by @Lob to persist such data directly into database.

//-- Edit Part

For such a large file, you can fetch the file contents into byte array of fixed size such that client won't run out of memory.

Client side:

//-------------    

    remoteInterface.initializeArraySize(ARRAY_SIZE);

    double splitIterations = ARRAY_SIZE/PERMISSIBLE_SIZE;

    for(int i=0; i < splitIterations; i++){

    // Get next byte[PERMISSIBLE_SIZE] from File

        remoteInterface.appendToArray(splittedArray);
    }

    // Finally uploading after processing

        remoteInterface.uploadFile

//---------------

Server side:

    @Stateless
    public class FileUploadSessionBean implements FileUploadSessionBeanRemote {

    private byte[] byteArray;

    public void initializeArraySize(double arraySize){

         // Initilialized only once
         byteArray = new byteArray[arraySize];
    }

    public void appendToArray(byte[] splittedByteArray){

    /* Append the splittedByteArray at end to byteArray each time
       to build the original array
    */
    }

    public void uploadFile(){

      // Convert byteArray to Blob & persist
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文