org.mmbase.storage.implementation.database
Class GenericDataSource

Package class diagram package GenericDataSource
java.lang.Object
  extended by org.mmbase.storage.implementation.database.GenericDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public final class GenericDataSource
extends Object
implements DataSource

This class functions as a DataSource wrapper around the JDBC Module. It is intended for use when MMBase runs outside an application server, or when the server does not (or poorly) support pooled DataSources. It can also be used by older systems that use the JDBC Module and do not want to change their configuration. Note that the JDBC Module will likely be faced out as a module at some point in the future, with code and supporting classes to be moved to this class instead.

Since:
MMBase-1.7
Version:
$Id: GenericDataSource.java 46551 2013-01-23 23:58:54Z michiel $
Author:
Pierre van Rooden, Michiel Meeuwissen

Nested Class Summary
static class GenericDataSource.ConnectionProxy
          Interesting trick to make things compile in both java 1.5 and 1.6
 
Constructor Summary
GenericDataSource(MMBase mmbase)
           
GenericDataSource(MMBase mmbase, File dataDir)
          Constructs a DataSource for accessing the database belonging to the given MMBase module.
 
Method Summary
 Connection getConnection()
           
 Connection getConnection(String userName, String password)
           
 Connection getDirectConnection()
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
 Logger getParentLogger()
           
 boolean isWrapperFor(Class<?> iface)
           
protected  String makeUrl()
          Makes URL which can be used to produce a Conncetion.
 void setLoginTimeout(int seconds)
           Note: currently this code does not actually change the timeout.
 void setLogWriter(PrintWriter out)
           
<T> T
unwrap(Class<T> iface)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericDataSource

GenericDataSource(MMBase mmbase,
                  File dataDir)
            throws StorageInaccessibleException
Constructs a DataSource for accessing the database belonging to the given MMBase module. The MMBase parameter is not currently used, but is included for future expansion

Parameters:
mmbase - the MMBase instance
A - data directory (as a string ending in a /) which may be used in some URL's (most noticeably those of HSQLDB). Can be null if not used.
Throws:
StorageInaccessibleException - if the JDBC module used in creating the DataSource is inaccessible

GenericDataSource

GenericDataSource(MMBase mmbase)
            throws StorageInaccessibleException
Throws:
StorageInaccessibleException
Method Detail

getConnection

public Connection getConnection()
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getDirectConnection

public Connection getDirectConnection()
                               throws SQLException
Throws:
SQLException
Since:
MMBase-1.8

getConnection

public Connection getConnection(String userName,
                                String password)
                         throws SQLException
Specified by:
getConnection in interface DataSource
Throws:
SQLException

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface CommonDataSource

getLogWriter

public PrintWriter getLogWriter()
Specified by:
getLogWriter in interface CommonDataSource

setLoginTimeout

public void setLoginTimeout(int seconds)
Note: currently this code does not actually change the timeout. Login timeout is not implemented by JDBC module

Specified by:
setLoginTimeout in interface CommonDataSource

setLogWriter

public void setLogWriter(PrintWriter out)
Specified by:
setLogWriter in interface CommonDataSource

makeUrl

protected String makeUrl()
Makes URL which can be used to produce a Conncetion. If this is a 'meta' datasource, then 'lookup.xml' will be tried, for a 'meta url'.

Since:
MMBase-1.8

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
Specified by:
isWrapperFor in interface Wrapper

unwrap

public <T> T unwrap(Class<T> iface)
Specified by:
unwrap in interface Wrapper

getParentLogger

public Logger getParentLogger()


MMBase2 Core 2.0-SNAPSHOT - 2013-03-30T06:36