Package overit.geocall.sql
Class DirectConnection
java.lang.Object
overit.geocall.sql.DirectConnection
- All Implemented Interfaces:
AutoCloseable
The class is the implementation of the standard connection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Connectionprotected StringName of the JDBC driver that must be instanciate with Class.forName()protected PooledConnectionInfoContains some informations about the connection such the last connection time, last release time, etc.protected StringGetterParameters of the connectionprotected StringPassword for the database accessprotected String[]Contains the scripts executed in the connection phaseprotected StringTest command for the database accessprotected StringDatabase access addressprotected StringUsername for the database access -
Constructor Summary
ConstructorsConstructorDescriptionDirectConnection(String driver, String url, String user, String password, String testStatement, String script, StringGetter parameters) Creates an instance of StandardPooledConnection starting from the JDBC driver, the database address, username and passwordDirectConnection(String name, Getter cr) Creates on instance of StandardPooledConnection starting from a name, that will be used to retrieve the information from a Getter. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Forcibly closes the JDBC connectionvoidconnect()Forcibly opens the JDBC connectiongetInfo()Returns thePooledConnectionInfobooleanChecks if the connection is working.
-
Field Details
-
connection
-
info
Contains some informations about the connection such the last connection time, last release time, etc. -
driver
Name of the JDBC driver that must be instanciate with Class.forName() -
url
Database access address -
user
Username for the database access -
password
Password for the database access -
testStatement
Test command for the database access -
parameters
Parameters of the connection -
setupScript
Contains the scripts executed in the connection phase
-
-
Constructor Details
-
DirectConnection
public DirectConnection(String driver, String url, String user, String password, String testStatement, String script, StringGetter parameters) throws ClassNotFoundException Creates an instance of StandardPooledConnection starting from the JDBC driver, the database address, username and password- Parameters:
driver- The name of the JDBC driverurl- The address of the databaseuser- The username for the database accesspassword- The password for the database accesstestStatement- A test command for the database accessscript- Scripts that will be execute in the connection phaseparameters- Parameters of the connection- Throws:
ClassNotFoundException- The search for the correct JDBC driver can raise aClassNotFoundException
-
DirectConnection
Creates on instance of StandardPooledConnection starting from a name, that will be used to retrieve the information from a Getter.
For example if we construct the instance usingnew StandardPooledConnection("oracle",getter);, where getter is a configurationPropertyGetterfile, will be searched into the properties file, and used to construct the connection, the keywords "oracle.driver", "oracle.url", "oracle.user" and "oracle.password"- Parameters:
name- The name of the connection, used to the search into the Gettercr- The Getter object used to retreive the information for the connection creation- Throws:
ClassNotFoundException- The search for the correct JDBC driver can raise aClassNotFoundException
-
-
Method Details
-
connect
Forcibly opens the JDBC connection- Throws:
SQLException- The request of the opening of a connection can raise an SQL exception
-
getInfo
Returns thePooledConnectionInfo- Returns:
- The
PooledConnectionInfo
-
isWorking
Checks if the connection is working. It can be extended to customize the test.- Returns:
- true if the connection is working, false otherwise
- Throws:
SQLException- This request can commmunicate with the database, so there can be an error that raise an SQLException
-
close
Forcibly closes the JDBC connection- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException- The request of the closing can raise an SQL exception
-