author | František Kučera <franta-hg@frantovo.cz> |
Sun, 09 Oct 2011 01:17:19 +0200 | |
changeset 66 | c04eae2c57df |
parent 64 | 72950b29569e |
child 68 | 6e16e3bee1ca |
permissions | -rw-r--r-- |
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@63 | 20 |
import java.sql.SQLException; |
franta-hg@64 | 21 |
import java.util.Map; |
franta-hg@64 | 22 |
import java.util.concurrent.ConcurrentHashMap; |
franta-hg@63 | 23 |
import org.sonews.storage.Storage; |
franta-hg@63 | 24 |
import org.sonews.storage.StorageBackendException; |
franta-hg@64 | 25 |
import org.sonews.storage.StorageProvider; |
franta-hg@63 | 26 |
|
franta-hg@63 | 27 |
/** |
franta-hg@63 | 28 |
* |
franta-hg@63 | 29 |
* @author František Kučera (frantovo.cz) |
franta-hg@63 | 30 |
*/ |
franta-hg@64 | 31 |
public class DrupalDatabaseProvider implements StorageProvider { |
franta-hg@64 | 32 |
|
franta-hg@64 | 33 |
protected static final Map<Thread, DrupalDatabase> instances = new ConcurrentHashMap<Thread, DrupalDatabase>(); |
franta-hg@64 | 34 |
|
franta-hg@64 | 35 |
@Override |
franta-hg@64 | 36 |
public boolean isSupported(String uri) { |
franta-hg@64 | 37 |
return uri.startsWith("jdbc:mysql") || uri.startsWith("jdbc:postgresql"); |
franta-hg@64 | 38 |
} |
franta-hg@63 | 39 |
|
franta-hg@63 | 40 |
@Override |
franta-hg@63 | 41 |
public Storage storage(Thread thread) |
franta-hg@63 | 42 |
throws StorageBackendException { |
franta-hg@63 | 43 |
try { |
franta-hg@63 | 44 |
if (!instances.containsKey(Thread.currentThread())) { |
franta-hg@63 | 45 |
DrupalDatabase db = new DrupalDatabase(); |
franta-hg@63 | 46 |
db.arise(); |
franta-hg@63 | 47 |
instances.put(Thread.currentThread(), db); |
franta-hg@63 | 48 |
return db; |
franta-hg@63 | 49 |
} else { |
franta-hg@63 | 50 |
return instances.get(Thread.currentThread()); |
franta-hg@63 | 51 |
} |
franta-hg@63 | 52 |
} catch (SQLException ex) { |
franta-hg@63 | 53 |
throw new StorageBackendException(ex); |
franta-hg@63 | 54 |
} |
franta-hg@63 | 55 |
} |
franta-hg@63 | 56 |
} |