}
}
Object[] args = new Object[orm.columnFields.length];
for(int i=0; i<orm.columnFields.length; i++){
ColumnField field = orm.columnFields[i];
sql1 += field.getName() + ",";
sql2 += "?,";
args[i] = OrmInfo.getFieldValue(c, field.getName(), obj);
}
String sql = sql1.substring(0,sql1.length()-1)+") " + sql2.substring(0,sql2.length()-1)+")";
int updated = execute(sql, args);
//获得自增长值
if (orm.idGeneratorType != GeneratorType.SEQUENCE){
if (adapter != null){
Object id = executeScalar(adapter.getIdentitySelectString(), null);
id = ConvertUtil.castFromObject(id.toString(), orm.idType);
OrmInfo.setFieldValue(c, orm.id, obj, id);
}
else{
String selectMaxSql = "select max(" + orm.id + ") from " + orm.table;
Object maxId = executeScalar(selectMaxSql, null);
maxId = ConvertUtil.castFromObject(maxId, orm.idType);
OrmInfo.setFieldValue(c, orm.id, obj, maxId);
}
}
OrmInfo.setFieldValue(ActiveRecordBase.class, "isnewrecord", obj, false);
return updated;
}
else{
String sql1 = "insert into " + orm.table + "(";
String sql2 = "values(";
List<Object> tmpArgs = new ArrayList<Object>();
if (orm.id != null){
sql1 += orm.id + ",";
sql2 += "?,";
Object value = OrmInfo.getFieldValue(c, orm.id, obj);
tmpArgs.add(value);
}
for(ColumnField field: orm.columnFields){
sql1 += field.getName() + ",";
sql2 += "?,";
Object value = OrmInfo.getFieldValue(c, field.getName(), obj);
tmpArgs.add(value);
}
String sql = sql1.substring(0,sql1.length()-1)+") " + sql2.substring(0,sql2.length()-1)+")";
Object[] args = tmpArgs.toArray();