/** * Returns whether a result set is expected to determine the column types * from the returned data * * @param level * Desired compatibility level * @return True if column types should be detected, false otherwise */ public static boolean shouldDetectColumnTypes(int level) { level = normalizeLevel(level); return level == HIGH; }
ColumnInfo[] columns = new ColumnInfo[vars.size()]; int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel()); boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level); boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level); columns[i] = JdbcCompatibility.detectColumnType(vars.get(i), b.get(Var.alloc(vars.get(i))), true); LOGGER.info("High compatibility, column " + vars.get(i) + " was detected as being of type " + columns[i].getClassName());
/** * Test that with medium compatibility columns will be typed as strings but not detected types */ @Test public void test_level_behaviours_columns_02() { Assert.assertTrue(JdbcCompatibility.shouldTypeColumnsAsString(JdbcCompatibility.MEDIUM)); Assert.assertFalse(JdbcCompatibility.shouldDetectColumnTypes(JdbcCompatibility.MEDIUM)); // This also applies to DEFAULT level Assert.assertTrue(JdbcCompatibility.shouldTypeColumnsAsString(JdbcCompatibility.DEFAULT)); Assert.assertFalse(JdbcCompatibility.shouldDetectColumnTypes(JdbcCompatibility.DEFAULT)); }
/** * Detects a columns types and checks basic information from the detected type, returns the detected column information so tests can make further assertions on this * @param var Variable Name i.e. Column Label * @param value Example value to detect from * @param allowNulls Whether the column allows nulls * @param jdbcType Expected detected JDBC type * @param className Expected detected class name * @return Column Information * @throws SQLException */ private ColumnInfo testColumnTypeDetection(String var, Node value, boolean allowNulls, int jdbcType, String className) throws SQLException { ColumnInfo info = JdbcCompatibility.detectColumnType(var, value, allowNulls); Assert.assertEquals(var, info.getLabel()); if (allowNulls) { Assert.assertEquals(ResultSetMetaData.columnNullable, info.getNullability()); } else { Assert.assertEquals(ResultSetMetaData.columnNoNulls, info.getNullability()); } Assert.assertEquals(jdbcType, info.getType()); Assert.assertEquals(className, info.getClassName()); Assert.assertEquals(Node.class.getCanonicalName(), info.getTypeName()); return info; }
if (dtUri != null) { return selectColumnType(var, dtUri, nullable); } else {
int compatibilityLevel = JdbcCompatibility.parseLevel(ps.get(PARAM_JDBC_COMPATIBILITY));
ColumnInfo[] columns = new ColumnInfo[vars.size()]; int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel()); boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level); boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level); columns[i] = JdbcCompatibility.detectColumnType(vars.get(i), b.get(Var.alloc(vars.get(i))), true); LOGGER.info("High compatibility, column " + vars.get(i) + " was detected as being of type " + columns[i].getClassName());
/** * Test that with low compatibility columns will not be typed as strings/detected types */ @Test public void test_level_behaviours_columns_01() { Assert.assertFalse(JdbcCompatibility.shouldTypeColumnsAsString(JdbcCompatibility.LOW)); Assert.assertFalse(JdbcCompatibility.shouldDetectColumnTypes(JdbcCompatibility.LOW)); }
if (dtUri != null) { return selectColumnType(var, dtUri, nullable); } else {
int compatibilityLevel = JdbcCompatibility.parseLevel(ps.get(PARAM_JDBC_COMPATIBILITY));
int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel()); boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level); boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level); columns[i] = JdbcCompatibility.detectColumnType(names[i], values[i], false); LOGGER.info("High compatibility, column " + names[i] + " was detected as being of type " + columns[i].getClassName());
/** * Returns whether a result set is expected to type returned columns as * strings * * @param level * Desired compatibility level * @return True if columns should be typed as string, false otherwise */ public static boolean shouldTypeColumnsAsString(int level) { level = normalizeLevel(level); return level >= MEDIUM && level < HIGH; }
/** * Test that with high compatibility columns will not be typed as strings but with detected types */ @Test public void test_level_behaviours_columns_03() { Assert.assertFalse(JdbcCompatibility.shouldTypeColumnsAsString(JdbcCompatibility.HIGH)); Assert.assertTrue(JdbcCompatibility.shouldDetectColumnTypes(JdbcCompatibility.HIGH)); }
int level = JdbcCompatibility.normalizeLevel(results.getJdbcCompatibilityLevel()); boolean columnsAsStrings = JdbcCompatibility.shouldTypeColumnsAsString(level); boolean columnsDetected = JdbcCompatibility.shouldDetectColumnTypes(level); columns[i] = JdbcCompatibility.detectColumnType(names[i], values[i], false); LOGGER.info("High compatibility, column " + names[i] + " was detected as being of type " + columns[i].getClassName());
/** * Returns whether a result set is expected to type returned columns as * strings * * @param level * Desired compatibility level * @return True if columns should be typed as string, false otherwise */ public static boolean shouldTypeColumnsAsString(int level) { level = normalizeLevel(level); return level >= MEDIUM && level < HIGH; }
/** * Returns whether a result set is expected to determine the column types * from the returned data * * @param level * Desired compatibility level * @return True if column types should be detected, false otherwise */ public static boolean shouldDetectColumnTypes(int level) { level = normalizeLevel(level); return level == HIGH; }
/** * Sets the JDBC compatibility level that is in use, see * {@link JdbcCompatibility} for explanations. * <p> * Changing the level may not effect existing open objects, behaviour in * this case will be implementation specific. * </p> * * @param level * Compatibility level */ public void setJdbcCompatibilityLevel(int level) { this.compatibilityLevel = JdbcCompatibility.normalizeLevel(level); }
/** * Sets the JDBC compatibility level that is in use, see * {@link JdbcCompatibility} for explanations. * <p> * Changing the level may not effect existing open objects, behaviour in * this case will be implementation specific. * </p> * * @param level * Compatibility level */ public void setJdbcCompatibilityLevel(int level) { this.compatibilityLevel = JdbcCompatibility.normalizeLevel(level); }
/** * Sets the JDBC compatibility level that is in use, see * {@link JdbcCompatibility} for explanations. * <p> * By default this is set at the connection level and inherited, however you * may call {@link #setJdbcCompatibilityLevel(int)} to set the compatibility * level for this statement. This allows you to change the compatibility * level on a per-query basis if so desired. * </p> * <p> * Changing the level may not effect existing open objects, behaviour in * this case will be implementation specific. * </p> * * @param level * Compatibility level */ public void setJdbcCompatibilityLevel(int level) { if (level == USE_CONNECTION_COMPATIBILITY) { this.compatibilityLevel = USE_CONNECTION_COMPATIBILITY; } else { this.compatibilityLevel = JdbcCompatibility.normalizeLevel(level); } }
/** * Sets the JDBC compatibility level that is in use, see * {@link JdbcCompatibility} for explanations. * <p> * By default this is set at the connection level and inherited, however you * may call {@link #setJdbcCompatibilityLevel(int)} to set the compatibility * level for this statement. This allows you to change the compatibility * level on a per-query basis if so desired. * </p> * <p> * Changing the level may not effect existing open objects, behaviour in * this case will be implementation specific. * </p> * * @param level * Compatibility level */ public void setJdbcCompatibilityLevel(int level) { if (level == USE_CONNECTION_COMPATIBILITY) { this.compatibilityLevel = USE_CONNECTION_COMPATIBILITY; } else { this.compatibilityLevel = JdbcCompatibility.normalizeLevel(level); } }