net.sf.jsqlparser.expression.LongValue Java Examples
The following examples show how to use
net.sf.jsqlparser.expression.LongValue.
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 |
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 #2
Source File: AbstractSpannerExpressionVisitorAdapter.java From spanner-jdbc with MIT License | 6 votes |
@Override public void visit(SignedExpression value) { Expression underlyingValue = value.getExpression(); if (underlyingValue instanceof DoubleValue) { DoubleValue doubleValue = (DoubleValue) underlyingValue; doubleValue .setValue(value.getSign() == '-' ? -doubleValue.getValue() : doubleValue.getValue()); visit(doubleValue); } else if (underlyingValue instanceof LongValue) { LongValue longValue = (LongValue) underlyingValue; longValue.setValue(value.getSign() == '-' ? -longValue.getValue() : longValue.getValue()); visit(longValue); } else { super.visit(value); } }
Example #3
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 #4
Source File: PreTenantHandler.java From pre with GNU General Public License v3.0 | 5 votes |
/** * 租户Id * * @return */ @Override public Expression getTenantId(boolean where) { Long tenantId = PreTenantContextHolder.getCurrentTenantId(); log.debug("当前租户为{}", tenantId); if (tenantId == null) { return new NullValue(); } return new LongValue(tenantId); }
Example #5
Source File: MyTenantHandler.java From SpringBootLearn with Apache License 2.0 | 5 votes |
/** * 租户Id * * @return */ @Override public Expression getTenantId() { // 从当前系统上下文中取出当前请求的服务商ID,通过解析器注入到SQL中。 Long tenantId = apiContext.getCurrentTenantId(); log.debug("当前租户为{}", tenantId); if (tenantId == null) { return new NullValue(); } return new LongValue(tenantId); }
Example #6
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 #7
Source File: AbstractSpannerExpressionVisitorAdapter.java From spanner-jdbc with MIT License | 4 votes |
@Override public void visit(LongValue value) { setValue(value.getValue(), Types.BIGINT); }
Example #8
Source File: SqlServerParser.java From Mybatis-PageHelper with MIT License | 4 votes |
/** * 获取一个外层包装的TOP查询 * * @param select * @return */ protected Select getPageSelect(Select select) { SelectBody selectBody = select.getSelectBody(); if (selectBody instanceof SetOperationList) { selectBody = wrapSetOperationList((SetOperationList) selectBody); } //这里的selectBody一定是PlainSelect if (((PlainSelect) selectBody).getTop() != null) { throw new PageException("被分页的语句已经包含了Top,不能再通过分页插件进行分页查询!"); } //获取查询列 List<SelectItem> selectItems = getSelectItems((PlainSelect) selectBody); //对一层的SQL增加ROW_NUMBER() List<SelectItem> autoItems = new ArrayList<SelectItem>(); SelectItem orderByColumn = addRowNumber((PlainSelect) selectBody, autoItems); //加入自动生成列 ((PlainSelect) selectBody).addSelectItems(autoItems.toArray(new SelectItem[autoItems.size()])); //处理子语句中的order by processSelectBody(selectBody, 0); //中层子查询 PlainSelect innerSelectBody = new PlainSelect(); //PAGE_ROW_NUMBER innerSelectBody.addSelectItems(orderByColumn); innerSelectBody.addSelectItems(selectItems.toArray(new SelectItem[selectItems.size()])); //将原始查询作为内层子查询 SubSelect fromInnerItem = new SubSelect(); fromInnerItem.setSelectBody(selectBody); fromInnerItem.setAlias(PAGE_TABLE_ALIAS); innerSelectBody.setFromItem(fromInnerItem); //新建一个select Select newSelect = new Select(); PlainSelect newSelectBody = new PlainSelect(); //设置top Top top = new Top(); top.setExpression(new LongValue(Long.MAX_VALUE)); newSelectBody.setTop(top); //设置order by List<OrderByElement> orderByElements = new ArrayList<OrderByElement>(); OrderByElement orderByElement = new OrderByElement(); orderByElement.setExpression(PAGE_ROW_NUMBER_COLUMN); orderByElements.add(orderByElement); newSelectBody.setOrderByElements(orderByElements); //设置where GreaterThan greaterThan = new GreaterThan(); greaterThan.setLeftExpression(PAGE_ROW_NUMBER_COLUMN); greaterThan.setRightExpression(new LongValue(Long.MIN_VALUE)); newSelectBody.setWhere(greaterThan); //设置selectItems newSelectBody.setSelectItems(selectItems); //设置fromIterm SubSelect fromItem = new SubSelect(); fromItem.setSelectBody(innerSelectBody); //中层子查询 fromItem.setAlias(PAGE_TABLE_ALIAS); newSelectBody.setFromItem(fromItem); newSelect.setSelectBody(newSelectBody); if (isNotEmptyList(select.getWithItemsList())) { newSelect.setWithItemsList(select.getWithItemsList()); } return newSelect; }
Example #9
Source File: CTEToNestedQueryConverter.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(LongValue longValue) { clear(); defaultTopLevelProcessing(longValue); }
Example #10
Source File: SqlServer.java From genericdao with Artistic License 2.0 | 4 votes |
/** * 获取一个外层包装的TOP查询 * * @param select * @return */ private Select getPageSelect(Select select, String orderBy) { SelectBody selectBody = select.getSelectBody(); if (selectBody instanceof SetOperationList) { selectBody = wrapSetOperationList((SetOperationList) selectBody); } //这里的selectBody一定是PlainSelect if (((PlainSelect) selectBody).getTop() != null) { throw new RuntimeException("被分页的语句已经包含了Top,不能再通过分页插件进行分页查询!"); } //获取查询列 List<SelectItem> selectItems = getSelectItems((PlainSelect) selectBody); //对一层的SQL增加ROW_NUMBER() addRowNumber((PlainSelect) selectBody, orderBy); //处理子语句中的order by processSelectBody(selectBody, 0); //新建一个select Select newSelect = new Select(); PlainSelect newSelectBody = new PlainSelect(); //设置top Top top = new Top(); top.setRowCount(Long.MAX_VALUE); newSelectBody.setTop(top); //设置order by List<OrderByElement> orderByElements = new ArrayList<OrderByElement>(); OrderByElement orderByElement = new OrderByElement(); orderByElement.setExpression(PAGE_ROW_NUMBER_COLUMN); orderByElements.add(orderByElement); newSelectBody.setOrderByElements(orderByElements); //设置where GreaterThan greaterThan = new GreaterThan(); greaterThan.setLeftExpression(PAGE_ROW_NUMBER_COLUMN); greaterThan.setRightExpression(new LongValue(Long.MIN_VALUE)); newSelectBody.setWhere(greaterThan); //设置selectItems newSelectBody.setSelectItems(selectItems); //设置fromIterm SubSelect fromItem = new SubSelect(); fromItem.setSelectBody(selectBody); fromItem.setAlias(PAGE_TABLE_ALIAS); newSelectBody.setFromItem(fromItem); newSelect.setSelectBody(newSelectBody); if (isNotEmptyList(select.getWithItemsList())) { newSelect.setWithItemsList(select.getWithItemsList()); } return newSelect; }
Example #11
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 #12
Source File: DMLWhereClauseVisitor.java From spanner-jdbc with MIT License | 4 votes |
@Override public void visit(LongValue value) { visitExpression(col, value); }
Example #13
Source File: AbstractTablePartWorker.java From spanner-jdbc with MIT License | 4 votes |
@VisibleForTesting String createCountQuery(Select select, long batchSize) { Limit limit = new Limit(); limit.setRowCount(new LongValue(batchSize)); return String.format("SELECT COUNT(*) AS C FROM ((%s)%s) Q", select, limit); }
Example #14
Source File: ExpressionVisitorImpl.java From DataPermissionHelper with Apache License 2.0 | 4 votes |
@Override public void visit(LongValue longValue) { }
Example #15
Source File: IntegerOrLongValueExpressionConverter.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
@Override public Class<LongValue> getJSqlParserExpressionClass() { return LongValue.class; }
Example #16
Source File: IntegerOrLongValueExpressionConverter.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
@Override public IntegerOrLongExpression fromJSqlParserExpression(LongValue expression) { return null; }
Example #17
Source File: IntegerOrLongValueExpressionConverter.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
@Override public LongValue toJSqlParserExpression(IntegerOrLongExpression expression) { return new LongValue(expression.getValue()); }