Jim and John #4

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+22 −6
Split
@@ -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;
@@ -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);
@@ -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) {
@@ -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;
@@ -37,9 +37,11 @@ public void storeMessage(Message msg) {
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")
@@ -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;
@@ -21,6 +22,9 @@
@Persistent
private String text;
+
+ @Persistent
+ private Date date = new Date();
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
@@ -30,9 +34,10 @@
* @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;
}
/**
@@ -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
@@ -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>
Binary file not shown.