}
}
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();
if (LOG.isTraceEnabled()) {
LOG.trace("Inserting: " + value + " using statement: " + statement);
}
result = session.insert(statement, value);
doProcessResult(exchange, result);
}
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("Inserting using statement: " + statement);
}
result = session.insert(statement);
doProcessResult(exchange, result);
}
} finally {
session.commit();
session.close();
}
}