}
}
private void doInsert(Exchange exchange) throws Exception {
SqlSessionFactory client = endpoint.getSqlSessionFactory();
SqlSession session = client.openSession();
try {
Object result;
Object in = exchange.getIn().getBody();
if (in != null) {
// lets handle arrays or collections of objects
Iterator<?> iter = ObjectHelper.createIterator(in);
while (iter.hasNext()) {
Object value = iter.next();
LOG.trace("Inserting: {} using statement: {}", value, statement);
result = session.insert(statement, value);
doProcessResult(exchange, result);
}
} else {
LOG.trace("Inserting using statement: {}", statement);
result = session.insert(statement);
doProcessResult(exchange, result);
}
} finally {
try {
session.commit();
} finally {
session.close();
}
}
}