xref: /aoo41x/main/qadevOOo/runner/convwatch/DB.java (revision ef39d40d)
1*ef39d40dSAndrew Rist /**************************************************************
2*ef39d40dSAndrew Rist  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22cdf0e10cSrcweir package convwatch;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import java.sql.Connection;
25cdf0e10cSrcweir import java.util.StringTokenizer;
26cdf0e10cSrcweir import java.util.ArrayList;
27cdf0e10cSrcweir import helper.OSHelper;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // import convwatch.DBHelper;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir public class DB extends DBHelper
32cdf0e10cSrcweir {
33cdf0e10cSrcweir     private static DB m_aDB = null;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir     // private ctor
DB()36cdf0e10cSrcweir     private DB()
37cdf0e10cSrcweir         {
38cdf0e10cSrcweir         }
39cdf0e10cSrcweir 
getDB()40cdf0e10cSrcweir     private static synchronized DB getDB()
41cdf0e10cSrcweir         {
42cdf0e10cSrcweir             if (m_aDB == null)
43cdf0e10cSrcweir             {
44cdf0e10cSrcweir                 m_aDB = new DB();
45cdf0e10cSrcweir             }
46cdf0e10cSrcweir             return m_aDB;
47cdf0e10cSrcweir         }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     private String m_sSourceVersion;
50cdf0e10cSrcweir     private String m_sDestinationVersion;
51cdf0e10cSrcweir     private String m_sDocumentPool;
52cdf0e10cSrcweir     private String m_sEnvironment;
53cdf0e10cSrcweir     private String m_sDocID;
54cdf0e10cSrcweir     private String m_sDBDistinct;
55cdf0e10cSrcweir 
init(String _sDBInfoString)56cdf0e10cSrcweir     public static void init(String _sDBInfoString)
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             if (_sDBInfoString == null) return;
59cdf0e10cSrcweir             getDB().fillVariables(_sDBInfoString);
60cdf0e10cSrcweir             getDB().updatestate_status("source started");
61cdf0e10cSrcweir         }
62cdf0e10cSrcweir 
test()63cdf0e10cSrcweir     public static void test()
64cdf0e10cSrcweir         {
65cdf0e10cSrcweir             getDB().sql_test();
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir 
source_start()68cdf0e10cSrcweir     public static void source_start()
69cdf0e10cSrcweir         {
70cdf0e10cSrcweir             getDB().updatestate_status("source started");
71cdf0e10cSrcweir         }
72cdf0e10cSrcweir 
source_finished()73cdf0e10cSrcweir     public static void source_finished()
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir             getDB().updatestate_status( "source finished");
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir 
source_failed(String _sMessage)78cdf0e10cSrcweir     public static void source_failed(String _sMessage)
79cdf0e10cSrcweir         {
80cdf0e10cSrcweir             getDB().updatestate_status("source failed");
81cdf0e10cSrcweir             getDB().updateinfo_status(_sMessage);
82cdf0e10cSrcweir         }
83cdf0e10cSrcweir 
destination_start()84cdf0e10cSrcweir     public static void destination_start()
85cdf0e10cSrcweir         {
86cdf0e10cSrcweir             getDB().updatestate_status("destination started");
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir 
destination_finished()89cdf0e10cSrcweir     public static void destination_finished()
90cdf0e10cSrcweir         {
91cdf0e10cSrcweir             getDB().updatestate_status("PASSED-OK");
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
destination_failed(String _sStatus, String _sMessage)94cdf0e10cSrcweir     public static void destination_failed(String _sStatus, String _sMessage)
95cdf0e10cSrcweir         {
96cdf0e10cSrcweir             getDB().updatestate_status(_sStatus);
97cdf0e10cSrcweir             getDB().updateinfo_status(_sMessage);
98cdf0e10cSrcweir         }
writeNumberOfPages(int _nPages)99cdf0e10cSrcweir     public static void writeNumberOfPages(int _nPages)
100cdf0e10cSrcweir         {
101cdf0e10cSrcweir             getDB().updatepagecount_documents(_nPages);
102cdf0e10cSrcweir         }
writeErrorFile(String _sErrorFile)103cdf0e10cSrcweir     public static void writeErrorFile(String _sErrorFile)
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             getDB().updateerrorfile_status(_sErrorFile);
106cdf0e10cSrcweir         }
writeHTMLFile(String _sHTMLFile)107cdf0e10cSrcweir     public static void writeHTMLFile(String _sHTMLFile)
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir             getDB().updatehtmlfile_status(_sHTMLFile);
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir 
writeToDB(String _sFilename, String _sBasename, String _sFileFormat, String _sBuildID, String _sSourceType, int _nResolution )112cdf0e10cSrcweir     public static void writeToDB(String _sFilename,
113cdf0e10cSrcweir                                  String _sBasename,
114cdf0e10cSrcweir                                  String _sFileFormat,
115cdf0e10cSrcweir                                  String _sBuildID,
116cdf0e10cSrcweir                                  String _sSourceType,
117cdf0e10cSrcweir                                  int _nResolution )
118cdf0e10cSrcweir         {
119cdf0e10cSrcweir             GlobalLogWriter.get().println("DB:   Filename:" + _sFilename);
120cdf0e10cSrcweir             GlobalLogWriter.get().println("DB:   Basename:" + _sBasename);
121cdf0e10cSrcweir             GlobalLogWriter.get().println("DB: FileFormat:" + _sFileFormat);
122cdf0e10cSrcweir             GlobalLogWriter.get().println("DB:    BuildID:" + _sBuildID);
123cdf0e10cSrcweir             GlobalLogWriter.get().println("DB: SourceType:" + _sSourceType);
124cdf0e10cSrcweir             GlobalLogWriter.get().println("DB: Resolution:" + _nResolution);
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
getEnvironment()127cdf0e10cSrcweir     private String getEnvironment()
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             if (OSHelper.isWindows())
130cdf0e10cSrcweir             {
131cdf0e10cSrcweir                 return "wntmsci";
132cdf0e10cSrcweir             }
133cdf0e10cSrcweir             else if ( OSHelper.isSolarisIntel())
134cdf0e10cSrcweir             {
135cdf0e10cSrcweir                 return "unxsoli";
136cdf0e10cSrcweir             }
137cdf0e10cSrcweir             else if ( OSHelper.isSolarisSparc())
138cdf0e10cSrcweir             {
139cdf0e10cSrcweir                 return "unxsols";
140cdf0e10cSrcweir             }
141cdf0e10cSrcweir             else if ( OSHelper.isLinuxIntel())
142cdf0e10cSrcweir             {
143cdf0e10cSrcweir                 return "unxlngi";
144cdf0e10cSrcweir             }
145cdf0e10cSrcweir             else
146cdf0e10cSrcweir             {
147cdf0e10cSrcweir                 GlobalLogWriter.get().println("DB: Unknown environment.");
148cdf0e10cSrcweir                 GlobalLogWriter.get().println("DB: os.name := " + System.getProperty("os.name").toLowerCase());
149cdf0e10cSrcweir                 GlobalLogWriter.get().println("DB: os.arch := " + System.getProperty("os.arch"));
150cdf0e10cSrcweir                 return "";
151cdf0e10cSrcweir             }
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     // fill some db access important variables with values given out of a simple string
155cdf0e10cSrcweir     // DOC_COMPARATOR_DB_INFO_STRING=p:m220,c:m224,d:demo_lla,src:m220,dest:m224,doc:demo_lla,id:294,distinct:81
156cdf0e10cSrcweir 
fillVariables(String _sInfo)157cdf0e10cSrcweir     private void fillVariables(String _sInfo)
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             fillDBConnection(_sInfo);
160cdf0e10cSrcweir             m_sEnvironment = getEnvironment();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir             StringTokenizer aTokenizer = new StringTokenizer(_sInfo,",",false);
163cdf0e10cSrcweir             while (aTokenizer.hasMoreTokens())
164cdf0e10cSrcweir             {
165cdf0e10cSrcweir                 String sPart = aTokenizer.nextToken();
166cdf0e10cSrcweir                 if (sPart.startsWith("p:"))
167cdf0e10cSrcweir                 {
168cdf0e10cSrcweir                     m_sSourceVersion = sPart.substring(2);
169cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
170cdf0e10cSrcweir                 }
171cdf0e10cSrcweir                 else if (sPart.startsWith("src:"))
172cdf0e10cSrcweir                 {
173cdf0e10cSrcweir                     m_sSourceVersion = sPart.substring(4);
174cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
175cdf0e10cSrcweir                 }
176cdf0e10cSrcweir                 else if (sPart.startsWith("c:"))
177cdf0e10cSrcweir                 {
178cdf0e10cSrcweir                     m_sDestinationVersion = sPart.substring(2);
179cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: destination version: " + m_sDestinationVersion);
180cdf0e10cSrcweir                 }
181cdf0e10cSrcweir                 else if (sPart.startsWith("dest:"))
182cdf0e10cSrcweir                 {
183cdf0e10cSrcweir                     m_sDestinationVersion = sPart.substring(5);
184cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: destination version: " + m_sDestinationVersion);
185cdf0e10cSrcweir                 }
186cdf0e10cSrcweir                 else if (sPart.startsWith("d:"))
187cdf0e10cSrcweir                 {
188cdf0e10cSrcweir                     m_sDocumentPool = sPart.substring(2);
189cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: documentpool version: " + m_sDocumentPool);
190cdf0e10cSrcweir                 }
191cdf0e10cSrcweir                 else if (sPart.startsWith("doc:"))
192cdf0e10cSrcweir                 {
193cdf0e10cSrcweir                     m_sDocumentPool = sPart.substring(4);
194cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: documentpool version: " + m_sDocumentPool);
195cdf0e10cSrcweir                 }
196cdf0e10cSrcweir                 else if (sPart.startsWith("id:"))
197cdf0e10cSrcweir                 {
198cdf0e10cSrcweir                     m_sDocID = sPart.substring(3);
199cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: docid: " + m_sDocID);
200cdf0e10cSrcweir                 }
201cdf0e10cSrcweir                 else if (sPart.startsWith("distinct:"))
202cdf0e10cSrcweir                 {
203cdf0e10cSrcweir                     m_sDBDistinct = sPart.substring(9);
204cdf0e10cSrcweir                     GlobalLogWriter.get().println("DB: distinct: " + m_sDBDistinct);
205cdf0e10cSrcweir                 }
206cdf0e10cSrcweir                 else
207cdf0e10cSrcweir                 {
208cdf0e10cSrcweir                 }
209cdf0e10cSrcweir             }
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     // public static void insertinto_file(String _sFilename,
213cdf0e10cSrcweir     //                                    String _sBasename,
214cdf0e10cSrcweir     //                                    String _sFileFormat,
215cdf0e10cSrcweir     //                                    String _sBuildID,
216cdf0e10cSrcweir     //                                    String _sSourceType,
217cdf0e10cSrcweir     //                                    int _nResolution )
218cdf0e10cSrcweir     //     {
219cdf0e10cSrcweir     //         Connection aCon = new ShareConnection().getConnection();
220cdf0e10cSrcweir     //
221cdf0e10cSrcweir     //         String sFilename = _sFilename.replace('\\', '/');
222cdf0e10cSrcweir     //
223cdf0e10cSrcweir     //         String sDeleteOld = "DELETE FROM file WHERE filename = " + Quote(sFilename);
224cdf0e10cSrcweir     //         ExecSQL(aCon, sDeleteOld);
225cdf0e10cSrcweir     //
226cdf0e10cSrcweir     //         String sValueLine = "type, filename, basename, fileformat, buildid, resolution, date";
227cdf0e10cSrcweir     //         StringBuffer aDataLine = new StringBuffer();
228cdf0e10cSrcweir     //         aDataLine.append( Quote(_sSourceType) ) . append( sComma ) .
229cdf0e10cSrcweir     //             append( Quote( sFilename) )   . append( sComma ) .
230cdf0e10cSrcweir     //             append( Quote( _sBasename) )   . append( sComma ) .
231cdf0e10cSrcweir     //             append( Quote( _sFileFormat) ) . append( sComma ) .
232cdf0e10cSrcweir     //             append( Quote( _sBuildID) )    . append( sComma ) .
233cdf0e10cSrcweir     //             append( _nResolution)    . append( sComma ) .
234cdf0e10cSrcweir     //             append( Quote( today() ) );
235cdf0e10cSrcweir     //
236cdf0e10cSrcweir     //         SQLinsertValues(aCon, "file", sValueLine, aDataLine.toString());
237cdf0e10cSrcweir     //     }
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     // public static void updatestate_currentdocs(String _sFilename,
240cdf0e10cSrcweir     //                                            String _sState)
241cdf0e10cSrcweir     //     {
242cdf0e10cSrcweir     //         Connection aCon = new ShareConnection().getConnection();
243cdf0e10cSrcweir     //
244cdf0e10cSrcweir     //         String sFilename = _sFilename.replace('\\', '/');
245cdf0e10cSrcweir     //
246cdf0e10cSrcweir     //         // String sDeleteOld = "DELETE FROM file WHERE filename = " + Quote(sFilename);
247cdf0e10cSrcweir     //         // ExecSQL(aCon, sDeleteOld);
248cdf0e10cSrcweir     //
249cdf0e10cSrcweir     //         String sSet = "state=" + Quote(_sState);
250cdf0e10cSrcweir     //         String sWhere = getWhereClause() + sAND + "name=" + Quote(sFilename);
251cdf0e10cSrcweir     //         SQLupdateValue( aCon, "currentdocs", sSet, sWhere );
252cdf0e10cSrcweir     //     }
253cdf0e10cSrcweir 
sql_test()254cdf0e10cSrcweir     private void sql_test()
255cdf0e10cSrcweir         {
256cdf0e10cSrcweir             String sUUID = getDBDistinct();
257cdf0e10cSrcweir             System.out.println("UUID: " + sUUID);
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir 
QuerySQL(Connection _aCon, String _sSQL)260cdf0e10cSrcweir     public ArrayList QuerySQL(Connection _aCon, String _sSQL)
261cdf0e10cSrcweir         {
262cdf0e10cSrcweir             java.sql.Statement oStmt = null;
263cdf0e10cSrcweir             Connection oCon = null;
264cdf0e10cSrcweir             ArrayList aResultList = new ArrayList();
265cdf0e10cSrcweir             try
266cdf0e10cSrcweir             {
267cdf0e10cSrcweir                 oStmt = _aCon.createStatement();
268cdf0e10cSrcweir 
269cdf0e10cSrcweir                 java.sql.ResultSet aResultSet = oStmt.executeQuery(_sSQL);
270cdf0e10cSrcweir                 java.sql.ResultSetMetaData aResultSetMetaData = aResultSet.getMetaData();
271cdf0e10cSrcweir 
272cdf0e10cSrcweir                 int nColumnCount = aResultSetMetaData.getColumnCount();         // java sql starts with '1'
273cdf0e10cSrcweir                 // String[] aColumnName = new String[nColumnCount];
274cdf0e10cSrcweir                 // for(int i=1;i<nColumnCount;i++)
275cdf0e10cSrcweir                 // {
276cdf0e10cSrcweir                 //     String aColumnName[i - 1] = aResultSetMetaData.getColumnName(i);
277cdf0e10cSrcweir                 // }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir                 while( aResultSet.next() )
280cdf0e10cSrcweir                 {
281cdf0e10cSrcweir                     StringBuffer aResult = new StringBuffer();
282cdf0e10cSrcweir                     try
283cdf0e10cSrcweir                     {
284cdf0e10cSrcweir                         Object aObj = null;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 
287cdf0e10cSrcweir                         aResult.append("sqlresult: ");
288cdf0e10cSrcweir                         for (int i=1;i<=nColumnCount;i++)
289cdf0e10cSrcweir                         {
290cdf0e10cSrcweir                             String sColumnName = aResultSetMetaData.getColumnName(i);
291cdf0e10cSrcweir                             aResult.append(sColumnName).append("=");
292cdf0e10cSrcweir                             String sValue;
293cdf0e10cSrcweir                             int nSQLType = aResultSetMetaData.getColumnType(i);
294cdf0e10cSrcweir                             switch(nSQLType)
295cdf0e10cSrcweir                             {
296cdf0e10cSrcweir                             case java.sql.Types.VARCHAR:
297cdf0e10cSrcweir                                 sValue = "'" + aResultSet.getString(i)  +  "'";
298cdf0e10cSrcweir                                 break;
299cdf0e10cSrcweir                             case java.sql.Types.INTEGER:
300cdf0e10cSrcweir                             {
301cdf0e10cSrcweir                                 int nValue = aResultSet.getInt(i);
302cdf0e10cSrcweir                                 sValue = String.valueOf(nValue);
303cdf0e10cSrcweir                                 break;
304cdf0e10cSrcweir                             }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir                             default:
307cdf0e10cSrcweir                                 sValue = "UNSUPPORTED TYPE";
308cdf0e10cSrcweir                             }
309cdf0e10cSrcweir                             aResult.append(sValue).append(", ");
310cdf0e10cSrcweir                             // String sName = aObj.getClass().getName();
311cdf0e10cSrcweir                             // System.out.println("sqlresult: Class name: " + sName);
312cdf0e10cSrcweir                         }
313cdf0e10cSrcweir                         String sResult = aResult.toString();
314cdf0e10cSrcweir                         aResultList.add(sResult);
315cdf0e10cSrcweir                         // System.out.println(sResult);
316cdf0e10cSrcweir                     }
317cdf0e10cSrcweir                     catch (java.sql.SQLException e)
318cdf0e10cSrcweir                     {
319cdf0e10cSrcweir                     }
320cdf0e10cSrcweir                 }
321cdf0e10cSrcweir             }
322cdf0e10cSrcweir             catch (java.sql.SQLException e)
323cdf0e10cSrcweir             {
324cdf0e10cSrcweir                 String sError = e.getMessage();
325cdf0e10cSrcweir                 GlobalLogWriter.get().println("DB: Original SQL error: " + sError);
326cdf0e10cSrcweir                 // throw new ValueNotFoundException("Cant execute SQL: " + _sSQL);
327cdf0e10cSrcweir             }
328cdf0e10cSrcweir             return aResultList;
329cdf0e10cSrcweir         }
330cdf0e10cSrcweir 
updatestate_status(String _sStatus)331cdf0e10cSrcweir     private void updatestate_status(String _sStatus)
332cdf0e10cSrcweir         {
333cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
334cdf0e10cSrcweir 
335cdf0e10cSrcweir             // String sInfo = _sInfo.replace('\\', '/');
336cdf0e10cSrcweir 
337cdf0e10cSrcweir             // String sDeleteOld = "DELETE FROM file WHERE filename = " + Quote(sFilename);
338cdf0e10cSrcweir             // ExecSQL(aCon, sDeleteOld);
339cdf0e10cSrcweir 
340cdf0e10cSrcweir             String sSet = "state=" + Quote(_sStatus);
341cdf0e10cSrcweir             String sWhere = getWhereClause();
342cdf0e10cSrcweir             if (sWhere.length() > 0)
343cdf0e10cSrcweir             {
344cdf0e10cSrcweir             SQLupdateValue( aCon, "status", sSet, sWhere );
345cdf0e10cSrcweir         }
346cdf0e10cSrcweir         }
updateinfo_status(String _sInfo)347cdf0e10cSrcweir     private void updateinfo_status(String _sInfo)
348cdf0e10cSrcweir         {
349cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
350cdf0e10cSrcweir 
351cdf0e10cSrcweir             // String sInfo = _sInfo.replace('\\', '/');
352cdf0e10cSrcweir 
353cdf0e10cSrcweir             // String sDeleteOld = "DELETE FROM file WHERE filename = " + Quote(sFilename);
354cdf0e10cSrcweir             // ExecSQL(aCon, sDeleteOld);
355cdf0e10cSrcweir 
356cdf0e10cSrcweir             String sSet = "info=" + Quote(_sInfo);
357cdf0e10cSrcweir             String sWhere = getWhereClause();
358cdf0e10cSrcweir             SQLupdateValue( aCon, "status", sSet, sWhere );
359cdf0e10cSrcweir         }
updateerrorfile_status(String _sErrorFile)360cdf0e10cSrcweir     private void updateerrorfile_status(String _sErrorFile)
361cdf0e10cSrcweir         {
362cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
363cdf0e10cSrcweir 
364cdf0e10cSrcweir             String sErrorFile = _sErrorFile.replace('\\', '/');
365cdf0e10cSrcweir 
366cdf0e10cSrcweir             String sSet = "errorfile=" + Quote(sErrorFile);
367cdf0e10cSrcweir             String sWhere = getWhereClause();
368cdf0e10cSrcweir             SQLupdateValue( aCon, "status", sSet, sWhere );
369cdf0e10cSrcweir         }
updatehtmlfile_status(String _sHtmlFile)370cdf0e10cSrcweir     private void updatehtmlfile_status(String _sHtmlFile)
371cdf0e10cSrcweir         {
372cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
373cdf0e10cSrcweir 
374cdf0e10cSrcweir             String sHtmlFile = _sHtmlFile.replace('\\', '/');
375cdf0e10cSrcweir 
376cdf0e10cSrcweir             String sSet = "htmlfile=" + Quote(sHtmlFile);
377cdf0e10cSrcweir             String sWhere = getWhereClause();
378cdf0e10cSrcweir             SQLupdateValue( aCon, "status", sSet, sWhere );
379cdf0e10cSrcweir         }
updatepagecount_documents(int _nPageCount)380cdf0e10cSrcweir     private void updatepagecount_documents(int _nPageCount)
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir             String sSet = "pagecount=" + _nPageCount;
385cdf0e10cSrcweir             String sWhere = getWhereClause();
386cdf0e10cSrcweir             SQLupdateValue( aCon, "documents", sSet, sWhere );
387cdf0e10cSrcweir 
388cdf0e10cSrcweir         }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
getWhereClause()391cdf0e10cSrcweir     private String getWhereClause()
392cdf0e10cSrcweir         {
393cdf0e10cSrcweir             StringBuffer aWhereClause = new StringBuffer();
394cdf0e10cSrcweir             // WHERE environment='' and referenceversion='' and currentversion='' and documentpool=''
395cdf0e10cSrcweir             // aWhere.append( "environment" ). append(sEqual) . append(Quote(m_sEnvironment)) .
396cdf0e10cSrcweir             //     append(sAND) .
397cdf0e10cSrcweir             //     append( "referenceversion" ). append(sEqual) . append(Quote(m_sSourceVersion)) .
398cdf0e10cSrcweir             //     append(sAND) .
399cdf0e10cSrcweir             //     append( "currentversion" ). append(sEqual) . append(Quote(m_sDestinationVersion)) .
400cdf0e10cSrcweir             //     append(sAND) .
401cdf0e10cSrcweir             //     append( "documentpool" ). append(sEqual) . append(Quote(m_sDocumentPool));
402cdf0e10cSrcweir             boolean bAND = false;
403cdf0e10cSrcweir             if (m_sDocID != null)
404cdf0e10cSrcweir             {
405cdf0e10cSrcweir                 aWhereClause.append( "docid" ). append(sEqual) . append(m_sDocID);
406cdf0e10cSrcweir                 bAND = true;
407cdf0e10cSrcweir             }
408cdf0e10cSrcweir             if (bAND)
409cdf0e10cSrcweir             {
410cdf0e10cSrcweir                 aWhereClause.append(sAND);
411cdf0e10cSrcweir             }
412cdf0e10cSrcweir             if (m_sDBDistinct != null)
413cdf0e10cSrcweir             {
414cdf0e10cSrcweir                 aWhereClause.append( "dbdistinct2" ). append(sEqual) . append(Quote(m_sDBDistinct));
415cdf0e10cSrcweir             }
416cdf0e10cSrcweir             return aWhereClause.toString();
417cdf0e10cSrcweir         }
418cdf0e10cSrcweir 
getDBDistinct()419cdf0e10cSrcweir     private String getDBDistinct()
420cdf0e10cSrcweir         {
421cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
422cdf0e10cSrcweir 
423cdf0e10cSrcweir             String sSQL = "SELECT uuid()";
424cdf0e10cSrcweir             ArrayList aResultList = QuerySQL(aCon, sSQL);
425cdf0e10cSrcweir 
426cdf0e10cSrcweir             for (int i=0;i<aResultList.size();i++)
427cdf0e10cSrcweir             {
428cdf0e10cSrcweir                 String sResult = (String)aResultList.get(i);
429cdf0e10cSrcweir 
430cdf0e10cSrcweir                 StringTokenizer aTokenizer = new StringTokenizer(sResult,",",false);
431cdf0e10cSrcweir                 while (aTokenizer.hasMoreTokens())
432cdf0e10cSrcweir                 {
433cdf0e10cSrcweir                     String sToken = aTokenizer.nextToken();
434cdf0e10cSrcweir                     // System.out.println("PART: " + sToken);
435cdf0e10cSrcweir                     int nIndex = sToken.indexOf("uuid()=");
436cdf0e10cSrcweir                     // System.out.println("Index " + nIndex);
437cdf0e10cSrcweir                     int nIndexTuettel = sToken.indexOf("'", nIndex);
438cdf0e10cSrcweir                     // System.out.println("IndexTuettel " + nIndexTuettel);
439cdf0e10cSrcweir                     int nIndexTuettel2 = sToken.lastIndexOf("'");
440cdf0e10cSrcweir                     // System.out.println("IndexTuettel2 " + nIndexTuettel2);
441cdf0e10cSrcweir                     String sUuid = sToken.substring(nIndexTuettel + 1, nIndexTuettel2);
442cdf0e10cSrcweir                     // if (sPart.startsWith("p:"))
443cdf0e10cSrcweir                     // {
444cdf0e10cSrcweir                         // m_sSourceVersion = sPart.substring(2);
445cdf0e10cSrcweir                         // GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
446cdf0e10cSrcweir                     // }
447cdf0e10cSrcweir                     return sUuid;
448cdf0e10cSrcweir                 }
449cdf0e10cSrcweir                 // System.out.println(sResult);
450cdf0e10cSrcweir             }
451cdf0e10cSrcweir 
452cdf0e10cSrcweir             return "0";
453cdf0e10cSrcweir         }
454cdf0e10cSrcweir 
insertinto_documentcompare(String _sSourceVersion, String _sSourceName, String _sSourceCreatorType, String _sDestinationVersion, String _sDestinationName, String _sDestinationCreatorType, String _sDocumentPoolDir, String _sDocumentPoolName, String _sMailAddress, String _sSpecial, String _sParentDistinct)455cdf0e10cSrcweir     public static void insertinto_documentcompare(String _sSourceVersion, String _sSourceName, String _sSourceCreatorType,
456cdf0e10cSrcweir                                                   String _sDestinationVersion, String _sDestinationName, String _sDestinationCreatorType,
457cdf0e10cSrcweir                                                   String _sDocumentPoolDir, String _sDocumentPoolName, String _sMailAddress,
458cdf0e10cSrcweir                                                   String _sSpecial, String _sParentDistinct)
459cdf0e10cSrcweir         {
460cdf0e10cSrcweir             getDB().insertinto_documentcompare_impl(  _sSourceVersion,   _sSourceName,   _sSourceCreatorType,
461cdf0e10cSrcweir                                                       _sDestinationVersion,   _sDestinationName,   _sDestinationCreatorType,
462cdf0e10cSrcweir                                                       _sDocumentPoolDir,   _sDocumentPoolName,   _sMailAddress,
463cdf0e10cSrcweir                                                       _sSpecial, _sParentDistinct);
464cdf0e10cSrcweir         }
465cdf0e10cSrcweir 
insertinto_documentcompare_impl(String _sSourceVersion, String _sSourceName, String _sSourceCreatorType, String _sDestinationVersion, String _sDestinationName, String _sDestinationCreatorType, String _sDocumentPoolDir, String _sDocumentPoolName, String _sMailAddress, String _sSpecial, String _sParentDistinct)466cdf0e10cSrcweir     private void insertinto_documentcompare_impl(String _sSourceVersion, String _sSourceName, String _sSourceCreatorType,
467cdf0e10cSrcweir                                                  String _sDestinationVersion, String _sDestinationName, String _sDestinationCreatorType,
468cdf0e10cSrcweir                                                  String _sDocumentPoolDir, String _sDocumentPoolName, String _sMailAddress,
469cdf0e10cSrcweir                                                  String _sSpecial, String _sParentDistinct)
470cdf0e10cSrcweir         {
471cdf0e10cSrcweir             // $sSQLInsert = "INSERT INTO documentcompare
472cdf0e10cSrcweir             if (_sParentDistinct == null)
473cdf0e10cSrcweir             {
474cdf0e10cSrcweir                 _sParentDistinct = "";
475cdf0e10cSrcweir             }
476cdf0e10cSrcweir 
477cdf0e10cSrcweir             Connection aCon = new ShareConnection().getConnection();
478cdf0e10cSrcweir 
479cdf0e10cSrcweir             String sValueLine="dbdistinct2, environment, sourceversion, sourcename, sourcecreatortype, destinationversion, destinationname, destinationcreatortype, documentpoolpath, documentpool, mailfeedback, state, special, parentdistinct, startdate";
480cdf0e10cSrcweir             String sDocumentPoolDir = _sDocumentPoolDir.replace('\\', '/');
481cdf0e10cSrcweir             StringBuffer aDataLine = new StringBuffer();
482cdf0e10cSrcweir             aDataLine.append( Quote(getDBDistinct()) ) . append( sComma ) .
483cdf0e10cSrcweir                 append( Quote( getEnvironment()) ) . append( sComma ) .
484cdf0e10cSrcweir                 append( Quote( _sSourceVersion) )   . append( sComma ) .
485cdf0e10cSrcweir                 append( Quote( _sSourceName) )   . append( sComma ) .
486cdf0e10cSrcweir                 append( Quote( _sSourceCreatorType ) )   . append( sComma ) .
487cdf0e10cSrcweir                 append( Quote( _sDestinationVersion) )   . append( sComma ) .
488cdf0e10cSrcweir                 append( Quote( _sDestinationName) )   . append( sComma ) .
489cdf0e10cSrcweir                 append( Quote( _sDestinationCreatorType ) )   . append( sComma ) .
490cdf0e10cSrcweir                 append( Quote( sDocumentPoolDir) ) . append( sComma ) .
491cdf0e10cSrcweir                 append( Quote( _sDocumentPoolName) ) . append( sComma ) .
492cdf0e10cSrcweir                 append( Quote( _sMailAddress) )    . append( sComma ) .
493cdf0e10cSrcweir                 append( Quote( "new" )) . append ( sComma ) .
494cdf0e10cSrcweir                 append( Quote( _sSpecial ) )    . append( sComma ) .
495cdf0e10cSrcweir                 append( Quote( _sParentDistinct ) )    . append( sComma ) .
496cdf0e10cSrcweir                 append( Quote( today() ));
497cdf0e10cSrcweir 
498cdf0e10cSrcweir             SQLinsertValues(aCon, "documentcompare", sValueLine, aDataLine.toString());
499cdf0e10cSrcweir         }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir     // public static void filesRemove(String _sDBInfoString)
502cdf0e10cSrcweir     //     {
503cdf0e10cSrcweir     //         if (_sDBInfoString == null) return;
504cdf0e10cSrcweir     //         fillVariables(_sDBInfoString);
505cdf0e10cSrcweir     //
506cdf0e10cSrcweir     //         Connection aCon = new ShareConnection().getConnection();
507cdf0e10cSrcweir     //
508cdf0e10cSrcweir     //         String sDeleteSQL = "DELETE FROM currentdocs WHERE " + getWhereClause();
509cdf0e10cSrcweir     //
510cdf0e10cSrcweir     //         ExecSQL(aCon, sDeleteSQL);
511cdf0e10cSrcweir     //     }
512cdf0e10cSrcweir     //
513cdf0e10cSrcweir     // public static void fileInsert(String _sDBInfoString,
514cdf0e10cSrcweir     //                               String _sFilename,
515cdf0e10cSrcweir     //                               String _sRemovePath)
516cdf0e10cSrcweir     //     {
517cdf0e10cSrcweir     //         if (_sDBInfoString == null) return;
518cdf0e10cSrcweir     //         fillVariables(_sDBInfoString);
519cdf0e10cSrcweir     //
520cdf0e10cSrcweir     //         String sFilename = _sFilename.replace('\\', '/');
521cdf0e10cSrcweir     //
522cdf0e10cSrcweir     //         Connection aCon = new ShareConnection().getConnection();
523cdf0e10cSrcweir     //
524cdf0e10cSrcweir     //         String sValueLine = "environment, referenceversion, currentversion, documentpool, name, state";
525cdf0e10cSrcweir     //         StringBuffer aDataLine = new StringBuffer();
526cdf0e10cSrcweir     //         aDataLine.append( Quote(m_sEnvironment) ) . append( sComma ) .
527cdf0e10cSrcweir     //             append( Quote( m_sSourceVersion) )   . append( sComma ) .
528cdf0e10cSrcweir     //             append( Quote( m_sDestinationVersion) )   . append( sComma ) .
529cdf0e10cSrcweir     //             append( Quote( m_sDocumentPool) ) . append( sComma ) .
530cdf0e10cSrcweir     //             append( Quote( sFilename) )    . append( sComma ) .
531cdf0e10cSrcweir     //             append( Quote( "undone"));
532cdf0e10cSrcweir     //
533cdf0e10cSrcweir     //         SQLinsertValues(aCon, "currentdocs", sValueLine, aDataLine.toString());
534cdf0e10cSrcweir     //     }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 
537cdf0e10cSrcweir     // public static void insertinto_file(String _sFilename, String _sFileFormat, String _sBuildID)
538cdf0e10cSrcweir     //     {
539cdf0e10cSrcweir     //         Connection aCon = new ShareConnection().getConnection();
540cdf0e10cSrcweir     //
541cdf0e10cSrcweir     //         String sValueLine = "type, filename, fileformat, buildid, date";
542cdf0e10cSrcweir     //         StringBuffer aDataLine = new StringBuffer();
543cdf0e10cSrcweir     //         aDataLine.append( "1" )            . append( sComma ) .
544cdf0e10cSrcweir     //             append( Quote( _sFilename) )   . append( sComma ) .
545cdf0e10cSrcweir     //             append( Quote( _sFileFormat) ) . append( sComma ) .
546cdf0e10cSrcweir     //             append( Quote( _sBuildID) )    . append( sComma ) .
547cdf0e10cSrcweir     //             append( Quote( today() ) );
548cdf0e10cSrcweir     //
549cdf0e10cSrcweir     //         SQLinsertValues(aCon, "file", sValueLine, aDataLine.toString());
550cdf0e10cSrcweir     //     }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     // public static void main( String[] args )
553cdf0e10cSrcweir     //     {
554cdf0e10cSrcweir     //
555cdf0e10cSrcweir     //         String _sFilename = "";
556cdf0e10cSrcweir     //         String _sFileFormat = "";
557cdf0e10cSrcweir     //         String _sBuildID = "";
558cdf0e10cSrcweir     //
559cdf0e10cSrcweir     //         // insertinto_file("c:\temp\test.txt", "test", "txt", "nix", "", 0);
560cdf0e10cSrcweir     //         fillVariables("p:m128,c:m134,d:demo");
561cdf0e10cSrcweir     //     }
562cdf0e10cSrcweir }
563