chris@0: /* chris@0: * StarOffice News Server chris@0: * see AUTHORS for the list of contributors chris@0: * chris@0: * This program is free software: you can redistribute it and/or modify chris@0: * it under the terms of the GNU General Public License as published by chris@0: * the Free Software Foundation, either version 3 of the License, or chris@0: * (at your option) any later version. chris@0: * chris@0: * This program is distributed in the hope that it will be useful, chris@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@0: * GNU General Public License for more details. chris@0: * chris@0: * You should have received a copy of the GNU General Public License chris@0: * along with this program. If not, see . chris@0: */ chris@0: chris@0: package com.so.news.storage; chris@0: chris@0: import java.sql.ResultSet; chris@0: import java.sql.SQLException; chris@0: import java.util.ArrayList; chris@0: import java.util.List; chris@0: import com.so.news.Debug; chris@0: chris@0: /** chris@0: * Represents a logical Group within this newsserver. chris@0: * @author Christian Lins chris@0: */ chris@0: public class Group chris@0: { chris@0: private long id; chris@0: private String name; chris@0: chris@0: /** chris@0: * Private constructor. chris@0: * @param name chris@0: * @param id chris@0: */ chris@0: Group(String name, long id) chris@0: { chris@0: this.id = id; chris@0: this.name = name; chris@0: } chris@0: chris@0: /** chris@0: * Returns a Group identified by its full name. chris@0: * @param name chris@0: * @return chris@0: */ chris@0: public static Group getByName(String name) chris@0: { chris@0: try chris@0: { chris@0: return Database.getInstance().getGroup(name); chris@0: } chris@0: catch(SQLException ex) chris@0: { chris@0: System.err.println(ex.getLocalizedMessage()); chris@0: ex.printStackTrace(Debug.getInstance().getStream()); chris@0: return null; chris@0: } chris@0: } chris@0: chris@0: /** chris@0: * Returns a list of all groups this server handles. chris@0: * @return chris@0: */ chris@0: public static ArrayList getAll() chris@0: { chris@0: ArrayList buffer = new ArrayList(); chris@0: chris@0: try chris@0: { chris@0: ResultSet rs = Database.getInstance().getGroups(); chris@0: chris@0: while(rs.next()) chris@0: { chris@0: String name = rs.getString("name"); chris@0: long id = rs.getLong("group_id"); chris@0: chris@0: Group group = new Group(name, id); chris@0: buffer.add(group); chris@0: } chris@0: } chris@0: catch(SQLException ex) chris@0: { chris@0: ex.printStackTrace(Debug.getInstance().getStream()); chris@0: System.err.println(ex.getLocalizedMessage()); chris@0: } chris@0: chris@0: return buffer; chris@0: } chris@0: chris@0: public List
getAllArticles() chris@0: throws SQLException chris@0: { chris@0: return getAllArticles(getFirstArticle(), getLastArticle()); chris@0: } chris@0: chris@0: public List
getAllArticles(int first, int last) chris@0: { chris@0: return null; chris@0: } chris@0: chris@0: public int getFirstArticle() chris@0: throws SQLException chris@0: { chris@0: return Database.getInstance().getFirstArticleNumber(this); chris@0: } chris@0: chris@0: public long getID() chris@0: { chris@0: return id; chris@0: } chris@0: chris@0: public int getLastArticle() chris@0: throws SQLException chris@0: { chris@0: return Database.getInstance().getLastArticleNumber(this); chris@0: } chris@0: chris@0: public String getName() chris@0: { chris@0: return name; chris@0: } chris@0: chris@0: public void setName(String name) chris@0: { chris@0: this.name = name; chris@0: } chris@0: chris@0: public int getEstimatedArticleCount() chris@0: throws SQLException chris@0: { chris@0: if (getLastArticle() < getFirstArticle()) chris@0: return 0; chris@0: return getLastArticle() - getFirstArticle() + 1; chris@0: } chris@0: chris@0: }