Java Code Examples for net.sf.jsqlparser.expression.LongValue

The following examples show how to use net.sf.jsqlparser.expression.LongValue. These examples are extracted from open source projects. 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 Project: spanner-jdbc   Author: olavloite   File: AbstractSpannerExpressionVisitorAdapter.java    License: MIT License 6 votes vote down vote up
@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 #2
Source Project: sql-to-mongo-db-query-converter   Author: vincentrussell   File: SqlUtils.java    License: Apache License 2.0 6 votes vote down vote up
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 #3
Source Project: SpringBootLearn   Author: LiHaodong888   File: MyTenantHandler.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 租户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 #4
Source Project: pre   Author: LiHaodong888   File: PreTenantHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 租户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 Project: herddb   Author: diennea   File: SQLRecordPredicate.java    License: Apache License 2.0 5 votes vote down vote up
static boolean isConstant(Expression exp) {
    return exp instanceof StringValue
            || exp instanceof LongValue
            || exp instanceof NullValue
            || exp instanceof TimestampValue
            || exp instanceof JdbcParameter;
}
 
Example #6
Source Project: foxtrot   Author: Flipkart   File: QueryUtils.java    License: Apache License 2.0 5 votes vote down vote up
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 #7
@Override
public LongValue toJSqlParserExpression(IntegerOrLongExpression expression) {
    return new LongValue(expression.getValue());
}
 
Example #8
@Override
public IntegerOrLongExpression fromJSqlParserExpression(LongValue expression) {
    return null;
}
 
Example #9
@Override
public Class<LongValue> getJSqlParserExpressionClass() {
    return LongValue.class;
}
 
Example #10
Source Project: DataPermissionHelper   Author: holyliao   File: ExpressionVisitorImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void visit(LongValue longValue) {
}
 
Example #11
Source Project: spanner-jdbc   Author: olavloite   File: AbstractTablePartWorker.java    License: MIT License 4 votes vote down vote up
@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 #12
Source Project: spanner-jdbc   Author: olavloite   File: AbstractSpannerExpressionVisitorAdapter.java    License: MIT License 4 votes vote down vote up
@Override
public void visit(LongValue value) {
  setValue(value.getValue(), Types.BIGINT);
}
 
Example #13
Source Project: spanner-jdbc   Author: olavloite   File: DMLWhereClauseVisitor.java    License: MIT License 4 votes vote down vote up
@Override
public void visit(LongValue value) {
  visitExpression(col, value);
}
 
Example #14
Source Project: herddb   Author: diennea   File: DDLSQLPlanner.java    License: Apache License 2.0 4 votes vote down vote up
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 #15
Source Project: genericdao   Author: lp895876294   File: SqlServer.java    License: Artistic License 2.0 4 votes vote down vote up
/**
 * 获取一个外层包装的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 #16
Source Project: quetzal   Author: Quetzal-RDF   File: CTEToNestedQueryConverter.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void visit(LongValue longValue) {
	clear();
	defaultTopLevelProcessing(longValue);
}
 
Example #17
Source Project: Mybatis-PageHelper   Author: pagehelper   File: SqlServerParser.java    License: MIT License 4 votes vote down vote up
/**
 * 获取一个外层包装的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;
}