1.1 --- a/org/sonews/storage/Group.java Sun Aug 29 17:04:25 2010 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,184 +0,0 @@
1.4 -/*
1.5 - * SONEWS News Server
1.6 - * see AUTHORS for the list of contributors
1.7 - *
1.8 - * This program is free software: you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License as published by
1.10 - * the Free Software Foundation, either version 3 of the License, or
1.11 - * (at your option) any later version.
1.12 - *
1.13 - * This program is distributed in the hope that it will be useful,
1.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.16 - * GNU General Public License for more details.
1.17 - *
1.18 - * You should have received a copy of the GNU General Public License
1.19 - * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.20 - */
1.21 -
1.22 -package org.sonews.storage;
1.23 -
1.24 -import java.sql.SQLException;
1.25 -import java.util.List;
1.26 -import org.sonews.util.Log;
1.27 -import org.sonews.util.Pair;
1.28 -
1.29 -/**
1.30 - * Represents a logical Group within this newsserver.
1.31 - * @author Christian Lins
1.32 - * @since sonews/0.5.0
1.33 - */
1.34 -// TODO: This class should not be public!
1.35 -public class Group extends Channel
1.36 -{
1.37 -
1.38 - private long id = 0;
1.39 - private int flags = -1;
1.40 - private String name = null;
1.41 -
1.42 - /**
1.43 - * @return List of all groups this server handles.
1.44 - */
1.45 - public static List<Channel> getAll()
1.46 - {
1.47 - try
1.48 - {
1.49 - return StorageManager.current().getGroups();
1.50 - }
1.51 - catch(StorageBackendException ex)
1.52 - {
1.53 - Log.get().severe(ex.getMessage());
1.54 - return null;
1.55 - }
1.56 - }
1.57 -
1.58 - /**
1.59 - * @param name
1.60 - * @param id
1.61 - */
1.62 - public Group(final String name, final long id, final int flags)
1.63 - {
1.64 - this.id = id;
1.65 - this.flags = flags;
1.66 - this.name = name;
1.67 - }
1.68 -
1.69 - @Override
1.70 - public boolean equals(Object obj)
1.71 - {
1.72 - if(obj instanceof Group)
1.73 - {
1.74 - return ((Group)obj).id == this.id;
1.75 - }
1.76 - else
1.77 - {
1.78 - return false;
1.79 - }
1.80 - }
1.81 -
1.82 - public Article getArticle(long idx)
1.83 - throws StorageBackendException
1.84 - {
1.85 - return StorageManager.current().getArticle(idx, this.id);
1.86 - }
1.87 -
1.88 - public List<Pair<Long, ArticleHead>> getArticleHeads(final long first, final long last)
1.89 - throws StorageBackendException
1.90 - {
1.91 - return StorageManager.current().getArticleHeads(this, first, last);
1.92 - }
1.93 -
1.94 - public List<Long> getArticleNumbers()
1.95 - throws StorageBackendException
1.96 - {
1.97 - return StorageManager.current().getArticleNumbers(id);
1.98 - }
1.99 -
1.100 - public long getFirstArticleNumber()
1.101 - throws StorageBackendException
1.102 - {
1.103 - return StorageManager.current().getFirstArticleNumber(this);
1.104 - }
1.105 -
1.106 - public int getFlags()
1.107 - {
1.108 - return this.flags;
1.109 - }
1.110 -
1.111 - public long getIndexOf(Article art)
1.112 - throws StorageBackendException
1.113 - {
1.114 - return StorageManager.current().getArticleIndex(art, this);
1.115 - }
1.116 -
1.117 - /**
1.118 - * Returns the group id.
1.119 - */
1.120 - public long getInternalID()
1.121 - {
1.122 - assert id > 0;
1.123 -
1.124 - return id;
1.125 - }
1.126 -
1.127 - public boolean isDeleted()
1.128 - {
1.129 - return (this.flags & DELETED) != 0;
1.130 - }
1.131 -
1.132 - public boolean isMailingList()
1.133 - {
1.134 - return (this.flags & MAILINGLIST) != 0;
1.135 - }
1.136 -
1.137 - public boolean isWriteable()
1.138 - {
1.139 - return true;
1.140 - }
1.141 -
1.142 - public long getLastArticleNumber()
1.143 - throws StorageBackendException
1.144 - {
1.145 - return StorageManager.current().getLastArticleNumber(this);
1.146 - }
1.147 -
1.148 - public String getName()
1.149 - {
1.150 - return name;
1.151 - }
1.152 -
1.153 - /**
1.154 - * Performs this.flags |= flag to set a specified flag and updates the data
1.155 - * in the JDBCDatabase.
1.156 - * @param flag
1.157 - */
1.158 - public void setFlag(final int flag)
1.159 - {
1.160 - this.flags |= flag;
1.161 - }
1.162 -
1.163 - public void setName(final String name)
1.164 - {
1.165 - this.name = name;
1.166 - }
1.167 -
1.168 - /**
1.169 - * @return Number of posted articles in this group.
1.170 - * @throws java.sql.SQLException
1.171 - */
1.172 - public long getPostingsCount()
1.173 - throws StorageBackendException
1.174 - {
1.175 - return StorageManager.current().getPostingsCount(this.name);
1.176 - }
1.177 -
1.178 - /**
1.179 - * Updates flags and name in the backend.
1.180 - */
1.181 - public void update()
1.182 - throws StorageBackendException
1.183 - {
1.184 - StorageManager.current().update(this);
1.185 - }
1.186 -
1.187 -}