jp.terasoluna.fw.collector.db.Queueing1NRelationResultHandlerImpl.java Source code

Java tutorial

Introduction

Here is the source code for jp.terasoluna.fw.collector.db.Queueing1NRelationResultHandlerImpl.java

Source

/*
 * Copyright (c) 2011 NTT DATA Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jp.terasoluna.fw.collector.db;

import java.lang.reflect.InvocationTargetException;

import jp.terasoluna.fw.collector.LogId;
import jp.terasoluna.fw.collector.vo.DataValueObject;
import jp.terasoluna.fw.exception.SystemException;
import jp.terasoluna.fw.logger.TLogger;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.PropertyUtils;

/**
 * Queueing1NRelationResultHandlerImpl?<br>
 * <p>
 * QueueingResultHandlerImpl?1:N<br>
 * 1:N?iBATIS?1:N?????? ResultHandler#handleResult()????? ?????
 * ResultHandler#handleResult()????????????? ??? ??????iBATIS????????<br>
 * ???1:N?iBATIS????????? ResultHandler#handleResult()?????iBATIS????????
 * ?????ResultHandler#handleResult()????????
 * ResultHandler#handleResult()??????
 * </p>
 * <p>
 * ??
 * <ul>
 * <li>resultMap??groupBy???1???(ORDER BY)???<br>
 * (???????????? 1:N??????BLogic???????????)</li>
 * </ul>
 * </p>
 * <p>
 * ????
 * <ul>
 * <li>?sqlMap?iBATIS?1:N????? ????????????<br>
 * (1:N?????? ?????????? QueueingResultHandlerImpl???)</li>
 * </ul>
 * </p>
 * <p>
 * sqlMap1(1:N)
 * 
 * <pre>
 * &lt;resultMap id=&quot;rmap_JB1231_SQL&quot; class=&quot;sample.JB1231Data&quot; &lt;b&gt;groupBy=&quot;col1&quot;&lt;/b&gt;&gt;
 *   &lt;result property=&quot;col1&quot;/&gt;
 *   &lt;result property=&quot;col2&quot;/&gt;
 *   &lt;result property=&quot;col3&quot;/&gt;
 *   &lt;result property=&quot;detail1&quot; resultMap=&quot;rmap_JB1231_SQL_detail1&quot;/&gt;
 * &lt;/resultMap&gt;
 * &lt;resultMap id=&quot;rmap_JB1231_SQL_detail1&quot; class=&quot;sample.Detail1&quot;&gt;
 *   &lt;result property=&quot;d12&quot; column=&quot;d12&quot;/&gt;
 *   &lt;result property=&quot;d13&quot; column=&quot;d13&quot;/&gt;
 * &lt;/resultMap&gt;
 * &lt;select id=&quot;JB1231_SQL&quot; resultMap=&quot;rmap_JB1231_SQL&quot;&gt;
 *     SELECT
 *       t1.col1 as col1,
 *       t1.col2 as col2,
 *       t1.col3 as col3,
 *       d1.col2 as d12,
 *       d1.col3 as d13,
 *     FROM (sample_table1 t1
 *       left outer join sample_table1_detail1 d1 on t1.col1 = d1.col1)
 *     &lt;b&gt;ORDER BY col1&lt;/b&gt;, ...
 * &lt;/select&gt;
 * </pre>
 * 
 * sqlMap2(1:M:N)
 * 
 * <pre>
 * &lt;resultMap id=&quot;rmap_JB1231_SQL&quot; class=&quot;sample.JB1231Data&quot; &lt;b&gt;groupBy=&quot;col1&quot;&lt;/b&gt;&gt;
 *   &lt;result property=&quot;col1&quot;/&gt;
 *   &lt;result property=&quot;col2&quot;/&gt;
 *   &lt;result property=&quot;col3&quot;/&gt;
 *   &lt;result property=&quot;detail1&quot; resultMap=&quot;rmap_JB1231_SQL_detail1&quot;/&gt;
 *   &lt;result property=&quot;detail2&quot; resultMap=&quot;rmap_JB1231_SQL_detail2&quot;/&gt;
 * &lt;/resultMap&gt;
 * &lt;resultMap id=&quot;rmap_JB1231_SQL_detail1&quot; class=&quot;sample.Detail1&quot;&gt;
 *   &lt;result property=&quot;d12&quot; column=&quot;d12&quot;/&gt;
 *   &lt;result property=&quot;d13&quot; column=&quot;d13&quot;/&gt;
 * &lt;/resultMap&gt;
 * &lt;resultMap id=&quot;rmap_JB1231_SQL_detail2&quot; class=&quot;sample.Detail2&quot;&gt;
 *   &lt;result property=&quot;d22&quot; column=&quot;d22&quot;/&gt;
 *   &lt;result property=&quot;d23&quot; column=&quot;d23&quot;/&gt;
 * &lt;/resultMap&gt;
 * &lt;select id=&quot;JB1231_SQL&quot; resultMap=&quot;rmap_JB1231_SQL&quot;&gt;
 *   SELECT * FROM (
 *     SELECT
 *       t1.col1 as col1,
 *       t1.col2 as col2,
 *       t1.col3 as col3,
 *       d1.col2 as d12,
 *       d1.col3 as d13,
 *       null as d22,
 *       null as d23
 *     FROM (sample_table1 t1
 *       left outer join sample_table1_detail1 d1 on t1.col1 = d1.col1)
 *     UNION ALL
 *     SELECT
 *       t1.col1 as col1,
 *       t1.col2 as col2,
 *       t1.col3 as col3,
 *       null as d12,
 *       null as d13,
 *       d2.col2 as d22,
 *       d2.col3 as d23
 *     FROM (sample_table1 t1
 *       left outer join sample_table1_detail2 d2 on t1.col1 = d2.col1)
 *   ) AS A &lt;b&gt;ORDER BY col1&lt;/b&gt;, ...
 * &lt;/select&gt;
 * </pre>
 * 
 * </p>
 * @deprecated
 * 1:N????MyBatis3?select?resultOrderedtrue??????
 * {@code Queueing1NRelationResultHandlerImpl}???{@code DaoCollectorConfig#setRelation1n()}??????
 * @see <a href="http://mybatis.github.io/mybatis-3/ja/sqlmap-xml.html">http://mybatis.github.io/mybatis-3/ja/sqlmap-xml.html</a>
 */
