io.odysz.transact.sql.parts.Sql Maven / Gradle / Ivy
The newest version!
package io.odysz.transact.sql.parts;
import io.odysz.common.LangExt;
import io.odysz.transact.sql.Query;
import io.odysz.transact.sql.parts.Logic.op;
import io.odysz.transact.sql.parts.antlr.ConditVisitor;
import io.odysz.transact.sql.parts.condition.Condit;
import io.odysz.transact.sql.parts.condition.ExprPart;
import io.odysz.transact.x.TransException;
/**Logic expression etc's helper */
public class Sql {
/**Create {@link Condit} from string.
* Note: '%' (like) in format must be '%%'.
* @param format e.g. on condition string in join clause.
* @param args runtime arguements
* @return Condit object
*/
public static Condit condt(String format, Object... args) {
// try format == op - user can be confused like condt("=", "f.c1", "v1");
op op = Logic.op(format);
if (op != null && args != null && args.length == 2)
return condt(op, (String)args[0], (String)args[1]);
String exp = String.format(format, args);
return parseCondit(exp);
}
private static Condit parseCondit(String exp) {
return ConditVisitor.parse(exp);
}
public static Condit condt(op op, String loperand, String roperand) {
return new Condit(op, loperand, roperand);
}
public static Condit condt(op op, String loperand, ExprPart part) {
return new Condit(op, loperand, part);
}
public static Condit condt(op op, String loperand, Query q) throws TransException {
return new Condit(op, loperand, q);
}
/**
* @since 1.4.40
* @param op
* @param lop
* @param rop
* @return condition
*/
public static Condit condt(op op, ExprPart lop, ExprPart rop) {
return new Condit(op, lop, rop);
}
/**
* @since 1.4.40
* @param op
* @param lop
* @return condition
*/
public static Condit condt(op op, ExprPart lop, String rop) {
return new Condit(op, lop, new ExprPart(rop));
}
/**Filtering out "'", replaced with "''".
* @param v
* @return replaced v
*/
public static String filterVal(String v) {
// for java regex lookahead and lookbehined, see
// https://www.logicbig.com/tutorials/core-java-tutorial/java-regular-expressions/regex-lookahead.html
// https://www.logicbig.com/tutorials/core-java-tutorial/java-regular-expressions/regex-lookbehind.html
return v == null ? null : v.replaceAll("(?
© 2015 - 2025 Weber Informatics LLC | Privacy Policy