Add storeSone() method to sone database.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 4 Mar 2014 19:18:32 +0000 (20:18 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 4 Mar 2014 19:18:32 +0000 (20:18 +0100)
src/main/java/net/pterodactylus/sone/database/SoneDatabase.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index 825be32..7ee7d9b 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.database;
 
+import net.pterodactylus.sone.data.Sone;
+
 /**
  * Combines a {@link SoneProvider} and a {@link SoneBuilderFactory} into a Sone
  * database.
@@ -25,4 +27,6 @@ package net.pterodactylus.sone.database;
  */
 public interface SoneDatabase extends SoneProvider, SoneBuilderFactory {
 
+       void storeSone(Sone sone);
+
 }
index df39511..edadf61 100644 (file)
@@ -238,6 +238,16 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        @Override
+       public void storeSone(Sone sone) {
+               lock.writeLock().lock();
+               try {
+                       sones.put(sone.getId(), sone);
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
+       @Override
        public SoneBuilder newSoneBuilder() {
                return new DefaultSoneBuilder(this) {
                        @Override