es.sm2.openppm.core.dao.WbstemplateDAO.java Source code

Java tutorial

Introduction

Here is the source code for es.sm2.openppm.core.dao.WbstemplateDAO.java

Source

/*
 * Copyright (C) 2009-2015 SM2 SOFTWARE & SERVICES MANAGEMENT
 * 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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program has been created in the hope that it will be useful.
 * It is distributed WITHOUT ANY WARRANTY of any Kind,
 * without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 *
 * For more information, please contact SM2 Software & Services Management.
 * Mail: info@talaia-openppm.com
 * Web: http://www.talaia-openppm.com
 *
 * Module: core
 * File: WbstemplateDAO.java
 * Create User: javier.hernandez
 * Create Date: 15/03/2015 12:52:46
 */

package es.sm2.openppm.core.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import es.sm2.openppm.core.model.impl.Company;
import es.sm2.openppm.core.model.impl.Wbstemplate;
import es.sm2.openppm.utils.hibernate.dao.AbstractGenericHibernateDAO;

/**
 * DAO object for domain model class Wbstemplate
 * @see es.sm2.openppm.core.dao.Wbstemplate
 * @author Hibernate Generator by Javier Hernandez
 */
public class WbstemplateDAO extends AbstractGenericHibernateDAO<Wbstemplate, Integer> {

    public WbstemplateDAO(Session session) {
        super(session);
    }

    /**
     * Find by company and property equal to null
     * @param company
     * @param parent
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Wbstemplate> findByCompanyAndRelationNull(Company company, String property) {

        Criteria crit = getSession().createCriteria(getPersistentClass()).addOrder(Order.asc(Wbstemplate.NAME))
                .add(Restrictions.isNull(property)).add(Restrictions.eq(Company.ENTITY, company));

        return crit.list();
    }

    /**
     * List all childs of WBSTemplate
     * @param wbstemplate
     * @param joins 
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Wbstemplate> findAllChilds(Wbstemplate wbstemplate, List<String> joins) {

        Criteria crit = getSession().createCriteria(getPersistentClass())
                .add(Restrictions.eq(Wbstemplate.ROOT, wbstemplate.getIdWbsnode()))
                .addOrder(Order.asc(Wbstemplate.NAME));

        addJoins(crit, joins);

        return crit.list();
    }

    /**
     * List childs of  WBSTemplate node
     * @param wbstemplate
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Wbstemplate> findChilds(Wbstemplate wbstemplate) {
        Criteria crit = getSession().createCriteria(getPersistentClass())
                .add(Restrictions.eq(Wbstemplate.WBSTEMPLATE, wbstemplate)).addOrder(Order.asc(Wbstemplate.NAME));

        return crit.list();
    }

    /**
     * Return tree of WBSTemplate of root node
     * @param wbstemplate
     * @return
     */
    @SuppressWarnings("unchecked")
    public List<Wbstemplate> findWbsTemplate(Wbstemplate wbstemplate) {
        Criteria crit = getSession().createCriteria(getPersistentClass())
                .add(Restrictions.or(Restrictions.eq(Wbstemplate.IDWBSNODE, wbstemplate.getIdWbsnode()),
                        Restrictions.eq(Wbstemplate.ROOT, wbstemplate.getIdWbsnode())))
                .addOrder(Order.asc(Wbstemplate.NAME));

        return crit.list();
    }

}