本文整理匯總了Java中com.ibatis.sqlmap.engine.mapping.statement.MappedStatement類的典型用法代碼示例。如果您正苦於以下問題:Java MappedStatement類的具體用法?Java MappedStatement怎麽用?Java MappedStatement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MappedStatement類屬於com.ibatis.sqlmap.engine.mapping.statement包,在下文中一共展示了MappedStatement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: process
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
private void process(StatementScope statementScope, Object parameterObject) {
SqlTagContext ctx = new SqlTagContext();
List localChildren = children;
processBodyChildren(statementScope, ctx, parameterObject, localChildren.iterator());
ParameterMap map = new ParameterMap(delegate);
map.setId(statementScope.getStatement().getId() + "-InlineParameterMap");
map.setParameterClass(((MappedStatement) statementScope.getStatement()).getParameterClass());
map.setParameterMappingList(ctx.getParameterMappings());
String dynSql = ctx.getBodyText();
// Processes $substitutions$ after DynamicSql
if (SimpleDynamicSql.isSimpleDynamicSql(dynSql)) {
dynSql = new SimpleDynamicSql(delegate, dynSql).getSql(statementScope, parameterObject);
}
statementScope.setDynamicSql(dynSql);
statementScope.setDynamicParameterMap(map);
}
示例2: executeSelectKey
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
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;
}
示例3: update
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* 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;
}
示例4: queryForObject
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* 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;
}
示例5: queryForList
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* 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;
}
示例6: queryWithRowHandler
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* 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);
}
}
示例7: getSQL
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
public String getSQL(String id,Object params){
try {
SqlMapClientImpl sci = (SqlMapClientImpl)this.sqlMapClientTemplate.getSqlMapClient();
MappedStatement ms = sci.getMappedStatement(id);
Sql sql = ms.getSql();
SessionScope sessionScope = new SessionScope();
sessionScope.incrementRequestStackDepth();
StatementScope statementScope = new StatementScope(sessionScope);
ms.initRequest(statementScope);
ms.getCacheKey(statementScope, params);
String sqlString = sql.getSql(statementScope, params);
Object[] sqlParam = sql.getParameterMap(statementScope, params).getParameterObjectValues(statementScope, params);
int sqlParamLen = sqlParam.length;
if (sqlParam != null && sqlParamLen > 0) {
for (int i=0; i < sqlParamLen; i++) {
if (sqlParam[i] instanceof Integer) {
sqlString = sqlString.replaceFirst("\\?", sqlParam[i].toString());
}
else if (sqlParam[i] instanceof String) {
sqlString = sqlString.replaceFirst("\\?", "'" + sqlParam[i].toString() + "'");
}
}
}
return sqlString;
} catch (Exception ex) {
LogConstant.error(ex.getMessage(), ex);
LogConstant.error("獲取SQL 出錯, id: " + id);
}
return "[未能獲取 SQL語句](id: " + id + ")";
}
示例8: translateStatementName
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
private String translateStatementName(String statementName) {
if (systemEnvironment.isDefaultDbProvider()) {
return statementName;
}
String forExternalDb = String.format("%s-%s", statementName, database.getType());
MappedStatement statement;
try {
statement = ((SqlMapClientImpl) super.getSqlMapClient()).getMappedStatement(forExternalDb);
} catch (Exception e) {
statement = null;
}
return statement != null ? forExternalDb : statementName;
}
示例9: handleMultipleResults
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
private ResultSet handleMultipleResults(PreparedStatement ps, StatementScope statementScope, int skipResults,
int maxResults, RowHandlerCallback callback) throws SQLException {
ResultSet rs;
rs = getFirstResultSet(statementScope, ps);
if (rs != null) {
handleResults(statementScope, rs, skipResults, maxResults, callback);
}
// Multiple ResultSet handling
if (callback.getRowHandler() instanceof DefaultRowHandler) {
MappedStatement statement = statementScope.getStatement();
DefaultRowHandler defaultRowHandler = ((DefaultRowHandler) callback.getRowHandler());
if (statement.hasMultipleResultMaps()) {
List multipleResults = new ArrayList();
multipleResults.add(defaultRowHandler.getList());
ResultMap[] resultMaps = statement.getAdditionalResultMaps();
int i = 0;
while (moveToNextResultsSafely(statementScope, ps)) {
if (i >= resultMaps.length)
break;
ResultMap rm = resultMaps[i];
statementScope.setResultMap(rm);
rs = ps.getResultSet();
DefaultRowHandler rh = new DefaultRowHandler();
handleResults(statementScope, rs, skipResults, maxResults, new RowHandlerCallback(rm, null, rh));
multipleResults.add(rh.getList());
i++;
}
defaultRowHandler.setList(multipleResults);
statementScope.setResultMap(statement.getResultMap());
} else {
while (moveToNextResultsSafely(statementScope, ps))
;
}
}
// End additional ResultSet handling
return rs;
}
示例10: addMappedStatement
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* Add a mapped statement
*
* @param ms
* - the mapped statement to add
*/
public void addMappedStatement(MappedStatement ms) {
if (mappedStatements.containsKey(ms.getId())) {
throw new SqlMapException("There is already a statement named " + ms.getId() + " in this SqlMap.");
}
ms.setBaseCacheKey(hashCode());
mappedStatements.put(ms.getId(), ms);
}
示例11: getMappedStatement
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* Get a mappedstatement by its ID
*
* @param id
* - the statement ID
* @return - the mapped statement
*/
public MappedStatement getMappedStatement(String id) {
MappedStatement ms = (MappedStatement) mappedStatements.get(id);
if (ms == null) {
throw new SqlMapException("There is no statement named " + id + " in this SqlMap.");
}
return ms;
}
示例12: setStatementTimeout
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
private static void setStatementTimeout(MappedStatement mappedStatement, Statement statement) throws SQLException {
if (mappedStatement.getTimeout() != null) {
statement.setQueryTimeout(mappedStatement.getTimeout().intValue());
}
}
示例13: insert
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
/**
* Call an insert statement by ID
*
* @param sessionScope
* - the session
* @param id
* - the statement ID
* @param param
* - the parameter object
* @return - the generated key (or null)
* @throws SQLException
* - if the insert fails
*/
public Object insert(SessionScope sessionScope, String id, Object param) throws SQLException {
Object generatedKey = null;
MappedStatement ms = getMappedStatement(id);
Transaction trans = getTransaction(sessionScope);
boolean autoStart = trans == null;
try {
trans = autoStartTransaction(sessionScope, autoStart, trans);
SelectKeyStatement selectKeyStatement = null;
if (ms instanceof InsertStatement) {
selectKeyStatement = ((InsertStatement) ms).getSelectKeyStatement();
}
// Here we get the old value for the key property. We'll want it later if for some
// reason the
// insert fails.
Object oldKeyValue = null;
String keyProperty = null;
boolean resetKeyValueOnFailure = false;
if (selectKeyStatement != null && !selectKeyStatement.isRunAfterSQL()) {
keyProperty = selectKeyStatement.getKeyProperty();
oldKeyValue = PROBE.getObject(param, keyProperty);
generatedKey = executeSelectKey(sessionScope, trans, ms, param);
resetKeyValueOnFailure = true;
}
StatementScope statementScope = beginStatementScope(sessionScope, ms);
try {
ms.executeUpdate(statementScope, trans, param);
} catch (SQLException e) {
// uh-oh, the insert failed, so if we set the reset flag earlier, we'll put the old
// value
// back...
if (resetKeyValueOnFailure)
PROBE.setObject(param, keyProperty, oldKeyValue);
// ...and still throw the exception.
throw e;
} finally {
endStatementScope(statementScope);
}
if (selectKeyStatement != null && selectKeyStatement.isRunAfterSQL()) {
generatedKey = executeSelectKey(sessionScope, trans, ms, param);
}
autoCommitTransaction(sessionScope, autoStart);
} finally {
autoEndTransaction(sessionScope, autoStart);
}
return generatedKey;
}
示例14: beginStatementScope
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
protected StatementScope beginStatementScope(SessionScope sessionScope, MappedStatement mappedStatement) {
StatementScope statementScope = new StatementScope(sessionScope);
sessionScope.incrementRequestStackDepth();
mappedStatement.initRequest(statementScope);
return statementScope;
}
示例15: getMappedStatement
import com.ibatis.sqlmap.engine.mapping.statement.MappedStatement; //導入依賴的package包/類
public MappedStatement getMappedStatement(String id) {
return delegate.getMappedStatement(id);
}