NutzCN Logo
问答 saveOrUpdate方法问题
发布于 2618天前 作者 Rekoe 2409 次浏览 复制 上一个帖子 下一个帖子
标签:

现在这个方法只有update没有insert的情况了

[14:31:15:629] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 284111 | 1505293028000 | 3257 | 52605 | 76d48da8-6486-4b5f-a261-0d45f7ea4f9f |
  For example:> "UPDATE dump_data SET res_id='284111',push_time=1505293028000,converted=3257,successful=52605  WHERE id='76d48da8-6486-4b5f-a261-0d45f7ea4f9f'"
21 回复
dao.insertOrUpdate(dd, null, FieldFilter.create(DumpData.class, FieldMatcher.simple("converted", "successful", "resId", "pushTime")));
			
mysql> select * from dump_data where id = '76d48da8-6486-4b5f-a261-0d45f7ea4f9f';
Empty set (0.00 sec)

mysql>

起码有个select的语句吧?

select 是我数据库查询的

执行过程就是先查询,然后决定insert还是update

我说日志里面, 没有select的日志出来?

@wendal 没看到select只有update

对 日志里没有select 只有update

pojo类贴出来看看

看了看代码, 如果Pojo只有@Name,没有@Id, 然后@Name的属性是null的情况下,才不会出现select的日志

[14:57:55:580] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 284111 | 1505293028000 | 3257 | 52605 | 76d48da8-6486-4b5f-a261-0d45f7ea4f9f |
  For example:> "UPDATE dump_data SET res_id='284111',push_time=1505293028000,converted=3257,successful=52605  WHERE id='76d48da8-6486-4b5f-a261-0d45f7ea4f9f'"
[14:57:55:881] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 283907 | 1505290904000 | 1485 | 73431 | 5c7febd1-be1e-44dc-95e1-c9347941e914 |
  For example:> "UPDATE dump_data SET res_id='283907',push_time=1505290904000,converted=1485,successful=73431  WHERE id='5c7febd1-be1e-44dc-95e1-c9347941e914'"
[14:57:56:159] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |     4 |                                    5 |
    |--------|---------------|-----|-------|--------------------------------------|
    | 283468 | 1505290376000 | 608 | 14714 | 0de5f116-3f30-494a-9d7d-4f6f014a4a59 |
  For example:> "UPDATE dump_data SET res_id='283468',push_time=1505290376000,converted=608,successful=14714  WHERE id='0de5f116-3f30-494a-9d7d-4f6f014a4a59'"
[14:57:56:452] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 284013 | 1505288326000 | 6128 | 87032 | 3d0eea29-4b72-4fc0-b7e9-cc720b46085c |
  For example:> "UPDATE dump_data SET res_id='284013',push_time=1505288326000,converted=6128,successful=87032  WHERE id='3d0eea29-4b72-4fc0-b7e9-cc720b46085c'"
[14:57:56:750] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |      4 |                                    5 |
    |--------|---------------|------|--------|--------------------------------------|
    | 283881 | 1505280519000 | 7923 | 192420 | 233ca81d-dd5c-4ddc-aaad-484a63f32deb |
  For example:> "UPDATE dump_data SET res_id='283881',push_time=1505280519000,converted=7923,successful=192420  WHERE id='233ca81d-dd5c-4ddc-aaad-484a63f32deb'"
[14:57:57:078] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 283745 | 1505279936000 | 1398 | 16683 | 24f4b165-1d72-4b48-b5f4-f2f0771bd479 |
  For example:> "UPDATE dump_data SET res_id='283745',push_time=1505279936000,converted=1398,successful=16683  WHERE id='24f4b165-1d72-4b48-b5f4-f2f0771bd479'"
[14:57:57:374] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 283091 | 1505279556000 | 1145 | 11017 | 8bbc5c26-fe68-440e-8582-c3b9872fb2cf |
  For example:> "UPDATE dump_data SET res_id='283091',push_time=1505279556000,converted=1145,successful=11017  WHERE id='8bbc5c26-fe68-440e-8582-c3b9872fb2cf'"
[14:57:57:693] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |   4 |                                    5 |
    |--------|---------------|-----|-----|--------------------------------------|
    | 283045 | 1505278997000 | 120 | 598 | 2bf96be9-1645-4f0e-bf7d-a402f7f14ec6 |
  For example:> "UPDATE dump_data SET res_id='283045',push_time=1505278997000,converted=120,successful=598  WHERE id='2bf96be9-1645-4f0e-bf7d-a402f7f14ec6'"
