-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Step5 datastore #11
Step5 datastore #11
Conversation
…can no longer be displayed on the site
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
Query query = new Query("Comment").addSort("timestamp", SortDirection.DESCENDING); | ||
|
||
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe DatastoreService could also be something that you keep as a field, like gson
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed! I guess I've been a little lazy copying the example code
commentEntity.setProperty("timestamp", timestamp); | ||
commentEntity.setProperty("text", comment); | ||
|
||
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you could reuse the instance in this method.
|
||
@Override | ||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
Query query = new Query("Comment").addSort("timestamp", SortDirection.DESCENDING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend making strings in your Java code, such as "Comment" and "timestamp" here as Java constants. That way, if you decided you needed to change the name, you don't have to find every place you used that string, you can just change the value of the constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -30,11 +36,25 @@ | |||
@WebServlet("/data") | |||
public class DataServlet extends HttpServlet { | |||
|
|||
// List of Datastore types (_T) and properties (_P) used | |||
private static final String COMMENT_T = "Comment"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest just spelling out type and property instead of just the letters, for better readability.
Converts comment storage method to cloud-based Datastore to maintain comments across server restarts.