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

com.jaregu.database.queries.compiling.OptionalSlashNamedParameterFeature Maven / Gradle / Ivy

Go to download

Java based SQL templating project. Store your queries in *.sql files and build queries for execution. Supports simple expressions and conditional clauses and interface proxying for java-sql bridge.

There is a newer version: 1.4.1
Show newest version
package com.jaregu.database.queries.compiling;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

import com.jaregu.database.queries.building.ParameterBinder;
import com.jaregu.database.queries.compiling.expr.ExpressionParser;
import com.jaregu.database.queries.parsing.ParsedQueryPart;

/**
 * Matches parameter line
 * 

* Example: * *

 * ...
 *  AND t.SOME_FIELD = 123 /* value_expression[; conditional_expression] */ [some additional SQL]
 * ...
 * 
* * Expression is something for what * {@link ExpressionParser#isLikeExpression(String)} is true */ final class OptionalSlashNamedParameterFeature extends OptionalNamedParameterFeatureBase { private final List> _const_comment_sql_ = Arrays.asList(isSqlWithoutNewLine, isSlashCommentExpression, isSQL); private final List> _question_comment_sql_ = Arrays.asList(isAnonymousVariable, isSlashCommentExpression, isSQL); private final List> _question_sql_comment_sql_ = Arrays .asList(isAnonymousVariable, isSqlWithoutNewLine, isSlashCommentExpression, isSQL); private final List> _sql_question_comment_sql_ = Arrays .asList(isSqlWithoutNewLine, isAnonymousVariable, isSlashCommentExpression, isSQL); private final List> _sql_question_sql_comment_sql_ = Arrays .asList(isSqlWithoutNewLine, isAnonymousVariable, isSqlWithoutNewLine, isSlashCommentExpression, isSQL); OptionalSlashNamedParameterFeature(ExpressionParser expressionParser, ParameterBinder parameterBinder) { super(expressionParser, parameterBinder); } @Override public boolean isCompilable(Source source) { return isPartsLike(source, _const_comment_sql_) || isPartsLike(source, _question_comment_sql_) || isPartsLike(source, _question_sql_comment_sql_) || isPartsLike(source, _sql_question_comment_sql_) || isPartsLike(source, _sql_question_sql_comment_sql_); } @Override public Result compile(Source source, Compiler compiler) { Builder builder; if (isPartsLike(source, _const_comment_sql_)) { builder = new Builder(source).before(0, true).after(1, 2).comment(1); } else if (isPartsLike(source, _question_comment_sql_)) { builder = new Builder(source).after(1, 2).comment(1); } else if (isPartsLike(source, _question_sql_comment_sql_)) { builder = new Builder(source).after(1, 2, 3).comment(2); } else if (isPartsLike(source, _sql_question_comment_sql_)) { builder = new Builder(source).before(0).after(2, 3).comment(2); } else if (isPartsLike(source, _sql_question_sql_comment_sql_)) { builder = new Builder(source).before(0).after(2, 3, 4).comment(3); } else { throw new QueryCompileException("Wrong parts count!"); } return builder.build(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy