org.springframework.expression.spel.standard.SpelExpression Java Examples

The following examples show how to use org.springframework.expression.spel.standard.SpelExpression. 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: SpelQueryCreatorUnitTests.java    From spring-data-keyvalue with Apache License 2.0 6 votes vote down vote up
private KeyValueQuery<SpelExpression> createQueryForMethodWithArgs(String methodName, Object... args)
		throws NoSuchMethodException, SecurityException {

	Class<?>[] argTypes = new Class<?>[args.length];
	if (!ObjectUtils.isEmpty(args)) {

		for (int i = 0; i < args.length; i++) {
			argTypes[i] = args[i].getClass();
		}
	}

	Method method = PersonRepository.class.getMethod(methodName, argTypes);
	doReturn(Person.class).when(metadataMock).getReturnedDomainClass(method);

	PartTree partTree = new PartTree(method.getName(), method.getReturnType());
	SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(
			new QueryMethod(method, metadataMock, new SpelAwareProxyProjectionFactory()).getParameters(), args));

	KeyValueQuery<SpelExpression> q = creator.createQuery();
	q.getCriteria().setEvaluationContext(
			SimpleEvaluationContext.forReadOnlyDataBinding().withRootObject(args).withInstanceMethods().build());

	return q;
}
 
Example #2
Source File: ParsingTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Parse the supplied expression and then create a string representation of the resultant AST, it should be the
 * expected value.
 *
 * @param expression the expression to parse
 * @param expectedStringFormOfAST the expected string form of the AST
 */
public void parseCheck(String expression, String expectedStringFormOfAST) {
	try {
		SpelExpression e = parser.parseRaw(expression);
		if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
			SpelUtilities.printAbstractSyntaxTree(System.err, e);
		}
		if (e == null) {
			fail("Parsed exception was null");
		}
		assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
	}
	catch (ParseException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	}
}
 
Example #3
Source File: ParsingTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Parse the supplied expression and then create a string representation of the resultant AST, it should be the
 * expected value.
 *
 * @param expression the expression to parse
 * @param expectedStringFormOfAST the expected string form of the AST
 */
public void parseCheck(String expression, String expectedStringFormOfAST) {
	try {
		SpelExpression e = parser.parseRaw(expression);
		if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
			SpelUtilities.printAbstractSyntaxTree(System.err, e);
		}
		if (e == null) {
			fail("Parsed exception was null");
		}
		assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
	} catch (ParseException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	}
}
 
Example #4
Source File: ParsingTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Parse the supplied expression and then create a string representation of the resultant AST, it should be the
 * expected value.
 *
 * @param expression the expression to parse
 * @param expectedStringFormOfAST the expected string form of the AST
 */
public void parseCheck(String expression, String expectedStringFormOfAST) {
	try {
		SpelExpression e = parser.parseRaw(expression);
		if (e != null && !e.toStringAST().equals(expectedStringFormOfAST)) {
			SpelUtilities.printAbstractSyntaxTree(System.err, e);
		}
		if (e == null) {
			fail("Parsed exception was null");
		}
		assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
	}
	catch (ParseException ee) {
		ee.printStackTrace();
		fail("Unexpected Exception: " + ee.getMessage());
	}
}
 
Example #5
Source File: SpelCriteriaAccessor.java    From spring-data-keyvalue with Apache License 2.0 6 votes vote down vote up
@Override
public SpelCriteria resolve(KeyValueQuery<?> query) {

	if (query.getCriteria() == null) {
		return null;
	}

	if (query.getCriteria() instanceof SpelExpression) {
		return new SpelCriteria((SpelExpression) query.getCriteria());
	}

	if (query.getCriteria() instanceof String) {
		return new SpelCriteria(parser.parseRaw((String) query.getCriteria()));
	}

	if (query.getCriteria() instanceof SpelCriteria) {
		return (SpelCriteria) query.getCriteria();
	}

	throw new IllegalArgumentException("Cannot create SpelCriteria for " + query.getCriteria());
}
 
