是否有可能在Google App Engine上使用Java计算属性? [英] Is it possible to have a computed property on Google App Engine using Java?
问题描述
我有一个应用程序引擎应用程序,我想运行一个查询,根据涉及两个属性的表达式对结果进行排序。到目前为止,我认为最好的方法是创建一个计算/计算的属性,存储该表达式的结果。虽然我看到Python中的GAE提供了一个ComputedProperty,这看起来正是我正在寻找的,但我无法在Java中找到相应的东西。
如果有帮助的话,我现在还在使用Objectify。
有什么想法? 使用@OnSave方法计算您的值:
@Entity
public class YourEntity {
@Id长ID;
String foo;
字符串栏;
@Index字符串计算;
@OnSave void computeComputed(){
computed = //从foo和bar合成
}
}
这是NDB的ComputedProperty实际所做的。 Java并没有真正的语法匹配方式,我不确定NDB的方法更优雅。只需放弃计算
的setter方法。
I have an app engine application and I want to run a query that sorts the result based on a expression involving two properties. Best way I thought of doing it so far is to create a computed/calculated property that stores the result of that expression. Although I saw that GAE in Python offers a ComputedProperty, which seems to be exactly what I'm looking for, I couldn't find an equivalent in Java.
I'm currently using Objectify too, if that helps.
Any ideas?
Compute your value in an @OnSave method:
@Entity
public class YourEntity {
@Id Long id;
String foo;
String bar;
@Index String computed;
@OnSave void computeComputed() {
computed = // synthesize from foo and bar
}
}
This is what NDB's ComputedProperty actually does. Java doesn't really have a way of matching that syntax, and I'm not sure NDB's approach is any more elegant. Just leave off the setter method for computed
.
这篇关于是否有可能在Google App Engine上使用Java计算属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!