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