cli@42: /*
cli@42: * SONEWS News Server
cli@42: * see AUTHORS for the list of contributors
cli@42: *
cli@42: * This program is free software: you can redistribute it and/or modify
cli@42: * it under the terms of the GNU General Public License as published by
cli@42: * the Free Software Foundation, either version 3 of the License, or
cli@42: * (at your option) any later version.
cli@42: *
cli@42: * This program is distributed in the hope that it will be useful,
cli@42: * but WITHOUT ANY WARRANTY; without even the implied warranty of
cli@42: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cli@42: * GNU General Public License for more details.
cli@42: *
cli@42: * You should have received a copy of the GNU General Public License
cli@42: * along with this program. If not, see .
cli@42: */
cli@42: package org.sonews.storage.impl;
cli@42:
cli@45: import java.sql.SQLException;
cli@45: import java.util.Map;
cli@45: import java.util.concurrent.ConcurrentHashMap;
cli@42: import org.sonews.storage.Storage;
cli@42: import org.sonews.storage.StorageBackendException;
cli@42: import org.sonews.storage.StorageProvider;
cli@42:
cli@42: /**
cli@42: *
cli@42: * @author Christian Lins
cli@42: * @since sonews/1.1
cli@42: */
cli@42: public class HSQLDBProvider implements StorageProvider {
cli@45: protected static final Map instances =
cli@45: new ConcurrentHashMap();
cli@42:
cli@45: @Override
cli@42: public boolean isSupported(String uri) {
cli@44: return uri.startsWith("jdbc:hsqldb");
cli@42: }
cli@42:
cli@45: @Override
cli@42: public Storage storage(Thread thread) throws StorageBackendException {
cli@45: try {
cli@45: if (!instances.containsKey(Thread.currentThread())) {
cli@45: HSQLDB db = new HSQLDB();
cli@45: db.arise();
cli@45: instances.put(Thread.currentThread(), db);
cli@45: return db;
cli@45: } else {
cli@45: return instances.get(Thread.currentThread());
cli@45: }
cli@45: } catch (SQLException ex) {
cli@45: throw new StorageBackendException(ex);
cli@45: }
cli@42: }
cli@42:
cli@42: }