next steps in new persitence
[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.Image;
42 import mir.core.model.Media;
43 import mir.core.model.Topic;
44 import mir.core.model.UploadedMedia;
45 import mir.core.model.Video;
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.2 2003/08/17 14:19:17 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                         System.out.println("****** content media");
79                         criteria = session.createCriteria(Content.class);
80                         list = criteria.setMaxResults(10).list();
81                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
82                                 Content media = (Content)iterator.next();
83                                 System.out.println(media.getTitle());
84                         }
85                         criteria = session.createCriteria(UploadedMedia.class);
86                         list = criteria.setMaxResults(10).list();
87                         System.out.println("****** uploaded media");
88                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
89                                 UploadedMedia media = (UploadedMedia)iterator.next();
90                                 System.out.println(media.toString() + media.getIconPath());
91                         }
92                         criteria = session.createCriteria(Image.class);
93                         list = criteria.setMaxResults(10).list();
94                         System.out.println("****** image media");
95                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
96                                 Image media = (Image)iterator.next();
97                                 System.out.println(media.toString() + media.getIconPath());
98                         }
99                         criteria = session.createCriteria(Audio.class);
100                         list = criteria.setMaxResults(10).list();
101                         System.out.println("****** audio media");
102                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
103                                 Audio media = (Audio)iterator.next();
104                                 System.out.println(media.toString() + media.getIconPath());
105                         }
106                         criteria = session.createCriteria(Video.class);
107                         list = criteria.setMaxResults(10).list();
108                         System.out.println("****** video media");
109                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
110                                 Video media = (Video)iterator.next();
111                                 System.out.println(media.toString() + media.getIconPath());
112                         }
113                         transaction.commit();
114                         session.close();
115                 } catch (HibernateException e) {
116                         // TODO Auto-generated catch block
117                         e.printStackTrace();
118                 }
119         }
120 }