Example usage for org.springframework.jdbc.core CallableStatementCreatorFactory CallableStatementCreatorFactory

List of usage examples for org.springframework.jdbc.core CallableStatementCreatorFactory CallableStatementCreatorFactory

Introduction

In this page you can find the example usage for org.springframework.jdbc.core CallableStatementCreatorFactory CallableStatementCreatorFactory.

Prototype

public CallableStatementCreatorFactory(String callString, List<SqlParameter> declaredParameters) 

Source Link

Document

Create a new factory with the given SQL and the given parameters.

Usage

From source file:anyframe.core.query.impl.QueryServiceImpl.java

/**
 *   ? ? ?? queryId?       Stored Procedure,
 * Function ? ./*from   ww  w  .ja va2 s.  c o m*/
 * 
 * @param queryId
 *            identifier of query statement to execute
 * @param values
 *             ?     ? ? Object Array
 * @param pageIndex
 *            page_number which expected to be displayed.
 * @param pageSize
 *            page_Size which expected to be displayed per page.
 * @return Stored Procedure, Function    ? Map? List
 * @throws QueryServiceException
 *             if there is any problem issuing that query
 */
public Map execute(String queryId, Map values, int pageIndex, int pageSize) throws QueryServiceException {
    String sql = "";
    try {
        containesQueryId(queryId);
        if (pageSize == -1)
            pageSize = getSqlRepository().getFetchCountPerQuery(queryId);
        IQueryInfo queryInfo = (IQueryInfo) getSqlRepository().getQueryInfos().get(queryId);

        sql = queryInfo.getQueryString();
        List paramList = queryInfo.getSqlParameterList();
        CallableStatementCreator callableStatementCreator = new CallableStatementCreatorFactory(sql, paramList)
                .newCallableStatementCreator(values);
        return jdbcTemplate.call(callableStatementCreator, paramList);
    } catch (Exception e) {
        throw processException("execute statement [query id = '" + queryId + "']", sql, e);
    }
}

From source file:anyframe.core.query.impl.QueryServiceImpl.java

public Map executeBySQL(String sql, String[] paramTypeNames, String[] paramBindingNames,
        String[] paramBindingTypes, Map values, int pageIndex, int pageSize) throws QueryServiceException {
    try {/*from   ww  w .jav a2  s .  c o m*/
        List paramList = SQLTypeTransfer.getSqlParameterList(paramTypeNames, paramBindingTypes,
                paramBindingNames);

        CallableStatementCreator callableStatementCreator = new CallableStatementCreatorFactory(sql, paramList)
                .newCallableStatementCreator(values);
        return jdbcTemplate.call(callableStatementCreator, paramList);
    } catch (Exception e) {
        throw processException("execute by SQL", sql, e);
    }
}

From source file:architecture.ee.jdbc.sqlquery.factory.impl.SqlQueryImpl.java

public Object call(String statement, Object... parameters) {
    BoundSql sql = getBoundSql(statement);

    List<SqlParameter> declaredParameters = new ArrayList<SqlParameter>();
    Map<String, Object> paramsToUse = new HashMap<String, Object>();

    //  ?? ? INPUT  OUTPU ? .

    for (ParameterMapping mapping : sql.getParameterMappings()) {

        mapping.getProperty();//  www .ja  v  a 2s. com
        mapping.getJdbcType();
        mapping.getMode();

        if (mapping.getMode() == ParameterMapping.Mode.IN) {

            SqlParameter input = new SqlParameter(mapping.getProperty(), mapping.getJdbcType().ordinal());
            declaredParameters.add(input);
            paramsToUse.put(mapping.getProperty(), parameters[mapping.getIndex() - 1]);

        } else if (mapping.getMode() == ParameterMapping.Mode.OUT) {
            SqlOutParameter output = new SqlOutParameter(mapping.getProperty(),
                    mapping.getJdbcType().ordinal());
            declaredParameters.add(output);
        }
    }

    CallableStatementCreatorFactory callableStatementFactory = new CallableStatementCreatorFactory(sql.getSql(),
            declaredParameters);
    return jdbcTemplate.call(callableStatementFactory.newCallableStatementCreator(paramsToUse),
            declaredParameters);

}

From source file:org.springframework.jdbc.core.simple.AbstractJdbcCall.java

/**
 * Delegate method to perform the actual compilation.
 * <p>Subclasses can override this template method to perform their own compilation.
 * Invoked after this base class's compilation is complete.
 *//*from  ww  w  .ja va 2 s .  c om*/
protected void compileInternal() {
    DataSource dataSource = getJdbcTemplate().getDataSource();
    Assert.state(dataSource != null, "No DataSource set");
    this.callMetaDataContext.initializeMetaData(dataSource);

    // Iterate over the declared RowMappers and register the corresponding SqlParameter
    for (Map.Entry<String, RowMapper<?>> entry : this.declaredRowMappers.entrySet()) {
        SqlParameter resultSetParameter = this.callMetaDataContext
                .createReturnResultSetParameter(entry.getKey(), entry.getValue());
        this.declaredParameters.add(resultSetParameter);
    }
    this.callMetaDataContext.processParameters(this.declaredParameters);

    this.callString = this.callMetaDataContext.createCallString();
    if (logger.isDebugEnabled()) {
        logger.debug("Compiled stored procedure. Call string is [" + this.callString + "]");
    }

    this.callableStatementFactory = new CallableStatementCreatorFactory(this.callString,
            this.callMetaDataContext.getCallParameters());

    onCompileInternal();
}