如何正确添加/操作实体组中的数千个子项?

发布于 2024-09-11 09:45:06 字数 1226 浏览 3 评论 0原文

这进一步解答了我的上一个关于在 BigTables 中处理大量对象的问题 /JDO。

假设 TransactionAccount 最终在其 transactions 列表中可能有多达 10,000 个对象,这如何与 Goodle 应用引擎配合使用?

如何将对象添加到如此大的列表而不将整个列表加载到内存中? (假设不应该将 10,000 个对象加载到内存中?)

我不是想问你如何做我的作业,我只是不知道从哪里开始解决这个问题,应用程序引擎文档和谷歌搜索没有帮助 :(

// example only, not meant to compile
@PersistenceCapable
public class TransactionAccount {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Key key;
    private long balance;
    private long transactionCount;
    @Element(dependent = "true")
    private List<Transaction> transactions = new ArrayList<Transaction>();
    ....
    public long getBalance() { return balance; }
}

@PersistenceCapable
private class Transaction {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Key key;
    public Date date;
    public long amount;
}

这个问题已提出但未解决 在以下 Google 群组帖子中

This further to my previous question on handling large numbers of objects in BigTables/JDO.

Assuming a TransactionAccount could end up with as many as 10,000 objects in its transactions list, how does this work with Goodle app engine?

How do you add objects to such a large list without the whole list being loaded into memory? (The assumption is that 10,000 objects shouldn't be loaded into memory?)

I am not trying to ask you how to do my homework, I just have no idea where to start to solve this, the app engine documentation and google searching is not helping :(

// example only, not meant to compile
@PersistenceCapable
public class TransactionAccount {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Key key;
    private long balance;
    private long transactionCount;
    @Element(dependent = "true")
    private List<Transaction> transactions = new ArrayList<Transaction>();
    ....
    public long getBalance() { return balance; }
}

@PersistenceCapable
private class Transaction {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Key key;
    public Date date;
    public long amount;
}

This question is raised but not resolved in the following google groups post.

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

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

发布评论

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

评论(1

何其悲哀 2024-09-18 09:45:06

尝试标记事务属性@NotPercient,以便它根本不存储在数据存储中。您可以使用祖先查询(更多信息请参见此帖子)。这样,您应该能够为给定帐户存储任意多的交易,因为它们并不全部存储在帐户实体中。

一个不太激烈的措施是使用此注释将交易属性标记为未索引:

@Extension(vendorName = "datanucleus", key = "gae.unindexed", value="true") 

帐户的交易仍将存储在列表中,但不会被索引,这将使其更加可行。尽管如此,您仍会在 10-100k 事务中达到 1MB 实体大小限制,如果您使用 @NotPercient,这不会成为问题。

try marking the transactions property @NotPersistent, so that it's not stored in the datastore at all. you can get the Transaction entities for a given TransactionAccount with an ancestor query (more in this thread). with that, you should be able to store arbitrarily many transactions for a given account, since they're not all stored in the account entity.

a less drastic measure would be to mark the transactions property unindexed with this annotation:

@Extension(vendorName = "datanucleus", key = "gae.unindexed", value="true") 

the account's transactions would still be stored in the list, but they wouldn't be indexed, which would make it a bit more feasible. still, you'd hit the 1MB entity size limit around 10-100k transactions, which wouldn't be a problem if you use @NotPersistent.

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