KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_insertMap


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

15 public class s_insertMap extends StoredProcedure implements ProcedureInterface {
16
17     // proprietes propres a cette stored proc
18
String JavaDoc itemID;
19
20     String JavaDoc mappingCode;
21
22     String JavaDoc rank;
23
24     String JavaDoc timeStart = "01/01/1980";
25
26     String JavaDoc timeEnd = "01/01/1980";
27
28     String JavaDoc pubName;
29
30     String JavaDoc section;
31
32     String JavaDoc pubDate;
33
34     String JavaDoc doesExists;
35
36     /**
37      * Constructor for the s_insertMap object
38      */

39     public s_insertMap() {
40     }
41
42     /**
43      * Description of the Method
44      *
45      * @param initData
46      * Description of the Parameter
47      * @param con
48      * Description of the Parameter
49      */

50     public void init(HashMap initData, Connection con) {
51         // on initialise le hashmap de donnees et la connection de l'objet
52
super.init(initData, con);
53         // on initialise les propprietes de l'objet
54
itemID = utils.getString(data, "ITEMID", "");
55         mappingCode = utils.getString(data, "MAPPINGCODE", "");
56         rank = utils.getString(data, "RANK", "");
57     }
58
59     /**
60      * Description of the Method
61      *
62      * @exception SQLException
63      * Description of the Exception
64      */

65     public void checkParams() throws SQLException {
66         if (itemID.equals(""))
67             throw new SQLException("ERROR: required field PUBDATE was not sent.");
68         if (mappingCode.equals(""))
69             throw new SQLException("ERROR: required field MAPPINGCODE was not sent.");
70         if (rank.equals(""))
71             throw new SQLException("ERROR: required field RANK was not sent.");
72
73         if (timeStart.equals("1/1/1980")) {
74             timeStart = sdf.format(new java.util.Date JavaDoc());
75         }
76         if (timeEnd.equals("1/1/1980")) {
77             timeEnd = sdf.format(new java.util.Date JavaDoc());
78         }
79
80         StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
81         v_sb.append("SELECT count(*) ").append("FROM tblarticleorder ").append("WHERE mappingCode = '" + mappingCode + "' ").append(
82                 "AND itemID = '" + itemID + "'");
83         doesExists = execStatementToValue(v_sb.toString());
84
85     }
86
87     /**
88      * Description of the Method
89      *
90      * @exception SQLException
91      * Description of the Exception
92      */

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

102     public void executeAction() throws SQLException {
103         if (Integer.parseInt(doesExists) > 0) {
104             StringBuffer JavaDoc v_sbDelete = new StringBuffer JavaDoc();
105             v_sbDelete.append("DELETE FROM tblarticleorder ").append(" WHERE mappingCode = '" + mappingCode + "' ").append("AND itemID = '" + itemID + "'");
106
107             execStatement(v_sbDelete.toString());
108         }
109
110         StringBuffer JavaDoc v_sb1 = new StringBuffer JavaDoc();
111         v_sb1.append("SELECT pubDate from tblarticles where itemID=" + itemID);
112         pubDate = execStatementToValue(v_sb1.toString());
113         StringBuffer JavaDoc v_sb2 = new StringBuffer JavaDoc();
114         v_sb2.append("SELECT pubName from tblsections where mappingCode=" + mappingCode);
115         pubName = execStatementToValue(v_sb2.toString());
116         StringBuffer JavaDoc v_sb3 = new StringBuffer JavaDoc();
117         v_sb3.append("SELECT section from tblsections where mappingCode=" + mappingCode);
118         section = execStatementToValue(v_sb3.toString());
119
120         StringBuffer JavaDoc v_sbInsert = new StringBuffer JavaDoc();
121         v_sbInsert.append("INSERT INTO tblarticleorder ").append("(itemID, rank, mappingCode, timeStart, timeEnd, ").append(
122                 "mappingUpdateDate, pubName, section, pubDate) ").append(
123                 " VALUES ('" + itemID + "', '" + rank + "', '" + mappingCode + "', '" + timeStart + "', '" + timeEnd + "', '"
124                         + sdf.format(new java.util.Date JavaDoc()) + "','" + pubName + "', '" + section + "', '" + pubDate + "')");
125
126         execStatement(v_sbInsert.toString());
127
128         StringBuffer JavaDoc v_sbUpdate = new StringBuffer JavaDoc();
129         v_sbUpdate.append("UPDATE tblarticles ").append("SET updateDate = now() ").append("WHERE itemID = '" + itemID + "'");
130
131         execStatement(v_sbUpdate.toString());
132
133         s_updateArticlePreload sp_uap = new s_updateArticlePreload();
134         sp_uap.init(data, psConnection);
135         sp_uap.setItemID(itemID);
136         sp_uap.setTargetDataStore(targetDataStore);
137         sp_uap.executeAction();
138
139         execStatementToRS(queryResultOk);
140
141     }
142 }
143
Popular Tags