2 * Copyright 2006 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.mythtv;
19 import java.sql.SQLException;
20 import java.util.HashMap;
21 import java.util.List;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.hibernate.HibernateException;
27 import org.hibernate.Session;
28 import org.hibernate.criterion.Expression;
29 import org.springframework.orm.hibernate3.HibernateCallback;
30 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
35 public class RecordingDatabase extends HibernateDaoSupport {
37 private static final Log LOG = LogFactory.getLog(RecordingDatabase.class);
39 public RecordingDatabase() {
45 for (Recording recording: (List<Recording>)getHibernateTemplate().loadAll(Recording.class) ) {
46 LOG.info("Found recording " + recording);
48 LOG.info("After listing recordings");
52 public Recording findRecording(final String aName) {
53 List<Recording> result = (List<Recording>) getHibernateTemplate().execute(new HibernateCallback() {
55 * @see org.springframework.orm.hibernate3.HibernateCallback#doInHibernate(org.hibernate.Session)
57 public Object doInHibernate(Session aSession) throws HibernateException, SQLException {
58 return aSession.createCriteria(Recording.class).add(Expression.eq("_basename", aName)).list();
61 if ( result.size() > 1 ) {
62 throw new RuntimeException("More than two recordings returned");
64 if ( result.size() == 0 ) {
70 public void update(Recording aRecording) {
71 getHibernateTemplate().update(aRecording);