001: /*
002: Copyright (C) 2003 Know Gate S.L. All rights reserved.
003: C/Oña, 107 1º2 28050 Madrid (Spain)
004:
005: Redistribution and use in source and binary forms, with or without
006: modification, are permitted provided that the following conditions
007: are met:
008:
009: 1. Redistributions of source code must retain the above copyright
010: notice, this list of conditions and the following disclaimer.
011:
012: 2. The end-user documentation included with the redistribution,
013: if any, must include the following acknowledgment:
014: "This product includes software parts from hipergate
015: (http://www.hipergate.org/)."
016: Alternately, this acknowledgment may appear in the software itself,
017: if and wherever such third-party acknowledgments normally appear.
018:
019: 3. The name hipergate must not be used to endorse or promote products
020: derived from this software without prior written permission.
021: Products derived from this software may not be called hipergate,
022: nor may hipergate appear in their name, without prior written
023: permission.
024:
025: This library is distributed in the hope that it will be useful,
026: but WITHOUT ANY WARRANTY; without even the implied warranty of
027: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029: You should have received a copy of hipergate License with this code;
030: if not, visit http://www.hipergate.org or mail to info@hipergate.org
031: */
032:
033: package com.knowgate.dataxslt.db;
034:
035: import com.knowgate.debug.DebugFile;
036: import com.knowgate.jdc.JDCConnection;
037: import com.knowgate.dataobjs.DB;
038: import com.knowgate.dataobjs.DBBind;
039: import com.knowgate.dataobjs.DBPersist;
040: import com.knowgate.misc.Gadgets;
041:
042: import java.io.File;
043: import java.io.IOException;
044:
045: import java.sql.SQLException;
046: import java.sql.CallableStatement;
047: import java.sql.PreparedStatement;
048: import java.sql.ResultSet;
049: import java.sql.Types;
050:
051: /**
052: *
053: * <p>Microsite database index</p>
054: * @author Sergio Montoro Ten
055: * @version 2.0
056: */
057: public class MicrositeDB extends DBPersist {
058:
059: public MicrositeDB() {
060: super (DB.k_microsites, "MicrositesDB");
061: }
062:
063: public MicrositeDB(JDCConnection oConn, String sMicrositeGUID)
064: throws SQLException {
065: super (DB.k_microsites, "MicrositesDB");
066: Object aPK[] = { sMicrositeGUID };
067: load(oConn, aPK);
068: }
069:
070: // ----------------------------------------------------------
071:
072: public boolean load(JDCConnection oConn, Object aPK[])
073: throws SQLException {
074: CallableStatement oStmt;
075: String sNmMicrosite;
076: boolean bRetVal;
077:
078: if (DebugFile.trace) {
079: DebugFile.writeln("Begin MicrositeDB.load([Connection], {"
080: + aPK[0] + "}");
081: DebugFile.incIdent();
082: }
083:
084: if (oConn.getDataBaseProduct() == JDCConnection.DBMS_ORACLE
085: || oConn.getDataBaseProduct() == JDCConnection.DBMS_MSSQL
086: || oConn.getDataBaseProduct() == JDCConnection.DBMS_MYSQL) {
087:
088: if (DebugFile.trace)
089: DebugFile
090: .writeln("Connection.prepareCall({ call k_sp_read_microsite ('"
091: + aPK[0] + "',?,?,?,?) }");
092:
093: oStmt = oConn
094: .prepareCall("{ call k_sp_read_microsite (?,?,?,?,?) }");
095:
096: clear();
097:
098: oStmt.setObject(1, aPK[0], Types.CHAR); // gu_microsite
099: oStmt.registerOutParameter(2, Types.INTEGER); // id_app
100: oStmt.registerOutParameter(3, Types.VARCHAR); // nm_microsite
101: oStmt.registerOutParameter(4, Types.VARCHAR); // path_metadata
102: oStmt.registerOutParameter(5, Types.CHAR); // gu_workarea
103:
104: if (DebugFile.trace)
105: DebugFile.writeln("CallableStatement.execute()");
106:
107: oStmt.execute();
108:
109: sNmMicrosite = oStmt.getString(3);
110:
111: bRetVal = (null != sNmMicrosite);
112:
113: put(DB.gu_microsite, aPK[0]);
114:
115: if (bRetVal) {
116: put(DB.id_app, oStmt.getInt(2));
117: put(DB.nm_microsite, oStmt.getString(3));
118: put(DB.path_metadata, oStmt.getString(4));
119:
120: if (oStmt.getObject(5) != null)
121: put(DB.gu_workarea, oStmt.getString(5).trim());
122: }
123:
124: oStmt.close();
125: } else
126: bRetVal = super .load(oConn, aPK);
127:
128: if (DebugFile.trace) {
129: DebugFile.decIdent();
130: DebugFile.writeln("End MicrositeDB.load() : "
131: + String.valueOf(bRetVal));
132: }
133:
134: return bRetVal;
135: } // load
136:
137: // ----------------------------------------------------------
138:
139: public boolean store(JDCConnection oConn) throws SQLException {
140: java.sql.Timestamp dtNow = new java.sql.Timestamp(DBBind
141: .getTime());
142:
143: if (!AllVals.containsKey(DB.gu_microsite))
144: put(DB.gu_microsite, Gadgets.generateUUID());
145:
146: return super .store(oConn);
147: }
148:
149: // ----------------------------------------------------------
150:
151: public boolean existsFile() {
152: if (!isNull(DB.path_metadata))
153: return new File(getString(DB.path_metadata)).exists();
154: else
155: return false;
156: } // existsFile
157:
158: // **********************************************************
159: // Metodos Estáticos
160:
161: /**
162: * <p>Get relative path to XML metadata file</p>
163: * Relative path is readed from field path_metadata of table k_microsites.<br>
164: * For example: xslt/templates/Basic.xml<br>
165: * Slashes or backsclashes are used as file separators depending on the value of
166: * System.getProperty("file.separator") and independently of what separator is
167: * used at path_metadata field.
168: * @param oConn Database Connection
169: * @param sMicrositeGUID GUID of Microsite witch metadata file relative path is to be retrieved
170: * @return Relative path to XML metadata file or <b>null</b> if no Microsite with such GUID was found at k_microsites table.
171: * @throws SQLException
172: */
173: public static String filePath(JDCConnection oConn,
174: String sMicrositeGUID) throws SQLException {
175:
176: if (DebugFile.trace) {
177: DebugFile
178: .writeln("Begin MicrositeDB.filePath([Connection], "
179: + sMicrositeGUID + ")");
180: DebugFile.incIdent();
181: }
182: PreparedStatement oStmt;
183: ResultSet oRSet;
184: String sFilePath;
185:
186: oStmt = oConn.prepareStatement("SELECT " + DB.path_metadata
187: + " FROM " + DB.k_microsites + " WHERE "
188: + DB.gu_microsite + "=?", ResultSet.TYPE_FORWARD_ONLY,
189: ResultSet.CONCUR_READ_ONLY);
190: oStmt.setString(1, sMicrositeGUID);
191: oRSet = oStmt.executeQuery();
192: if (oRSet.next())
193: sFilePath = oRSet.getString(1);
194: else
195: sFilePath = null;
196: oRSet.close();
197: oStmt.close();
198:
199: if (System.getProperty("file.separator").equals("\\")
200: && (null != sFilePath))
201: sFilePath = sFilePath.replace('/', '\\');
202:
203: if (DebugFile.trace) {
204: DebugFile.decIdent();
205: DebugFile.writeln("End MicrositeDB.filePath() : "
206: + (sFilePath != null ? sFilePath : "null"));
207: }
208: return sFilePath;
209: } // filePath
210:
211: // **********************************************************
212: // * Variables estáticas
213:
214: public static final short ClassId = 70;
215:
216: public static short TYPE_XSL = 1;
217: public static short TYPE_HTML = 2;
218: public static short TYPE_SURVEY = 4;
219: }
|