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: FatDataBaseOutProducer.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 java
.text
.DecimalFormat
;
33 import share
.LogWriter
;
34 import java
.util
.Hashtable
;
35 import java
.util
.Calendar
;
36 import java
.util
.GregorianCalendar
;
42 public class FatDataBaseOutProducer
extends DataBaseOutProducer
{
45 /** Creates a new instance of APIDataBaseOutProducer */
46 public FatDataBaseOutProducer(Hashtable param
) {
48 String testBase
= (String
)mSqlInput
.get("TestBase");
49 int sep
= testBase
.indexOf('_');
50 String testLanguage
= testBase
.substring(0,sep
);
51 testBase
= testBase
.substring(sep
+1);
52 String apiVersion
= (String
)mSqlInput
.get("Version");
53 String descriptionString
= testLanguage
+":"+(String
)mSqlInput
.get("OperatingSystem")+":"+testBase
+":"+apiVersion
;
54 apiVersion
= apiVersion
.substring(0, 6);
56 if (mSqlInput
.get("Date") != null) {
57 mSqlInput
.put("date", mSqlInput
.get("Date"));
59 if (mSqlInput
.get("date") == null) {
60 // build date if it's not there
61 Calendar cal
= new GregorianCalendar();
62 DecimalFormat dfmt
= new DecimalFormat("00");
63 String year
= Integer
.toString(cal
.get(GregorianCalendar
.YEAR
));
64 // month is starting with "0"
65 String month
= dfmt
.format(cal
.get(GregorianCalendar
.MONTH
) + 1);
66 String day
= dfmt
.format(cal
.get(GregorianCalendar
.DATE
));
67 String dateString
= year
+ "-" + month
+ "-" + day
;
69 mSqlInput
.put("date", dateString
);
72 setWriteableEntryTypes(new String
[]{"property", "method", "component", "interface", "service"});
74 mSqlInput
.put("test_run.description", descriptionString
);
75 mSqlInput
.put("api_version_name", apiVersion
);
78 protected boolean prepareDataBase(LogWriter log
) {
79 executeSQLCommand("SHOW TABLES");
81 executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" +
82 " WHERE date = \"$date\" AND description = \"$test_run.description\";", true);
83 String id
= (String
)mSqlInput
.get("test_run.id");
84 // create an entry for this test run
86 executeSQLCommand("SELECT id AS api_version_id FROM api_version" +
87 " WHERE version = \"$api_version_name\";", true);
88 String api_version_id
= (String
)mSqlInput
.get("api_version_id");
89 // create an entry for this API
90 if (api_version_id
== null) {
91 executeSQLCommand("INSERT api_version (api_name, version)" +
92 " VALUES (\"soapi\", \"$api_version_name\")");
93 executeSQLCommand("SELECT id AS api_version_id FROM api_version" +
94 " WHERE version = \"$api_version_name\";", true);
96 // complete entry for the test run
97 executeSQLCommand("INSERT test_run (api_version_id, description, date)" +
98 " VALUES ($api_version_id, \"$test_run.description\", \"$date\");");
99 executeSQLCommand("SELECT test_run.id AS \"test_run.id\", api_version_id, description, date FROM test_run" +
100 " WHERE date = \"$date\" AND description = \"$test_run.description\";", true);
105 // check the database afterwards
106 protected boolean checkDataBase(LogWriter log
) {
110 protected boolean insertEntry(LogWriter log
) {
112 executeSQLCommand("SELECT id AS \"entry.id\", name AS \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true);
113 if (mSqlInput
.get("entry.id") == null) {
114 executeSQLCommand("INSERT entry (name, type)" +
115 " VALUES (\"$EntryLongName\", \"$EntryType\");");
116 executeSQLCommand("SELECT id AS \"entry.id\", name AS \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true);
118 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" +
119 " WHERE entry_id = $entry.id;", true);
120 if (mSqlInput
.get("api_entry.id") == null) {
121 executeSQLCommand("INSERT api_entry (entry_id, api_version_id)"+
122 " VALUES ($entry.id, $api_version_id);");
123 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" +
124 " WHERE entry_id = $entry.id;", true);
126 executeSQLCommand("SELECT status AS \"test_state.status\" FROM test_state"+
127 " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;", true);
129 String status
= (String
)mSqlInput
.get("test_state.status");
130 if (status
== null) {
131 executeSQLCommand("INSERT test_state (test_run_id, entry_id, status)"+
132 " VALUES ($test_run.id, $entry.id, \"$EntryState\");");
135 if (!status
.endsWith("OK")) {
136 executeSQLCommand("UPDATE test_state SET status = \"$EntryState\""+
137 " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;");
143 public Object
getWatcher() {
147 public void setWatcher(Object watcher
) {