Class JdbcCompatibility

java.lang.Object
org.apache.jena.jdbc.JdbcCompatibility

public class JdbcCompatibility extends 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 final int
    Constant for default JDBC compatibility which is set to MEDIUM
    static final int
    Constant for high JDBC compatibility level
    static final int
    Constant for low JDBC compatibility level
    static final int
    Constant for medium JDBC compatibility level
  • Method Summary

    Modifier and Type
    Method
    Description
    static ColumnInfo
    detectColumnType(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
    Parses the JDBC compatibility level from the given object and normalizes it if necessary.
    static boolean
    Returns whether a result set is expected to determine the column types from the returned data
    static boolean
    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 Details

    • 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:
    • 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:
    • 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:
    • DEFAULT

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

    • 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(String var, Node value, boolean allowsNulls) throws 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:
      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(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