Skip to content

Commit

Permalink
fix: 为 #1294 添加testcase并改进实现逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wendal committed Apr 1, 2018
1 parent 29082c7 commit 7ca405a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/org/nutz/dao/impl/EntityOperator.java
Expand Up @@ -9,6 +9,7 @@
import org.nutz.dao.FieldMatcher;
import org.nutz.dao.entity.Entity;
import org.nutz.dao.entity.MappingField;
import org.nutz.dao.entity.PkType;
import org.nutz.dao.impl.sql.pojo.AbstractPItem;
import org.nutz.dao.impl.sql.pojo.ConditionPItem;
import org.nutz.dao.impl.sql.pojo.InsertByChainPItem;
Expand Down Expand Up @@ -89,17 +90,20 @@ public Pojo addUpdateByPkAndCnd(Condition cnd) {
public Pojo addUpdateByPkAndCnd(final Entity<?> en, final Object obj, final Condition cnd) {
if (null == en)
return null;

Pojo pojo = dao.pojoMaker.makeUpdate(en, null)
.append(Pojos.Items.cndAuto(en, Lang.first(obj)))
.setOperatingObject(obj);
pojo.append(new Static(" AND "));
Pojo pojo = dao.pojoMaker.makeUpdate(en, null);

boolean pureCnd = en.getPkType() == PkType.UNKNOWN;
if (!pureCnd) {
pojo.append(Pojos.Items.cndAuto(en, Lang.first(obj)));
pojo.append(new Static(" AND "));
}
if (cnd instanceof Criteria) {
// 只取它的where条件
pojo.append(((Criteria)cnd).where().setTop(false));
pojo.append(((Criteria)cnd).where().setTop(pureCnd));
} else {
pojo.append(new ConditionPItem(cnd).setTop(false));
pojo.append(new ConditionPItem(cnd).setTop(pureCnd));
}
pojo.setOperatingObject(obj);
pojoList.add(pojo);
return pojo;
}
Expand Down
18 changes: 18 additions & 0 deletions test/org/nutz/dao/test/normal/SimpleDaoTest.java
Expand Up @@ -1194,4 +1194,22 @@ public void test_cnd_clone2() {
// 克隆的cndCloned应该不受影响
assertEquals(t, dao.count(Pet.class, cndCloned));
}

@Test
public void test_issue_1294() {
dao.clear(Pet.class);
dao.insert(Pet.create("wendal"));
Record re = new Record();
re.put(".table", "t_pet");
re.put("*name", "wendal");
re.put("age", 30);
dao.update(re, Cnd.where("age", ">", -100));
assertEquals(30, dao.fetch(Pet.class).getAge());

re = new Record();
re.put(".table", "t_pet");
re.put("age", 31);
dao.update(re, Cnd.where("age", ">", -100));
assertEquals(31, dao.fetch(Pet.class).getAge());
}
}

0 comments on commit 7ca405a

Please sign in to comment.