1.1 --- a/src/org/sonews/storage/impl/HSQLDBProvider.java Tue Jun 07 11:55:22 2011 +0200
1.2 +++ b/src/org/sonews/storage/impl/HSQLDBProvider.java Mon Sep 12 20:24:40 2011 +0200
1.3 @@ -17,6 +17,9 @@
1.4 */
1.5 package org.sonews.storage.impl;
1.6
1.7 +import java.sql.SQLException;
1.8 +import java.util.Map;
1.9 +import java.util.concurrent.ConcurrentHashMap;
1.10 import org.sonews.storage.Storage;
1.11 import org.sonews.storage.StorageBackendException;
1.12 import org.sonews.storage.StorageProvider;
1.13 @@ -27,13 +30,28 @@
1.14 * @since sonews/1.1
1.15 */
1.16 public class HSQLDBProvider implements StorageProvider {
1.17 + protected static final Map<Thread, HSQLDB> instances =
1.18 + new ConcurrentHashMap<Thread, HSQLDB>();
1.19
1.20 + @Override
1.21 public boolean isSupported(String uri) {
1.22 return uri.startsWith("jdbc:hsqldb");
1.23 }
1.24
1.25 + @Override
1.26 public Storage storage(Thread thread) throws StorageBackendException {
1.27 - throw new UnsupportedOperationException("Not supported yet.");
1.28 + try {
1.29 + if (!instances.containsKey(Thread.currentThread())) {
1.30 + HSQLDB db = new HSQLDB();
1.31 + db.arise();
1.32 + instances.put(Thread.currentThread(), db);
1.33 + return db;
1.34 + } else {
1.35 + return instances.get(Thread.currentThread());
1.36 + }
1.37 + } catch (SQLException ex) {
1.38 + throw new StorageBackendException(ex);
1.39 + }
1.40 }
1.41
1.42 }