我@Cached在我的实体上使用了objectify的注释.显然,这意味着每当我对我的实体执行PUT时,它也会将其写入memcache.然而,最近,我已经看到memcache关闭了appengine,因此objectify无法写入memcache的权利(写入数据存储区很好).
然而,在这个失败中,objectify会抛出memcache异常 - 具体来说: com.google.appengine.api.memcache.MemcacheServiceException: Memcache put: Set failed to set 1 keys:
有没有办法让客观化不抛出这些例外?它们相对无害,我不想在任何地方添加尝试/捕获.
我有一个简单的问题
在objectify文档中,它说"只有get(),put()和delete()与缓存交互.query()没有缓存" http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Global_Cache.
我想知道的 - 如果你有一个根实体(由于所有可扩展性问题,我没有使用@Parent),所有其他实体都有一个Key,你做了一个查询,如
ofy.query(ChildEntity.class).filter("rootEntity", rootEntity).list()
Run Code Online (Sandbox Code Playgroud)
这是完全绕过缓存?
如果是这种情况,是否有一种有效的缓存方式来对条件进行查询 - 或者就此而言,您可以使用父级缓存查询,您必须在其中创建一个实际的祖先查询,如下所示
Key<Parent> rootKey = ObjectifyService.factory().getKey(root)
ofy.query(ChildEntity.class).ancestor(rootKey)
Run Code Online (Sandbox Code Playgroud)
谢谢
至于下面的评论之一,我添加了一个编辑
sample dao(忽略validate方法 - 它只进行一些null和数量检查):
这是一个示例查找请求工厂ServiceLocator正在使用的DAO调用的委托内的所有方法
public List<EquipmentCheckin> findAll(Subject subject, Objectify ofy, Event event) {
final Business business = (Business) subject.getSession().getAttribute(BUSINESS_ATTRIBUTE);
final List<EquipmentCheckin> checkins = ofy.query(EquipmentCheckin.class).filter(BUSINESS_ATTRIBUTE, business)
.filter(EVENT_CONDITION, event).list();
return validate(ofy, checkins);
}
Run Code Online (Sandbox Code Playgroud)
现在,当执行此操作时,我发现在AbstractDAO中实际调用了以下方法.
/**
*
* @param id
* @return
*/
public T find(Long id) {
System.out.println("finding " + clazz.getSimpleName() + " id = " + id);
return ObjectifyService.begin().find(clazz, id); …Run Code Online (Sandbox Code Playgroud) 我在GAE上使用Objectify作为我的DAO层,我想让我的实体大部分都是软删除能力,使这些实体用isActive布尔扩展父类是一个好主意,还是我应该使用嵌入式或者我应该只使用它一个接口isSoftDeleteable?
我要问的原因是,Objectify似乎将Entity与同一个实体类中的同一个父类存储起来(至少从我在_ah/admin中看到的那个),并且当一切都在同一个实体类型下时它可能会减慢查询速度,也许?
哪种方法最好,或者有更好的方法在GAE中进行软删除?
请提前通知并提前致谢!
这个问题可能看起来很愚蠢,但对我来说,循环引用是例如对象 A 引用对象 B 而对象 B 引用对象 A。
我正在使用一个 android 应用程序与一个带有 objectify DB 的 GAE 服务器进行通信。
我的模型很简单,但出现错误:
org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle (through reference chain: java.util.ArrayList[0]->com.my.model.MyMessage["senderKey"]->com.googlecode.objectify.Key["root"])
Run Code Online (Sandbox Code Playgroud)
这是我的模型:MyMessage 指的是 MyUser(MyUser DOESNT 指的是 MyMessage...
这是代码:
public class MyMessage implements Serializable {
private static final long serialVersionUID = -1075184303389185795L;
@Id
private Long id;
@Unindexed
private String sendMessage;
@Unindexed
private String answerMessage;
private MessageStatus status = MessageStatus.FREE;
@Parent
Key<MyUser> senderKey;
Key<MyUser> answererKey;
@SuppressWarnings("unused")
private MyMessage() {
}
public MyMessage(MyUser user, String message) { …Run Code Online (Sandbox Code Playgroud) 我正在相同类型的实体之间实现友谊功能Profile.此实体类型是root(非父)实体.一个Profile有一个Set<Ref<Profile>>名为的字段friends,它是getter getFriends().
这里的代码:
public boolean makeFriends(final Profile profile1, final Profile profile2) {
final Ref<Profile> profileRef1 = Ref.create(profile1);
final Ref<Profile> profileRef2 = Ref.create(profile2);
boolean result = false;
// test to avoid useless transaction
if (!profile1.getFriends().contains(profileRef2) && !profile2.getFriends().contains(profileRef1)) {
// add to friends (Set<Ref<Profile>>) the Ref of each other
result = ofy().transact(new Work<Boolean>() {
@Override
public Boolean run() {
profile1.getFriends().add(profileRef2);
profile2.getFriends().add(profileRef1);
ofy().save().entities(profile1, profile2).now();
return true;
}
});
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
这段代码给了我一个:
java.lang.IllegalArgumentException: cross-group transaction …Run Code Online (Sandbox Code Playgroud) 是否可以通过仅返回具有特定列表字段为空的实体来过滤对象中的实体?
例如,如果我有一个客户端实体,它具有属性"地址",这是一种类型的列表,我怎么才能只返回没有相关地址的客户端?
是否有某种"空"或"空"过滤器?就像是:
ofy().load().type(Client.class).filter("address", null).list();
Run Code Online (Sandbox Code Playgroud)
要么
ofy().load().type(Client.class).filter("address is", null).list();
Run Code Online (Sandbox Code Playgroud)
非常感谢.
我正在使用GAE,我需要写一个Objectify查询,询问9月1日之后创建的元素.
dateCreated字段是Java.util.Date,它以2012-11-29 16:03:59.494000的格式存储.
此请求不起作用:
public List<MyElement> listAllFromUser(String userId)
{
Objectify ofy = ObjectifyService.begin();
Query<MyElement> q=ofy.query(MyElement.class).filter("dateCreated >", "2013-09-01 00:00:00");
List<MyElement> results = q.list();
return results;
}
Run Code Online (Sandbox Code Playgroud) 在GAE中,使用Objectify时,您可以查询HashMap吗?如果是这样你会怎么写呢?
ofy().load().type(MyClass.class).filter("hashMapfieldName", "keyQueryinggFor").list();
Run Code Online (Sandbox Code Playgroud)
似乎不工作,而且hashMapfieldName是一个HashMap<String, String>.我期待找到hashMapfieldName包含某个键的实体.
我想从我包含在使用 Google Plugin for Eclipse 的 Google App Engine 项目中的 Objectify 3.1 库中过滤源代码目录。很可能我错误地导入了他们的库,但我想看看是否可以从 Eclipse 中“隐藏”这个源目录,这样它就不会尝试编译它。
我正在尝试使用资源过滤器。项目相对路径似乎最合适,但我无法弄清楚语法。斜杠朝哪个方向走?我在开头加斜杠吗?
java eclipse google-app-engine objectify google-plugin-eclipse
我正在努力掌握Google App Engine编程,并想知道这两种方法之间的区别是什么 - 如果有实际差异的话.
方法A)
public Collection<Conference> getConferencesToAttend(Profile profile)
{
List<String> keyStringsToAttend = profile.getConferenceKeysToAttend();
List<Conference> conferences = new ArrayList<Conference>();
for(String conferenceString : keyStringsToAttend)
{
conferences.add(ofy().load().key(Key.create(Conference.class,conferenceString)).now());
}
return conferences;
}
Run Code Online (Sandbox Code Playgroud)
方法B)
public Collection<Conference> getConferencesToAttend(Profile profile)
List<String> keyStringsToAttend = profile.getConferenceKeysToAttend();
List<Key<Conference>> keysToAttend = new ArrayList<>();
for (String keyString : keyStringsToAttend) {
keysToAttend.add(Key.<Conference>create(keyString));
}
return ofy().load().keys(keysToAttend).values();
}
Run Code Online (Sandbox Code Playgroud)
"conferenceKeysToAttend"列表保证只有唯一的会议 - 即使我选择了两种备选方案中的哪一种呢?如果是这样,为什么?