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