com.j256.ormlite.jdbc
Class DataSourceConnectionSource

java.lang.Object
  extended by com.j256.ormlite.support.BaseConnectionSource
      extended by com.j256.ormlite.jdbc.DataSourceConnectionSource
All Implemented Interfaces:
com.j256.ormlite.support.ConnectionSource

public class DataSourceConnectionSource
extends com.j256.ormlite.support.BaseConnectionSource
implements com.j256.ormlite.support.ConnectionSource

Wrapper around a DataSource that supports our ConnectionSource interface. This allows you to wrap other 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

Field Summary
 
Fields inherited from class com.j256.ormlite.support.BaseConnectionSource
usedSpecialConnection
 
Constructor Summary
DataSourceConnectionSource()
          Constructor for Spring type wiring if you are using the set methods.
DataSourceConnectionSource(DataSource dataSource, com.j256.ormlite.db.DatabaseType databaseType)
          Create a data source wrapper for a DataSource.
DataSourceConnectionSource(DataSource dataSource, String databaseUrl)
          Create a data source wrapper for a DataSource.
 
Method Summary
 void clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
           
 void close()
          This typically closes the connection source but because there is not a close() method on the DataSource (grrrr), this close method does _nothing_.
 com.j256.ormlite.db.DatabaseType getDatabaseType()
           
 com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection()
           
 com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection(String username, String password)
           
 com.j256.ormlite.support.DatabaseConnection getReadWriteConnection()
           
 com.j256.ormlite.support.DatabaseConnection getReadWriteConnection(String username, String password)
           
 void initialize()
          Initialize the class after the setters have been called.
 boolean isOpen()
          Unfortunately we cannot tell if the related data source has been closed so this just returns true.
 void releaseConnection(com.j256.ormlite.support.DatabaseConnection connection)
           
 boolean saveSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
           
 void setDatabaseType(com.j256.ormlite.db.DatabaseType databaseType)
           
 void setDatabaseUrl(String databaseUrl)
           
 void setDataSource(DataSource dataSource)
           
 void setUsesTransactions(boolean usesTransactions)
           
 
Methods inherited from class com.j256.ormlite.support.BaseConnectionSource
clearSpecial, getSavedConnection, getSpecialConnection, isSavedConnection, saveSpecial
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.j256.ormlite.support.ConnectionSource
getSpecialConnection
 

Constructor Detail

DataSourceConnectionSource

public DataSourceConnectionSource()
Constructor for Spring type wiring if you are using the set methods. If you are using Spring then your should use: init-method="initialize"


DataSourceConnectionSource

public DataSourceConnectionSource(DataSource dataSource,
                                  String databaseUrl)
                           throws SQLException
Create a data source wrapper for a DataSource.

Throws:
SQLException - If the driver associated with the database URL is not found in the classpath.

DataSourceConnectionSource

public DataSourceConnectionSource(DataSource dataSource,
                                  com.j256.ormlite.db.DatabaseType databaseType)
                           throws SQLException
Create a data source wrapper for a DataSource. The databaseType is usually determined from the databaseUrl so most users should call DataSourceConnectionSource(DataSource, String) instead. If, however, you need to force the class to use a specific DatabaseType then this constructor should be used.

Throws:
SQLException - If the driver associated with the database URL is not found in the classpath.
Method Detail

initialize

public void initialize()
                throws SQLException
Initialize the class after the setters have been called. If you are using the no-arg constructor and Spring type wiring, this should be called after all of the set methods.

Throws:
SQLException - If the driver associated with the database URL is not found in the classpath.

getReadOnlyConnection

public com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection()
                                                                  throws SQLException
Specified by:
getReadOnlyConnection in interface com.j256.ormlite.support.ConnectionSource
Throws:
SQLException

getReadOnlyConnection

public com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection(String username,
                                                                         String password)
                                                                  throws SQLException
Throws:
SQLException

getReadWriteConnection

public com.j256.ormlite.support.DatabaseConnection getReadWriteConnection()
                                                                   throws SQLException
Specified by:
getReadWriteConnection in interface com.j256.ormlite.support.ConnectionSource
Throws:
SQLException

releaseConnection

public void releaseConnection(com.j256.ormlite.support.DatabaseConnection connection)
                       throws SQLException
Specified by:
releaseConnection in interface com.j256.ormlite.support.ConnectionSource
Throws:
SQLException

getReadWriteConnection

public com.j256.ormlite.support.DatabaseConnection getReadWriteConnection(String username,
                                                                          String password)
                                                                   throws SQLException
Throws:
SQLException

saveSpecialConnection

public boolean saveSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
                              throws SQLException
Specified by:
saveSpecialConnection in interface com.j256.ormlite.support.ConnectionSource
Throws:
SQLException

clearSpecialConnection

public void clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
Specified by:
clearSpecialConnection in interface com.j256.ormlite.support.ConnectionSource

close

public void close()
           throws SQLException
This typically closes the connection source but because there is not a close() method on the DataSource (grrrr), this close method does _nothing_. You must close the underlying data-source yourself.

Specified by:
close in interface com.j256.ormlite.support.ConnectionSource
Throws:
SQLException

getDatabaseType

public com.j256.ormlite.db.DatabaseType getDatabaseType()
Specified by:
getDatabaseType in interface com.j256.ormlite.support.ConnectionSource

isOpen

public boolean isOpen()
Unfortunately we cannot tell if the related data source has been closed so this just returns true.

Specified by:
isOpen in interface com.j256.ormlite.support.ConnectionSource

setDataSource

public void setDataSource(DataSource dataSource)

setDatabaseType

public void setDatabaseType(com.j256.ormlite.db.DatabaseType databaseType)

setDatabaseUrl

public void setDatabaseUrl(String databaseUrl)

setUsesTransactions

public void setUsesTransactions(boolean usesTransactions)


This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.