/* * Copyright 2006 the original author or authors. * * 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.wamblee.mythtv; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.persistence.EntityManager; import javax.persistence.Query; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.criterion.Expression; import org.springframework.orm.hibernate3.HibernateCallback; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.orm.jpa.JpaTemplate; import org.springframework.orm.jpa.support.JpaDaoSupport; /** * */ public class RecordingDatabase extends JpaDaoSupport { private static final Log LOG = LogFactory.getLog(RecordingDatabase.class); public RecordingDatabase() { // Empty } public void init() { /* for (Recording recording: (List)getHibernateTemplate().loadAll(Recording.class) ) { LOG.info("Found recording " + recording); } LOG.info("After listing recordings"); */ } public Recording findRecording(final String aName) { JpaTemplate jpaTemplate = getJpaTemplate(); EntityManager entityManager = jpaTemplate.getEntityManager(); Query query = entityManager.createQuery( "from org.wamblee.mythtv.Recording where basename = ?1"); query.setParameter(1, aName); List result = query.getResultList(); if ( result.size() > 1 ) { throw new RuntimeException("More than two recordings returned"); } if ( result.size() == 0 ) { return null; } return result.get(0); } public void update(Recording aRecording) { // Update is not required since the whole task of updating the // directory structure occurs within a single transaction. // Therefore, modifications to recordings are automatically persisted. } }