4 * Copyright (C) 2001, 2002, 2003 The Mir-coders group
6 * This file is part of Mir.
8 * Mir is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Mir is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Mir; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * In addition, as a special exception, The Mir-coders gives permission to link
23 * the code of this program with any library licensed under the Apache Software License,
24 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
25 * (or with modified versions of the above that use the same license as the above),
26 * and distribute linked combinations including the two. You must obey the
27 * GNU General Public License in all respects for all of the code used other than
28 * the above mentioned libraries. If you modify this file, you may extend this
29 * exception to your version of the file, but you are not obligated to do so.
30 * If you do not wish to do so, delete this exception statement from your version.
32 package mir.core.test;
34 import java.util.Iterator;
35 import java.util.List;
37 import mir.core.model.Audio;
38 import mir.core.model.Content;
39 import mir.core.model.IImage;
40 import mir.core.model.Image;
41 import mir.core.model.Media;
42 import mir.core.model.Topic;
43 import mir.core.model.UploadedMedia;
44 import mir.core.model.Video;
45 import mir.core.service.storage.ContentService;
46 import mir.core.service.storage.ImageService;
47 import net.sf.hibernate.Criteria;
48 import net.sf.hibernate.HibernateException;
49 import net.sf.hibernate.Session;
50 import net.sf.hibernate.SessionFactory;
51 import net.sf.hibernate.Transaction;
52 import net.sf.hibernate.cfg.Configuration;
56 * @version $Id: Test.java,v 1.8 2003/09/10 20:59:01 idfx Exp $
61 public static void main(String[] args) {
62 //BasicConfigurator.configure();
64 SessionFactory factory = new Configuration().configure().buildSessionFactory();
65 Session session = factory.openSession();
66 Transaction transaction = session.beginTransaction();
67 Criteria criteria = session.createCriteria(Topic.class);
68 List list = criteria.setMaxResults(10).list();
69 for(Iterator iterator = list.iterator(); iterator.hasNext();){
70 Topic media = (Topic)iterator.next();
71 System.out.println(media.toString());
73 criteria = session.createCriteria(Media.class);
74 list = criteria.setMaxResults(10).list();
75 for(Iterator iterator = list.iterator(); iterator.hasNext();){
76 Media media = (Media)iterator.next();
77 System.out.println(media.toString());
82 ContentService contentService = new ContentService(factory);
84 Object content = contentService.load(new Integer(7));
85 System.out.println(content + content.getClass().getName());
87 System.out.println("****** content media");
89 list = contentService.list(0,10);
90 for(Iterator iterator = list.iterator(); iterator.hasNext();){
91 Content media = (Content)iterator.next();
92 System.out.println(media.getTitle());
95 session = factory.openSession();
96 transaction = session.beginTransaction();
97 criteria = session.createCriteria(UploadedMedia.class);
98 list = criteria.setMaxResults(10).list();
99 System.out.println("****** uploaded media");
100 for(Iterator iterator = list.iterator(); iterator.hasNext();){
101 UploadedMedia media = (UploadedMedia)iterator.next();
102 System.out.println(media.toString() + media.getIconPath());
104 transaction.commit();
106 ImageService imageService = new ImageService(factory);
107 list = imageService.list(0,10);
108 System.out.println("****** image media");
109 for(Iterator iterator = list.iterator(); iterator.hasNext();){
110 Image media = (Image)iterator.next();
111 System.out.println(media.toString() + media.getIconPath());
113 IImage image = (IImage)imageService.load(new Integer(18));
114 System.out.println(image + " " + image.getImage().length);
115 session = factory.openSession();
116 transaction = session.beginTransaction();
117 criteria = session.createCriteria(Audio.class);
118 list = criteria.setMaxResults(10).list();
119 System.out.println("****** audio media");
120 for(Iterator iterator = list.iterator(); iterator.hasNext();){
121 Audio media = (Audio)iterator.next();
122 System.out.println(media.toString() + media.getIconPath());
124 criteria = session.createCriteria(Video.class);
125 list = criteria.setMaxResults(10).list();
126 System.out.println("****** video media");
127 for(Iterator iterator = list.iterator(); iterator.hasNext();){
128 Video media = (Video)iterator.next();
129 System.out.println(media.toString() + media.getIconPath());
131 transaction.commit();
133 } catch (HibernateException e) {
134 // TODO Auto-generated catch block