Package org.g4studio.core.orm.xibatis.sqlmap.engine.mapping.statement

Examples of org.g4studio.core.orm.xibatis.sqlmap.engine.mapping.statement.MappedStatement


  }

  protected void addStatementNodelets() {
    parser.addNodelet("/sqlMap/statement", new Nodelet() {
      public void process(Node node) throws Exception {
        statementParser.parseGeneralStatement(node, new MappedStatement());
      }
    });
    parser.addNodelet("/sqlMap/insert", new Nodelet() {
      public void process(Node node) throws Exception {
        statementParser.parseGeneralStatement(node, new InsertStatement());
View Full Code Here


      TypeHandlerFactory typeHandlerFactory = getDelegate().getTypeHandlerFactory();

      String statementName = mapping.getStatementName();
      SqlMapClientImpl client = (SqlMapClientImpl) statementScope.getSession().getSqlMapClient();

      MappedStatement mappedStatement = client.getMappedStatement(statementName);
      Class parameterType = mappedStatement.getParameterClass();
      Object parameterObject = null;

      if (parameterType == null) {
        parameterObject = prepareBeanParameterObject(statementScope, rs, mapping, parameterType);
      } else {
        if (typeHandlerFactory.hasTypeHandler(parameterType)) {
          parameterObject = preparePrimitiveParameterObject(rs, mapping, parameterType);
        } else if (DomTypeMarker.class.isAssignableFrom(parameterType)) {
          parameterObject = prepareDomParameterObject(rs, mapping);
        } else {
          parameterObject = prepareBeanParameterObject(statementScope, rs, mapping, parameterType);
        }
      }

      Object result = null;
      if (parameterObject != null) {

        Sql sql = mappedStatement.getSql();
        ResultMap resultMap = sql.getResultMap(statementScope, parameterObject);
        Class resultClass = resultMap.getResultClass();

        if (resultClass != null && !DomTypeMarker.class.isAssignableFrom(targetType)) {
          if (DomCollectionTypeMarker.class.isAssignableFrom(resultClass)) {
View Full Code Here

      String cacheName = (String) cacheNames.next();
      CacheModel cacheModel = client.getDelegate().getCacheModel(cacheName);
      Iterator statementNames = cacheModel.getFlushTriggerStatementNames();
      while (statementNames.hasNext()) {
        String statementName = (String) statementNames.next();
        MappedStatement statement = client.getDelegate().getMappedStatement(statementName);
        if (statement != null) {
          statement.addExecuteListener(cacheModel);
        } else {
          throw new RuntimeException("Could not find statement named '" + statementName
              + "' for use as a flush trigger for the cache model named '" + cacheName + "'.");
        }
      }
View Full Code Here

   * @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;
  }
View Full Code Here

   *             - 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)
View Full Code Here

   *             - 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);
View Full Code Here

   */
  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);
View Full Code Here

      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))
          ;
      }
    }
View Full Code Here

   */
  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);
View Full Code Here

   *             - 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);
View Full Code Here

TOP

Related Classes of org.g4studio.core.orm.xibatis.sqlmap.engine.mapping.statement.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.