You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2016/12/08 00:45:44 UTC
[17/38] incubator-trafodion git commit: convert trafci project into
maven project
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceQueryException.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceQueryException.java b/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceQueryException.java
new file mode 100644
index 0000000..a4115a4
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceQueryException.java
@@ -0,0 +1,35 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.ci;
+
+public class InterfaceQueryException extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ InterfaceQueryException()
+ {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceSyntaxError.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceSyntaxError.java b/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceSyntaxError.java
new file mode 100644
index 0000000..f81373a
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/InterfaceSyntaxError.java
@@ -0,0 +1,83 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.ci;
+
+public class InterfaceSyntaxError
+{
+
+
+ private StringBuffer errMesg=null;
+ private String errPrefix = SessionError.SYNTAX_ERROR_PREFIX; //"ERROR: A syntax error occurred at or before:";
+
+ InterfaceSyntaxError()
+ {
+
+ }
+
+ public void setSyntaxError(String qryString ,String remainderStr)
+ {
+ if (errMesg == null)
+ {
+ errMesg=new StringBuffer();
+ }
+ this.errMesg.delete(0,errMesg.length());
+ //this.errMesg.append(SessionDefaults.lineSeperator);
+ this.errMesg.append(errPrefix);
+ this.errMesg.append(SessionDefaults.lineSeperator);
+ this.errMesg.append(qryString);
+ this.errMesg.append(SessionDefaults.lineSeperator);
+
+ this.errMesg.append(qryString.replaceAll("\\S"," "));
+
+ /*for(int i=0; i < (qryString.length()-remainderStr.length());i++)
+ this.errMesg.append(" ");*/
+ for (int i=0; i < remainderStr.length();i++)
+ this.errMesg.delete(errMesg.length()-1,errMesg.length());
+
+ this.errMesg.append("^");
+
+ this.errMesg.replace(0,this.errMesg.length(),this.errMesg.toString().replaceAll("(?m)^\\s+$",""));
+ //this.errMesg.append("^");
+ }
+
+ public ErrorObject getSyntaxError(String qryString,String remainderStr )
+ {
+
+ if (qryString != null)
+ {
+ qryString=qryString.replaceAll("\\s+$","");
+ }
+
+ if (remainderStr == null)
+ {
+ remainderStr="";
+ }
+ else
+ {
+ remainderStr=remainderStr.trim();
+ }
+
+ setSyntaxError(qryString,remainderStr);
+ return new ErrorObject(SessionError.GENERIC_SYNTAX_ERROR_CODE, errMesg.toString());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/InvalidNumberOfArguments.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/InvalidNumberOfArguments.java b/core/conn/trafci/src/main/java/org/trafodion/ci/InvalidNumberOfArguments.java
new file mode 100644
index 0000000..e01b988
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/InvalidNumberOfArguments.java
@@ -0,0 +1,35 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.ci;
+
+public class InvalidNumberOfArguments extends Exception
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ InvalidNumberOfArguments()
+ {
+ super(SessionError.CMD_LINE_ARGS_ERR.RAWOutputError());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/JDBCVproc.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/JDBCVproc.java b/core/conn/trafci/src/main/java/org/trafodion/ci/JDBCVproc.java
new file mode 100644
index 0000000..d81c896
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/JDBCVproc.java
@@ -0,0 +1,38 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.ci;
+
+public class JDBCVproc
+{
+ public static String getVproc()
+ {
+ try {
+ return (org.trafodion.jdbc.t4.Vproc.getVproc());
+ } catch (java.lang.IllegalAccessError iae)
+ {
+ return iae.getMessage();
+
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/LFProperties.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/LFProperties.java b/core/conn/trafci/src/main/java/org/trafodion/ci/LFProperties.java
new file mode 100644
index 0000000..0b80f90
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/LFProperties.java
@@ -0,0 +1,130 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+/**
+ *
+ * Class to load and display the look and feel properties file.
+ *
+ */
+
+package org.trafodion.ci;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class LFProperties
+{
+
+ private Properties lfProps=null;
+ private Session sessObj=null;
+
+ LFProperties(){}
+
+ public String getStatus(Query qryObj) {
+ String qryString = Utils.trimSQLTerminator(deleteCStyleComments(qryObj.getQueryText().trim()),sessObj.getSessionSQLTerminator());
+ String queryString=sessObj.getStrMode()+"_"+qryString.trim().toUpperCase().replaceAll("\\s+"," ");
+ Enumeration<Object> enumKeys=lfProps.keys();
+ int keySize=0;
+ String matchedElement=null;
+ String matchedValue=null;
+
+ while (enumKeys.hasMoreElements())
+ {
+ String nextElement=enumKeys.nextElement().toString();
+
+ if (queryString.matches(nextElement))
+ {
+ if (nextElement.length() > keySize)
+ {
+ keySize=nextElement.length();
+ matchedElement=nextElement;
+ }
+ }
+
+ }
+
+ if (keySize > 0)
+ {
+ String stmtType=qryObj.getStmtType();
+
+ if (((matchedElement.startsWith("SQL_EXECUTE")) && !qryObj.isTrimOut() &&
+ ( (stmtType.equalsIgnoreCase("SELECT")) ||
+ (stmtType.equalsIgnoreCase("INSERT")) ||
+ (stmtType.equalsIgnoreCase("UPDATE")) ||
+ (stmtType.equalsIgnoreCase("DELETE")) ) ) || ( stmtType != null && stmtType.equals("SELECT_LIST_COUNT")))
+ {
+ matchedElement=sessObj.getStrMode()+"_"+stmtType+" .*";
+ }
+
+ if ((matchedElement.startsWith("SQL_EXECUTE")) && !qryObj.isTrimOut() &&
+ (stmtType.equalsIgnoreCase("CREATE_TABLE_AS")))
+ {
+ matchedElement = "SQL_CREATE TABLE .* AS SELECT .*";
+ }
+
+
+ matchedValue = lfProps.getProperty(matchedElement);
+ if (matchedValue.indexOf("@rownum@") != -1)
+ {
+ return (matchedValue.replaceFirst("@rownum@",qryObj.getRowCount()));
+ }
+ return (matchedValue);
+ }
+ return (lfProps.getProperty(sessObj.getStrMode()+"_UNKNOWN_CMD"));
+ }
+
+ /*
+ * Delete C-style comments in a String
+ */
+ private String deleteCStyleComments(String originalString)
+ {
+ Pattern p = Pattern.compile( "/[*]{1,2}.*?[*]/",Pattern.DOTALL);
+ Matcher m = p.matcher(originalString);
+ return m.replaceAll("");
+ }
+
+ // load the look and feel properties
+ public void loadLookAndFeelProps(Session sessObj, boolean specialModeEnabled)
+ throws FileNotFoundException, IOException {
+ String laFileName=null;
+ String laOption=System.getProperty(SessionDefaults.PROP_TRAFCILF);
+ this.sessObj = sessObj;
+
+ laFileName= SessionDefaults.PROP_DEFAULT_NAME;
+ sessObj.setSessView(SessionDefaults.CIDEFAULT_VIEW);
+
+ loadProperties(laFileName);
+ }
+
+ public void loadProperties(String fileName) throws FileNotFoundException, IOException
+ {
+
+ lfProps=new Properties();
+ lfProps.load(this.getClass().getResourceAsStream(fileName));
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/MaskingThread.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/MaskingThread.java b/core/conn/trafci/src/main/java/org/trafodion/ci/MaskingThread.java
new file mode 100644
index 0000000..5df4d86
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/MaskingThread.java
@@ -0,0 +1,73 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.ci;
+
+public class MaskingThread extends Thread
+{
+ private boolean stop = false;
+ private String prompt = null;
+
+ /**
+ * @param thePrompt The prompt displayed to the user
+ */
+ public MaskingThread(String thePrompt)
+ {
+ prompt = thePrompt;
+ }
+
+ /**
+ * Begin masking until asked to stop.
+ */
+ public void run()
+ {
+ int priority = Thread.currentThread().getPriority();
+ Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
+
+ while (!stop)
+ {
+ if (!stop)
+ System.out.print( " \r" + prompt );
+ //System.out.flush();
+ try
+ {
+ // attempt masking at this rate (refresh every 1 ms.)
+ sleep(1);
+ }
+ catch (InterruptedException iex)
+ {
+ iex.printStackTrace();
+ }
+ finally
+ { // restore the original priority
+ Thread.currentThread().setPriority(priority);
+ }
+
+ }
+ }
+
+ /**
+ * Instruct the thread to stop masking.
+ */
+ public void stopMasking()
+ {
+ stop = true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/MultiByteUtils.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/MultiByteUtils.java b/core/conn/trafci/src/main/java/org/trafodion/ci/MultiByteUtils.java
new file mode 100644
index 0000000..220243c
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/MultiByteUtils.java
@@ -0,0 +1,56 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.ci;
+
+
+import java.awt.FontMetrics;
+import java.awt.Font;
+import java.awt.Panel;
+
+public class MultiByteUtils {
+
+ private static MultiByteUtils mbUtils = new MultiByteUtils();
+ private FontMetrics fm = null;
+
+ MultiByteUtils()
+ {
+ try {
+ System.setProperty("java.awt.headless", "true");
+ }catch(Throwable t)
+ {
+ }
+ try {
+ Panel pan = new Panel();
+ fm = pan.getFontMetrics(new Font("Monospaced",Font.PLAIN, 12));
+ } catch (Throwable t)
+ {
+ System.out.println(SessionError.MULTIBYTE_DISP_WARN.errorMessage());
+ }
+ }
+
+
+ public static FontMetrics getFontMetrics()
+ {
+ return mbUtils.fm;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/NullKeyWordException.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/NullKeyWordException.java b/core/conn/trafci/src/main/java/org/trafodion/ci/NullKeyWordException.java
new file mode 100644
index 0000000..a7854d5
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/NullKeyWordException.java
@@ -0,0 +1,35 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+package org.trafodion.ci;
+
+public class NullKeyWordException extends InterfaceQueryException
+{
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ NullKeyWordException()
+ {
+ super();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/OutputColumnAttribute.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/OutputColumnAttribute.java b/core/conn/trafci/src/main/java/org/trafodion/ci/OutputColumnAttribute.java
new file mode 100644
index 0000000..d84dce4
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/OutputColumnAttribute.java
@@ -0,0 +1,47 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.ci;
+
+public class OutputColumnAttribute {
+ public String name;
+ public int width = SessionDefaults.MIN_COL_DISPLAY_SIZE;
+ public int align=OutputContents.LiftAlign;
+
+ public String getDisplayFormatName()
+ {
+ if(width>name.length())
+ {
+ StringBuilder sbName = new StringBuilder(width);
+ sbName.append(name);
+ for(int i=0;i<width-name.length();i++)
+ {
+ sbName.append(" ");
+ }
+ return sbName.toString();
+ }
+ else
+ {
+ return name;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/OutputContents.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/OutputContents.java b/core/conn/trafci/src/main/java/org/trafodion/ci/OutputContents.java
new file mode 100644
index 0000000..41c2c41
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/OutputContents.java
@@ -0,0 +1,144 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.ci;
+
+import java.util.ArrayList;
+
+public class OutputContents {
+
+ public static int LiftAlign = 0;
+ public static int RightAlign = 1;
+ public static int CenterAlign = 2;
+
+ private String title="";
+ private String itemName="";
+ private String headerSeparator = "-";
+ private String columnSeparator = " ";
+ private ArrayList<OutputColumnAttribute> alColumns;
+ private ArrayList<ArrayList<String>> alRows;
+
+ public OutputContents()
+ {
+ alColumns = new ArrayList<OutputColumnAttribute>();
+ alRows = new ArrayList<ArrayList<String>>();
+ }
+
+ public OutputContents(int columnCount)
+ {
+ alColumns = new ArrayList<OutputColumnAttribute>(columnCount);
+ alRows = new ArrayList<ArrayList<String>>();
+ }
+
+ public ArrayList<String> newRow()
+ {
+ ArrayList<String> row = new ArrayList<String>(alColumns.size());
+ alRows.add(row);
+ return row;
+ }
+
+ public ArrayList<ArrayList<String>> getRows()
+ {
+ return this.alRows;
+ }
+
+ public OutputColumnAttribute newColumn()
+ {
+ OutputColumnAttribute column = new OutputColumnAttribute();
+ alColumns.add(column);
+
+ return column;
+ }
+
+ public void setColumnWidth(String columnName, int width)
+ {
+ for(int i=0; i<alColumns.size();i++)
+ {
+ OutputColumnAttribute column = (OutputColumnAttribute)alColumns.get(i);
+ if(column!=null && column.name.equals(columnName))
+ {
+ if(column.width<width)
+ column.width=width;
+ break;
+ }
+ }
+ }
+
+ public void setColumnAlign(String columnName, int align)
+ {
+ for(int i=0; i<alColumns.size();i++)
+ {
+ OutputColumnAttribute column = (OutputColumnAttribute)alColumns.get(i);
+ if(column!=null && column.name.equals(columnName))
+ {
+ column.align=align;
+ break;
+ }
+ }
+ }
+
+ public String getHeaderSeparator()
+ {
+ return this.headerSeparator;
+ }
+
+ public void setHeaderSeparator(String hdSeparator)
+ {
+ this.headerSeparator = hdSeparator;
+ }
+
+ public String getColumnSeparator()
+ {
+ return this.columnSeparator;
+ }
+
+ public void setColumnSeparator(String clSeparator)
+ {
+ this.columnSeparator = clSeparator;
+ }
+
+ public String getTitle()
+ {
+ return this.title;
+ }
+
+ public void setTitle(String t)
+ {
+ this.title=t;
+ }
+
+ public String getItemName()
+ {
+ return itemName;
+ }
+
+ public void setItemName(String name)
+ {
+ itemName = name;
+ }
+ public ArrayList<OutputColumnAttribute> getColumns()
+ {
+ return alColumns;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/ParallelRun.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/ParallelRun.java b/core/conn/trafci/src/main/java/org/trafodion/ci/ParallelRun.java
new file mode 100644
index 0000000..2e91975
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/ParallelRun.java
@@ -0,0 +1,1320 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.ci;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+import java.sql.ResultSet;
+import java.util.Vector;
+import sun.misc.Signal;
+import sun.misc.SignalHandler;
+
+public class ParallelRun extends Thread
+{
+
+ String scriptsDir=null;
+ String scriptsExt=null;
+ String logsDir=null;
+ boolean overwriteLogs=false;
+ int connectionCnt=2;
+ ConsoleReader crObj=null;
+ ConsoleWriter cwObj=null;
+ String summaryFile=null;
+ PrunUserInterruption pui=null;
+ Properties lfProps=null;
+ final String SCRIPT_EXT="sql";
+ int MAX_THREADS=64;
+ int MIN_THREADS=2;
+ List<String> scriptsList=null;
+ Session sessObj=null;
+ FileWriter summaryWriter=null;
+ int threadNumber=0;
+ int totalScriptFiles=0;
+ int totalScriptFilesProcessed=0;
+ int totalSQLsProcessed=0;
+ int totalSQLErrors=0;
+ int totalSQLWarnings=0;
+ int totalConnections=0;
+ int seqNo=0;
+ Utils utils=null;
+ SignalHandler CTRLCHandler=null;
+ Signal INTSignal=null;
+ boolean isUserInterrupt=false;
+ ThreadGroup prunGroup=null;
+ List<Session> activeSessionLists=null;
+ StatusThread status=null;
+ int noOfArgs=0;
+ String[] args=null;
+ HTMLObject htmlObj = null;
+ XMLObject xmlObj = null;
+ boolean errorMsg = false;
+ Writer writeObj = null;
+ PrunSummary summaryObj = new PrunSummary();
+ Query qryObj=null;
+
+ final String TIMER_DEFAULT="60";
+ int timerValue = 60;
+ long endTime = 0;
+ long nowTime = 0;
+ boolean timerMode = false;
+ List<String> scriptsListBak=null;
+ int connDelta = 0;
+
+ //Added for debugging prun
+ boolean prunDebug=false;
+
+
+ ParallelRun()
+ {
+
+ }
+
+ ParallelRun(ConsoleReader crObj, ConsoleWriter cwObj,Properties lfProps,Session sessObj) throws IOException
+ {
+ threadNumber=0;
+ this.lfProps=lfProps;
+ this.sessObj=sessObj;
+ this.htmlObj = sessObj.getHtmlObj();
+ this.xmlObj = sessObj.getXmlObj();
+ this.crObj=crObj;
+ this.cwObj=cwObj;
+ this.summaryWriter=new FileWriter();
+ pui=new PrunUserInterruption();
+ utils=new Utils();
+ writeObj = sessObj.getWriter();
+ qryObj = sessObj.getQuery();
+ CTRLCHandler =new SignalHandler ()
+ {
+ public void handle(Signal sig)
+ {
+ isUserInterrupt=true;
+ if (prunGroup != null)
+ {
+ status.beforeStatus="Cancelling";
+ status.afterStatus="Cancelled";
+ }
+ while (activeSessionLists !=null && activeSessionLists.size() > 0)
+ {
+
+ ((Session)(activeSessionLists.get(0))).setQueryInterrupted(true);
+ ((Session)(activeSessionLists.get(0))).setDBConnExists(false);
+ if (((Session)(activeSessionLists.get(0))).getCurrentStmtObj() != null)
+ {
+ try
+ {
+ ((Statement)((Session)(activeSessionLists.get(0))).getCurrentStmtObj()).cancel();
+ } catch (Exception e)
+ {
+
+ }
+ }
+ activeSessionLists.remove(0);
+ }
+ }
+ };
+ try {
+ INTSignal=new Signal("INT");
+ } catch (Exception e) {}
+
+ // get the maxservers allowed for the current datasource
+ // undocumented arg to disable calling getMaxServers(), -Dtrafci.prun.maxconn=n
+ int maxThreads=0;
+ String maxConn=System.getProperty("trafci.prun.maxconn");
+
+ try
+ {
+ if ((maxConn!=null) && ((maxThreads = Integer.parseInt(maxConn.trim() )) > MAX_THREADS ))
+ MAX_THREADS=maxThreads;
+ else
+ MAX_THREADS=getMaxServers();
+ } catch (NumberFormatException nfe)
+ {
+ this.writePrunErrors(SessionError.INVALID_MAXCONN);
+ throw nfe;
+ }
+ MIN_THREADS = MAX_THREADS == 1 ? MAX_THREADS:MIN_THREADS;
+
+ String strTimerMode = System.getProperty("trafci.prun.timermode");
+ if ((strTimerMode!=null) && strTimerMode.equalsIgnoreCase("y"))
+ {
+ timerMode=true;
+ String strConnDelta = System.getProperty("trafci.prun.connection.delta");
+ if (strConnDelta != null)
+ connDelta = Integer.parseInt(strConnDelta);
+ }
+
+ }
+
+ public void execute() throws IOException, PrunUserInterruption, InvalidNumberOfArguments, UserInterruption
+ {
+ //Signal.handle(INTSignal, CTRLCHandler);
+ String queryStr = sessObj.getQuery().getQueryText();
+ queryStr = queryStr.replaceAll("\\s+"," ").trim();
+ boolean okay = validateArgs(queryStr);
+ if (!okay)
+ {
+ throw new PrunUserInterruption();
+ }
+
+ if (noOfArgs == 1)
+ getInputs();
+ try {
+ Signal.handle(INTSignal, CTRLCHandler);
+ }catch (Exception e) {}
+
+ scriptsList=null;
+
+ scriptsList=new ArrayList<String>();
+
+ activeSessionLists=new ArrayList<Session>();
+
+ FilenameFilter filter = new FilenameFilter()
+ {
+ public boolean accept(File dir, String name)
+ {
+ if (System.getProperty("os.name").toUpperCase()
+ .startsWith("WINDOW"))
+ {
+ return name.matches("(?i).*\\." + scriptsExt +"$" );
+ }
+ else
+ {
+ return name.endsWith("."+scriptsExt);
+ }
+ }
+
+
+ };
+
+ File dir=new File(scriptsDir);
+ File[] fl=dir.listFiles(filter);
+ //String separator=File.separator;
+ for (int i=0;i< fl.length; i++)
+ {
+ scriptsList.add(fl[i].getName().toString());
+ }
+
+ prunDebug = Boolean.getBoolean("trafci.prun.debug");
+ if (scriptsList.size() == 0)
+ {
+ if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ htmlObj.init();
+ cwObj.println(htmlObj._beginTableTag);
+ cwObj.println(htmlObj._startCommentTag);
+ cwObj.println("No files present with this extension.");
+ cwObj.println(htmlObj._endCommentTag);
+ cwObj.println(htmlObj._endTableTag);
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ xmlObj.init();
+ xmlObj.handleStartTags();
+ cwObj.println(xmlObj._beginStatusTag);
+ cwObj.println(xmlObj._beginCdataTag + "No files present with this extension." + xmlObj._endCdataTag);
+ cwObj.println(xmlObj._endStatusTag);
+ xmlObj.handleEndTags();
+ }
+ else
+ {
+ cwObj.println();
+ cwObj.println("No files present with this extension.");
+ }
+ return;
+ }
+
+ scriptsListBak=new ArrayList<String>(scriptsList);
+
+ totalScriptFiles=this.scriptsList.size();
+
+ try
+ {
+ String summaryDir=logsDir+File.separator+ "error" ;
+ if (!isValid(summaryDir,"dir","write"))
+ {
+ if (new File(summaryDir).mkdir())
+ {
+ if (!isValid(summaryDir,"dir","write"))
+ {
+ summaryDir=logsDir;
+ }
+ }
+ else
+ {
+ summaryDir=logsDir;
+ }
+ }
+ summaryFile=summaryDir+File.separator+"prun.err.log";
+ String summaryTitle = "PRUN started at "+DateFormat.getDateTimeInstance().format(new Date());
+ if (!this.overwriteLogs)
+ summaryWriter.setAppend(true);
+ summaryWriter.initialize(summaryFile);
+ if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ summaryWriter.writeln(htmlObj._beginTableTag);
+ summaryWriter.writeln(htmlObj._startCommentTag + summaryTitle + htmlObj._endCommentTag);
+ summaryWriter.writeln(htmlObj._beginRowTag);
+ summaryWriter.writeln(htmlObj._beginTblHeadTag +"Scripts directory " + htmlObj._endTblHeadTag);
+ summaryWriter.writeln(htmlObj._beginTblDataTag + this.scriptsDir + htmlObj._endTblDataTag);
+ summaryWriter.writeln(htmlObj._endRowTag);
+ summaryWriter.writeln(htmlObj._beginRowTag);
+ summaryWriter.writeln(htmlObj._beginTblHeadTag +"Logs directory " + htmlObj._endTblHeadTag);
+ summaryWriter.writeln(htmlObj._beginTblDataTag + this.logsDir + htmlObj._endTblDataTag);
+ summaryWriter.writeln(htmlObj._endRowTag);
+ summaryWriter.writeln(htmlObj._beginRowTag);
+ summaryWriter.writeln(htmlObj._beginTblHeadTag +"Logs overwritten " + htmlObj._endTblHeadTag);
+ summaryWriter.writeln(htmlObj._beginTblDataTag + (this.overwriteLogs ? "y":"n") + htmlObj._endTblDataTag);
+ summaryWriter.writeln(htmlObj._endRowTag);
+ summaryWriter.writeln(htmlObj._beginRowTag);
+ summaryWriter.writeln(htmlObj._beginTblHeadTag +"Number of connections " + htmlObj._endTblHeadTag);
+ summaryWriter.writeln(htmlObj._beginTblDataTag + this.connectionCnt + htmlObj._endTblDataTag);
+ summaryWriter.writeln(htmlObj._endRowTag);
+ if (timerMode)
+ {
+ summaryWriter.writeln(htmlObj._beginRowTag);
+ summaryWriter.writeln(htmlObj._beginTblHeadTag +"Time to run (mins) " + htmlObj._endTblHeadTag);
+ summaryWriter.writeln(htmlObj._beginTblDataTag + this.timerValue + htmlObj._endTblDataTag);
+ summaryWriter.writeln(htmlObj._endRowTag);
+ }
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ summaryWriter.writeln(xmlObj._xmlNameSpaceTag);
+ summaryWriter.writeln(xmlObj._beginRootTag);
+ summaryWriter.writeln(xmlObj._beginCdataTag + summaryTitle + xmlObj._endCdataTag);
+ summaryWriter.writeln(xmlObj._beginScriptsDirTag + this.scriptsDir + xmlObj._endStriptsDirTag);
+ summaryWriter.writeln(xmlObj._beginLogsDirTag + this.logsDir + xmlObj._endLogsDirTag);
+ summaryWriter.writeln(xmlObj._beginLogsO + (this.overwriteLogs ? "y":"n") + xmlObj._endLogsO);
+ summaryWriter.writeln(xmlObj._beginConnTag + this.connectionCnt + xmlObj._endConnTag);
+ if (timerMode)
+ summaryWriter.writeln(xmlObj._beginMinTag + this.timerValue + xmlObj._endMinTag);
+
+ }
+ else
+ {
+ summaryWriter.write((utils.formatString("=",80,'=')));
+ summaryWriter.writeln();
+ summaryWriter.write(summaryTitle);
+ summaryWriter.writeln();
+ summaryWriter.write((utils.formatString("=",80,'=')));
+ summaryWriter.writeln();
+ summaryWriter.writeln();
+ summaryWriter.writeln("Scripts directory: "+this.scriptsDir);
+ summaryWriter.writeln("Logs directory: "+this.logsDir);
+ summaryWriter.writeln("Logs overwritten: "+ (this.overwriteLogs ? "y":"n") );
+ summaryWriter.writeln("Number of connections: "+this.connectionCnt);
+ if (timerMode)
+ {
+ summaryWriter.writeln("Time to run (mins): "+this.timerValue);
+ summaryWriter.writeln("Connection delay (secs): "+this.connDelta);
+ }
+ if (prunDebug)
+ {
+ summaryWriter.writeln();
+ }
+
+ }
+ }
+ catch (IOException ioe)
+ {
+ cwObj.println("Could not create the summary file.");
+ return;
+ }
+
+
+ prunGroup=new ThreadGroup("prgroup");
+ Thread prunThread=null;
+
+ status = new StatusThread(cwObj, sessObj);
+
+ // start the status thread
+ if (cwObj.getConsoleOut())
+ status.start();
+
+ if (this.connectionCnt > totalScriptFiles)
+ {
+ this.connectionCnt=totalScriptFiles;
+ }
+
+ sessObj.setQryStartTime();
+ for (int i=1; i <= this.connectionCnt ; i++)
+ {
+ if (this.scriptsList.size()== 0 || this.isUserInterrupt)
+ break;
+ prunThread =new Thread(prunGroup,this);
+ prunThread.setName("Thread"+i);
+ prunThread.start();
+
+ try
+ {
+ Thread.sleep(connDelta * 1000);
+
+ } catch (InterruptedException ie)
+ {
+ }
+
+ }
+ //this.start();
+
+ //Lets wait for all child threads to complete before proceeding further
+ Thread[] activeLists= new Thread[prunGroup.activeCount()];
+ int activeCounts=prunGroup.enumerate(activeLists);
+ for (int t=0;t < activeCounts; t++)
+ {
+ try
+ {
+ activeLists[t].join();
+ } catch (InterruptedException e)
+ {
+
+ }
+ }
+
+ // this loop is not required but need
+ while (prunGroup.activeCount() > 0)
+ {
+ status.stop=false;
+ }
+
+
+ status.stop=true;
+
+ if (cwObj.getConsoleOut())
+ {
+ try
+ {
+ status.join();
+ } catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ //e.printStackTrace();
+ }
+ while (status.isAlive())
+ {
+
+ }
+ }
+
+ summaryObj.setTotalScriptFiles(this.totalScriptFiles);
+ summaryObj.setTotalScriptFilesProcessed(this.totalScriptFilesProcessed);
+ summaryObj.setTotalSQLsProcessed(this.totalSQLsProcessed);
+ summaryObj.setTotalSQLErrors(this.totalSQLErrors);
+ summaryObj.setTotalSQLWarnings(this.totalSQLWarnings);
+ summaryObj.setTotalConnections(this.totalConnections);
+ summaryObj.setTotalSQLSuccess(this.totalSQLsProcessed - this.totalSQLErrors);
+ summaryObj.setTotalConnectionFailures(this.connectionCnt - this.totalConnections);
+
+ sessObj.setQryEndTime();
+ String elapsedTime = writeObj.getElapsedTime(sessObj,qryObj,utils);
+ if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ sessObj.getXmlObj().handlePrunSummary(cwObj,summaryObj, elapsedTime);
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ sessObj.getHtmlObj().handlePrunSummary(cwObj,summaryObj, elapsedTime);
+ }
+ else
+ {
+ cwObj.println();
+ cwObj.println("\t"+utils.formatString("_",45,'_'));
+ cwObj.println("\t"+utils.formatString(" PARALLELRUN(PRUN) SUMMARY",45,' '));
+ cwObj.println("\t"+utils.formatString("_",45,'_'));
+ cwObj.println("\t"+utils.formatString("Total files present ",45,'.',""+this.totalScriptFiles));
+ cwObj.println("\t"+utils.formatString("Total files processed ",45,'.',""+(this.totalScriptFilesProcessed)));
+ cwObj.println("\t"+utils.formatString("Total queries processed ",45,'.',""+this.totalSQLsProcessed));
+ cwObj.println("\t"+utils.formatString("Total errors ",45,'.',""+this.totalSQLErrors));
+ cwObj.println("\t"+utils.formatString("Total warnings ",45,'.',""+this.totalSQLWarnings));
+ cwObj.println("\t"+utils.formatString("Total successes ",45,'.',""+(this.totalSQLsProcessed-this.totalSQLErrors)));
+ cwObj.println("\t"+utils.formatString("Total connections ",45,'.',""+ (this.totalConnections) ));
+ cwObj.println("\t"+utils.formatString("Total connection failures ",45,'.',""+ (connectionCnt-this.totalConnections) ));
+ cwObj.println(SessionDefaults.lineSeperator + writeObj.getElapsedTime(sessObj,qryObj,utils));
+ cwObj.println();
+ }
+ if (this.totalSQLErrors > 0)
+ {
+ String errorLogInfo = "Please verify the error log file " + summaryFile + " for error summary.";
+ cwObj.println(formatSummaryStr(errorLogInfo));
+ }
+ endPrunConsoleTags();
+
+ if ((this.totalScriptFiles - this.scriptsList.size()) == 0)
+ {
+ String errorMsgStr = "";
+ if (errorMsg)
+ errorMsgStr = "No script files have been processed. See preceeding error message(s).";
+ else
+ errorMsgStr = "No script files have been processed successfully.";
+
+ summaryWriter.writeln(formatSummaryStr(errorMsgStr));
+ }
+ else if ((this.totalScriptFiles - this.scriptsList.size()) < this.totalScriptFiles)
+ {
+ String scriptFileMsg ="";
+ if (errorMsg)
+ scriptFileMsg = "Not all script files have been processed successfully. See preceeding error message(s).";
+ else
+ scriptFileMsg = "Not all script files have been processed successfully.";
+
+ summaryWriter.writeln(formatSummaryStr(scriptFileMsg));
+ }
+ else
+ {
+ String finalMsg = "";
+ if (errorMsg)
+ {
+ finalMsg = "All the script files have been processed successfully. See preceeding error message(s).";
+ }
+ else if (this.totalSQLErrors == 0)
+ {
+ finalMsg = "All the script files have been processed successfully.";
+ }
+
+ summaryWriter.writeln(formatSummaryStr( finalMsg));
+ }
+
+ String summaryEnd = "PRUN completed at " + DateFormat.getDateTimeInstance().format(new Date());
+
+
+ if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ sessObj.getXmlObj().handlePrunSummary(summaryWriter, summaryObj, summaryEnd, elapsedTime);
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ sessObj.getHtmlObj().handlePrunSummary(summaryWriter,summaryObj, summaryEnd, elapsedTime);
+ }
+ else
+ {
+ summaryWriter.writeln();
+ summaryWriter.writeln("\t"+utils.formatString("_",45,'_'));
+ summaryWriter.writeln("\t"+utils.formatString(" PARALLELRUN(PRUN) SUMMARY",45,' '));
+ summaryWriter.writeln("\t"+utils.formatString("_",45,'_'));
+ summaryWriter.writeln("\t"+utils.formatString("Total files present ",45,'.',""+this.totalScriptFiles));
+ summaryWriter.writeln("\t"+utils.formatString("Total files processed ",45,'.',""+(this.totalScriptFilesProcessed)));
+ summaryWriter.writeln("\t"+utils.formatString("Total queries processed ",45,'.',""+this.totalSQLsProcessed));
+ summaryWriter.writeln("\t"+utils.formatString("Total errors ",45,'.',""+this.totalSQLErrors));
+ summaryWriter.writeln("\t"+utils.formatString("Total warnings ",45,'.',""+this.totalSQLWarnings));
+ summaryWriter.writeln("\t"+utils.formatString("Total successes ",45,'.',""+(this.totalSQLsProcessed-this.totalSQLErrors)));
+ summaryWriter.writeln("\t"+utils.formatString("Total connections ",45,'.',""+ (this.totalConnections) ));
+ summaryWriter.writeln("\t"+utils.formatString("Total connection failures ",45,'.',""+ (connectionCnt-this.totalConnections) ));
+ summaryWriter.writeln();
+ summaryWriter.write((utils.formatString("=",80,'=')));
+ summaryWriter.writeln();
+ summaryWriter.write(summaryEnd);
+ summaryWriter.write(" " + elapsedTime);
+ summaryWriter.writeln();
+ summaryWriter.write((utils.formatString("=",80,'=')));
+ summaryWriter.writeln();
+ }
+
+ this.summaryWriter.close();
+ errorMsg = false;
+ }
+
+ private void getInputs() throws IOException, PrunUserInterruption, UserInterruption
+ {
+ cwObj.print(utils.formatString("Enter * as input to stop the current prun session",50,' '));
+ cwObj.println();
+ cwObj.println(utils.formatString("-",50,'-'));
+ cwObj.println();
+
+ while (true)
+ {
+ this.scriptsDir=getInput("Enter the scripts directory :",null);
+
+ if (isValid(scriptsDir,"dir","read"))
+ {
+ scriptsDir = this.getCanonicalPath(scriptsDir);
+ break;
+ }
+ cwObj.println(SessionError.DIR_NOT_FOUND.errorMessage());
+ cwObj.println();
+
+ }
+
+ this.scriptsExt=getInput("Enter the script file extension["+SCRIPT_EXT+"] :",SCRIPT_EXT);
+
+ while (true)
+ {
+ this.logsDir=getInput("Enter the logs directory[scripts dir] :",this.scriptsDir);
+
+ if (isValid(logsDir,"dir","write"))
+ {
+ logsDir = this.getCanonicalPath(logsDir);
+ break;
+ }
+ cwObj.println(SessionError.DIR_NOT_FOUND.errorMessage());
+ cwObj.println();
+
+ }
+
+ while (true)
+ {
+ String overWriteVal=getInput("Overwrite the log files (y/n)[n]? :","n");
+ if (overWriteVal.equalsIgnoreCase("y"))
+ {
+ this.overwriteLogs=true;
+ break;
+ }
+ else if (overWriteVal.equalsIgnoreCase("n"))
+ {
+ this.overwriteLogs=false;
+ break;
+ }
+ else
+ {
+ cwObj.println(SessionError.INCORRECT_OVERWRITE_OPTION.errorMessage());
+ cwObj.println();
+ }
+
+ }
+
+ while (true)
+ {
+ String connValue=getInput("Enter the number of connections("+ MIN_THREADS + "-" + utils.formatString(MAX_THREADS+")["+MIN_THREADS+"]",8,' ')+":",""+MIN_THREADS);
+ try
+ {
+ this.connectionCnt=Integer.parseInt(connValue);
+ if (this.connectionCnt >= MIN_THREADS && this.connectionCnt <= MAX_THREADS)
+ {
+ break;
+ }
+ cwObj.println(SessionError.PRUN_CONN_CNT_ERR.errorMessage());
+ cwObj.println();
+
+ }catch (NumberFormatException nfe)
+ {
+ cwObj.println("Invalid value specified for connections."+SessionDefaults.lineSeperator);
+ }
+
+ }
+
+ if (timerMode)
+ {
+ while (true)
+ {
+ String strTimerValue=getInput("Enter the time to run in minutes (0=single interation) ["+TIMER_DEFAULT+"]:",TIMER_DEFAULT); //0=run to completion
+ try
+ {
+
+ timerValue= Integer.parseInt(strTimerValue);
+
+ if (timerValue >= 0)
+ {
+ if (timerValue > 0)
+ {
+ this.endTime = (timerValue*1000*60) + System.currentTimeMillis();
+ timerMode=true;
+ }
+ else
+ timerMode=false;
+
+ break;
+ }
+
+ cwObj.println("Invalid timer value");
+ cwObj.println();
+
+ }
+ catch (NumberFormatException nfe)
+ {
+
+ }
+
+ } //end while
+ }
+
+
+ }
+
+ private boolean isValid(String input,String type, String permissions)
+ {
+ if (input != null)
+ {
+ File file=new File(input);
+
+ if (!file.exists())
+ {
+ return false;
+ }
+ if ("dir".equals(type) && !file.isDirectory())
+ {
+ return false;
+ }
+ else if ("file".equals(type) && file.isDirectory())
+ {
+ return false;
+ }
+
+ if (("read".equals(permissions)) && !file.canRead())
+ {
+ return false;
+ }
+ if (("write".equals(permissions)) && !file.canWrite())
+ {
+ return false;
+ }
+ return true;
+
+ }
+ return false;
+ }
+
+ private String getInput(String requestString,String defaultVal) throws IOException, PrunUserInterruption, UserInterruption
+ {
+
+ cwObj.print((utils.formatString(requestString,46,' ')));
+ String input=crObj.getLine();
+ if ((input == null || input.trim().equals("")) && defaultVal != null)
+ {
+ input=defaultVal;
+ }
+ else if (input != null)
+ {
+ input=input.trim();
+ }
+ if ((input != null && input.equals("*")) || isUserInterrupt)
+ {
+ throw pui;
+ }
+
+ return input;
+ }
+
+ /*
+ * Gets the number of connection available for parallelload
+ * the maxthread value is set by the return value of this method
+ */
+ int getMaxServers()
+ {
+ boolean moreResults=false;
+ int defaultservercnt=MAX_THREADS;
+ Statement statement=null;
+ try
+ {
+ if ((statement=sessObj.getStmtObj()) != null)
+ {
+ moreResults=statement.execute("cfgcmd:INFO DS "+sessObj.getSessionDsn());
+ }
+
+ if (moreResults)
+ {
+ ResultSet resultSet=statement.getResultSet();
+ if (resultSet.next())
+ defaultservercnt=resultSet.getInt("MAX_SRVR_CNT");
+
+ }
+ }
+ catch (SQLException sqle)
+ {
+ //printAllExceptions(sqle);
+ }
+ return defaultservercnt;
+
+ }
+
+
+ public void run()
+ {
+
+ SessionInterface shareObj=new SessionInterface();
+ Session sessObjt=null;
+ ErrorObject errObj=null;
+ StringBuffer errBuf = new StringBuffer();
+ String threadName=currentThread().getName();
+ String logFile=null;
+ ArrayList<Vector<String>> errArr = new ArrayList<Vector<String>>();
+ Vector<String> errVec=null;
+
+
+ try
+ {
+ sessObjt=new Session( this.sessObj.getSessionUser(),
+ this.sessObj.getSessionPass(),
+ this.sessObj.getSessionRole(),
+ this.sessObj.getSessionServer(),
+ this.sessObj.getSessionPort(),
+ this.sessObj.getSessionDsn(),
+ crObj,
+ cwObj);
+ // copy the required values from the main session
+ sessObjt.setSessionCtlg(this.sessObj.getSessionCtlg());
+ sessObjt.setSessionSchema(this.sessObj.getSessionSchema());
+ sessObjt.setSessionSQLTerminator(this.sessObj.getSessionSQLTerminator());
+ sessObjt.setSessionPrompt(this.sessObj.getPrompt());
+ sessObjt.setSessionTiming(this.sessObj.isSessionTimingOn());
+ sessObjt.setSessionTime(this.sessObj.isSessionTimeOn());
+ sessObjt.setSessionColSep(this.sessObj.getSessionColSep());
+ sessObjt.setListCount(this.sessObj.getListCount());
+ sessObjt.setStrDisplayFormat(this.sessObj.getStrDisplayFormat());
+ sessObjt.setMxosrvrVersion(this.sessObj.getMxosrvrVersion());
+ sessObjt.setSutVersion(this.sessObj.getSutVersion());
+ sessObjt.setT4verNum(sessObj.getT4verNum());
+ sessObjt.setSessionAutoPrepare(sessObj.isSessionAutoPrepare());
+ sessObjt.setSessionStatsEnabled(sessObj.isSessionStatsEnabled());
+
+ sessObjt= shareObj.createSession(sessObjt, 1, false);
+
+ } catch (FileNotFoundException e)
+ {
+ errObj=SessionError.SCRIPT_FILE_NOT_FOUND;
+ return;
+ } catch (SQLException e)
+ {
+ if (e.getErrorCode() == SessionDefaults.SQL_ERR_CONN_MAX_LIMIT)
+ {
+ errObj=SessionError.CONN_MAX_LIMIT_ERR;
+ }else
+ {
+ errObj = new ErrorObject(e.toString(), e.getErrorCode());
+ }
+
+ return;
+ } catch (InstantiationException e)
+ {
+ errObj=SessionError.DRIVER_INIT_ERR;
+ return;
+ } catch (IllegalAccessException e)
+ {
+ errObj=SessionError.DRIVER_INIT_ILLEGAL_ERR;
+ return;
+ } catch (ClassNotFoundException e)
+ {
+ errObj=SessionError.DRIVER_CLASS_ERR;
+ return;
+ } catch (IOException e)
+ {
+ errObj=new ErrorObject(SessionError.INTERNAL_ERR, "", " "+e.toString());
+ return;
+ }
+ finally
+ {
+ if (this.isUserInterrupt)
+ {
+ try
+ {
+
+ if (sessObjt.getConnObj() != null)
+ {
+ sessObjt.getConnObj().close();
+ }
+ } catch (SQLException e)
+ {
+ //
+ }
+ sessObjt.setConnObj(null);
+ shareObj=null;
+ return;
+ }
+ if (errObj != null)
+ {
+ synchronized(this)
+ {
+ //if(this.summaryWriter !=null)
+ //this.summaryWriter.write(" Failed");
+ try
+ {
+ this.summaryWriter.writeln();
+ this.summaryWriter.writeln(DateFormat.getDateTimeInstance().format(new Date()) + " An error occurred in "+threadName+" when connecting to the database: "+errObj.errorMessage());
+ errorMsg = true;
+ } catch (IOException e)
+ {
+
+ }
+ }
+ }
+ synchronized(this)
+ {
+ activeSessionLists.add(sessObjt);
+ }
+
+
+ } //end finally
+
+ this.totalConnections++;
+ //cwObj.println("\nConnection made for "+threadName);
+
+ while (true)
+ {
+
+ if (timerMode && ((nowTime=System.currentTimeMillis()) >= endTime))
+ {
+ //cwObj.println("\n" + threadName + " run time reached, terminating ...");
+ break;
+ }
+
+ logFile=null;
+ synchronized(this.scriptsList)
+ {
+ if (this.scriptsList.size() > 0)
+ {
+
+ if (this.isUserInterrupt)
+ {
+ break;
+ }
+ String fileName=this.scriptsList.get(0).toString();
+ logFile=fileName+".log";
+ shareObj.setLogFile(this.logsDir+File.separator+logFile,this.overwriteLogs);
+ shareObj.setScriptFile(this.scriptsDir+File.separator+fileName);
+ this.scriptsList.remove(0);
+ this.totalScriptFilesProcessed++;
+ //debug information, prints the thread name and the script file it picks up for processing
+ if (prunDebug ){
+ try
+ {
+ String debugMsg = DateFormat.getDateTimeInstance().format(new Date()) + ": Thread " + threadName + " processing " + shareObj.getScriptFile();
+ if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ this.summaryWriter.writeln(xmlObj._beginCdataTag + debugMsg + xmlObj._endCdataTag);
+ else if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ this.summaryWriter.writeln(htmlObj._startCommentTag + debugMsg + htmlObj._endCommentTag);
+ else
+ this.summaryWriter.writeln( debugMsg );
+ } catch (IOException ioEx)
+ {
+ }
+ }
+
+ }
+ else
+ { // no more files to process
+
+ if (timerMode)
+ {
+ this.scriptsList.addAll(this.scriptsListBak);
+ //cwObj.println("List addAll");
+ continue;
+ }
+
+ break;
+ }
+ }
+ try
+ {
+ int sqlerrCnt=shareObj.getSqlErrorCount();
+ int sqlQueryCnt=shareObj.getSqlQueryCount();
+ int sqlWarningsCnt=shareObj.getSqlWarningsCount();
+ shareObj.invokeSession(sessObjt);
+ //if there are any error occurred in the current file ..write them in to the errBuf
+ if (shareObj.getSqlErrorCount() > sqlerrCnt || shareObj.getSqlWarningsCount() > sqlWarningsCnt)
+ {
+ errVec = new Vector<String>();
+ String scriptSqls=""+(shareObj.getSqlQueryCount() - sqlQueryCnt);
+ String scriptErrs=""+(shareObj.getSqlErrorCount() - sqlerrCnt);
+ String scriptWarns=""+(shareObj.getSqlWarningsCount() - sqlWarningsCnt);
+ if (sessObj.getDisplayFormat() == SessionDefaults.RAW_FORMAT || sessObj.getDisplayFormat() == SessionDefaults.CSV_FORMAT)
+ {
+ errBuf.append(utils.formatString(logFile,65,' ',"")+" "+utils.formatString("",10,' ',""+scriptSqls)+" "+utils.formatString("",7,' ',""+scriptErrs)+" "+utils.formatString("",10,' ',""+scriptWarns));
+ errBuf.append("####");
+ }
+ else
+ {
+ errVec.add(0,logFile);
+ errVec.add(1,scriptSqls);
+ errVec.add(2, scriptErrs);
+ errVec.add(3, scriptWarns);
+ errArr.add(errVec);
+ }
+
+ }
+ } catch (IOException e)
+ {
+ // where to write this exception
+ }
+ }
+ try
+ {
+ //if(sessObjt.getConnObj() != null)
+ sessObjt.getConnObj().close();
+ sessObjt.setConnObj(null);
+ }catch (SQLException sqle)
+ {
+
+ }finally
+ {
+ sessObjt.setConnObj(null);
+ synchronized(this)
+ {
+ //this.totalScriptFilesProcessed++;
+ int sqlerrors=this.totalSQLErrors;
+ int sqlwarnings=this.totalSQLWarnings;
+ boolean isErrHeadPrinted=true;
+ this.totalSQLErrors+=shareObj.getSqlErrorCount();
+ this.totalSQLWarnings+=shareObj.getSqlWarningsCount();
+ if ((sqlerrors == 0 && this.totalSQLErrors != 0) ||
+ (sqlwarnings == 0 && this.totalSQLWarnings !=0) )
+ {
+ isErrHeadPrinted=false;
+ }
+ this.totalSQLsProcessed+=shareObj.getSqlQueryCount();
+ try
+ {
+ if (!isErrHeadPrinted)
+ {
+ if (sessObj.getDisplayFormat() == SessionDefaults.RAW_FORMAT || sessObj.getDisplayFormat() == SessionDefaults.CSV_FORMAT)
+ {
+
+ this.summaryWriter.writeln();
+ this.summaryWriter.writeln("Check the following log files for the detailed error message.");
+ this.summaryWriter.writeln(utils.formatString("-",4+65+27+8,'-')); // 65 - size of the log file name + 27 - size of the remaining fields + 6 - spaces between the heading columns
+ this.summaryWriter.writeln(utils.formatString("Seq#",4,' ',"")+" "+utils.formatString("Log File Name",65,' ',"")+" "+utils.formatString("",10,' ',"Total Qrys")+" "+utils.formatString("",7,' ',"Errors")+" "+utils.formatString("",10,' ',""+"Warnings"));
+ this.summaryWriter.writeln(utils.formatString("-",4+65+27+8,'-',""));
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ this.summaryWriter.writeln(htmlObj._beginRowTag);
+ this.summaryWriter.writeln(htmlObj._beginTblHeadTag + "Seq # " + htmlObj._endTblHeadTag);
+ this.summaryWriter.writeln(htmlObj._beginTblHeadTag + "Logfile " + htmlObj._endTblHeadTag);
+ this.summaryWriter.writeln(htmlObj._beginTblHeadTag + "Total Qrys" + htmlObj._endTblHeadTag);
+ this.summaryWriter.writeln(htmlObj._beginTblHeadTag + "Errors" + htmlObj._endTblHeadTag);
+ this.summaryWriter.writeln(htmlObj._beginTblHeadTag + "Warnings" + htmlObj._endTblHeadTag);
+ this.summaryWriter.writeln(htmlObj._endRowTag);
+ }
+ isErrHeadPrinted=true;
+ }
+
+ if (errBuf.length() > 0)
+ {
+ int newLineIdx=-1;
+
+ while ((newLineIdx=errBuf.indexOf("####")) != -1)
+ {
+ this.seqNo++;
+ this.summaryWriter.writeln(utils.formatString("",4,' ',this.seqNo+"")+" "+errBuf.substring(0,newLineIdx).toString());
+ errBuf.delete(0,newLineIdx+4);
+ }
+ }
+ else
+ {
+ for (int i=0; i< errArr.size();i++)
+ {
+ Vector<String> vect = errArr.get(i);
+ this.seqNo++;
+ if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ this.summaryWriter.writeln(xmlObj._beginSeqIdTag + this.seqNo + xmlObj._endAttributeTag);
+ this.summaryWriter.writeln(xmlObj._beginLogFileNameTag + vect.get(0).trim() + xmlObj._endLogFileNameTag);
+ this.summaryWriter.writeln(xmlObj._beginTotalSqlsTag + vect.get(1).trim() + xmlObj._endTotalSqlsTag);
+ this.summaryWriter.writeln(xmlObj._beginTotalErrors + vect.get(2).trim() + xmlObj._endTotalErrors);
+ this.summaryWriter.writeln(xmlObj._beginTotalWarnings + vect.get(3).trim() +xmlObj._endTotalWarnings);
+ this.summaryWriter.writeln(xmlObj._endSeqIdTag);
+ }
+ else if ((sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT))
+ {
+ this.summaryWriter.writeln(htmlObj._beginRowTag);
+ this.summaryWriter.writeln(htmlObj._beginTblDataAlignTag + this.seqNo + htmlObj._endTblDataTag);
+ this.summaryWriter.writeln(htmlObj._beginTblDataTag + vect.get(0) + htmlObj._endTblDataTag);
+ this.summaryWriter.writeln(htmlObj._beginTblDataAlignTag +vect.get(1) + htmlObj._endTblDataTag);
+ this.summaryWriter.writeln(htmlObj._beginTblDataAlignTag + vect.get(2)+ htmlObj._endTblDataTag);
+ this.summaryWriter.writeln(htmlObj._beginTblDataAlignTag + vect.get(3) + htmlObj._endTblDataTag);
+ this.summaryWriter.writeln(htmlObj._endRowTag);
+ }
+ }
+ }
+ errBuf=null;
+ } catch (IOException e)
+ {
+
+ }
+ }
+ }
+ sessObjt=null;
+
+
+
+ } //end run
+
+ public boolean validateArgs(String query) throws InvalidNumberOfArguments, IOException
+ {
+ if (query.endsWith(sessObj.getSessionSQLTerminator()))
+ {
+ query = query.substring(0, query.length()-sessObj.getSessionSQLTerminator().length());
+ }
+
+ setArgs(query.split(" "));
+
+ if (noOfArgs == 1)
+ return true;
+
+ if (sessObj.isDebugOn())
+ System.out.println("No.of args :: " + noOfArgs);
+ if (noOfArgs > 11)
+ {
+ //writeObj.writeln();
+ throw new InvalidNumberOfArguments();
+ }
+
+ //Set defaults for non-interactive mode
+ scriptsDir=System.getProperty("user.dir");
+ scriptsExt = SCRIPT_EXT;
+ connectionCnt = MIN_THREADS;
+
+ for (int i=1; i < noOfArgs; i++)
+ {
+ String value = null;
+ String option=this.args[i++].trim();
+
+ if (i < noOfArgs)
+ {
+ value=this.args[i].trim();
+ }
+ else
+ {
+ if (!option.equalsIgnoreCase("-d") && !option.equalsIgnoreCase("-defaults"))
+ {
+ //writeObj.writeln();
+ throw new InvalidNumberOfArguments();
+ }
+ }
+
+ if (option.equalsIgnoreCase("-sd")|| option.equalsIgnoreCase("-scriptsdir"))
+ {
+ scriptsDir=this.getCanonicalPath(value);
+ }
+ else if (option.equalsIgnoreCase("-e")|| option.equalsIgnoreCase("-extension"))
+ {
+ scriptsExt=value;
+ }
+ else if (option.equalsIgnoreCase("-ld")|| option.equalsIgnoreCase("-logsdir"))
+ {
+ logsDir=this.getCanonicalPath(value);
+ }
+ else if (option.equalsIgnoreCase("-o")|| option.equalsIgnoreCase("-overwrite"))
+ {
+ if (value.equalsIgnoreCase("y"))
+ {
+ this.overwriteLogs=true;
+ }
+ else if (value.equalsIgnoreCase("n"))
+ {
+ this.overwriteLogs=false;
+ }
+ else
+ {
+ this.writePrunErrors(SessionError.INCORRECT_OVERWRITE_OPTION);
+ return false;
+ }
+ }
+ else if (option.equalsIgnoreCase("-c")|| option.equalsIgnoreCase("-connections"))
+ {
+ try
+ {
+ connectionCnt = Integer.parseInt(value);
+ } catch (NumberFormatException nfe)
+ {
+ this.writePrunErrors(SessionError.INVALID_CONN_VALUE);
+ return false;
+ }
+ }
+ else if (option.equalsIgnoreCase("-m")|| option.equalsIgnoreCase("-minutes"))
+ {
+ if (!timerMode)
+ {
+ this.writePrunErrors(new ErrorObject(SessionError.UNKOWN_OPTION, "" ,option));
+ //If not in XML, HTML, or CSV markup mode, display help usage.
+ if(sessObj.getDisplayFormat() == SessionDefaults.RAW_FORMAT)
+ printUsage();
+ return (false);
+ }
+
+ timerValue = Integer.parseInt(value);
+
+ }
+ else if (option.equalsIgnoreCase("-d")|| option.equalsIgnoreCase("-defaults"))
+ {
+ if (noOfArgs > 2)
+ {
+ this.writePrunErrors(SessionError.DEFAULT_OPTION_ERR);
+ //If not in XML, HTML, or CSV markup mode, display help usage.
+ if(sessObj.getDisplayFormat() == SessionDefaults.RAW_FORMAT)
+ printUsage();
+ return (false);
+ }
+ }
+ else
+ {
+ this.writePrunErrors(new ErrorObject(SessionError.UNKOWN_OPTION.errorCode(),SessionError.UNKOWN_OPTION.errorMessage()+ option));
+ //If not in XML, HTML, or CSV markup mode, display help usage.
+ if(sessObj.getDisplayFormat() == SessionDefaults.RAW_FORMAT)
+ printUsage();
+ return (false);
+ }
+
+ } //end for
+
+ if (!isValid(scriptsDir,"dir","read"))
+ {
+ this.writePrunErrors(SessionError.SCRIPTS_DIR_NOT_FOUND);
+ return (false);
+ }
+
+ if (logsDir == null)
+ logsDir = scriptsDir;
+ else if (!isValid(logsDir,"dir","read"))
+ {
+ this.writePrunErrors(SessionError.LOGS_DIR_NOT_FOUND);
+ return (false);
+ }
+
+ if (connectionCnt < MIN_THREADS || connectionCnt > MAX_THREADS)
+ {
+ this.writePrunErrors(SessionError.PRUN_CONN_CNT_ERR);
+ return (false);
+ }
+
+ if (timerMode)
+ {
+ if (timerValue > 0)
+ {
+ endTime= (timerValue * 1000*60) + System.currentTimeMillis();
+ }
+ else if (timerValue < 0)
+ {
+ cwObj.println("Invalid timer value");
+ cwObj.println();
+ return (false);
+ }
+ else //timerValue=0
+ {
+ cwObj.println(SessionDefaults.lineSeperator+"Timer mode ignored, -m is 0"+SessionDefaults.lineSeperator);
+ timerMode = false;
+ }
+
+ }
+
+ if (cwObj.getConsoleOut())
+ {
+ cwObj.println(SessionDefaults.lineSeperator+"PRUN options are -scriptsdir " + scriptsDir +
+ SessionDefaults.lineSeperator+" -logsdir " + logsDir +
+ SessionDefaults.lineSeperator+" -extension " + scriptsExt +
+ SessionDefaults.lineSeperator+" -overwrite " + (this.overwriteLogs ? "y":"n") +
+ SessionDefaults.lineSeperator+" -connections " + connectionCnt);
+
+ if (timerMode)
+ cwObj.println(SessionDefaults.lineSeperator+" -minutes " + timerValue );
+ }
+
+ return (true);
+
+
+ } //end validateArgs
+
+ private void setArgs(String[] args)
+ {
+ noOfArgs=args.length;
+ this.args=args;
+ }
+
+ private String getCanonicalPath(String fileName)
+ {
+ File file = new File(fileName);
+
+ try
+ {
+ return (file.getCanonicalPath());
+ }catch (IOException io)
+ {
+
+ }
+ return (fileName);
+ }
+
+ public void printUsage() throws IOException
+ {
+ writeObj.writeln();
+ writeObj.writeln("prun -sd|scriptsdir <directory-name> -e|extension <extension> ");
+ writeObj.writeln(" -ld|logsdir <directory-name> -o|overwrite {y|n} ");
+ writeObj.writeln(" -c|connections <no-of-connections>" );
+ if (timerMode)
+ writeObj.writeln(" -m|minutes <no-of-minutes>" );
+
+ writeObj.writeln();
+ writeObj.writeln("\t----- OR -----");
+ writeObj.writeln();
+ writeObj.writeln("prun -d|defaults");
+ writeObj.writeln();
+ writeObj.writeln("where:");
+ writeObj.writeln("\t-defaults \tspecifies default values for all the options.");
+ writeObj.writeln("\t-scriptsdir \tspecifies the directory containing the script files.");
+ writeObj.writeln("\t-extension \tspecifies the extension of script files.");
+ writeObj.writeln("\t-logsdir \tspecifies the directory where logs files are created.");
+ writeObj.writeln("\t-overwrite \tspecifies if the log files have to be overwritten.");
+ writeObj.writeln("\t-connections \tspecifies the number of connections.");
+ if (timerMode)
+ {
+ writeObj.writeln("\t-minutes \tspecifies the time to run test.");
+ writeObj.writeln();
+ writeObj.writeln("\t[ optional property -Dtrafci.prun.connection.delta=n ]");
+ }
+ }
+
+ private String formatSummaryStr(String msg)
+ {
+ String summaryStr = null;
+ if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ summaryStr = xmlObj._beginCdataTag + msg + xmlObj._endCdataTag;
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ summaryStr = htmlObj._startCommentTag + msg + htmlObj._endCommentTag;
+ }
+ else
+ {
+ summaryStr = "\t" + msg + SessionDefaults.lineSeperator;
+ }
+ return summaryStr;
+ }
+
+ private void writePrunErrors(ErrorObject prunError) throws IOException
+ {
+ if(sessObj.getDisplayFormat() != SessionDefaults.XML_FORMAT)
+ writeObj.writeln();
+
+ writeObj.writeInterfaceErrors(this.sessObj, prunError);
+ }
+
+ private void endPrunConsoleTags()
+ {
+ if (sessObj.getDisplayFormat() == SessionDefaults.XML_FORMAT)
+ {
+ cwObj.println(xmlObj._endRootTag);
+ xmlObj._beginRootElement = false;
+ }
+ else if (sessObj.getDisplayFormat() == SessionDefaults.HTML_FORMAT)
+ {
+ cwObj.println(htmlObj._endTableTag);
+ htmlObj._startTags = false;
+ }
+ }
+
+} //end class
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/ParamStringObject.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/ParamStringObject.java b/core/conn/trafci/src/main/java/org/trafodion/ci/ParamStringObject.java
new file mode 100644
index 0000000..263b98a
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/ParamStringObject.java
@@ -0,0 +1,256 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+package org.trafodion.ci;
+
+
+import java.io.UnsupportedEncodingException;
+
+
+
+/**
+ * Implementation of a CI or SQL parameter value.
+ *
+ *
+ */
+public class ParamStringObject {
+
+
+ /**
+ * Member variables containing the charset name, is hexadecimal value and
+ * actual parameter value string specified.
+ */
+ private String _charsetName = null;
+ private String _hexPrefixStr = null;
+ private String _inputValue = null;
+
+
+ /**
+ * Boolean flag indicating whether or not the input value is in hex.
+ */
+ private boolean _isHexInput = false;
+
+
+
+ /**
+ * Default Parameter value constructor.
+ *
+ * @param charsetName The character set name
+ * @param hexInput Prefix if the parameter value is in hex (x'')
+ * @param theValue The actual parameter value
+ *
+ * @since R2.4 SP2
+ *
+ */
+ public ParamStringObject(String charsetName, String hexInputPrefix,
+ String theValue) {
+ this._charsetName = charsetName;
+ this._hexPrefixStr = hexInputPrefix;
+ this._inputValue = theValue;
+
+ if (null != this._hexPrefixStr) {
+ this._hexPrefixStr = this._hexPrefixStr.trim();
+
+ if (this._hexPrefixStr.toLowerCase().equals("x") )
+ this._isHexInput = true;
+
+ }
+
+
+ } /* End of ParamStringValue Constructor. */
+
+
+
+ /**
+ * Returns the character set name specified for this parameter value.
+ *
+ * @return the SQL character set name
+ *
+ */
+ public String getCharacterSetName() {
+ return this._charsetName;
+
+ } /* End of getCharacterSetName method. */
+
+
+
+ /**
+ * Returns the evaluated parameter value -- any hex input is converted.
+ *
+ * @return the evaluated parameter value.
+ * @since R2.4 SP2
+ *
+ */
+ public String getParameterValue() throws Exception {
+ /**
+ * Trim out the quotes.
+ */
+ String theInput = this._inputValue.trim();
+ if (theInput.startsWith("'") && theInput.endsWith("'") )
+ theInput = theInput.substring(1, theInput.length() - 1);
+
+
+ /**
+ * If its plain and simple text -- return it as is.
+ */
+ if (!this._isHexInput)
+ return theInput;
+
+
+ /**
+ * For hexadecimal values, trim out the spaces inside the quotes.
+ */
+ theInput = theInput.trim();
+
+
+ /**
+ * Okay its a hexadecimal stream that we need to convert.
+ */
+ String[] inputBits = theInput.split(" ");
+ String retValue = "";
+ int lengthOfInputByte = 0;
+ for (int i = 0; i < inputBits.length; i++) {
+ if (inputBits[i].length() % 2 == 1)
+ throw new Exception("'" + theInput + "' is not a valid "
+ + "character encoding value. ");
+ lengthOfInputByte += inputBits[i].length() / 2;
+ }
+ byte[] inputByte = new byte[lengthOfInputByte];
+ int inputPos = 0;
+
+ for (int idx = 0; idx < inputBits.length; idx++) {
+ String aChunk = inputBits[idx];
+ int length = aChunk.length() & -4;
+ if (this._charsetName == null
+ || (!this._charsetName.equalsIgnoreCase("_UCS2") && !this._charsetName
+ .equalsIgnoreCase("_UTF8"))) {
+ do {
+ String bitVal = aChunk;
+ if (4 < aChunk.length() ) {
+ bitVal = aChunk.substring(0, 4);
+ aChunk = aChunk.substring(4, aChunk.length() );
+ } else
+ aChunk = "";
+
+ try {
+ int val = Integer.parseInt(bitVal, 16);
+
+ byte b1 = (byte) (val & 0xFF);
+ byte b2 = (byte) ((val >> 8) & 0xFF);
+ byte b3 = (byte) ((val >> 16) & 0xFF);
+ byte b4 = (byte) ((val >> 24) & 0xFF);
+
+ if ((0 != b4) || (0 != b3) )
+ retValue += new String(new byte[] { b4, b3, b2, b1 } );
+ else if (0 != b2)
+ retValue += new String(new byte[] { b2, b1 } );
+ else
+ retValue += new String(new byte[] { b1 });
+ } catch(Exception e) {
+ throw new Exception("'" + inputBits[idx]
+ + "' is not a valid " + "hexadecimal value. ");
+ }
+ } while (0 < aChunk.length() );
+ }/**
+ * for UTF-8
+ * modify to fix the defect CRID1331
+ */
+ else if (this._charsetName.equalsIgnoreCase("_UTF8")) {
+ for (int pos = 0; pos < aChunk.length(); pos += 2) {
+ try {
+ int val = Integer.parseInt(
+ aChunk.substring(pos, pos + 2), 16);
+ inputByte[inputPos++] = (byte) (val & 0xFF);
+ } catch (NumberFormatException NF_Ex) {
+ throw new Exception("'" + aChunk + "' is not a valid "
+ + "hexadecimal value. ");
+ }
+ //when it comes to the end of the bits, convert it
+ if (idx == inputBits.length - 1
+ && pos == aChunk.length() - 2)
+ try {
+ retValue = new String(inputByte, "UTF8");
+ } catch (UnsupportedEncodingException e) {
+ throw new Exception(
+ "The input hexadecimal is not a valid UTF-8 hexadecimal value. ");
+ }
+ }
+ }else{ // UCS2
+ /**
+ * set Param is used to set ucs2 values. CI gives wrong data
+ * Internal Analysis: by shifting all low bits to right causes UCS2 hex
+ * to get the first byte chopped off & turn into invalid character
+ * Fix Description: simply convert hex values to String
+ */
+ for ( int pos=0; pos < length; pos += 4) {
+ int this_char = 0;
+ try {
+ this_char = Integer.parseInt( aChunk.substring( pos,pos+4), 16);
+ }
+ catch ( NumberFormatException NF_Ex) {
+ throw new Exception("'"
+ + aChunk + "' is not a valid " + "hexadecimal value. ");
+ }
+ retValue += (char) this_char;
+ }
+ }
+ } /* End of FOR loop for all the parts in the input. */
+
+ return retValue;
+
+ } /* End of getParameterValue method. */
+
+
+
+
+ /**
+ * Returns the Stringified form of this parameter value.
+ *
+ * @return the stringified form of this parameter value.
+ * @since R2.4 SP2
+ *
+ */
+ public String toString() {
+ String theValue = null;
+
+ if (null != this._charsetName)
+ theValue = this._charsetName.toUpperCase();
+
+ if (null == theValue)
+ theValue = this._hexPrefixStr;
+ else if (null != this._hexPrefixStr)
+ theValue += " " + this._hexPrefixStr;
+
+
+ if (null == theValue)
+ theValue = this._inputValue;
+ else
+ theValue += this._inputValue;
+
+ return theValue;
+
+ } /* End of toString method. */
+
+
+
+} /* End of class ParamStringValue. */
+
+