Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Implement Document Storage and Search on Google Java App Engine : Page 2

Learn how to use the Java version of the Google App Engine by implementing search and document storage on a Java web application running on the platform.


advertisement

The Document Model Class

The combination of the Eclipse or IntelliJ IDEA App Engine plugin, JDO, and the DataNucleus tools is very easy to operate. You should be able to design and implement your model files and add the required annotations without any problems. Just watch for any error messages when the DataNucleus tools run in the background.

Before beginning the implementation of the persisted classes, take a look at the model class below, which represents documents in the system. The class definition imports the required JDO classes (in practice, you can start coding and let your IDE fill in these import statements for you). The first annotation added to the Document model class states that the class is persistent. The identity type is declared as APPLICATION to allow you to assign IDs for objects yourself as the objects are created and persisted. If you wanted to have the datastore assign object IDs, then you would specify the identity type as DATASTORE.

package com.kbsportal.model; import javax.jdo.annotations.IdentityType; import javax.jdo.annotations.PersistenceCapable; import javax.jdo.annotations.Persistent; import javax.jdo.annotations.PrimaryKey; @PersistenceCapable(identityType=IdentityType.APPLICATION) public class Document {

The code declares the member variable uri as the primary key for finding Document objects in the datastore. This JDO retrieval primary key is set to the URI for the document. The sample document store developed in this article uses this primary key in a class IndexToken (which the next section discusses further). The code also specifies that the member variables title, content, and numWords should be saved in persistent storage:


@PrimaryKey private String uri; @Persistent private String title; @Persistent private String content; @Persistent private int numWords;

The rest of the class definition contains no JDO-specific annotations:

public Document(String uri, String title, String content) { super(); setContent(content); this.title = title; this.key = uri; } public String getUri() { return key; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; this.numWords = content.split("[\\ \\.\\,\\:\\;!]").length; System.out.println("** numWords = " + numWords + " content: "+content); } public int getNumWords() { return numWords; } }

Notice the size limit placed on the content string; Google datastore limits String properties to no more than 500 characters. (Use com.google.appengine.api.datastore.Text for unlimited-size text properties.)



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap