rebuilding head
[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.Comment;
39 import mir.core.model.Content;
40 import mir.core.model.IImage;
41 import mir.core.model.Image;
42 import mir.core.model.Media;
43 import mir.core.model.Topic;
44 import mir.core.model.TopicRich;
45 import mir.core.model.UploadedMedia;
46 import mir.core.model.Video;
47 import mir.core.service.storage.ContentService;
48 import mir.core.service.storage.ImageService;
49 import net.sf.hibernate.Criteria;
50 import net.sf.hibernate.HibernateException;
51 import net.sf.hibernate.Session;
52 import net.sf.hibernate.SessionFactory;
53 import net.sf.hibernate.Transaction;
54 import net.sf.hibernate.cfg.Configuration;
55 import net.sf.hibernate.expression.Order;
56 import net.sf.hibernate.tool.hbm2ddl.SchemaExport;
57
58 /**
59  * Test
60  * @version $Id: Test.java,v 1.9 2003/12/20 20:27:09 idfx Exp $
61  * @author idefix
62  */
63 public class Test {
64
65         public static void main(String[] args) {
66                 //BasicConfigurator.configure();
67                 try {
68                         Configuration configuration = new Configuration().configure();
69                         SessionFactory factory = configuration.buildSessionFactory();
70                         Session session = factory.openSession();
71 //                      SchemaExport export = new SchemaExport(configuration);
72 //                      export.setOutputFile("/tmp/test.sql");
73 //                      export.create(true, false);
74                         Transaction transaction = session.beginTransaction();
75                         Criteria criteria = session.createCriteria(Topic.class);
76                         List list = criteria.setMaxResults(10).list();
77                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
78                                 Topic media = (Topic)iterator.next();
79                                 System.out.println(media.toString());
80                         }
81                         criteria = session.createCriteria(Media.class);
82                         criteria.addOrder(Order.asc("id"));
83                         list = criteria.list();
84                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
85                                 Media media = (Media)iterator.next();
86                                 System.out.println(media.toString());
87                         }
88                         System.out.println("media size " + list.size());
89                         
90                         criteria = session.createCriteria(Comment.class);
91                         criteria.addOrder(Order.asc("id"));
92                         list = criteria.list();
93                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
94                                 Comment media = (Comment)iterator.next();
95                                 System.out.println(media.toString());
96                         }
97                         System.out.println("comment size " + list.size());
98
99                         criteria = session.createCriteria(Content.class);
100                         criteria.addOrder(Order.asc("id"));
101                         list = criteria.list();
102                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
103                                 Content media = (Content)iterator.next();
104                                 System.out.println(media.toString());
105                         }
106                         System.out.println("content size " + list.size());
107
108                         transaction.commit();
109                         session.close();
110
111                         ContentService contentService = new ContentService(factory);
112                         
113                         Object content = contentService.load(new Integer(7));
114                         System.out.println(content + content.getClass().getName());
115                         
116                         System.out.println("****** content media");
117
118                         list = contentService.list(0,10);
119                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
120                                 Content media = (Content)iterator.next();
121                                 System.out.println(media.getTitle());
122                         }
123
124                         session = factory.openSession();
125                         transaction = session.beginTransaction();
126                         criteria = session.createCriteria(UploadedMedia.class);
127                         list = criteria.setMaxResults(10).list();
128                         System.out.println("****** uploaded media");
129                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
130                                 UploadedMedia media = (UploadedMedia)iterator.next();
131                                 System.out.println(media.toString() + media.getIconPath());
132                         }
133                         transaction.commit();
134                         session.close();
135                         ImageService imageService = new ImageService(factory);
136                         list = imageService.list(0,10);
137                         System.out.println("****** image media");
138                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
139                                 Image media = (Image)iterator.next();
140                                 System.out.println(media.toString() + media.getIconPath());
141                         }
142                         IImage image = (IImage)imageService.load(new Integer(18));
143                         System.out.println(image + " " + image.getImage().length);
144                         session = factory.openSession();
145                         transaction = session.beginTransaction();
146                         criteria = session.createCriteria(Audio.class);
147                         list = criteria.setMaxResults(10).list();
148                         System.out.println("****** audio media");
149                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
150                                 Audio media = (Audio)iterator.next();
151                                 System.out.println(media.toString() + media.getIconPath());
152                         }
153                         criteria = session.createCriteria(Video.class);
154                         list = criteria.setMaxResults(10).list();
155                         System.out.println("****** video media");
156                         for(Iterator iterator = list.iterator(); iterator.hasNext();){
157                                 Video media = (Video)iterator.next();
158                                 System.out.println(media.toString() + media.getIconPath());
159                         }
160                         transaction.commit();
161                         session.close();
162                 } catch (HibernateException e) {
163                         // TODO Auto-generated catch block
164                         e.printStackTrace();
165                 }
166         }
167 }