public class NutSql extends NutStatement implements Sql
| Modifier and Type | Field and Description |
|---|---|
protected SqlCallback |
callback |
protected Map<String,ValueAdaptor> |
customValueAdaptor |
protected List<PItem> |
items |
protected VarIndex |
paramIndex |
protected VarSet |
params |
protected char[] |
placeholder |
protected List<VarSet> |
rows |
protected String |
sourceSql |
protected VarIndex |
varIndex |
protected VarSet |
vars |
expert| Constructor and Description |
|---|
NutSql(String source) |
NutSql(String source,
SqlCallback callback) |
| Modifier and Type | Method and Description |
|---|---|
protected int |
_params_count() |
void |
addBatch()
将当前的参数列表存储,以便执行批处理
|
Sql |
changePlaceholder(char param,
char var)
修改原有的占位符(默认是$和@),并重新解析.仅作用于当前SQL对象
|
void |
clearBatch()
清除所有的曾经设置过的参数
|
Sql |
duplicate() |
ValueAdaptor[] |
getAdaptors()
为本语句每一个参数提供一个适配器
|
Record |
getOutParams()
获取存储过程的出参
|
Object[][] |
getParamMatrix()
用一个矩阵描述语句的参数表。
这个参数矩阵将同 getAdaptors() 的返回组合使用 |
String |
getSourceSql()
获取原始SQL
|
protected SqlLiteral |
literal()
若需要定制参数字符和变量字符,覆盖本方法,通过SqlLiteral的构造方法指定之
|
void |
onAfter(Connection conn,
ResultSet rs,
Statement stmt)
语句执行完毕的后续操作
|
void |
onBefore(Connection conn)
语句执行之前的操作
|
VarIndex |
paramIndex() |
VarSet |
params()
所谓"参数",就是当 Sql 对象转换成 PreparedStatement 对象前,会被填充成 ? 的占位符
|
Sql |
setCallback(SqlCallback callback)
当前 Statement 被执行完毕后,有可能会产生一个 ResultSet。 针对这个 ResultSet 你可以执行更多的操作。
|
Sql |
setCondition(Condition cnd)
为 SQL 增加条件,SQL 必须有 '$condition' 变量
|
Sql |
setEntity(Entity<?> entity)
设置 当前语句对应的实体
|
DaoStatement |
setPager(Pager pager)
为自定义SQL设置Pager
如果设置为非空值,那么将附加上分页语句!!
由于不带SQL语法分析,无法探知用户是否已经自行添加分页语句!!
使用这个功能,你就不要自己在SQL里面写limit了!!!
|
Sql |
setParam(String name,
Object value)
sql.params().set(name, value)的链式调用方式
|
void |
setSourceSql(String sql)
设置原始SQL,将重新解析里面的占位符
|
void |
setValueAdaptor(String name,
ValueAdaptor adaptor)
手动为某个语句参数设置适配器。
|
Sql |
setVar(String name,
Object value)
sql.vars().set(name, value)的链式调用方式
|
String |
toPreparedStatement()
将 Dao 语句转换为 JDBC SQL 缓冲语句
|
VarIndex |
varIndex() |
VarSet |
vars()
所谓"变量",就是当 Sql 对象转换成 Statement 对象前,预先被填充的占位符。
|
forceExecQuery, forPrint, getAdapterBy, getBoolean, getContext, getDouble, getDouble, getEntity, getFloat, getFloat, getInt, getInt, getList, getLong, getLong, getNumber, getObject, getResult, getSqlType, getString, getUpdateCount, isAlter, isCall, isCreate, isDelete, isDrop, isExec, isForceExecQuery, isInsert, isOther, isRun, isSelect, isUpdate, param2String, setContext, setExpert, setSqlType, toExampleStatement, toStatement, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforceExecQuery, forPrint, getBoolean, getContext, getDouble, getDouble, getEntity, getFloat, getFloat, getInt, getInt, getList, getLong, getLong, getNumber, getObject, getResult, getSqlType, getString, getUpdateCount, isAlter, isCall, isCreate, isDelete, isDrop, isExec, isForceExecQuery, isInsert, isOther, isRun, isSelect, isUpdate, setExpert, toStringprotected String sourceSql
protected VarSet vars
protected VarSet params
protected SqlCallback callback
protected VarIndex varIndex
protected VarIndex paramIndex
protected Map<String,ValueAdaptor> customValueAdaptor
protected char[] placeholder
public NutSql(String source)
public NutSql(String source, SqlCallback callback)
public void setSourceSql(String sql)
SqlsetSourceSql in interface Sqlprotected int _params_count()
public ValueAdaptor[] getAdaptors()
DaoStatementgetAdaptors in interface DaoStatementpublic Object[][] getParamMatrix()
DaoStatement矩阵的每一行相当于执行一条语句
参数表的下标意义为: Object[行][列]
getParamMatrix in interface DaoStatementpublic String toPreparedStatement()
DaoStatementtoPreparedStatement in interface DaoStatementpublic void onBefore(Connection conn) throws SQLException
DaoStatement这个接口函数你基本不会直接使用的
onBefore in interface DaoStatementconn - 当前执行语句的连接SQLExceptionpublic void onAfter(Connection conn, ResultSet rs, Statement stmt) throws SQLException
DaoStatement这个接口函数你基本不会直接使用的
onAfter in interface DaoStatementconn - 当前执行语句的连接rs - 当前语句执行的结果集stmt - TODOSQLException - 回调函数抛出的异常public DaoStatement setPager(Pager pager)
DaoStatementsetPager in interface DaoStatementpublic VarSet vars()
Sql这个集合允许你为 SQL 的变量占位符设值
public VarSet params()
Sql
集合是一个个的名值对,你设置了值的地方,会在执行时,被设置到 PreparedStatement中。
这样省却了你一个一个计算 ? 位置的烦恼
public void setValueAdaptor(String name, ValueAdaptor adaptor)
Sql
默认的,Sql 的实现类会自动根据你设置的值,自动为所有的参数设置适配器。
但是,有些时候,你可能传入了 null 值或者其他的特殊对象,
这里允许你主动为其设置一个适配器,这样你就有了终极手段最合理的适配你的参数对象
setValueAdaptor in interface Sqlname - 对应参数的名称adaptor - 适配器实例public VarIndex varIndex()
public VarIndex paramIndex()
paramIndex in interface Sqlpublic void addBatch()
Sqlpublic void clearBatch()
SqlclearBatch in interface Sqlpublic Sql setEntity(Entity<?> entity)
DaoStatementsetEntity in interface DaoStatementsetEntity in interface SqlsetEntity in class NutStatemententity - 实体public Sql setCallback(SqlCallback callback)
Sql
当然如果不是 SELECT 语句,那么你依然可以设置一个回调,
当你的语句执行完毕后, 会调用它(Connection 不会被 commit),但是 ResultSet 参数会是 null
setCallback in interface Sqlcallback - 回调函数public Sql setCondition(Condition cnd)
SqlsetCondition in interface Sqlcnd - 条件public Sql duplicate()
public String getSourceSql()
SqlgetSourceSql in interface Sqlprotected SqlLiteral literal()
public Sql setParam(String name, Object value)
SqlsetParam in interface Sqlname - 参数名称value - 参数值Sql.params()public Sql setVar(String name, Object value)
SqlsetVar in interface Sqlname - 变量名称value - 变量值Sql.vars()public Record getOutParams()
SqlgetOutParams in interface Sqlpublic Sql changePlaceholder(char param, char var)
SqlchangePlaceholder in interface Sqlparam - 参数占位符,默认是@var - 变量占位符,默认是$Copyright © 2017. All rights reserved.