Example #6
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void array() {
	ExpressionParser parser = new SpelExpressionParser();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Expression expression = null;
	Object result = null;

	expression = parser.parseExpression("new java.lang.Long[0].class");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

	expression = parser.parseExpression("T(java.lang.Long[])");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

	expression = parser.parseExpression("T(java.lang.String[][][])");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
	assertEquals("T(java.lang.String[][][])", ((SpelExpression) expression).toStringAST());

	expression = parser.parseExpression("new int[0].class");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [I", result.toString());

	expression = parser.parseExpression("T(int[][])");
	result = expression.getValue(context, "");
	assertEquals("class [[I", result.toString());
}
 
Example #7
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void reservedWordProperties_SPR9862() {
	StandardEvaluationContext context = new StandardEvaluationContext();
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
	Object value = expression.getValue(context);
	assertEquals(value, Reserver.CONST);
}
 
Example #8
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void reservedWordProperties_9862() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext();
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
	Object value = expression.getValue(ctx);
	assertEquals(value, Reserver.CONST);
}
 
Example #9
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void greaterThanWithNulls_SPR7840() throws Exception {
	List<D> list = new ArrayList<D>();
	list.add(new D("aaa"));
	list.add(new D("bbb"));
	list.add(new D(null));
	list.add(new D("ccc"));
	list.add(new D(null));
	list.add(new D("zzz"));

	StandardEvaluationContext ctx = new StandardEvaluationContext(list);
	SpelExpressionParser parser = new SpelExpressionParser();

	String el1 = "#root.?[a < 'hhh']";
	SpelExpression exp = parser.parseRaw(el1);
	Object value = exp.getValue(ctx);
	assertEquals("[D(aaa), D(bbb), D(null), D(ccc), D(null)]", value.toString());

	String el2 = "#root.?[a > 'hhh']";
	SpelExpression exp2 = parser.parseRaw(el2);
	Object value2 = exp2.getValue(ctx);
	assertEquals("[D(zzz)]", value2.toString());

	// trim out the nulls first
	String el3 = "#root.?[a!=null].?[a < 'hhh']";
	SpelExpression exp3 = parser.parseRaw(el3);
	Object value3 = exp3.getValue(ctx);
	assertEquals("[D(aaa), D(bbb), D(ccc)]", value3.toString());
}
 
Example #10
Source File: SpelCompilationCoverageTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void functionReferenceNonCompilableArguments_SPR12359() throws Exception {
	StandardEvaluationContext context = new StandardEvaluationContext(new  Object[] { "1" });
	context.registerFunction("negate", SomeCompareMethod2.class.getDeclaredMethod(
			"negate", Integer.TYPE));
	context.setVariable("arg", "2");
	int[] ints = new int[]{1,2,3};
	context.setVariable("ints",ints);

	expression = parser.parseExpression("#negate(#ints.?[#this<2][0])");
	assertEquals("-1",expression.getValue(context, Integer.class).toString());
	// Selection isn't compilable.
	assertFalse(((SpelNodeImpl)((SpelExpression)expression).getAST()).isCompilable());
}
 
Example #11
Source File: SpelExpressionConverterConfiguration.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Override
public Expression convert(String source) {
	try {
		Expression expression = this.parser.parseExpression(source);
		if (expression instanceof SpelExpression) {
			((SpelExpression) expression)
					.setEvaluationContext(this.evaluationContext);
		}
		return expression;
	}
	catch (ParseException e) {
		throw new IllegalArgumentException(String.format(
				"Could not convert '%s' into a SpEL expression", source), e);
	}
}
 
