Google App Engine PersistenceManager 可以处理多个对象吗?
我有一些这样的代码:
PersistenceManager pm=PMF.get().getPersistenceManager();
String query="select from "+PayPal_Message.class.getName()+" where processed == false order by time desc";
List<PayPal_Message> messages=(List<PayPal_Message>)pm.newQuery(query).execute();
if (messages.isEmpty())
{
}
else
{
for (PayPal_Message g : messages)
{
Contact_Info_Entry A_Contact_Entry=Process_PayPal_Message_To_Get_A_License(g.getContent().getValue());
pm=PMF.get().getPersistenceManager();
try
{
pm.makePersistent(A_Contact_Entry);
g.setProcessed(true);
pm.makePersistent(g);
}
catch (Exception e)
{
Send_Email(Email_From,"[email protected]","Servlet Error Message [ "+time+" ]",new Text(e.toString()));
}
// finally { pm.close(); }
}
}
pm.close();
我想知道在关闭之前使用上面的 pm 处理多个对象是否可以。或者我是否必须获取并关闭 pm 来处理每个对象?
I have some code like this :
PersistenceManager pm=PMF.get().getPersistenceManager();
String query="select from "+PayPal_Message.class.getName()+" where processed == false order by time desc";
List<PayPal_Message> messages=(List<PayPal_Message>)pm.newQuery(query).execute();
if (messages.isEmpty())
{
}
else
{
for (PayPal_Message g : messages)
{
Contact_Info_Entry A_Contact_Entry=Process_PayPal_Message_To_Get_A_License(g.getContent().getValue());
pm=PMF.get().getPersistenceManager();
try
{
pm.makePersistent(A_Contact_Entry);
g.setProcessed(true);
pm.makePersistent(g);
}
catch (Exception e)
{
Send_Email(Email_From,"[email protected]","Servlet Error Message [ "+time+" ]",new Text(e.toString()));
}
// finally { pm.close(); }
}
}
pm.close();
I wonder if it's ok to use the pm above to process multiple objects before closing it. Or do I have to get and close pm for processing each object ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 PM 对多个对象执行操作有 2 种方法:
批处理仅限于同一类型的对象,而事务仅限于同一组的实体。
一些建议:
我希望这有帮助。
There are 2 ways to use PM to perform operations to multiple objects:
Batch processing is limited to objects with the same type while transaction is limited to entities of the same group.
Some advises:
I hope this help.
您应该尝试使用相同的 PersistenceManager 来完成尽可能多的工作。
一直购买新的可能会导致不必要的开销。如果您想使用事务,我相信无论如何您都必须使用同一个管理器来执行其中的所有活动。
You should try to use the same PersistenceManager for as much work as possible.
Getting a new one all the time probably results in unnecessary overhead. If you want to use transactions, I believe you have to use the same manager for all activities in there anyway.
试试这个...
Try this ...