f94670d1d3ec329d5255dcd5b2fe69c64cbb6769
[mir.git] / source / mir / core / test / Test.java
1 /*
2  * Test.java
3  * 
4  * Copyright (C) 2001, 2002, 2003 The Mir-coders group
5  *
6  * This file is part of Mir.
7  *
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.
12  *
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.
17  *
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
21  *
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.
31  */
32 package mir.core.test;
33
34 import java.util.Iterator;
35 import java.util.List;
36
37 import org.apache.log4j.BasicConfigurator;
38
39 import mir.core.model.Audio;
40 import mir.core.model.Content;
41 import mir.core.model.IContent;
42 import mir.core.model.IImage;
43 import mir.core.model.Image;
44 import mir.core.model.Media;
45 import mir.core.model.Topic;
46 import mir.core.model.UploadedMedia;
47 import mir.core.model.Video;
48 import mir.core.service.storage.ContentService;
49 import mir.core.service.storage.ImageService;
50 import net.sf.hibernate.Criteria;
51 import net.sf.hibernate.HibernateException;
52 import net.sf.hibernate.Session;
53 import net.sf.hibernate.SessionFactory;
54 import net.sf.hibernate.Transaction;
55 import net.sf.hibernate.cfg.Configuration;
56
57 /**
58  * Test
59  * @version $Id: Test.java,v 1.6 2003/09/05 20:23:59 idfx Exp $
60  * @author idefix
61  */
62 public class Test {
63
64         public static void main(String[] args) {
65                 //BasicConfigurator.configure();
66                 try {
67                         SessionFactory factory = new Configuration().configure().buildSessionFactory();
68                         Session session = factory.openSession();
69                         Transaction transaction = session.beginTransaction();
70                         Criteria criteria = session.createCriteria(Topic.class);
71                         List list = criteria.setMaxResults(10).list();
72                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
73                                 Topic media = (Topic)iterator.next();
74                                 System.out.println(media.toString());
75                         }
76                         criteria = session.createCriteria(Media.class);
77                         list = criteria.setMaxResults(10).list();
78                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
79                                 Media media = (Media)iterator.next();
80                                 System.out.println(media.toString());
81                         }
82                         transaction.commit();
83                         session.close();
84
85                         ContentService contentService = new ContentService(factory);
86                         
87                         Object content = contentService.load(new Integer(7));
88                         System.out.println(content + content.getClass().getName());
89                         
90                         System.out.println("****** content media");
91
92                         list = contentService.list(0,10);
93                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
94                                 Content media = (Content)iterator.next();
95                                 System.out.println(media.getTitle());
96                         }
97
98                         session = factory.openSession();
99                         transaction = session.beginTransaction();
100                         criteria = session.createCriteria(UploadedMedia.class);
101                         list = criteria.setMaxResults(10).list();
102                         System.out.println("****** uploaded media");
103                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
104                                 UploadedMedia media = (UploadedMedia)iterator.next();
105                                 System.out.println(media.toString() + media.getIconPath());
106                         }
107                         transaction.commit();
108                         session.close();
109                         ImageService imageService = new ImageService(factory);
110                         //list = imageService.list(0,10);
111                         System.out.println("****** image media");
112                         //for(Iterator iterator = list.iterator(); iterator.hasNext();){
113                         //      Image media = (Image)iterator.next();
114                         //      System.out.println(media.toString() + media.getIconPath());
115                         //}
116                         IImage image = (IImage)imageService.load(new Integer(18));
117                         System.out.println(image);
118                         session = factory.openSession();
119                         transaction = session.beginTransaction();
120                         criteria = session.createCriteria(Audio.class);
121                         list = criteria.setMaxResults(10).list();
122                         System.out.println("****** audio media");
123                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
124                                 Audio media = (Audio)iterator.next();
125                                 System.out.println(media.toString() + media.getIconPath());
126                         }
127                         criteria = session.createCriteria(Video.class);
128                         list = criteria.setMaxResults(10).list();
129                         System.out.println("****** video media");
130                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
131                                 Video media = (Video)iterator.next();
132                                 System.out.println(media.toString() + media.getIconPath());
133                         }
134                         transaction.commit();
135                         session.close();
136                 } catch (HibernateException e) {
137                         // TODO Auto-generated catch block
138                         e.printStackTrace();
139                 }
140         }
141 }