List<?> tarList = null;
try {
tarList = (List<?>) tarGetter.invoke(t);
} catch (Exception e) {
throw new DAOException(tarGetter + " invoke exception ", e);
}
if (tarList == null || tarList.size() == 0) {
// 当关联对象为空的时候,删除所有关联对象
// delete from {tarTable} where {column} = {idVal}
String format = "delete from %s where %s = ? ";
String sql = String.format(format, tarTable, column);
DAOFactory.getUpdateDAO(dsName).updateBySQLWithArgs(sql, idVal);
} else {
for (int i = 0; i < tarList.size(); i++) {
Object tarObj = tarList.get(i);
if (tarObj == null)
continue;
// 检查是否该对象真的与主对象有关联且存在数据库
// select * from {tarTable} where {tarIdColumn} =
// {tarIdVal} and {column} = {idVal}
String format = "select * from %s where %s = ? and %s = ? ";
ReflectUtil tarRu = new ReflectUtil(tarObj);
String tarIdColumn = ORMConfigBeanUtil
.getIdColumn(tarClass);
String tarIdField = ORMConfigBeanUtil.getIdField(tarClass);
Method tarIdGetter = tarRu.getGetter(tarIdField);
if (tarIdGetter == null)
throw new DAOException("can not find tarIdGetter.",
null);
Object tarIdValObj = null;
try {
tarIdValObj = tarIdGetter.invoke(tarObj);
} catch (Exception e) {
throw new DAOException(tarIdGetter
+ " invoke exception ", e);
}
if (tarIdValObj == null)
continue;