Skip to content
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

Merged
merged 4 commits into from
Jun 4, 2020
Merged

Step5 datastore #11

merged 4 commits into from
Jun 4, 2020

Conversation

gwynethsc
Copy link
Owner

Converts comment storage method to cloud-based Datastore to maintain comments across server restarts.


@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
Query query = new Query("Comment").addSort("timestamp", SortDirection.DESCENDING);

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Copy link
Collaborator

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?

Copy link
Owner Author

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();
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Copy link
Owner Author

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";
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants