@SuppressWarnings({ "rawtypes", "unchecked" }) private MetaResultSet createResultSet(List iterable, Class clazz, String... names) { final List<ColumnMetaData> columns = new ArrayList<ColumnMetaData>(); final List<Field> fields = new ArrayList<Field>(); final List<String> fieldNames = new ArrayList<String>(); for (String name : names) { final int index = fields.size(); final String fieldName = AvaticaUtils.toCamelCase(name); final Field field; try { field = clazz.getField(fieldName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } columns.add(columnMetaData(name, index, field.getType(), true)); fields.add(field); fieldNames.add(fieldName); } CursorFactory cursorFactory = CursorFactory.record(clazz, fields, fieldNames); Signature signature = new Signature(columns, "", null, Collections.<String, Object> emptyMap(), cursorFactory, StatementType.SELECT); StatementHandle sh = this.createStatement(connection().handle); Frame frame = new Frame(0, true, iterable); return MetaResultSet.create(connection().id, sh.id, true, signature, frame); }
<T> DatabaseProperty(T defaultValue) { this.defaultValue = defaultValue; final String methodName = AvaticaUtils.toCamelCase(name()); try { this.method = DatabaseMetaData.class.getMethod(methodName); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } this.type = AvaticaUtils.box(method.getReturnType()); assert defaultValue == null || defaultValue.getClass() == type; }
<T> DatabaseProperty(T defaultValue) { this.defaultValue = defaultValue; final String methodName = AvaticaUtils.toCamelCase(name()); Method localMethod = null; try { localMethod = DatabaseMetaData.class.getMethod(methodName); } catch (NoSuchMethodException e) { // Pass, localMethod stays null. } if (null == localMethod) { this.method = null; this.type = null; this.isJdbc = false; } else { this.method = localMethod; this.type = AvaticaUtils.box(method.getReturnType()); this.isJdbc = true; } // It's either: 1) not a JDBC method, 2) has no default value, // 3) the defaultValue is of the expected type assert !isJdbc || defaultValue == null || defaultValue.getClass() == type; }
private <E> MetaResultSet createResultSet(Enumerable<E> enumerable, Class clazz, String... names) { final List<ColumnMetaData> columns = new ArrayList<>(); final List<Field> fields = new ArrayList<>(); final List<String> fieldNames = new ArrayList<>(); for (String name : names) { final int index = fields.size(); final String fieldName = AvaticaUtils.toCamelCase(name); final Field field; try { field = clazz.getField(fieldName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } columns.add(columnMetaData(name, index, field.getType(), false)); fields.add(field); fieldNames.add(fieldName); } //noinspection unchecked final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable; return createResultSet(Collections.emptyMap(), columns, CursorFactory.record(clazz, fields, fieldNames), new Frame(0, true, iterable)); }
<T> DatabaseProperty(T defaultValue) { this.defaultValue = defaultValue; final String methodName = AvaticaUtils.toCamelCase(name()); Method localMethod = null; try { localMethod = DatabaseMetaData.class.getMethod(methodName); } catch (NoSuchMethodException e) { // Pass, localMethod stays null. } if (null == localMethod) { this.method = null; this.type = null; this.isJdbc = false; } else { this.method = localMethod; this.type = AvaticaUtils.box(method.getReturnType()); this.isJdbc = true; } // It's either: 1) not a JDBC method, 2) has no default value, // 3) the defaultValue is of the expected type assert !isJdbc || defaultValue == null || defaultValue.getClass() == type; }
private <E> MetaResultSet createResultSet(Enumerable<E> enumerable, Class clazz, String... names) { final List<ColumnMetaData> columns = new ArrayList<>(); final List<Field> fields = new ArrayList<>(); final List<String> fieldNames = new ArrayList<>(); for (String name : names) { final int index = fields.size(); final String fieldName = AvaticaUtils.toCamelCase(name); final Field field; try { field = clazz.getField(fieldName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } columns.add(columnMetaData(name, index, field.getType(), false)); fields.add(field); fieldNames.add(fieldName); } //noinspection unchecked final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable; return createResultSet(Collections.emptyMap(), columns, CursorFactory.record(clazz, fields, fieldNames), new Frame(0, true, iterable)); }
private <E> MetaResultSet createResultSet(Enumerable<E> enumerable, Class clazz, String... names) { final List<ColumnMetaData> columns = new ArrayList<>(); final List<Field> fields = new ArrayList<>(); final List<String> fieldNames = new ArrayList<>(); for (String name : names) { final int index = fields.size(); final String fieldName = AvaticaUtils.toCamelCase(name); final Field field; try { field = clazz.getField(fieldName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } columns.add(columnMetaData(name, index, field.getType(), false)); fields.add(field); fieldNames.add(fieldName); } //noinspection unchecked final Iterable<Object> iterable = (Iterable<Object>) (Iterable) enumerable; return createResultSet(Collections.<String, Object>emptyMap(), columns, CursorFactory.record(clazz, fields, fieldNames), new Frame(0, true, iterable)); }
private Method findMethod(String path) { // E.g. path "sql/agg.iq" gives method "testSqlAgg" String methodName = AvaticaUtils.toCamelCase( "test_" + path.replace(File.separatorChar, '_').replaceAll("\\.iq$", "")); Method m; try { m = getClass().getMethod(methodName); } catch (NoSuchMethodException e) { m = null; } return m; }
private Method findMethod(String path) { // E.g. path "sql/agg.iq" gives method "testSqlAgg" String methodName = AvaticaUtils.toCamelCase( "test_" + path.replace(File.separatorChar, '_').replaceAll("\\.iq$", "")); Method m; try { m = getClass().getMethod(methodName); } catch (NoSuchMethodException e) { m = null; } return m; }
/** * Unit test for {@link AvaticaUtils#toCamelCase(String)}. */ @Test public void testToCamelCase() { assertEquals("myJdbcDriver", AvaticaUtils.toCamelCase("MY_JDBC_DRIVER")); assertEquals("myJdbcDriver", AvaticaUtils.toCamelCase("MY_JDBC__DRIVER")); assertEquals("myJdbcDriver", AvaticaUtils.toCamelCase("my_jdbc_driver")); assertEquals("abCdefGHij", AvaticaUtils.toCamelCase("ab_cdEf_g_Hij")); assertEquals("JdbcDriver", AvaticaUtils.toCamelCase("_JDBC_DRIVER")); assertEquals("", AvaticaUtils.toCamelCase("_")); assertEquals("", AvaticaUtils.toCamelCase("")); }
/** * Unit test for {@link AvaticaUtils#toCamelCase(String)}. */ @Test public void testToCamelCase() { assertEquals("myJdbcDriver", AvaticaUtils.toCamelCase("MY_JDBC_DRIVER")); assertEquals("myJdbcDriver", AvaticaUtils.toCamelCase("MY_JDBC__DRIVER")); assertEquals("myJdbcDriver", AvaticaUtils.toCamelCase("my_jdbc_driver")); assertEquals("abCdefGHij", AvaticaUtils.toCamelCase("ab_cdEf_g_Hij")); assertEquals("JdbcDriver", AvaticaUtils.toCamelCase("_JDBC_DRIVER")); assertEquals("", AvaticaUtils.toCamelCase("_")); assertEquals("", AvaticaUtils.toCamelCase("")); }