Class MckoiConnection


  • public final class MckoiConnection
    extends java.lang.Object
    Wraps a Connection and provides Mckoi specific extensions that are outside the JDBC specification.

    Example,

     Connection connection = java.sql.DriverManager.getConnection( .... );
     MckoiConnection mckoi_connection = new MckoiConnection(connection);
     // 'mckoi_connection' is used for mckoi specific comms.
     
    Author:
    Tobias Downer
    • Constructor Summary

      Constructors 
      Constructor Description
      MckoiConnection​(java.sql.Connection connection)
      Constructs the Mckoi specific extension access object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addTriggerListener​(java.lang.String trigger_name, TriggerListener trigger_listener)
      Registers a TriggerListener to listen for any triggers that are fired with the given name.
      static java.lang.String quote​(java.lang.String java_string)
      Given a string, this will use escape codes to convert the Java string into a Mckoi SQL string that can be parsed correctly by the database.
      void removeTriggerListener​(java.lang.String trigger_name, TriggerListener trigger_listener)
      Removes a TriggerListener that is listening for triggers with the given name.
      void setStrictGetObject​(boolean status)
      This method can be used to disable strict get object in ResultSet.
      void setVerboseColumnNames​(boolean status)
      This method is used to enable verbose column names in ResultSetMetaData.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MckoiConnection

        public MckoiConnection​(java.sql.Connection connection)
        Constructs the Mckoi specific extension access object.
    • Method Detail

      • setStrictGetObject

        public void setStrictGetObject​(boolean status)
        This method can be used to disable strict get object in ResultSet. If strict get object is disabled then the 'getObject' method will return the raw data type that the engine uses to represent the respective data item. If it is enabled the 'getObject' method returns the correct type as specified by the JDBC spec.

        Strict get is enabled by default.

      • setVerboseColumnNames

        public void setVerboseColumnNames​(boolean status)
        This method is used to enable verbose column names in ResultSetMetaData. If verbose column names is enabled the getColumnName method returns a string which includes the schema and table name. This property is disabled by default and provided only for compatibility with older Mckoi applications.
      • addTriggerListener

        public void addTriggerListener​(java.lang.String trigger_name,
                                       TriggerListener trigger_listener)
        Registers a TriggerListener to listen for any triggers that are fired with the given name. A TriggerListener may be registered to listen for multiple database triggers.

        NOTE: All trigger events are fired on a dedicated trigger thread. All triggers are fired from this thread in sequence.

        Parameters:
        trigger_name - the name of the database trigger to listen for.
        trigger_listener - the listener to be notified when the trigger event occurs.
      • removeTriggerListener

        public void removeTriggerListener​(java.lang.String trigger_name,
                                          TriggerListener trigger_listener)
        Removes a TriggerListener that is listening for triggers with the given name.
        Parameters:
        trigger_name - the name of the database trigger to stop listening for.
        trigger_listener - the listener to stop being notified of trigger events for this trigger name.
      • quote

        public static java.lang.String quote​(java.lang.String java_string)
        Given a string, this will use escape codes to convert the Java string into a Mckoi SQL string that can be parsed correctly by the database. For example;

           String user_input = [some untrusted string]
           Statement statement = connection.createStatement();
           ResultSet result = statement.executeQuery(
                 "SELECT number FROM Part WHERE number = " +
                 MckoiConnection.quote(user_input));
         
        If the user supplies the string "Gr's\nut\'", this method will generate the SQL query string;

           SELECT number FROM Part WHERE number = 'Gr\'s\\nut\\\''
         
        This is used for generating secure dynamic SQL commands. It is particularly important if the quoted strings are coming from an untrusted source.

        This security precaution is not necessary if using PreparedStatement to form the SQL parameters.