org.redkalex.source.parser.DataNativeJsqlParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redkale-plugins Show documentation
Show all versions of redkale-plugins Show documentation
Redkale-Plugins -- java framework
/*
*
*/
package org.redkalex.source.parser;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.IntFunction;
import java.util.logging.*;
import org.redkale.annotation.ResourceType;
import org.redkale.source.DataNativeSqlInfo;
import org.redkale.source.DataNativeSqlParser;
import org.redkale.source.DataNativeSqlStatement;
import org.redkale.source.RowBound;
/**
* 基于jsqlparser的DataNativeSqlParser实现类
*
* @author zhangjx
*/
@ResourceType(DataNativeSqlParser.class)
public class DataNativeJsqlParser implements DataNativeSqlParser {
protected final Logger logger = Logger.getLogger(DataNativeJsqlParser.class.getSimpleName());
private final ConcurrentHashMap parserInfo = new ConcurrentHashMap();
@Override
public DataNativeSqlInfo parse(IntFunction signFunc, String dbType, String rawSql) {
return parserInfo.computeIfAbsent(rawSql, sql -> new NativeParserInfo(sql, dbType, signFunc));
}
@Override
public DataNativeSqlStatement parse(
IntFunction signFunc,
String dbType,
String rawSql,
boolean countable,
RowBound round,
Map params) {
NativeParserInfo info = parserInfo.computeIfAbsent(rawSql, sql -> new NativeParserInfo(sql, dbType, signFunc));
NativeSqlTemplet templet = info.createTemplet(params);
if (logger.isLoggable(Level.FINER)) {
logger.log(
Level.FINER,
DataNativeSqlParser.class.getSimpleName() + " parse. rawSql: " + rawSql + ", dynamic: "
+ info.isDynamic() + ", templetSql: " + templet.getJdbcSql());
}
NativeParserNode node = info.loadParserNode(templet.getJdbcSql(), countable);
DataNativeSqlStatement statement = node.loadStatement(round, templet.getTempletParams());
if (logger.isLoggable(Level.FINE)) {
if (countable) {
logger.log(
Level.FINE,
DataNativeSqlParser.class.getSimpleName() + " parse. rawSql: " + rawSql + ", nativePageSql: "
+ statement.getNativePageSql() + ", nativeCountSql: " + statement.getNativeCountSql()
+ ", paramNames: " + statement.getParamNames());
} else {
logger.log(
Level.FINE,
DataNativeSqlParser.class.getSimpleName() + " parse. rawSql: " + rawSql + ", nativeSql: "
+ statement.getNativeSql() + ", paramNames: " + statement.getParamNames());
}
}
return statement;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy