import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.database.DatabaseException;
-import net.pterodactylus.sone.database.PostBuilder;
import net.pterodactylus.sone.database.PostDatabase;
-import net.pterodactylus.sone.database.PostReplyBuilder;
import net.pterodactylus.sone.database.SoneBuilder;
import net.pterodactylus.util.config.Configuration;
import net.pterodactylus.util.config.ConfigurationException;
// DATABASE METHODS
//
- /**
- * Saves the database.
- *
- * @throws DatabaseException
- * if an error occurs while saving
- */
@Override
public void save() throws DatabaseException {
saveKnownPosts();
// SERVICE METHODS
//
- /** {@inheritDocs} */
@Override
protected void doStart() {
loadKnownPosts();
notifyStarted();
}
- /** {@inheritDocs} */
@Override
protected void doStop() {
try {
// POSTPROVIDER METHODS
//
- /** {@inheritDocs} */
@Override
public Optional<Post> getPost(String postId) {
lock.readLock().lock();
}
}
- /** {@inheritDocs} */
@Override
public Collection<Post> getPosts(String soneId) {
return new HashSet<Post>(getPostsFrom(soneId));
}
- /** {@inheritDocs} */
@Override
public Collection<Post> getDirectedPosts(String recipientId) {
lock.readLock().lock();
// POSTSTORE METHODS
//
- /** {@inheritDocs} */
@Override
public void storePost(Post post) {
checkNotNull(post, "post must not be null");
}
}
- /** {@inheritDocs} */
@Override
public void removePost(Post post) {
checkNotNull(post, "post must not be null");
}
}
- /** {@inheritDocs} */
@Override
public void storePosts(Sone sone, Collection<Post> posts) throws IllegalArgumentException {
checkNotNull(sone, "sone must not be null");
}
}
- /** {@inheritDocs} */
@Override
public void removePosts(Sone sone) {
checkNotNull(sone, "sone must not be null");
// POSTREPLYPROVIDER METHODS
//
- /** {@inheritDocs} */
@Override
public Optional<PostReply> getPostReply(String id) {
lock.readLock().lock();
}
}
- /** {@inheritDocs} */
@Override
public List<PostReply> getReplies(String postId) {
lock.readLock().lock();
// POSTREPLYSTORE METHODS
//
- /** {@inheritDocs} */
+ /**
+ * Returns whether the given post reply is known.
+ *
+ * @param postReply
+ * The post reply
+ * @return {@code true} if the given post reply is known, {@code false}
+ * otherwise
+ */
+ public boolean isPostReplyKnown(PostReply postReply) {
+ lock.readLock().lock();
+ try {
+ return knownPostReplies.contains(postReply.getId());
+ } finally {
+ lock.readLock().unlock();
+ }
+ }
+
+ @Override
+ public void setPostReplyKnown(PostReply postReply) {
+ lock.writeLock().lock();
+ try {
+ knownPostReplies.add(postReply.getId());
+ } finally {
+ lock.writeLock().unlock();
+ }
+ }
+
@Override
public void storePostReply(PostReply postReply) {
lock.writeLock().lock();
}
}
- /** {@inheritDocs} */
@Override
public void storePostReplies(Sone sone, Collection<PostReply> postReplies) {
checkNotNull(sone, "sone must not be null");
}
}
- /** {@inheritDocs} */
@Override
public void removePostReply(PostReply postReply) {
lock.writeLock().lock();
}
}
- /** {@inheritDocs} */
@Override
public void removePostReplies(Sone sone) {
checkNotNull(sone, "sone must not be null");
}
}
- /**
- * Returns whether the given post reply is known.
- *
- * @param postReply
- * The post reply
- * @return {@code true} if the given post reply is known, {@code false}
- * otherwise
- */
- boolean isPostReplyKnown(PostReply postReply) {
- lock.readLock().lock();
- try {
- return knownPostReplies.contains(postReply.getId());
- } finally {
- lock.readLock().unlock();
- }
- }
-
- /**
- * Sets whether the given post reply is known.
- *
- * @param postReply
- * The post reply
- * @param known
- * {@code true} if the post reply is known, {@code false} otherwise
- */
- void setPostReplyKnown(PostReply postReply, boolean known) {
- lock.writeLock().lock();
- try {
- if (known) {
- knownPostReplies.add(postReply.getId());
- } else {
- knownPostReplies.remove(postReply.getId());
- }
- } finally {
- lock.writeLock().unlock();
- }
- }
-
//
// PRIVATE METHODS
//