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 whether the given Sone is a local Sone.
36 * @return {@code true} if the given Sone is a local Sone, {@code false}
38 * @throws IllegalArgumentException
39 * if {@code sone} is {@code null}
40 * @throws DatabaseException
41 * if a database error occurs
43 public boolean isLocalSone(Sone sone) throws DatabaseException;
46 * Returns whether the given Sone ID belongs to a local Sone.
49 * The Sone ID to check
50 * @return {@code true} if the given Sone ID belongs to a local Sone,
51 * {@code false} otherwise
52 * @throws IllegalArgumentException
53 * if {@code id} is {@code null}
54 * @throws DatabaseException
55 * if a database error occurs
57 public boolean isLocalSone(String id) throws DatabaseException;
60 * Returns whether the given Sone is a remote Sone.
64 * @return {@code true} if the given Sone is a remote Sone, {@code false}
66 * @throws IllegalArgumentException
67 * if {@code sone} is {@code null}
68 * @throws DatabaseException
69 * if a database error occurs
71 public boolean isRemoteSone(Sone sone) throws DatabaseException;
74 * Returns whether the given Sone ID belongs to a remote Sone.
77 * The Sone ID to check
78 * @return {@code true} if the given Sone ID belongs to a remote Sone,
79 * {@code false} otherwise
80 * @throws IllegalArgumentException
81 * if {@code id} is {@code null}
82 * @throws DatabaseException
83 * if a database error occurs
85 public boolean isRemoteSone(String id) throws DatabaseException;
88 * Returns the Sone with the given ID, creating a new Sone if a Sone with
89 * the given ID does not exist and {@code create} is {@code true}. When
90 * searching for a Sone with the given IDs, local Sones are preferred.
93 * The ID of the new Sone
95 * {@code true} to create a new Sone if a Sone with the given ID
96 * does not exist, {@code false} to return {@code null} if a Sone
97 * with the given ID does not exist
98 * @return The created Sone
99 * @throws IllegalArgumentException
100 * if {@code id} is {@code null}
101 * @throws DatabaseException
102 * if a database error occurs
104 public Sone getSone(String id, boolean create) throws DatabaseException;
107 * Returns all known Sones.
109 * @return All known Sones
110 * @throws DatabaseException
111 * if a database error occurs
113 public Collection<Sone> getSones() throws DatabaseException;
116 * Returns all known local Sones.
118 * @return All known local Sones
119 * @throws DatabaseException
120 * if a database error occurs
122 public Collection<Sone> getLocalSones() throws DatabaseException;
125 * Returns all known remote Sones.
127 * @return All known remote Sones
128 * @throws DatabaseException
129 * if a database error occurs
131 public Collection<Sone> getRemoteSones() throws DatabaseException;
134 * Returns the local Sone with the given ID, creating it if it doesn’t exist
135 * and {@code create} is {@code true}.
140 * {@code true} to create a Sone if no Sone with the given ID
141 * exists yet, {@code false} to return {@code null}
142 * @return The existing Sone, the created Sone, or {@code null}
143 * @throws DatabaseException
144 * if adatabase error occurs
146 public Sone getLocalSone(String id, boolean create) throws DatabaseException;
149 * Returns the remote Sone with the given ID, creating it if it doesn’t
150 * exist and {@code create} is {@code true}.
155 * {@code true} to create a Sone if no Sone with the given ID
156 * exists yet, {@code false} to return {@code null}
157 * @return The existing Sone, the created Sone, or {@code null}
158 * @throws DatabaseException
159 * if adatabase error occurs
161 public Sone getRemoteSone(String id, boolean create) throws DatabaseException;
164 * Stores the given Sone. The given Sone has to be an object that was
165 * returned by a previous call to {@link #getSone(String, boolean)}.
169 * @throws IllegalArgumentException
170 * if {@code sone} is {@code null}, or the Sone was not
171 * retrieved by a call to {@link #getSone(String, boolean)}
172 * @throws DatabaseException
173 * if a database error occurs
175 public void saveSone(Sone sone) throws DatabaseException;
178 * Removes the given Sone from the database.
182 * @throws DatabaseException
183 * if a database error occurs
185 public void removeSone(Sone sone) throws DatabaseException;
188 * Removes the Sone with the given ID from the database.
191 * The ID of the Sone to remove
192 * @throws DatabaseException
193 * if a database error occurs
195 public void removeSone(String id) throws DatabaseException;