update dev300-m58
[ooovba.git] / qadevOOo / runner / stats / DataBaseOutProducer.java
bloba7f19f6fdbded7833ff9dcccfdc7e7718fca5b4f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DataBaseOutProducer.java,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package stats;
32 import share.LogWriter;
33 import share.DescEntry;
35 import java.util.Hashtable;
37 /**
39 * @author sg128468
41 public abstract class DataBaseOutProducer implements LogWriter {
42 protected Hashtable mSqlInput = null;
43 protected Hashtable mSqlOutput = null;
44 protected String[] mWriteableEntryTypes = null;
45 protected SQLExecution mSqlExec;
46 protected boolean m_bDebug = false;
49 /** Creates a new instance of DataBaseOutProducer
50 * @param param The Hashtable with test parameters
52 public DataBaseOutProducer(Hashtable param) {
53 mSqlInput = new Hashtable();
54 mSqlInput.putAll(param);
56 Object o = param.get("DebugIsActive");
57 String debug = null;
58 if (o instanceof String)
59 debug = (String)o;
60 else
61 debug = o.toString();
62 if (debug != null && (debug.equalsIgnoreCase("true") || debug.equalsIgnoreCase("yes"))) {
63 m_bDebug = true;
65 // set default for writeable entries: method
66 setWriteableEntryTypes(new String[]{"method"});
69 /** initialization
72 public boolean initialize(DescEntry entry, boolean active) {
73 if (entry.UserDefinedParams != null)
74 mSqlInput.putAll(entry.UserDefinedParams);
76 String jdbcClass = (String)mSqlInput.get("JDBC");
77 if (jdbcClass == null)
78 jdbcClass = "org.gjt.mm.mysql.Driver";
79 String dbURL = (String)mSqlInput.get("DataBaseURL");
80 String user = (String)mSqlInput.get("User");
81 String password = (String)mSqlInput.get("Password");
82 if (user == null)
83 user = (String)mSqlInput.get("OperatingSystem");
84 if (password == null)
85 password = user;
87 mSqlExec = new SQLExecution(jdbcClass, dbURL, user, password, m_bDebug);
88 mSqlExec.openConnection();
89 prepareDataBase(entry.Logger);
90 return true;
93 /**
97 public boolean summary(DescEntry entry) {
98 mSqlExec.openConnection();
99 findTypeInEntryTree(entry, entry.Logger);
100 // checkDataBase(entry.Logger);
101 mSqlExec.closeConnection();
102 return true;
106 * Step recursively through the entry tree: write all entries of the
107 * defined types to the database.
108 * @param entry The description entry that is take as root
109 * @param log The log writer
111 protected boolean findTypeInEntryTree(DescEntry entry, LogWriter log) {
112 boolean returnVal = true;
113 if (isWriteableEntryType(entry)) {
114 returnVal &= insertEntry(entry, log);
117 if (entry.SubEntryCount >0) {
118 for (int i=0; i<entry.SubEntryCount; i++) {
119 returnVal &= findTypeInEntryTree(entry.SubEntries[i], log);
122 // if we are not on method leaf, exit here
123 // insert one method result into database
124 return returnVal;
128 * Insert this entrry to the database.
129 * @param entry The entry to write.
130 * @param log The log writer.
132 protected boolean insertEntry(DescEntry entry, LogWriter log) {
133 // copy the swlInput Hashtable, so it can be reset easily for the next run
134 Hashtable copySqlInput = new Hashtable();
135 copySqlInput.putAll(mSqlInput);
136 // put some stuff from entry in the Hashtable
137 mSqlInput.put("EntryLongName", entry.longName);
138 mSqlInput.put("EntryName", entry.entryName);
139 mSqlInput.put("EntryState", entry.State);
140 mSqlInput.put("EntryType", entry.EntryType);
141 boolean result = insertEntry(log);
142 // reset the Hashtable
143 mSqlInput = copySqlInput;
144 return result;
149 * Set the writeable entry types: for example "method", "interface", etc.
150 * All these entries are written to the database.
151 * @param types A String array with all types that have to be written.
153 public void setWriteableEntryTypes(String[] types) {
154 mWriteableEntryTypes = types;
158 * Is the entry of the writeable entry type?
159 * @param entry The entry that is checked
160 * @return True, if it is indeed a writeable entry.
162 protected boolean isWriteableEntryType(DescEntry entry) {
163 boolean result = false;
164 for (int i=0; i<mWriteableEntryTypes.length; i++) {
165 if (entry.EntryType.equals(mWriteableEntryTypes[i])) {
166 result = true;
167 break;
170 return result;
174 * Wrap the command of SQLExecution class for transparency.
176 protected boolean executeSQLCommand(String command, boolean mergeOutput) {
177 return mSqlExec.executeSQLCommand(command, mSqlInput, mSqlOutput, mergeOutput);
181 * Wrap the command of SQLExecution class for transparency.
183 protected boolean executeSQLCommand(String command) {
184 return mSqlExec.executeSQLCommand(command, mSqlInput, mSqlOutput);
188 * Method to print: empty here
190 public void println(String msg) {
194 * Prepare the database: executed once at the beginning.
195 * Abstract method, so derived classes have to overwrite it.
197 protected abstract boolean prepareDataBase(LogWriter log);
200 * Insert one entr into the database.
201 * Abstract method, so derived classes have to overwrite it.
203 protected abstract boolean insertEntry(LogWriter log);
207 protected abstract boolean checkDataBase(LogWriter log);