Package org.apache.ibatis.mapping

Examples of org.apache.ibatis.mapping.MappedStatement


  public int update(final String id, final Object parameterObject) throws SQLException {
    return (Integer) transactionManager.doInTransaction(new TransactionScope() {
      public Object execute(Transaction transaction) throws SQLException {
        transaction.setCommitRequired(true);
        MappedStatement ms = configuration.getMappedStatement(id);
        Executor executor = transaction.getExecutor();
        return executor.update(ms, wrapCollection(parameterObject));
      }
    });
  }
View Full Code Here


  }

  public Object queryForObject(String id, Object parameterObject, Object userObject) throws SQLException {
    Object systemObject = queryForObject(id, parameterObject);
    if (systemObject != null && userObject != null) {
      MappedStatement ms = configuration.getMappedStatement(id);
      for (ResultMap rm : ms.getResultMaps()) {
        for (ResultMapping mapping : rm.getPropertyResultMappings()) {
          MetaObject metaUserObject = MetaObject.forObject(userObject);
          MetaObject metaSystemObject = MetaObject.forObject(systemObject);
          String propName = mapping.getProperty();
          if (propName != null) {
View Full Code Here

  }

  public Object queryForObject(final String id, final Object parameterObject) throws SQLException {
    return transactionManager.doInTransaction(new TransactionScope() {
      public Object execute(Transaction transaction) throws SQLException {
        MappedStatement ms = configuration.getMappedStatement(id);
        Executor executor = transaction.getExecutor();
        List list = executor.query(ms, wrapCollection(parameterObject), RowBounds.DEFAULT, null);
        if (list.size() == 1) {
          return list.get(0);
        } else if (list.size() > 1) {
View Full Code Here

  public List queryForList(final String id, final Object parameterObject, final int skip, final int max) throws SQLException {
    return (List) transactionManager.doInTransaction(new TransactionScope() {
      public Object execute(Transaction transaction) throws SQLException {
        Executor executor = transaction.getExecutor();
        MappedStatement ms = configuration.getMappedStatement(id);
        return executor.query(ms, wrapCollection(parameterObject), new RowBounds(skip, max), null);
      }
    });
  }
View Full Code Here

  }

  public void queryWithRowHandler(final String id, final Object parameterObject, final RowHandler rowHandler) throws SQLException {
    transactionManager.doInTransaction(new TransactionScope() {
      public Object execute(Transaction transaction) throws SQLException {
        MappedStatement ms = configuration.getMappedStatement(id);
        Executor executor = transaction.getExecutor();
        return executor.query(ms, wrapCollection(parameterObject), RowBounds.DEFAULT, new ResultHandler() {
          public void handleResult(ResultContext context) {
            rowHandler.handleRow(context.getResultObject());
          }
View Full Code Here

  }

  private int getKey(String id, final Object parameterObject) throws SQLException {
    int key = Integer.MIN_VALUE;
    String selectKeyId = selectKeyIdFor(id);
    final MappedStatement keyStatement;

    if (configuration.getMappedStatementNames().contains(selectKeyId)) {
      keyStatement = configuration.getMappedStatement(selectKeyId);
    } else {
      keyStatement = null;
    }
    if (keyStatement != null) {
      List results = (List) transactionManager.doInTransaction(new TransactionScope() {
        public Object execute(Transaction transaction) throws SQLException {
          transaction.setCommitRequired(true);
          Executor executor = transaction.getExecutor();
          return executor.query(keyStatement, parameterObject, RowBounds.DEFAULT, null);
        }
      });
      try {
        key = (Integer) ((Map) results.get(0)).values().iterator().next();
      } catch (Exception e) {
        //Ignore...sometimes code sucks.  This is a good example.
      }
    }
    try {
      String property = keyStatement.getResultMaps().get(0).getResultMappings().get(0).getProperty();
      MetaObject.forObject(parameterObject).setValue(property, key);
    } catch (Exception e) {
      //Ignore...sometimes code sucks.  This is a good example.
    }
    return key;
View Full Code Here

public class FlushCacheInterceptor implements Interceptor {

  private Map<String, Set<Cache>> flushCacheMap = new HashMap<String, Set<Cache>>();

  public Object intercept(Invocation invocation) throws Throwable {
    MappedStatement statement = (MappedStatement) invocation.getArgs()[0];
    if (statement != null) {
      Set<Cache> cachesToFlush = flushCacheMap.get(statement.getId());
      if (cachesToFlush != null) {
        for (Cache c : cachesToFlush) {
          c.clear();
        }
      }
View Full Code Here

                // preserve headers
                answer.getHeaders().putAll(exchange.getIn().getHeaders());
            }

            // we should not set the body if its a stored procedure as the result is already in its OUT parameter
            MappedStatement ms = session.getConfiguration().getMappedStatement(statement);
            if (ms != null && ms.getStatementType() == org.apache.ibatis.mapping.StatementType.CALLABLE) {
                if (result == null) {
                    LOG.trace("Setting result as existing body as MyBatis statement type is Callable, and there was no result.");
                    answer.setBody(exchange.getIn().getBody());
                } else {
                    // set the result as body for insert
View Full Code Here

  }

  public void addMappedStatement(MappedStatement ms, String databaseId) {
    if (databaseId == null || databaseId.equals(this.environment.getDatabaseId())) {
      if (this.mappedStatements.containsKey(ms.getId())) {
        MappedStatement previous = this.mappedStatements.get(ms.getId());
        if (databaseId != null) {
          if (previous != null && previous.getDatabaseId() == null) {
            mappedStatements.remove(ms.getId());
          }
          mappedStatements.put(ms.getId(), ms);
        } else {
          if (previous == null || previous.getDatabaseId() == null) {
            mappedStatements.put(ms.getId(), ms);
          }
        }
      } else {
        mappedStatements.put(ms.getId(), ms);
View Full Code Here

        for (int i = 0, n = statementList.size(); i < n; i++) {
          Statement stmt = statementList.get(i);
          BatchResult batchResult = batchResultList.get(i);
          try {
            batchResult.setUpdateCounts(stmt.executeBatch());
            MappedStatement ms = batchResult.getMappedStatement();
            Object parameter = batchResult.getParameterObject();
            KeyGenerator keyGenerator = ms.getKeyGenerator();
            if (keyGenerator instanceof Jdbc3KeyGenerator) {
              keyGenerator.processAfter(this, ms, stmt, parameter);
            }
          } catch (BatchUpdateException e) {
            StringBuffer message = new StringBuffer();
View Full Code Here

TOP

Related Classes of org.apache.ibatis.mapping.MappedStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.