src/org/sonews/storage/Group.java
changeset 37 74139325d305
parent 35 ed84c8bdd87b
child 42 7f84f4de2893
     1.1 --- a/src/org/sonews/storage/Group.java	Sun Aug 29 17:43:58 2010 +0200
     1.2 +++ b/src/org/sonews/storage/Group.java	Sun Aug 29 18:17:37 2010 +0200
     1.3 @@ -31,154 +31,147 @@
     1.4  // TODO: This class should not be public!
     1.5  public class Group extends Channel
     1.6  {
     1.7 -  
     1.8 -  private long   id     = 0;
     1.9 -  private int    flags  = -1;
    1.10 -  private String name   = null;
    1.11  
    1.12 -  /**
    1.13 -   * @return List of all groups this server handles.
    1.14 -   */
    1.15 -  public static List<Channel> getAll()
    1.16 -  {
    1.17 -    try
    1.18 -    {
    1.19 -      return StorageManager.current().getGroups();
    1.20 -    }
    1.21 -    catch(StorageBackendException ex)
    1.22 -    {
    1.23 -      Log.get().severe(ex.getMessage());
    1.24 -      return null;
    1.25 -    }
    1.26 -  }
    1.27 -  
    1.28 -  /**
    1.29 -   * @param name
    1.30 -   * @param id
    1.31 -   */
    1.32 -  public Group(final String name, final long id, final int flags)
    1.33 -  {
    1.34 -    this.id    = id;
    1.35 -    this.flags = flags;
    1.36 -    this.name  = name;
    1.37 -  }
    1.38 +	private long id = 0;
    1.39 +	private int flags = -1;
    1.40 +	private String name = null;
    1.41  
    1.42 -  @Override
    1.43 -  public boolean equals(Object obj)
    1.44 -  {
    1.45 -    if(obj instanceof Group)
    1.46 -    {
    1.47 -      return ((Group)obj).id == this.id;
    1.48 -    }
    1.49 -    else
    1.50 -    {
    1.51 -      return false;
    1.52 -    }
    1.53 -  }
    1.54 +	/**
    1.55 +	 * @return List of all groups this server handles.
    1.56 +	 */
    1.57 +	public static List<Channel> getAll()
    1.58 +	{
    1.59 +		try {
    1.60 +			return StorageManager.current().getGroups();
    1.61 +		} catch (StorageBackendException ex) {
    1.62 +			Log.get().severe(ex.getMessage());
    1.63 +			return null;
    1.64 +		}
    1.65 +	}
    1.66  
    1.67 -  public Article getArticle(long idx)
    1.68 -    throws StorageBackendException
    1.69 -  {
    1.70 -    return StorageManager.current().getArticle(idx, this.id);
    1.71 -  }
    1.72 +	/**
    1.73 +	 * @param name
    1.74 +	 * @param id
    1.75 +	 */
    1.76 +	public Group(final String name, final long id, final int flags)
    1.77 +	{
    1.78 +		this.id = id;
    1.79 +		this.flags = flags;
    1.80 +		this.name = name;
    1.81 +	}
    1.82  
    1.83 -  public List<Pair<Long, ArticleHead>> getArticleHeads(final long first, final long last)
    1.84 -    throws StorageBackendException
    1.85 -  {
    1.86 -    return StorageManager.current().getArticleHeads(this, first, last);
    1.87 -  }
    1.88 -  
    1.89 -  public List<Long> getArticleNumbers()
    1.90 -    throws StorageBackendException
    1.91 -  {
    1.92 -    return StorageManager.current().getArticleNumbers(id);
    1.93 -  }
    1.94 +	@Override
    1.95 +	public boolean equals(Object obj)
    1.96 +	{
    1.97 +		if (obj instanceof Group) {
    1.98 +			return ((Group) obj).id == this.id;
    1.99 +		} else {
   1.100 +			return false;
   1.101 +		}
   1.102 +	}
   1.103  
   1.104 -  public long getFirstArticleNumber()
   1.105 -    throws StorageBackendException
   1.106 -  {
   1.107 -    return StorageManager.current().getFirstArticleNumber(this);
   1.108 -  }
   1.109 +	public Article getArticle(long idx)
   1.110 +		throws StorageBackendException
   1.111 +	{
   1.112 +		return StorageManager.current().getArticle(idx, this.id);
   1.113 +	}
   1.114  
   1.115 -  public int getFlags()
   1.116 -  {
   1.117 -    return this.flags;
   1.118 -  }
   1.119 +	public List<Pair<Long, ArticleHead>> getArticleHeads(final long first, final long last)
   1.120 +		throws StorageBackendException
   1.121 +	{
   1.122 +		return StorageManager.current().getArticleHeads(this, first, last);
   1.123 +	}
   1.124  
   1.125 -  public long getIndexOf(Article art)
   1.126 -    throws StorageBackendException
   1.127 -  {
   1.128 -    return StorageManager.current().getArticleIndex(art, this);
   1.129 -  }
   1.130 +	public List<Long> getArticleNumbers()
   1.131 +		throws StorageBackendException
   1.132 +	{
   1.133 +		return StorageManager.current().getArticleNumbers(id);
   1.134 +	}
   1.135  
   1.136 -  /**
   1.137 -   * Returns the group id.
   1.138 -   */
   1.139 -  public long getInternalID()
   1.140 -  {
   1.141 -    assert id > 0;
   1.142 +	public long getFirstArticleNumber()
   1.143 +		throws StorageBackendException
   1.144 +	{
   1.145 +		return StorageManager.current().getFirstArticleNumber(this);
   1.146 +	}
   1.147  
   1.148 -    return id;
   1.149 -  }
   1.150 +	public int getFlags()
   1.151 +	{
   1.152 +		return this.flags;
   1.153 +	}
   1.154  
   1.155 -  public boolean isDeleted()
   1.156 -  {
   1.157 -    return (this.flags & DELETED) != 0;
   1.158 -  }
   1.159 +	public long getIndexOf(Article art)
   1.160 +		throws StorageBackendException
   1.161 +	{
   1.162 +		return StorageManager.current().getArticleIndex(art, this);
   1.163 +	}
   1.164  
   1.165 -  public boolean isMailingList()
   1.166 -  {
   1.167 -    return (this.flags & MAILINGLIST) != 0;
   1.168 -  }
   1.169 +	/**
   1.170 +	 * Returns the group id.
   1.171 +	 */
   1.172 +	public long getInternalID()
   1.173 +	{
   1.174 +		assert id > 0;
   1.175  
   1.176 -  public boolean isWriteable()
   1.177 -  {
   1.178 -    return true;
   1.179 -  }
   1.180 +		return id;
   1.181 +	}
   1.182  
   1.183 -  public long getLastArticleNumber()
   1.184 -    throws StorageBackendException
   1.185 -  {
   1.186 -    return StorageManager.current().getLastArticleNumber(this);
   1.187 -  }
   1.188 +	public boolean isDeleted()
   1.189 +	{
   1.190 +		return (this.flags & DELETED) != 0;
   1.191 +	}
   1.192  
   1.193 -  public String getName()
   1.194 -  {
   1.195 -    return name;
   1.196 -  }
   1.197 +	public boolean isMailingList()
   1.198 +	{
   1.199 +		return (this.flags & MAILINGLIST) != 0;
   1.200 +	}
   1.201  
   1.202 -  /**
   1.203 -   * Performs this.flags |= flag to set a specified flag and updates the data
   1.204 -   * in the JDBCDatabase.
   1.205 -   * @param flag
   1.206 -   */
   1.207 -  public void setFlag(final int flag)
   1.208 -  {
   1.209 -    this.flags |= flag;
   1.210 -  }
   1.211 +	public boolean isWriteable()
   1.212 +	{
   1.213 +		return true;
   1.214 +	}
   1.215  
   1.216 -  public void setName(final String name)
   1.217 -  {
   1.218 -    this.name = name;
   1.219 -  }
   1.220 +	public long getLastArticleNumber()
   1.221 +		throws StorageBackendException
   1.222 +	{
   1.223 +		return StorageManager.current().getLastArticleNumber(this);
   1.224 +	}
   1.225  
   1.226 -  /**
   1.227 -   * @return Number of posted articles in this group.
   1.228 -   * @throws java.sql.SQLException
   1.229 -   */
   1.230 -  public long getPostingsCount()
   1.231 -    throws StorageBackendException
   1.232 -  {
   1.233 -    return StorageManager.current().getPostingsCount(this.name);
   1.234 -  }
   1.235 +	public String getName()
   1.236 +	{
   1.237 +		return name;
   1.238 +	}
   1.239  
   1.240 -  /**
   1.241 -   * Updates flags and name in the backend.
   1.242 -   */
   1.243 -  public void update()
   1.244 -    throws StorageBackendException
   1.245 -  {
   1.246 -    StorageManager.current().update(this);
   1.247 -  }
   1.248 +	/**
   1.249 +	 * Performs this.flags |= flag to set a specified flag and updates the data
   1.250 +	 * in the JDBCDatabase.
   1.251 +	 * @param flag
   1.252 +	 */
   1.253 +	public void setFlag(final int flag)
   1.254 +	{
   1.255 +		this.flags |= flag;
   1.256 +	}
   1.257  
   1.258 +	public void setName(final String name)
   1.259 +	{
   1.260 +		this.name = name;
   1.261 +	}
   1.262 +
   1.263 +	/**
   1.264 +	 * @return Number of posted articles in this group.
   1.265 +	 * @throws java.sql.SQLException
   1.266 +	 */
   1.267 +	public long getPostingsCount()
   1.268 +		throws StorageBackendException
   1.269 +	{
   1.270 +		return StorageManager.current().getPostingsCount(this.name);
   1.271 +	}
   1.272 +
   1.273 +	/**
   1.274 +	 * Updates flags and name in the backend.
   1.275 +	 */
   1.276 +	public void update()
   1.277 +		throws StorageBackendException
   1.278 +	{
   1.279 +		StorageManager.current().update(this);
   1.280 +	}
   1.281  }