/** * Copyright 2014 David L. Whitehurst * * 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.musicrecital.dao.hibernate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.musicrecital.dao.LookupDao; import org.musicrecital.model.Role; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import java.util.List; import org.hibernate.Session; /** * Hibernate implementation of LookupDao. * * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a> * @author jgarcia: updated to hibernate 4 * @author <a href="mailto:dlwhitehurst@gmail.com">David L. Whitehurst</a> * @version $Id: c10a1f3e67e8aa4529341c5bf7c190a02ed82e74 $ */ @Repository public class LookupDaoHibernate implements LookupDao { private Log log = LogFactory.getLog(LookupDaoHibernate.class); private final SessionFactory sessionFactory; /** * Initialize LookupDaoHibernate with Hibernate SessionFactory. * @param sessionFactory */ @Autowired public LookupDaoHibernate(final SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } /** * {@inheritDoc} */ @SuppressWarnings("unchecked") public List<Role> getRoles() { log.debug("Retrieving all role names..."); Session session = sessionFactory.getCurrentSession(); return session.createCriteria(Role.class).list(); } }