org.yx.db.mapper.NamedExecutor 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.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.yx.db.sql.InsertResult;
import org.yx.db.sql.MapedSql;
import org.yx.db.sql.SqlBuilder;
import org.yx.db.visit.Visitors;
import org.yx.exception.SumkException;
/**
* 这里的sql,占位符不是?,而是#{**},里面的name,与map的key要一一对应,忽略大小写
* 大小写敏感
*
* @author 游夏
*
*/
public final class NamedExecutor {
private static class InnerSqlBuilder implements SqlBuilder {
private final Map map;
private final SqlParser sqlParser;
InnerSqlBuilder(SqlParser sql, Map map) {
this.sqlParser = sql;
this.map = map == null ? Collections.emptyMap() : new HashMap<>(map);
}
@Override
public MapedSql toMapedSql() throws Exception {
return sqlParser.toMapedSql(map);
}
}
private static InnerSqlBuilder createSqlBuilder(SqlParser sql, Map map) {
return new InnerSqlBuilder(sql, map);
}
public static int execute(SqlParser sql, Map map) {
try {
return Visitors.modifyVisitor.visit(createSqlBuilder(sql, map));
} catch (Exception e) {
throw SumkException.wrap(e);
}
}
public static InsertResult insertWithAutoGeneratedKeys(SqlParser sql, Map map) {
try {
return Visitors.insertWithAutoGeneratedKeysVisitor.visit(createSqlBuilder(sql, map));
} catch (Exception e) {
throw SumkException.wrap(e);
}
}
public static List
© 2015 - 2024 Weber Informatics LLC | Privacy Policy