Java 类org.springframework.jdbc.core.CallableStatementCallback 实例源码

项目:ryf_mms2    文件:SystemDao.java   
public void collect(String sql) {
    final int yesterday = DateUtil.systemDate(-1);//new RypCommon().getIntDate(-1);
    update("delete from tlog_collect where sys_date=" + yesterday);
    getJdbcTemplate().execute(sql, new CallableStatementCallback() {
        @Override
        public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
            cs.setString(1, yesterday + "");
            cs.execute();
            System.err.println("store procedure is finish");
            return null;
        }
    });
}
项目:ryf_mms2    文件:SystemDao.java   
public void dailyCollect(String sql) {
    getJdbcTemplate().execute(sql, new CallableStatementCallback() {
        @Override
        public Object doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
            cs.execute();
            System.err.println("store procedure is finish");
            return null;
        }
    });
}
项目:Camel    文件:CallableStatementWrapper.java   
@Override
public int[] executeBatch() throws SQLException {

    if (this.batchItems == null) {
        throw new IllegalArgumentException("Batch must have at least one item");
    }

    final Iterator<Map<String, ?>> params = batchItems.iterator();


    return factory.getJdbcTemplate().execute(new CallableStatementCreator() {
        @Override
        public CallableStatement createCallableStatement(Connection connection) throws SQLException {
            return batchFactory.newCallableStatementCreator(params.next()).createCallableStatement(connection);

        }
    }, new CallableStatementCallback<int[]>() {
        @Override
        public int[] doInCallableStatement(CallableStatement callableStatement) throws SQLException, DataAccessException {
            //add first item to batch
            callableStatement.addBatch();

            while (params.hasNext()) {
                batchFactory.addParameter(callableStatement, params.next());
                callableStatement.addBatch();
            }
            return callableStatement.executeBatch();
        }
    });
}
项目:egd-web    文件:ReportDB.java   
public List<Map<String, ?>> getTofuTranslatedByUser(String uuid) {

        String sql = "{? = call core.f_tofu_translated_by_user(?)}";

        CustomCallableStatementCreator sc = new CustomCallableStatementCreator(sql) {
            public CallableStatement createCallableStatement(Connection con) throws SQLException {
                con.setAutoCommit(false);
                CallableStatement s = super.createCallableStatement(con);
                s.registerOutParameter(1, Types.OTHER);//cursor
                s.setString(2, uuid);
                return s;
            }
        };

        CallableStatementCallback<List<Map<String, ?>>> cb = s -> {
            s.execute();
            ResultSet rs = (ResultSet) s.getObject(1);

            List<Map<String, ?>> result = new ArrayList<>();

            while (rs.next()) {
                Map<String, Object> item = new HashMap<>();
                item.put("id", rs.getInt("id"));
                item.put("word", rs.getString("word"));
                item.put("sentence", rs.getString("sentence"));
                item.put("lang", rs.getString("lang"));
                item.put("translation", rs.getString("translation"));

                result.add(item);
            }
            return result;
        };
        return execute(sc, cb);
    }
项目:egd-web    文件:ReportDB.java   
public List<Map<String, ?>> getTranslatedEntrRatio() {

        String sql = "{? = call public.f_jmet_entr_gloss_ratio()}";

        CustomCallableStatementCreator sc = new CustomCallableStatementCreator(sql) {
            public CallableStatement createCallableStatement(Connection con) throws SQLException {
                con.setAutoCommit(false);
                CallableStatement s = super.createCallableStatement(con);
                s.registerOutParameter(1, Types.OTHER);//cursor
                return s;
            }
        };

        CallableStatementCallback<List<Map<String, ?>>> cb = s -> {
            s.execute();
            ResultSet rs = (ResultSet) s.getObject(1);

            List<Map<String, ?>> result = new ArrayList<>();
            Map<String, Object> item;
            while (rs.next()) {
                item = new LinkedHashMap<>();

                item.put("countGloss", rs.getInt(1));
                item.put("sumCount", rs.getInt(2));
                item.put("sumRatio", rs.getFloat(3));

                result.add(item);
            }

            rs.close();
            return result;
        };
        return execute(sc, cb);
    }
