net.sf.jsqlparser.expression.StringValue Java Examples
The following examples show how to use
net.sf.jsqlparser.expression.StringValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlUtils.java From sql-to-mongo-db-query-converter with Apache License 2.0 | 6 votes |
private static RegexFunction getRegexFunction(Function function) throws ParseException { final String column = getStringValue(function.getParameters().getExpressions().get(0)); final String regex = fixDoubleSingleQuotes( ((StringValue) (function.getParameters().getExpressions().get(1))).getValue()); try { Pattern.compile(regex); } catch (PatternSyntaxException e) { throw new ParseException(e.getMessage()); } RegexFunction regexFunction = new RegexFunction(column, regex); if (function.getParameters().getExpressions().size() == 3 && StringValue.class .isInstance(function.getParameters().getExpressions().get(2))) { regexFunction.setOptions( ((StringValue) (function.getParameters().getExpressions().get(2))).getValue()); } return regexFunction; }
Example #2
Source File: SqlUtils.java From sql-to-mongo-db-query-converter with Apache License 2.0 | 6 votes |
public static DateFunction isDateFunction(Expression incomingExpression) throws ParseException { if (ComparisonOperator.class.isInstance(incomingExpression)) { ComparisonOperator comparisonOperator = (ComparisonOperator)incomingExpression; String rightExpression = getStringValue(comparisonOperator.getRightExpression()); if (Function.class.isInstance(comparisonOperator.getLeftExpression())) { Function function = ((Function)comparisonOperator.getLeftExpression()); if ("date".equals(function.getName().toLowerCase()) && (function.getParameters().getExpressions().size()==2) && StringValue.class.isInstance(function.getParameters().getExpressions().get(1))) { String column = getStringValue(function.getParameters().getExpressions().get(0)); DateFunction dateFunction = null; try { dateFunction = new DateFunction(((StringValue)(function.getParameters().getExpressions().get(1))).getValue(),rightExpression,column); dateFunction.setComparisonFunction(comparisonOperator); } catch (IllegalArgumentException e) { throw new ParseException(e.getMessage()); } return dateFunction; } } } return null; }
Example #3
Source File: SqlUtils.java From sql-to-mongo-db-query-converter with Apache License 2.0 | 6 votes |
public static Object getValue(Expression incomingExpression, Expression otherSide, FieldType defaultFieldType, Map<String, FieldType> fieldNameToFieldTypeMapping) throws ParseException { FieldType fieldType = otherSide !=null ? firstNonNull(fieldNameToFieldTypeMapping.get(getStringValue(otherSide)), defaultFieldType) : FieldType.UNKNOWN; if (LongValue.class.isInstance(incomingExpression)) { return normalizeValue((((LongValue)incomingExpression).getValue()),fieldType); } else if (SignedExpression.class.isInstance(incomingExpression)) { return normalizeValue((((SignedExpression)incomingExpression).toString()),fieldType); } else if (StringValue.class.isInstance(incomingExpression)) { return normalizeValue((((StringValue)incomingExpression).getValue()),fieldType); } else if (Column.class.isInstance(incomingExpression)) { return normalizeValue(getStringValue(incomingExpression),fieldType); } else { throw new ParseException("can not parseNaturalLanguageDate: " + incomingExpression.toString()); } }
Example #4
Source File: QueryUtils.java From foxtrot with Apache License 2.0 | 5 votes |
public static Number expressionToNumber(Expression expression) { if(expression instanceof StringValue) { return Long.valueOf(((StringValue)expression).getValue()); } if(expression instanceof LongValue) { return ((LongValue)expression).getValue(); } if(expression instanceof DoubleValue) { return ((DoubleValue)expression).getValue(); } return null; }
Example #5
Source File: TenantAutoConfigure.java From microservices-platform with Apache License 2.0 | 5 votes |
@Bean public TenantHandler tenantHandler() { return new TenantHandler() { /** * 获取租户id */ @Override public Expression getTenantId(boolean where) { String tenant = TenantContextHolder.getTenant(); if (tenant != null) { return new StringValue(TenantContextHolder.getTenant()); } return new NullValue(); } /** * 获取租户列名 */ @Override public String getTenantIdColumn() { return "tenant_id"; } /** * 过滤不需要根据租户隔离的表 * @param tableName 表名 */ @Override public boolean doTableFilter(String tableName) { return tenantProperties.getIgnoreTables().stream().anyMatch( (e) -> e.equalsIgnoreCase(tableName) ); } }; }
Example #6
Source File: QueryUtils.java From foxtrot with Apache License 2.0 | 5 votes |
public static String expressionToString(Expression expression) { if(expression instanceof Column) { return ((Column)expression).getFullyQualifiedName(); } if(expression instanceof StringValue) { return ((StringValue)expression).getValue(); } return null; }
Example #7
Source File: SQLRecordPredicate.java From herddb with Apache License 2.0 | 5 votes |
static boolean isConstant(Expression exp) { return exp instanceof StringValue || exp instanceof LongValue || exp instanceof NullValue || exp instanceof TimestampValue || exp instanceof JdbcParameter; }
Example #8
Source File: SqlUtils.java From sql-to-mongo-db-query-converter with Apache License 2.0 | 5 votes |
public static String getStringValue(Expression expression) { if (StringValue.class.isInstance(expression)) { return ((StringValue)expression).getValue(); } else if (Column.class.isInstance(expression)) { String columnName = expression.toString(); Matcher matcher = SURROUNDED_IN_QUOTES.matcher(columnName); if (matcher.matches()) { return matcher.group(1); } return columnName; } return expression.toString(); }
Example #9
Source File: DDLSQLPlanner.java From herddb with Apache License 2.0 | 4 votes |
private static Object resolveValue(Expression expression, boolean allowColumn) throws StatementExecutionException { if (expression instanceof JdbcParameter) { throw new StatementExecutionException("jdbcparameter expression not usable in this query"); } else if (allowColumn && expression instanceof net.sf.jsqlparser.schema.Column) { // this is only for supporting back ticks in DDL return fixMySqlBackTicks(((net.sf.jsqlparser.schema.Column) expression).getColumnName()); } else if (expression instanceof StringValue) { return ((StringValue) expression).getValue(); } else if (expression instanceof LongValue) { return ((LongValue) expression).getValue(); } else if (expression instanceof TimestampValue) { return ((TimestampValue) expression).getValue(); } else if (expression instanceof SignedExpression) { SignedExpression se = (SignedExpression) expression; switch (se.getSign()) { case '+': { return resolveValue(se.getExpression(), allowColumn); } case '-': { Object value = resolveValue(se.getExpression(), allowColumn); if (value == null) { return null; } if (value instanceof Integer) { return -1L * ((Integer) value); } else if (value instanceof Long) { return -1L * ((Long) value); } else { throw new StatementExecutionException( "unsupported value type " + expression.getClass() + " with sign " + se.getSign() + " on value " + value + " of type " + value. getClass()); } } default: throw new StatementExecutionException( "unsupported value type " + expression.getClass() + " with sign " + se.getSign()); } } else { throw new StatementExecutionException("unsupported value type " + expression.getClass()); } }
Example #10
Source File: CTEToNestedQueryConverter.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(StringValue stringValue) { clear(); defaultTopLevelProcessing(stringValue); }
Example #11
Source File: ObjPD.java From openprodoc with GNU Affero General Public License v3.0 | 4 votes |
private Conditions EvalExpr(Expression ParentExpr ) throws PDException { Conditions New = new Conditions(); int ExprType= EvalExprType(ParentExpr); //System.out.println("ParentExpr=["+ParentExpr+"] Type="+ExprType); switch (ExprType) { case EXPR_BASIC: ComparisonOperator CO = (ComparisonOperator) ParentExpr; String Left=CO.getLeftExpression().toString(); String Comp=CO.getStringExpression(); String Right=CO.getRightExpression().toString(); if (isField(Left) && isField(Right)) New.addCondition(new Condition(Left, Right)); else { String FieldName; Object Value; int TypeVal; if (isField(Left)) { FieldName=Left; Value=CalcVal(Right); TypeVal=CalcTypeVal(Right); } else { FieldName=Right; Value=CalcVal(Left); TypeVal=CalcTypeVal(Left); } // System.out.println("Value="+Value+" class="+Value.getClass().getName()); New.addCondition(new Condition(FieldName, getCompConv().get(Comp), Value, TypeVal)); } break; case EXPR_NOT: Conditions Cs=EvalExpr(((NotExpression) ParentExpr).getExpression()); Cs.setInvert(true); New.addCondition(Cs); break; case EXPR_AND: New.addCondition(EvalExpr(((AndExpression) ParentExpr).getLeftExpression() )); New.addCondition(EvalExpr(((AndExpression) ParentExpr).getRightExpression() )); break; case EXPR_OR: New.addCondition(EvalExpr(((OrExpression) ParentExpr).getLeftExpression() )); New.addCondition(EvalExpr(((OrExpression) ParentExpr).getRightExpression() )); New.setOperatorAnd(false); break; case EXPR_PAR: New.addCondition(EvalExpr(((Parenthesis) ParentExpr).getExpression() )); break; case EXPR_IN: String FieldNameIn=((InExpression)ParentExpr).getLeftExpression().toString(); HashSet<String> ListTerms = new HashSet<String>(); List<Expression> LT =((ExpressionList)((InExpression)ParentExpr).getLeftItemsList()).getExpressions(); for (Iterator<Expression> iterator = LT.iterator(); iterator.hasNext();) { StringValue NextTerm = (StringValue)iterator.next(); ListTerms.add(NextTerm.getValue()); } New.addCondition(new Condition(FieldNameIn,ListTerms)); break; case EXPR_FUNCT: String Arg=((Function)ParentExpr).getParameters().getExpressions().get(0).toString(); switch (((Function)ParentExpr).getName()) { case Condition.CONTAINS: New.addCondition(Condition.genContainsCond(PDDocs.getTableName(),Arg, getDrv())); break; case Condition.INTREE: New.addCondition(Condition.genInTreeCond( Arg, getDrv())); break; case Condition.INFOLDER: New.addCondition(Condition.genInFolder(Arg, getDrv())); break; } break; } return(New); }
Example #12
Source File: StringExpressionConverter.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
@Override public StringValue toJSqlParserExpression(StringExpression expression) { return new StringValue(expression.getValue()); }
Example #13
Source File: DMLWhereClauseVisitor.java From spanner-jdbc with MIT License | 4 votes |
@Override public void visit(StringValue value) { visitExpression(col, value); }
Example #14
Source File: AbstractSpannerExpressionVisitorAdapter.java From spanner-jdbc with MIT License | 4 votes |
@Override public void visit(StringValue value) { setValue(value.getValue(), Types.NVARCHAR); }
Example #15
Source File: ExpressionVisitorImpl.java From DataPermissionHelper with Apache License 2.0 | 4 votes |
@Override public void visit(StringValue stringValue) { }
Example #16
Source File: StringExpressionConverter.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Class<StringValue> getJSqlParserExpressionClass() { return StringValue.class; }
Example #17
Source File: StringExpressionConverter.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
@Override public StringExpression fromJSqlParserExpression(StringValue expression) { return null; }
Example #18
Source File: BladeTenantHandler.java From blade-tool with GNU Lesser General Public License v3.0 | 2 votes |
/** * 获取租户ID * * @return 租户ID */ @Override public Expression getTenantId(boolean where) { return new StringValue(Func.toStr(SecureUtil.getTenantId(), TenantConstant.DEFAULT_TENANT_ID)); }