private String makeSQL(T t, String[] fields) throws SqlCreateException {
Class<?> clazz = t.getClass();
String table = ORMConfigBeanUtil.getTable(clazz);
StringBuilder condition = new StringBuilder();
StringBuilder values = new StringBuilder();
ReflectUtil ru = new ReflectUtil(t);
String[] columns = ORMConfigBeanUtil.getColumns(clazz, fields);
String idColumn = ORMConfigBeanUtil.getIdColumn(clazz);
String idField = ORMConfigBeanUtil.getIdField(clazz);
Method idGetter = ru.getGetter(idField);
if (idGetter == null)
throw new SqlCreateException("can not find id getter.");
try {
condition.append(idColumn).append(" = '")
.append(idGetter.invoke(t)).append("'");
} catch (Exception e) {
throw new SqlCreateException(idGetter + " invoke exception "
+ e.toString());
}
for (int i = 0; i < fields.length; i++) {
String field = fields[i];
String column = columns[i];
Method getter = ru.getGetter(field);
if (getter == null)
continue;
try {
Object _value = getter.invoke(t);
if (_value == null)
continue;
Object value = null;
if (ClassUtil.isPojo(_value.getClass())) {
Field f = ru.getField(field);
OneToOne oneAnn = getter.getAnnotation(OneToOne.class);
if (oneAnn == null)
oneAnn = f.getAnnotation(OneToOne.class);
if (oneAnn != null) {
ReflectUtil tarRu = new ReflectUtil(_value);
String tarFKField = ORMConfigBeanUtil.getIdField(_value
.getClass());
Method tarFKGetter = tarRu.getGetter(tarFKField);
value = tarFKGetter.invoke(_value);
}
}
if (value == null)