开发者

unique constraints-Google app engine [duplicate]

开发者 https://www.devze.com 2023-01-02 22:00 出处:网络
This question already has answers here: 开发者_JAVA技巧 Closed 10 years ago. Possible Duplicate: Unique Constraint At Data Level in GAE
This question already has answers here: 开发者_JAVA技巧 Closed 10 years ago.

Possible Duplicate:

Unique Constraint At Data Level in GAE

Does the Google App engine datastore support unique constraints?


Not really, but keys are guaranteed to be unique and you can set the key of your entity to be an arbitrary string. You can take advantage of this to create a unique key when you save your entity to the data store. For example,

public class Entity implements Serializable {

    @Id String id;

    String unique_together_1;
    String unique_together_2;

    public Entity (String unique_together_1, String unique_together_2) {

    this.id = unique_together_1 + "-" + unique_together_2;
    this.unique_together_1 = unique_together_1;
    this.unique_together_2 = unique_together_2;
    }

Obviously this won't work if the unique fields of your entity change later or if you need multiple unique constraints for a single entity type.

0

精彩评论

暂无评论...
验证码 换一张
取 消