com.j256.ormlite.support
Interface ConnectionSource

All Known Implementing Classes:
BaseConnectionSource

public interface ConnectionSource

A reduction of the SQL DataSource so we can implement its functionality outside of JDBC.

Author:
graywatson

Method Summary
 void clearSpecialConnection(DatabaseConnection connection)
          Clear the saved connection.
 void close()
          Close any outstanding database connections.
 DatabaseType getDatabaseType()
          Return the DatabaseTypre associated with this connection.
 DatabaseConnection getReadOnlyConnection()
          Return a database connection suitable for read-only operations.
 DatabaseConnection getReadWriteConnection()
          Return a database connection suitable for read or write operations.
 DatabaseConnection getSpecialConnection()
          Return the currently saved connection or null if none.
 boolean isOpen()
          Return true if the connection source is open.
 void releaseConnection(DatabaseConnection connection)
          Release a database connection previously returned by getReadOnlyConnection() or getReadWriteConnection().
 boolean saveSpecialConnection(DatabaseConnection connection)
          Save this connection and return it for all calls to getReadOnlyConnection() and getReadWriteConnection() unless the clearSpecialConnection(DatabaseConnection) method is called, all This is used by the transaction mechanism since since all operations within a transaction must operate on the same connection.
 

Method Detail

getReadOnlyConnection

DatabaseConnection getReadOnlyConnection()
                                         throws SQLException
Return a database connection suitable for read-only operations. After you are done, you should call releaseConnection(DatabaseConnection).

Throws:
SQLException

getReadWriteConnection

DatabaseConnection getReadWriteConnection()
                                          throws SQLException
Return a database connection suitable for read or write operations. After you are done, you should call releaseConnection(DatabaseConnection).

Throws:
SQLException

releaseConnection

void releaseConnection(DatabaseConnection connection)
                       throws SQLException
Release a database connection previously returned by getReadOnlyConnection() or getReadWriteConnection().

Throws:
SQLException

saveSpecialConnection

boolean saveSpecialConnection(DatabaseConnection connection)
                              throws SQLException
Save this connection and return it for all calls to getReadOnlyConnection() and getReadWriteConnection() unless the clearSpecialConnection(DatabaseConnection) method is called, all This is used by the transaction mechanism since since all operations within a transaction must operate on the same connection. It is also used by the Android code during initialization.

NOTE: This should be a read-write connection since transactions and Android need it to be so.

NOTE: Saving a connection is usually accomplished using ThreadLocals so multiple threads should not be using connections in this scenario.

Returns:
True if the connection was saved or false if we were already inside of a saved connection.
Throws:
SQLException

clearSpecialConnection

void clearSpecialConnection(DatabaseConnection connection)
Clear the saved connection.


getSpecialConnection

DatabaseConnection getSpecialConnection()
Return the currently saved connection or null if none.


close

void close()
           throws SQLException
Close any outstanding database connections.

Throws:
SQLException

getDatabaseType

DatabaseType getDatabaseType()
Return the DatabaseTypre associated with this connection.


isOpen

boolean isOpen()
Return true if the connection source is open. Once close() has been called, this should return false.



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