Search in sources :

Example 1 with DaoStatement

use of org.nutz.dao.sql.DaoStatement in project nutz by nutzam.

the class DaoLogInterceptor method filter.

public void filter(DaoInterceptorChain chain) throws DaoException {
    DaoStatement statement = chain.getDaoStatement();
    if (statement != null) {
        NutDaoExecutor.printSQL(statement);
    }
    chain.doChain();
}
Also used : DaoStatement(org.nutz.dao.sql.DaoStatement)

Example 2 with DaoStatement

use of org.nutz.dao.sql.DaoStatement in project nutz by nutzam.

the class NutDao method func2.

public Object func2(Class<?> classOfT, String func2Name, String colName, Condition cnd) {
    Entity<?> en = holder.getEntity(classOfT);
    if (null != en.getField(colName))
        colName = en.getField(colName).getColumnNameInSql();
    DaoStatement pojo = pojoMaker.makeFunc(en.getViewName(), func2Name, colName).append(Pojos.Items.cnd(cnd)).setAfter(_pojo_fetchObject).setEntity(en);
    _exec(pojo);
    return pojo.getResult();
}
Also used : DaoStatement(org.nutz.dao.sql.DaoStatement)

Example 3 with DaoStatement

use of org.nutz.dao.sql.DaoStatement in project nutz by nutzam.

the class NutDao method func.

public int func(String tableName, String funcName, String colName, Condition cnd) {
    DaoStatement pojo = pojoMaker.makeFunc(tableName, funcName, colName).append(Pojos.Items.cnd(cnd)).setAfter(_pojo_fetchInt);
    _exec(pojo);
    return pojo.getInt();
}
Also used : DaoStatement(org.nutz.dao.sql.DaoStatement)

Example 4 with DaoStatement

use of org.nutz.dao.sql.DaoStatement in project nutz by nutzam.

the class NutDaoExecutor method _runStatement.

private void _runStatement(Connection conn, DaoStatement st) throws SQLException {
    boolean statIsClosed = false;
    Statement stat = null;
    String sql = st.toPreparedStatement();
    try {
        stat = conn.createStatement();
        stat.execute(sql);
        st.getContext().setUpdateCount(stat.getUpdateCount());
        st.onAfter(conn, null, stat);
        stat.close();
        statIsClosed = true;
    } finally {
        if (!statIsClosed)
            Daos.safeClose(stat);
    }
    // 打印更详细的调试信息
    if (log.isTraceEnabled())
        log.trace("...DONE");
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) DaoStatement(org.nutz.dao.sql.DaoStatement)

Example 5 with DaoStatement

use of org.nutz.dao.sql.DaoStatement in project nutz by nutzam.

the class DaoInterceptorChain method invoke.

/**
     * 这是DaoExecutor会执行的方法,拦截器内不要执行这个方法!! 这里也是拦截器开始生效的地方.
     */
public void invoke(Connection conn) throws Exception {
    for (DaoStatement st : sts) {
        if (st == null) {
            if (log.isInfoEnabled())
                log.info("Found a null DaoStatement(SQL), ingore it ~~");
            continue;
        }
        current = 0;
        daoStatement = st;
        this.connection = conn;
        doChain();
    }
}
Also used : DaoStatement(org.nutz.dao.sql.DaoStatement)

Aggregations

DaoStatement (org.nutz.dao.sql.DaoStatement)11 CallableStatement (java.sql.CallableStatement)2 PreparedStatement (java.sql.PreparedStatement)2 Statement (java.sql.Statement)2 DaoInterceptorChain (org.nutz.dao.DaoInterceptorChain)2 Method (java.lang.reflect.Method)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DataSource (javax.sql.DataSource)1 Test (org.junit.Test)1 DaoException (org.nutz.dao.DaoException)1 DaoExecutor (org.nutz.dao.impl.DaoExecutor)1 NutDao (org.nutz.dao.impl.NutDao)1 SimpleDataSource (org.nutz.dao.impl.SimpleDataSource)1 ValueAdaptor (org.nutz.dao.jdbc.ValueAdaptor)1 Pager (org.nutz.dao.pager.Pager)1 Atom (org.nutz.trans.Atom)1 Transaction (org.nutz.trans.Transaction)1