编程语言
首页 > 编程语言> > java – 如何在实体组中正确添加/操作数千个子项?

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

作者:互联网

这是我在BigTables / JDO中的previous question on handling large numbers of objects.

假设TransactionAccount最终可能在其事务列表中包含多达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;
}

提出这个问题但没有解决in the following google groups post.

解决方法:

尝试标记事务属性@NotPersistent,以便它根本不存储在数据存储区中.您可以使用ancestor query(this thread中的更多内容)获取给定TransactionAccount的交易实体.因此,您应该能够为给定帐户存储任意多个交易,因为它们并非都存储在帐户实体中.

一个不那么激烈的措施是用这个注释标记未编入索引的交易属性:

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

帐户的交易仍然会存储在列表中,但它们不会被编入索引,这会使其更加可行.你仍然会在10-100k交易中达到1MB的实体大小限制,如果你使用@NotPersistent则不会有问题.

标签:jdo,java,google-app-engine
来源: https://codeday.me/bug/20191006/1858838.html