使用 JDO 的 Google 应用程序引擎的数据模型示例

发布于 2024-10-30 02:20:22 字数 1200 浏览 5 评论 0原文

我一直在尝试使用 GWT/GAE/GoogleDatastore 学习和创建示例项目。

我只是想找出为学习管理系统设计数据模型的最佳方法。让我们以传统方式说以下是实体......

用户
角色

用户

课程课程
科目
材料

用户与角色是一对一的
课程与主题是一对多
主题与材料是一对多
使用 UserCourses 进行课程的用户是多对多的

有人可以指导我在 JDO 中表示这一点的最佳方式是什么吗?

--->问题的延伸。

谢谢你,Shifty,但我完全陷入了无主关系模型......试图/努力摆脱传统的关系模型。

让我以简单的主题与材料为例

,尝试以下模型

@PersistenceCapable(identityType = IdentityType.APPLICATION) 公开课主题 {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private List<Materials> materials;

}

公开课材料{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private String materialName;
@Persistent
private String author;
@Persistent
private String materialType;
@Persistent
private String url;

}
当我尝试先保存材料然后将该对象分配给主题时出现问题。正如我所读,您不能将孩子分配给已经在没有父母的情况下持续存在的父母。
有时可以添加材料而不分配给主题,但可以稍后分配。

I have been trying to learn and creating a sample project using GWT/GAE/GoogleDatastore.

Am just trying to figure out what would be the best way to design the data model for a learning management system. Let's say in the traditional way the following are the entities.....

User
Role

UserCourses

Courses
Subjects
Materials

User is one to one to Role
Courses is one to many with Subjects
Subjects is one to many with Materials
Users is Many to Many with Courses using UserCourses

Can someone guide me what would be the best possible way to represent this in JDO ?

---> Extension of the question.

Thank You Shifty, but am completely stuck with unowned relationship model... trying/struggling to come out of the traditional relational model.

Let me take the simple Subjects vs Materials

Am trying out the following model,

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Subjects {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private List<Materials> materials;

}

public class Materials{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
@Persistent
private String materialName;
@Persistent
private String author;
@Persistent
private String materialType;
@Persistent
private String url;

}

When i try to save the materials first and then assigning that object into subjects is having issues. As i read, you cannot assign the child to a parent which is already persisted without parent.

Sometimes it is possible to add materials without assigned to the Subjects, but can get assigned later on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

偏爱你一生 2024-11-06 02:20:22

如果你想与 GAE 和 JDO 建立多对多关系,你必须在模型中存储键列表。

用户模型

import java.util.Set;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class User {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private Set<Key> courses;
}

课程 通过

   import java.util.Set;
    import com.google.appengine.api.datastore.Key;

    @PersistenceCapable
    public class Courses {
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;
        @Persistent
        private Set<Key> users;
    }

这种方式建模,您不需要 UserCourses 类。

编辑:

如果您使用

@Persistent
private List<Materials> materials;

您所拥有的关系模型。
这样您就不能先保留模型,然后将其添加到主题模型并保留主题模型。
只需将不持久的材料添加到主题模型的材料列表中并持久化主题模型即可。这样也能节省材料。

也许我的问题可能是错的,但我希望这会有所帮助。

if you want to make a many-to-many relationship with GAE and JDO you have to store a list of the keys in the models.

User Model

import java.util.Set;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class User {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private Set<Key> courses;
}

Courses Model

   import java.util.Set;
    import com.google.appengine.api.datastore.Key;

    @PersistenceCapable
    public class Courses {
        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;
        @Persistent
        private Set<Key> users;
    }

this way you don't need the UserCourses class.

EDIT:

If you use

@Persistent
private List<Materials> materials;

you work with a owned relationship model.
this way you can not persist the model first and then add this to the subject model and the persist the subject model.
Just add the not persistent material to the materials list of the subject model and persist the subject model. this will also save the materials.

maybe I could the question wrong but I hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文