org/sonews/storage/impl/JDBCDatabaseProvider.java
author cli
Wed Aug 26 17:04:04 2009 +0200 (2009-08-26)
changeset 24 2ff819fa5be1
child 30 146b3275b792
permissions -rw-r--r--
Some changes to storage interface.
chris@3
     1
/*
chris@3
     2
 *   SONEWS News Server
chris@3
     3
 *   see AUTHORS for the list of contributors
chris@3
     4
 *
chris@3
     5
 *   This program is free software: you can redistribute it and/or modify
chris@3
     6
 *   it under the terms of the GNU General Public License as published by
chris@3
     7
 *   the Free Software Foundation, either version 3 of the License, or
chris@3
     8
 *   (at your option) any later version.
chris@3
     9
 *
chris@3
    10
 *   This program is distributed in the hope that it will be useful,
chris@3
    11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@3
    12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
chris@3
    13
 *   GNU General Public License for more details.
chris@3
    14
 *
chris@3
    15
 *   You should have received a copy of the GNU General Public License
chris@3
    16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
chris@3
    17
 */
chris@3
    18
chris@3
    19
package org.sonews.storage.impl;
chris@3
    20
chris@3
    21
import org.sonews.storage.*;
chris@3
    22
import java.sql.SQLException;
chris@3
    23
import java.util.Map;
chris@3
    24
import java.util.concurrent.ConcurrentHashMap;
chris@3
    25
chris@3
    26
/**
chris@3
    27
 *
chris@3
    28
 * @author Christian Lins
chris@3
    29
 * @since sonews/1.0
chris@3
    30
 */
chris@3
    31
public class JDBCDatabaseProvider implements StorageProvider
chris@3
    32
{
chris@3
    33
chris@3
    34
  protected static final Map<Thread, JDBCDatabase> instances
chris@3
    35
    = new ConcurrentHashMap<Thread, JDBCDatabase>();
chris@3
    36
chris@3
    37
  @Override
chris@3
    38
  public boolean isSupported(String uri)
chris@3
    39
  {
chris@3
    40
    throw new UnsupportedOperationException("Not supported yet.");
chris@3
    41
  }
chris@3
    42
chris@3
    43
  @Override
chris@3
    44
  public Storage storage(Thread thread)
chris@3
    45
    throws StorageBackendException
chris@3
    46
  {
chris@3
    47
    try
chris@3
    48
    {
chris@3
    49
    if(!instances.containsKey(Thread.currentThread()))
chris@3
    50
    {
chris@3
    51
      JDBCDatabase db = new JDBCDatabase();
chris@3
    52
      db.arise();
chris@3
    53
      instances.put(Thread.currentThread(), db);
chris@3
    54
      return db;
chris@3
    55
    }
chris@3
    56
    else
chris@3
    57
    {
chris@3
    58
      return instances.get(Thread.currentThread());
chris@3
    59
    }
chris@3
    60
    }
chris@3
    61
    catch(SQLException ex)
chris@3
    62
    {
chris@3
    63
      throw new StorageBackendException(ex);
chris@3
    64
    }
chris@3
    65
  }
chris@3
    66
chris@3
    67
}