summaryrefslogtreecommitdiff
path: root/qadevOOo/runner/stats
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-13 13:20:47 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-14 07:15:41 +0000
commita2c481457cd2d03263054a5fefe80da316e09a44 (patch)
tree5b8717ae1fdfd55b5c3c56410408acd92a94ef42 /qadevOOo/runner/stats
parentfa6ac05beaaf1160c205e40099b99f0ed0efb131 (diff)
runner: finally block to ensure that a resource is closed (Prior to Java SE 7)
http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html Change-Id: I5ecefd3e5bf84fea2a8735a44236ed4c86b440c4 Reviewed-on: https://gerrit.libreoffice.org/11950 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'qadevOOo/runner/stats')
-rw-r--r--qadevOOo/runner/stats/FileLogWriter.java13
-rw-r--r--qadevOOo/runner/stats/SQLExecution.java86
-rw-r--r--qadevOOo/runner/stats/SimpleFileOutProducer.java64
3 files changed, 90 insertions, 73 deletions
diff --git a/qadevOOo/runner/stats/FileLogWriter.java b/qadevOOo/runner/stats/FileLogWriter.java
index 22d538df988b..aebcb0fbf868 100644
--- a/qadevOOo/runner/stats/FileLogWriter.java
+++ b/qadevOOo/runner/stats/FileLogWriter.java
@@ -59,10 +59,17 @@ public class FileLogWriter extends PrintWriter implements LogWriter {
public void addFileLog(String filePath){
+ FileWriter fileWriter = null;
try{
- if(mFileWriters == null)
- mFileWriters = new HashMap<String, FileWriter>();
- mFileWriters.put(filePath, new FileWriter(filePath));
+ try{
+ if(mFileWriters == null)
+ mFileWriters = new HashMap<String, FileWriter>();
+ fileWriter = new FileWriter(filePath);
+ mFileWriters.put(filePath, fileWriter);
+ }finally{
+ if (fileWriter != null)
+ fileWriter.close();
+ }
}catch(IOException e ){
e.printStackTrace(this);
}
diff --git a/qadevOOo/runner/stats/SQLExecution.java b/qadevOOo/runner/stats/SQLExecution.java
index 9c6dca8a69c9..bb50dce7b1a5 100644
--- a/qadevOOo/runner/stats/SQLExecution.java
+++ b/qadevOOo/runner/stats/SQLExecution.java
@@ -255,54 +255,60 @@ public class SQLExecution {
private void execute(String command, HashMap<String, String[]> output, boolean update) {
if (m_bDebug)
System.out.println("Debug - SQLExecution - execute Command: " + command);
+
+ ResultSet sqlResult = null;
try {
- if (update) {
- // make an update
- mStatement.executeUpdate(command);
- }
- else {
- // make a select: collect the result
- ResultSet sqlResult = mStatement.executeQuery(command);
- ResultSetMetaData sqlRSMeta = sqlResult.getMetaData();
- int columnCount = sqlRSMeta.getColumnCount();
- String[] columnNames = new String[columnCount];
- int countRows = 0;
- boolean goThroughRowsTheFirstTime = true;
- for(int i=1; i<=columnCount; i++) {
- columnNames[i-1] = sqlRSMeta.getColumnName(i);
- // initialize output
- ArrayList<String> v = new ArrayList<String>();
+ try {
+ if (update) {
+ // make an update
+ mStatement.executeUpdate(command);
+ }
+ else {
+ // make a select: collect the result
+ sqlResult = mStatement.executeQuery(command);
+ ResultSetMetaData sqlRSMeta = sqlResult.getMetaData();
+ int columnCount = sqlRSMeta.getColumnCount();
+ String[] columnNames = new String[columnCount];
+ int countRows = 0;
+ boolean goThroughRowsTheFirstTime = true;
+ for(int i=1; i<=columnCount; i++) {
+ columnNames[i-1] = sqlRSMeta.getColumnName(i);
+ // initialize output
+ ArrayList<String> v = new ArrayList<String>();
- sqlResult.beforeFirst();
- while (sqlResult.next()) {
- String value = sqlResult.getString(i);
- v.add(value);
- // the first time: count rows
+ sqlResult.beforeFirst();
+ while (sqlResult.next()) {
+ String value = sqlResult.getString(i);
+ v.add(value);
+ // the first time: count rows
+ if (goThroughRowsTheFirstTime)
+ countRows++;
+ }
+ // rows are counted
if (goThroughRowsTheFirstTime)
- countRows++;
- }
- // rows are counted
- if (goThroughRowsTheFirstTime)
- goThroughRowsTheFirstTime = false;
+ goThroughRowsTheFirstTime = false;
- // put result in output HashMap
- String[]s = new String[countRows];
- s = v.toArray(s);
- output.put(columnNames[i-1], s);
- if (m_bDebug) {
- if (i == 1) {
- System.out.print("Debug - SQLExecution - Command returns: ");
- System.out.print("row: " + columnNames[i-1] + " vals: ");
+ // put result in output HashMap
+ String[]s = new String[countRows];
+ s = v.toArray(s);
+ output.put(columnNames[i-1], s);
+ if (m_bDebug) {
+ if (i == 1) {
+ System.out.print("Debug - SQLExecution - Command returns: ");
+ System.out.print("row: " + columnNames[i-1] + " vals: ");
+ }
+ for (int j=0; j<s.length; j++)
+ System.out.print(s[j] + " ");
+ if (i == columnCount - 1)
+ System.out.println();
}
- for (int j=0; j<s.length; j++)
- System.out.print(s[j] + " ");
- if (i == columnCount - 1)
- System.out.println();
}
}
+ } finally {
+ if (sqlResult != null)
+ sqlResult.close();
}
- }
- catch (java.sql.SQLException e) {
+ } catch (java.sql.SQLException e) {
e.printStackTrace();
}
}
diff --git a/qadevOOo/runner/stats/SimpleFileOutProducer.java b/qadevOOo/runner/stats/SimpleFileOutProducer.java
index 2a0dbf6096e5..e8d572ecb657 100644
--- a/qadevOOo/runner/stats/SimpleFileOutProducer.java
+++ b/qadevOOo/runner/stats/SimpleFileOutProducer.java
@@ -42,39 +42,43 @@ public class SimpleFileOutProducer implements LogWriter {
* the information, maybe write them to a db
*/
public boolean summary(share.DescEntry entry) {
+ FileWriter out = null;
try {
- String outpath = (String) entry.UserDefinedParams.get("OutputPath");
- if (outpath==null) {
- System.out.println("## Parameter OutputPath isn't defined using default");
- return summary_default(entry);
+ try {
+ String outpath = (String) entry.UserDefinedParams.get("OutputPath");
+ if (outpath==null) {
+ System.out.println("## Parameter OutputPath isn't defined using default");
+ return summary_default(entry);
+ }
+ String FileName = entry.longName + ".out";
+ if (!entry.EntryType.equals("component")) {
+ FileName = entry.longName.substring(0,
+ entry.longName.indexOf(':')) + ".out";
+ }
+ util.utils.make_Directories("",outpath);
+ File outputFile = new File(outpath, FileName);
+ out = new FileWriter(outputFile.toString(),true);
+ String ls = System.getProperty("line.separator");
+ String date = new java.util.Date().toString();
+ String header = "***** State for "+entry.longName+"( "+ date +" ) ******";
+ out.write(header+ls);
+ if (entry.hasErrorMsg) {
+ out.write(entry.ErrorMsg+ls);
+ out.write("Whole "+entry.EntryType+": "+entry.State+ls);
+ } else {
+ out.write("Whole "+entry.EntryType+": "+entry.State+ls);
+ }
+ String bottom="";
+ for (int i=0;i<header.length();i++) {
+ bottom += "*";
+ }
+ out.write(bottom+ls);
+ out.write(""+ls);
+ } finally {
+ if (out != null)
+ out.close();
}
- String FileName = entry.longName + ".out";
- if (!entry.EntryType.equals("component")) {
- FileName = entry.longName.substring(0,
- entry.longName.indexOf(':')) + ".out";
- }
- util.utils.make_Directories("",outpath);
- File outputFile = new File(outpath, FileName);
- FileWriter out = new FileWriter(outputFile.toString(),true);
- String ls = System.getProperty("line.separator");
- String date = new java.util.Date().toString();
- String header = "***** State for "+entry.longName+"( "+ date +" ) ******";
- out.write(header+ls);
- if (entry.hasErrorMsg) {
- out.write(entry.ErrorMsg+ls);
- out.write("Whole "+entry.EntryType+": "+entry.State+ls);
- } else {
- out.write("Whole "+entry.EntryType+": "+entry.State+ls);
- }
- String bottom="";
- for (int i=0;i<header.length();i++) {
- bottom += "*";
- }
- out.write(bottom+ls);
- out.write(""+ls);
- out.close();
} catch (java.io.IOException e) {
-
}
return true;
}