Class JdbcCompatibility


  • public class JdbcCompatibility
    extends java.lang.Object

    Class containing constants and helper methods related to JDBC compatibility

    Understanding Compatibility Levels

    Since JDBC is very SQL centric API by definition shoe-horning SPARQL into it has some caveats and provisos, the aim of this class it to provide some level of configurability of how nice we will try to play with JDBC. We provide the notion of a configurable compatibility level, by definition we use the MEDIUM compatibility level, see the documentation on the constants and helper methods to understand exactly what each level means.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT
      Constant for default JDBC compatibility which is set to MEDIUM
      static int HIGH
      Constant for high JDBC compatibility level
      static int LOW
      Constant for low JDBC compatibility level
      static int MEDIUM
      Constant for medium JDBC compatibility level
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ColumnInfo detectColumnType​(java.lang.String var, Node value, boolean allowsNulls)
      Detects the column type information based on an example value
      static int normalizeLevel​(int level)
      Normalizes the compatibility level given to be within the acceptable range of 1-9
      static int parseLevel​(java.lang.Object object)
      Parses the JDBC compatibility level from the given object and normalizes it if necessary.
      static boolean shouldDetectColumnTypes​(int level)
      Returns whether a result set is expected to determine the column types from the returned data
      static boolean shouldTypeColumnsAsString​(int level)
      Returns whether a result set is expected to type returned columns as strings
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOW

        public static final int LOW
        Constant for low JDBC compatibility level

        This is the level you should use when you know you are accessing a SPARQL source and are able to cope with the Jena/ARQ representation of RDF terms natively.

        Behavior Specifies

        • Column Typing - All result set columns are reported as being as typed as Types.JAVA_OBJECT and Java type is the ARQ Node type.
        See Also:
        Constant Field Values
      • MEDIUM

        public static final int MEDIUM
        Constant for medium JDBC compatibility level

        This is the default compatibility level, we will make some effort to be compatible with JDBC but these efforts will not be perfect.

        Behavior Specifics

        • Column Typing - All result set columns are reported as being as typed as Types.NVARCHAR and Java type is String.
        See Also:
        Constant Field Values
      • HIGH

        public static final int HIGH
        Constant for high JDBC compatibility level

        This is the highest compatibility level, we will do our best to be compatible with JDBC however these efforts may still not be perfect.

        Behavior Specifics

        • Column Typing - Result set columns are typed by inspecting the first row of the data so native JDBC types like Types.INTEGER and so forth may be reported depending on the query.
        See Also:
        Constant Field Values
      • DEFAULT

        public static final int DEFAULT
        Constant for default JDBC compatibility which is set to MEDIUM
        See Also:
        Constant Field Values
    • Method Detail

      • normalizeLevel

        public static int normalizeLevel​(int level)
        Normalizes the compatibility level given to be within the acceptable range of 1-9
        Parameters:
        level - Level
        Returns:
        Normalized level
      • shouldDetectColumnTypes

        public static boolean shouldDetectColumnTypes​(int level)
        Returns whether a result set is expected to determine the column types from the returned data
        Parameters:
        level - Desired compatibility level
        Returns:
        True if column types should be detected, false otherwise
      • shouldTypeColumnsAsString

        public static boolean shouldTypeColumnsAsString​(int level)
        Returns whether a result set is expected to type returned columns as strings
        Parameters:
        level - Desired compatibility level
        Returns:
        True if columns should be typed as string, false otherwise
      • detectColumnType

        public static ColumnInfo detectColumnType​(java.lang.String var,
                                                  Node value,
                                                  boolean allowsNulls)
                                           throws java.sql.SQLException
        Detects the column type information based on an example value
        Parameters:
        var - Variable Name i.e. the column label
        value - Example value
        allowsNulls - Whether the result set we are detecting the type for allows null values in this column
        Returns:
        Column Information
        Throws:
        java.sql.SQLException - Thrown if the column type cannot be detected, this should only occur if you state that the column does not allow nulls and then provide a null example value
      • parseLevel

        public static int parseLevel​(java.lang.Object object)
        Parses the JDBC compatibility level from the given object and normalizes it if necessary. If the given object is null or does not contain a valid integer value (or can be parsed as such) then the returned compatibility level will be DEFAULT
        Parameters:
        object - Object to parse
        Returns:
        Normalized JDBC compatibility level