org.cimmyt.dnast.dao.imp.StSampleidHome.java Source code

Java tutorial

Introduction

Here is the source code for org.cimmyt.dnast.dao.imp.StSampleidHome.java

Source

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

// Generated Apr 23, 2013 11:57:22 PM by Hibernate Tools 3.4.0.CR1

import static org.hibernate.criterion.Example.create;

import java.util.List;

import javax.naming.InitialContext;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cimmyt.dnast.dto.StSampleid;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;

/**
 * Home object for domain model class StSampleid.
 * @see .StSampleid
 * @author Hibernate Tools
 */
public class StSampleidHome {

    private static final Log log = LogFactory.getLog(StSampleidHome.class);

    private final SessionFactory sessionFactory = getSessionFactory();

    protected SessionFactory getSessionFactory() {
        try {
            return (SessionFactory) new InitialContext().lookup("SessionFactory");
        } catch (Exception e) {
            log.error("Could not locate SessionFactory in JNDI", e);
            throw new IllegalStateException("Could not locate SessionFactory in JNDI");
        }
    }

    public void persist(StSampleid transientInstance) {
        log.debug("persisting StSampleid instance");
        try {
            sessionFactory.getCurrentSession().persist(transientInstance);
            log.debug("persist successful");
        } catch (RuntimeException re) {
            log.error("persist failed", re);
            throw re;
        }
    }

    public void attachDirty(StSampleid instance) {
        log.debug("attaching dirty StSampleid instance");
        try {
            sessionFactory.getCurrentSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void attachClean(StSampleid instance) {
        log.debug("attaching clean StSampleid instance");
        try {
            sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public void delete(StSampleid persistentInstance) {
        log.debug("deleting StSampleid instance");
        try {
            sessionFactory.getCurrentSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public StSampleid merge(StSampleid detachedInstance) {
        log.debug("merging StSampleid instance");
        try {
            StSampleid result = (StSampleid) sessionFactory.getCurrentSession().merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public StSampleid findById(java.lang.Integer id) {
        log.debug("getting StSampleid instance with id: " + id);
        try {
            StSampleid instance = (StSampleid) sessionFactory.getCurrentSession().get("StSampleid", id);
            if (instance == null) {
                log.debug("get successful, no instance found");
            } else {
                log.debug("get successful, instance found");
            }
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public List<StSampleid> findByExample(StSampleid instance) {
        log.debug("finding StSampleid instance by example");
        try {
            List<StSampleid> results = (List<StSampleid>) sessionFactory.getCurrentSession()
                    .createCriteria("StSampleid").add(create(instance)).list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }
}