Initial import.
2 * StarOffice News Server
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 com.so.news.storage;
21 import java.sql.ResultSet;
22 import java.sql.SQLException;
23 import java.util.ArrayList;
24 import java.util.List;
25 import com.so.news.Debug;
28 * Represents a logical Group within this newsserver.
29 * @author Christian Lins
37 * Private constructor.
41 Group(String name, long id)
48 * Returns a Group identified by its full name.
52 public static Group getByName(String name)
56 return Database.getInstance().getGroup(name);
58 catch(SQLException ex)
60 System.err.println(ex.getLocalizedMessage());
61 ex.printStackTrace(Debug.getInstance().getStream());
67 * Returns a list of all groups this server handles.
70 public static ArrayList<Group> getAll()
72 ArrayList<Group> buffer = new ArrayList<Group>();
76 ResultSet rs = Database.getInstance().getGroups();
80 String name = rs.getString("name");
81 long id = rs.getLong("group_id");
83 Group group = new Group(name, id);
87 catch(SQLException ex)
89 ex.printStackTrace(Debug.getInstance().getStream());
90 System.err.println(ex.getLocalizedMessage());
96 public List<Article> getAllArticles()
99 return getAllArticles(getFirstArticle(), getLastArticle());
102 public List<Article> getAllArticles(int first, int last)
107 public int getFirstArticle()
110 return Database.getInstance().getFirstArticleNumber(this);
118 public int getLastArticle()
121 return Database.getInstance().getLastArticleNumber(this);
124 public String getName()
129 public void setName(String name)
134 public int getEstimatedArticleCount()
137 if (getLastArticle() < getFirstArticle())
139 return getLastArticle() - getFirstArticle() + 1;