next steps in itegrating struts and hibernate.\rlogin and logout ist now possible...
[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 mir.core.model.Audio;
38 import mir.core.model.Content;
39 import mir.core.model.IImage;
40 import mir.core.model.Media;
41 import mir.core.model.Topic;
42 import mir.core.model.UploadedMedia;
43 import mir.core.model.Video;
44 import mir.core.service.storage.ContentService;
45 import mir.core.service.storage.ImageService;
46 import net.sf.hibernate.Criteria;
47 import net.sf.hibernate.HibernateException;
48 import net.sf.hibernate.Session;
49 import net.sf.hibernate.SessionFactory;
50 import net.sf.hibernate.Transaction;
51 import net.sf.hibernate.cfg.Configuration;
52
53 /**
54  * Test
55  * @version $Id: Test.java,v 1.7 2003/09/07 16:55:00 idfx Exp $
56  * @author idefix
57  */
58 public class Test {
59
60         public static void main(String[] args) {
61                 //BasicConfigurator.configure();
62                 try {
63                         SessionFactory factory = new Configuration().configure().buildSessionFactory();
64                         Session session = factory.openSession();
65                         Transaction transaction = session.beginTransaction();
66                         Criteria criteria = session.createCriteria(Topic.class);
67                         List list = criteria.setMaxResults(10).list();
68                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
69                                 Topic media = (Topic)iterator.next();
70                                 System.out.println(media.toString());
71                         }
72                         criteria = session.createCriteria(Media.class);
73                         list = criteria.setMaxResults(10).list();
74                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
75                                 Media media = (Media)iterator.next();
76                                 System.out.println(media.toString());
77                         }
78                         transaction.commit();
79                         session.close();
80
81                         ContentService contentService = new ContentService(factory);
82                         
83                         Object content = contentService.load(new Integer(7));
84                         System.out.println(content + content.getClass().getName());
85                         
86                         System.out.println("****** content media");
87
88                         list = contentService.list(0,10);
89                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
90                                 Content media = (Content)iterator.next();
91                                 System.out.println(media.getTitle());
92                         }
93
94                         session = factory.openSession();
95                         transaction = session.beginTransaction();
96                         criteria = session.createCriteria(UploadedMedia.class);
97                         list = criteria.setMaxResults(10).list();
98                         System.out.println("****** uploaded media");
99                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
100                                 UploadedMedia media = (UploadedMedia)iterator.next();
101                                 System.out.println(media.toString() + media.getIconPath());
102                         }
103                         transaction.commit();
104                         session.close();
105                         ImageService imageService = new ImageService(factory);
106                         //list = imageService.list(0,10);
107                         System.out.println("****** image media");
108                         //for(Iterator iterator = list.iterator(); iterator.hasNext();){
109                         //      Image media = (Image)iterator.next();
110                         //      System.out.println(media.toString() + media.getIconPath());
111                         //}
112                         IImage image = (IImage)imageService.load(new Integer(18));
113                         System.out.println(image);
114                         session = factory.openSession();
115                         transaction = session.beginTransaction();
116                         criteria = session.createCriteria(Audio.class);
117                         list = criteria.setMaxResults(10).list();
118                         System.out.println("****** audio media");
119                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
120                                 Audio media = (Audio)iterator.next();
121                                 System.out.println(media.toString() + media.getIconPath());
122                         }
123                         criteria = session.createCriteria(Video.class);
124                         list = criteria.setMaxResults(10).list();
125                         System.out.println("****** video media");
126                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
127                                 Video media = (Video)iterator.next();
128                                 System.out.println(media.toString() + media.getIconPath());
129                         }
130                         transaction.commit();
131                         session.close();
132                 } catch (HibernateException e) {
133                         // TODO Auto-generated catch block
134                         e.printStackTrace();
135                 }
136         }
137 }