/* * 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.util.List; import javax.persistence.EntityManager; import javax.persistence.Query; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * * * @author Erik Brakkee */ public class RecordingDatabase { private static final Log LOG = LogFactory.getLog(RecordingDatabase.class); private EntityManager _entityManager; public RecordingDatabase(EntityManager aEntityManager) { _entityManager = aEntityManager; } public Recording findRecording(final String aName) { Query query = _entityManager.createQuery( "select r from Recording r where r.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) { _entityManager.merge(aRecording); } }