0
votes

I embedding a User Defined Class (StudentProfile) inside another class (Account) using the @Embedded and @EmbeddedOnly JDO Annotations. Google Datastore indexes the attributes of the Embedded class by default and I would like to unindex many of the attributes in the Embedded Class (StudentProfile).

I have tried using the '@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")' in the Account Class, where I declare the StudentProfile Attribute, and at the various attributes of StudentProfile class itself. Even after this, I am able to filter by studentAttribute.shortName (a field I annotated to be unindexed). Since Google Datastore documentation says that unindexed fields cannot be used as filters, I take this to mean that the unindexing effort was in vain.

I believe there is an @Unindex annotation in objectify, is there an equivalent in JDO?

I also tried to experiment with unindexing a normal attribute in the Account class (using the JDO Extension) and it works (ie returns null when I try to filter by that attribute). Here is the relevant code from each class. Any help is greatly aprreciated! Thanks!

@PersistenceCapable
public class Account {
    // primary key and other attributes...

    // the embedded class with renaming for the clashing fields
    @Persistent(dependent="true", defaultFetchGroup="false")
    @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
    @Embedded(members = {
        @Persistent(name="shortName", columns=@Column(name="shortName"), extensions=@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")),
        @Persistent(name="email", columns=@Column(name="personalEmail")),
        @Persistent(name="institute", columns=@Column(name="originalInstitute"))
    })
    private StudentProfile studentProfile;
}

// the embeddedOnly class
@PersistenceCapable(embeddedOnly="true")
public class StudentProfile {
    // other attributes...

    // the filter attribute I used for querying 
    @Persistent
    @Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
    private String shortName;

}


public StudentProfileAttributes getStudentProfile(String shortName) {
    Query q = getPM().newQuery(Account.class);
    q.declareParameters("String shortNameParam");
    q.setFilter("studentProfile.shortName == shortNameParam");

    // the following execution works and a result is returned!
    @SuppressWarnings("unchecked")
    List<Account> accountsList = (List<Account>) q.execute(shortName);


}
1

1 Answers

0
votes

There is a blog post that tells you all about such things. And more recent versions (2.x) of GAE JDO plugin have an @Unindexed (which is clearly not part of JDO, being GAE-specific). http://gae-java-persistence.blogspot.co.uk/2009/11/unindexed-properties.html