Class JdbcCompatibility
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
FieldsModifier and TypeFieldDescriptionstatic final int
Constant for default JDBC compatibility which is set toMEDIUM
static final int
Constant for high JDBC compatibility levelstatic final int
Constant for low JDBC compatibility levelstatic final int
Constant for medium JDBC compatibility level -
Method Summary
Modifier and TypeMethodDescriptionstatic ColumnInfo
detectColumnType
(String var, Node value, boolean allowsNulls) Detects the column type information based on an example valuestatic int
normalizeLevel
(int level) Normalizes the compatibility level given to be within the acceptable range of 1-9static int
parseLevel
(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 datastatic boolean
shouldTypeColumnsAsString
(int level) Returns whether a result set is expected to type returned columns as strings
-
Field Details
-
LOW
public static final int LOWConstant for low JDBC compatibility levelThis 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 ARQNode
type.
- See Also:
- Column Typing - All result set columns are reported as being as typed
as
-
MEDIUM
public static final int MEDIUMConstant for medium JDBC compatibility levelThis 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 isString
.
- See Also:
- Column Typing - All result set columns are reported as being as typed
as
-
HIGH
public static final int HIGHConstant for high JDBC compatibility levelThis 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:
- Column Typing - Result set columns are typed by inspecting the first
row of the data so native JDBC types like
-
DEFAULT
public static final int DEFAULTConstant for default JDBC compatibility which is set toMEDIUM
- 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 labelvalue
- Example valueallowsNulls
- 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
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 beDEFAULT
- Parameters:
object
- Object to parse- Returns:
- Normalized JDBC compatibility level
-