Part Two of the Stockwatcher Google App Engine experience

August 8, 2010 at 4:51 pm Leave a comment

This is the followup to the first part of the stockwatcher walkthu.

I have some experience with JDO dating back 5 years ago.

In the META-INF directory, a file jdoconfig.xml is created which specifies the JDO config with Google App Engine (GAE) .

With GAE, for JDO its uses the Data Nucleus Platform’s API.

The UserService class  is Part of the Users  AppEngine API : The UserService provides information useful for forcing a user to log in or out, and retrieving information about the user who is currently logged-in.

The class LoginServiceImpl is where we make use of the login functionality.  We’ll see this as we start out with the Stockwatcher class which is the entrypoint:

<entry-point class= ‘com.google.gwt.sample.stockwatcher.client.StockWatcher’>

In the OnModuleLoad method, its starts out by making an rpc call to the login method in the LoginService passing in the string value requestUri:

 GWT.getHostPageBaseURL()

 The class  LoginServiceImpl makes use of the Users API where is checks if it has a valid user as follows:

UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser(); 
user.getEmail();
userService.createLogoutURL(requestUri) ;

 Then after the RPC call returns, either the user is asked to login  on failure, or we proceed onto the Stockwatcher main flow.

The Stockwatcher starts out by reading the stock values from “the cloud” that have already been saved.  The stock domain object is defined as follows:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Stock {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private User user;
@Persistent
private String symbol;
@Persistent
private Date createDate;
public Stock() {
this.createDate = new Date();
}
public Stock(User user, String symbol) {
this();
this.user = user;
this.symbol = symbol;
}

The stocks are retrieved in StockServiceImpl to retrieve the stocks:

PersistenceManager pm = getPersistenceManager();
List symbols = new ArrayList();
try {
Query q = pm.newQuery(Stock.class, "user == u");
q.declareParameters("com.google.appengine.api.users.User u");
q.setOrdering("createDate");
List stocks = (List) q.execute(getUser());
for (Stock stock : stocks) {
symbols.add(stock.getSymbol());
}

 Of course, the stocks are saved as follows:

PersistenceManager pm = getPersistenceManager();
try {
pm.makePersistent(new Stock(getUser(), symbol));
} finally {
pm.close();
}

Advertisements

Entry filed under: Uncategorized.

Stockwatcher Google App Engine experience Stockwatcher GAE JPA

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


@davidmbloom


%d bloggers like this: