Search in sources :

Example 1 with Chain

use of org.nutz.dao.Chain in project nutz by nutzam.

the class UpdateFieldsByChainPItem method joinParams.

public int joinParams(Entity<?> en, Object obj, Object[] params, int off) {
    Chain c = chain.head();
    while (c != null) {
        params[off++] = c.value();
        c = c.next();
    }
    return off;
}
Also used : Chain(org.nutz.dao.Chain)

Example 2 with Chain

use of org.nutz.dao.Chain in project nutz by nutzam.

the class ChainTest method test_chain_from_object.

/**
     * Issue 93
     */
@Test
public void test_chain_from_object() {
    Worker w = new Worker();
    w.age = 20;
    w.name = "zzh";
    Chain c = Chain.from(w, FieldMatcher.make("age|name", null, true));
    Map<String, Object> map = c.toMap();
    assertEquals(2, map.size());
    assertEquals("zzh", map.get("name"));
    assertEquals(20, ((Short) map.get("age")).intValue());
}
Also used : Chain(org.nutz.dao.Chain) Test(org.junit.Test)

Example 3 with Chain

use of org.nutz.dao.Chain in project nutz by nutzam.

the class EntityOperator method addInsertSelfOnly.

public Pojo addInsertSelfOnly(Entity<?> en, Object obj) {
    if (null == en)
        return null;
    Pojo pojo;
    if (obj instanceof Chain) {
        pojo = dao.pojoMaker.makePojo(SqlType.INSERT);
        pojo.append(Pojos.Items.entityTableName());
        pojo.append(new InsertByChainPItem((Chain) obj));
        pojo.setEntity(en);
    } else {
        pojo = dao.pojoMaker.makeInsert(en).setOperatingObject(obj);
    }
    pojoList.add(pojo);
    return pojo;
}
Also used : Chain(org.nutz.dao.Chain) Pojo(org.nutz.dao.sql.Pojo) InsertByChainPItem(org.nutz.dao.impl.sql.pojo.InsertByChainPItem)

Example 4 with Chain

use of org.nutz.dao.Chain in project nutz by nutzam.

the class UpdateFieldsByChainPItem method joinAdaptor.

public int joinAdaptor(Entity<?> en, ValueAdaptor[] adaptors, int off) {
    Chain c = chain.head();
    while (c != null) {
        MappingField mf = en.getField(c.name());
        // TODO 移除这种数组下标用++的写法!!!
        if (c.adaptor() == null)
            adaptors[off++] = (null == mf ? Jdbcs.getAdaptorBy(c.value()) : mf.getAdaptor());
        else
            adaptors[off++] = c.adaptor();
        c = c.next();
    }
    return off;
}
Also used : Chain(org.nutz.dao.Chain) MappingField(org.nutz.dao.entity.MappingField)

Example 5 with Chain

use of org.nutz.dao.Chain in project nutz by nutzam.

the class UpdateFieldsByChainPItem method joinSql.

public void joinSql(Entity<?> en, StringBuilder sb) {
    if (chain.size() > 0) {
        sb.append(" SET ");
        Chain c = chain.head();
        while (c != null) {
            sb.append(this._fmtcolnm(en, c.name()));
            sb.append("=? ,");
            c = c.next();
        }
        sb.deleteCharAt(sb.length() - 1);
        sb.append(' ');
    } else {
        throw Lang.makeThrow("Entity chain for UPDATE '%s'", en.getType().getName());
    }
}
Also used : Chain(org.nutz.dao.Chain)

Aggregations

Chain (org.nutz.dao.Chain)9 Test (org.junit.Test)3 MappingField (org.nutz.dao.entity.MappingField)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 ConnCallback (org.nutz.dao.ConnCallback)2 DaoException (org.nutz.dao.DaoException)2 ValueAdaptor (org.nutz.dao.jdbc.ValueAdaptor)2 InsertByChainPItem (org.nutz.dao.impl.sql.pojo.InsertByChainPItem)1 Pojo (org.nutz.dao.sql.Pojo)1