com.tida_okinawa.corona.io.dam.hibernate.IoService.java Source code

Java tutorial

Introduction

Here is the source code for com.tida_okinawa.corona.io.dam.hibernate.IoService.java

Source

/**
 * @version $Id: IoService.java 1135 2013-09-10 00:33:04Z hajime-uchihara $
 *
 * 2013/10/28 10:56:24
 * @author hajime-uchihara
 *
 * Copyright 2011-2014 TIDA All Rights Reserved.
 */
package com.tida_okinawa.corona.io.dam.hibernate;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import com.tida_okinawa.corona.CoronaActivator;
import com.tida_okinawa.corona.PreferenceInitializer;
import com.tida_okinawa.corona.io.IoActivator;
import com.tida_okinawa.corona.io.bean.CategoryBean;
import com.tida_okinawa.corona.io.bean.ClaimsBean;
import com.tida_okinawa.corona.io.bean.CoronaDbVersionBean;
import com.tida_okinawa.corona.io.bean.DicCommonBean;
import com.tida_okinawa.corona.io.bean.DicPriorityBean;
import com.tida_okinawa.corona.io.bean.DicTableBean;
import com.tida_okinawa.corona.io.bean.FieldsBean;
import com.tida_okinawa.corona.io.bean.ProductBean;
import com.tida_okinawa.corona.io.bean.ProjectBean;
import com.tida_okinawa.corona.io.bean.RelClmProductBean;
import com.tida_okinawa.corona.io.bean.RelPrjClmBean;
import com.tida_okinawa.corona.io.bean.RelPrjProductBean;
import com.tida_okinawa.corona.io.bean.TablesBean;
import com.tida_okinawa.corona.io.bean.TypePatternBean;
import com.tida_okinawa.corona.io.bean.WorkdatasBean;
import com.tida_okinawa.corona.io.dam.hibernate.hql.CommonCreateQuery;
import com.tida_okinawa.corona.io.model.ClaimWorkDataType;
import com.tida_okinawa.corona.io.model.IClaimData;
import com.tida_okinawa.corona.io.model.IClaimWorkData;
import com.tida_okinawa.corona.io.model.ICoronaProduct;
import com.tida_okinawa.corona.io.model.ICoronaProject;
import com.tida_okinawa.corona.io.model.TextItem;
import com.tida_okinawa.corona.io.model.dic.DicType;
import com.tida_okinawa.corona.io.model.dic.ICoronaDic;
import com.tida_okinawa.corona.io.model.dic.IDicFactory;
import com.tida_okinawa.corona.io.model.dic.IUserDic;
import com.tida_okinawa.corona.io.model.dic.PatternType;
import com.tida_okinawa.corona.io.model.dic.TermCForm;
import com.tida_okinawa.corona.io.model.dic.TermClass;
import com.tida_okinawa.corona.io.model.dic.TermPart;
import com.tida_okinawa.corona.io.model.table.IFieldHeader;
import com.tida_okinawa.corona.io.model.table.TableType;
import com.tida_okinawa.corona.io.model.table.impl.FieldHeader;
import com.tida_okinawa.corona.io.service.IIoService;
import com.tida_okinawa.corona.io.service.abstraction.AbstractIoService;
import com.tida_okinawa.corona.io.util.CoronaIoUtils;
import com.tida_okinawa.corona.license.LicenseActivator;

/**
 * @author wataru-higa
 */
public final class IoService extends AbstractIoService {

    /**
     * 
     */
    private static IIoService _instance = new IoService();

    /**
     * ???
     */
    private IoService() {

    }

    /**
     * ?
     * 
     * @return _instance
     */
    public static IIoService getInstance() {
        return _instance;
    }

    /* ****************************************
     * DB
     */
    /**
     * SQLException?DB????????????SQLState??????
     */
    public static final String ER_CODE_CONNECTION_FAILED = "Corona:0001"; //$NON-NLS-1$

    /**
     * ?
     */
    private volatile Session session = null;

