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@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@68: public Storage storage(Thread thread) throws StorageBackendException {
franta-hg@68: DrupalDatabase db = instances.get(Thread.currentThread());
franta-hg@68:
franta-hg@68: if (db == null) {
franta-hg@68: db = new DrupalDatabase();
franta-hg@68: instances.put(Thread.currentThread(), db);
franta-hg@63: }
franta-hg@68:
franta-hg@68: return db;
franta-hg@63: }
franta-hg@68: }