How do you properly add/manipulate thousands of children in an entity group?

社会主义新天地 提交于 2019-12-18 18:22:45

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3342603/how-do-you-properly-add-manipulate-thousands-of-children-in-an-entity-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!