8f651e445336a09e1890b4f81adbddb55bb64898
[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 Entity
21 {
22         private static int instances;
23
24         public EntityVideo()
25         {
26                 super();
27                 instances++;
28         }
29
30         public EntityVideo(StorageObject theStorage) {
31                 this();
32                 setStorage(theStorage);
33         }
34
35         //
36         // methods
37
38         public byte[] getVideoData()
39         {
40
41                 Connection con=null;Statement stmt=null;
42                 byte[] video_data=null;
43
44                 try {
45                         con = theStorageObject.getPooledCon();
46                         con.setAutoCommit(false);
47                         stmt = con.createStatement();
48                         ResultSet rs = theStorageObject.executeSql(stmt,"select video_data from video where id="+getId());
49                         if(rs!=null) {
50                                 if (rs.next()) {
51                                          video_data = rs.getBytes(1);
52                                 }
53                                 rs.close();
54                         }
55                 }
56                 catch (Exception e) {theLog.printDebugInfo("-- getImage gescheitert: "+e.toString());}
57                 finally {
58                         try {con.setAutoCommit(true); } catch (Exception e) {;}
59                         theStorageObject.freeConnection(con,stmt); }
60
61                 return video_data;
62         }
63
64         public void setVideoData(byte[] uploadData)
65         {
66                 if (uploadData!=null) {
67                         Connection con=null;PreparedStatement pstmt=null;
68                         try {
69
70                                 con = theStorageObject.getPooledCon();
71                                 con.setAutoCommit(false);
72                                 theLog.printDebugInfo("setvideo :: trying to insert video");
73
74                                 // setting values
75                                 String sql = "update videos set image_data=? where id="+getId();
76                                 theLog.printDebugInfo("setvideo: "+ sql);
77                                 pstmt = con.prepareStatement(sql);
78                                 pstmt.setBytes(1, uploadData);
79                                 pstmt.executeUpdate();
80                                 sql="update content set is_produced='0' where to_media="+getId();
81                                 pstmt = con.prepareStatement(sql);
82                                 pstmt.executeUpdate();
83                         }
84                         catch (Exception e) {theLog.printDebugInfo("setvideo :: setvideo gescheitert: "+e.toString());}
85                         finally {
86                                 try {con.setAutoCommit(true); } catch (Exception e) {;}
87                                 theStorageObject.freeConnection(con,pstmt); }
88                 }
89         }
90
91         public void update() throws StorageObjectException {
92                 super.update();
93                 try {
94                         theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
95                 } catch (SQLException e) {
96                         theLog.printError("video :: update :: failed!! "+ e.toString());
97                 }
98         }
99
100         public void setValues(HashMap theStringValues)
101         {
102                 if (theStringValues != null) {
103                         if (!theStringValues.containsKey("is_published"))
104                          theStringValues.put("is_published","0");
105                 }
106                 super.setValues(theStringValues);
107         }
108
109
110         public void finalize() {
111                 instances--;
112                 super.finalize();
113         }
114
115 }