use of java.util.Map in project camel by apache.
the class InfinispanProducerTest method publishMapWithLifespanAsync.
@Test
public void publishMapWithLifespanAsync() throws Exception {
template.send("direct:putallasync", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put(KEY_ONE, VALUE_ONE);
map.put(KEY_TWO, VALUE_TWO);
exchange.getIn().setHeader(InfinispanConstants.MAP, map);
exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_ALL);
exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_TIME));
exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
}
});
waitFor(new Condition() {
@Override
public boolean isSatisfied() throws Exception {
Object valueOne = currentCache().get(KEY_ONE);
Object valueTwo = currentCache().get(KEY_TWO);
return valueOne.equals(VALUE_ONE) && valueTwo.equals(VALUE_TWO) && currentCache().size() == 2;
}
}, 100);
waitForNullValue(KEY_ONE);
}
use of java.util.Map in project camel by apache.
the class InfinispanProducerTest method publishMapWithLifespanAndMaxIdleTime.
@Test
public void publishMapWithLifespanAndMaxIdleTime() throws Exception {
template.send("direct:start", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put(KEY_ONE, VALUE_ONE);
map.put(KEY_TWO, VALUE_TWO);
exchange.getIn().setHeader(InfinispanConstants.MAP, map);
exchange.getIn().setHeader(InfinispanConstants.OPERATION, InfinispanConstants.PUT_ALL);
exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME, new Long(LIFESPAN_FOR_MAX_IDLE));
exchange.getIn().setHeader(InfinispanConstants.LIFESPAN_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME, new Long(MAX_IDLE_TIME));
exchange.getIn().setHeader(InfinispanConstants.MAX_IDLE_TIME_UNIT, TimeUnit.MILLISECONDS.toString());
}
});
assertEquals(2, currentCache().size());
Thread.sleep(300);
waitForNullValue(KEY_TWO);
}
use of java.util.Map in project camel by apache.
the class DefaultJdbcPrepareStatementStrategy method createPopulateIterator.
@Override
public Iterator<?> createPopulateIterator(final String query, final String preparedQuery, final int expectedParams, final Exchange exchange, final Object value) throws SQLException {
Map<?, ?> map = null;
if (exchange.getIn().hasHeaders()) {
if (exchange.getIn().getHeader(JdbcConstants.JDBC_PARAMETERS) != null) {
// header JDBC_PARAMETERS takes precedence over regular headers
map = exchange.getIn().getHeader(JdbcConstants.JDBC_PARAMETERS, Map.class);
} else {
map = exchange.getIn().getHeaders();
}
}
final Map<?, ?> headerMap = map;
if (hasNamedParameters(query)) {
// create an iterator that returns the value in the named order
try {
return new Iterator<Object>() {
private NamedQueryParser parser = new NamedQueryParser(query);
private Object next;
private boolean done;
private boolean preFetched;
@Override
public boolean hasNext() {
if (!done && !preFetched) {
next();
preFetched = true;
}
return !done;
}
@Override
public Object next() {
if (!preFetched) {
String key = parser.next();
if (key == null) {
done = true;
return null;
}
// the key is expected to exist, if not report so end user can see this
boolean contains = headerMap != null && headerMap.containsKey(key);
if (!contains) {
throw new RuntimeExchangeException("Cannot find key [" + key + "] in message body or headers to use when setting named parameter in query [" + query + "]", exchange);
}
next = headerMap.get(key);
}
preFetched = false;
return next;
}
@Override
public void remove() {
// noop
}
};
} catch (Exception e) {
throw new SQLException("Error iterating parameters for the query: " + query, e);
}
} else {
// just use a regular iterator
return exchange.getContext().getTypeConverter().convertTo(Iterator.class, headerMap != null ? headerMap.values() : null);
}
}
use of java.util.Map in project camel by apache.
the class AbstractJdbcGeneratedKeysTest method testRetrieveGeneratedKeysWithStringGeneratedColumns.
@SuppressWarnings("unchecked")
protected void testRetrieveGeneratedKeysWithStringGeneratedColumns(String query, Map<String, Object> parameters) throws Exception {
// first we create our exchange using the endpoint
Endpoint endpoint = context.getEndpoint("direct:hello");
Exchange exchange = endpoint.createExchange();
// then we set the SQL on the in body and add possible parameters
exchange.getIn().setBody(query);
exchange.getIn().setHeader(JdbcConstants.JDBC_RETRIEVE_GENERATED_KEYS, true);
exchange.getIn().setHeader(JdbcConstants.JDBC_GENERATED_COLUMNS, new String[] { "ID" });
setHeaders(exchange, parameters);
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
// assertions of the response
assertNotNull(out);
assertNotNull(out.getOut());
assertNotNull(out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_DATA));
assertNotNull(out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to an ArrayList - was: " + out.getOut().getBody(), generatedKeys);
assertEquals(1, generatedKeys.size());
Map<String, Object> row = generatedKeys.get(0);
assertEquals("auto increment value should be 2", BigDecimal.valueOf(2), row.get("1"));
assertEquals("generated keys row count should be one", 1, out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT));
}
use of java.util.Map in project camel by apache.
the class AbstractJdbcGeneratedKeysTest method testRetrieveGeneratedKeys.
@SuppressWarnings("unchecked")
protected void testRetrieveGeneratedKeys(String query, Map<String, Object> parameters) throws Exception {
// first we create our exchange using the endpoint
Endpoint endpoint = context.getEndpoint("direct:hello");
Exchange exchange = endpoint.createExchange();
// then we set the SQL on the in body and add possible parameters
exchange.getIn().setBody(query);
exchange.getIn().setHeader(JdbcConstants.JDBC_RETRIEVE_GENERATED_KEYS, true);
setHeaders(exchange, parameters);
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
// assertions of the response
assertNotNull(out);
assertNotNull(out.getOut());
assertNotNull(out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_DATA));
assertNotNull(out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT));
List<Map<String, Object>> generatedKeys = out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_DATA, List.class);
assertNotNull("out body could not be converted to an ArrayList - was: " + out.getOut().getBody(), generatedKeys);
assertEquals(1, generatedKeys.size());
Map<String, Object> row = generatedKeys.get(0);
assertEquals("auto increment value should be 2", BigDecimal.valueOf(2), row.get("1"));
assertEquals("generated keys row count should be one", 1, out.getOut().getHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT));
}
Aggregations