org.apache.ibatis.jdbc.SqlRunner Maven / Gradle / Ivy
/**
* Copyright 2009-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeHandlerRegistry;
/**
* @author Clinton Begin
*/
public class SqlRunner {
public static final int NO_GENERATED_KEY = Integer.MIN_VALUE + 1001;
private final Connection connection;
private final TypeHandlerRegistry typeHandlerRegistry;
private boolean useGeneratedKeySupport;
public SqlRunner(Connection connection) {
this.connection = connection;
this.typeHandlerRegistry = new TypeHandlerRegistry();
}
public void setUseGeneratedKeySupport(boolean useGeneratedKeySupport) {
this.useGeneratedKeySupport = useGeneratedKeySupport;
}
/*
* Executes a SELECT statement that returns one row.
*
* @param sql The SQL
* @param args The arguments to be set on the statement.
* @return The row expected.
* @throws SQLException If less or more than one row is returned
*/
public Map selectOne(String sql, Object... args) throws SQLException {
List