1 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 ; 43 import java.io.IOException ; 44 45 import java.sql.SQLException ; 46 import java.sql.CallableStatement ; 47 import java.sql.PreparedStatement ; 48 import java.sql.ResultSet ; 49 import java.sql.Types ; 50 51 57 public class MicrositeDB extends DBPersist { 58 59 public MicrositeDB() { 60 super(DB.k_microsites, "MicrositesDB"); 61 } 62 63 public MicrositeDB(JDCConnection oConn, String sMicrositeGUID) throws SQLException { 64 super(DB.k_microsites, "MicrositesDB"); 65 Object aPK[] = {sMicrositeGUID}; 66 load (oConn, aPK); 67 } 68 69 71 public boolean load(JDCConnection oConn, Object aPK[]) throws SQLException { 72 CallableStatement oStmt; 73 String 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); oStmt.registerOutParameter(2, Types.INTEGER); oStmt.registerOutParameter(3, Types.VARCHAR); oStmt.registerOutParameter(4, Types.VARCHAR); oStmt.registerOutParameter(5, Types.CHAR); 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 } 129 131 public boolean store(JDCConnection oConn) throws SQLException { 132 java.sql.Timestamp dtNow = new java.sql.Timestamp (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 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 } 149 152 164 public static String filePath(JDCConnection oConn, String sMicrositeGUID) throws SQLException { 165 166 if (DebugFile.trace) { 167 DebugFile.writeln("Begin MicrositeDB.filePath([Connection], " + sMicrositeGUID + ")"); 168 DebugFile.incIdent(); 169 } 170 PreparedStatement oStmt; 171 ResultSet oRSet; 172 String 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 } 194 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 |