org.yx.db.mapper.RawExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sumk Show documentation
Show all versions of sumk Show documentation
A quick developing framewort for internet company
/**
* Copyright (C) 2016 - 2030 youtongluan.
*
* 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.yx.db.mapper;
import java.util.List;
import java.util.Map;
import org.yx.db.sql.InsertResult;
import org.yx.db.sql.RawSqlBuilder;
import org.yx.db.visit.Visitors;
import org.yx.exception.SumkException;
/**
* 以?为占位符的原生sql。推荐通过常量或其它方式引用
* sql的参数支持以List的方式传入
*
* @author 游夏
*
*/
public class RawExecutor {
/**
* @param sql
* 以?为占位符的原生sql。
* @param params
* 参数
* @return sql执行结果
*/
public static int execute(String sql, Object... params) {
try {
return Visitors.modifyVisitor.visit(new RawSqlBuilder(sql, params));
} catch (Exception e) {
throw SumkException.create(e);
}
}
/**
* 这个方法用于需要获取自增长主键的值的情况
*
* @param sql
* 以?为占位符的原生sql。
* @param params
* 参数
* @return sql执行结果
*/
public static InsertResult insertWithAutoGeneratedKeys(String sql, Object... params) {
try {
return Visitors.insertWithAutoGeneratedKeysVisitor.visit(new RawSqlBuilder(sql, params));
} catch (Exception e) {
throw SumkException.create(e);
}
}
/**
* @param sql
* 以?为占位符的原生sql
* @param params
* 参数
* @return 结果集
*/
public static List