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

Jim and John #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.gac.mcs270.messageboard.client;

import java.util.List;
import java.util.Date;

import edu.gac.mcs270.messageboard.shared.Message;
import edu.gac.mcs270.messageboard.shared.MessageStore;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void onModuleLoad() {
final TextBox textField = new TextBox();
entryPanel.add(textLabel);
entryPanel.add(textField);

final Button postButton = new Button("Post");
entryPanel.add(postButton);

Expand All @@ -77,7 +78,7 @@ public void onClick(ClickEvent event) {
messageStore.storeMessage(
new Message(
authorField.getText(),
textField.getText()),
textField.getText(), new Date()),
new AsyncCallback<Void>(){
@Override
public void onFailure(Throwable caught) {
Expand Down Expand Up @@ -130,12 +131,13 @@ public void onSuccess(List<Message> result) {
updatingLabel.setVisible(false);
int position = 0;
for(Message m : result){
Label heading = new Label(m.getAuthor());
Label heading = new Label(m.getAuthor() + " - " + m.getDate().toString());
heading.addStyleName("messageHeading");
messagesPanel.insert(heading, position++);
Label body = new Label(m.getText());
body.addStyleName("messageBody");
messagesPanel.insert(body, position++);

}
if(!result.isEmpty()){
nextID = result.get(0).getId() + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public List<Message> getMessages(Long minimumID) {
PersistenceManager pm = pmf.getPersistenceManager();
Query query = pm.newQuery(Message.class);
query.declareParameters("Long minimumID");
//limit to new messages
query.setFilter("id >= minimumID");
query.setOrdering("id descending");
if(minimumID == 1){
//keeps initial updates fast
query.setRange(0, MessageStore.INITIAL_LIMIT);
}
@SuppressWarnings("unchecked")
Expand Down
14 changes: 13 additions & 1 deletion MessageBoard/src/edu/gac/mcs270/messageboard/shared/Message.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.gac.mcs270.messageboard.shared;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
Expand All @@ -21,6 +22,9 @@ public class Message implements Serializable{

@Persistent
private String text;

@Persistent
private Date date = new Date();

@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
Expand All @@ -30,9 +34,10 @@ public class Message implements Serializable{
* @param author the name of the Message's author
* @param text the body of the Message
*/
public Message(String author, String text) {
public Message(String author, String text, Date date) {
this.author = author;
this.text = text;
this.date = date;
}

/**
Expand All @@ -48,6 +53,13 @@ public String getAuthor() {
public String getText() {
return text;
}

/**
* @return the date of this Message
*/
public Date getDate() {
return date;
}

/**
* @return the id of this Message
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!-- Indices written at Sat, 24 Mar 2012 19:02:37 UTC -->
<!-- Indices written at Tue, 27 Mar 2012 16:51:56 UTC -->

<datastore-indexes>

<!-- Used 6 times in query history -->
<!-- Used 104 times in query history -->
<datastore-index kind="Message" ancestor="false" source="auto">
<property name="__key__" direction="desc"/>
</datastore-index>
Expand Down
Binary file modified MessageBoard/war/WEB-INF/appengine-generated/local_db.bin
Binary file not shown.