Search in sources :

Example 61 with List

use of java.util.List in project camel by apache.

the class JdbcProducer method extractRows.

@SuppressWarnings("unchecked")
private List extractRows(ResultSetIterator iterator) throws SQLException {
    List result = new ArrayList();
    int maxRowCount = readSize == 0 ? Integer.MAX_VALUE : readSize;
    for (int i = 0; iterator.hasNext() && i < maxRowCount; i++) {
        Map<String, Object> row = iterator.next();
        Object value;
        if (getEndpoint().getOutputClass() != null) {
            value = newBeanInstance(row);
        } else {
            value = row;
        }
        result.add(value);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 62 with List

use of java.util.List in project camel by apache.

the class JcloudsSpringBlobstoreTest method testBlobStoreRemoveBlobs.

@Test
public void testBlobStoreRemoveBlobs() throws InterruptedException {
    Boolean result = template.requestBody("direct:exists", "Some message", Boolean.class);
    assertEquals(true, result);
    List blobsToRemove = new ArrayList<>();
    blobsToRemove.add("testName");
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(JcloudsConstants.OPERATION, JcloudsConstants.REMOVE_BLOBS);
    headers.put(JcloudsConstants.CONTAINER_NAME, "foo");
    headers.put(JcloudsConstants.BLOB_NAME_LIST, blobsToRemove);
    template.sendBodyAndHeaders("direct:remove-blobs", null, headers);
    Long count = template.requestBody("direct:count-after-remove-blobs", null, Long.class);
    assertEquals(new Long(0), count);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 63 with List

use of java.util.List in project camel by apache.

the class JcloudsBlobStoreProducer method process.

@Override
public void process(Exchange exchange) throws Exception {
    String container = getContainerName(exchange);
    String blobName = getBlobName(exchange);
    String operation = getOperation(exchange);
    List blobNames = getBlobNameList(exchange);
    if (LOG.isTraceEnabled()) {
        LOG.trace("Processing {} operation on '{}'", operation, container + "/" + blobName);
    }
    if (JcloudsConstants.GET.equals(operation)) {
        exchange.getOut().setBody(JcloudsBlobStoreHelper.readBlob(blobStore, container, blobName));
    } else if (JcloudsConstants.COUNT_BLOBS.equals(operation)) {
        exchange.getOut().setBody(JcloudsBlobStoreHelper.countBlob(blobStore, container));
    } else if (JcloudsConstants.REMOVE_BLOB.equals(operation)) {
        JcloudsBlobStoreHelper.removeBlob(blobStore, container, blobName);
    } else if (JcloudsConstants.CLEAR_CONTAINER.equals(operation)) {
        JcloudsBlobStoreHelper.clearContainer(blobStore, container);
    } else if (JcloudsConstants.DELETE_CONTAINER.equals(operation)) {
        JcloudsBlobStoreHelper.deleteContainer(blobStore, container);
    } else if (JcloudsConstants.CONTAINER_EXISTS.equals(operation)) {
        exchange.getOut().setBody(JcloudsBlobStoreHelper.containerExists(blobStore, container));
    } else if (JcloudsConstants.REMOVE_BLOBS.equals(operation)) {
        JcloudsBlobStoreHelper.removeBlobs(blobStore, container, blobNames);
    } else {
        Payload body = exchange.getIn().getBody(Payload.class);
        JcloudsBlobStoreHelper.writeBlob(blobStore, container, blobName, body);
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Payload(org.jclouds.io.Payload)

Example 64 with List

use of java.util.List in project camel by apache.

the class JdbcProducerConcurrenctTest method doSendMessages.

@SuppressWarnings("rawtypes")
private void doSendMessages(int files, int poolSize) throws Exception {
    mock.expectedMessageCount(files);
    ExecutorService executor = Executors.newFixedThreadPool(poolSize);
    // we access the responses Map below only inside the main thread,
    // so no need for a thread-safe Map implementation
    Map<Integer, Future<List<?>>> responses = new HashMap<Integer, Future<List<?>>>();
    for (int i = 0; i < files; i++) {
        final int index = i;
        Future<List<?>> out = executor.submit(new Callable<List<?>>() {

            public List<?> call() throws Exception {
                int id = (index % 2) + 1;
                return template.requestBody("direct:start", "select * from customer where id = 'cust" + id + "'", List.class);
            }
        });
        responses.put(index, out);
    }
    assertMockEndpointsSatisfied();
    assertEquals(files, responses.size());
    for (int i = 0; i < files; i++) {
        List<?> rows = responses.get(i).get();
        Map columns = (Map) rows.get(0);
        if (i % 2 == 0) {
            assertEquals("jstrachan", columns.get("NAME"));
        } else {
            assertEquals("nsandhu", columns.get("NAME"));
        }
    }
    executor.shutdownNow();
}
Also used : HashMap(java.util.HashMap) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 65 with List

use of java.util.List in project camel by apache.

the class JdbcProducerOutputTypeSelectListOutputClassTest method testOutputTypeSelectListOutputClass.

@Test
public void testOutputTypeSelectListOutputClass() throws Exception {
    mock.expectedMessageCount(1);
    template.sendBody("direct:start", "select * from customer order by ID");
    assertMockEndpointsSatisfied();
    List list = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody(List.class));
    assertNotNull(list);
    assertEquals(3, list.size());
    CustomerModel cust1 = (CustomerModel) list.get(0);
    assertEquals("cust1", cust1.getId());
    assertEquals("jstrachan", cust1.getName());
    CustomerModel cust2 = (CustomerModel) list.get(1);
    assertEquals("cust2", cust2.getId());
    assertEquals("nsandhu", cust2.getName());
    CustomerModel cust3 = (CustomerModel) list.get(2);
    assertEquals("cust3", cust3.getId());
    assertEquals("willem", cust3.getName());
}
Also used : List(java.util.List) Test(org.junit.Test)

Aggregations

List (java.util.List)19204 ArrayList (java.util.ArrayList)12470 Test (org.junit.Test)4025 HashMap (java.util.HashMap)3622 Map (java.util.Map)3242 IOException (java.io.IOException)1670 Iterator (java.util.Iterator)1563 LinkedList (java.util.LinkedList)1336 HashSet (java.util.HashSet)1189 Set (java.util.Set)1151 File (java.io.File)921 ImmutableList (com.google.common.collect.ImmutableList)826 Collectors (java.util.stream.Collectors)784 LinkedHashMap (java.util.LinkedHashMap)540 Test (org.testng.annotations.Test)527 Session (org.hibernate.Session)521 Collection (java.util.Collection)496 Collections (java.util.Collections)474 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)471 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)453