[14:57:57:976] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |    4 |                                    5 |
    |--------|---------------|-----|------|--------------------------------------|
    | 283173 | 1505278273000 | 300 | 2075 | e75b7f2c-e03c-423b-a455-17debff22241 |
  For example:> "UPDATE dump_data SET res_id='283173',push_time=1505278273000,converted=300,successful=2075  WHERE id='e75b7f2c-e03c-423b-a455-17debff22241'"
[14:57:58:276] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |    4 |                                    5 |
    |--------|---------------|-----|------|--------------------------------------|
    | 283469 | 1505277784000 | 854 | 6291 | df642a40-a554-4daf-bb80-04ee50e7ef56 |
package com.mysada.bean;

import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Comment;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;
import org.nutz.dao.entity.annotation.TableMeta;

@Table("dump_data")
@TableMeta("{'mysql-charset':'utf8mb4'}")
public class DumpData extends BasePojo {

	private static final long serialVersionUID = 1969165949550249069L;

	@Name
	private String id;

	@Column(hump = true)
	private String resId;

	@Column(hump = true)
	private long pushTime;

	@Column
	@Comment("打开推送")
	private long converted;

	@Column
	@Comment("收到推送")
	private long successful;

	@Column
	private String title;

	@Column("is_modify")
	private boolean modify;

	@Column
	private String category;

	@Column
	private String area;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getResId() {
		return resId;
	}

	public void setResId(String resId) {
		this.resId = resId;
	}

	public long getPushTime() {
		return pushTime;
	}

	public void setPushTime(long pushTime) {
		this.pushTime = pushTime;
	}

	public long getConverted() {
		return converted;
	}

	public void setConverted(long converted) {
		this.converted = converted;
	}

	public long getSuccessful() {
		return successful;
	}

	public void setSuccessful(long successful) {
		this.successful = successful;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public boolean isModify() {
		return modify;
	}

	public void setModify(boolean modify) {
		this.modify = modify;
	}

	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}

}

我重现看看

@Name没有值才查询

            if (val == null && fetch(obj.getClass(), Cnd.where(mf.getName(), "=", val)) == null) {
                insert(t, insertFieldFilter);
            } else {
                update(t, updateFieldFilter);
            }

我貌似知道了

把testcase加上了, 固化下来

  For example:> "UPDATE dump_data SET push_time=1505328124000,converted=5,successful=373  WHERE id='a829da0b-dce7-423b-a159-7bd3a428a2a6'"
[15:21:34:544] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |     4 |                                    5 |
    |--------|---------------|-----|-------|--------------------------------------|
    | 283468 | 1505290376000 | 609 | 14714 | 0de5f116-3f30-494a-9d7d-4f6f014a4a59 |
  For example:> "UPDATE dump_data SET res_id='283468',push_time=1505290376000,converted=609,successful=14714  WHERE id='0de5f116-3f30-494a-9d7d-4f6f014a4a59'"
[15:21:34:655] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |    4 |                                    5 |
    |--------|---------------|-----|------|--------------------------------------|
    | 283469 | 1505277784000 | 854 | 6291 | df642a40-a554-4daf-bb80-04ee50e7ef56 |
  For example:> "UPDATE dump_data SET res_id='283469',push_time=1505277784000,converted=854,successful=6291  WHERE id='df642a40-a554-4daf-bb80-04ee50e7ef56'"
[15:21:35:158] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |    4 |                                    5 |
    |--------|---------------|-----|------|--------------------------------------|
    | 283173 | 1505278273000 | 301 | 2075 | e75b7f2c-e03c-423b-a455-17debff22241 |
  For example:> "UPDATE dump_data SET res_id='283173',push_time=1505278273000,converted=301,successful=2075  WHERE id='e75b7f2c-e03c-423b-a455-17debff22241'"
[15:21:35:830] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |    3 |     4 |                                    5 |
    |--------|---------------|------|-------|--------------------------------------|
    | 284111 | 1505293028000 | 3258 | 52605 | 76d48da8-6486-4b5f-a261-0d45f7ea4f9f |
  For example:> "UPDATE dump_data SET res_id='284111',push_time=1505293028000,converted=3258,successful=52605  WHERE id='76d48da8-6486-4b5f-a261-0d45f7ea4f9f'"
[15:21:35:842] [DEBUG] - org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) - UPDATE dump_data SET res_id=?,push_time=?,converted=?,successful=?  WHERE id=?
    |      1 |             2 |   3 |     4 |                                    5 |
    |--------|---------------|-----|-------|--------------------------------------|
    | 283429 | 1505297002000 | 527 | 14699 | a138e46c-e262-405b-8f2e-cf5c47fdf47a |
  For example:> "UPDATE dump_data SET res_id='283429',push_time=1505297002000,converted=527,successful=14699  WHERE id='a138e46c-e262-405b-8f2e-cf5c47fdf47a'"

好了 没事了

添加回复
请先登陆
回到顶部