Last Thursday, Google announced that Google Cloud SQL is available for limited preview. If you want to try the new services, you can sign up at Google's page. This weblog covers Google Cloud SQL after the first public release. It will make a nice addition to the Datastore, which is NoSQL. Depending on your use case and non-functional requirements, it is good to have a choice!
Go to Google's Cloud SQL website to find out more about the limited preview.
Essential App Engine
Adriaan de Jonge
Sunday, October 9, 2011
Thursday, October 6, 2011
Prospective Search API part 2/4 - Registering a Query
Part 1 of this post gave a general introduction of the Prospective Search API. Part 2 shows you how to register a query. Let's start with the code:
package com.appspot.prospect;
import com.google.appengine.api.prospectivesearch.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class SubscribeProspectiveSearchServlet
extends HttpServlet {
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
ProspectiveSearchService prospectiveSearch =
ProspectiveSearchServiceFactory
.getProspectiveSearchService();
String topic = "Person";
String subscriptionId = "SearchPersonByName";
long leaseTimeInMilliseconds = 24 * 60 * 60 * 1000;
String query = "name:Adriaan";
Map<String, FieldType> schema =
new HashMap<String, FieldType>();
schema.put("name", FieldType.STRING);
schema.put("email", FieldType.STRING);
prospectiveSearch.subscribe(
topic,
subscriptionId,
leaseTimeInMilliseconds,
query,
schema);
resp.getWriter().write("New Query Added");
}
}
There are a few things worth mentioning.
The topic allows you to group prospective searches. This way, when you are adding a new document and you want to see if it matches certain prospective searches, it is not necessary to test all searches you have registered. Only those that are relevant. A good start is to keep the topic equal to your entity kind.
The subscriptionId must be unique. If you register a new subscription with the same id, the previous one is overwritten. If you allow your visitors to register their own searches, you should include a visitor id. If visitors can register multiple searches, you should also distinguish between those.
If you want a lease time that does not expire, you should set it to 0.
The query asks for entities that have a name field with the value Adriaan.
The prospective search API needs a schema definition in the form of a Map.
Once you provided these parameters, you can register a query and later on, provide matching documents.
package com.appspot.prospect;
import com.google.appengine.api.prospectivesearch.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class SubscribeProspectiveSearchServlet
extends HttpServlet {
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
ProspectiveSearchService prospectiveSearch =
ProspectiveSearchServiceFactory
.getProspectiveSearchService();
String topic = "Person";
String subscriptionId = "SearchPersonByName";
long leaseTimeInMilliseconds = 24 * 60 * 60 * 1000;
String query = "name:Adriaan";
Map<String, FieldType> schema =
new HashMap<String, FieldType>();
schema.put("name", FieldType.STRING);
schema.put("email", FieldType.STRING);
prospectiveSearch.subscribe(
topic,
subscriptionId,
leaseTimeInMilliseconds,
query,
schema);
resp.getWriter().write("New Query Added");
}
}
There are a few things worth mentioning.
The topic allows you to group prospective searches. This way, when you are adding a new document and you want to see if it matches certain prospective searches, it is not necessary to test all searches you have registered. Only those that are relevant. A good start is to keep the topic equal to your entity kind.
The subscriptionId must be unique. If you register a new subscription with the same id, the previous one is overwritten. If you allow your visitors to register their own searches, you should include a visitor id. If visitors can register multiple searches, you should also distinguish between those.
If you want a lease time that does not expire, you should set it to 0.
The query asks for entities that have a name field with the value Adriaan.
The prospective search API needs a schema definition in the form of a Map.
Once you provided these parameters, you can register a query and later on, provide matching documents.
Monday, September 26, 2011
Prospective Search API part 1/4 - Introduction
After reading Essential App Engine, you already know the datastore API, how to save, update and delete data, and how to query through your data set using the low level API. The regular way of searching through a data set is great when your data has a static nature. Consider data sets that change no more than three or four times each year and only with minor updates. In that case, the result of the search will be presented to the visitor directly.
By contrast, consider a data set that is changing frequently. Imagine that a data set of one day old is already hopelessly outdated. Think of news, the latest twitter trends, traffic jams, speed camera's, stock prices, or anything like it.
Sometimes your visitors are only interested in your data when newly entered records meet certain criteria. In such cases, the Prospective Search API is a useful tool.
The Prospective Search API allows you to register a query on data that has not been entered into the system yet. As soon as a new record is added that meets the search criteria of the registered query, a specific task in the task queue is triggered to take action.
Whether the action sends an e-mail, fires a call to a web service or does something completely different, that is up to you. The action implementation follows the usual everything-is-a-HTTP-request principle, also seen in other service calls.
The APIs are introduced in a series of smaller blog posts.
Part 1 - Introduction (this post)
Part 3 - Matching Documents
Part 4 - Handling Query Results
Wednesday, September 21, 2011
Upcoming conference talk: J-Fall on November 2nd, 2011
At November 2nd I will speak at the Dutch Java user group's conference called J-Fall. Click here for conference information and registration.
15 Ways to Improve Google App Engine PerformanceGoogle App Engine is designed for high scalability and adapts quickly to changes in demand. Although many existing libraries and frameworks can run on the App Engine, they do not always fit with Google's design for scalability. For example, a common approach to optimize response times is to take a performance hit at system startup. When your application is started and stopped every 10 or 15 minutes, this optimization strategy becomes undesirable.This presentation challenges some common habits and technologies in Java programming in order to speed up App Engine applications. The audience is encouraged to rethink practices like data normalization and start doing the exact opposite. Although this may feel unnatural at first, there is good reasoning behind it.The presentation covers popular technologies like NoSQL storage, HTML5-related APIs and programming for a cloud environment.Click here for details.
Subscribe to:
Posts (Atom)