summaryrefslogtreecommitdiffstats
path: root/qadevOOo/runner/convwatch
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /qadevOOo/runner/convwatch
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qadevOOo/runner/convwatch')
-rw-r--r--qadevOOo/runner/convwatch/DB.java174
-rw-r--r--qadevOOo/runner/convwatch/DBHelper.java190
-rw-r--r--qadevOOo/runner/convwatch/GlobalLogWriter.java38
3 files changed, 402 insertions, 0 deletions
diff --git a/qadevOOo/runner/convwatch/DB.java b/qadevOOo/runner/convwatch/DB.java
new file mode 100644
index 000000000..a9b2f7076
--- /dev/null
+++ b/qadevOOo/runner/convwatch/DB.java
@@ -0,0 +1,174 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package convwatch;
+
+import java.sql.Connection;
+import java.util.StringTokenizer;
+import helper.OSHelper;
+
+public class DB extends DBHelper
+{
+ private static DB m_aDB = null;
+
+ // private ctor
+ private DB()
+ {
+ }
+
+ private static synchronized DB getDB()
+ {
+ if (m_aDB == null)
+ {
+ m_aDB = new DB();
+ }
+ return m_aDB;
+ }
+
+ private String m_sSourceVersion;
+ private String m_sDestinationVersion;
+ private String m_sDocumentPool;
+ private String m_sDocID;
+ private String m_sDBDistinct;
+
+ public static void init(String _sDBInfoString)
+ {
+ if (_sDBInfoString == null) return;
+ getDB().fillVariables(_sDBInfoString);
+ getDB().updatestate_status("source started");
+ }
+
+ private String getEnvironment()
+ {
+ if (OSHelper.isWindows())
+ {
+ return "wntmsci";
+ }
+ else if ( OSHelper.isSolarisIntel())
+ {
+ return "unxsoli";
+ }
+ else if ( OSHelper.isSolarisSparc())
+ {
+ return "unxsols";
+ }
+ else if ( OSHelper.isLinuxIntel())
+ {
+ return "unxlngi";
+ }
+ else
+ {
+ GlobalLogWriter.get().println("DB: Unknown environment.");
+ GlobalLogWriter.get().println("DB: os.name := " + System.getProperty("os.name").toLowerCase());
+ GlobalLogWriter.get().println("DB: os.arch := " + System.getProperty("os.arch"));
+ return "";
+ }
+ }
+
+ // fill some db access important variables with values given out of a simple string
+ // DOC_COMPARATOR_DB_INFO_STRING=p:m220,c:m224,d:demo_lla,src:m220,dest:m224,doc:demo_lla,id:294,distinct:81
+
+ private void fillVariables(String _sInfo)
+ {
+ fillDBConnection(_sInfo);
+ getEnvironment();
+
+ StringTokenizer aTokenizer = new StringTokenizer(_sInfo,",",false);
+ while (aTokenizer.hasMoreTokens())
+ {
+ String sPart = aTokenizer.nextToken();
+ if (sPart.startsWith("p:"))
+ {
+ m_sSourceVersion = sPart.substring(2);
+ GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
+ }
+ else if (sPart.startsWith("src:"))
+ {
+ m_sSourceVersion = sPart.substring(4);
+ GlobalLogWriter.get().println("DB: source version: " + m_sSourceVersion);
+ }
+ else if (sPart.startsWith("c:"))
+ {
+ m_sDestinationVersion = sPart.substring(2);
+ GlobalLogWriter.get().println("DB: destination version: " + m_sDestinationVersion);
+ }
+ else if (sPart.startsWith("dest:"))
+ {
+ m_sDestinationVersion = sPart.substring(5);
+ GlobalLogWriter.get().println("DB: destination version: " + m_sDestinationVersion);
+ }
+ else if (sPart.startsWith("d:"))
+ {
+ m_sDocumentPool = sPart.substring(2);
+ GlobalLogWriter.get().println("DB: documentpool version: " + m_sDocumentPool);
+ }
+ else if (sPart.startsWith("doc:"))
+ {
+ m_sDocumentPool = sPart.substring(4);
+ GlobalLogWriter.get().println("DB: documentpool version: " + m_sDocumentPool);
+ }
+ else if (sPart.startsWith("id:"))
+ {
+ m_sDocID = sPart.substring(3);
+ GlobalLogWriter.get().println("DB: docid: " + m_sDocID);
+ }
+ else if (sPart.startsWith("distinct:"))
+ {
+ m_sDBDistinct = sPart.substring(9);
+ GlobalLogWriter.get().println("DB: distinct: " + m_sDBDistinct);
+ }
+ else
+ {
+ }
+ }
+ }
+
+ private void updatestate_status(String _sStatus)
+ {
+ Connection aCon = new ShareConnection().getConnection();
+
+ String sSet = "state=" + Quote(_sStatus);
+ String sWhere = getWhereClause();
+ if (sWhere.length() > 0)
+ {
+ SQLupdateValue( aCon, "status", sSet, sWhere );
+ }
+ }
+
+
+ private String getWhereClause()
+ {
+ StringBuffer aWhereClause = new StringBuffer();
+ boolean bAND = false;
+ if (m_sDocID != null)
+ {
+ aWhereClause.append( "docid" ). append(sEqual) . append(m_sDocID);
+ bAND = true;
+ }
+ if (bAND)
+ {
+ aWhereClause.append(sAND);
+ }
+ if (m_sDBDistinct != null)
+ {
+ aWhereClause.append( "dbdistinct2" ). append(sEqual) . append(Quote(m_sDBDistinct));
+ }
+ return aWhereClause.toString();
+ }
+
+}
diff --git a/qadevOOo/runner/convwatch/DBHelper.java b/qadevOOo/runner/convwatch/DBHelper.java
new file mode 100644
index 000000000..34e1e1cfd
--- /dev/null
+++ b/qadevOOo/runner/convwatch/DBHelper.java
@@ -0,0 +1,190 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package convwatch;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.sql.SQLException;
+
+import java.util.StringTokenizer;
+
+class ShareConnection
+{
+ private Connection m_aConnection = null;
+
+ public Connection getConnection()
+ {
+ if (m_aConnection == null)
+ {
+ try
+ {
+ m_aConnection = DBHelper.getMySQLConnection();
+ }
+ catch(java.sql.SQLException e)
+ {
+ GlobalLogWriter.get().println("DB: ERROR: can't connect to DB.");
+ m_aConnection = null;
+ }
+ }
+ return m_aConnection;
+ }
+}
+
+ class MySQLThread extends Thread
+ {
+ private final Connection m_aCon;
+ private final String m_sSQL;
+ public MySQLThread(Connection _aCon, String _sSQL)
+ {
+ m_aCon = _aCon;
+ m_sSQL = _sSQL;
+ }
+
+ @Override
+ public void run()
+ {
+ Statement oStmt = null;
+ if (m_aCon == null)
+ {
+ GlobalLogWriter.get().println("DB: ERROR: in ExecSQL, connection not established.");
+ return;
+ }
+
+ try
+ {
+ try
+ {
+ oStmt = m_aCon.createStatement();
+
+ GlobalLogWriter.get().println("DB: " + m_sSQL);
+ /* ResultSet oResult = */
+ oStmt.executeUpdate(m_sSQL);
+ }
+ finally
+ {
+ if (oStmt != null)
+ oStmt.close();
+ }
+ }
+ catch(Exception e)
+ {
+ GlobalLogWriter.get().println("DB: Couldn't execute sql string '" + m_sSQL + "'");
+ GlobalLogWriter.get().println("DB: Reason: " + e.getMessage());
+ }
+ }
+ }
+
+public class DBHelper
+{
+ public void SQLupdateValue(Connection _aCon, String _sTableName, String _sSet, String _sWhere)
+ {
+ if (_aCon == null)
+ {
+ GlobalLogWriter.get().println("DB: ERROR: in SQLinsertValues, connection not established.");
+ return;
+ }
+
+ StringBuffer aUpdateStr = new StringBuffer();
+
+ aUpdateStr.append( "UPDATE " ).append( _sTableName )
+ .append( " SET " ).append( _sSet )
+ .append( " WHERE " ).append( _sWhere );
+ ExecSQL( _aCon, aUpdateStr.toString() );
+ }
+
+ private static String m_sDBServerName;
+ private static String m_sDBName;
+ private static String m_sDBUser;
+ private static String m_sDBPasswd;
+
+ protected synchronized void fillDBConnection(String _sInfo)
+ {
+ StringTokenizer aTokenizer = new StringTokenizer(_sInfo,",",false);
+ while (aTokenizer.hasMoreTokens())
+ {
+ String sPart = aTokenizer.nextToken();
+ if (sPart.startsWith("db:"))
+ {
+ m_sDBName = sPart.substring(3);
+ }
+ else if (sPart.startsWith("user:"))
+ {
+ m_sDBUser = sPart.substring(5);
+ }
+ else if (sPart.startsWith("passwd:"))
+ {
+ m_sDBPasswd = sPart.substring(7);
+ }
+ else if (sPart.startsWith("server:"))
+ {
+ m_sDBServerName = sPart.substring(7);
+ }
+ }
+ }
+
+ /**
+ * This method establishes a Connection<br>
+ * with the database 'module_unit' on jakobus
+ */
+
+ public static Connection getMySQLConnection() throws SQLException
+ {
+ try
+ {
+ Class.forName("org.gjt.mm.mysql.Driver");
+ String sConnection = "jdbc:mysql://" + m_sDBServerName + ":3306/" + m_sDBName;
+ // Connection mysql = DriverManager.getConnection(
+ // "jdbc:mysql://jakobus:3306/jobs_convwatch","admin","admin");
+ Connection mysql = DriverManager.getConnection(sConnection, m_sDBUser, m_sDBPasswd);
+ return mysql;
+ }
+ catch (ClassNotFoundException e)
+ {
+ GlobalLogWriter.get().println("DB: Class not found exception caught: " + e.getMessage());
+ GlobalLogWriter.get().println("DB: Maybe mysql.jar is not added to the classpath.");
+ }
+ return null;
+ }
+
+ private synchronized void ExecSQL(Connection _aCon, String _sSQL)
+ {
+ MySQLThread aSQLThread = new MySQLThread(_aCon, _sSQL);
+ aSQLThread.start();
+ }
+
+
+
+ public String Quote(String _sToQuote)
+ {
+ char ts = '\'';
+ char ds = '"';
+ int nQuote = _sToQuote.indexOf(ts);
+ if (nQuote >= 0)
+ {
+ return ds + _sToQuote + ds;
+ }
+ return ts + _sToQuote + ts;
+ }
+
+ public static final String sEqual = "=";
+ public static final String sAND = " AND ";
+
+}
+
diff --git a/qadevOOo/runner/convwatch/GlobalLogWriter.java b/qadevOOo/runner/convwatch/GlobalLogWriter.java
new file mode 100644
index 000000000..f77845e56
--- /dev/null
+++ b/qadevOOo/runner/convwatch/GlobalLogWriter.java
@@ -0,0 +1,38 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package convwatch;
+
+import share.LogWriter;
+import stats.SimpleLogWriter;
+
+public class GlobalLogWriter
+{
+ private static LogWriter m_aGlobalLogWriter = null;
+ public static synchronized LogWriter get()
+ {
+ if (m_aGlobalLogWriter == null)
+ {
+ SimpleLogWriter aLog = new SimpleLogWriter();
+ m_aGlobalLogWriter = aLog;
+ }
+ return m_aGlobalLogWriter;
+ }
+
+}
+