Class DirectConnection

java.lang.Object
overit.geocall.sql.DirectConnection
All Implemented Interfaces:
AutoCloseable

public class DirectConnection extends Object implements AutoCloseable
The class is the implementation of the standard connection.
  • Field Details

    • connection

      protected Connection connection
    • info

      protected PooledConnectionInfo info
      Contains some informations about the connection such the last connection time, last release time, etc.
    • driver

      protected String driver
      Name of the JDBC driver that must be instanciate with Class.forName()
    • url

      protected String url
      Database access address
    • user

      protected String user
      Username for the database access
    • password

      protected String password
      Password for the database access
    • testStatement

      protected String testStatement
      Test command for the database access
    • parameters

      protected StringGetter parameters
      Parameters of the connection
    • setupScript

      protected String[] 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 driver
      url - The address of the database
      user - The username for the database access
      password - The password for the database access
      testStatement - A test command for the database access
      script - Scripts that will be execute in the connection phase
      parameters - Parameters of the connection
      Throws:
      ClassNotFoundException - The search for the correct JDBC driver can raise a ClassNotFoundException
    • DirectConnection

      public DirectConnection(String name, Getter cr) throws ClassNotFoundException
      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 using new StandardPooledConnection("oracle",getter);, where getter is a configuration PropertyGetter file, 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 Getter
      cr - The Getter object used to retreive the information for the connection creation
      Throws:
      ClassNotFoundException - The search for the correct JDBC driver can raise a ClassNotFoundException
  • Method Details

    • connect

      public void connect() throws SQLException
      Forcibly opens the JDBC connection
      Throws:
      SQLException - The request of the opening of a connection can raise an SQL exception
    • getInfo

      public PooledConnectionInfo getInfo()
      Returns:
      The PooledConnectionInfo
    • isWorking

      public boolean isWorking() throws SQLException
      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

      public void close() throws SQLException
      Forcibly closes the JDBC connection
      Specified by:
      close in interface AutoCloseable
      Throws:
      SQLException - The request of the closing can raise an SQL exception