private Object executeSelectKey(SessionScope sessionScope, Transaction trans, MappedStatement ms, Object param) throws SQLException { Object generatedKey = null; StatementScope statementScope; InsertStatement insert = (InsertStatement) ms; SelectKeyStatement selectKeyStatement = insert.getSelectKeyStatement(); if (selectKeyStatement != null) { statementScope = beginStatementScope(sessionScope, selectKeyStatement); try { generatedKey = selectKeyStatement.executeQueryForObject(statementScope, trans, param, null); String keyProp = selectKeyStatement.getKeyProperty(); if (keyProp != null) { PROBE.setObject(param, keyProp, generatedKey); } } finally { endStatementScope(statementScope); } } return generatedKey; }
private Object executeSelectKey(SessionScope sessionScope, Transaction trans, MappedStatement ms, Object param) throws SQLException { Object generatedKey = null; StatementScope statementScope; InsertStatement insert = (InsertStatement) ms; SelectKeyStatement selectKeyStatement = insert.getSelectKeyStatement(); if (selectKeyStatement != null) { statementScope = beginStatementScope(sessionScope, selectKeyStatement); try { generatedKey = selectKeyStatement.executeQueryForObject(statementScope, trans, param, null); String keyProp = selectKeyStatement.getKeyProperty(); if (keyProp != null) { PROBE.setObject(param, keyProp, generatedKey); } } finally { endStatementScope(statementScope); } } return generatedKey; }
/** * Execute a query with a row handler. * The row handler is called once per row in the query results. * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param rowHandler - the row handler * @throws SQLException - if the query fails */ public void queryWithRowHandler(SessionScope sessionScope, String id, Object paramObject, RowHandler rowHandler) throws SQLException { MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { ms.executeQueryWithRowHandler(statementScope, trans, paramObject, rowHandler); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } }
/** * Execute an update statement * * @param sessionScope - the session scope * @param id - the statement ID * @param param - the parameter object * @return - the number of rows updated * @throws SQLException - if the update fails */ public int update(SessionScope sessionScope, String id, Object param) throws SQLException { int rows = 0; MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { rows = ms.executeUpdate(statementScope, trans, param); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } return rows; }
/** * Execute a query with a row handler. * The row handler is called once per row in the query results. * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param rowHandler - the row handler * @throws SQLException - if the query fails */ public void queryWithRowHandler(SessionScope sessionScope, String id, Object paramObject, RowHandler rowHandler) throws SQLException { MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { ms.executeQueryWithRowHandler(statementScope, trans, paramObject, rowHandler); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } }
/** * Execute a select for a single object * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param resultObject - the result object (if not supplied or null, a new object will be created) * @return - the result of the query * @throws SQLException - if the query fails */ public Object queryForObject(SessionScope sessionScope, String id, Object paramObject, Object resultObject) throws SQLException { Object object = null; MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { object = ms.executeQueryForObject(statementScope, trans, paramObject, resultObject); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } return object; }
/** * Execute an update statement * * @param sessionScope - the session scope * @param id - the statement ID * @param param - the parameter object * @return - the number of rows updated * @throws SQLException - if the update fails */ public int update(SessionScope sessionScope, String id, Object param) throws SQLException { int rows = 0; MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { rows = ms.executeUpdate(statementScope, trans, param); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } return rows; }
/** * Execute a select for a single object * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param resultObject - the result object (if not supplied or null, a new object will be created) * @return - the result of the query * @throws SQLException - if the query fails */ public Object queryForObject(SessionScope sessionScope, String id, Object paramObject, Object resultObject) throws SQLException { Object object = null; MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { object = ms.executeQueryForObject(statementScope, trans, paramObject, resultObject); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } return object; }
/** * Execute a query for a list * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param skip - the number of rows to skip * @param max - the maximum number of rows to return * @return - the data list * @throws SQLException - if the query fails */ public List queryForList(SessionScope sessionScope, String id, Object paramObject, int skip, int max) throws SQLException { List list = null; MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { list = ms.executeQueryForList(statementScope, trans, paramObject, skip, max); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } return list; }
/** * Execute a query for a list * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param skip - the number of rows to skip * @param max - the maximum number of rows to return * @return - the data list * @throws SQLException - if the query fails */ public List queryForList(SessionScope sessionScope, String id, Object paramObject, int skip, int max) throws SQLException { List list = null; MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { list = ms.executeQueryForList(statementScope, trans, paramObject, skip, max); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } return list; }
StatementScope statementScope = beginStatementScope(sessionScope, ms); try { ms.executeUpdate(statementScope, trans, param);
StatementScope statementScope = beginStatementScope(sessionScope, ms); try { ms.executeUpdate(statementScope, trans, param);