chris@1: /* chris@1: * SONEWS News Server chris@1: * see AUTHORS for the list of contributors chris@1: * chris@1: * This program is free software: you can redistribute it and/or modify chris@1: * it under the terms of the GNU General Public License as published by chris@1: * the Free Software Foundation, either version 3 of the License, or chris@1: * (at your option) any later version. chris@1: * chris@1: * This program is distributed in the hope that it will be useful, chris@1: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@1: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@1: * GNU General Public License for more details. chris@1: * chris@1: * You should have received a copy of the GNU General Public License chris@1: * along with this program. If not, see . chris@1: */ chris@1: chris@1: package org.sonews.daemon.storage; chris@1: chris@1: import java.sql.SQLException; chris@1: import java.util.List; chris@1: import org.sonews.util.Log; chris@1: import org.sonews.util.Pair; chris@1: chris@1: /** chris@1: * Represents a logical Group within this newsserver. chris@1: * @author Christian Lins chris@1: * @since sonews/0.5.0 chris@1: */ chris@1: public class Group chris@1: { chris@1: chris@1: /** chris@1: * If this flag is set the Group is no real newsgroup but a mailing list chris@1: * mirror. In that case every posting and receiving mails must go through chris@1: * the mailing list gateway. chris@1: */ chris@1: public static final int MAILINGLIST = 0x1; chris@1: chris@1: /** chris@1: * If this flag is set the Group is marked as readonly and the posting chris@1: * is prohibited. This can be useful for groups that are synced only in chris@1: * one direction. chris@1: */ chris@1: public static final int READONLY = 0x2; chris@1: chris@1: /** chris@1: * If this flag is set the Group is marked as deleted and must not occur chris@1: * in any output. The deletion is done lazily by a low priority daemon. chris@1: */ chris@1: public static final int DELETED = 0x128; chris@1: chris@1: private long id = 0; chris@1: private int flags = -1; chris@1: private String name = null; chris@1: chris@1: /** chris@1: * Returns a Group identified by its full name. chris@1: * @param name chris@1: * @return chris@1: */ chris@1: public static Group getByName(final String name) chris@1: { chris@1: try chris@1: { chris@1: return Database.getInstance().getGroup(name); chris@1: } chris@1: catch(SQLException ex) chris@1: { chris@1: ex.printStackTrace(); chris@1: return null; chris@1: } chris@1: } chris@1: chris@1: /** chris@1: * @return List of all groups this server handles. chris@1: */ chris@1: public static List getAll() chris@1: { chris@1: try chris@1: { chris@1: return Database.getInstance().getGroups(); chris@1: } chris@1: catch(SQLException ex) chris@1: { chris@1: Log.msg(ex.getMessage(), false); chris@1: return null; chris@1: } chris@1: } chris@1: chris@1: /** chris@1: * Private constructor. chris@1: * @param name chris@1: * @param id chris@1: */ chris@1: Group(final String name, final long id, final int flags) chris@1: { chris@1: this.id = id; chris@1: this.flags = flags; chris@1: this.name = name; chris@1: } chris@1: chris@1: @Override chris@1: public boolean equals(Object obj) chris@1: { chris@1: if(obj instanceof Group) chris@1: { chris@1: return ((Group)obj).id == this.id; chris@1: } chris@1: else chris@1: { chris@1: return false; chris@1: } chris@1: } chris@1: chris@1: public List> getArticleHeads(final int first, final int last) chris@1: throws SQLException chris@1: { chris@1: return Database.getInstance().getArticleHeads(this, first, last); chris@1: } chris@1: chris@1: public List getArticleNumbers() chris@1: throws SQLException chris@1: { chris@1: return Database.getInstance().getArticleNumbers(id); chris@1: } chris@1: chris@1: public int getFirstArticleNumber() chris@1: throws SQLException chris@1: { chris@1: return Database.getInstance().getFirstArticleNumber(this); chris@1: } chris@1: chris@1: /** chris@1: * Returns the group id. chris@1: */ chris@1: public long getID() chris@1: { chris@1: assert id > 0; chris@1: chris@1: return id; chris@1: } chris@1: chris@1: public boolean isMailingList() chris@1: { chris@1: return (this.flags & MAILINGLIST) != 0; chris@1: } chris@1: chris@1: public int getLastArticleNumber() chris@1: throws SQLException chris@1: { chris@1: return Database.getInstance().getLastArticleNumber(this); chris@1: } chris@1: chris@1: public String getName() chris@1: { chris@1: return name; chris@1: } chris@1: chris@1: /** chris@1: * Performs this.flags |= flag to set a specified flag and updates the data chris@1: * in the Database. chris@1: * @param flag chris@1: */ chris@1: public void setFlag(final int flag) chris@1: { chris@1: this.flags |= flag; chris@1: } chris@1: chris@1: public void setName(final String name) chris@1: { chris@1: this.name = name; chris@1: } chris@1: chris@1: /** chris@1: * @return Number of posted articles in this group. chris@1: * @throws java.sql.SQLException chris@1: */ chris@1: public int getPostingsCount() chris@1: throws SQLException chris@1: { chris@1: return Database.getInstance().getPostingsCount(this.name); chris@1: } chris@1: chris@1: }