Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / qadevOOo / runner / convwatch / DB.java
bloba9b2f70763c2111b54f2172c2b8bb06caf69e2bf
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package convwatch;
21 import java.sql.Connection;
22 import java.util.StringTokenizer;
23 import helper.OSHelper;
25 public class DB extends DBHelper
27 private static DB m_aDB = null;
29 // private ctor
30 private DB()
34 private static synchronized DB getDB()
36 if (m_aDB == null)
38 m_aDB = new DB();
40 return m_aDB;
43 private String m_sSourceVersion;
44 private String m_sDestinationVersion;
45 private String m_sDocumentPool;
46 private String m_sDocID;
47 private String m_sDBDistinct;
49 public static void init(String _sDBInfoString)
51 if (_sDBInfoString == null) return;
52 getDB().fillVariables(_sDBInfoString);
53 getDB().updatestate_status("source started");
56 private String getEnvironment()
58 if (OSHelper.isWindows())
60 return "wntmsci";
62 else if ( OSHelper.isSolarisIntel())
64 return "unxsoli";
66 else if ( OSHelper.isSolarisSparc())
68 return "unxsols";
70 else if ( OSHelper.isLinuxIntel())
72 return "unxlngi";
74 else
76 GlobalLogWriter.get().println("DB: Unknown environment.");
77 GlobalLogWriter.get().println("DB: os.name := " + System.getProperty("os.name").toLowerCase());
78 GlobalLogWriter.get().println("DB: os.arch := " + System.getProperty("os.arch"));
79 return "";
83 // fill some db access important variables with values given out of a simple string
84 // DOC_COMPARATOR_DB_INFO_STRING=p:m220,c:m224,d:demo_lla,src:m220,dest:m224,doc:demo_lla,id:294,distinct:81
86 private void fillVariables(String _sInfo)
88 fillDBConnection(_sInfo);
89 getEnvironment();
91 StringTokenizer aTokenizer = new StringTokenizer(_sInfo,",",false);
92 while (aTokenizer.hasMoreTokens())
94 String sPart = aTokenizer.nextToken();
95 if (sPart.startsWith("p:"))
97 m_sSourceVersion = sPart.substring(2);
98 GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
100 else if (sPart.startsWith("src:"))
102 m_sSourceVersion = sPart.substring(4);
103 GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
105 else if (sPart.startsWith("c:"))
107 m_sDestinationVersion = sPart.substring(2);
108 GlobalLogWriter.get().println("DB: destination version: " + m_sDestinationVersion);
110 else if (sPart.startsWith("dest:"))
112 m_sDestinationVersion = sPart.substring(5);
113 GlobalLogWriter.get().println("DB: destination version: " + m_sDestinationVersion);
115 else if (sPart.startsWith("d:"))
117 m_sDocumentPool = sPart.substring(2);
118 GlobalLogWriter.get().println("DB: documentpool version: " + m_sDocumentPool);
120 else if (sPart.startsWith("doc:"))
122 m_sDocumentPool = sPart.substring(4);
123 GlobalLogWriter.get().println("DB: documentpool version: " + m_sDocumentPool);
125 else if (sPart.startsWith("id:"))
127 m_sDocID = sPart.substring(3);
128 GlobalLogWriter.get().println("DB: docid: " + m_sDocID);
130 else if (sPart.startsWith("distinct:"))
132 m_sDBDistinct = sPart.substring(9);
133 GlobalLogWriter.get().println("DB: distinct: " + m_sDBDistinct);
135 else
141 private void updatestate_status(String _sStatus)
143 Connection aCon = new ShareConnection().getConnection();
145 String sSet = "state=" + Quote(_sStatus);
146 String sWhere = getWhereClause();
147 if (sWhere.length() > 0)
149 SQLupdateValue( aCon, "status", sSet, sWhere );
154 private String getWhereClause()
156 StringBuffer aWhereClause = new StringBuffer();
157 boolean bAND = false;
158 if (m_sDocID != null)
160 aWhereClause.append( "docid" ). append(sEqual) . append(m_sDocID);
161 bAND = true;
163 if (bAND)
165 aWhereClause.append(sAND);
167 if (m_sDBDistinct != null)
169 aWhereClause.append( "dbdistinct2" ). append(sEqual) . append(Quote(m_sDBDistinct));
171 return aWhereClause.toString();