com.j256.ormlite.jdbc
Class JdbcConnectionSource

java.lang.Object
  extended by com.j256.ormlite.support.BaseConnectionSource
      extended by com.j256.ormlite.jdbc.JdbcConnectionSource
All Implemented Interfaces:
com.j256.ormlite.support.ConnectionSource
Direct Known Subclasses:
JdbcPooledConnectionSource

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

Implementation of the ConnectionSource interface that supports what is needed by ORMLite. This is not thread-safe nor synchronized. For other dataSources, see the DataSourceConnectionSource class.

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
protected  com.j256.ormlite.db.DatabaseType databaseType
           
protected  boolean initialized
           
 
Fields inherited from class com.j256.ormlite.support.BaseConnectionSource
usedSpecialConnection
 
Constructor Summary
JdbcConnectionSource()
          Constructor for Spring type wiring if you are using the set methods.
JdbcConnectionSource(String url)
          Create a data source for a particular database URL.
JdbcConnectionSource(String url, com.j256.ormlite.db.DatabaseType databaseType)
          Create a data source for a particular database URL.
JdbcConnectionSource(String url, String username, String password)
          Create a data source for a particular database URL with username and password permissions.
JdbcConnectionSource(String url, String username, String password, com.j256.ormlite.db.DatabaseType databaseType)
          Create a data source for a particular database URL with username and password permissions.
 
Method Summary
 void clearSpecialConnection(com.j256.ormlite.support.DatabaseConnection connection)
           
 void close()
           
 com.j256.ormlite.db.DatabaseType getDatabaseType()
           
 com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection()
           
 com.j256.ormlite.support.DatabaseConnection getReadWriteConnection()
           
 String getUrl()
           
 void initialize()
          Initialize the class after the setters have been called.
 boolean isOpen()
           
protected  JdbcDatabaseConnection makeConnection(com.j256.ormlite.logger.Logger logger)
          Make a connection to the database.
 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 setPassword(String password)
           
 void setUrl(String url)
           
 void setUsername(String username)
           
 
Methods inherited from class com.j256.ormlite.support.BaseConnectionSource
clearSpecial, getSavedConnection, getSpecial, 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
 

Field Detail

databaseType

protected com.j256.ormlite.db.DatabaseType databaseType

initialized

protected boolean initialized
Constructor Detail

JdbcConnectionSource

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


JdbcConnectionSource

public JdbcConnectionSource(String url)
                     throws SQLException
Create a data source for a particular database URL.

Parameters:
url - The database URL which should start jdbc:...
Throws:
SQLException - If the driver associated with the database driver is not found in the classpath.

JdbcConnectionSource

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

Parameters:
url - The database URL which should start jdbc:...
databaseType - Database to associate with this connection source.
Throws:
SQLException - If the driver associated with the database driver is not found in the classpath.

JdbcConnectionSource

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

Parameters:
url - The database URL which should start jdbc:...
username - Username for permissions on the database.
password - Password for permissions on the database.
Throws:
SQLException - If the driver associated with the database driver is not found in the classpath.

JdbcConnectionSource

public JdbcConnectionSource(String url,
                            String username,
                            String password,
                            com.j256.ormlite.db.DatabaseType databaseType)
                     throws SQLException
Create a data source for a particular database URL with username and password permissions. The databaseType is usually determined from the databaseUrl so most users should call JdbcConnectionSource(String, String, String) instead. If, however, you need to force the class to use a specific DatabaseType then this constructor should be used.

Parameters:
url - The database URL which should start jdbc:...
username - Username for permissions on the database.
password - Password for permissions on the database.
databaseType - Database to associate with this connection source.
Throws:
SQLException - If the driver associated with the database driver 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.

close

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

getUrl

public String getUrl()

setUrl

public void setUrl(String url)

getReadOnlyConnection

public com.j256.ormlite.support.DatabaseConnection getReadOnlyConnection()
                                                                  throws SQLException
Specified by:
getReadOnlyConnection in interface com.j256.ormlite.support.ConnectionSource
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

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

getDatabaseType

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

isOpen

public boolean isOpen()
Specified by:
isOpen in interface com.j256.ormlite.support.ConnectionSource

setUsername

public void setUsername(String username)

setPassword

public void setPassword(String password)

setDatabaseType

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

makeConnection

protected JdbcDatabaseConnection makeConnection(com.j256.ormlite.logger.Logger logger)
                                         throws SQLException
Make a connection to the database.

Throws:
SQLException


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