2 * Sone - Database.java - Copyright © 2011 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.database;
20 import java.util.Collection;
22 import net.pterodactylus.sone.data.Sone;
25 * Interface for Sone’s database.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public interface Database {
32 * Returns the Sone with the given ID, creating a new Sone if a Sone with
33 * the given ID does not exist and {@code create} is {@code true}. When
34 * searching for a Sone with the given IDs, local Sones are preferred.
37 * The ID of the new Sone
39 * {@code true} to create a new Sone if a Sone with the given ID
40 * does not exist, {@code false} to return {@code null} if a Sone
41 * with the given ID does not exist
42 * @return The created Sone
43 * @throws IllegalArgumentException
44 * if {@code id} is {@code null}
45 * @throws DatabaseException
46 * if a database error occurs
48 public Sone getSone(String id, boolean create) throws DatabaseException;
51 * Returns all known Sones.
53 * @return All known Sones
54 * @throws DatabaseException
55 * if a database error occurs
57 public Collection<Sone> getSones() throws DatabaseException;
60 * Returns all known local Sones.
62 * @return All known local Sones
63 * @throws DatabaseException
64 * if a database error occurs
66 public Collection<Sone> getLocalSones() throws DatabaseException;
69 * Returns all known remote Sones.
71 * @return All known remote Sones
72 * @throws DatabaseException
73 * if a database error occurs
75 public Collection<Sone> getRemoteSones() throws DatabaseException;
78 * Returns the local Sone with the given ID, creating it if it doesn’t exist
79 * and {@code create} is {@code true}.
84 * {@code true} to create a Sone if no Sone with the given ID
85 * exists yet, {@code false} to return {@code null}
86 * @return The existing Sone, the created Sone, or {@code null}
87 * @throws DatabaseException
88 * if adatabase error occurs
90 public Sone getLocalSone(String id, boolean create) throws DatabaseException;
93 * Returns the remote Sone with the given ID, creating it if it doesn’t
94 * exist and {@code create} is {@code true}.
99 * {@code true} to create a Sone if no Sone with the given ID
100 * exists yet, {@code false} to return {@code null}
101 * @return The existing Sone, the created Sone, or {@code null}
102 * @throws DatabaseException
103 * if adatabase error occurs
105 public Sone getRemoteSone(String id, boolean create) throws DatabaseException;
108 * Stores the given Sone. The given Sone has to be an object that was
109 * returned by a previous call to {@link #getSone(String, boolean)}.
113 * @throws IllegalArgumentException
114 * if {@code sone} is {@code null}, or the Sone was not
115 * retrieved by a call to {@link #getSone(String, boolean)}
116 * @throws DatabaseException
117 * if a database error occurs
119 public void saveSone(Sone sone) throws DatabaseException;
122 * Removes the given Sone from the database.
126 * @throws DatabaseException
127 * if a database error occurs
129 public void removeSone(Sone sone) throws DatabaseException;
132 * Removes the Sone with the given ID from the database.
135 * The ID of the Sone to remove
136 * @throws DatabaseException
137 * if a database error occurs
139 public void removeSone(String id) throws DatabaseException;