Author: azeez
Date: Mon Dec 3 06:56:38 2007
New Revision: 10442
Log:
Merging the WSAS 2.1 branch to the trunk
Added:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Result.java
- copied unchanged from r10353,
branches/wsas/java/2.1/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Result.java
Modified:
trunk/commons/data-services/pom.xml
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/ExcelQuery.java
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
Modified: trunk/commons/data-services/pom.xml
==============================================================================
--- trunk/commons/data-services/pom.xml (original)
+++ trunk/commons/data-services/pom.xml Mon Dec 3 06:56:38 2007
@@ -5,7 +5,7 @@
<groupId>org.wso2.dataservice</groupId>
<artifactId>wso2data-service</artifactId>
<packaging>jar</packaging>
- <version>SNAPSHOT</version>
+ <version>2.1-SNAPSHOT</version>
<name>WSO2 Data Service</name>
<url>http://wso2.org</url>
<description>WSO2 Data Services</description>
@@ -178,6 +178,35 @@
</plugins>
</build>
+
+ <profiles>
+ <profile>
+ <activation>
+ <property>
+ <name>sign</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.0-alpha-3</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
<properties>
<axis2.version>1.3</axis2.version>
<axiom.version>1.2.5</axiom.version>
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
Mon Dec 3 06:56:38 2007
@@ -19,6 +19,7 @@
import javax.xml.namespace.QName;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
public class CallQuery {
@@ -93,7 +94,13 @@
String type = DBDeployer.getJavaTypeFromSQLType(sqlType);
QueryElement inputElement = new QueryElement();
inputElement.setClassType(type);
- inputElement.setName(name);
+
+ //String withParamName = getExternalParameterName(queryElement,
paramsPerCallQueryMap, name);
+ //if(withParamName != null){
+ // inputElement.setName(withParamName);
+ //}else{
+ inputElement.setName(name);
+ //}
addInputParms(inputElement);
}
OMElement sqlQuery = queryElement.getFirstChildWithName(new
QName("sql"));
@@ -123,4 +130,18 @@
}
}
+
+ private String getExternalParameterName(OMElement queryElement,
+ HashMap paramsPerCallQueryMap, String name) {
+ String withParamName = null;
+ String queryId = queryElement.getAttributeValue(new QName("id"));
+ HashMap callQueryParamNames =
(HashMap)paramsPerCallQueryMap.get(queryId);
+ if(callQueryParamNames != null){
+ withParamName = (String) callQueryParamNames.get(name);
+ }
+ return withParamName;
+ }
+
+
+
}
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
Mon Dec 3 06:56:38 2007
@@ -67,21 +67,23 @@
public static final String DATASOURCE_TYPE_JNDI= "JNDI";
+ //same values are present in data_service.js & data_service.xsl.If you
change any value here,
+ //make sure you change those files as well.
public interface Query{
//CSV query parameters
String CSV = "csv";
String EXCEL = "excel";
- String HAS_HEADER = "hasHeader";
- String STARTING_ROW = "startingRow";
- String MAX_ROW_COUNT = "maxRowCount";
+ String HAS_HEADER = "hasheader";
+ String STARTING_ROW = "startingrow";
+ String MAX_ROW_COUNT = "maxrowcount";
String COLUMNS = "columns";
String COLUMN = "column";
//CSV query parameters
- String CSV_COLUMN_SEPERATOR = "columnSeperator";
- String CSV_COLUMN_ORDER = "columnOrdinal";
+ String CSV_COLUMN_SEPERATOR = "columnseperator";
+ String CSV_COLUMN_ORDER = "columnordinal";
//excel query parameters
- String EXCEL_WORKBOOK_NAME = "workBookName";
+ String EXCEL_WORKBOOK_NAME = "workbookname";
}
public interface JNDI{
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
Mon Dec 3 06:56:38 2007
@@ -232,8 +232,7 @@
dataSourceType =
DBConstants.DATASOURCE_TYPE_JNDI;
}
String propValue = (String) props.get(propName);
- axisService.addParameter(new Parameter(propName,
propValue));
- }
+ axisService.addParameter(new Parameter(propName,
propValue)); }
}
//connection properties are added to Axis Service.
//Lets create the connect & put it to AxisConfiguration
@@ -246,11 +245,9 @@
} else {
throw new AxisFault("Could not establish a connection
to database.");
}
- } catch (SQLException e1) {
- throw new AxisFault(e1.getMessage());
- } catch (ClassNotFoundException e1) {
- throw new AxisFault(e1.getMessage());
- }
+ } catch (AxisFault e1) {
+ throw e1;
+ }
}else if(dataSourceType.equals(DBConstants.DATASOURCE_TYPE_JNDI)){
Connection dbConnection =
JNDIUtils.createConnection(axisService);
if (dbConnection != null) {
@@ -269,12 +266,19 @@
// Get all query elements & put them into a hashmap with id as the
// key
Iterator queries = configElement.getChildrenWithName(new
QName("query"));
+
+ //This contains map of parameters passed along with query href
+ //HashMap paramsPerCallQueryMap = new HashMap();
+ //extractParamsPerCallQuery(configElement, queries,
+ // paramsPerCallQueryMap);
+
HashMap queryMap = new HashMap();
while (queries.hasNext()) {
OMElement queryElement = (OMElement) queries.next();
String queryId = queryElement.getAttributeValue(new
QName("id"));
queryMap.put(queryId, queryElement);
CallQuery callQuery = new CallQuery();
+
//callQuery.populateCallQuery(queryElement,paramsPerCallQueryMap);
callQuery.populateCallQuery(queryElement);
callQueryMap.put(queryId,callQuery);
}
@@ -309,11 +313,12 @@
operation));
axisService.addOperation(axisOperation);
- //gettin the query element
+ //getting the query element
OMElement callQuery = operation.getFirstChildWithName(new
QName("call-query"));
String hrefVal = callQuery.getAttributeValue(new
QName("href"));
OMElement query = (OMElement) queryMap.get(hrefVal);
CallQuery callQueryElement = new CallQuery();
+
//callQueryElement.populateCallQuery(query,paramsPerCallQueryMap);
callQueryElement.populateCallQuery(query);
//creating a parameter to hold query object
@@ -347,6 +352,47 @@
schemaGenerator.generateSchema();
return axisService;
}
+
+
+ /*
+ * map populated here (paramsPerCallQueryMap) will be used to get user
+ * defined parameter name for web service operation
+ */
+ private void extractParamsPerCallQuery(OMElement configElement,
+ Iterator queries, HashMap paramsPerCallQueryMap) {
+ Iterator operations = configElement.getChildrenWithName(new
QName("operation"));
+ while(operations.hasNext()){
+ OMElement operationElement = (OMElement) operations.next();
+ Iterator callQueries = operationElement.getChildrenWithName(new
QName("call-query"));
+ if(callQueries != null){
+ //there can be only one call-query per operation
+ Object obj = null;
+ while(callQueries.hasNext()){
+ obj = callQueries.next();
+ if(obj instanceof OMElement){
+ break;
+ }
+ }
+ if(obj != null){
+ OMElement callQuery = (OMElement)obj;
+
+ Iterator withParams = callQuery.getChildrenWithName(new
QName("with-param"));
+
+ //this hashmap holds following key, value pairs
+ //<with-param name="id" query-param="deptId"/>
+ HashMap paramNameWithQueryParam = new HashMap();
+ while(withParams.hasNext()){
+ OMElement withParam = (OMElement)withParams.next();
+ String paramName = withParam.getAttributeValue(new
QName("name"));
+ String queryParam = withParam.getAttributeValue(new
QName("query-param"));
+ paramNameWithQueryParam.put(paramName,queryParam);
+ }
+ String callQueryRef = callQuery.getAttributeValue(new
QName("href"));
+
paramsPerCallQueryMap.put(callQueryRef,paramNameWithQueryParam);
+ }
+ }
+ }
+ }
public static String getJavaTypeFromSQLType(String sqlType) {
HashMap convertionMap = getConversionTable();
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
Mon Dec 3 06:56:38 2007
@@ -47,8 +47,9 @@
}
newmsgContext.setEnvelope(envelope);
- } catch (Exception e) {
- throw AxisFault.makeFault(e);
+ } catch (AxisFault e) {
+ //throw AxisFault.makeFault(e);
+ throw e;
}
}
}
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
Mon Dec 3 06:56:38 2007
@@ -15,19 +15,25 @@
*/
package org.wso2.ws.dataservice;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.PrintWriter;
import java.io.Reader;
+import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
+import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
@@ -58,6 +64,7 @@
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.wso2.ws.dataservice.beans.CSVQuery;
import org.wso2.ws.dataservice.beans.ExcelQuery;
+import org.wso2.ws.dataservice.beans.Result;
import au.com.bytecode.opencsv.CSVReader;
@@ -91,10 +98,10 @@
OMElement callQueryElement =
operationElement.getFirstChildWithName(new
QName("call-query"));
- return getResult(callQueryElement, axisService, inputs);
+ return getRDBMSResult(callQueryElement, axisService, inputs);
}
- private static OMElement getResult(OMElement callQueryElement,
AxisService axisService,
+ private static OMElement getRDBMSResult(OMElement callQueryElement,
AxisService axisService,
HashMap inputs) {
OMElement resultElement = null;
OMElement queryElement ;
@@ -146,19 +153,80 @@
resultElement =
getSelectResult(queryElement, inputs,
params, paramOrder, axisService, false);
}
-
-// } else {
-// // eg: DROP statement, stored procedure call
-// throw new UnsupportedOperationException("The SQL " +
query
-// + " is not supported yet..");
-// }
} catch (Exception e) {
- e.printStackTrace();
- }
-
+ if(e instanceof AxisFault){
+ return
generateErrorResponse(axisService.getTargetNamespace(), (AxisFault)e);
+ }
+ }
return resultElement;
}
+ /*
+ * Generates an response containing fault element.
+ * Fault element contains two elements(code & detail)
+ */
+ private static OMElement generateErrorResponse(String
targetNamespace,AxisFault e){
+ //get stackTrace into a String
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ e.printStackTrace(pw);
+
+
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMNamespace omNs = fac.createOMNamespace(targetNamespace,
"data");
+
+ OMElement resultElement = fac.createOMElement("data", omNs);
+ //TODO : read from query/fault
+ OMElement faultElement = fac.createOMElement("fault",null);
+
+ OMElement codeElement = fac.createOMElement("code", omNs);
+ codeElement.setText(e.getMessage());
+ OMElement detailElement = fac.createOMElement("detail", omNs);
+ detailElement.setText(sw.toString());
+
+ faultElement.addChild(codeElement);
+ faultElement.addChild(detailElement);
+ resultElement.addChild(faultElement);
+ return resultElement;
+ }
+
+// private static void getDefaultValuesForResultsWrapper(String
wrapperElementName,String rowElementName){
+// if(wrapperElementName == null || wrapperElementName.trim().length()
== 0){
+// //default value
+// wrapperElementName = "results";
+// }
+// if(rowElementName == null || rowElementName.trim().length() == 0){
+// //default value
+// rowElementName = "row";
+// }
+// }
+
+ /*
+ * For RDBMS & JNDI connections re-establishing connection, if existing
connection is closed.
+ */
+ private static Connection checkDBConnectionStatus(AxisService
axisService,Connection conn) throws AxisFault{
+ if(log.isDebugEnabled()){
+ log.debug("checking database connection status");
+ }
+ if(
DBConstants.DATASOURCE_TYPE_RDBMS.equals((String)axisService.getParameterValue(DBConstants.DATASOURCE_TYPE))
+ ||
DBConstants.DATASOURCE_TYPE_JNDI.equals((String)axisService.getParameterValue(DBConstants.DATASOURCE_TYPE))){
+ try {
+ if(conn.isClosed()){
+ if(log.isDebugEnabled()){
+ log.debug("Database connection is closed.Trying to
re-establish.");
+ }
+ return createConnection(axisService);
+ }else{
+ //existing connection is not closed. Return it.
+ return conn;
+ }
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to re-establish the
database connection.", e);
+ throw new AxisFault("Error occurred while trying to
re-establish the database connection.",e);
+ }
+ }
+ return null;
+ }
private static OMElement getSelectResult(OMElement queryElement,
HashMap inputValues,
HashMap params, HashMap paramOrder, AxisService
axisService, boolean isDML)
throws AxisFault {
@@ -168,9 +236,10 @@
try {
Parameter dbConnectionParam =
axisService.getParameter(DBConstants.DB_CONNECTION);
if(dbConnectionParam == null){
- throw new AxisFault("Database connection not
found in AxisConfiguration");
+ throw new AxisFault("Database connection not
found in Axis Configuration");
}
conn = (Connection)dbConnectionParam.getValue();
+ conn = checkDBConnectionStatus(axisService, conn);
conn.setAutoCommit(false);
PreparedStatement preparedStatement =
getProcessedPreparedStatement(inputValues,
params, paramOrder, conn, sqlQuery);
@@ -183,30 +252,54 @@
}
OMElement result =
queryElement.getFirstChildWithName(new QName("result"));
- String wrapperElementName =
result.getAttributeValue(new QName("element"));
- String rowElementName = result.getAttributeValue(new
QName("rowName"));
+ Result resultObj = new Result(result);
+// String wrapperElementName =
result.getAttributeValue(new QName("element"));
+// String rowElementName = result.getAttributeValue(new
QName("rowName"));
+//
+// //if wrapper element || row element is not set, set
default values to them
+// if(wrapperElementName == null ||
wrapperElementName.trim().length() == 0){
+// //default value
+// wrapperElementName = "results";
+// }
+// if(rowElementName == null || rowElementName.trim().length() ==
0){
+// //default value
+// rowElementName = "row";
+// }
+
+ //TODO : need to define a way to get values automatically
+
//getDefaultValuesForResultsWrapper(wrapperElementName,rowElementName);
// check ??
String columnDefalut = result.getAttributeValue(new
QName("columnDefault"));
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs =
fac.createOMNamespace(axisService.getTargetNamespace(), "data");
- resultElement = fac.createOMElement(wrapperElementName,
omNs);
+ resultElement =
fac.createOMElement(resultObj.getResultWrapper(), omNs);
if (isDML) {
resultElement
.setText("Your query executed successfully.
Return code from the database was "
+ responseCode);
} else {
+ //check if wrapper element should be qualified
if ( !axisService.isElementFormDefault()) {
omNs =fac.createOMNamespace("",
"data");
}
+
+ //put result elements into an array
+ Iterator tmpElements = result.getChildElements();
+ ArrayList tmpElementsArrayList = new ArrayList();
+ while(tmpElements.hasNext()){
+ OMElement element = (OMElement) tmpElements.next();
+ tmpElementsArrayList.add(element);
+ }
+
while (rs.next()) {
HashMap elementValues = new HashMap();
int columnCount =
rs.getMetaData().getColumnCount();
- OMElement row =
fac.createOMElement(rowElementName, omNs);
- if (rowElementName == null) {
+ OMElement row =
fac.createOMElement(resultObj.getRowName(), omNs);
+ if (resultObj.getRowName() == null) {
row = resultElement;
}
for (int i = 1; i <= columnCount; i++) {
@@ -215,22 +308,26 @@
elementValues.put(columnName,
columnValue);
}
- Iterator elements =
result.getChildElements();
+ //Iterator elements =
result.getChildElements();
boolean useAsParamToNextQuery = false;
- while (elements.hasNext()) {
- OMElement element = (OMElement)
elements.next();
- if
(element.getLocalName().equals("element")) {
- String displayTagName =
element.getAttributeValue(new QName("name"));
- String
resultSetFieldName =
-
element.getAttributeValue(new QName("column"));
+ //while (elements.hasNext()) {
+ for(int a=0;a <
resultObj.getDisplayColumnNames().length;a++){
+ //OMElement element =
(OMElement) elements.next();
+ if
(resultObj.getElementLocalNames()[a].equals("element")) {
+ //String displayTagName
= element.getAttributeValue(new QName("name"));
+ String displayTagName =
resultObj.getDisplayColumnNames()[a];
+ //String
resultSetFieldName = element.getAttributeValue(new QName("column"));
+ String resultSetFieldName =
resultObj.getResultSetColumnNames()[a];
// This means,the
parameter is not part of the
// resultset. i.e. it
is being passed from user's
// parameters.
- if (resultSetFieldName
== null) {
-
resultSetFieldName = element.getAttributeValue(new QName("param"));
-
useAsParamToNextQuery = true;
- }
+
+ //TODO **********
+// if (resultSetFieldName ==
null) {
+//
resultSetFieldName = element.getAttributeValue(new QName("param"));
+//
useAsParamToNextQuery = true;
+// }
String elementValue;
if
(useAsParamToNextQuery) {
@@ -247,21 +344,25 @@
} else if
(columnDefalut.equals("attribute")) {
row.addAttribute(displayTagName, elementValue, omNs);
}
- } else if
(element.getLocalName().equals("call-query")) {
- OMElement rowElement =
getResult(element, axisService, elementValues);
+ } else if
(resultObj.getElementLocalNames()[a].equals("call-query")) {
+ //OMElement element = (OMElement)
elements.next();
+ OMElement element =
(OMElement)tmpElementsArrayList.get(a);
+ OMElement rowElement =
getRDBMSResult(element, axisService, elementValues);
row.addChild(rowElement);
}
}
- if (rowElementName != null) {
+ if (resultObj.getRowName() != null) {
resultElement.addChild(row);
}
}
}
} catch (SQLException e) {
- log.error(e.getMessage());
- throw new AxisFault("Exception occurred while trying to
execute the SQL statement.", e);
+ log.error("Exception occurred while trying to execute the
SQL statement : "+sqlQuery, e);
+ throw new AxisFault("Exception occurred while trying to
execute the SQL statement : "+sqlQuery, e);
}
+
+
// finally {
// try {
// if (conn != null) {
@@ -276,7 +377,7 @@
return resultElement;
}
- public static OMElement invoke(MessageContext msgContext){
+ public static OMElement invoke(MessageContext msgContext) throws
AxisFault{
AxisOperation axisOp = msgContext.getAxisOperation();
AxisService axisService = msgContext.getAxisService();
OMElement inputMessage =
msgContext.getEnvelope().getBody().getFirstElement();
@@ -289,7 +390,7 @@
else
if(DBConstants.DATASOURCE_TYPE_EXCEL.equals((String)axisService.getParameterValue(DBConstants.DATASOURCE_TYPE))){
return processExcelQuery(operationElement, axisService,
inputMessage);
}
- else{//default is RDBMS
+ else{//default is RDBMS (JNDI Data source falls under this too)
return DBUtils.processSQLQuery(operationElement,
axisService, inputMessage);
}
}
@@ -308,25 +409,33 @@
return true;
}catch(ClassNotFoundException e){
- throw new AxisFault("Library not found for :
"+libraryName);
+ log.error("Library not found for : "+libraryName,e);
+ throw new AxisFault("Library not found for :
"+libraryName,e);
}
}
private synchronized static OMElement processExcelQuery(OMElement
operationElement, AxisService axisService,
- OMElement inputMessage){
+ OMElement inputMessage) throws AxisFault{
String excelFilePath =
(String)axisService.getParameterValue(DBConstants.EXCEL_DATASOURCE);
- log.info("Using Excel file from : "+excelFilePath);
+ log.info("Using Excel file from : "+excelFilePath);
- boolean errorOccured = false;
- String errorMessage = "";
+ InputStream dataSourceInputStream = null;
try
{
//check for POI library
checkLibraryAvailability("POI");
- POIFSFileSystem fs;
- HSSFWorkbook wb;
- fs = new POIFSFileSystem(new
FileInputStream(excelFilePath));
+ POIFSFileSystem fs;
+ HSSFWorkbook wb;
+
+ if(excelFilePath.startsWith("http://")){
+ //This is a url file path
+ URL url = new URL(excelFilePath);
+ dataSourceInputStream = url.openStream();
+ }else{
+ dataSourceInputStream = new
FileInputStream(excelFilePath);
+ }
+ fs = new POIFSFileSystem(dataSourceInputStream);
wb = new HSSFWorkbook(fs);
OMElement callQueryElement =
@@ -344,27 +453,21 @@
return getExcelResult(wb,queryElement,axisService);
}catch (FileNotFoundException e1) {
- errorOccured = true;
- errorMessage = e1.getMessage();
- e1.printStackTrace();
- }catch (AxisFault e) {
- errorOccured = true;
- errorMessage = e.getMessage();
- e.printStackTrace();
- } catch (IOException e) {
- errorOccured = true;
- errorMessage = e.getMessage();
- e.printStackTrace();
+ log.error("Excel file not fould : "+excelFilePath, e1);
+ throw new AxisFault("Excel file not fould :
"+excelFilePath);
+ }
+ catch (IOException e) {
+ log.error("Error loading Excel file : "+excelFilePath, e);
+ throw new AxisFault("Error loading Excel file :
"+excelFilePath);
}finally{
- if(errorOccured){
- OMFactory fac =
OMAbstractFactory.getOMFactory();
- OMNamespace omNs =
fac.createOMNamespace(axisService.getTargetNamespace(), "data");
- OMElement resultElement =
fac.createOMElement("error", omNs);
- resultElement.setText(errorMessage);
- return resultElement;
+ if(dataSourceInputStream != null){
+ try {
+ dataSourceInputStream.close();
+ } catch (IOException e) {
+ log.debug("Error occured while close
InputStream for : "+excelFilePath, e);
+ }
}
}
- return null;
}
@@ -373,8 +476,8 @@
, AxisService axisService)throws AxisFault {
OMElement resultElement = null;
- OMElement excelElement = queryElement.getFirstChildWithName(new
QName("excel"));
- ExcelQuery excelQuery = new ExcelQuery(axisService);
+ //OMElement excelElement =
queryElement.getFirstChildWithName(new QName("excel"));
+ ExcelQuery excelQuery = new
ExcelQuery(axisService,queryElement);
OMElement result = queryElement.getFirstChildWithName(new
QName("result"));
String wrapperElementName = result.getAttributeValue(new
QName("element"));
@@ -394,6 +497,10 @@
//this is used to skip header columns, the spread sheet
int startReadingFromRow = excelQuery.getStartingRow();
+ if(startReadingFromRow >= 0){
+ //rows start from 0
+ startReadingFromRow = startReadingFromRow -1;
+ }
int maxRowCount = excelQuery.getMaxRowCount();
HSSFSheet sheet = wb.getSheet(sheetName);
@@ -434,12 +541,30 @@
//get the column number
using specified name
columnNumber =
getExcelColumnNumber(columnValue,firstRow);
}else{
- columnNumber =
(short)(Short.valueOf(columnValue).shortValue()- a);
+ try{
+ columnNumber =
(short)(Short.valueOf(columnValue).shortValue()- a);
+
}catch(NumberFormatException e){
+ log.error("Column
value for element : "+displayTagName +" should be a number.",e);
+ throw new
AxisFault("Column value for element : "+displayTagName +" should be a number.");
+ }
+
}
- //TODO : throw a meaningful
exception if columnNo is not a number
HSSFCell hssfCell =
hssfRow.getCell(columnNumber);
- String elementValue =
hssfCell.getRichStringCellValue().getString();
+ String elementValue = "";
+ if(hssfCell != null){
+ if
(HSSFCell.CELL_TYPE_STRING == hssfCell.getCellType()){
+ elementValue =
hssfCell.getRichStringCellValue().getString();
+ }else
if(HSSFCell.CELL_TYPE_BLANK == hssfCell.getCellType()){
+ //do nothing
+ }else
if(HSSFCell.CELL_TYPE_BOOLEAN == hssfCell.getCellType()){
+ elementValue =
String.valueOf(hssfCell.getBooleanCellValue());
+ }else
if(HSSFCell.CELL_TYPE_FORMULA == hssfCell.getCellType()){
+ elementValue =
"{formula}";
+ }else
if(HSSFCell.CELL_TYPE_NUMERIC == hssfCell.getCellType()){
+ elementValue =
String.valueOf(hssfCell.getNumericCellValue());
+ }
+ }
if (columnDefalut == null ||
columnDefalut.equals("element")) {
OMElement rowElement =
fac.createOMElement(displayTagName, omNs);
@@ -459,104 +584,117 @@
return resultElement;
}
- private static short getExcelColumnNumber(String columnName,HSSFRow
headerRow){
+ private static short getExcelColumnNumber(String columnName,HSSFRow
headerRow)
+ throws AxisFault{
int noOfCells = headerRow.getPhysicalNumberOfCells();
short columnNo = -1;
for(int a = 0;a <noOfCells;a++){
HSSFCell cell = headerRow.getCell((short)a);
- if(cell.getCellType() == cell.CELL_TYPE_STRING){
+ if(HSSFCell.CELL_TYPE_STRING == cell.getCellType()){
if(columnName.equals(cell.getRichStringCellValue().getString())){
columnNo = (short)a;
break;
}
- }else{
- //TODO : should we allow numeric type column
headers
-
+ }else if(HSSFCell.CELL_TYPE_NUMERIC ==
cell.getCellType()){
+ try{
+ double columnNameInDouble =
Double.valueOf(columnName).doubleValue();
+ if(columnNameInDouble ==
cell.getNumericCellValue()){
+ columnNo = (short)a;
+ break;
+ }
+ }catch(NumberFormatException e){
+ log.error("Numeric value expected for
Column Name : "+columnName, e);
+ throw new AxisFault("Numeric value
expected for Column Name : "+columnName, e);
+ }
}
}
return columnNo;
}
- private synchronized static OMElement processCSVQuery(OMElement
operationElement, AxisService axisService,
- OMElement inputMessage) {
-
- String csvFilePath =
(String)axisService.getParameterValue(DBConstants.CSV_DATASOURCE);
- log.info("Using CSV file from : "+csvFilePath);
+ private synchronized static OMElement processCSVQuery(
+ OMElement operationElement, AxisService axisService,
+ OMElement inputMessage) throws AxisFault{
+
+ String csvFilePath = (String) axisService
+ .getParameterValue(DBConstants.CSV_DATASOURCE);
+ log.info("Using CSV file from : " + csvFilePath);
CSVReader reader = null;
+ InputStreamReader inputStreamReader = null;
try {
- if(csvFilePath.startsWith("http://")){
- //This is a url file path
+ if (csvFilePath.startsWith("http://")) {
+ // This is a url file path
URL url = new URL(csvFilePath);
- InputStreamReader inputStreamReader = new
InputStreamReader(url.openStream());
- reader = new CSVReader(inputStreamReader);
- }else{
- //local file
- reader = new CSVReader(new
FileReader(csvFilePath));
+ inputStreamReader = new
InputStreamReader(url.openStream());
+ reader = new CSVReader(inputStreamReader);
+ } else {
+ if(csvFilePath.startsWith("."+File.separator)
+ ||
csvFilePath.startsWith(".."+File.separator)){
+ //this is relative path
+ File csvFile = new File(csvFilePath);
+ csvFilePath = csvFile.getAbsolutePath();
+ log.info("relative file path reference found.
Using "+csvFilePath+" as absolute path.");
+ }
+ // local file
+ reader = new CSVReader(new
FileReader(csvFilePath));
}
+ OMElement callQueryElement = operationElement
+ .getFirstChildWithName(new
QName("call-query"));
+ // Find the corresponding query element
+ String href = callQueryElement.getAttributeValue(new
QName("href"));
+ OMElement queryElement;
+ if (href != null) {
+ HashMap queries = (HashMap) axisService
+
.getParameterValue(DBConstants.DB_QUERY_ELEMENTS);
+ queryElement = (OMElement) queries.get(href);
+ } else {
+ queryElement = callQueryElement
+ .getFirstChildWithName(new
QName("query"));
+ }
+
+ try {
+ return getCSVResult(reader, queryElement,
axisService);
+ } catch (AxisFault e) {
+ throw e;
+ /*
+ OMElement resultElement = null;
+ OMFactory fac =
OMAbstractFactory.getOMFactory();
+ OMNamespace omNs =
fac.createOMNamespace(axisService
+ .getTargetNamespace(), "data");
+ resultElement =
fac.createOMElement("csvoutput", omNs);
+ resultElement.setText(e.getMessage());
+ return resultElement;
+ */
+ }
} catch (FileNotFoundException e) {
- //TODO : throw axis fault
- e.printStackTrace();
+ log.error("CSV file not found : "+csvFilePath,e);
+ throw new AxisFault("CSV file not found :
"+csvFilePath,e);
} catch (MalformedURLException e) {
- //TODO : throw axis fault
- e.printStackTrace();
- } catch (IOException e) {
- //TODO : throw axis fault
- e.printStackTrace();
+ log.error("Incorrect URL : "+csvFilePath,e);
+ throw new AxisFault("Incorrect URL : "+csvFilePath,e);
}
-
- OMElement callQueryElement =
- operationElement.getFirstChildWithName(new
QName("call-query"));
- // Find the corresponding query element
- String href = callQueryElement.getAttributeValue(new
QName("href"));
- OMElement queryElement;
- if (href != null) {
- HashMap queries =
- (HashMap)
axisService.getParameterValue(DBConstants.DB_QUERY_ELEMENTS);
- queryElement = (OMElement) queries.get(href);
- } else {
- queryElement =
callQueryElement.getFirstChildWithName(new QName("query"));
- }
-
-
- try {
- return getCSVResult(reader,queryElement,axisService);
- } catch (AxisFault e) {
- e.printStackTrace();
- //TODO do proper error handling
- OMElement resultElement = null;
- OMFactory fac = OMAbstractFactory.getOMFactory();
- OMNamespace omNs =
fac.createOMNamespace(axisService.getTargetNamespace(), "data");
- resultElement = fac.createOMElement("csvoutput", omNs);
- resultElement.setText(e.getMessage());
- return resultElement;
+ catch (IOException e) {
+ log.error("Error opening stream for : "+csvFilePath, e);
+ throw new AxisFault("Error opening stream for :
"+csvFilePath, e);
+ }
+ finally{
+ if(inputStreamReader != null){
+ try {
+ inputStreamReader.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
}
private static OMElement getCSVResult(CSVReader reader,OMElement
queryElement, AxisService axisService)
throws AxisFault {
OMElement resultElement = null;
-
//Extract CSV Query Parameters
- OMElement csv = queryElement.getFirstChildWithName(new
QName(DBConstants.Query.CSV));
-
-
CSVQuery csvQuery = new CSVQuery(axisService);
- //OMElement csvColumns = csv.getFirstChildWithName(new
QName(DBConstants.Query.COLUMNS));
-
- //Iterator columnItr = csvColumns.getChildrenWithName(new
QName(DBConstants.Query.COLUMN));
-
-
- //HashMap columns = new HashMap();
- //ArrayList columns = new ArrayList();
- //for (Iterator iterator = columnItr; iterator.hasNext();) {
- // String column = ((OMElement)iterator.next()).getText();
- // columns.put(column,column);
- //columns.add(column);
- //}
-
//compute number of rows to read
int start = csvQuery.getStartingRow();
int end = csvQuery.getMaxRowCount();
@@ -567,7 +705,10 @@
}else{
noOfRowsToRead = end;
}
-
+
+ if(start >= 0){
+ start = start -1;
+ }
//Extract how result to be formatted
OMElement result = queryElement.getFirstChildWithName(new
QName("result"));
@@ -603,9 +744,10 @@
columnNumbersToRead[index] = b;
index++;
}
- }
+ }
} catch (IOException e) {
+ log.error("Error reading header record",e);
throw new AxisFault("Error reading header
record",e);
}
}else{
@@ -618,8 +760,10 @@
colNo = csvQuery.getColumnNames()[a];
columnNumbersToRead[a] =
Integer.valueOf(colNo).intValue();
}catch (NumberFormatException e){
+ log.error("When headers are set to false,
you need to have " +
+ "numeric value for column.Incorrect value found :
"+colNo,e);
throw new AxisFault("When headers are
set to false, you need to have " +
- "numeric value for
column.Incorrect value found : "+colNo);
+ "numeric value for
column.Incorrect value found : "+colNo,e);
}
}
}
@@ -627,6 +771,13 @@
try {
int processedRowCount = 0;
while ((nextLine = reader.readNext()) != null) {
+ //work-a-round for lines with spaces
+ //Array size for this line is 1 (i.e no
separators/commas)
+ if(nextLine.length == 1){
+ if(nextLine[0] == null ||
nextLine[0].trim().equals("")){
+ continue;
+ }
+ }
if(noOfRowsToRead != -1){
if((processedRowCount+start) ==
(noOfRowsToRead+start)){
break;
@@ -635,8 +786,7 @@
if(start > (processedRowCount + 1)){
processedRowCount++;
continue;
- }
-
+ }
HashMap elementValues = new HashMap();
int columnCount =
csvQuery.getColumnNames().length;
@@ -646,9 +796,14 @@
row = resultElement;
}
for (int i = 0; i < columnCount; i++) {
- int columnNo = columnNumbersToRead[i];
- //String columnName =
String.valueOf(columnNo);
- String columnValue =
nextLine[columnNo]; //Columns start from 0
+ int columnNo = columnNumbersToRead[i];
+ String columnValue = "";
+ try{
+ columnValue =
nextLine[columnNo];
+ }catch(ArrayIndexOutOfBoundsException
e){
+ log.info("Reading row :
"+(processedRowCount+1) +".No value found " +
+ "for column no
: "+columnNo+".Empty value will be printed.",e);
+ }
elementValues.put(new
Integer(columnNo), columnValue);
}
@@ -664,12 +819,14 @@
try{
columnRef =
Integer.valueOf(columnReference).intValue();
}catch(NumberFormatException e){
+ log.error("Column value
specified "+ columnReference
+ + " for "+displayTagName+" should be a
numeric value.",e);
throw new
AxisFault("Column value specified "+ columnReference
- + " for
"+displayTagName+" should be a numeric value.");
+ + " for
"+displayTagName+" should be a numeric value.",e);
}
- //columnRef -1, columns start
from 0
- String elementValue = (String)
elementValues.get(new Integer(columnRef -1));
+ //in dbs file column number
starts from 1, but inside code it starts from 0
+ String elementValue = (String)
elementValues.get(new Integer(columnRef - 1));
if (columnDefalut == null ||
columnDefalut.equals("element")) {
OMElement rowElement =
fac.createOMElement(displayTagName, omNs);
@@ -690,15 +847,15 @@
}
processedRowCount++;
}
- } catch (IOException e) {
- // TODO Implement proper error handling
- log.error(e);
+ }catch (IOException e) {
+ log.error("Error reading CSV file.",e);
+ throw new AxisFault("Error reading CSV file.",e);
}
return resultElement;
}
- public static Connection createConnection(AxisService axisService)
throws SQLException,ClassNotFoundException {
+ public static Connection createConnection(AxisService axisService)
throws AxisFault {
try{
log.info("Creating database connection for
"+axisService.getName());
//Try to load the JDBC driver class. If class not found
throw an error.
@@ -708,51 +865,82 @@
props.put("user",
axisService.getParameterValue(DBConstants.USER));
props.put("password",
axisService.getParameterValue(DBConstants.PASSWORD));
-
conn = DriverManager.getConnection((String) axisService
.getParameterValue(DBConstants.PROTOCOL), props);
return conn;
} catch (SQLException e) {
- log.info(e.getMessage());
- e.printStackTrace();
- throw e;
+ log.error("Error occured while connecting to
database",e);
+ throw new AxisFault("Error occured while connecting to
database",e);
+
} catch (ClassNotFoundException e) {
- log.info("JDBC driver not available in classpath :
"+e.getMessage());
- e.printStackTrace();
- throw e;
- } catch (InstantiationException e) {
- log.error(e.getMessage());
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- log.error(e.getMessage());
- e.printStackTrace();
+ log.error("JDBC driver not available in classpath :
"+e.getMessage());
+ throw new AxisFault("JDBC driver not available in
classpath : "+e.getMessage());
+ }
+ catch (InstantiationException e) {
+ log.error("Error occurred during instantiating
"+(String) axisService.getParameterValue(DBConstants.DRIVER), e);
+ throw new AxisFault("Error occurred during
instantiating "+(String) axisService.getParameterValue(DBConstants.DRIVER), e);
+ }
+ catch (IllegalAccessException e) {
+ log.error("Illegal Access error during loading
"+(String) axisService.getParameterValue(DBConstants.DRIVER), e);
+ throw new AxisFault("Illegal Access error during
loading "+(String) axisService.getParameterValue(DBConstants.DRIVER), e);
}
- return null;
}
public static PreparedStatement getProcessedPreparedStatement(HashMap
inputs, HashMap params,
- HashMap paramOrder, Connection conn, String
sqlStatement) throws SQLException {
- PreparedStatement sqlQuery =
conn.prepareStatement(sqlStatement);
+ HashMap paramOrder, Connection conn, String
sqlStatement) throws AxisFault {
+
+ String paramName = null;
+ String sqlType = null;
+ String value = null;
+ try{
+
+ PreparedStatement sqlQuery =
conn.prepareStatement(sqlStatement);
+ log.debug("Processing prepared statement for SQL " +
sqlStatement);
Set paramNames = params.keySet();
Object pramNameArray[] = paramNames.toArray();
for (int i = 0; i < pramNameArray.length; i++) {
- String paramName = (String) paramOrder.get(new
Integer(i + 1));
- String sqlType = (String) params.get(paramName);
- String value = (String) inputs.get(paramName);
+ paramName = (String) paramOrder.get(new Integer(i + 1));
+ sqlType = (String) params.get(paramName);
+ value = (String) inputs.get(paramName);
+ log.debug("Param name : "+paramName
+ +" SQL Type : "+sqlType
+ +" Value : "+value);
+
if (sqlType == null) {
// Defaults to string
sqlQuery.setString(i + 1, value);
} else if (sqlType.equals("INTEGER")) {
sqlQuery.setInt(i + 1, Integer.parseInt(value));
} else if (sqlType.equals("STRING")) {
+ if(value == null || value.trim().length() == 0){
+ log.error("Empty value found for parameter :
"+paramName);
+ throw new AxisFault("Empty value found for
parameter : "+paramName);
+ }
sqlQuery.setString(i + 1, value);
} else if (sqlType.equals("DOUBLE")) {
sqlQuery.setDouble(i + 1,
Double.parseDouble(value));
+ }else if(sqlType.equals("DATE")){
+ try{
+ sqlQuery.setDate(i+1, Date.valueOf(value));
+ }catch(IllegalArgumentException e){
+ log.error("Incorrect date format for parameter :
"+paramName, e);
+ throw new AxisFault("Incorrect date format for
parameter : "
+ +paramName+".Date should be in yyyy-mm-dd
format.", e);
+ }
}
+
}
return sqlQuery;
+ }
+ catch(NumberFormatException e){
+ log.error("Incorrect value found for parameter : "+paramName,
e);
+ throw new AxisFault("Incorrect value found for parameter :
"+paramName, e);
+ }catch(SQLException e){
+ log.error("Error occurred while preparing prepared statement
for sql : "+sqlStatement, e);
+ throw new AxisFault("Error occurred while preparing prepared
statement for sql : "+sqlStatement, e);
+ }
}
}
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
Mon Dec 3 06:56:38 2007
@@ -1,13 +1,13 @@
package org.wso2.ws.dataservice;
import java.sql.Connection;
-import java.util.Enumeration;
-import java.util.Hashtable;
+import java.sql.SQLException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import javax.sql.DataSource;
import org.apache.axis2.AxisFault;
import org.apache.axis2.description.AxisService;
@@ -17,9 +17,13 @@
public class JNDIUtils {
private static final Log log = LogFactory.getLog(JNDIUtils.class);
- public static Connection createConnection(AxisService axisService){
- Properties properties = null;
-
+
+ /*
+ * Returns a JDBC Connection using JNDI resource properties specified
as
+ * AxisService parameters
+ */
+ public static Connection createConnection(AxisService axisService)
throws AxisFault{
+ Properties properties = null;
// username
Parameter username =
axisService.getParameter(DBConstants.JNDI.USERNAME);
if (username != null) {
@@ -56,26 +60,36 @@
Parameter resource =
axisService.getParameter(DBConstants.JNDI.RESOURCE_NAME);
if (resource == null) {
log.error("JNDI Resource name not specified in Data
Service Configuration file");
- //cannot retrieve connection, return null
return null;
- }
-
+ }
// get connection using these properties
try {
InitialContext context = getContext(properties);
Object obj = getJNDIResource(context,
(String)resource.getValue());
if(obj != null){
- return (Connection)obj;
+ DataSource ds = (DataSource)obj;
+ Connection conn = ds.getConnection();
+ return conn;
}
} catch (AxisFault e) {
- e.printStackTrace();
+ log.error("Error retrieving properties from
AxisService", e);
+ throw e;
} catch (NamingException e) {
- e.printStackTrace();
+ log.error("Naming error occurred while trying to
retrieve JDBC Connection " +
+ "from JNDI tree.",e);
+ throw new AxisFault("Naming error occurred while trying
to retrieve JDBC Connection " +
+ "from JNDI tree.",e);
+ } catch (SQLException e) {
+ log.error("Error occurred while trying to get
connection " +
+ "from DataSource :
"+(String)resource.getValue(),e);
+ throw new AxisFault("Error occurred while trying to get
connection " +
+ "from DataSource : "+(String)resource.getValue(),e);
}
return null;
}
+
private static InitialContext getContext(Properties properties)
throws AxisFault, javax.naming.NamingException {
return new InitialContext(properties);
@@ -83,12 +97,11 @@
private static Object getJNDIResource(InitialContext context, String
resourceName)
throws AxisFault, javax.naming.NamingException {
- log.info("Looking up for resource : "+resourceName);
- //Enumeration ht = context.getEnvironment().keys();
- //while(ht.hasMoreElements()){
- // Object obj = ht.nextElement();
- //}
- Context ctx = (Context)context.lookup("java:comp/env");
- return ctx.lookup(resourceName);
+ if(log.isDebugEnabled()){
+ log.debug("Looking up for resource : "+resourceName);
+ }
+ Object obj = context.lookup(resourceName);
+ return obj;
}
-}
\ No newline at end of file
+
+}
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/ExcelQuery.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/ExcelQuery.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/ExcelQuery.java
Mon Dec 3 06:56:38 2007
@@ -1,5 +1,8 @@
package org.wso2.ws.dataservice.beans;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
import org.apache.axis2.description.AxisService;
import org.wso2.ws.dataservice.DBConstants;
@@ -15,14 +18,41 @@
}
- public ExcelQuery(AxisService axisService){
- super(axisService,DBConstants.Query.EXCEL);
+ public ExcelQuery(AxisService axisService,OMElement query){
+ //unlike CSV query properties, EXCEL query properties are
defined @ query level.
+ //Reason : single Excel document can have multiple sheets & we
can have different operations
+ //per each sheet.
+
+ //extracting query properties from query/excel element
+ OMElement excelEle = query.getFirstChildWithName(new
QName(DBConstants.Query.EXCEL));
+ OMElement workBookNameEle = excelEle.getFirstChildWithName(new
QName(DBConstants.Query.EXCEL_WORKBOOK_NAME));
+ OMElement hasHeaderEle = excelEle.getFirstChildWithName(new
QName(DBConstants.Query.HAS_HEADER));
+ OMElement startingRowEle = excelEle.getFirstChildWithName(new
QName(DBConstants.Query.STARTING_ROW));
+ OMElement maxRowCountEle = excelEle.getFirstChildWithName(new
QName(DBConstants.Query.MAX_ROW_COUNT));
- Object value =
axisService.getParameterValue(DBConstants.Query.EXCEL +"_"+
DBConstants.Query.EXCEL_WORKBOOK_NAME);
- if( value != null){
- this.workBookName = (String)value;
+ if(workBookNameEle != null && workBookNameEle.getText() != null
&& workBookNameEle.getText().trim().length() > 0){
+ this.workBookName = workBookNameEle.getText();
}else{
this.workBookName = "Sheet1"; //default name
}
+
+ if(hasHeaderEle != null && hasHeaderEle.getText() != null &&
hasHeaderEle.getText().trim().length() > 0){
+ this.hasHeaders =
Boolean.valueOf(hasHeaderEle.getText()).booleanValue();
+ }else{
+ this.hasHeaders = false; //default name
+ }
+
+ if(startingRowEle != null && startingRowEle.getText() != null
&& startingRowEle.getText().trim().length() > 0){
+ this.startingRow =
Integer.valueOf(startingRowEle.getText()).intValue();
+ }else{
+ this.startingRow = 1;//default name
+ }
+
+ if(maxRowCountEle != null && maxRowCountEle.getText() != null
&& maxRowCountEle.getText().trim().length() > 0){
+ this.maxRowCount =
Integer.valueOf(maxRowCountEle.getText()).intValue();
+ }else{
+ this.maxRowCount = -1; //default name
+ }
+
}
}
Modified:
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
==============================================================================
---
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
(original)
+++
trunk/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
Mon Dec 3 06:56:38 2007
@@ -3,6 +3,8 @@
import java.util.StringTokenizer;
import org.apache.axis2.description.AxisService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.wso2.ws.dataservice.DBConstants;
public class NonSQLQuery {
@@ -12,6 +14,7 @@
String[] columnNames;
String[] columnOrder;
protected String queryType = "";
+ private static final Log log = LogFactory.getLog(NonSQLQuery.class);
public boolean hasHeaders() {
return hasHeaders;
@@ -69,14 +72,27 @@
value = axisService.getParameterValue(queryType + "_" +
DBConstants.Query.STARTING_ROW);
if(value != null){
- this.startingRow =
Integer.valueOf((String)value).intValue();
+ try{
+ this.startingRow =
Integer.valueOf((String)value).intValue();
+ }catch(NumberFormatException e){
+ log.info("Found non-numeric value for "
+ +queryType + "_" +
DBConstants.Query.STARTING_ROW+ " : "+value);
+ this.startingRow = 0;
+ }
}else{
this.startingRow = 0; //default value
}
value = axisService.getParameterValue(queryType + "_" +
DBConstants.Query.MAX_ROW_COUNT);
if(value != null){
- this.maxRowCount =
Integer.valueOf((String)value).intValue();
+ try{
+ this.maxRowCount =
Integer.valueOf((String)value).intValue();
+ }catch(NumberFormatException e){
+ log.info("Found non-numeric value for "
+ +queryType + "_" + DBConstants.Query.MAX_ROW_COUNT+ "
: "+value);
+ this.maxRowCount = -1;
+ }
+
}else{
this.maxRowCount = -1; //default value
}
@@ -104,5 +120,9 @@
}
}
- }
+ }
+
+ public NonSQLQuery(){
+
+ }
}
_______________________________________________
Commons-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/commons-dev