CompiledStatement stmt = null;
try {
stmt =
conn.compileStatement("select * from " + TABLE_NAME, StatementType.SELECT, noFieldTypes,
DatabaseConnection.DEFAULT_RESULT_FLAGS);
DatabaseResults results = stmt.runQuery(null);
assertTrue(results.next());
int colNum = results.findColumn(columnName);
Field field = clazz.getDeclaredField(columnName);
FieldType fieldType = FieldType.createFieldType(connectionSource, TABLE_NAME, field, clazz);
Class<?>[] classes = fieldType.getDataPersister().getAssociatedClasses();
if (classes.length > 0) {
assertTrue(classes[0].isAssignableFrom(fieldType.getType()));
}
assertTrue(fieldType.getDataPersister().isValidForField(field));
if (javaVal instanceof byte[]) {
assertTrue(Arrays.equals((byte[]) javaVal,
(byte[]) dataPersister.resultToJava(fieldType, results, colNum)));
} else {
Map<String, Integer> colMap = new HashMap<String, Integer>();
colMap.put(columnName, colNum);
Object result = fieldType.resultToJava(results, colMap);
assertEquals(javaVal, result);
}
if (dataType == DataType.STRING_BYTES || dataType == DataType.BYTE_ARRAY
|| dataType == DataType.SERIALIZABLE) {
try {
dataPersister.parseDefaultString(fieldType, "");
fail("parseDefaultString should have thrown for " + dataType);
} catch (SQLException e) {
// expected
}
} else if (defaultValStr != null) {
assertEquals(defaultSqlVal, dataPersister.parseDefaultString(fieldType, defaultValStr));
}
if (sqlArg == null) {
// noop
} else if (sqlArg instanceof byte[]) {
assertTrue(Arrays.equals((byte[]) sqlArg, (byte[]) dataPersister.javaToSqlArg(fieldType, javaVal)));
} else {
assertEquals(sqlArg, dataPersister.javaToSqlArg(fieldType, javaVal));
}
assertEquals(isValidGeneratedType, dataPersister.isValidGeneratedType());
assertEquals(isAppropriateId, dataPersister.isAppropriateId());
assertEquals(isEscapedValue, dataPersister.isEscapedValue());
assertEquals(isEscapedValue, dataPersister.isEscapedDefaultValue());
assertEquals(isPrimitive, dataPersister.isPrimitive());
assertEquals(isSelectArgRequired, dataPersister.isArgumentHolderRequired());
assertEquals(isStreamType, dataPersister.isStreamType());
assertEquals(isComparable, dataPersister.isComparable());
if (isConvertableId) {
assertNotNull(dataPersister.convertIdNumber(10));
} else {
assertNull(dataPersister.convertIdNumber(10));
}
List<T> list = dao.queryForAll();
assertEquals(1, list.size());
assertTrue(dao.objectsEqual(foo, list.get(0)));
// if we have a value then look for it, floats don't find any results because of rounding issues
if (javaVal != null && dataPersister.isComparable() && dataType != DataType.FLOAT
&& dataType != DataType.FLOAT_OBJ) {
// test for inline arguments
list = dao.queryForMatching(foo);
assertEquals(1, list.size());
assertTrue(dao.objectsEqual(foo, list.get(0)));
// test for SelectArg arguments
list = dao.queryForMatchingArgs(foo);
assertEquals(1, list.size());
assertTrue(dao.objectsEqual(foo, list.get(0)));
}
if (dataType == DataType.STRING_BYTES || dataType == DataType.BYTE_ARRAY
|| dataType == DataType.SERIALIZABLE) {
// no converting from string to value
} else {
// test string conversion
String stringVal = results.getString(colNum);
Object convertedJavaVal = fieldType.convertStringToJavaField(stringVal, 0);
assertEquals(javaVal, convertedJavaVal);
}
} finally {
if (stmt != null) {