    /**
     * ?
     * 
     * @param connect
     * @param user
     * @param passwd
     * @return true/false
     */
    @Override
    protected synchronized Boolean connectDam(String connect, String user, String passwd) {
        // TODO getPatternTypes()????
        try {
            Configuration config = new org.hibernate.cfg.Configuration().configure()
                    .setProperty("hibernate.connection.url", connect) //$NON-NLS-1$
                    .setProperty("hibernate.connection.username", user) //$NON-NLS-1$
                    .setProperty("hibernate.connection.password", passwd); //$NON-NLS-1$
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
                    .buildServiceRegistry();
            SessionFactory sessionFactory = null; // config.buildSessionFactory(serviceRegistry);
            try {
                sessionFactory = config.buildSessionFactory(serviceRegistry);
            } catch (HibernateException ee) {
                throw ee;
            } catch (Exception ex) {
                ex.printStackTrace();
                /* ???? NullPointerException????????? */
                if (ex instanceof NullPointerException) {
                    return false;
                }
                throw ex;
            }

            this.session = sessionFactory.openSession();
            this.session.setFlushMode(FlushMode.MANUAL);

            /*  */
            this.session.beginTransaction();
            if (!isConnect()) {
                // DB????????????
                LicenseActivator license = LicenseActivator.getDefault();
                String dbVersion = license.getDbVersion().trim();
                CoronaDbVersionBean bean = new CoronaDbVersionBean();
                bean.setVersion(dbVersion);
                this.session.save(bean);
                this.session.flush();
            }

            this.getPatternTypes();
            this.strConnect = connect;
            this.strUser = user;
            this.strPasswd = passwd;
            if (CoronaActivator.getDefault() != null) {
                CoronaActivator.getDefault().getLogger().getOutStream()
                        .println(Messages.IoService_connectDatabaseSuccess + strConnect);
            }
            /*  */
            this.session.getTransaction().commit();
            return true;
        } catch (HibernateException e) {
            System.err.println(Messages.IoService_errorConnectDatabase);
            e.printStackTrace();
            if (this.session != null) {
                if (this.session.isConnected()) {
                    this.session.disconnect();
                    this.session.close();
                }
            }
            return false;
        } finally {
            if (session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
    }

    /**
     * ?
     * 
     * @return true/false
     */
    @Override
    protected synchronized Boolean disConnectDam() {
        try {
            this.session.disconnect();
            this.session.close();
            if (this.session.isOpen()) {
                return false;
            } else {
                CoronaActivator.getDefault().getLogger().getOutStream()
                        .println(Messages.IoService_connectDatabaseFail + strConnect);
                return true;
            }
        } catch (HibernateException e) {
            System.err.println(Messages.IoService_errorDisconnectionDatabase);
            e.printStackTrace();
            return false;
        }
    }

    /**
     * ??
     * 
     * @return true/false
     */
    @Override
    protected Boolean isConnectDam() {
        try {
            if (this.session == null) {
                return false;
            }
            Object result = CommonCreateQuery.getCoronaDbVersionQuery(this.session).uniqueResult();
            if (result != null) {
                return true;
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            return false;
        }
        return false;
    }

    /**
     * TODO:?????????????????
     */
    @Override
    public String[] connectTest(String connect, String user, String passwd) {
        boolean connected = false;
        Session session = null;
        try {
            Configuration config = new Configuration().configure().setProperty("hibernate.connection.url", connect) //$NON-NLS-1$
                    .setProperty("hibernate.connection.username", user) //$NON-NLS-1$
                    .setProperty("hibernate.connection.password", passwd); //$NON-NLS-1$
            ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties())
                    .buildServiceRegistry();
            SessionFactory sessionFactory = config.buildSessionFactory(serviceRegistry);
            session = sessionFactory.openSession();
            Object isConnected = CommonCreateQuery.getCoronaDbVersionQuery(session).uniqueResult();
            if (isConnected != null) {
                connected = true;
            }
            session.close();
            session = null;
        } catch (HibernateException e) {
            return new String[] { e.getMessage() };
        } finally {
            if (session != null) {
                if (session.isOpen()) {
                    session.close();
                    session = null;
                }
            }
        }
        if (connected) {
            return new String[0];
        } else {
            return new String[] { "???????" }; //$NON-NLS-1$
        }
    }

    /**
     * ??
     * 
     * @return SQLConnection??????????
     */
    @Override
    public Session getSession() {
        if (!isConnectDam()) {
            CoronaActivator activator = CoronaActivator.getDefault();
            if (activator != null) {
                final int retryCount = activator.getPreferenceStore()
                        .getInt(PreferenceInitializer.PREF_DB_RETRY_CNT);

                PrintStream out = activator.getLogger().getOutStream();
                out.println(Messages.IoService_reconnectDatabase);

                for (int i = 1; i <= retryCount; i++) {
                    out.print(Messages.bind(Messages.IoService_reconnect, i));
                    reConnect();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        CoronaActivator.debugLog(Messages.IoService_interrupt);
                    }

                    if (this.session.isConnected() && isConnectDam()) {
                        out.println(Messages.IoService_connectionSuccess);
                        return this.session;
                    }
                    out.println(Messages.IoService_connectionFail);
                }

                /*  */
                HibernateException connectError = new HibernateException(
                        Messages.IoService_errorReconnectDatabaseFail + " " + ER_CODE_CONNECTION_FAILED); //$NON-NLS-1$
                IStatus status = new Status(IStatus.ERROR, IoActivator.PLUGIN_ID,
                        Messages.IoService_errorReconnectDatabaseFail, connectError);
                activator.getLog().log(status);
                try {
                    throw connectError;
                } catch (HibernateException e1) {
                    e1.printStackTrace();
                }
            }
            throw new RuntimeException(Messages.IoService_errorEndCoronaActivator);
        }

        return this.session;
    }

    /* ****************************************
     * 
     */
    /**
     * ?
     * 
     * @return List<ICoronaProject>
     * 
     */
    @Override
    public Map<Integer, ICoronaProject> getProjectsMap() {
        if (_projectList == null) {
            updateProjects();
        }
        return _projectList;
    }

    /**
     * 
     * 
     * @param project
     * @return true/false
     */
    @Override
    protected Boolean addProjectDam(ICoronaProject project) {
        ProjectBean result = null;

        try {
            /* ?? */
            @SuppressWarnings("unchecked")
            List<ProjectBean> list = CommonCreateQuery.getProjectQuery(project.getName()).list();
            if (list != null && list.size() > 0) {
                result = list.get(0);
            }
            if (result != null) {
                project.setId(result.getProjectId());
                project.update();
                return true;
            }

            try {
                // ?
                ProjectBean projectBean = new ProjectBean();
                projectBean.setProjectName(project.getName());

                /*  */
                this.session.beginTransaction();
                this.session.save(projectBean);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();

                // INSERT?ID???
                project.setId(projectBean.getProjectId());

                /* ? */
                updateDictionarys();

                // JUMAN?????
                List<ICoronaDic> dics = getDictionarys(IUserDic.class);
                for (ICoronaDic dic : dics) {
                    if (((IUserDic) dic).getDicType().getIntValue() == DicType.JUMAN.getIntValue()) {
                        project.addDictionary(dic);
                    }
                }

                return true;
            } catch (HibernateException ee) {
                ee.printStackTrace();
                throw new HibernateException(Messages.IoService_errorSetProjectInfo);
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            return false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
    }

    /**
     * ?
     */
    @Override
    public Boolean removeProject(ICoronaProject project) {

        try {
            boolean result = true;
            /* ? */
            for (ICoronaProduct product : project.getProducts()) {
                /* ConcurrentModificationException */
                List<IClaimWorkData> works = new ArrayList<IClaimWorkData>(product.getClaimWorkDatas());
                for (IClaimWorkData workData : works) {
                    if (workData.getClaimWorkDataType() != ClaimWorkDataType.CORRECTION_MISTAKES) {
                        product.removeClaimWorkData(workData);
                    }
                }
            }

            /* ? */
            if (project.getProducts().size() > 0) {
                for (ICoronaProduct product : project.getProducts()) {
                    try {
                        RelPrjProductBean relPrjPrd = (RelPrjProductBean) CommonCreateQuery
                                .getRelPrjProductQuery(project.getId(), product.getId()).uniqueResult();
                        if (relPrjPrd != null) {
                            /*  */
                            this.session.beginTransaction();
                            this.session.delete(relPrjPrd);
                            this.session.flush();
                            /*  */
                            this.session.getTransaction().commit();
                        }
                        relPrjPrd = (RelPrjProductBean) CommonCreateQuery
                                .getRelPrjProductQuery(project.getId(), product.getId()).uniqueResult();
                        /* -? */
                        if (relPrjPrd != null) {
                            result = false;
                        }
                    } catch (HibernateException ee) {
                        ee.printStackTrace();
                        result = false;
                    } finally {
                        if (this.session.getTransaction().isActive()) {
                            this.session.getTransaction().rollback();
                        }
                    }
                }
            }

            /* -()? */
            /* rel_clm_product?rel_prj_clm? */
            for (IClaimData claim : project.getClaimDatas()) {

                // rel_clm_product??
                int claimId = claim.getId();
                int id = project.getId();
                try {
                    StringBuilder sql = new StringBuilder(128);
                    sql.append("DELETE FROM REL_CLM_PRODUCT WHERE TBL_ID = ").append(claimId) //$NON-NLS-1$
                            .append(" AND PRJ_ID = ").append(id); //$NON-NLS-1$
                    /*  */
                    this.session.beginTransaction();
                    /* rel_clm_product? */
                    this.session.createSQLQuery(sql.toString()).executeUpdate();
                    this.session.flush();
                    /* rel_prj_clm?? */
                    RelPrjClmBean delRelPrjClm = (RelPrjClmBean) CommonCreateQuery
                            .getRelPrjClmQuery(claim.getId(), project.getId()).uniqueResult();
                    if (delRelPrjClm != null) {
                        this.session.delete(delRelPrjClm);
                        this.session.flush();
                    }
                    /*  */
                    this.session.getTransaction().commit();

                    delRelPrjClm = (RelPrjClmBean) CommonCreateQuery
                            .getRelPrjClmQuery(claim.getId(), project.getId()).uniqueResult();
                    if (delRelPrjClm != null) {
                        result = false;
                    }

                } catch (HibernateException ee) {
                    ee.printStackTrace();
                    result = false;
                } finally {
                    if (this.session.getTransaction().isActive()) {
                        this.session.getTransaction().rollback();
                    }
                }
            }

            /* -? */
            /* rel_prj_dic? */
            try {
                int projectId = project.getId();
                StringBuilder sql = new StringBuilder(64);
                sql.append("DELETE FROM REL_PRJ_DIC WHERE PROJECT_ID = ").append(projectId); //$NON-NLS-1$
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(sql.toString()).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException ex) {
                ex.printStackTrace();
                result = false;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }

            /* ? */
            /* project?? */
            if (result) {
                try {
                    ProjectBean delProject = (ProjectBean) CommonCreateQuery.getProjectQuery(project.getName())
                            .uniqueResult();
                    /*  */
                    this.session.beginTransaction();
                    if (delProject != null) {
                        this.session.delete(delProject);
                        this.session.flush();
                    }
                    /*  */
                    this.session.getTransaction().commit();
                    delProject = (ProjectBean) CommonCreateQuery.getProjectQuery(project.getName()).uniqueResult();
                    if (delProject != null) {
                        result = false;
                    }
                } catch (HibernateException ee) {
                    ee.printStackTrace();
                    result = false;
                } finally {
                    if (this.session.getTransaction().isActive()) {
                        this.session.getTransaction().rollback();
                    }
                }
                // ?
                super.removeProject(project);
            }
            return result;
        } catch (HibernateException e) {
            e.printStackTrace();
            return false;
        }
    }

    /**
     * 
     * 
     * 
     * @returnIStatus
     */
    private IStatus updateProjects() {
        if (_projectList == null) {
            _projectList = new HashMap<Integer, ICoronaProject>();
        }
        try {
            @SuppressWarnings("unchecked")
            List<ProjectBean> projects = CommonCreateQuery.getProjectQuery().list();
            for (ProjectBean project : projects) {
                ICoronaProject coronaProject = _projectList.get(project.getProjectId());
                if (coronaProject == null) {
                    coronaProject = new Project(project.getProjectName(), project.getProjectId());
                    _projectList.put(project.getProjectId(), coronaProject);
                } else {
                    coronaProject.setName(project.getProjectName());
                }
            }
            return Status.OK_STATUS;
        } catch (HibernateException e) {
            e.printStackTrace();
            return new Status(IStatus.ERROR, IoActivator.PLUGIN_ID,
                    Messages.IoService_errorGetProjectInfo + e.getLocalizedMessage(), e);
        }
    }

    /* ****************************************
     * ?????
     */
    /**
     * claimList
     */
    private Map<Integer, IClaimData> _claimList;

    @Override
    public Map<Integer, IClaimData> getClaimDatasMap() {
        if (_claimList == null) {
            updateClaimDatas();
        }
        return _claimList;
    }

    @Override
    public IClaimData getClaimData(int claimId) {
        if (_claimList == null) {
            updateClaimDatas();
        }
        return _claimList.get(claimId);
    }

    /**
     * ?????
     * 
     * @return IStatus
     */
    private IStatus updateClaimDatas() {
        if (_claimList == null) {
            _claimList = new HashMap<Integer, IClaimData>();
        }

        try {
            @SuppressWarnings("unchecked")
            Iterator<TablesBean> tableList = CommonCreateQuery.getTablesQuery(TableType.CLAIM_DATA.getIntValue())
                    .iterate();
            while (tableList.hasNext()) {
                TablesBean table = tableList.next();
                if (!_claimList.containsKey(table.getId())) {
                    _claimList.put(table.getId(), new ClaimData(table.getName(), table.getDbname(), table.getId()));
                }
            }

            /* TODO ????????????update???? */
            for (Entry<Integer, IClaimData> entry : _claimList.entrySet()) {
                entry.getValue().update();
            }
            return Status.OK_STATUS;
        } catch (HibernateException e) {
            return new Status(IStatus.ERROR, IoActivator.PLUGIN_ID,
                    Messages.IoService_getDataFileFail + e.getLocalizedMessage(), e);
        }
    }

    @Override
    public Boolean removeClaimData(int claimId) {
        boolean result = true;
        ClaimData claim = (ClaimData) this.getClaimData(claimId);
        if (claim == null)
            return false;

        String clmTblName = claim.getTableName();
        String cmTblName = CoronaIoUtils.createWorkTableName(clmTblName, TableType.CORRECTION_MISTAKES_DATA, 0);

        /* ??????? */
        // claims??
        try {
            ClaimsBean delClaim = (ClaimsBean) this.session.get(ClaimsBean.class, claimId);
            if (delClaim != null) {
                /*  */
                this.session.beginTransaction();
                this.session.delete(delClaim);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
                delClaim = (ClaimsBean) this.session.get(ClaimsBean.class, claimId);
                if (delClaim != null) {
                    result = false;
                }
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ?? */
        // fields??
        try {
            FieldsBean delField = (FieldsBean) this.session.get(FieldsBean.class, claimId);
            if (delField != null) {
                /*  */
                this.session.beginTransaction();
                this.session.delete(delField);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
                delField = (FieldsBean) this.session.get(FieldsBean.class, claimId);
                if (delField != null) {
                    result = false;
                }
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ??? */
        // dic_pri?workdatas?
        String strQuery = null;
        try {
            Query query = CommonCreateQuery.getWorkdatasQuery(0, 0, claimId, ClaimWorkDataType.CORRECTION_MISTAKES);
            strQuery = query.toString();
            @SuppressWarnings("unchecked")
            List<WorkdatasBean> delWorkDatas = query.list();
            /*  */
            this.session.beginTransaction();
            for (WorkdatasBean workdata : delWorkDatas) {
                /* ? */
                @SuppressWarnings("unchecked")
                List<DicPriorityBean> delDicPriList = CommonCreateQuery.getDicPriQuery(workdata.getId()).list();
                for (DicPriorityBean dicPri : delDicPriList) {
                    // dic_pri??
                    this.session.delete(dicPri);
                    this.session.flush();
                }
                // workdatas??
                this.session.delete(workdata);
                this.session.flush();
            }
            /*  */
            this.session.getTransaction().commit();

            /* ?? */
            @SuppressWarnings("unchecked")
            List<WorkdatasBean> checkDeleteWorkDatas = query.list();
            if (checkDeleteWorkDatas != null && checkDeleteWorkDatas.size() > 0) {
                /*  */
                result = false;
            }

        } catch (HibernateException e) {
            CoronaActivator.debugLog("CommonCreateQuery.getWorkdatasQuery[ " + strQuery + " ]"); //$NON-NLS-1$ //$NON-NLS-2$
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ?? */
        // tables??
        TablesBean delTable = null;
        boolean delExecFlag = false;
        try {
            @SuppressWarnings("unchecked")
            List<TablesBean> list = CommonCreateQuery.getTablesQuery(cmTblName).list();
            if (list != null && list.size() > 0) {
                delTable = list.get(0);
            }
            if (delTable != null) {
                delExecFlag = true;
                /*  */
                this.session.beginTransaction();
                this.session.delete(delTable);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();

                @SuppressWarnings("unchecked")
                List<TablesBean> checkList = CommonCreateQuery.getTablesQuery(cmTblName).list();
                if (checkList != null && checkList.size() > 0) {
                    result = false;
                }
            }
            // TODOSession?????????
            /* ? */
            // usr_claim_xxx?
            if (delExecFlag) {
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery("DROP TABLE " + cmTblName).executeUpdate(); //$NON-NLS-1$
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        // // TODOSession?????????
        // /* ? */
        // // usr_claim_xxx?
        // try {
        // if (delExecFlag) {
        // /*  */
        // this.session.beginTransaction();
        //                this.session.createSQLQuery("DROP TABLE " + cmTblName).executeUpdate(); //$NON-NLS-1$
        // this.session.flush();
        // /*  */
        // this.session.getTransaction().commit();
        // }
        // } catch (HibernateException e) {
        // e.printStackTrace();
        // result = false;
        // } finally {
        // if (this.session.getTransaction().isActive()) {
        // this.session.getTransaction().rollback();
        // }
        // }

        /* Product?? */
        // rel_clm_product??
        try {
            @SuppressWarnings("unchecked")
            List<RelClmProductBean> delRelClmProductList = CommonCreateQuery.getRelClmProductQuery(claimId).list();
            /*  */
            this.session.beginTransaction();
            for (RelClmProductBean delRelClmProduct : delRelClmProductList) {
                this.session.delete(delRelClmProduct);
            }
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* Project?? */
        // rel_prj_clm??
        try {
            @SuppressWarnings("unchecked")
            List<RelPrjClmBean> delRelPrjClmList = CommonCreateQuery.getRelPrjClmQuery(claimId).list();
            /*  */
            this.session.beginTransaction();
            for (RelPrjClmBean delRelPrjClm : delRelPrjClmList) {
                if (delRelPrjClm != null) {
                    this.session.delete(delRelPrjClm);
                }
            }
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ?? */
        try {
            TablesBean delTableOrg = (TablesBean) this.session.get(TablesBean.class, claimId);
            if (delTableOrg != null) {
                /*  */
                this.session.beginTransaction();
                this.session.delete(delTableOrg);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ? */
        try {
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery("DROP TABLE " + clmTblName).executeUpdate(); //$NON-NLS-1$
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            e.printStackTrace();
            result = false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        this._claimList.remove(claimId);
        this.updateClaimDatas();

        return result;
    }

    /**
     * ??????
     * 
     * @param path
     * @param definePath
     * @param tableName
     * @return IClaimData
     * 
     */
    @Override
    protected IClaimData importClaimDataDam(String path, String definePath, String tableName, boolean headFlg)
            throws SQLException, IOException {
        /* ????? */
        String strSQL;
        String fileName;
        String dbName = tableName;

        /* DB_NAME */
        fileName = path;
        int idx = path.lastIndexOf(File.separatorChar);
        if (idx > 0) {
            fileName = path.substring(idx + 1);
        }
        dbName = CoronaIoUtils.createWorkTableName(dbName, TableType.CLAIM_DATA, -1);

        strSQL = null;
        try {

            /*  */
            this.session.beginTransaction();
            /* ????? */
            Query query = CommonCreateQuery.createUsrClaimTableSQLQuery(definePath, dbName);
            strSQL = query.toString();
            query.executeUpdate();
            this.session.flush();

            /* ? */
            String[] columns = null;
            strSQL = "SHOW COLUMNS FROM " + dbName; //$NON-NLS-1$
            List<String> tableColumns = new ArrayList<String>();
            @SuppressWarnings("unchecked")
            List<Object[]> columnsList = session.createSQLQuery(strSQL).list();
            if (columnsList != null) {
                for (Object[] rs : columnsList) {
                    tableColumns.add((String) rs[0]);
                }
                columns = tableColumns.toArray(new String[tableColumns.size()]);
            }

            /* ID???? */
            StringBuilder strColumns = new StringBuilder(100);
            for (int i = 1; i < columns.length; i++) {
                strColumns.append(",").append(columns[i]); //$NON-NLS-1$
            }
            /* ?????? */
            strSQL = "loadDataInUsrClaimTableSQLQuery()"; //$NON-NLS-1$

            query = CommonCreateQuery.loadDataInUsrClaimTableSQLQuery(path, dbName, strColumns.substring(1),
                    headFlg);
            if (query == null) {
                return null;
            }

            /* ??SQL?? */
            strSQL = query.toString();

            /* ?? */
            query.executeUpdate();
            this.session.flush();

            /*  */
            this.session.getTransaction().commit();

            String strExeSql = null;
            // INSERT IGNORE INTO TABLES....???
            StringBuilder strCheckHQL = new StringBuilder(150)
                    .append("from TablesBean where name = :NAME and dbname = :DBNAME and type = :TYPE"); //$NON-NLS-1$
            @SuppressWarnings("unchecked")
            List<TablesBean> tableBeanlist = session.createQuery(strCheckHQL.toString()).setString("NAME", fileName) //$NON-NLS-1$
                    .setString("DBNAME", dbName) //$NON-NLS-1$
                    .setInteger("TYPE", TableType.CLAIM_DATA.getIntValue()) //$NON-NLS-1$
                    .list();

            if (tableBeanlist != null && tableBeanlist.size() == 0) {
                StringBuilder strSql = new StringBuilder(128)
                        .append("INSERT INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                strSql.append(fileName).append("','").append(dbName).append("',") //$NON-NLS-1$//$NON-NLS-2$
                        .append(TableType.CLAIM_DATA.getIntValue()).append(",now())"); //$NON-NLS-1$
                strExeSql = strSql.toString();
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }

            int claimId = 0;
            int keyId = 1;
            /* ? */
            strExeSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(dbName) //$NON-NLS-1$
                    .append("'").toString(); //$NON-NLS-1$
            @SuppressWarnings("unchecked")
            List<Object> idList = this.session.createSQLQuery(strExeSql).list();
            if (idList != null && idList.size() > 0) {
                Object rs = idList.get(0);
                claimId = Integer.parseInt(rs.toString());
            }

            /* ID? */
            int workId = 0;
            workId = createClaimWorkDataTable(TableType.CORRECTION_MISTAKES_DATA.toString(), dbName,
                    TableType.CORRECTION_MISTAKES_DATA, 0, 0, 0, null);

            /* ????? */
            /*
             * ClaimWorkDataDao.insertCorrectionMistakes(claimId, keyId,
             * workId);
             * ??
             */
            ClaimsBean claims = (ClaimsBean) this.session.get(ClaimsBean.class, claimId);
            if (claims == null) {
                // ??
                claims = new ClaimsBean();
                claims.setId(claimId);
            }
            claims.setKeyFieldId(keyId);
            claims.setProductFieldId(0);
            claims.setTargetFields("0"); //$NON-NLS-1$
            claims.setExternalFlag(false);
            claims.setInternalFlag(false);
            claims.setWorkTableId(workId);
            /*  */
            this.session.beginTransaction();
            this.session.save(claims);
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();

            /* ????? */
            updateClaimDatas();
            /* ? */
            return getClaimData(claimId);

        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strSQL); //$NON-NLS-1$
            e.printStackTrace();
            return null;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
    }

    /**
     * ??????
     * 
     * @param path
     *            
     * @param tableName
     *            ??
     * @param target
     *            ??
     * @param records
     *            
     * @return IClaimData
     */
    @Override
    protected IClaimData importClaimDataDamForDocument(String path, String tableName, String target,
            List<String> records) throws SQLException, IOException, HibernateException {
        String fileName;
        String dbName = tableName;
        String strExeSql = null;

        /* DB_NAME */
        fileName = path;
        int idx = path.lastIndexOf(File.separatorChar);
        if (idx > 0) {
            fileName = path.substring(idx + 1);
        }
        dbName = CoronaIoUtils.createWorkTableName(dbName, TableType.CLAIM_DATA, -1);

        /* ????? */
        if (!createClaimDataTableForDocument(dbName, target, records)) {
            return null;
        }

        /* ? */
        /* TablesDao.insertTable(fileName, dbName, TableType.CLAIM_DATA) ?? */
        try {
            // INSERT IGNORE INTO WORKDATAS....???
            StringBuilder strCheckHQL = new StringBuilder(150)
                    .append("from TablesBean where name = :NAME and dbname = :DBNAME and type = :TYPE"); //$NON-NLS-1$
            @SuppressWarnings("unchecked")
            List<TablesBean> list = this.session.createQuery(strCheckHQL.toString()).setString("NAME", fileName) //$NON-NLS-1$
                    .setString("DBNAME", dbName) //$NON-NLS-1$
                    .setInteger("TYPE", TableType.CLAIM_DATA.getIntValue()) //$NON-NLS-1$
                    .list();

            if (list != null && list.size() == 0) {
                // StringBuilder strSql = new StringBuilder(128).append("INSERT IGNORE INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                StringBuilder strSql = new StringBuilder(128)
                        .append("INSERT INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                strSql.append(fileName).append("','").append(dbName).append("',") //$NON-NLS-1$//$NON-NLS-2$
                        .append(TableType.CLAIM_DATA.getIntValue()).append(",now())"); //$NON-NLS-1$
                strExeSql = strSql.toString();
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        int claimId = 0;
        int keyId = 1;
        /* TablesDao.getTableId(dbName); ?? */
        try {
            strExeSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(dbName) //$NON-NLS-1$
                    .append("'").toString(); //$NON-NLS-1$
            @SuppressWarnings("unchecked")
            List<Object> list = this.session.createSQLQuery(strExeSql).list();
            if (list != null && list.size() > 0) {
                Object rs = list.get(0);
                claimId = Integer.parseInt(rs.toString());
            }
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        }

        /*  */
        int workId = 0;
        try {
            workId = createClaimWorkDataTable(TableType.CORRECTION_MISTAKES_DATA.toString(), dbName,
                    TableType.CORRECTION_MISTAKES_DATA, 0, 0, 0, null);
        } catch (HibernateException e) {
            e.printStackTrace();
            throw e;
        }
        /* ????? */
        /*
         * ClaimWorkDataDao.insertCorrectionMistakes(claimId, keyId, workId);
         * ??
         */
        try {
            StringBuilder sql = new StringBuilder(512);
            sql.append(
                    "MERGE INTO CLAIMS (ID, KEY_FLD_ID, PRODUCT_FLD_ID, TGT_FLDS, EXTERNAL_FLG, INTERNAL_FLG, WORK_TBL_ID) "); //$NON-NLS-1$
            sql.append("KEY (ID) "); //$NON-NLS-1$
            sql.append("VALUES (").append(claimId).append(",").append(keyId).append(",0,0,false,false,") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    .append(workId).append(") "); //$NON-NLS-1$
            // TODO 20131206 MERGE?
            //            sql.append("INSERT INTO CLAIMS (ID, KEY_FLD_ID, PRODUCT_FLD_ID, TGT_FLDS, EXTERNAL_FLG, INTERNAL_FLG, WORK_TBL_ID) "); //$NON-NLS-1$
            //            sql.append("VALUES (").append(claimId).append(",").append(keyId).append(",0,0,false,false,").append(workId).append(") "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            //            sql.append("ON DUPLICATE KEY UPDATE KEY_FLD_ID =VALUES(KEY_FLD_ID)"); //$NON-NLS-1$
            //            sql.append(",PRODUCT_FLD_ID =VALUES(PRODUCT_FLD_ID)"); //$NON-NLS-1$
            //            sql.append(",TGT_FLDS =VALUES(TGT_FLDS),EXTERNAL_FLG =VALUES(EXTERNAL_FLG)"); //$NON-NLS-1$
            //            sql.append(",INTERNAL_FLG =VALUES(INTERNAL_FLG),WORK_TBL_ID =VALUES(WORK_TBL_ID)"); //$NON-NLS-1$
            strExeSql = sql.toString();
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery(strExeSql).executeUpdate();
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            e.printStackTrace();
            throw e;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        /* ????? */
        updateClaimDatas();
        /* ? */
        return getClaimData(claimId);
    }

    /* ****************************************
     * 
     */
    @Override
    public Map<Integer, ICoronaDic> getDictionarysMap() {
        if (_dics == null) {
            /*  */
            updateDictionarys();
        }
        return _dics;
    }

    @Override
    public ICoronaDic getDictionary(int id) {
        if (_dics == null) {
            updateDictionarys();
        }
        /* ??????? */
        return _dics.get(id);
    }

    @Override
    public ICoronaDic getDictionary(String name) {
        if (_dics == null) {
            updateDictionarys();
        }
        for (Entry<Integer, ICoronaDic> entry : _dics.entrySet()) {
            if (entry.getValue().getName().equals(name)) {
                return entry.getValue();
            }
        }
        return null;
    }

    /**
     * ?(ID)
     * 
     * @param id
     *            ID
     * @return 
     */
    public List<ICoronaDic> getDictionary(Set<Integer> id) {
        List<ICoronaDic> list = new ArrayList<ICoronaDic>();
        if (_dics == null) {
            updateDictionarys();
        }
        for (int i : id) {
            /* ??????? */
            ICoronaDic dic = _dics.get(i);
            if (dic != null) {
                list.add(dic);
            }
        }
        return list;
    }

    /**
     * ??
     * 
     * @param dic
     *            
     */
    @Override
    public boolean addDictionary(ICoronaDic dic) {
        if (_dics == null) {
            updateDictionarys();
        }
        _dics.put(dic.getId(), dic);
        return true;
    }

    @Override
    public void removeDictionary(int dicId) {
        /* ? */
        try {
            DicTableBean dicTbl = (DicTableBean) session.get(DicTableBean.class, dicId);
            if (dicTbl != null) {
                dicTbl.setInactive(true);
                dicTbl.setDicName("_%deleted%_" + dicTbl.getDicName()); //$NON-NLS-1$
                /*  */
                this.session.beginTransaction();
                this.session.save(dicTbl);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }

            /* ??? */
            @SuppressWarnings("unchecked")
            List<DicPriorityBean> dicPriList = CommonCreateQuery.getDicPriQuery(dicId).list();
            if (dicPriList != null) {
                /*  */
                this.session.beginTransaction();
                for (DicPriorityBean dicPri : dicPriList) {
                    this.session.delete(dicPri);
                }
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            }
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }

        if (_dics == null) {
            updateDictionarys();
        }
        _dics.remove(dicId);
    }

    @Override
    public boolean exportDictionarys(String outputPath, String encoding) {
        /* TODO ??? */
        return false;
    }

    @Override
    public Collection<IUserDic> searchParentDic(List<IUserDic> searchDics, String header, String reading,
            String part, String cls, String cform) {
        Set<IUserDic> out = new TreeSet<IUserDic>(new Comparator<IUserDic>() {
            @Override
            public int compare(IUserDic o1, IUserDic o2) {
                return o1.getId() - o2.getId();
            }
        });
        try {
            @SuppressWarnings("unchecked")
            List<DicCommonBean> dicCommonList = CommonCreateQuery
                    .getDicCommonQuery(searchDics, header, reading, TermPart.valueOfName(part),
                            TermClass.valueOfName(cls),
                            TermCForm.valueOf(cform, TermPart.valueOfName(part), TermClass.valueOfName(cls)))
                    .list();
            for (DicCommonBean dicCommon : dicCommonList) {
                for (IUserDic usrDic : searchDics) {
                    if (usrDic.getId() == dicCommon.getDicId()) {
                        out.add(usrDic);
                    }
                }
            }
        } catch (HibernateException e) {
            e.printStackTrace();
        }
        return out;
    }

    /**
     * 
     * 
     * @return List<ICoronaDic>
     */
    public IStatus updateDictionarys() {
        Map<Integer, ICoronaDic> workMap = new TreeMap<Integer, ICoronaDic>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1 - o2;
            }
        });

        if (_dics == null) {
            _dics = new TreeMap<Integer, ICoronaDic>();
        }

        updateCategorys();
        try {
            @SuppressWarnings("unchecked")
            List<DicTableBean> dicTableList = CommonCreateQuery.getDicTableQuery(false).list();
            IDicFactory factory = DicFactory.getInstance();
            for (DicTableBean dicTable : dicTableList) {
                ICoronaDic dic = this._dics.get(dicTable.getDicId());
                if (dic == null) {
                    switch (DicType.valueOf(dicTable.getDicType())) {
                    case JUMAN: /* JUMAN */
                    case COMMON: /*  */
                    case CATEGORY: /*  */
                    case SPECIAL: /*  */
                        dic = factory.createUserDic(dicTable.getDicName(), dicTable.getDicFileName(),
                                DicType.valueOf(dicTable.getDicType()));
                        /* ID?NULL??????? */
                        if (dicTable.getCategoryId() != null) {
                            for (TextItem item : _categoryList) {
                                if (dicTable.getCategoryId() == item.getId()) {
                                    ((IUserDic) dic).setDicCategory(item);
                                }
                            }
                        }
                        break;
                    case LABEL: /*  */
                        dic = factory.createLabelDic(dicTable.getDicName());
                        dic.setParentIds(CoronaIoUtils.stringToIntSet(dicTable.getParentId()));
                        break;
                    case FLUC: /* ? */
                        dic = factory.createFlucDic(dicTable.getDicName(),
                                CoronaIoUtils.stringToIntSet(dicTable.getParentId()));
                        break;
                    case SYNONYM: /* ? */
                        dic = factory.createSynonymDic(dicTable.getDicName(),
                                CoronaIoUtils.stringToIntSet(dicTable.getParentId()));
                        break;
                    case PATTERN: /*  */
                        dic = factory.createPatternDic(dicTable.getDicName());
                        break;
                    default:
                        CoronaIoUtils.setErrorLog(IStatus.WARNING,
                                ":ID=" + dicTable.getDicId(), null); //$NON-NLS-1$
                    }
                } else if (DicType.valueOf(dicTable.getDicType()).equals(DicType.JUMAN)
                        && dicTable.getDicType() != ((UserDic) dic).getDicType().getIntValue()) {
                    /* juman????????????? */
                    dic = factory.createUserDic(dicTable.getDicName(), dicTable.getDicFileName(),
                            DicType.valueOf(dicTable.getDicType()));
                }
                if (dic != null) {
                    dic.setId(dicTable.getDicId()); /* ID */
                    dic.setLasted(dicTable.getDate()); /*  */
                    dic.setCreationTime(dicTable.getCreationTime()); /* ? */
                    workMap.put(dicTable.getDicId(), dic);
                }
            }
            _dics = workMap;
            return Status.OK_STATUS;

        } catch (HibernateException e) {
            e.printStackTrace();
            return new Status(IStatus.ERROR, IoActivator.PLUGIN_ID,
                    Messages.IoService_getDicInfoFail + e.getLocalizedMessage(), e);
        }
    }

    /* ****************************************
     * ??
     */
    @Override
    public List<TextItem> updateCategorys() {
        List<TextItem> workList = new ArrayList<TextItem>();

        if (_categoryList == null) {
            _categoryList = new ArrayList<TextItem>();
        }
        try {
            @SuppressWarnings("unchecked")
            List<CategoryBean> categoryList = CommonCreateQuery.getCategoryQuery().list();
            for (CategoryBean category : categoryList) {
                TextItem item = null;
                for (TextItem i : _categoryList) {
                    if (i.getId() == category.getId()) {
                        i.setText(category.getName());
                        item = i;
                        break;
                    }
                }
                if (item == null) {
                    item = new TextItem(category.getId(), category.getName());
                }
                workList.add(item);
            }
            /*  */
            _categoryList = workList;
            return _categoryList;
        } catch (HibernateException e) {
            e.printStackTrace();
            return _categoryList;
        }
    }

    @Override
    protected int addCategoryDam(String category) {
        try {
            int id = 0;
            CategoryBean result = (CategoryBean) CommonCreateQuery.getCategoryQuery(category).uniqueResult();
            if (result != null) {
                id = result.getId();
                if (id != 0) {
                    return 0;
                }
            }
            CategoryBean addCategory = new CategoryBean();
            addCategory.setName(category);
            /*  */
            this.session.beginTransaction();
            this.session.save(addCategory);
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
            result = (CategoryBean) CommonCreateQuery.getCategoryQuery(category).uniqueResult();
            if (result.getId() <= 0) {
                throw new HibernateException(Messages.IoService_systemErrorGetCategoryInfo);
            }
            return result.getId();
        } catch (HibernateException e) {
            e.printStackTrace();
            return -1;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
    }

    @Override
    public void removeCategory(String categoryName) {
        CategoryBean category = (CategoryBean) CommonCreateQuery.getCategoryQuery(categoryName).uniqueResult();
        if (category != null) {
            try {
                /*  */
                this.session.beginTransaction();
                this.session.delete(category);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException e) {
                e.printStackTrace();
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }
            category = (CategoryBean) CommonCreateQuery.getCategoryQuery(categoryName).uniqueResult();
            if (category != null) {
                throw new HibernateException(
                        "?????()"); //$NON-NLS-1$
            }
        }
        for (Iterator<TextItem> itr = _categoryList.iterator(); itr.hasNext();) {
            TextItem item = itr.next();
            if (item.getText().equals(categoryName)) {
                itr.remove();
                break;
            }
        }
    }

    @Override
    public boolean modifyCategory(int categoryId, String newCategoryName) {
        try {
            CategoryBean category = (CategoryBean) CommonCreateQuery.getCategoryQuery(categoryId).uniqueResult();
            if (category != null) {
                category.setName(newCategoryName);
                /*  */
                this.session.beginTransaction();
                this.session.save(category);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
                for (TextItem item : _categoryList) {
                    if (item.getId() == categoryId) {
                        item.setText(newCategoryName);
                        break;
                    }
                }
                return true;
            }
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        return false;
    }

    /* ****************************************
     * 
     */
    @Override
    public PatternType addPatternType(String name) {
        TypePatternBean typePattern = new TypePatternBean();
        try {
            typePattern.setName(name);
            /*  */
            this.session.beginTransaction();
            this.session.save(typePattern);
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        int id = 0;
        try {
            @SuppressWarnings("unchecked")
            List<TypePatternBean> list = CommonCreateQuery.getTypePatternQuery(name).list();
            if (list != null && list.size() > 0) {
                typePattern = list.get(0);
                id = typePattern.getId();
            }
        } catch (HibernateException e) {
            e.printStackTrace();
            id = -1;
        }
        PatternType patternType = new PatternType(id, name);
        PatternType.addPatternType(patternType);
        return patternType;
    }

    @Override
    public boolean removePatternType(PatternType type) {
        TypePatternBean typePattern = (TypePatternBean) CommonCreateQuery.getTypePatternQuery(type.getId())
                .uniqueResult();
        try {
            if (typePattern != null) {
                /*  */
                this.session.beginTransaction();
                this.session.delete(typePattern);
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
                typePattern = (TypePatternBean) CommonCreateQuery.getTypePatternQuery(type.getId()).uniqueResult();
                if (typePattern == null) {
                    PatternType.removePatternType(type);
                    return true;
                }
            }
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        return false;
    }

    @Override
    public PatternType[] getPatternTypes() {
        try {
            @SuppressWarnings("unchecked")
            List<TypePatternBean> typePatternList = CommonCreateQuery.getTypePatternQuery().list();
            for (TypePatternBean typePattern : typePatternList) {
                int id = typePattern.getId();
                PatternType type = PatternType.getPatternType(id);
                if (type == null) {
                    type = new PatternType(typePattern.getId(), typePattern.getName());
                    PatternType.addPatternType(type);
                }
            }
        } catch (HibernateException e) {
            e.printStackTrace();
        }
        return PatternType.getPatternTypes();
    }

    /**
     * ?
     * 
     * @return true/false
     */
    @Override
    public boolean update() {
        /* TODO IStatus?????(code??) */
        MultiStatus retStatus = new MultiStatus(IoActivator.PLUGIN_ID, 320, Messages.IoService_modifyProject, null);

        /* ?? */
        IStatus status = updateProjects();
        retStatus.add(status);

        /* ?? */
        status = updateDictionarys();
        retStatus.add(status);

        /* ??????? */
        status = updateClaimDatas();
        retStatus.add(status);

        return retStatus.isOK();
    }

    @Override
    public boolean commit(IProgressMonitor monitor) {
        return commit(true, monitor);
    }

    @Deprecated
    @Override
    public boolean commit(boolean bRecords, IProgressMonitor monitor) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String getProductName(int productId) {
        ProductBean product = (ProductBean) CommonCreateQuery.getProductQuery(productId).uniqueResult();
        if (product != null) {
            return product.getProductName();
        }
        return null;
    }

    @Override
    public List<IFieldHeader> getTableColumnsDam(String path, String definePath, String tableName)
            throws SQLException, IOException, HibernateException {
        /*
         * 1?
         * 2.List<IFieldHeader>??
         * 3???
         * 4.?
         */
        String strSQL;
        String dbName = tableName + Messages.IoService_dummy;
        List<IFieldHeader> list = new ArrayList<IFieldHeader>();

        /* ????? */
        strSQL = createClaimDataTable(definePath, dbName);
        try {
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery(strSQL).executeUpdate();
            this.session.flush();

            /* ? */
            String[] columns = null;
            String strColSQL = "Show Columns From " + dbName; //$NON-NLS-1$
            List<String> tableColumns = new ArrayList<String>();
            @SuppressWarnings("unchecked")
            List<Object[]> colList = this.session.createSQLQuery(strColSQL).list();
            if (colList != null) {
                for (Object[] rs : colList) {
                    tableColumns.add((String) rs[0]);
                }
                columns = tableColumns.toArray(new String[tableColumns.size()]);
            }

            for (int i = 0; i < columns.length; i++) {
                /* DB??????? */
                IFieldHeader header = new FieldHeader(columns[i], columns[i], "", i + 1); //$NON-NLS-1$
                list.add(header);
            }

            /* ???? */
            StringBuilder strExeSql = new StringBuilder(128);
            strExeSql.append("DROP TABLE ").append(dbName); //$NON-NLS-1$
            this.session.createSQLQuery(strExeSql.toString()).executeUpdate();
            this.session.flush();

            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strSQL); //$NON-NLS-1$
            return null;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        return list;
    }

    @Override
    public boolean chkRelPrjClm(int id) {
        @SuppressWarnings("unchecked")
        List<RelPrjClmBean> relPrjClm = CommonCreateQuery.getRelPrjClmQuery(id).list();
        if (relPrjClm != null && relPrjClm.size() > 0) {
            return true;
        }
        return false;
    }

    /**
     * DB?DB???
     * 
     * @param result
     *            ?0:)
     * @return ???
     */
    @Override
    public String getDbVersionDam(int result[]) {
        CoronaDbVersionBean version = (CoronaDbVersionBean) CommonCreateQuery.getCoronaDbVersionQuery(this.session)
                .uniqueResult();
        if (version != null) {
            return version.getVersion();
        }
        return null;
    }

    /**
     * ??????
     * TODO:???????finally????
     * 
     * @param name
     *            ???????
     * @param dbName
     *            ???????????
     * @param type
     *            
     * @param projectId
     *            ID
     * @param productId
     *            ID
     * @param claimId
     *            ?????ID
     * @param tgts
     *            ID
     * @return ?ID
     * @throws SQLException
     *             , HibernateException
     */
    private int createClaimWorkDataTable(String name, String dbName, TableType type, int projectId, int productId,
            int claimId, Set<Integer> tgts) throws SQLException, HibernateException {

        // ClaimWorkDataDao

        StringBuilder strSQL = new StringBuilder(192).append("CREATE TABLE "); //$NON-NLS-1$
        if (dbName == null) {
            throw new HibernateException("Not find dbname"); //$NON-NLS-1$
        }
        /* ? */
        String strExeSql = ""; //$NON-NLS-1$
        String strWork = CoronaIoUtils.createWorkTableName(dbName, type, projectId);
        int workId = 0;

        /* TablesDao.getTableId(strWork);?? */
        try {
            strExeSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(strWork) //$NON-NLS-1$
                    .append("'").toString(); //$NON-NLS-1$
            @SuppressWarnings("unchecked")
            List<Object> list = this.session.createSQLQuery(strExeSql).list();
            if (list != null && list.size() > 0) {
                Object rs = list.get(0);
                workId = Integer.parseInt(rs.toString());
            }
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        }
        if (workId == 0) {
            // ???USR_WORK_????USR_CM_??USR_CM_()????????
            strSQL.append(strWork).append(" (").append("WORK_ID INT NOT NULL, ").append("FLD_ID INT NOT NULL, ") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    .append("REC_ID INT NOT NULL, "); //$NON-NLS-1$

            if (TableType.CORRECTION_MISTAKES_DATA.equals(type)) {
                // USR_CM_??
                strSQL.append("DATA MEDIUMTEXT, ").append("PRIMARY KEY (WORK_ID, FLD_ID, REC_ID));"); //$NON-NLS-1$ //$NON-NLS-2$
            } else {
                // USR_WORK_????ID???
                strSQL.append("HISTORY_ID INT, "); //$NON-NLS-1$
                strSQL.append("DATA MEDIUMTEXT, ").append("PRIMARY KEY (WORK_ID, FLD_ID, REC_ID, HISTORY_ID));"); //$NON-NLS-1$ //$NON-NLS-2$
            }
            try {
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strSQL.toString()).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strSQL.toString()); //$NON-NLS-1$
                throw e;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }

            /* ? */
            /* TablesDao.insertTable(name, strWork, type);?? */
            try {
                // INSERT IGNORE INTO TABLES....???
                StringBuilder strCheckHQL = new StringBuilder(150)
                        .append("from TablesBean where name = :NAME and dbname = :DBNAME and type = :TYPE"); //$NON-NLS-1$
                @SuppressWarnings("unchecked")
                List<TablesBean> list = this.session.createQuery(strCheckHQL.toString()).setString("NAME", name) //$NON-NLS-1$
                        .setString("DBNAME", strWork) //$NON-NLS-1$
                        .setInteger("TYPE", type.getIntValue()) //$NON-NLS-1$
                        .list();
                if (list != null && list.size() == 0) {
                    StringBuilder strSql = new StringBuilder(128)
                            .append("INSERT INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                    strSql.append(name).append("','").append(strWork).append("',").append(type.getIntValue()) //$NON-NLS-1$//$NON-NLS-2$
                            .append(",now())"); //$NON-NLS-1$
                    strExeSql = strSql.toString();
                    /*  */
                    this.session.beginTransaction();
                    this.session.createSQLQuery(strExeSql).executeUpdate();
                    this.session.flush();
                    /*  */
                    this.session.getTransaction().commit();
                }

            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            } finally {
                if (this.session.getTransaction().isActive()) {
                    this.session.getTransaction().rollback();
                }
            }
            /* workId = TablesDao.getTableId(strWork); ?? */
            try {
                String strSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(dbName) //$NON-NLS-1$
                        .append("'").toString(); //$NON-NLS-1$
                strExeSql = strSql;
                @SuppressWarnings("unchecked")
                List<Object> list = this.session.createSQLQuery(strExeSql).list();
                if (list != null && list.size() > 0) {
                    Object rs = list.get(0);
                    workId = Integer.parseInt(rs.toString());
                }
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            }
            if (workId == 0) {
                throw new HibernateException("not find workId"); //$NON-NLS-1$
            }

            // ??USR_CLAIMxxx?Index
            if (!TableType.CORRECTION_MISTAKES_DATA.equals(type)) {
                StringBuilder strCreateIndex = new StringBuilder("CREATE INDEX "); //$NON-NLS-1$
                strCreateIndex.append(strWork).append("_INDEX ON ").append(strWork) //$NON-NLS-1$
                        .append("(WORK_ID, HISTORY_ID, REC_ID ASC);"); //$NON-NLS-1$
                // CommonDao.executeSQL4Throws(strCreateIndex.toString());
                // ??
                try {
                    strExeSql = strCreateIndex.toString();
                    /*  */
                    this.session.beginTransaction();
                    this.session.createSQLQuery(strExeSql).executeUpdate();
                    this.session.flush();
                    /*  */
                    this.session.getTransaction().commit();
                } catch (HibernateException e) {
                    CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                    throw e;
                } finally {
                    if (this.session.getTransaction().isActive()) {
                        this.session.getTransaction().rollback();
                    }
                }
            }
        }

        if (type == TableType.WORK_DATA) {
            /* TODO:? */
            String strRelPtn = CoronaIoUtils.createWorkTableName(dbName, TableType.RESULT_DATA, projectId);
            int relId = 0;
            /* TablesDao.getTableId(strRelPtn); ?? */
            try {
                String strSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='") //$NON-NLS-1$
                        .append(strRelPtn).append("'").toString(); //$NON-NLS-1$
                strExeSql = strSql;
                @SuppressWarnings("unchecked")
                List<Object> list = this.session.createSQLQuery(strExeSql).list();
                if (list != null && list.size() > 0) {
                    Object rs = list.get(0);
                    relId = Integer.parseInt(rs.toString());
                }
            } catch (HibernateException e) {
                CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                throw e;
            }

            if (relId == 0) {
                StringBuilder createSql = new StringBuilder(128);
                createSql.append("Create Table ").append(strRelPtn); //$NON-NLS-1$
                createSql.append("(work_id Int Not NULL,").append("fld_id Int Not NULL,"); //$NON-NLS-1$ //$NON-NLS-2$
                createSql.append("history Int Not NULL,").append("rec_id Int Not NULL,"); //$NON-NLS-1$ //$NON-NLS-2$
                createSql.append("pattern_id Int Not NULL,").append("hit_info MediumText Not NULL)"); //$NON-NLS-1$ //$NON-NLS-2$
                // CommonDao.executeSQL4Throws(createSql.toString());
                try {
                    strExeSql = createSql.toString();
                    /*  */
                    this.session.beginTransaction();
                    this.session.createSQLQuery(strExeSql).executeUpdate();
                    this.session.flush();
                    /*  */
                    this.session.getTransaction().commit();
                } catch (HibernateException e) {
                    CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                    throw e;
                } finally {
                    if (this.session.getTransaction().isActive()) {
                        this.session.getTransaction().rollback();
                    }
                }
                // ?
                /*
                 * TablesDao.insertTable(TableType.RESULT_DATA.toString(),
                 * strRelPtn, TableType.RESULT_DATA); ??
                 */
                try {
                    String paraName = TableType.RESULT_DATA.toString();
                    String paraDbName = strRelPtn;
                    int paraType = TableType.RESULT_DATA.getIntValue();

                    // INSERT IGNORE INTO WORKDATAS....???
                    StringBuilder strCheckHQL = new StringBuilder(150)
                            .append("from TablesBean where name = :NAME and dbname = :DBNAME and type = :TYPE"); //$NON-NLS-1$
                    @SuppressWarnings("unchecked")
                    List<TablesBean> list = this.session.createQuery(strCheckHQL.toString())
                            .setString("NAME", paraName) //$NON-NLS-1$
                            .setString("DBNAME", paraDbName) //$NON-NLS-1$
                            .setInteger("TYPE", paraType) //$NON-NLS-1$
                            .list();
                    if (list != null && list.size() == 0) {
                        StringBuilder strSql = new StringBuilder(128)
                                .append("INSERT INTO TABLES (NAME, DBNAME, TYPE, LASTED) VALUES('"); //$NON-NLS-1$
                        strSql.append(paraName).append("','").append(paraDbName).append("',").append(paraType) //$NON-NLS-1$//$NON-NLS-2$
                                .append(",now())"); //$NON-NLS-1$
                        strExeSql = strSql.toString();
                        /*  */
                        this.session.beginTransaction();
                        this.session.createSQLQuery(strExeSql).executeUpdate();
                        this.session.flush();
                        /*  */
                        this.session.getTransaction().commit();
                    }
                } catch (HibernateException e) {
                    CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                    throw e;
                } finally {
                    if (this.session.getTransaction().isActive()) {
                        this.session.getTransaction().rollback();
                    }
                }
                /* relId = TablesDao.getTableId(strRelPtn); ? */
                relId = 0;
                try {
                    String strSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='") //$NON-NLS-1$
                            .append(strRelPtn).append("'").toString(); //$NON-NLS-1$
                    strExeSql = strSql;
                    @SuppressWarnings("unchecked")
                    List<Object> list = this.session.createSQLQuery(strExeSql).list();
                    if (list != null && list.size() > 0) {
                        Object rs = list.get(0);
                        relId = Integer.parseInt(rs.toString());
                    }
                } catch (HibernateException e) {
                    CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                    throw e;
                }
                if (relId == 0) {
                    throw new HibernateException("not find workId"); //$NON-NLS-1$
                }

                StringBuffer strCreateIndex = new StringBuffer().append("CREATE INDEX "); //$NON-NLS-1$
                strCreateIndex.append(strRelPtn).append("_INDEX ON ").append(strRelPtn) //$NON-NLS-1$
                        .append("(WORK_ID, HISTORY, REC_ID ASC);"); //$NON-NLS-1$
                /*
                 * CommonDao.executeSQL4Throws(strCreateIndex.toString());
                 * ??
                 */
                try {
                    strExeSql = strCreateIndex.toString();
                    /*  */
                    this.session.beginTransaction();
                    this.session.createSQLQuery(strExeSql).executeUpdate();
                    this.session.flush();
                    /*  */
                    this.session.getTransaction().commit();
                } catch (HibernateException e) {
                    CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
                    throw e;
                } finally {
                    if (this.session.getTransaction().isActive()) {
                        this.session.getTransaction().rollback();
                    }
                }

            }

            /* - */
            insertRelationClaimData(projectId, productId, claimId, workId, relId, tgts);

        }

        /* ID? */
        /* return TablesDao.getTableId(strWork); ?? */
        try {
            strExeSql = new StringBuilder(64).append("SELECT ID FROM TABLES WHERE DBNAME ='").append(strWork) //$NON-NLS-1$
                    .append("'").toString(); //$NON-NLS-1$
            workId = 0;
            @SuppressWarnings("unchecked")
            List<Object> list = this.session.createSQLQuery(strExeSql).list();
            if (list != null && list.size() > 0) {
                Object rs = list.get(0);
                workId = Integer.parseInt(rs.toString());
            }
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            throw e;
        }
        return workId;
    }

    /**
     * ????????????<br/>
     * ????????????
     * 
     * @param projectId
     *            ??ID
     * @param productId
     *            ??ID
     * @param claimId
     *            ??????ID
     * @param workId
     *            ????ID<br/>
     *            0??
     * @param relId
     *            ????ID<br/>
     *            0??
     * @param tgts
     *            ?ID?
     * @return ?????true???????false
     */
    private boolean insertRelationClaimData(int projectId, int productId, int claimId, int workId, int relId,
            Collection<Integer> tgts) {

        // ProductDao
        String strTgts = CoronaIoUtils.intListToString(tgts);

        StringBuilder strSQL = new StringBuilder(1024);
        strSQL.append("MERGE INTO REL_CLM_PRODUCT ") //$NON-NLS-1$
                .append("(PRJ_ID, PRODUCT_ID, TBL_ID, WORK_TBL_ID, REL_TBL_ID, TGT_FLD) "); //$NON-NLS-1$
        strSQL.append(" KEY (PRJ_ID, PRODUCT_ID, TBL_ID) VALUES ("); //$NON-NLS-1$
        strSQL.append(projectId).append(",").append(productId).append(",").append(claimId).append(","); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        strSQL.append(workId).append(",").append(relId).append(",").append("'").append(strTgts).append("')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$

        /* return CommonDao.executeSQL(strSQL.toString()); ?? */
        String strExeSql = null;
        try {
            strExeSql = strSQL.toString();
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery(strExeSql).executeUpdate();
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            e.printStackTrace();
            return false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        return true;
    }

    /**
     * ?????SQL?(
     * 
     * @param tableName
     *            ??
     * @return SQL
     * @throws SQLException
     *             ????
     */
    private boolean createClaimDataTableForDocument(String tableName, String target, List<String> records)
            throws SQLException {

        // ClaimDataDao

        String strExeSql = null;
        try {
            strExeSql = "CREATE TABLE " + tableName //$NON-NLS-1$
                    + "(ID INT NOT NULL AUTO_INCREMENT, BODY TEXT, TARGET VARCHAR(256), PRIMARY KEY (ID))"; //$NON-NLS-1$
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery(strExeSql).executeUpdate();
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            e.printStackTrace();
            return false;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
        StringBuilder strSQL = new StringBuilder(200);
        strSQL.append("INSERT INTO ").append(tableName).append(" (BODY,TARGET) VALUES"); //$NON-NLS-1$ //$NON-NLS-2$
        for (String s : records) {
            strSQL.append("('").append(s).append("','").append(target).append("'),"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
        strSQL = strSQL.deleteCharAt(strSQL.length() - 1);
        try {
            strExeSql = strSQL.toString();
            /*  */
            this.session.beginTransaction();
            this.session.createSQLQuery(strExeSql).executeUpdate();
            this.session.flush();
            /*  */
            this.session.getTransaction().commit();
            return true;
        } catch (HibernateException e) {
            CoronaActivator.debugLog("Error SQL : " + strExeSql); //$NON-NLS-1$
            // CommonDao.deleteTable(tableName);
            try {
                strExeSql = "DROP TABLE " + tableName; //$NON-NLS-1$
                /*  */
                this.session.beginTransaction();
                this.session.createSQLQuery(strExeSql).executeUpdate();
                this.session.flush();
                /*  */
                this.session.getTransaction().commit();
            } catch (HibernateException ex) {
                ex.printStackTrace();
            }
            throw e;
        } finally {
            if (this.session.getTransaction().isActive()) {
                this.session.getTransaction().rollback();
            }
        }
    }

    /**
     * ?????SQL?
     * 
     * @param definePath
     *            ??
     * @param tableName
     *            ???
     * @return ?????SQL
     * @throws IOException
     *             ???????
     */
    private static String createClaimDataTable(String definePath, String tableName) throws IOException {

        // ClaimDataDao 

        BufferedReader br = null;
        String line;
        StringBuilder strSQL = new StringBuilder(200);
        try {
            br = new BufferedReader(new FileReader(definePath));

            while ((line = br.readLine()) != null) {
                strSQL.append(line);
            }

            /* ??? */
            String suffix = "("; //$NON-NLS-1$
            String prefix = "CREATE TABLE"; //$NON-NLS-1$
            int idx = strSQL.indexOf(suffix);
            if (idx > -1) {
                strSQL.delete(0, idx);
                strSQL.insert(0, " ").insert(0, tableName).insert(0, ' ').insert(0, prefix); //$NON-NLS-1$
            }
        } catch (IOException e) {
            throw e;
        } finally {
            /* ? */
            if (br != null) {
                br.close();
            }
        }
        return strSQL.toString();
    }
}