org.apache.camel.component.mybatis.MyBatisConsumer Maven / Gradle / Ivy
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.mybatis;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import org.apache.camel.BatchConsumer;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.ShutdownRunningTask;
import org.apache.camel.impl.ScheduledPollConsumer;
import org.apache.camel.spi.ShutdownAware;
import org.apache.camel.util.CastUtils;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Consumer to read data from a database.
*
* @version
*/
public class MyBatisConsumer extends ScheduledPollConsumer implements BatchConsumer, ShutdownAware {
private static final Logger LOG = LoggerFactory.getLogger(MyBatisConsumer.class);
private static final class DataHolder {
private Exchange exchange;
private Object data;
private DataHolder() {
}
}
protected volatile ShutdownRunningTask shutdownRunningTask;
protected volatile int pendingExchanges;
/**
* Statement to run after data has been processed in the route
*/
private String onConsume;
/**
* Process resultset individually or as a list
*/
private boolean useIterator = true;
/**
* Whether allow empty resultset to be routed to the next hop
*/
private boolean routeEmptyResultSet;
private int maxMessagesPerPoll;
public MyBatisConsumer(MyBatisEndpoint endpoint, Processor processor) {
super(endpoint, processor);
}
public MyBatisEndpoint getEndpoint() {
return (MyBatisEndpoint) super.getEndpoint();
}
/**
* Polls the database
*/
@Override
protected int poll() throws Exception {
// must reset for each poll
shutdownRunningTask = null;
pendingExchanges = 0;
// poll data from the database
MyBatisEndpoint endpoint = getEndpoint();
LOG.trace("Polling: {}", endpoint);
List