}
foreignFieldType = null;
mappedQueryForId = null;
} else if (fieldConfig.isForeignCollection()) {
if (clazz != Collection.class && !ForeignCollection.class.isAssignableFrom(clazz)) {
throw new SQLException("Field class for '" + field.getName() + "' must be of class "
+ ForeignCollection.class.getSimpleName() + " or Collection.");
}
Type type = field.getGenericType();
if (!(type instanceof ParameterizedType)) {
throw new SQLException("Field class for '" + field.getName() + "' must be a parameterized Collection.");
}
Type[] genericArguments = ((ParameterizedType) type).getActualTypeArguments();
if (genericArguments.length == 0) {
// i doubt this will ever be reached
throw new SQLException("Field class for '" + field.getName()
+ "' must be a parameterized Collection with at least 1 type.");
}
clazz = (Class<?>) genericArguments[0];
DatabaseTableConfig<?> tableConfig = fieldConfig.getForeignTableConfig();
Dao<Object, Object> foundDao;
if (tableConfig == null) {
@SuppressWarnings("unchecked")
Dao<Object, Object> castDao = (Dao<Object, Object>) DaoManager.createDao(connectionSource, clazz);
foundDao = castDao;
} else {
@SuppressWarnings("unchecked")
Dao<Object, Object> castDao = (Dao<Object, Object>) DaoManager.createDao(connectionSource, tableConfig);
foundDao = castDao;
}
FieldType findForeignFieldType = null;
for (FieldType fieldType : ((BaseDaoImpl<?, ?>) foundDao).getTableInfo().getFieldTypes()) {
if (fieldType.getFieldType() == parentClass) {
findForeignFieldType = fieldType;
break;
}
}
if (findForeignFieldType == null) {
throw new SQLException("Foreign collection object " + clazz + " for field '" + field.getName()
+ "' does not contain a foreign field of class " + parentClass);
}
if (!findForeignFieldType.fieldConfig.isForeign()
&& !findForeignFieldType.fieldConfig.isForeignAutoRefresh()) {
// this may never be reached
throw new SQLException("Foreign collection object " + clazz + " for field '" + field.getName()
+ "' contains a field of class " + parentClass + " but it's not foreign");
}
foreignDao = foundDao;
foreignFieldType = findForeignFieldType;
foreignIdField = null;