本文整理汇总了Java中net.sf.jsqlparser.expression.Function类的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于net.sf.jsqlparser.expression包,在下文中一共展示了Function类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: countSelectItem
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
/**
* 获取jsqlparser中count的SelectItem
*
* @return
*/
private static List<SelectItem> countSelectItem() {
if (CollectionUtils.isNotEmpty(countSelectItem)) {
return countSelectItem;
}
Function function = new Function();
function.setName("COUNT");
List<Expression> expressions = new ArrayList<>();
LongValue longValue = new LongValue(1);
ExpressionList expressionList = new ExpressionList();
expressions.add(longValue);
expressionList.setExpressions(expressions);
function.setParameters(expressionList);
countSelectItem = new ArrayList<>();
SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
countSelectItem.add(selectExpressionItem);
return countSelectItem;
}
示例2: isSimpleCount
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
/**
* 是否可以用简单的count查询方式
*
* @param select
* @return
*/
public static boolean isSimpleCount(PlainSelect select) {
//包含group by的时候不可以
if (select.getGroupByColumnReferences() != null) {
return false;
}
//包含distinct的时候不可以
if (select.getDistinct() != null) {
return false;
}
for (SelectItem item : select.getSelectItems()) {
//select列中包含参数的时候不可以,否则会引起参数个数错误
if (item.toString().contains("?")) {
return false;
}
//如果查询列中包含函数,也不可以,函数可能会聚合列
if (item instanceof SelectExpressionItem) {
if (((SelectExpressionItem) item).getExpression() instanceof Function) {
return false;
}
}
}
return true;
}
示例3: isSimpleCount
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
/**
* 是否可以用简单的count查询方式
*
* @param select
* @return
*/
public boolean isSimpleCount(PlainSelect select) {
//包含group by的时候不可以
if (select.getGroupByColumnReferences() != null) {
return false;
}
//包含distinct的时候不可以
if (select.getDistinct() != null) {
return false;
}
for (SelectItem item : select.getSelectItems()) {
//select列中包含参数的时候不可以,否则会引起参数个数错误
if (item.toString().contains("?")) {
return false;
}
//如果查询列中包含函数,也不可以,函数可能会聚合列
if (item instanceof SelectExpressionItem) {
if (((SelectExpressionItem) item).getExpression() instanceof Function) {
return false;
}
}
}
return true;
}
示例4: visit
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
public void visit(Function function) {
if (function.isEscaped()) {
buffer.append(function.getCommentBeginEscaped() != null ? function.getCommentBeginEscaped() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("{fn ");
}
buffer.append(function.getCommentName() != null ? function.getCommentName() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append(function.getName());
if (function.isAllColumns()) {
buffer.append(function.getCommentBeginEscaped() != null ? function.getCommentBeginBracket() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("(").append(function.getCommentBeginEscaped() != null ? function.getCommentAllColumns() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("*").append(function.getCommentBeginEscaped() != null ? function.getCommentEndBracket() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append(")");
} else if (function.getParameters() == null) {
buffer.append(function.getCommentBeginEscaped() != null ? function.getCommentBeginBracket() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("(").append(function.getCommentEndEscaped() != null ? function.getCommentEndBracket() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append(")");
} else {
boolean oldUseBracketsInExprList = useBracketsInExprList;
if (function.isDistinct()) {
useBracketsInExprList = false;
buffer.append(function.getCommentBeginEscaped() != null ? function.getCommentBeginBracket() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("(").append(function.getCommentDistinct() != null ? function.getCommentDistinct() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("Distinct ");
}
visit(function.getParameters());
useBracketsInExprList = oldUseBracketsInExprList;
if (function.isDistinct()) {
buffer.append(function.getCommentBeginEscaped() != null ? function.getCommentEndBracket() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append(")");
}
}
if (function.isEscaped()) {
buffer.append(function.getCommentEndEscaped() != null ? function.getCommentEndEscaped() + " " + ExpressionDeParser.LINE_SEPARATOR : "").append("}");
}
}
示例5: test
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
@Test
public void test() {
Select select = select("select max(name),code,min(aa),nvl(ab,0),heh from user where a > 100");
List<SelectItem> selectItems = ((PlainSelect) select.getSelectBody()).getSelectItems();
for (SelectItem item : selectItems) {
if (item instanceof SelectExpressionItem) {
Expression exp = ((SelectExpressionItem) item).getExpression();
if (exp instanceof Function) {
System.out.println("Function:" + item.toString());
} else {
System.out.println("Not a function:" + exp.toString());
}
} else {
System.out.println("Not a function:" + item.toString());
}
}
}
示例6: removeOperations
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
public static String removeOperations(String select){
Select stmt = asStatement(select);
SelectBody selectBody = stmt.getSelectBody();
if (selectBody instanceof PlainSelect) {
PlainSelect plainSelect = (PlainSelect) selectBody;
plainSelect.getSelectItems()
.removeIf(item ->
((SelectExpressionItem)item).getExpression() instanceof Function);
}
return stmt.toString();
}
示例7: isAggregateFunction
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
private boolean isAggregateFunction(Expression expression) throws StatementExecutionException {
if (!(expression instanceof Function)) {
return false;
}
Function function = (Function) expression;
String name = function.getName().toLowerCase();
if (BuiltinFunctions.isAggregateFunction(function.getName())) {
return true;
}
if (BuiltinFunctions.isScalarFunction(function.getName())) {
return false;
}
throw new StatementExecutionException("unsupported function " + name);
}
示例8: SQLAggregator
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
public SQLAggregator(List<SelectItem> selectItems, List<Expression> groupByColumnReferences, RecordSetFactory recordSetFactory) throws StatementExecutionException {
this.recordSetFactory = recordSetFactory;
this.selectItems = selectItems;
this.groupByColumnReferences = groupByColumnReferences != null ? groupByColumnReferences : Collections.emptyList();
for (SelectItem item : selectItems) {
boolean done = false;
if (item instanceof SelectExpressionItem) {
SelectExpressionItem sei = (SelectExpressionItem) item;
Expression expression = sei.getExpression();
if (expression instanceof Function) {
Function f = (Function) expression;
if (BuiltinFunctions.isAggregateFunction(f.getName())) {
done = true;
}
} else if (expression instanceof net.sf.jsqlparser.schema.Column) {
net.sf.jsqlparser.schema.Column c = (net.sf.jsqlparser.schema.Column) expression;
for (Expression ex : this.groupByColumnReferences) {
if (ex instanceof net.sf.jsqlparser.schema.Column) {
net.sf.jsqlparser.schema.Column cex = (net.sf.jsqlparser.schema.Column) ex;
if (cex.getColumnName().equals(c.getColumnName())) {
done = true;
break;
}
}
}
}
}
if (!done) {
throw new StatementExecutionException("field " + item + " MUST appear in GROUP BY clause");
}
}
}
示例9: visit
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
@Override
public void visit(Function function) {
function.setName(function.getName().toLowerCase());
if (function.getParameters() != null) {
function.getParameters().accept(this);
}
}
示例10: toAggregatedOutputColumn
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
public static Column toAggregatedOutputColumn(String fieldName, Function f) {
if (f.getName().equalsIgnoreCase(BuiltinFunctions.COUNT)) {
return Column.column(fieldName, ColumnTypes.LONG);
}
if (f.getName().equalsIgnoreCase(BuiltinFunctions.SUM) && f.getParameters() != null && f.getParameters().getExpressions() != null && f.getParameters().getExpressions().size() == 1) {
return Column.column(fieldName, ColumnTypes.LONG);
}
if (f.getName().equalsIgnoreCase(BuiltinFunctions.MIN) && f.getParameters() != null && f.getParameters().getExpressions() != null && f.getParameters().getExpressions().size() == 1) {
return Column.column(fieldName, ColumnTypes.LONG);
}
if (f.getName().equalsIgnoreCase(BuiltinFunctions.MAX) && f.getParameters() != null && f.getParameters().getExpressions() != null && f.getParameters().getExpressions().size() == 1) {
return Column.column(fieldName, ColumnTypes.LONG);
}
return null;
}
示例11: getColumnCalculator
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
public static AggregatedColumnCalculator getColumnCalculator(Function f, String fieldName,
StatementEvaluationContext context) throws StatementExecutionException {
String functionName = f.getName();
CompiledSQLExpression firstParam = f.getParameters() == null || f.getParameters().getExpressions() == null || f.getParameters().getExpressions().isEmpty() ? null
: SQLExpressionCompiler.compileExpression(null, f.getParameters().getExpressions().get(0));
return getColumnCalculator(functionName, fieldName, firstParam, context);
}
示例12: countSelectItem
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
/**
* <p>
* 获取jsqlparser中count的SelectItem
* </p>
*/
private static List<SelectItem> countSelectItem() {
Function function = new Function();
function.setName("COUNT");
List<Expression> expressions = new ArrayList<>();
LongValue longValue = new LongValue(1);
ExpressionList expressionList = new ExpressionList();
expressions.add(longValue);
expressionList.setExpressions(expressions);
function.setParameters(expressionList);
List<SelectItem> selectItems = new ArrayList<>();
SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
selectItems.add(selectExpressionItem);
return selectItems;
}
示例13: countSelectItem
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
/**
* 获取jsqlparser中count的SelectItem
*
* @return
*/
private static List<SelectItem> countSelectItem() {
if (CollectionUtils.isNotEmpty(countSelectItem)) {
return countSelectItem;
}
Function function = new Function();
function.setName("COUNT");
List<Expression> expressions = new ArrayList<Expression>();
LongValue longValue = new LongValue(0);
ExpressionList expressionList = new ExpressionList();
expressions.add(longValue);
expressionList.setExpressions(expressions);
function.setParameters(expressionList);
countSelectItem = new ArrayList<SelectItem>();
SelectExpressionItem selectExpressionItem = new SelectExpressionItem(function);
countSelectItem.add(selectExpressionItem);
return countSelectItem;
}
示例14: getInstance
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
public static Projector getInstance(Expression expression, String alias, QueryTypeExtractor queryTypeExtractor) {
Projector instance = null;
if (expression instanceof net.sf.jsqlparser.schema.Column) {
instance = new ColumnProjector((net.sf.jsqlparser.schema.Column) expression, alias, queryTypeExtractor);
} else if (expression instanceof Function) {
instance = new FunctionProjector((Function) expression, alias, queryTypeExtractor);
} else if (expression instanceof BinaryExpression) {
instance = new BinaryExpressionProjector((BinaryExpression) expression, alias, queryTypeExtractor);
} else if (expression instanceof LongValue) {
instance = new LongProjector(expression, alias, queryTypeExtractor);
} else if (expression instanceof StringValue) {
instance = new StringProjector(expression, alias, queryTypeExtractor);
} else if (expression instanceof DoubleValue) {
instance = new DoubleProjector(expression, alias, queryTypeExtractor);
} else if (expression instanceof Parenthesis) {
instance = new ParenthesisProjector((Parenthesis) expression, queryTypeExtractor);
} else if (expression instanceof JdbcParameter) {
instance = new JdbcParameterProjector(queryTypeExtractor);
} else if (expression instanceof SubSelect) {
instance = new SubSelectProjector((SubSelect) expression, alias, queryTypeExtractor);
} else {
throw new RuntimeException("Not supported");
}
return instance;
}
示例15: visit
import net.sf.jsqlparser.expression.Function; //导入依赖的package包/类
@Override
public void visit(Function fnctn) {
if (fnctn.getParameters() != null) {
for (Iterator it = fnctn.getParameters().getExpressions().iterator(); it.hasNext();) {
((Expression) it.next()).accept(this);
}
}
}