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