Example #12
Source File: KeyValuePartTreeQuery.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
protected KeyValueQuery<?> prepareQuery(KeyValueQuery<?> instance, Object[] parameters) {

	ParametersParameterAccessor accessor = new ParametersParameterAccessor(getQueryMethod().getParameters(),
			parameters);

	Object criteria = instance.getCriteria();

	if (criteria instanceof SpelCriteria || criteria instanceof SpelExpression) {

		SpelExpression spelExpression = getSpelExpression(criteria);
		EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(getQueryMethod().getParameters(),
				parameters);
		criteria = new SpelCriteria(spelExpression, context);
	}

	KeyValueQuery<?> query = new KeyValueQuery(criteria);
	Pageable pageable = accessor.getPageable();
	Sort sort = accessor.getSort();

	query.setOffset(pageable.toOptional().map(Pageable::getOffset).orElse(-1L));

	if (pageable.isPaged()) {
		query.setRows(pageable.getPageSize());
	} else if (instance.getRows() >= 0) {
		query.setRows(instance.getRows());
	}

	query.setSort(sort.isUnsorted() ? instance.getSort() : sort);

	return query;
}
 
Example #13
Source File: KeyValuePartTreeQuery.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
private SpelExpression getSpelExpression(Object criteria) {

		if (criteria instanceof SpelExpression) {
			return (SpelExpression) criteria;
		}

		if (criteria instanceof SpelCriteria) {
			return getSpelExpression(((SpelCriteria) criteria).getExpression());
		}

		throw new IllegalStateException(String.format("Cannot retrieve SpelExpression from %s", criteria));
	}
 
Example #14
Source File: SpelQueryCreator.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
@Override
protected KeyValueQuery<SpelExpression> complete(String criteria, Sort sort) {

	KeyValueQuery<SpelExpression> query = new KeyValueQuery<>(this.expression);

	if (sort.isSorted()) {
		query.orderBy(sort);
	}

	return query;
}
 
Example #15
Source File: SpelPropertyComparator.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
/**
 * Parse values to {@link SpelExpression}
 *
 * @return
 */
protected SpelExpression getExpression() {

	if (this.expression == null) {
		this.expression = parser.parseRaw(buildExpressionForPath());
	}

	return this.expression;
}
 
Example #16
Source File: SpelCriteria.java    From spring-data-keyvalue with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new {@link SpelCriteria}.
 *
 * @param expression must not be {@literal null}.
 * @param context must not be {@literal null}.
 */
public SpelCriteria(SpelExpression expression, EvaluationContext context) {

	Assert.notNull(expression, "SpEL expression must not be null!");
	Assert.notNull(context, "EvaluationContext must not be null!");

	this.expression = expression;
	this.context = context;
}
 
Example #17
Source File: MessageBusCacheInvalidator.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Cache cache, Map<String, String> args) {
    CacheInvalidatorAgent cia;
    synchronized (agents) {
        cia = agents.get(cache);
    }
    if(cia != null) {
        return;
    }

    String busName = args.get(BUS_KEY);
    Assert.hasText(busName, "bus name is null or empty");

    String exprStr = args.get(EXP_KEY);
    SpelExpression expr = null;
    if(StringUtils.hasText(exprStr)) {
        expr = parser.parseRaw(exprStr);
    }

    cia = new CacheInvalidatorAgent(cache, expr);
    CacheInvalidatorAgent old;
    synchronized (agents) {
        old = agents.putIfAbsent(cache, cia);
    }
    if(old == null) {
        @SuppressWarnings("unchecked")
        MessageBus<Object> bus = beanFactory.getBean(busName, MessageBus.class);
        bus.subscribe(cia);
    }
}
 
