this.endpoint = endpoint;
this.statement = endpoint.getStatement();
}
public void process(Exchange exchange) throws Exception {
SqlSession session;
ExecutorType executorType = endpoint.getExecutorType();
if (executorType == null) {
session = endpoint.getSqlSessionFactory().openSession();
} else {
session = endpoint.getSqlSessionFactory().openSession(executorType);
}
try {
switch (endpoint.getStatementType()) {
case SelectOne:
doSelectOne(exchange, session);
break;
case SelectList:
doSelectList(exchange, session);
break;
case Insert:
doInsert(exchange, session);
break;
case InsertList:
doInsertList(exchange, session);
break;
case Update:
doUpdate(exchange, session);
break;
case UpdateList:
doUpdateList(exchange, session);
break;
case Delete:
doDelete(exchange, session);
break;
case DeleteList:
doDeleteList(exchange, session);
break;
default:
throw new IllegalArgumentException("Unsupported statementType: " + endpoint.getStatementType());
}
// flush the batch statements and commit the database connection
session.commit();
} catch (Exception e) {
// discard the pending batch statements and roll the database connection back
session.rollback();
throw e;
} finally {
// and finally close the session as we're done
session.close();
}
}