Added columns to the DB to support retrieval of message headers.

This commit is contained in:
akwizgran
2013-02-28 12:49:48 +00:00
parent 88aea1bb72
commit bfd4ee5e9f
17 changed files with 296 additions and 229 deletions

View File

@@ -166,11 +166,13 @@ public interface DatabaseComponent {
/** Returns the body of the message with the given ID. */
byte[] getMessageBody(MessageId m) throws DbException;
/** Returns the header of the message with the given ID. */
MessageHeader getMessageHeader(MessageId m) throws DbException;
/** Returns the headers of all messages in the given group. */
Collection<MessageHeader> getMessageHeaders(GroupId g) throws DbException;
Collection<GroupMessageHeader> getMessageHeaders(GroupId g)
throws DbException;
/** Returns the headers of all private messages. */
Collection<PrivateMessageHeader> getPrivateMessageHeaders()
throws DbException;
/** Returns the user's rating for the given author. */
Rating getRating(AuthorId a) throws DbException;

View File

@@ -0,0 +1,31 @@
package net.sf.briar.api.db;
import net.sf.briar.api.messaging.Author;
import net.sf.briar.api.messaging.GroupId;
import net.sf.briar.api.messaging.MessageId;
public class GroupMessageHeader extends MessageHeader {
private final GroupId groupId;
private final Author author;
public GroupMessageHeader(MessageId id, MessageId parent, String subject,
long timestamp, boolean read, boolean starred, GroupId groupId,
Author author) {
super(id, parent, subject, timestamp, read, starred);
this.groupId = groupId;
this.author = author;
}
/** Returns the ID of the group to which the message belongs. */
public GroupId getGroupId() {
return groupId;
}
/**
* Returns the message's author, or null if this is an anonymous message.
*/
public Author getAuthor() {
return author;
}
}

View File

@@ -1,25 +1,18 @@
package net.sf.briar.api.db;
import net.sf.briar.api.messaging.AuthorId;
import net.sf.briar.api.messaging.GroupId;
import net.sf.briar.api.messaging.MessageId;
public class MessageHeader {
public abstract class MessageHeader {
private final MessageId id, parent;
private final GroupId group;
private final AuthorId author;
private final String subject;
private final long timestamp;
private final boolean read, starred;
public MessageHeader(MessageId id, MessageId parent, GroupId group,
AuthorId author, String subject, long timestamp, boolean read,
boolean starred) {
protected MessageHeader(MessageId id, MessageId parent, String subject,
long timestamp, boolean read, boolean starred) {
this.id = id;
this.parent = parent;
this.group = group;
this.author = author;
this.subject = subject;
this.timestamp = timestamp;
this.read = read;
@@ -39,22 +32,6 @@ public class MessageHeader {
return parent;
}
/**
* Returns the ID of the group to which the message belongs, or null if
* this is a private message.
*/
public GroupId getGroup() {
return group;
}
/**
* Returns the ID of the message's author, or null if this is an
* anonymous message.
*/
public AuthorId getAuthor() {
return author;
}
/** Returns the message's subject line. */
public String getSubject() {
return subject;

View File

@@ -0,0 +1,31 @@
package net.sf.briar.api.db;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.messaging.MessageId;
public class PrivateMessageHeader extends MessageHeader {
private final ContactId contactId;
private final boolean incoming;
public PrivateMessageHeader(MessageId id, MessageId parent, String subject,
long timestamp, boolean read, boolean starred, ContactId contactId,
boolean incoming) {
super(id, parent, subject, timestamp, read, starred);
this.contactId = contactId;
this.incoming = incoming;
}
/**
* Returns the ID of the contact who is the sender (if incoming) or
* recipient (if outgoing) of this message.
*/
public ContactId getContactId() {
return contactId;
}
/** Returns true if this is an incoming message. */
public boolean isIncoming() {
return incoming;
}
}

View File

@@ -1,9 +0,0 @@
package net.sf.briar.api.db.event;
/**
* An event that is broadcast when the retention time of the local database
* changes.
*/
public class LocalRetentionTimeUpdatedEvent extends DatabaseEvent {
}

View File

@@ -0,0 +1,9 @@
package net.sf.briar.api.db.event;
/**
* An event that is broadcast when one or messages expire from the database,
* potentially changing the database's retention time.
*/
public class MessageExpiredEvent extends DatabaseEvent {
}

View File

@@ -12,16 +12,16 @@ public interface Message {
MessageId getParent();
/**
* Returns the identifier of the {@link Group} to which the message
* belongs, or null if this is a private message.
* Returns the {@link Group} to which the message belongs, or null if this
* is a private message.
*/
GroupId getGroup();
Group getGroup();
/**
* Returns the identifier of the message's {@link Author}, or null if this
* is an anonymous message.
* Returns the message's {@link Author}, or null if this is an anonymous
* message.
*/
AuthorId getAuthor();
Author getAuthor();
/** Returns the message's subject line. */
String getSubject();