KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_insertMultimedia


1 package smile.stored;
2
3 import java.util.*;
4 import java.sql.*;
5
6 import org.cofax.cms.CofaxToolsUtil;
7
8 /**
9  * s_insertMultimedia is an implements the ProcedureInterface and is a sub-class
10  * of StoredProcedure. This class inserts multimedia types in the database.
11  * Copyright 2002 Smile Les motoristes Internet http://www.smile.fr/ Contact
12  * cofax@smile.fr for further information
13  *
14  * @author Smile Les motoristes Internet
15  * @created March 22, 2002
16  */

17 public class s_insertMultimedia extends StoredProcedure implements ProcedureInterface {
18
19     // proprietes propres a cette stored proc
20
String JavaDoc itemID;
21
22     String JavaDoc type;
23
24     String JavaDoc itemName;
25
26     String JavaDoc caption;
27
28     String JavaDoc mimeType;
29
30     int rank;
31
32     String JavaDoc credit;
33
34     String JavaDoc size;
35
36     String JavaDoc icon;
37
38     String JavaDoc filename; // added by FX
39

40     /**
41      * Constructor for the s_insertMultimedia object
42      */

43     public s_insertMultimedia() {
44     }
45
46     /**
47      * Description of the Method
48      *
49      * @param initData
50      * Description of the Parameter
51      * @param con
52      * Description of the Parameter
53      */

54     public void init(HashMap initData, Connection con) {
55         // on initialise le hashmap de donnees et la connection de l'objet
56
super.init(initData, con);
57         // on initialise les propprietes de l'objet
58
itemID = utils.getString(data, "ITEMID", "");
59         type = utils.getString(data, "MULTIMEDIATYPE", "");
60         itemName = utils.getString(data, "ARTICLEIMAGENAME", "");
61         caption = utils.getString(data, "MULTIMEDIACAPTION", "");
62         size = utils.getString(data, "SIZE", "0");
63         icon = utils.getString(data, "ICON", "");
64         filename = utils.getString(data, "FILENAME", "dummy.bin"); // added by
65
// fx
66

67         if (rank == 0) {
68             rank = 999;
69         }
70     }
71
72     /**
73      * Description of the Method
74      *
75      * @exception SQLException
76      * Description of the Exception
77      */

78     public void checkParams() throws SQLException {
79
80         if (caption == null) {
81             caption = "";
82         }
83         if (itemID.equals("") || type.equals("") || itemName.equals("")) {
84
85             throw new SQLException("ERROR: REQUIRED FIELDS WERE NOT SENT.");
86         }
87     }
88
89     /**
90      * Description of the Method
91      *
92      * @exception SQLException
93      * Description of the Exception
94      */

95     public void checkAction() throws SQLException {
96     }
97
98     /**
99      * Description of the Method
100      *
101      * @exception SQLException
102      * Description of the Exception
103      */

104     public void executeAction() throws SQLException {
105         if ((type.equals("sectionImage")) || (type.equals("articleImage"))) {
106             StringBuffer JavaDoc v_sbDelete = new StringBuffer JavaDoc();
107             v_sbDelete.append("DELETE from tblmultimedia").append(" WHERE type = '" + type + "'").append(" AND itemID = '" + itemID + "'");
108             execStatement(v_sbDelete.toString());
109         } else {
110             StringBuffer JavaDoc v_sbDelete = new StringBuffer JavaDoc();
111             v_sbDelete.append("DELETE from tblmultimedia").append(" WHERE type = '" + type + "'").append(" AND itemID = '" + itemID + "'").append(
112                     " AND itemName = '" + itemName + "'");
113             execStatement(v_sbDelete.toString());
114         }
115
116         StringBuffer JavaDoc v_sbInsert = new StringBuffer JavaDoc();
117         v_sbInsert.append("INSERT INTO tblmultimedia ").append(
118                 "(filename, itemID, type, itemName, mimeType, caption, rank, credit, multimediaUpdateDate, size, icon)").append(
119                 " VALUES ('" + filename + "', '" + itemID + "', '" + type + "', '" + itemName + "', '" + mimeType + "', '" + caption + "', '" + rank + "', '"
120                         + credit + "', '" + sdf.format(new java.util.Date JavaDoc()) + "', '" + size + "', '" + icon + "')");
121
122         CofaxToolsUtil.log("Insert avec le filename :" + filename); // added by
123
// fx.
124
execStatement(v_sbInsert.toString());
125
126         StringBuffer JavaDoc v_sbUpdate = new StringBuffer JavaDoc();
127         v_sbUpdate.append("UPDATE tblarticles ").append(" SET updateDate = now() ").append(" WHERE itemID = '" + itemID + "'");
128
129         execStatement(v_sbUpdate.toString());
130
131         // Update tblarticlepreload
132
if (type.equals("articleImage")) {
133             StringBuffer JavaDoc v_sbUpdate2 = new StringBuffer JavaDoc();
134             v_sbUpdate2.append("UPDATE tblarticlepreload SET ").append(" articleImage= '" + itemName + "', ")
135                     .append(" articleImagecaption= '" + caption + "' ").append(" WHERE ITEMID= '" + itemID + "' ");
136             execStatement(v_sbUpdate2.toString());
137         }
138
139         if (type.equals("sectionImage")) {
140             StringBuffer JavaDoc v_sbUpdate2 = new StringBuffer JavaDoc();
141             v_sbUpdate2.append("UPDATE tblarticlepreload SET ").append(" listImage= '" + itemName + "', ").append(" listImagecaption= '" + caption + "' ")
142                     .append(" WHERE ITEMID= '" + itemID + "' ");
143             execStatement(v_sbUpdate2.toString());
144         }
145
146         execStatementToRS(queryResultOk);
147
148     }
149 }
150
Popular Tags