Add some checks to prevent #13 happen.
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.storage;
21 import java.sql.SQLException;
22 import java.util.List;
23 import org.sonews.util.Log;
24 import org.sonews.util.Pair;
27 * Represents a logical Group within this newsserver.
28 * @author Christian Lins
31 // TODO: This class should not be public!
32 public class Group extends Channel
36 private int flags = -1;
37 private String name = null;
40 * @return List of all groups this server handles.
42 public static List<Channel> getAll()
46 return StorageManager.current().getGroups();
48 catch(StorageBackendException ex)
50 Log.get().severe(ex.getMessage());
59 public Group(final String name, final long id, final int flags)
67 public boolean equals(Object obj)
69 if(obj instanceof Group)
71 return ((Group)obj).id == this.id;
79 public Article getArticle(long idx)
80 throws StorageBackendException
82 return StorageManager.current().getArticle(idx, this.id);
85 public List<Pair<Long, ArticleHead>> getArticleHeads(final long first, final long last)
86 throws StorageBackendException
88 return StorageManager.current().getArticleHeads(this, first, last);
91 public List<Long> getArticleNumbers()
92 throws StorageBackendException
94 return StorageManager.current().getArticleNumbers(id);
97 public long getFirstArticleNumber()
98 throws StorageBackendException
100 return StorageManager.current().getFirstArticleNumber(this);
103 public int getFlags()
108 public long getIndexOf(Article art)
109 throws StorageBackendException
111 return StorageManager.current().getArticleIndex(art, this);
115 * Returns the group id.
117 public long getInternalID()
124 public boolean isDeleted()
126 return (this.flags & DELETED) != 0;
129 public boolean isMailingList()
131 return (this.flags & MAILINGLIST) != 0;
134 public boolean isWriteable()
139 public long getLastArticleNumber()
140 throws StorageBackendException
142 return StorageManager.current().getLastArticleNumber(this);
145 public String getName()
151 * Performs this.flags |= flag to set a specified flag and updates the data
152 * in the JDBCDatabase.
155 public void setFlag(final int flag)
160 public void setName(final String name)
166 * @return Number of posted articles in this group.
167 * @throws java.sql.SQLException
169 public long getPostingsCount()
170 throws StorageBackendException
172 return StorageManager.current().getPostingsCount(this.name);
176 * Updates flags and name in the backend.
179 throws StorageBackendException
181 StorageManager.current().update(this);