项目:buffer-slayer    文件:BatchJdbcTemplate.java   
public <T> T execute(CallableStatementCreator csc,
    CallableStatementCallback<T> action) throws DataAccessException {
  return delegate.execute(csc, action);
}
项目:buffer-slayer    文件:BatchJdbcTemplate.java   
public <T> T execute(String callString,
    CallableStatementCallback<T> action) throws DataAccessException {
  return delegate.execute(callString, action);
}
项目:jbpm4ssh    文件:AbstractDaoSupport.java   
public Object callProcedure(final String callStr, final Object[] inValues,
        final int[] outTypes) {
    return getJdbcTemplate().execute(callStr,
            new CallableStatementCallback() {
                @SuppressWarnings("unchecked")
                public Object doInCallableStatement(CallableStatement cs)
                        throws SQLException {
                    int i = 0;
                    if (inValues != null) {
                        for (int index = 0; index < inValues.length; index++) {
                            i++;

                            Object inValue = inValues[index];
                            if (inValue instanceof StringBuffer
                                    || inValue instanceof StringWriter) {
                                cs.setString(i, inValue.toString());
                            } else if ((inValue instanceof java.util.Date)
                                    && !(inValue instanceof java.sql.Date
                                            || inValue instanceof java.sql.Time || inValue instanceof java.sql.Timestamp)) {
                                cs.setTimestamp(i, new java.sql.Timestamp(
                                        ((java.util.Date) inValue)
                                                .getTime()));
                            } else if (inValue instanceof Calendar) {
                                Calendar cal = (Calendar) inValue;
                                cs.setTimestamp(i, new java.sql.Timestamp(
                                        cal.getTime().getTime()));
                            } else {
                                // Fall back to generic setObject call
                                // without SQL type specified.
                                cs.setObject(i, inValue);
                            }
                        }
                    }
                    if (outTypes != null) {
                        for (int index = 0; index < outTypes.length; index++) {
                            i++;
                            cs.registerOutParameter(i, outTypes[index]);
                        }
                    }

                    boolean retVal = cs.execute();
                    int updateCount = cs.getUpdateCount();

                    if (retVal || updateCount != -1) {
                        // Map returnedResults = new HashMap();
                        // returnedResults.putAll(extractReturnedResultSets(cs,
                        // declaredParameters, updateCount));
                    }
                    if (outTypes == null || outTypes.length <= 0) {
                        return null;
                    } else if (outTypes.length == 1) {
                        return cs.getObject(i);
                    } else {
                        List results = new ArrayList();
                        // 依次返回结果
                        for (int index = 0; index < outTypes.length; index++) {
                            results.add(cs.getObject(inValues.length
                                    + index + 1));

                        }
                        return results;
                    }

                }
            });
}
项目:jbpm4ssh    文件:AbstractDaoSupport.java   
public Object callFunction(final String callStr, final Object[] inValues,
        final int[] outTypes) {
    return getJdbcTemplate().execute(callStr,
            new CallableStatementCallback() {
                @SuppressWarnings("unchecked")
                public Object doInCallableStatement(CallableStatement cs)
                        throws SQLException {
                    int i = 0;
                    if (outTypes != null) {
                        for (int index = 0; index < outTypes.length; index++) {
                            i++;
                            cs.registerOutParameter(i, outTypes[index]);
                        }
                    }

                    if (inValues != null) {
                        for (int index = 0; index < inValues.length; index++) {
                            i++;
                            // StatementCreatorUtils.setParameterValue(cs,
                            // i,
                            // Integer.MIN_VALUE, null,
                            // inValues[index]);
                            Object inValue = inValues[index];
                            if (inValue instanceof StringBuffer
                                    || inValue instanceof StringWriter) {
                                cs.setString(i, inValue.toString());
                            } else if ((inValue instanceof java.util.Date)
                                    && !(inValue instanceof java.sql.Date
                                            || inValue instanceof java.sql.Time || inValue instanceof java.sql.Timestamp)) {
                                cs.setTimestamp(i, new java.sql.Timestamp(
                                        ((java.util.Date) inValue)
                                                .getTime()));
                            } else if (inValue instanceof Calendar) {
                                Calendar cal = (Calendar) inValue;
                                cs.setTimestamp(i, new java.sql.Timestamp(
                                        cal.getTime().getTime()));
                            } else {
                                // Fall back to generic setObject call
                                // without SQL type specified.
                                cs.setObject(i, inValue);
                            }
                        }
                    }

                    boolean retVal = cs.execute();
                    int updateCount = cs.getUpdateCount();

                    if (retVal || updateCount != -1) {
                        // Map returnedResults = new HashMap();
                        // returnedResults.putAll(extractReturnedResultSets(cs,
                        // declaredParameters, updateCount));
                    }
                    if (outTypes == null || outTypes.length <= 0) {
                        return null;
                    } else if (outTypes.length == 1) {
                        return cs.getObject(1);
                    } else {
                        List results = new ArrayList();
                        // 依次返回结果
                        for (int index = 0; index < outTypes.length; index++) {
                            results.add(cs.getObject(index + 1));

                        }
                        return results;
                    }

                }
            });
}
项目:kratos-1    文件:KratosJdbcTemplate.java   
@Override
public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException {

    return super.execute(csc, action);
}
项目:kratos-1    文件:KratosJdbcTemplate.java   
@Override
public <T> T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException {

    return super.execute(callString, action);
}
项目:appBack    文件:BaseBusinessBO.java   
/**
 *
 * 调用存储过程统一用这个方法
 */
public Object executePRC(String callString,CallableStatementCallback callback) {
    return getJdbcTemplate().execute(callString, callback);
}
项目:appBack    文件:BaseBusinessBO.java   
/** 调用指定数据源中的存储过程
 * 
 * @param callString
 * @param callback
 * @return
 */
public Object executePRC(String dataSourceName, String callString,CallableStatementCallback callback) {

    DataSource dataSource = DataSourceUtils.findDataSource(dataSourceName);
    return getJdbcTemplate(dataSource).execute(callString, callback);
}