src/org/sonews/storage/impl/DrupalDatabaseProvider.java
author František Kučera <franta-hg@frantovo.cz>
Wed, 12 Oct 2011 00:25:14 +0200
changeset 73 1feed5fbf147
parent 68 6e16e3bee1ca
permissions -rw-r--r--
Drupal: vyhození zbytečností.
franta-hg@63
     1
/*
franta-hg@63
     2
 *   SONEWS News Server
franta-hg@63
     3
 *   see AUTHORS for the list of contributors
franta-hg@63
     4
 *
franta-hg@63
     5
 *   This program is free software: you can redistribute it and/or modify
franta-hg@63
     6
 *   it under the terms of the GNU General Public License as published by
franta-hg@63
     7
 *   the Free Software Foundation, either version 3 of the License, or
franta-hg@63
     8
 *   (at your option) any later version.
franta-hg@63
     9
 *
franta-hg@63
    10
 *   This program is distributed in the hope that it will be useful,
franta-hg@63
    11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@63
    12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
franta-hg@63
    13
 *   GNU General Public License for more details.
franta-hg@63
    14
 *
franta-hg@63
    15
 *   You should have received a copy of the GNU General Public License
franta-hg@63
    16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
franta-hg@63
    17
 */
franta-hg@63
    18
package org.sonews.storage.impl;
franta-hg@63
    19
franta-hg@64
    20
import java.util.Map;
franta-hg@64
    21
import java.util.concurrent.ConcurrentHashMap;
franta-hg@63
    22
import org.sonews.storage.Storage;
franta-hg@63
    23
import org.sonews.storage.StorageBackendException;
franta-hg@64
    24
import org.sonews.storage.StorageProvider;
franta-hg@63
    25
franta-hg@63
    26
/**
franta-hg@63
    27
 *
franta-hg@63
    28
 * @author František Kučera (frantovo.cz)
franta-hg@63
    29
 */
franta-hg@64
    30
public class DrupalDatabaseProvider implements StorageProvider {
franta-hg@64
    31
franta-hg@64
    32
	protected static final Map<Thread, DrupalDatabase> instances = new ConcurrentHashMap<Thread, DrupalDatabase>();
franta-hg@64
    33
franta-hg@64
    34
	@Override
franta-hg@64
    35
	public boolean isSupported(String uri) {
franta-hg@64
    36
		return uri.startsWith("jdbc:mysql") || uri.startsWith("jdbc:postgresql");
franta-hg@64
    37
	}
franta-hg@63
    38
franta-hg@63
    39
	@Override
franta-hg@68
    40
	public Storage storage(Thread thread) throws StorageBackendException {
franta-hg@68
    41
		DrupalDatabase db = instances.get(Thread.currentThread());
franta-hg@68
    42
franta-hg@68
    43
		if (db == null) {
franta-hg@68
    44
			db = new DrupalDatabase();
franta-hg@68
    45
			instances.put(Thread.currentThread(), db);
franta-hg@63
    46
		}
franta-hg@68
    47
franta-hg@68
    48
		return db;
franta-hg@63
    49
	}
franta-hg@68
    50
}