forked from nutzam/nutz
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: http://nutz.googlecode.com/svn/trunk@2086 423f10f2-e3a4-11dd-a6ea-a32d6b26a33d
- Loading branch information
Showing
6 changed files
with
144 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/org/nutz/dao/impl/sql/pojo/UpdateFieldsByChainPItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.nutz.dao.impl.sql.pojo; | ||
|
||
import org.nutz.dao.Chain; | ||
import org.nutz.dao.entity.Entity; | ||
import org.nutz.dao.entity.MappingField; | ||
import org.nutz.dao.jdbc.Jdbcs; | ||
import org.nutz.dao.jdbc.ValueAdaptor; | ||
import org.nutz.lang.Lang; | ||
|
||
public class UpdateFieldsByChainPItem extends AbstractPItem { | ||
|
||
private Chain chain; | ||
|
||
public UpdateFieldsByChainPItem(Chain chain) { | ||
this.chain = chain; | ||
} | ||
|
||
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()); | ||
} | ||
} | ||
|
||
public int joinAdaptor(Entity<?> en, ValueAdaptor[] adaptors, int off) { | ||
Chain c = chain.head(); | ||
while (c != null) { | ||
MappingField mf = en.getField(c.name()); | ||
adaptors[off++] = (null == mf ? Jdbcs.getAdaptorBy(c.value()) : mf.getAdaptor()); | ||
c = c.next(); | ||
} | ||
return off; | ||
} | ||
|
||
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; | ||
} | ||
|
||
public int paramCount(Entity<?> en) { | ||
return chain.size(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.