src/org/sonews/storage/impl/HSQLDB.java
author cli
Wed, 14 Sep 2011 12:54:40 +0200
changeset 60 39f1fadf50a0
parent 48 b78e77619152
permissions -rw-r--r--
Add libcommons-codec-java to Debian dependencies.
cli@42
     1
/*
cli@42
     2
 *   SONEWS News Server
cli@42
     3
 *   see AUTHORS for the list of contributors
cli@42
     4
 *
cli@42
     5
 *   This program is free software: you can redistribute it and/or modify
cli@42
     6
 *   it under the terms of the GNU General Public License as published by
cli@42
     7
 *   the Free Software Foundation, either version 3 of the License, or
cli@42
     8
 *   (at your option) any later version.
cli@42
     9
 *
cli@42
    10
 *   This program is distributed in the hope that it will be useful,
cli@42
    11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
cli@42
    12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cli@42
    13
 *   GNU General Public License for more details.
cli@42
    14
 *
cli@42
    15
 *   You should have received a copy of the GNU General Public License
cli@42
    16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
cli@42
    17
 */
cli@42
    18
package org.sonews.storage.impl;
cli@42
    19
cli@45
    20
import java.sql.SQLException;
cli@48
    21
import org.sonews.storage.Group;
cli@42
    22
import org.sonews.storage.Storage;
cli@42
    23
cli@42
    24
/**
cli@44
    25
 * A specialized JDBCDatabase supporting HSQLDB.
cli@42
    26
 * @author Christian Lins
cli@42
    27
 * @since sonews/1.1
cli@42
    28
 */
cli@44
    29
public class HSQLDB extends JDBCDatabase implements Storage {
cli@42
    30
cli@45
    31
	@Override
cli@45
    32
	protected void prepareAddGroupStatement() throws SQLException {
cli@45
    33
		this.pstmtAddGroup0 = conn.prepareStatement(
cli@45
    34
				"INSERT INTO groups (name, flags, group_id) VALUES (?, ?, IDENTITY())");
cli@45
    35
	}
cli@42
    36
cli@45
    37
	@Override
cli@45
    38
	protected void prepareCountGroupsStatement() throws SQLException {
cli@45
    39
		this.pstmtCountGroups = conn.prepareStatement(
cli@45
    40
				"SELECT Count(group_id) FROM groups WHERE "
cli@48
    41
				+ "BITAND(flags, " + Group.DELETED + ") = 0");
cli@45
    42
	}
cli@45
    43
cli@45
    44
	@Override
cli@45
    45
	protected void prepareGetPostingsCountStatement() throws SQLException {
cli@45
    46
		this.pstmtGetPostingsCount = conn.prepareStatement(
cli@45
    47
				"SELECT Count(*) FROM postings JOIN groups "
cli@45
    48
				+ "ON groups.name = ? GROUP BY groups.name");
cli@45
    49
	}
cli@45
    50
cli@45
    51
	@Override
cli@45
    52
	protected void prepareGetSubscriptionsStatement() throws SQLException {
cli@45
    53
		this.pstmtGetSubscriptions = conn.prepareStatement(
cli@45
    54
				"SELECT * FROM (SELECT feedtype, host, port, peer_id FROM peers JOIN "
cli@45
    55
				+ "peer_subscriptions ON peers.peer_id = peer_subscriptions.peer_id) "
cli@45
    56
				+ "JOIN groups ON group_id = groups.group_id WHERE feedtype = ?");
cli@45
    57
	}
cli@42
    58
}