1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import share
.LogWriter
;
30 import share
.DescEntry
;
32 import java
.util
.Hashtable
;
38 public abstract class DataBaseOutProducer
implements LogWriter
{
39 protected Hashtable mSqlInput
= null;
40 protected Hashtable mSqlOutput
= null;
41 protected String
[] mWriteableEntryTypes
= null;
42 protected SQLExecution mSqlExec
;
43 protected boolean m_bDebug
= false;
46 /** Creates a new instance of DataBaseOutProducer
47 * @param param The Hashtable with test parameters
49 public DataBaseOutProducer(Hashtable param
) {
50 mSqlInput
= new Hashtable();
51 mSqlInput
.putAll(param
);
53 Object o
= param
.get("DebugIsActive");
55 if (o
instanceof String
)
59 if (debug
!= null && (debug
.equalsIgnoreCase("true") || debug
.equalsIgnoreCase("yes"))) {
62 // set default for writeable entries: method
63 setWriteableEntryTypes(new String
[]{"method"});
69 public boolean initialize(DescEntry entry
, boolean active
) {
70 if (entry
.UserDefinedParams
!= null)
71 mSqlInput
.putAll(entry
.UserDefinedParams
);
73 String jdbcClass
= (String
)mSqlInput
.get("JDBC");
74 if (jdbcClass
== null)
75 jdbcClass
= "org.gjt.mm.mysql.Driver";
76 String dbURL
= (String
)mSqlInput
.get("DataBaseURL");
77 String user
= (String
)mSqlInput
.get("User");
78 String password
= (String
)mSqlInput
.get("Password");
80 user
= (String
)mSqlInput
.get("OperatingSystem");
84 mSqlExec
= new SQLExecution(jdbcClass
, dbURL
, user
, password
, m_bDebug
);
85 mSqlExec
.openConnection();
86 prepareDataBase(entry
.Logger
);
94 public boolean summary(DescEntry entry
) {
95 mSqlExec
.openConnection();
96 findTypeInEntryTree(entry
, entry
.Logger
);
97 // checkDataBase(entry.Logger);
98 mSqlExec
.closeConnection();
103 * Step recursively through the entry tree: write all entries of the
104 * defined types to the database.
105 * @param entry The description entry that is take as root
106 * @param log The log writer
108 protected boolean findTypeInEntryTree(DescEntry entry
, LogWriter log
) {
109 boolean returnVal
= true;
110 if (isWriteableEntryType(entry
)) {
111 returnVal
&= insertEntry(entry
, log
);
114 if (entry
.SubEntryCount
>0) {
115 for (int i
=0; i
<entry
.SubEntryCount
; i
++) {
116 returnVal
&= findTypeInEntryTree(entry
.SubEntries
[i
], log
);
119 // if we are not on method leaf, exit here
120 // insert one method result into database
125 * Insert this entrry to the database.
126 * @param entry The entry to write.
127 * @param log The log writer.
129 protected boolean insertEntry(DescEntry entry
, LogWriter log
) {
130 // copy the swlInput Hashtable, so it can be reset easily for the next run
131 Hashtable copySqlInput
= new Hashtable();
132 copySqlInput
.putAll(mSqlInput
);
133 // put some stuff from entry in the Hashtable
134 mSqlInput
.put("EntryLongName", entry
.longName
);
135 mSqlInput
.put("EntryName", entry
.entryName
);
136 mSqlInput
.put("EntryState", entry
.State
);
137 mSqlInput
.put("EntryType", entry
.EntryType
);
138 boolean result
= insertEntry(log
);
139 // reset the Hashtable
140 mSqlInput
= copySqlInput
;
146 * Set the writeable entry types: for example "method", "interface", etc.
147 * All these entries are written to the database.
148 * @param types A String array with all types that have to be written.
150 public void setWriteableEntryTypes(String
[] types
) {
151 mWriteableEntryTypes
= types
;
155 * Is the entry of the writeable entry type?
156 * @param entry The entry that is checked
157 * @return True, if it is indeed a writeable entry.
159 protected boolean isWriteableEntryType(DescEntry entry
) {
160 boolean result
= false;
161 for (int i
=0; i
<mWriteableEntryTypes
.length
; i
++) {
162 if (entry
.EntryType
.equals(mWriteableEntryTypes
[i
])) {
171 * Wrap the command of SQLExecution class for transparency.
173 protected boolean executeSQLCommand(String command
, boolean mergeOutput
) {
174 return mSqlExec
.executeSQLCommand(command
, mSqlInput
, mSqlOutput
, mergeOutput
);
178 * Wrap the command of SQLExecution class for transparency.
180 protected boolean executeSQLCommand(String command
) {
181 return mSqlExec
.executeSQLCommand(command
, mSqlInput
, mSqlOutput
);
185 * Method to print: empty here
187 public void println(String msg
) {
191 * Prepare the database: executed once at the beginning.
192 * Abstract method, so derived classes have to overwrite it.
194 protected abstract boolean prepareDataBase(LogWriter log
);
197 * Insert one entr into the database.
198 * Abstract method, so derived classes have to overwrite it.
200 protected abstract boolean insertEntry(LogWriter log
);
204 protected abstract boolean checkDataBase(LogWriter log);