1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ComplexDataBaseOutProducer.java,v $
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 ************************************************************************/
32 import share
.LogWriter
;
33 import java
.text
.DecimalFormat
;
34 import java
.util
.Hashtable
;
35 import java
.util
.Calendar
;
36 import java
.util
.GregorianCalendar
;
42 public class ComplexDataBaseOutProducer
extends DataBaseOutProducer
{
44 /** Creates a new instance of ComplexDataBaseOutProducer */
45 public ComplexDataBaseOutProducer(Hashtable param
) {
47 // do we have to write debug output?
48 Object o
= param
.get("DebugIsActive");
50 if (o
instanceof String
) {
51 String debug
= (String
)o
;
52 m_bDebug
= (debug
.equalsIgnoreCase("yes") || debug
.equalsIgnoreCase("true"));
57 String testBase
= (String
)mSqlInput
.get("TestBase");
58 String apiVersion
= (String
)mSqlInput
.get("Version");
59 String os
= (String
)mSqlInput
.get("OperatingSystem");
60 if (testBase
== null || apiVersion
== null || os
== null) {
61 System
.err
.println("The ComplexDataBaseOutProducer constructor needs this parameters to work correctly:");
62 System
.err
.println("TestBase - " + testBase
);
63 System
.err
.println("Version - " + apiVersion
);
64 System
.err
.println("OperatingSystem - " + os
);
65 System
.err
.println("Add the missing parameter.");
67 int sep
= testBase
.indexOf('_');
68 String testLanguage
= testBase
.substring(0,sep
);
69 testBase
= testBase
.substring(sep
+1);
72 // if (os == null || os.equals(""))
73 // os = System.getProperty("os.name");
74 String descriptionString
= testLanguage
+":"+ os
+":"+testBase
+":"+apiVersion
;
75 if (apiVersion
!= null)
76 apiVersion
= apiVersion
.substring(0, 6);
78 if (mSqlInput
.get("date") == null) {
79 // build date if it's not there
80 Calendar cal
= new GregorianCalendar();
81 DecimalFormat dfmt
= new DecimalFormat("00");
82 String year
= Integer
.toString(cal
.get(GregorianCalendar
.YEAR
));
83 // month is starting with "0"
84 String month
= dfmt
.format(cal
.get(GregorianCalendar
.MONTH
) + 1);
85 String day
= dfmt
.format(cal
.get(GregorianCalendar
.DATE
));
86 String dateString
= year
+ "-" + month
+ "-" + day
;
88 mSqlInput
.put("date", dateString
);
90 mSqlInput
.put("test_run_description", descriptionString
);
91 mSqlInput
.put("api_version_name", apiVersion
);
92 setWriteableEntryTypes(new String
[]{"unit", "method"});
96 * Prepare the database.
97 * @parameter log A log writer
98 * @return True, if everything worked.
100 protected boolean prepareDataBase(LogWriter log
) {
101 executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" +
102 " WHERE date = \"$date\" AND description = \"$test_run_description\";", true);
103 String id
= (String
)mSqlInput
.get("test_run.id");
104 // create an entry for this test run
106 executeSQLCommand("SELECT id as api_version_id FROM api_version" +
107 " WHERE version = \"$api_version_name\";", true);
108 String api_version_id
= (String
)mSqlInput
.get("api_version_id");
109 // create an entry for this API
110 if (api_version_id
== null) {
111 executeSQLCommand("INSERT api_version (api_name, version)" +
112 " VALUES (\"soapi\", \"$api_version_name\")");
113 executeSQLCommand("SELECT id as api_version_id FROM api_version" +
114 " WHERE version = \"$api_version_name\";", true);
116 executeSQLCommand("INSERT test_run (api_version_id, description, date)" +
117 " VALUES ($api_version_id, \"$test_run_description\", \"$date\");");
118 executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" +
119 " WHERE date = \"$date\" AND description = \"$test_run_description\";", true);
125 * Insert the result of the test of an entry into the database.
126 * @parameter log A log writer
127 * @return True, if everything worked.
129 protected boolean insertEntry(LogWriter log
) {
132 System
.out
.println("DEBUG - ComplexDataBaseOutProducer: entry.id has to be null: " + (mSqlInput
.get("entry.id")==null));
133 System
.out
.println("DEBUG - ComplexDataBaseOutProducer: EntryLongName: " + mSqlInput
.get("EntryLongName"));
135 executeSQLCommand("SELECT id as \"entry.id\", name as \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true);
137 if (mSqlInput
.get("entry.id") == null) {
139 System
.out
.println("DEBUG - ComplexDataBaseOutProducer: No entry.id found, this is a new entry in the database.");
141 executeSQLCommand("INSERT entry (name, type)" +
142 " VALUES (\"$EntryLongName\", \"$EntryType\");");
143 executeSQLCommand("SELECT id as \"entry.id\", name as \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true);
147 executeSQLCommand("SELECT id as \"api_entry.id\", api_version_id as \"api_entry.api_version_id\", entry_id as \"api_entry.entry_id\" FROM api_entry" +
148 " WHERE entry_id = $entry.id;", true);
149 if (mSqlInput
.get("api_entry.id") == null) {
150 System
.out
.println("No api_entry.id found");
151 executeSQLCommand("INSERT api_entry (entry_id, api_version_id)"+
152 " VALUES ($entry.id, $api_version_id);");
153 executeSQLCommand("SELECT id as \"api_entry.id\", api_version_id as \"api_entry.api_version_id\", entry_id as \"api_entry.entry_id\" FROM api_entry" +
154 " WHERE entry_id = $entry.id;", true);
158 executeSQLCommand("SELECT status as \"test_state.status\" FROM test_state"+
159 " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;", true);
161 String entryState
= (String
)mSqlInput
.get("EntryState");
162 String status
= (String
)mSqlInput
.get("test_state.status");
164 if (!entryState
.equals("SKIPPED.FAILED")) { // occurs in case of misspellings: do not make an database entry.
165 if (status
== null) {
166 executeSQLCommand("INSERT test_state (test_run_id, entry_id, status)"+
167 " VALUES ($test_run.id, $entry.id, \"$EntryState\");");
170 executeSQLCommand("UPDATE test_state SET status = \"$EntryState\""+
171 " where test_run_id =$test_run.id AND entry_id = $entry.id;");
177 public Object
getWatcher() {
181 public void setWatcher(Object watcher
) {