@Deprecated
public class Queueing1NRelationResultHandlerImpl<T> extends QueueingResultHandlerImpl<T> {

    /**
     * Log.
     */
    private static final TLogger LOGGER = TLogger.getLogger(Queueing1NRelationResultHandlerImpl.class);

    /**
     * ?handleResult???<code>Row</code>???
     */
    @Override
    public void delayCollect() {
        if (this.prevRow == null) {
            return;
        }
        if (Thread.currentThread().isInterrupted()) {
            return;
        }
        try {
            // ??
            Object copy = BeanUtils.cloneBean(this.prevRow);
            PropertyUtils.copyProperties(this.prevRow, this.prevRow.getClass().newInstance());

            if (this.daoCollector != null) {
                // ????1???
                this.daoCollector.addQueue(new DataValueObject(copy, this.dataCount.incrementAndGet()));
            }
        } catch (IllegalAccessException e) {
            throw new SystemException(e);
        } catch (InstantiationException e) {
            throw new SystemException(e);
        } catch (InvocationTargetException e) {
            throw new SystemException(e);
        } catch (NoSuchMethodException e) {
            throw new SystemException(e);
        } catch (InterruptedException e) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace(LogId.TAL041002, Thread.currentThread().getName());
            }
            // InterruptedException??????
            // ?????????????????????
            Thread.currentThread().interrupt();
        }
    }
}