Created
August 6, 2014 11:38
-
-
Save imjacobclark/cf717c24221c551fc868 to your computer and use it in GitHub Desktop.
Messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package models; | |
import java.util.*; | |
import play.modules.mongodb.jackson.MongoDB; | |
import net.vz.mongodb.jackson.JacksonDBCollection; | |
import net.vz.mongodb.jackson.Id; | |
import net.vz.mongodb.jackson.ObjectId; | |
import org.codehaus.jackson.annotate.JsonProperty; | |
import net.vz.mongodb.jackson.*; | |
import net.vz.mongodb.jackson.DBQuery.*; | |
import net.vz.mongodb.jackson.DBUpdate.*; | |
import javax.persistence.*; | |
public class Message{ | |
@Id | |
@ObjectId | |
public String id; | |
public String from; | |
public String to; | |
public String subject; | |
public String message; | |
private static JacksonDBCollection<Message, String> coll = MongoDB.getCollection("messages", Message.class, String.class); | |
public Message(){ | |
} | |
public Message(String from, String to, String subject, String message) { | |
this.from = from; | |
this.to = to; | |
this.subject = subject; | |
this.message = message; | |
} | |
public static List<Message> all() { | |
return Message.coll.find().toArray(); | |
} | |
public static void create(Message message) { | |
Message.coll.save(message); | |
} | |
public static void create(String from, String to, String subject, String message){ | |
create(new Message(from, to, subject, message)); | |
} | |
public static void delete(String id) { | |
Message message = Message.coll.findOneById(id); | |
if (message != null) | |
Message.coll.remove(message); | |
} | |
public static List<Message> findByFrom(String from){ | |
return Message.coll.find( DBQuery.is("from", from) ).toArray(); | |
} | |
public static List<Message> findByTo(String to){ | |
return Message.coll.find( DBQuery.is("to", to) ).toArray(); | |
} | |
public static void removeAll(){ | |
Message.coll.drop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment