Tag injection in JDO

I am implementing a tag system for a website using JDO. I would like to use this method.

However, I am new to relationships in JDO. To make it simple, I look like this:

@PersistentCapable
class Post {
@Persistent String title;
@Persistent String body;
}

@PersistentCapable
class Tag {
@Persistent String name;
}

What kind of JDO relationships do I need and how to implement them? I want to be able to list all Tagthat belong Post, and also be able to list all Postthat have a given Tag. So in the end I would like to have something like this:

Table: Post
Columns: PostID, Title, Body

Table: Tag
Columns: TagID, name

Table: PostTag
Columns: PostID, TagID
+3
source share
2 answers

: http://code.google.com/appengine/docs/java/datastore/relationships.html#Unowned_Relationships

PostTag, Key :

@PersistentCapable
class PostTag {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key; 
    /*you should add this to Post and Tag as well,
    since this is what the fields in PostTag will reference
    you can rename them to ClassnameID if you like, I believe*/

    @Persistent
    private Key post;

    @Persistent
    private Key tag;
}

, PostTag, -

PostTag pt = new PostTag();
pt.setPost(post.getKey());
pt.setTag(tag.getKey());
// persist pt here;

getters/setters , , ; "post" "tag" , .

: : http://code.google.com/appengine/docs/java/datastore/usingjdo.html#Unsupported_Features_of_JDO, JDO ( , - -, , ). .

+3

" " , JDO. App Engine JDO, , .

0

Source: https://habr.com/ru/post/1746328/


All Articles