com.j256.ormlite.support
Class SimpleDataSource

java.lang.Object
  extended by com.j256.ormlite.support.SimpleDataSource
All Implemented Interfaces:
Wrapper, CommonDataSource, DataSource

public class SimpleDataSource
extends Object
implements DataSource

Implementation of the DataSource interface that supports what is needed by ORMLite. This is not thread-safe nor synchronized. For multi-threaded, high-performance data sources, see Apache DBCP, CP30, or BoneCP.

NOTE: If you are using the Spring type wiring in Java, initialize() should be called after all of the set methods. In Spring XML, init-method="initialize" should be used.

Author:
graywatson

Constructor Summary
SimpleDataSource()
          Constructor for Spring type wiring if you are using the set methods.
SimpleDataSource(String url)
          Create a data source for a particular database URL.
SimpleDataSource(String url, String username, String password)
          Create a data source for a particular database URL with username and password permissions.
 
Method Summary
 void close()
          Close any connections opened by the data source.
 void destroy()
          Cleanup method to close any open connections and do other cleanups.
 Connection getConnection()
           
 Connection getConnection(String username, String password)
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
 String getUrl()
           
 void initialize()
          If you are using the Spring type wiring, this should be called after all of the set methods.
 boolean isWrapperFor(Class<?> iface)
          NOTE: this is part of the Java6 JDK definition for DataSource.
 void setLoginTimeout(int loginTimeoutSecs)
           
 void setLogWriter(PrintWriter printWriter)
           
 void setPassword(String password)
           
 void setUrl(String url)
           
 void setUsername(String username)
           
<T> T
unwrap(Class<T> iface)
          NOTE: this is part of the Java6 JDK definition for DataSource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDataSource

public SimpleDataSource()
Constructor for Spring type wiring if you are using the set methods.


SimpleDataSource

public SimpleDataSource(String url)
Create a data source for a particular database URL.


SimpleDataSource

public SimpleDataSource(String url,
                        String username,
                        String password)
Create a data source for a particular database URL with username and password permissions.

Method Detail

initialize

public void initialize()
If you are using the Spring type wiring, this should be called after all of the set methods.


destroy

public void destroy()
             throws SQLException
Cleanup method to close any open connections and do other cleanups.

Throws:
SQLException

close

public void close()
           throws SQLException
Close any connections opened by the data source.

Throws:
SQLException

getUrl

public String getUrl()

setUrl

public void setUrl(String url)

getConnection

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

getConnection

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

getLogWriter

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

setLogWriter

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

getLoginTimeout

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

setLoginTimeout

public void setLoginTimeout(int loginTimeoutSecs)
Specified by:
setLoginTimeout in interface CommonDataSource

setUsername

public void setUsername(String username)

setPassword

public void setPassword(String password)

isWrapperFor

public boolean isWrapperFor(Class<?> iface)
                     throws SQLException
NOTE: this is part of the Java6 JDK definition for DataSource.

Specified by:
isWrapperFor in interface Wrapper
Throws:
SQLException

unwrap

public <T> T unwrap(Class<T> iface)
         throws SQLException
NOTE: this is part of the Java6 JDK definition for DataSource.

Specified by:
unwrap in interface Wrapper
Throws:
SQLException


Copyright © 2010. All Rights Reserved.