Java tutorial
/* 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.StInvestigator; import org.hibernate.LockMode; import org.hibernate.SessionFactory; /** * Home object for domain model class StInvestigator. * @see .StInvestigator * @author Hibernate Tools */ public class StInvestigatorHome { private static final Log log = LogFactory.getLog(StInvestigatorHome.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(StInvestigator transientInstance) { log.debug("persisting StInvestigator instance"); try { sessionFactory.getCurrentSession().persist(transientInstance); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } } public void attachDirty(StInvestigator instance) { log.debug("attaching dirty StInvestigator instance"); try { sessionFactory.getCurrentSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(StInvestigator instance) { log.debug("attaching clean StInvestigator 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(StInvestigator persistentInstance) { log.debug("deleting StInvestigator instance"); try { sessionFactory.getCurrentSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public StInvestigator merge(StInvestigator detachedInstance) { log.debug("merging StInvestigator instance"); try { StInvestigator result = (StInvestigator) sessionFactory.getCurrentSession().merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public StInvestigator findById(java.lang.Integer id) { log.debug("getting StInvestigator instance with id: " + id); try { StInvestigator instance = (StInvestigator) sessionFactory.getCurrentSession().get("StInvestigator", 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<StInvestigator> findByExample(StInvestigator instance) { log.debug("finding StInvestigator instance by example"); try { List<StInvestigator> results = (List<StInvestigator>) sessionFactory.getCurrentSession() .createCriteria("StInvestigator").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; } } }