/** * Verify the columnName is valid and return its FieldType. * * @throws IllegalArgumentException * if the column name is not valid. */ protected FieldType verifyColumnName(String columnName) { return tableInfo.getFieldTypeByColumnName(columnName); }
/** * Verify the columnName is valid and return its FieldType. * * @throws IllegalArgumentException * if the column name is not valid. */ protected FieldType verifyColumnName(String columnName) { return tableInfo.getFieldTypeByColumnName(columnName); }
private FieldType findColumnFieldType(String columnName) { return tableInfo.getFieldTypeByColumnName(columnName); }
private FieldType findColumnFieldType(String columnName) { return tableInfo.getFieldTypeByColumnName(columnName); }
/** * Match up our joined fields so we can throw a nice exception immediately if you can't join with this type. */ private void matchJoinedFieldsByName(JoinInfo joinInfo, String localColumnName, String joinedColumnName, QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException { joinInfo.localField = tableInfo.getFieldTypeByColumnName(localColumnName); if (joinInfo.localField == null) { throw new SQLException("Could not find field in " + tableInfo.getDataClass() + " that has column-name '" + localColumnName + "'"); } joinInfo.remoteField = joinedQueryBuilder.tableInfo.getFieldTypeByColumnName(joinedColumnName); if (joinInfo.remoteField == null) { throw new SQLException("Could not find field in " + joinedQueryBuilder.tableInfo.getDataClass() + " that has column-name '" + joinedColumnName + "'"); } }
/** * Match up our joined fields so we can throw a nice exception immediately if you can't join with this type. */ private void matchJoinedFieldsByName(JoinInfo joinInfo, String localColumnName, String joinedColumnName, QueryBuilder<?, ?> joinedQueryBuilder) throws SQLException { joinInfo.localField = tableInfo.getFieldTypeByColumnName(localColumnName); if (joinInfo.localField == null) { throw new SQLException("Could not find field in " + tableInfo.getDataClass() + " that has column-name '" + localColumnName + "'"); } joinInfo.remoteField = joinedQueryBuilder.tableInfo.getFieldTypeByColumnName(joinedColumnName); if (joinInfo.remoteField == null) { throw new SQLException("Could not find field in " + joinedQueryBuilder.tableInfo.getDataClass() + " that has column-name '" + joinedColumnName + "'"); } }
@Override public T mapRow(String[] columnNames, String[] resultColumns) throws SQLException { // create our object T rowObj = tableInfo.createObject(); for (int i = 0; i < columnNames.length; i++) { // sanity check, prolly will never happen but let's be careful out there if (i >= resultColumns.length) { continue; } // run through and convert each field FieldType fieldType = tableInfo.getFieldTypeByColumnName(columnNames[i]); Object fieldObj = fieldType.convertStringToJavaField(resultColumns[i], i); // assign it to the row object fieldType.assignField(rowObj, fieldObj, false, null); } return rowObj; } }
continue; FieldType fieldType = tableInfo.getFieldTypeByColumnName(select.getColumnName());
continue; FieldType fieldType = tableInfo.getFieldTypeByColumnName(select.getColumnName());
@Override public T mapRow(String[] columnNames, String[] resultColumns) throws SQLException { // create our object T rowObj = dao.createObjectInstance(); for (int i = 0; i < columnNames.length; i++) { // sanity check, prolly will never happen but let's be careful out there if (i >= resultColumns.length) { continue; } // run through and convert each field FieldType fieldType = tableInfo.getFieldTypeByColumnName(columnNames[i]); Object fieldObj = fieldType.convertStringToJavaField(resultColumns[i], i); // assign it to the row object fieldType.assignField(dao.getConnectionSource(), rowObj, fieldObj, false, null); } return rowObj; } }
@Test public void testUnknownForeignField() throws Exception { TableInfo<Foreign, Void> tableInfo = new TableInfo<Foreign, Void>(databaseType, Foreign.class); try { tableInfo.getFieldTypeByColumnName("foo"); fail("expected exception"); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("'" + Foreign.FOREIGN_FIELD_NAME + "'")); assertTrue(e.getMessage().contains("'foo'")); } }
foreignRefField = foreignIdField; } else { foreignRefField = foreignTableInfo.getFieldTypeByColumnName(foreignColumnName); if (foreignRefField == null) { throw new IllegalArgumentException(
foreignRefField = foreignIdField; } else { foreignRefField = foreignTableInfo.getFieldTypeByColumnName(foreignColumnName); if (foreignRefField == null) { throw new IllegalArgumentException(
@Test public void testBasic() throws SQLException { TableInfo<Foo, String> tableInfo = new TableInfo<Foo, String>(databaseType, Foo.class); assertEquals(Foo.class, tableInfo.getDataClass()); assertEquals(TABLE_NAME, tableInfo.getTableName()); assertEquals(COLUMN_NAME, tableInfo.getIdField().getColumnName()); assertEquals(1, tableInfo.getFieldTypes().length); assertSame(tableInfo.getIdField(), tableInfo.getFieldTypes()[0]); assertEquals(COLUMN_NAME, tableInfo.getFieldTypeByColumnName(COLUMN_NAME).getColumnName()); }