All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yx.db.mapper.RawExecutor Maven / Gradle / Ivy

There is a newer version: 4.0.2
Show newest version
/**
 * 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> list(String sql, Object... params) { try { return Visitors.queryVisitor.visit(new RawSqlBuilder(sql, params)); } catch (Exception e) { throw SumkException.create(e); } } /** * @param sql * 以?为占位符的原生sql * @param params * 参数 * @return 结果集 */ public static List listInOrder(String sql, Object... params) { try { return Visitors.arrayListQueryVisitor.visit(new RawSqlBuilder(sql, params)); } catch (Exception e) { throw SumkException.create(e); } } /** * 只有一个列的list方法
* sum等函数是特殊的singleColumnList,它返回的list的size为1 * * @param sql * 以?为占位符的原生sql * @param params * 参数 * @return 结果集 */ public static List singleColumnList(String sql, Object... params) { try { return Visitors.singleListQueryVisitor.visit(new RawSqlBuilder(sql, params)); } catch (Exception e) { throw SumkException.create(e); } } /** * @param sql * 以?为占位符的原生sql * @param params * 参数 * @return 记录数 */ public static int count(String sql, Object... params) { try { List list = Visitors.singleListQueryVisitor.visit(new RawSqlBuilder(sql, params)); Number n = (Number) list.get(0); return n.intValue(); } catch (Exception e) { throw SumkException.create(e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy