KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > dataxslt > db > MicrositeDB


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/Oña, 107 1º2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.dataxslt.db;
34
35 import com.knowgate.debug.DebugFile;
36 import com.knowgate.jdc.JDCConnection;
37 import com.knowgate.dataobjs.DB;
38 import com.knowgate.dataobjs.DBBind;
39 import com.knowgate.dataobjs.DBPersist;
40 import com.knowgate.misc.Gadgets;
41
42 import java.io.File JavaDoc;
43 import java.io.IOException JavaDoc;
44
45 import java.sql.SQLException JavaDoc;
46 import java.sql.CallableStatement JavaDoc;
47 import java.sql.PreparedStatement JavaDoc;
48 import java.sql.ResultSet JavaDoc;
49 import java.sql.Types JavaDoc;
50
51 /**
52  *
53  * <p>Microsite database index</p>
54  * @author Sergio Montoro Ten
55  * @version 2.0
56  */

57 public class MicrositeDB extends DBPersist {
58
59   public MicrositeDB() {
60     super(DB.k_microsites, "MicrositesDB");
61   }
62
63   public MicrositeDB(JDCConnection oConn, String JavaDoc sMicrositeGUID) throws SQLException JavaDoc {
64     super(DB.k_microsites, "MicrositesDB");
65     Object JavaDoc aPK[] = {sMicrositeGUID};
66     load (oConn, aPK);
67   }
68
69   // ----------------------------------------------------------
70

71   public boolean load(JDCConnection oConn, Object JavaDoc aPK[]) throws SQLException JavaDoc {
72     CallableStatement JavaDoc oStmt;
73     String JavaDoc sNmMicrosite;
74     boolean bRetVal;
75
76     if (DebugFile.trace) {
77       DebugFile.writeln("Begin MicrositeDB.load([Connection], {" + aPK[0] + "}");
78       DebugFile.incIdent();
79     }
80
81     if (oConn.getDataBaseProduct()==JDCConnection.DBMS_ORACLE ||
82         oConn.getDataBaseProduct()==JDCConnection.DBMS_MSSQL ||
83         oConn.getDataBaseProduct()==JDCConnection.DBMS_MYSQL) {
84
85       if (DebugFile.trace)
86         DebugFile.writeln("Connection.prepareCall({ call k_sp_read_microsite ('" + aPK[0] + "',?,?,?,?) }");
87
88       oStmt = oConn.prepareCall("{ call k_sp_read_microsite (?,?,?,?,?) }");
89
90       clear();
91
92       oStmt.setObject(1, aPK[0], Types.CHAR); // gu_microsite
93
oStmt.registerOutParameter(2, Types.INTEGER); // id_app
94
oStmt.registerOutParameter(3, Types.VARCHAR); // nm_microsite
95
oStmt.registerOutParameter(4, Types.VARCHAR); // path_metadata
96
oStmt.registerOutParameter(5, Types.CHAR); // gu_workarea
97

98       if (DebugFile.trace) DebugFile.writeln("CallableStatement.execute()");
99
100       oStmt.execute();
101
102       sNmMicrosite = oStmt.getString(3);
103
104       bRetVal = (null!=sNmMicrosite);
105
106       put (DB.gu_microsite, aPK[0]);
107
108       if (bRetVal) {
109         put(DB.id_app, oStmt.getInt(2));
110         put(DB.nm_microsite, oStmt.getString(3));
111         put(DB.path_metadata, oStmt.getString(4));
112
113         if (oStmt.getObject(5)!=null) put(DB.gu_workarea, oStmt.getString(5).trim());
114       }
115
116     oStmt.close();
117     }
118     else
119       bRetVal = super.load(oConn, aPK);
120
121     if (DebugFile.trace) {
122       DebugFile.decIdent();
123       DebugFile.writeln("End MicrositeDB.load() : " + String.valueOf(bRetVal));
124     }
125
126     return bRetVal;
127   } // load
128

129   // ----------------------------------------------------------
130

131   public boolean store(JDCConnection oConn) throws SQLException JavaDoc {
132     java.sql.Timestamp JavaDoc dtNow = new java.sql.Timestamp JavaDoc(DBBind.getTime());
133
134     if (!AllVals.containsKey(DB.gu_microsite))
135       put(DB.gu_microsite, Gadgets.generateUUID());
136
137     return super.store(oConn);
138   }
139
140   // ----------------------------------------------------------
141

142   public boolean existsFile() {
143     if (!isNull(DB.path_metadata))
144       return new File(getString(DB.path_metadata)).exists();
145     else
146       return false;
147   } // existsFile
148

149   // **********************************************************
150
// Metodos Estáticos
151

152   /**
153    * <p>Get relative path to XML metadata file</p>
154    * Relative path is readed from field path_metadata of table k_microsites.<br>
155    * For example: xslt/templates/Basic.xml<br>
156    * Slashes or backsclashes are used as file separators depending on the value of
157    * System.getProperty("file.separator") and independently of what separator is
158    * used at path_metadata field.
159    * @param oConn Database Connection
160    * @param sMicrositeGUID GUID of Microsite witch metadata file relative path is to be retrieved
161    * @return Relative path to XML metadata file or <b>null</b> if no Microsite with such GUID was found at k_microsites table.
162    * @throws SQLException
163    */

164   public static String JavaDoc filePath(JDCConnection oConn, String JavaDoc sMicrositeGUID) throws SQLException JavaDoc {
165
166     if (DebugFile.trace) {
167       DebugFile.writeln("Begin MicrositeDB.filePath([Connection], " + sMicrositeGUID + ")");
168       DebugFile.incIdent();
169     }
170     PreparedStatement JavaDoc oStmt;
171     ResultSet JavaDoc oRSet;
172     String JavaDoc sFilePath;
173
174     oStmt = oConn.prepareStatement("SELECT " + DB.path_metadata + " FROM " + DB.k_microsites + " WHERE " + DB.gu_microsite + "=?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
175     oStmt.setString(1, sMicrositeGUID);
176     oRSet = oStmt.executeQuery();
177     if (oRSet.next())
178       sFilePath = oRSet.getString(1);
179     else
180       sFilePath = null;
181     oRSet.close();
182     oStmt.close();
183
184     if (System.getProperty("file.separator").equals("\\") && (null!=sFilePath))
185       sFilePath = sFilePath.replace('/','\\');
186
187     if (DebugFile.trace) {
188       DebugFile.decIdent();
189       DebugFile.writeln("End MicrositeDB.filePath() : " + (sFilePath!=null ? sFilePath : "null"));
190     }
191     return sFilePath;
192   } // filePath
193

194   // **********************************************************
195
// * Variables estáticas
196

197   public static final short ClassId = 70;
198
199   public static short TYPE_XSL = 1;
200   public static short TYPE_HTML = 2;
201   public static short TYPE_SURVEY = 4;
202 }
203
Popular Tags