1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package stats; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import java.text.DecimalFormat; 26cdf0e10cSrcweir import share.LogWriter; 27cdf0e10cSrcweir import java.util.Hashtable; 28cdf0e10cSrcweir import java.util.Calendar; 29cdf0e10cSrcweir import java.util.GregorianCalendar; 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** 33cdf0e10cSrcweir * 34cdf0e10cSrcweir */ 35cdf0e10cSrcweir public class FatDataBaseOutProducer extends DataBaseOutProducer { 36cdf0e10cSrcweir 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** Creates a new instance of APIDataBaseOutProducer */ FatDataBaseOutProducer(Hashtable param)39cdf0e10cSrcweir public FatDataBaseOutProducer(Hashtable param) { 40cdf0e10cSrcweir super(param); 41cdf0e10cSrcweir String testBase = (String)mSqlInput.get("TestBase"); 42cdf0e10cSrcweir int sep = testBase.indexOf('_'); 43cdf0e10cSrcweir String testLanguage = testBase.substring(0,sep); 44cdf0e10cSrcweir testBase = testBase.substring(sep+1); 45cdf0e10cSrcweir String apiVersion = (String)mSqlInput.get("Version"); 46cdf0e10cSrcweir String descriptionString = testLanguage+":"+(String)mSqlInput.get("OperatingSystem")+":"+testBase+":"+apiVersion; 47cdf0e10cSrcweir apiVersion = apiVersion.substring(0, 6); 48cdf0e10cSrcweir // build date 49cdf0e10cSrcweir if (mSqlInput.get("Date") != null) { 50cdf0e10cSrcweir mSqlInput.put("date", mSqlInput.get("Date")); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir if (mSqlInput.get("date") == null) { 53cdf0e10cSrcweir // build date if it's not there 54cdf0e10cSrcweir Calendar cal = new GregorianCalendar(); 55cdf0e10cSrcweir DecimalFormat dfmt = new DecimalFormat("00"); 56cdf0e10cSrcweir String year = Integer.toString(cal.get(GregorianCalendar.YEAR)); 57cdf0e10cSrcweir // month is starting with "0" 58cdf0e10cSrcweir String month = dfmt.format(cal.get(GregorianCalendar.MONTH) + 1); 59cdf0e10cSrcweir String day = dfmt.format(cal.get(GregorianCalendar.DATE)); 60cdf0e10cSrcweir String dateString = year + "-" + month + "-" + day; 61cdf0e10cSrcweir 62cdf0e10cSrcweir mSqlInput.put("date", dateString); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir setWriteableEntryTypes(new String[]{"property", "method", "component", "interface", "service"}); 66cdf0e10cSrcweir 67cdf0e10cSrcweir mSqlInput.put("test_run.description", descriptionString); 68cdf0e10cSrcweir mSqlInput.put("api_version_name", apiVersion); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir prepareDataBase(LogWriter log)71cdf0e10cSrcweir protected boolean prepareDataBase(LogWriter log) { 72cdf0e10cSrcweir executeSQLCommand("SHOW TABLES"); 73cdf0e10cSrcweir 74cdf0e10cSrcweir executeSQLCommand("SELECT id AS \"test_run.id\", api_version_id, description, date FROM test_run" + 75cdf0e10cSrcweir " WHERE date = \"$date\" AND description = \"$test_run.description\";", true); 76cdf0e10cSrcweir String id = (String)mSqlInput.get("test_run.id"); 77cdf0e10cSrcweir // create an entry for this test run 78cdf0e10cSrcweir if (id == null) { 79cdf0e10cSrcweir executeSQLCommand("SELECT id AS api_version_id FROM api_version" + 80cdf0e10cSrcweir " WHERE version = \"$api_version_name\";", true); 81cdf0e10cSrcweir String api_version_id = (String)mSqlInput.get("api_version_id"); 82cdf0e10cSrcweir // create an entry for this API 83cdf0e10cSrcweir if (api_version_id == null) { 84cdf0e10cSrcweir executeSQLCommand("INSERT api_version (api_name, version)" + 85cdf0e10cSrcweir " VALUES (\"soapi\", \"$api_version_name\")"); 86cdf0e10cSrcweir executeSQLCommand("SELECT id AS api_version_id FROM api_version" + 87cdf0e10cSrcweir " WHERE version = \"$api_version_name\";", true); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir // complete entry for the test run 90cdf0e10cSrcweir executeSQLCommand("INSERT test_run (api_version_id, description, date)" + 91cdf0e10cSrcweir " VALUES ($api_version_id, \"$test_run.description\", \"$date\");"); 92cdf0e10cSrcweir executeSQLCommand("SELECT test_run.id AS \"test_run.id\", api_version_id, description, date FROM test_run" + 93cdf0e10cSrcweir " WHERE date = \"$date\" AND description = \"$test_run.description\";", true); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir return true; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir // check the database afterwards checkDataBase(LogWriter log)99cdf0e10cSrcweir protected boolean checkDataBase(LogWriter log) { 100cdf0e10cSrcweir return true; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir insertEntry(LogWriter log)103cdf0e10cSrcweir protected boolean insertEntry(LogWriter log) { 104cdf0e10cSrcweir 105cdf0e10cSrcweir executeSQLCommand("SELECT id AS \"entry.id\", name AS \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true); 106cdf0e10cSrcweir if (mSqlInput.get("entry.id") == null) { 107cdf0e10cSrcweir executeSQLCommand("INSERT entry (name, type)" + 108cdf0e10cSrcweir " VALUES (\"$EntryLongName\", \"$EntryType\");"); 109cdf0e10cSrcweir executeSQLCommand("SELECT id AS \"entry.id\", name AS \"entry.name\" FROM entry WHERE name = \"$EntryLongName\";", true); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 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" + 112cdf0e10cSrcweir " WHERE entry_id = $entry.id;", true); 113cdf0e10cSrcweir if (mSqlInput.get("api_entry.id") == null) { 114cdf0e10cSrcweir executeSQLCommand("INSERT api_entry (entry_id, api_version_id)"+ 115cdf0e10cSrcweir " VALUES ($entry.id, $api_version_id);"); 116cdf0e10cSrcweir 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" + 117cdf0e10cSrcweir " WHERE entry_id = $entry.id;", true); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir executeSQLCommand("SELECT status AS \"test_state.status\" FROM test_state"+ 120cdf0e10cSrcweir " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;", true); 121cdf0e10cSrcweir 122cdf0e10cSrcweir String status = (String)mSqlInput.get("test_state.status"); 123cdf0e10cSrcweir if (status == null) { 124cdf0e10cSrcweir executeSQLCommand("INSERT test_state (test_run_id, entry_id, status)"+ 125cdf0e10cSrcweir " VALUES ($test_run.id, $entry.id, \"$EntryState\");"); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir else { 128cdf0e10cSrcweir if (!status.endsWith("OK")) { 129cdf0e10cSrcweir executeSQLCommand("UPDATE test_state SET status = \"$EntryState\""+ 130cdf0e10cSrcweir " WHERE test_run_id = $test_run.id AND entry_id = $entry.id;"); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir return true; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir getWatcher()136cdf0e10cSrcweir public Object getWatcher() { 137cdf0e10cSrcweir return null; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir setWatcher(Object watcher)140cdf0e10cSrcweir public void setWatcher(Object watcher) { 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir } 144