com.clustercontrol.performance.factory.OperateCollectCategoryMaster.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.performance.factory.OperateCollectCategoryMaster.java

Source

/*
    
Copyright (C) since 2009 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
 */

package com.clustercontrol.performance.factory;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityExistsException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.clustercontrol.commons.util.HinemosEntityManager;
import com.clustercontrol.commons.util.JpaTransactionManager;
import com.clustercontrol.fault.CollectorNotFound;
import com.clustercontrol.performance.monitor.entity.CollectorCategoryMstData;
import com.clustercontrol.performance.monitor.model.CollectorCategoryMstEntity;
import com.clustercontrol.performance.monitor.util.QueryUtil;

/**
 * ?
 * 
 * @version 1.2.0
 * @since 1.2.0
 *
 */
public class OperateCollectCategoryMaster {

    private static Log m_log = LogFactory.getLog(OperateCollectCategoryMaster.class);

    /**
     * ????
     * 
     * @param data ?
     * @return ?????true
     * @throws EntityExistsException
     * 
     */
    public boolean add(CollectorCategoryMstData data) throws EntityExistsException {

        JpaTransactionManager jtm = new JpaTransactionManager();

        // ??
        try {
            // ?
            CollectorCategoryMstEntity entity = new CollectorCategoryMstEntity(data.getCategoryCode());
            // ??
            jtm.checkEntityExists(CollectorCategoryMstEntity.class, entity.getCategoryCode());
            entity.setCategoryName(data.getCategoryName());
        } catch (EntityExistsException e) {
            m_log.info("add() : " + e.getClass().getSimpleName() + ", " + e.getMessage());
            throw e;
        }

        return true;
    }

    /**
     * ????
     * @throws CollectorNotFound
     */
    public boolean delete(String categoryCode) throws CollectorNotFound {

        HinemosEntityManager em = new JpaTransactionManager().getEntityManager();

        CollectorCategoryMstEntity entity = QueryUtil.getCollectorCategoryMstPK(categoryCode);
        // pk???????????
        em.remove(entity);

        return true;
    }

    /**
     * ?????
     */
    public boolean deleteAll() {

        HinemosEntityManager em = new JpaTransactionManager().getEntityManager();

        List<CollectorCategoryMstEntity> col = QueryUtil.getAllCollectorCategoryMst();
        for (CollectorCategoryMstEntity entity : col) {
            //?
            em.remove(entity);
        }

        return true;
    }

    /**
     * ?????
     * @return ArrayList<CollectorCategoryMstData>
     */
    public ArrayList<CollectorCategoryMstData> findAll() {

        List<CollectorCategoryMstEntity> col = QueryUtil.getAllCollectorCategoryMst();

        ArrayList<CollectorCategoryMstData> list = new ArrayList<CollectorCategoryMstData>();
        for (CollectorCategoryMstEntity entity : col) {
            CollectorCategoryMstData data = new CollectorCategoryMstData(entity.getCategoryCode(),
                    entity.getCategoryName());
            list.add(data);
        }
        return list;
    }

}