1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package stats; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import java.text.DecimalFormat; 30*cdf0e10cSrcweir import share.LogWriter; 31*cdf0e10cSrcweir import java.util.Hashtable; 32*cdf0e10cSrcweir import java.util.Calendar; 33*cdf0e10cSrcweir import java.util.GregorianCalendar; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** 37*cdf0e10cSrcweir * 38*cdf0e10cSrcweir */ 39*cdf0e10cSrcweir public class FatDataBaseOutProducer extends DataBaseOutProducer { 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /** Creates a new instance of APIDataBaseOutProducer */ 43*cdf0e10cSrcweir public FatDataBaseOutProducer(Hashtable param) { 44*cdf0e10cSrcweir super(param); 45*cdf0e10cSrcweir String testBase = (String)mSqlInput.get("TestBase"); 46*cdf0e10cSrcweir int sep = testBase.indexOf('_'); 47*cdf0e10cSrcweir String testLanguage = testBase.substring(0,sep); 48*cdf0e10cSrcweir testBase = testBase.substring(sep+1); 49*cdf0e10cSrcweir String apiVersion = (String)mSqlInput.get("Version"); 50*cdf0e10cSrcweir String descriptionString = testLanguage+":"+(String)mSqlInput.get("OperatingSystem")+":"+testBase+":"+apiVersion; 51*cdf0e10cSrcweir apiVersion = apiVersion.substring(0, 6); 52*cdf0e10cSrcweir // build date 53*cdf0e10cSrcweir if (mSqlInput.get("Date") != null) { 54*cdf0e10cSrcweir mSqlInput.put("date", mSqlInput.get("Date")); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir if (mSqlInput.get("date") == null) { 57*cdf0e10cSrcweir // build date if it's not there 58*cdf0e10cSrcweir Calendar cal = new GregorianCalendar(); 59*cdf0e10cSrcweir DecimalFormat dfmt = new DecimalFormat("00"); 60*cdf0e10cSrcweir String year = Integer.toString(cal.get(GregorianCalendar.YEAR)); 61*cdf0e10cSrcweir // month is starting with "0" 62*cdf0e10cSrcweir String month = dfmt.format(cal.get(GregorianCalendar.MONTH) + 1); 63*cdf0e10cSrcweir String day = dfmt.format(cal.get(GregorianCalendar.DATE)); 64*cdf0e10cSrcweir String dateString = year + "-" + month + "-" + day; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir mSqlInput.put("date", dateString); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir setWriteableEntryTypes(new String[]{"property", "method", "component", "interface", "service"}); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir mSqlInput.put("test_run.description", descriptionString); 72*cdf0e10cSrcweir mSqlInput.put("api_version_name", apiVersion); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir protected boolean prepareDataBase(LogWriter log) { 76*cdf0e10cSrcweir executeSQLCommand("SHOW TABLES"); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" + 79*cdf0e10cSrcweir " WHERE date = \"$date\" AND description = \"$test_run.description\";", true); 80*cdf0e10cSrcweir String id = (String)mSqlInput.get("test_run.id"); 81*cdf0e10cSrcweir // create an entry for this test run 82*cdf0e10cSrcweir if (id == null) { 83*cdf0e10cSrcweir executeSQLCommand("SELECT id AS api_version_id FROM api_version" + 84*cdf0e10cSrcweir " WHERE version = \"$api_version_name\";", true); 85*cdf0e10cSrcweir String api_version_id = (String)mSqlInput.get("api_version_id"); 86*cdf0e10cSrcweir // create an entry for this API 87*cdf0e10cSrcweir if (api_version_id == null) { 88*cdf0e10cSrcweir executeSQLCommand("INSERT api_version (api_name, version)" + 89*cdf0e10cSrcweir " VALUES (\"soapi\", \"$api_version_name\")"); 90*cdf0e10cSrcweir executeSQLCommand("SELECT id AS api_version_id FROM api_version" + 91*cdf0e10cSrcweir " WHERE version = \"$api_version_name\";", true); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir // complete entry for the test run 94*cdf0e10cSrcweir executeSQLCommand("INSERT test_run (api_version_id, description, date)" + 95*cdf0e10cSrcweir " VALUES ($api_version_id, \"$test_run.description\", \"$date\");"); 96*cdf0e10cSrcweir executeSQLCommand("SELECT test_run.id AS \"test_run.id\", api_version_id, description, date FROM test_run" + 97*cdf0e10cSrcweir " WHERE date = \"$date\" AND description = \"$test_run.description\";", true); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir return true; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // check the database afterwards 103*cdf0e10cSrcweir protected boolean checkDataBase(LogWriter log) { 104*cdf0e10cSrcweir return true; 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir protected boolean insertEntry(LogWriter log) { 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir executeSQLCommand("SELECT id AS \"entry.id\", name AS \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true); 110*cdf0e10cSrcweir if (mSqlInput.get("entry.id") == null) { 111*cdf0e10cSrcweir executeSQLCommand("INSERT entry (name, type)" + 112*cdf0e10cSrcweir " VALUES (\"$EntryLongName\", \"$EntryType\");"); 113*cdf0e10cSrcweir executeSQLCommand("SELECT id AS \"entry.id\", name AS \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 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" + 116*cdf0e10cSrcweir " WHERE entry_id = $entry.id;", true); 117*cdf0e10cSrcweir if (mSqlInput.get("api_entry.id") == null) { 118*cdf0e10cSrcweir executeSQLCommand("INSERT api_entry (entry_id, api_version_id)"+ 119*cdf0e10cSrcweir " VALUES ($entry.id, $api_version_id);"); 120*cdf0e10cSrcweir 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" + 121*cdf0e10cSrcweir " WHERE entry_id = $entry.id;", true); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir executeSQLCommand("SELECT status AS \"test_state.status\" FROM test_state"+ 124*cdf0e10cSrcweir " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;", true); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir String status = (String)mSqlInput.get("test_state.status"); 127*cdf0e10cSrcweir if (status == null) { 128*cdf0e10cSrcweir executeSQLCommand("INSERT test_state (test_run_id, entry_id, status)"+ 129*cdf0e10cSrcweir " VALUES ($test_run.id, $entry.id, \"$EntryState\");"); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir else { 132*cdf0e10cSrcweir if (!status.endsWith("OK")) { 133*cdf0e10cSrcweir executeSQLCommand("UPDATE test_state SET status = \"$EntryState\""+ 134*cdf0e10cSrcweir " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;"); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir return true; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir public Object getWatcher() { 141*cdf0e10cSrcweir return null; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir public void setWatcher(Object watcher) { 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir } 148