first cut of merge of STABLE-pre1_0 into HEAD. I won't even guarantee that it
[mir.git] / source / mircoders / entity / EntityVideo.java
1 package mircoders.entity;
2
3 import java.lang.*;
4 import java.io.*;
5 import java.util.*;
6 import java.sql.*;
7
8 import mir.entity.*;
9 import mir.misc.*;
10 import mir.storage.*;
11
12 /**
13  * Diese Klasse enthält die Daten eines MetaObjekts
14  *
15  * @author RK
16  * @version 11.11.2000
17  */
18
19
20 public class EntityVideo extends EntityUploadedMedia
21 {
22
23         public EntityVideo()
24         {
25                 super();
26         }
27
28         public EntityVideo(StorageObject theStorage) {
29                 this();
30                 setStorage(theStorage);
31         }
32
33         //
34         // methods
35
36         public byte[] getVideoData() throws StorageObjectException
37         {
38
39                 Connection con=null;Statement stmt=null;
40                 byte[] video_data=null;
41
42                 try {
43                         con = theStorageObject.getPooledCon();
44                         con.setAutoCommit(false);
45                         stmt = con.createStatement();
46                         ResultSet rs = theStorageObject.executeSql(stmt,"select video_data from video where id="+getId());
47                         if(rs!=null) {
48                                 if (rs.next()) {
49                                          video_data = rs.getBytes(1);
50                                 }
51                                 rs.close();
52                         }
53                 }
54                 catch (Exception e) {theLog.printDebugInfo("-- getImage gescheitert: "+e.toString());}
55                 finally {
56                         try {con.setAutoCommit(true); } catch (Exception e) {;}
57                         theStorageObject.freeConnection(con,stmt); }
58
59                 return video_data;
60         }
61
62         public void setVideoData(byte[] uploadData) throws StorageObjectException
63         {
64                 if (uploadData!=null) {
65                         Connection con=null;PreparedStatement pstmt=null;
66                         try {
67
68                                 con = theStorageObject.getPooledCon();
69                                 con.setAutoCommit(false);
70                                 theLog.printDebugInfo("setvideo :: trying to insert video");
71
72                                 // setting values
73                                 String sql = "update videos set image_data=? where id="+getId();
74                                 theLog.printDebugInfo("setvideo: "+ sql);
75                                 pstmt = con.prepareStatement(sql);
76                                 pstmt.setBytes(1, uploadData);
77                                 pstmt.executeUpdate();
78                                 sql="update content set is_produced='0' where to_media="+getId();
79                                 pstmt = con.prepareStatement(sql);
80                                 pstmt.executeUpdate();
81                         }
82                         catch (Exception e) {theLog.printDebugInfo("setvideo :: setvideo gescheitert: "+e.toString());}
83                         finally {
84                                 try {con.setAutoCommit(true); } catch (Exception e) {;}
85                                 theStorageObject.freeConnection(con,pstmt); }
86                 }
87         }
88
89         public void update() throws StorageObjectException {
90                 super.update();
91                 try {
92                         theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
93                 } catch (SQLException e) {
94                         theLog.printError("video :: update :: failed!! "+ e.toString());
95                 }
96         }
97
98         public void setValues(HashMap theStringValues)
99         {
100                 if (theStringValues != null) {
101                         if (!theStringValues.containsKey("is_published"))
102                          theStringValues.put("is_published","0");
103                 }
104                 super.setValues(theStringValues);
105         }
106
107 }