用Objectify Appengine存储大块 [英] Storing large blob with Objectify Appengine

查看:95
本文介绍了用Objectify Appengine存储大块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个类,我想使用Objectify持久化,这个类将表示一个大于1MB的数据,所以有一个Blob对象列表,它表示存储的字节数组的片段大小小于1MB:

  @Entity 
public class BigBlob {

@Id
private Long id;
public static final int FRAGMENT_LIMIT = 777 * 1024;
@Serialized
私人列表< Blob> fragments = new ArrayList< Blob>();

...

}

然而, ,片段是@Serialized,它将使这个BigBlob类/对象的大小大于1MB。



导致此错误:

  com.google.apphosting.api .ApiProxy $ RequestTooLargeException:对API调用datastore_v3.Put()的请求太大。 

如果我使用@Embedded注解,则会出现此错误:

 不能在@Embedded数组或集合中放置数组或集合属性

如何确保片段作为单独的实体存储?

顺便说一下,我已经有了字节块处理逻辑,它能够将整个字节数组排序并将这些段放入 List Blob ,所以这个问题并不涉及如何切分字节。

大部分我想知道的更多的是坚持的一面。

解决方案

Rick的答案确实是blobstore中最好的商店blob,尤其是如果您对GAE不熟悉并且存在概念问题数据存储。

另一方面,使用拆分实体存储blob有一些很好的理由,特别是如果要存储接近1M边的数据时。你不会想用100MB的blob来做到这一点,但2MB的blob可以做到这一点。



首先,你不想要序列化或嵌入式。这些都是在单个实体内部构造数据的简单方法。



另外,没有魔法注释可以让您在实体之间分割斑点。你必须手工完成。您不需要实际创建主或根实体;只需创建所有实体片段,并使用由id定义的父级(但不包括实际实体)并使用ancestor()查询来获取所有片段。


I have this class which I want to persist using Objectify, this class will represent a data larger than 1MB so there's a List of Blob objects which represents a fragment of the byte array stored that is less than 1MB in size:

@Entity
public class BigBlob {

    @Id
    private Long id;
    public static final int FRAGMENT_LIMIT = 777 * 1024;
    @Serialized
    private List<Blob> fragments = new ArrayList<Blob>();

    ...

}

Yet, the the "fragments" is @Serialized, which will render the size of this BigBlob class/object larger than 1MB.

Causing this error:

com.google.apphosting.api.ApiProxy$RequestTooLargeException: The request to API call datastore_v3.Put() was too large.

If I use @Embedded annotation I get this error:

Cannot place array or collection properties inside @Embedded arrays or collections

How do I make sure that the "fragments" are stored as a separate entity?

BTW, I already have the byte chunking logic that chops the whole byte array and put the fragments into a List of Blob so this question does not pertain as to how to chop bytes.

Mostly what I want to know is more on the persisting side.

解决方案

Rick's answer is really the best - store blobs in the blobstore, especially if you are new to GAE and having conceptual issues with the datastore.

On the other hand, there are some good reasons to use split entities for storing blobs, especially if you are storing data that is close to the 1M edge. You wouldn't want to do this with 100MB blobs, but 2MB blobs can make sense.

First of all, you don't want serialized or embedded. Those are simply ways to structure data inside a single entity.

Also, there's no magic annotation that lets you split blobs across entities. You have to do it all by hand. You don't need to actually create a 'master' or root entity; just create all the entity fragments with a parent defined by an id (but no actual entity) and use an ancestor() query to fetch all the pieces.

这篇关于用Objectify Appengine存储大块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