Example #18
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_3() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ms.![key.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(ctx);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example #19
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_2() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "as.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	Object[] value = (Object[]) exp.getValue(ctx);
	// value is array containing [true,false]
	assertEquals(Boolean.class, value[0].getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
	assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
 
Example #20
Source File: SpelReproTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void projectionTypeDescriptors_1() throws Exception {
	StandardEvaluationContext ctx = new StandardEvaluationContext(new C());
	SpelExpressionParser parser = new SpelExpressionParser();
	String el1 = "ls.![#this.equals('abc')]";
	SpelExpression exp = parser.parseRaw(el1);
	List<?> value = (List<?>) exp.getValue(ctx);
	// value is list containing [true,false]
	assertEquals(Boolean.class, value.get(0).getClass());
	TypeDescriptor evaluated = exp.getValueTypeDescriptor(ctx);
	assertEquals(null, evaluated.getElementTypeDescriptor());
}
 
Example #21
Source File: ReflectionHelperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
	public void testUtilities() throws ParseException {
		SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		PrintStream ps = new PrintStream(baos);
		SpelUtilities.printAbstractSyntaxTree(ps, expr);
		ps.flush();
		String s = baos.toString();
//		===> Expression '3+4+5+6+7-2' - AST start
//		OperatorMinus  value:(((((3 + 4) + 5) + 6) + 7) - 2)  #children:2
//		  OperatorPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2
//		    OperatorPlus  value:(((3 + 4) + 5) + 6)  #children:2
//		      OperatorPlus  value:((3 + 4) + 5)  #children:2
//		        OperatorPlus  value:(3 + 4)  #children:2
//		          CompoundExpression  value:3
//		            IntLiteral  value:3
//		          CompoundExpression  value:4
//		            IntLiteral  value:4
//		        CompoundExpression  value:5
//		          IntLiteral  value:5
//		      CompoundExpression  value:6
//		        IntLiteral  value:6
//		    CompoundExpression  value:7
//		      IntLiteral  value:7
//		  CompoundExpression  value:2
//		    IntLiteral  value:2
//		===> Expression '3+4+5+6+7-2' - AST end
		assertTrue(s.contains("===> Expression '3+4+5+6+7-2' - AST start"));
		assertTrue(s.contains(" OpPlus  value:((((3 + 4) + 5) + 6) + 7)  #children:2"));
	}
 
Example #22
Source File: MapTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void checkConstantMap(String expressionText, boolean expectedToBeConstant) {
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
	SpelNode node = expression.getAST();
	assertTrue(node instanceof InlineMap);
	InlineMap inlineMap = (InlineMap) node;
	if (expectedToBeConstant) {
		assertTrue(inlineMap.isConstant());
	}
	else {
		assertFalse(inlineMap.isConstant());
	}
}
 
Example #23
Source File: OperatorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testOperatorNames() throws Exception {
	Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
	assertEquals("==",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
	assertEquals("!=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
	assertEquals("/",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
	assertEquals("+",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
	assertEquals("-",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3<4"));
	assertEquals("<",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
	assertEquals("<=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
	assertEquals("*",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
	assertEquals("%",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
	assertEquals(">=",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
	assertEquals("between",node.getOperatorName());

	node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
	assertEquals("^",node.getOperatorName());
}
 
Example #24
Source File: EvaluationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void operatorVariants() throws Exception {
	SpelExpression expr = (SpelExpression)parser.parseExpression("#a < #b");
	EvaluationContext ctx = new StandardEvaluationContext();
	ctx.setVariable("a", (short)3);
	ctx.setVariable("b", (short)6);
	assertTrue(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("b", (byte)6);
	assertTrue(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte)9);
	ctx.setVariable("b", (byte)6);
	assertFalse(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("a", 10L);
	ctx.setVariable("b", (short)30);
	assertTrue(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte)3);
	ctx.setVariable("b", (short)30);
	assertTrue(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte)3);
	ctx.setVariable("b", 30L);
	assertTrue(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("a", (byte)3);
	ctx.setVariable("b", 30f);
	assertTrue(expr.getValue(ctx, Boolean.class));
	ctx.setVariable("a", new BigInteger("10"));
	ctx.setVariable("b", new BigInteger("20"));
	assertTrue(expr.getValue(ctx, Boolean.class));
}
 
Example #25
Source File: EvaluationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testTypeReferencesAndQualifiedIdentifierCaching() throws Exception {
	SpelExpression expr = (SpelExpression) parser.parseExpression("T(java.lang.String)");
	assertFalse(expr.isWritable(new StandardEvaluationContext()));
	assertEquals("T(java.lang.String)", expr.toStringAST());
	assertEquals(String.class, expr.getValue(Class.class));
	// use cached QualifiedIdentifier:
	assertEquals("T(java.lang.String)", expr.toStringAST());
	assertEquals(String.class, expr.getValue(Class.class));
}
 
Example #26
Source File: EvaluationTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructorInvocation06() throws Exception {
	// repeated evaluation to drive use of cached executor
	SpelExpression expr = (SpelExpression) parser.parseExpression("new String('wibble')");
	String newString = expr.getValue(String.class);
	assertEquals("wibble", newString);
	newString = expr.getValue(String.class);
	assertEquals("wibble", newString);

	// not writable
	assertFalse(expr.isWritable(new StandardEvaluationContext()));

	// ast
	assertEquals("new String('wibble')", expr.toStringAST());
}
 
Example #27
Source File: ListTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void checkConstantList(String expressionText, boolean expectedToBeConstant) {
	SpelExpressionParser parser = new SpelExpressionParser();
	SpelExpression expression = (SpelExpression) parser.parseExpression(expressionText);
	SpelNode node = expression.getAST();
	assertTrue(node instanceof InlineList);
	InlineList inlineList = (InlineList) node;
	if (expectedToBeConstant) {
		assertTrue(inlineList.isConstant());
	}
	else {
		assertFalse(inlineList.isConstant());
	}
}
 
Example #28
Source File: SqlSpannerQuery.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
private void resolveSpELTags(QueryTagValue queryTagValue) {
	Expression[] expressions = detectExpressions(queryTagValue.sql);
	StringBuilder sb = new StringBuilder();
	Map<Object, String> valueToTag = new HashMap<>();
	int tagNum = 0;
	EvaluationContext evaluationContext = this.evaluationContextProvider
			.getEvaluationContext(this.queryMethod.getParameters(),
					queryTagValue.rawParams);
	for (Expression expression : expressions) {
		if (expression instanceof LiteralExpression) {
			sb.append(expression.getValue(String.class));
		}
		else if (expression instanceof SpelExpression) {
			Object value = expression.getValue(evaluationContext);
			if (valueToTag.containsKey(value)) {
				sb.append("@").append(valueToTag.get(value));
			}
			else {
				String newTag;
				do {
					tagNum++;
					newTag = "SpELtag" + tagNum;
				}
				while (queryTagValue.initialTags.contains(newTag));
				valueToTag.put(value, newTag);
				queryTagValue.params.add(value);
				queryTagValue.tags.add(newTag);
				sb.append("@").append(newTag);
			}
		}
		else {
			throw new SpannerDataException(
					"Unexpected expression type. SQL queries are expected to be "
							+ "concatenation of Literal and SpEL expressions.");
		}
	}
	queryTagValue.sql = sb.toString();
}
 
Example #29
Source File: SpelReproTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void array() {
	ExpressionParser parser = new SpelExpressionParser();
	StandardEvaluationContext context = new StandardEvaluationContext();
	Expression expression = null;
	Object result = null;

	expression = parser.parseExpression("new java.lang.Long[0].class");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

	expression = parser.parseExpression("T(java.lang.Long[])");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [Ljava.lang.Long;", result.toString());

	expression = parser.parseExpression("T(java.lang.String[][][])");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [[[Ljava.lang.String;", result.toString());
	assertEquals("T(java.lang.String[][][])", ((SpelExpression) expression).toStringAST());

	expression = parser.parseExpression("new int[0].class");
	result = expression.getValue(context, "");
	assertEquals("Equal assertion failed: ", "class [I", result.toString());

	expression = parser.parseExpression("T(int[][])");
	result = expression.getValue(context, "");
	assertEquals("class [[I", result.toString());
}
 
Example #30
Source File: EvaluationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testConstructorInvocation06() {
	// repeated evaluation to drive use of cached executor
	SpelExpression e = (SpelExpression) parser.parseExpression("new String('wibble')");
	String newString = e.getValue(String.class);
	assertEquals("wibble", newString);
	newString = e.getValue(String.class);
	assertEquals("wibble", newString);

	// not writable
	assertFalse(e.isWritable(new StandardEvaluationContext()));

	// ast
	assertEquals("new String('wibble')", e.toStringAST());
}