Java tutorial
package jedai.domain.security; /* * Jedai Networking Framework - http://jedai.googlecode.com * * Copyright (c) 2006-2009 by respective authors (see below). All rights reserved. * * This library is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free Software * Foundation; either version 2.1 of the License, or (at your option) any later * version. * * This library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along * with this library; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.List; import javax.naming.InitialContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.LockMode; import org.hibernate.SessionFactory; import org.hibernate.criterion.Example; /** * Home object for domain model class AclEntry. * @see jedai.domain.security.AclEntry * @author Hibernate Tools */ public class AclEntryHome { private static final Log log = LogFactory.getLog(AclEntryHome.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(AclEntry transientInstance) { log.debug("persisting AclEntry instance"); try { sessionFactory.getCurrentSession().persist(transientInstance); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } } public void attachDirty(AclEntry instance) { log.debug("attaching dirty AclEntry instance"); try { sessionFactory.getCurrentSession().saveOrUpdate(instance); log.debug("attach successful"); } catch (RuntimeException re) { log.error("attach failed", re); throw re; } } public void attachClean(AclEntry instance) { log.debug("attaching clean AclEntry 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(AclEntry persistentInstance) { log.debug("deleting AclEntry instance"); try { sessionFactory.getCurrentSession().delete(persistentInstance); log.debug("delete successful"); } catch (RuntimeException re) { log.error("delete failed", re); throw re; } } public AclEntry merge(AclEntry detachedInstance) { log.debug("merging AclEntry instance"); try { AclEntry result = (AclEntry) sessionFactory.getCurrentSession().merge(detachedInstance); log.debug("merge successful"); return result; } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } public AclEntry findById(java.lang.Long id) { log.debug("getting AclEntry instance with id: " + id); try { AclEntry instance = (AclEntry) sessionFactory.getCurrentSession().get("jedai.domain.security.AclEntry", 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 findByExample(AclEntry instance) { log.debug("finding AclEntry instance by example"); try { List results = sessionFactory.getCurrentSession().createCriteria("jedai.domain.security.AclEntry") .add(Example.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; } } }