Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- The two classes represent [un-owned] one-to-many relationship between a theme and verses. Each theme can have several verses. The persistence is done using jdo appengine api which i've implemented. like
- //verse details
- Verse verse = new Verse();
- verse.setVerseTitle("i shall not fear");
- verse.setVerseRef("psalms 23:2");
- verse.setVerseBody("the lord is my light and salvation, whom shall i fear");
- //theme details
- Theme theme = new Theme();
- theme.setTheme("psallms");
- theme.setThemeDescription("this is the theme on book of psalms");
- theme.getVerseSets().add(verse);
- pm.makePersistent(theme);
- My question is;
- How do i select only verses from a specific theme...the equivalent of "select * from verse where theme_id="theme_id" if it were the usual relational db.
- //Theme.java
- package com.versefeed.entities;
- import java.util.List;
- import javax.jdo.annotations.Element;
- import javax.jdo.annotations.IdGeneratorStrategy;
- import javax.jdo.annotations.PersistenceCapable;
- import javax.jdo.annotations.Persistent;
- import javax.jdo.annotations.PrimaryKey;
- import com.google.appengine.api.datastore.Key;
- @PersistenceCapable
- public class Theme {
- @PrimaryKey
- @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
- private Key key;
- @Persistent
- private String theme;
- @Persistent
- private String themeDescription;
- @Persistent
- private String themeArthur;
- @Persistent(mappedBy = "themes")
- @Element(dependent = "true")//cascade deletes to child objects
- private List<Verse> verseSets;
- public String getTheme() {
- return theme;
- }
- public void setTheme(String theme) {
- this.theme = theme;
- }
- public String getThemeDescription() {
- return themeDescription;
- }
- public void setThemeDescription(String themeDescription) {
- this.themeDescription = themeDescription;
- }
- public String getThemeArthur() {
- return themeArthur;
- }
- public void setThemeArthur(String themeArthur) {
- this.themeArthur = themeArthur;
- }
- public List<Verse> getVerseSets() {
- return verseSets;
- }
- public void setVerseSets(List<Verse> verseSets) {
- this.verseSets = verseSets;
- }
- public Key getKey() {
- return key;
- }
- public Theme() {
- // TODO Auto-generated constructor stub
- }
- }
- //Verse.java
- package com.versefeed.entities;
- import javax.jdo.annotations.IdGeneratorStrategy;
- import javax.jdo.annotations.PersistenceCapable;
- import javax.jdo.annotations.Persistent;
- import javax.jdo.annotations.PrimaryKey;
- import com.google.appengine.api.datastore.Key;
- import com.google.appengine.api.datastore.Text;
- @PersistenceCapable
- public class Verse {
- @PrimaryKey
- @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
- private Key key;
- @Persistent
- private boolean flag = false;
- @Persistent
- private Text verseBody;
- @Persistent
- private String verseRef;
- @Persistent
- private String verseTitle;
- @Persistent
- private Theme themes;
- public Verse() {
- // TODO Auto-generated constructor stub
- }
- public boolean isFlag() {
- return flag;
- }
- public void setFlag(boolean flag) {
- this.flag = flag;
- }
- public Text getVerseBody() {
- return verseBody;
- }
- public void setVerseBody(String verseBody) {
- this.verseBody = new Text(verseBody);
- }
- public String getVerseRef() {
- return verseRef;
- }
- public void setVerseRef(String verseRef) {
- this.verseRef = verseRef;
- }
- public String getVerseTitle() {
- return verseTitle;
- }
- public void setVerseTitle(String verseTitle) {
- this.verseTitle = verseTitle;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement