
com.gitee.qdbp.jdbc.api.SqlBufferJdbcOperations Maven / Gradle / Ivy
package com.gitee.qdbp.jdbc.api;
import java.net.URL;
import java.util.List;
import java.util.Map;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import com.gitee.qdbp.able.exception.ServiceException;
import com.gitee.qdbp.jdbc.model.DbVersion;
import com.gitee.qdbp.jdbc.plugins.DbPluginHelper;
import com.gitee.qdbp.jdbc.plugins.SqlDialect;
import com.gitee.qdbp.jdbc.sql.SqlBuffer;
import com.gitee.qdbp.tools.files.PathTools;
/**
* SqlBuffer数据库操作类
* 参考自spring-jdbc NamedParameterJdbcOperations
*
* @author 赵卉华
* @version 190601
*/
public interface SqlBufferJdbcOperations {
/**
* 获取数据库版本信息
*
* @return 数据库版本信息
*/
DbVersion dbVersion();
/**
* 获取根据数据库版本信息生成的SQL方言处理类
*
* @return SQL方言处理类
*/
SqlDialect sqlDialect();
/**
* Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This
* allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC
* environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into
* Spring's ServiceException hierarchy.
*
* The callback action can return a result object, for example a domain object or a collection of domain objects.
*
* @param sb SqlBuffer
* @param action callback object that specifies the action
* @return a result object returned by the action, or {@code null}
* @throws ServiceException if there is any problem
*/
T execute(SqlBuffer sb, PreparedStatementCallback action) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the
* ResultSet with a ResultSetExtractor.
*
* @param sb SqlBuffer
* @param rse object that will extract results
* @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws ServiceException if the query fails
*/
T query(SqlBuffer sb, ResultSetExtractor rse) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the
* ResultSet on a per-row basis with a RowCallbackHandler.
*
* @param sb SqlBuffer
* @param rch object that will extract results, one row at a time
* @throws ServiceException if the query fails
*/
void query(SqlBuffer sb, RowCallbackHandler rch) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping
* each row to a Java object via a RowMapper.
*
* @param sb SqlBuffer
* @param rowMapper object that will map one object per row
* @return the result List, containing mapped objects
* @throws ServiceException if the query fails
*/
List query(SqlBuffer sb, RowMapper rowMapper) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a
* single result row to a Java object via a RowMapper.
*
* @param sb SqlBuffer
* @param rowMapper object that will map one object per row
* @return the single mapped object
* @throws ServiceException if the query fails
*/
T queryForObject(SqlBuffer sb, RowMapper rowMapper) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a
* result object.
*
* The query is expected to be a single row/single column query; the returned result will be directly mapped to the
* corresponding object type.
*
* @param sb SqlBuffer
* @param requiredType the type that the result object is expected to match
* @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws ServiceException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
*/
T queryForObject(SqlBuffer sb, Class requiredType) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a
* result Map.
*
* The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each
* column, using the column name as the key).
*
* @param sb SqlBuffer
* @return the result Map (one entry for each column, using the column name as the key)
* @throws ServiceException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
* @see org.springframework.jdbc.core.ColumnMapRowMapper
*/
Map queryForMap(SqlBuffer sb) throws ServiceException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a
* result Map.
*
* The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each
* column, using the column name as the key).
*
* @param sb SqlBuffer
* @param rowMapper ResultSet row convert to map handler
* @return the result Map (one entry for each column, using the column name as the key)
* @throws ServiceException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForMap(String)
* @see org.springframework.jdbc.core.ColumnMapRowMapper
*/
Map queryForMap(SqlBuffer sb, RowMapper