use of org.apache.camel.builder.ValueBuilder in project camel by apache.
the class JpaRouteTest method testRouteJpa.
@Test
public void testRouteJpa() throws Exception {
// should auto setup transaction manager and entity factory
JpaComponent jpa = context.getComponent("jpa", JpaComponent.class);
assertNotNull("Should have been auto assigned", jpa.getEntityManagerFactory());
assertNotNull("Should have been auto assigned", jpa.getTransactionManager());
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
ValueBuilder header = mock.message(0).header(JpaConstants.ENTITYMANAGER);
header.isNotNull();
header.isInstanceOf(EntityManager.class);
template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));
assertMockEndpointsSatisfied();
assertEntityInDB(1);
}
use of org.apache.camel.builder.ValueBuilder in project camel by apache.
the class BinaryExpression method createInExpression.
private Expression createInExpression(final Expression leftExp, final Expression rightExp) {
return new Expression() {
@Override
public <T> T evaluate(Exchange exchange, Class<T> type) {
// okay the in operator is a bit more complex as we need to build a list of values
// from the right hand side expression.
// each element on the right hand side must be separated by comma (default for create iterator)
Iterator<Object> it = ObjectHelper.createIterator(rightExp.evaluate(exchange, Object.class));
List<Object> values = new ArrayList<Object>();
while (it.hasNext()) {
values.add(it.next());
}
// then reuse value builder to create the in predicate with the list of values
ValueBuilder vb = new ValueBuilder(leftExp);
Predicate predicate = vb.in(values.toArray());
if (operator == BinaryOperatorType.NOT_IN) {
predicate = PredicateBuilder.not(predicate);
}
boolean answer = predicate.matches(exchange);
return exchange.getContext().getTypeConverter().convertTo(type, answer);
}
@Override
public String toString() {
return left + " " + token.getText() + " " + right;
}
};
}
use of org.apache.camel.builder.ValueBuilder in project camel by apache.
the class ExpressionNodeHelper method toExpressionDefinition.
/**
* Determines which {@link ExpressionDefinition} describes the given expression best possible.
* <p/>
* This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
* if the given expression is detect as such a type.
*
* @param expression the expression
* @return a definition which describes the expression
*/
public static ExpressionDefinition toExpressionDefinition(Expression expression) {
if (expression instanceof SimpleBuilder) {
SimpleBuilder builder = (SimpleBuilder) expression;
// we keep the original expression by using the constructor that accepts an expression
SimpleExpression answer = new SimpleExpression(builder);
answer.setExpression(builder.getText());
answer.setResultType(builder.getResultType());
return answer;
} else if (expression instanceof XPathBuilder) {
XPathBuilder builder = (XPathBuilder) expression;
// we keep the original expression by using the constructor that accepts an expression
XPathExpression answer = new XPathExpression(builder);
answer.setExpression(builder.getText());
answer.setResultType(builder.getResultType());
return answer;
} else if (expression instanceof ValueBuilder) {
// ValueBuilder wraps the actual expression so unwrap
ValueBuilder builder = (ValueBuilder) expression;
expression = builder.getExpression();
}
if (expression instanceof ExpressionDefinition) {
return (ExpressionDefinition) expression;
}
return new ExpressionDefinition(expression);
}
use of org.apache.camel.builder.ValueBuilder in project camel by apache.
the class ExpressionNodeHelper method toExpressionDefinition.
/**
* Determines which {@link ExpressionDefinition} describes the given predicate best possible.
* <p/>
* This implementation will use types such as {@link SimpleExpression}, {@link XPathExpression} etc.
* if the given predicate is detect as such a type.
*
* @param predicate the predicate
* @return a definition which describes the predicate
*/
public static ExpressionDefinition toExpressionDefinition(Predicate predicate) {
if (predicate instanceof SimpleBuilder) {
SimpleBuilder builder = (SimpleBuilder) predicate;
// we keep the original expression by using the constructor that accepts an expression
SimpleExpression answer = new SimpleExpression(builder);
answer.setExpression(builder.getText());
return answer;
} else if (predicate instanceof XPathBuilder) {
XPathBuilder builder = (XPathBuilder) predicate;
// we keep the original expression by using the constructor that accepts an expression
XPathExpression answer = new XPathExpression(builder);
answer.setExpression(builder.getText());
return answer;
} else if (predicate instanceof ValueBuilder) {
// ValueBuilder wraps the actual predicate so unwrap
ValueBuilder builder = (ValueBuilder) predicate;
Expression expression = builder.getExpression();
if (expression instanceof Predicate) {
predicate = (Predicate) expression;
}
}
if (predicate instanceof ExpressionDefinition) {
return (ExpressionDefinition) predicate;
}
return new ExpressionDefinition(predicate);
}
Aggregations