Merge branch 'next' into new-database-38
[Sone.git] / src / main / java / net / pterodactylus / sone / database / Database.java
1 /*
2  * Sone - Database.java - Copyright © 2011 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.database;
19
20 import java.util.Collection;
21
22 import net.pterodactylus.sone.data.Sone;
23
24 /**
25  * Interface for Sone’s database.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28  */
29 public interface Database {
30
31         /**
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.
35          *
36          * @param id
37          *            The ID of the new Sone
38          * @param create
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
47          */
48         public Sone getSone(String id, boolean create) throws DatabaseException;
49
50         /**
51          * Returns all known Sones.
52          *
53          * @return All known Sones
54          * @throws DatabaseException
55          *             if a database error occurs
56          */
57         public Collection<Sone> getSones() throws DatabaseException;
58
59         /**
60          * Returns all known local Sones.
61          *
62          * @return All known local Sones
63          * @throws DatabaseException
64          *             if a database error occurs
65          */
66         public Collection<Sone> getLocalSones() throws DatabaseException;
67
68         /**
69          * Returns all known remote Sones.
70          *
71          * @return All known remote Sones
72          * @throws DatabaseException
73          *             if a database error occurs
74          */
75         public Collection<Sone> getRemoteSones() throws DatabaseException;
76
77         /**
78          * Returns the local Sone with the given ID, creating it if it doesn’t exist
79          * and {@code create} is {@code true}.
80          *
81          * @param id
82          *            The ID of the Sone
83          * @param create
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
89          */
90         public Sone getLocalSone(String id, boolean create) throws DatabaseException;
91
92         /**
93          * Returns the remote Sone with the given ID, creating it if it doesn’t
94          * exist and {@code create} is {@code true}.
95          *
96          * @param id
97          *            The ID of the Sone
98          * @param create
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
104          */
105         public Sone getRemoteSone(String id, boolean create) throws DatabaseException;
106
107         /**
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)}.
110          *
111          * @param sone
112          *            The Sone to store
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
118          */
119         public void saveSone(Sone sone) throws DatabaseException;
120
121         /**
122          * Removes the given Sone from the database.
123          *
124          * @param sone
125          *            The Sone to remove
126          * @throws DatabaseException
127          *             if a database error occurs
128          */
129         public void removeSone(Sone sone) throws DatabaseException;
130
131         /**
132          * Removes the Sone with the given ID from the database.
133          *
134          * @param id
135          *            The ID of the Sone to remove
136          * @throws DatabaseException
137          *             if a database error occurs
138          */
139         public void removeSone(String id) throws DatabaseException;
140
141 }