Author: sumedha
Date: Fri Jan 18 20:49:06 2008
New Revision: 12496

Log:

optimization on DBCP connection pooling, fix for WSAS 695 and some code 
refactoring

Modified:
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBCPConnectionManager.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DataServiceDocLitWrappedSchemaGenerator.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Param.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Query.java
   
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Result.java

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
   (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/CallQuery.java
   Fri Jan 18 20:49:06 2008
@@ -16,7 +16,6 @@
 package org.wso2.ws.dataservice;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 
 import javax.xml.namespace.QName;
@@ -208,6 +207,7 @@
 
     }
 
+       /*
     private String getExternalParameterName(OMElement queryElement,
             HashMap paramsPerCallQueryMap, String name) {
         String withParamName = null;
@@ -217,7 +217,7 @@
             withParamName = (String) callQueryParamNames.get(name);
         }
         return withParamName;
-    }
+    }*/
     
     
     

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBCPConnectionManager.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBCPConnectionManager.java
       (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBCPConnectionManager.java
       Fri Jan 18 20:49:06 2008
@@ -63,8 +63,8 @@
                String maxPool = 
config.getPropertyValue(DBConstants.MAX_POOL_SIZE);
 
                // set numeric values for min & max pool sizes
-               int minPoolSize = 10; // default values
-               int maxPoolSize = 20; // default values
+               int minPoolSize = 1; // default values
+               int maxPoolSize = 5; // default values
                try {
                        if (minPool != null && minPool.trim().length() > 0) {
                                minPoolSize = 
Integer.valueOf(minPool).intValue();
@@ -103,12 +103,14 @@
                GenericObjectPool connectionPool = new GenericObjectPool(null);
                connectionPool.setMinIdle(minIdle);
                connectionPool.setMaxActive(maxActive);
+               connectionPool.setMaxWait(1000*60);
 
                pool = connectionPool;
                ConnectionFactory connectionFactory = new 
DriverManagerConnectionFactory(
                                connectionURL, username, password);
                PoolableConnectionFactory factory = new 
PoolableConnectionFactory(
                                connectionFactory, connectionPool, null, null, 
false, true);
+               
                pool.setFactory(factory);
                PoolingDataSource dataSource = new 
PoolingDataSource(connectionPool);
                dataSource.setAccessToUnderlyingConnectionAllowed(true);

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
 (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBConstants.java
 Fri Jan 18 20:49:06 2008
@@ -70,7 +70,7 @@
            public static final String TIME = "TIME";
            public static final String TIMESTAMP = "TIMESTAMP";         
        }
-    public static String WSO2_NAMESPACE = "http://ws.wso2.org/dataservice";;
+    public static final String WSO2_NAMESPACE = 
"http://ws.wso2.org/dataservice";;
     
     //Datasource Type
     public static final String DATASOURCE_TYPE = "DATASOURCE_TYPE";

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
  (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBDeployer.java
  Fri Jan 18 20:49:06 2008
@@ -21,7 +21,6 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
-import java.sql.Connection;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -29,6 +28,7 @@
 import java.util.Timer;
 import java.util.TimerTask;
 
+import javax.sql.DataSource;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 
@@ -57,19 +57,14 @@
 
 public class DBDeployer implements Deployer, DeploymentConstants {
     private static final Log log = LogFactory.getLog(DBDeployer.class);
-
     private AxisConfiguration axisConfig;
-
     private ConfigurationContext configCtx;
-
     private DBMessageReceiver dbMessageReceiver;
-
     private String repoDir = null;
-
     private String extension = null;
     private Config config; 
-
     private static HashMap conversionType = null;
+    private AxisService axisService = null;
 
     private static HashMap getConversionTable() {
         if (conversionType == null) {
@@ -107,7 +102,6 @@
         serviceStatus = "";
         try {
             
deploymentFileData.setClassLoader(axisConfig.getSystemClassLoader());
-
             AxisServiceGroup serviceGroup = new AxisServiceGroup(axisConfig);
             
serviceGroup.setServiceGroupClassLoader(deploymentFileData.getClassLoader());
             ArrayList serviceList =
@@ -116,7 +110,6 @@
                     .getFile().toURL(), deploymentFileData, axisConfig);
             log.info(Messages.getMessage("deployingws", 
deploymentFileData.getName()));
         } catch (DeploymentException de) {
-            de.printStackTrace();
             log.error(Messages.getMessage(DeploymentErrorMsgs.INVALID_SERVICE, 
deploymentFileData
                     .getName(), de.getMessage()), de);
             PrintWriter error_ptintWriter = new PrintWriter(errorWriter);
@@ -156,9 +149,12 @@
                         serviceStatus);
                 //Registering a timer task to re-establish the database 
connection 
                 //& deploy the service again
-                       TimerTask faultyServiceRectifier = new 
FaultyServiceRectifier(deploymentFileData,configCtx,config);
+                       TimerTask faultyServiceRectifier = new 
FaultyServiceRectifier(axisService,
+                                       deploymentFileData,configCtx,config);
                        Timer timer = new Timer();
-                       timer.scheduleAtFixedRate(faultyServiceRectifier, new 
Date(),new Long(1000*60).longValue());
+                       //Retry in 1 minute
+                       long retryIn = new Long(1000*60).longValue();
+                       timer.scheduleAtFixedRate(faultyServiceRectifier, new 
Date(),retryIn);
             }
         }
     }
@@ -208,7 +204,7 @@
             fis = new FileInputStream(configFilePath);
             configElement = (new StAXOMBuilder(fis)).getDocumentElement();
             configElement.build();
-            String serviceName = configElement.getAttributeValue(new 
QName("name")).toString();
+            String serviceName = configElement.getAttributeValue(new 
QName("name"));
             baseURI = configElement.getAttributeValue(new QName("baseURI"));
             axisService = new AxisService(serviceName);
 
@@ -255,21 +251,17 @@
             //connection properties are added to Axis Service.
             //Lets create the connect & put it to AxisConfiguration
             if(dataSourceType.equals(DBConstants.DATASOURCE_TYPE_RDBMS)){
-                Connection dbConnection;
-                try {
-                    dbConnection = 
DBUtils.createConnection(axisService.getName(),config);
-                    if (dbConnection != null) {
-                        axisService.addParameter(DBConstants.DB_CONNECTION, 
dbConnection);
-                    } else {
-                        throw new AxisFault("Could not establish a connection 
to database.");
-                    }
-                } catch (AxisFault e1) {
-                    throw e1;
-                } 
+               DBCPConnectionManager dbcpConnectionManager = 
+                       
DBUtils.initializeDBConnectionManager(axisService.getName(),config);
+               if(dbcpConnectionManager != null){
+                       axisService.addParameter(DBConstants.DB_CONNECTION, 
dbcpConnectionManager.getDatasource());
+               }else {
+                  throw new AxisFault("Pooling manager could not establish a 
connection to database.");
+                }              
             }else if(dataSourceType.equals(DBConstants.DATASOURCE_TYPE_JNDI)){
-               Connection dbConnection = 
JNDIUtils.createConnection(axisService);
-                if (dbConnection != null) {
-                    axisService.addParameter(DBConstants.DB_CONNECTION, 
dbConnection);
+               DataSource dataSource = JNDIUtils.getDataSource(axisService);
+                if (dataSource != null) {
+                    axisService.addParameter(DBConstants.DB_CONNECTION, 
dataSource);
                 } else {
                     throw new AxisFault("Could not establish a connection to 
database.");
                 }      
@@ -392,6 +384,7 @@
      * 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"));
@@ -427,6 +420,7 @@
             }
         }
     }
+    */
 
     public static String getJavaTypeFromSQLType(String sqlType) {
         HashMap convertionMap = getConversionTable();
@@ -464,7 +458,7 @@
        //service group name is taken from the file name, where as
        //service name is taken from name provided inside configuration
        String serviceGroupName = dataServiceFileName.substring(0, 
dataServiceFileName.lastIndexOf("."));
-        AxisService axisService = 
createDBService(currentFile.getAbsolutePath(), 
+        axisService = createDBService(currentFile.getAbsolutePath(), 
                                        configCtx.getAxisConfiguration());
         axisServiceGroup.setServiceGroupName(serviceGroupName);
         axisService.setParent(axisServiceGroup);

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
   (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBMessageReceiver.java
   Fri Jan 18 20:49:06 2008
@@ -35,20 +35,19 @@
         *             on invalid method (wrong signature) or behavior (return
         *             null)
         */
-       public void invokeBusinessLogic(MessageContext msgContext, 
MessageContext newmsgContext)
+       public void invokeBusinessLogic(MessageContext msgContext, 
MessageContext newMsgContext)
        throws AxisFault {
                try {
                        OMElement result = DBUtils.invoke(msgContext);
                        SOAPFactory fac = getSOAPFactory(msgContext);
                        SOAPEnvelope envelope = fac.getDefaultEnvelope();
-
                        if (result != null) {
                                envelope.getBody().addChild(result);
                        }
-                       newmsgContext.setEnvelope(envelope);
+                       newMsgContext.setEnvelope(envelope);
 
                } catch (AxisFault e) {
                    throw e;
                }
        }
-}
+}
\ No newline at end of file

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
     (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DBUtils.java
     Fri Jan 18 20:49:06 2008
@@ -44,6 +44,7 @@
 import java.util.Properties;
 import java.util.Set;
 
+import javax.sql.DataSource;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -60,7 +61,6 @@
 import org.apache.axis2.databinding.utils.BeanUtil;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.Parameter;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.poi.hssf.usermodel.HSSFCell;
@@ -117,8 +117,7 @@
 
                        HashMap params = new HashMap();
                        // TODO : sumedha, we need a mechanism to specify 
parameter ordering
-                       // in the spec.
-                       // Right now order in which it appears in taken.
+                       // in the spec.As of now order in which it appears in 
taken.
                        HashMap paramOrder = new HashMap();
                        //To keep track of parameter names with original case
                        HashMap originalParamNames = new HashMap();
@@ -143,8 +142,7 @@
                                        paramOrder.put(new Integer(position + 
1), paramName.toLowerCase());
                                        originalParamNames.put(new 
Integer(position + 1), paramName);
                                        paramType.put(paramName.toLowerCase(), 
inOutType);
-                                       position++;                             
        
-
+                                       position++;             
                        }
 
                        String query = queryElement.getFirstChildWithName(new 
QName("sql")).getText();
@@ -155,18 +153,21 @@
 
                        if (firstPartOfSQL.equalsIgnoreCase("SELECT")) {
                                resultElement =
-                                       getSelectResult(queryElement, inputs, 
params, paramOrder,originalParamNames,paramType, axisService, false,queryLevel);
+                                       getSelectResult(queryElement, inputs, 
params, paramOrder
+                                                       
,originalParamNames,paramType, axisService, false,queryLevel);
 
                        } else if (firstPartOfSQL.equalsIgnoreCase("INSERT")
                                        || 
firstPartOfSQL.equalsIgnoreCase("UPDATE")
                                        || 
firstPartOfSQL.equalsIgnoreCase("DELETE")
                                        || 
firstPartOfSQL.equalsIgnoreCase("CREATE")) {
-                               resultElement = getSelectResult(queryElement, 
inputs, params, paramOrder,originalParamNames,paramType, axisService, 
true,queryLevel);
+                               resultElement = getSelectResult(queryElement, 
inputs, params
+                                               
,paramOrder,originalParamNames,paramType, axisService, true,queryLevel);
 
                        }else {
                                //This can be a stored procedure call
                                resultElement =
-                                       getStoredProcedureResult(queryElement, 
inputs, params, paramOrder,originalParamNames,paramType, 
axisService,queryLevel);
+                                       getStoredProcedureResult(queryElement, 
inputs, params
+                                                       
,paramOrder,originalParamNames,paramType, axisService,queryLevel);
 
                        }
                } catch (Exception e) {
@@ -185,7 +186,6 @@
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
-
                
                OMFactory fac = OMAbstractFactory.getOMFactory();
                OMNamespace omNs = fac.createOMNamespace(targetNamespace, 
"data");
@@ -219,19 +219,22 @@
        /*
         * For RDBMS & JNDI connections re-establishing connection, if existing 
connection is closed.
         */
-       private static Connection checkDBConnectionStatus(AxisService 
axisService,Connection conn) throws AxisFault{
+       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))){
+           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 == null || conn.isClosed()){
                     if(log.isDebugEnabled()){
                         log.debug("Database connection is closed.Trying to 
re-establish.");
                     }
                     Config config = 
(Config)axisService.getParameterValue(DBConstants.CONNECTION_CONFIG);
-                    return createConnection(axisService.getName(),config);
+                    return createConnection(axisService,config);
                 }else{
                     //existing connection is not closed. Return it.
                     return conn;
@@ -530,7 +533,8 @@
        
        
        private static OMElement getSelectResult(OMElement queryElement, 
HashMap inputValues,
-                       HashMap params, HashMap paramOrder,HashMap 
originalParamNames,HashMap paramType, AxisService axisService, boolean isDML
+                       HashMap params, HashMap paramOrder,HashMap 
originalParamNames,HashMap paramType
+                       , AxisService axisService, boolean isDML
                        ,int queryLevel)
        throws AxisFault {
                OMElement resultElement = null;
@@ -539,9 +543,7 @@
                OMFactory fac = null;
                OMNamespace omNs = null;
                Result resultObj = null;
-               String columnDefault = null;
-
- 
+               //String columnDefault = null; 
                
                String sqlQuery = queryElement.getFirstChildWithName(new 
QName("sql")).getText();
                try {
@@ -582,7 +584,7 @@
                        //TODO : need to define a way to get values 
automatically
                                
//getDefaultValuesForResultsWrapper(wrapperElementName,rowElementName);
                                // check ??
-                               columnDefault = result.getAttributeValue(new 
QName("columnDefault"));
+                               //columnDefault = result.getAttributeValue(new 
QName("columnDefault"));
                                fac = OMAbstractFactory.getOMFactory();
 
                                //get prefix for namespace
@@ -628,8 +630,7 @@
                                }else{
                                        resultElement = 
fac.createOMElement(resultObj.getResultWrapper(), omNs);
                                }                       
-                       }
-                       
+                       }                       
 
                        if (isDML) {
                                if(hasResponse){
@@ -731,9 +732,9 @@
                                        conn.close();
                                }
                        } catch (SQLException e) {
-                               log.error(e.getMessage());
-                               //throw new AxisFault(
-                               //              "Exception occurred while 
trying to commit.", e);
+                               log.error("Exception occured while trying to 
close the DB connection.",e);
+                               throw new AxisFault(
+                                               "Exception occured while trying 
to close the DB connection.", e);
                        }
                }
                
@@ -758,10 +759,12 @@
                OMElement operationElement =
                        (OMElement) 
(axisOp.getParameterValue(DBConstants.DB_OPERATION_ELEMENT));
 
-               
if(DBConstants.DATASOURCE_TYPE_CSV.equals((String)axisService.getParameterValue(DBConstants.DATASOURCE_TYPE))){
+               
if(DBConstants.DATASOURCE_TYPE_CSV.equals((String)axisService.getParameterValue(
+                               DBConstants.DATASOURCE_TYPE))){
                        return DBUtils.processCSVQuery(operationElement, 
axisService, inputMessage);
                }
-               else 
if(DBConstants.DATASOURCE_TYPE_EXCEL.equals((String)axisService.getParameterValue(DBConstants.DATASOURCE_TYPE))){
+               else 
if(DBConstants.DATASOURCE_TYPE_EXCEL.equals((String)axisService.getParameterValue(
+                               DBConstants.DATASOURCE_TYPE))){
                        return processExcelQuery(operationElement, axisService, 
inputMessage);
                }
                else{//default is RDBMS (JNDI Data source falls under this too)
@@ -1230,16 +1233,17 @@
        }
 
 
-       public static Connection createConnection(String serviceName,Config 
config) throws AxisFault {
+       public static Connection createConnection(AxisService 
axisService,Config config) throws AxisFault {
                try{
-                       log.debug("Getting database connection for 
"+serviceName);
+                       log.debug("Getting database connection for 
"+axisService.getName());
                        Connection conn = null;                 
                        
                        if(config.getPropertyValue(DBConstants.MIN_POOL_SIZE) 
!= null 
                                        || 
config.getPropertyValue(DBConstants.MAX_POOL_SIZE) != null){
                                //user has set connection pool size(s). Get 
connection from pooling manager
-                               DBCPConnectionManager dbcpConnectionManager = 
new DBCPConnectionManager(config);
-                               conn = 
dbcpConnectionManager.getDatasource().getConnection();                          
 
+                               DataSource dataSource =
+                                       
(DataSource)axisService.getParameterValue(DBConstants.DB_CONNECTION);
+                               conn = dataSource.getConnection();              
                
                        }else{
                                //Try to load the JDBC driver class. If class 
not found throw an error.
                                
Class.forName(config.getPropertyValue(DBConstants.DRIVER)).newInstance();
@@ -1267,6 +1271,14 @@
                }
        }
 
+       public static DBCPConnectionManager initializeDBConnectionManager(
+                       String serviceName, Config config) throws AxisFault {
+               log.debug("Getting database connection for " + serviceName);
+               DBCPConnectionManager dbcpConnectionManager = null;
+               dbcpConnectionManager = new DBCPConnectionManager(config);
+               return dbcpConnectionManager;
+       }
+       
        public static PreparedStatement getProcessedPreparedStatement(HashMap 
inputs, HashMap params,
                        HashMap paramOrder,HashMap originalParamNames,HashMap 
paramTypes, Connection conn
                        , String sqlStatement

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DataServiceDocLitWrappedSchemaGenerator.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DataServiceDocLitWrappedSchemaGenerator.java
     (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/DataServiceDocLitWrappedSchemaGenerator.java
     Fri Jan 18 20:49:06 2008
@@ -7,7 +7,6 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.axis2.AxisFault;
 import org.apache.axis2.description.AxisMessage;
 import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.description.AxisService;

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
      (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/FaultyServiceRectifier.java
      Fri Jan 18 20:49:06 2008
@@ -1,26 +1,31 @@
 package org.wso2.ws.dataservice;
 
 import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.TimerTask;
 
+import javax.sql.DataSource;
+
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.repository.util.DeploymentFileData;
+import org.apache.axis2.description.AxisService;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.ws.dataservice.beans.Config;
 
 public class FaultyServiceRectifier extends TimerTask {
-       private static final Log log = LogFactory
-                       .getLog(FaultyServiceRectifier.class);
-       private ConfigurationContext configurationCtx = null;
-       private Config config = null;
+       private static final Log log = 
LogFactory.getLog(FaultyServiceRectifier.class);
+       private ConfigurationContext configurationCtx;
+       private Config config;
+       private AxisService axisService;
        private DeploymentFileData deploymentFileData;
 
-       public FaultyServiceRectifier(DeploymentFileData deploymentData,
-                       ConfigurationContext configCtx, Config 
dataServiceConfigSection) {
-               configurationCtx = configCtx;
+       public FaultyServiceRectifier(AxisService service,DeploymentFileData 
deploymentData
+                       ,ConfigurationContext configCtx, Config 
dataServiceConfigSection) {
+               axisService = service;
                deploymentFileData = deploymentData;
+               configurationCtx = configCtx;           
                config = dataServiceConfigSection;
        }
 
@@ -29,15 +34,16 @@
        }
 
        public void run() {
-               Connection dbConnection;
+               DataSource dataSource;
                String deploymentFileName = "";
                try {
-                       deploymentFileName = deploymentFileData.getFile()
-                                       .getAbsolutePath();
-                       log.info("Trying to re-establish fautly database 
connection for data services :"
-                                       +deploymentFileName);
-                       dbConnection = 
DBUtils.createConnection(deploymentFileName, config);
-                       if (dbConnection != null) {
+                       deploymentFileName = 
deploymentFileData.getFile().getAbsolutePath();
+                       log.info("Trying to re-establish fautly database 
connection " +
+                                       "for data services 
:"+deploymentFileName);
+                       DBCPConnectionManager dbcpConnectionManager = 
+                               
DBUtils.initializeDBConnectionManager(deploymentFileName, config);
+                       dataSource = dbcpConnectionManager.getDatasource();
+                       if (dataSource != null) {
                                log.info("Database connection successful. 
Removing "
                                                + deploymentFileName + " from 
Fault Service list.");
                                
configurationCtx.getAxisConfiguration().getFaultyServices()
@@ -54,10 +60,8 @@
                        }
                } catch (AxisFault e) {
                        log     .error("Error occurred while trying to 
re-establish database connection for "
-                                       +deploymentFileName,
-                                       e);
-               }
-
+                                       +deploymentFileName+".Retrying....",e);
+               } 
        }
 
 }

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
   (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/JNDIUtils.java
   Fri Jan 18 20:49:06 2008
@@ -1,7 +1,5 @@
 package org.wso2.ws.dataservice;
 
-import java.sql.Connection;
-import java.sql.SQLException;
 import java.util.Properties;
 
 import javax.naming.Context;
@@ -22,7 +20,7 @@
         * Returns a JDBC Connection using JNDI resource properties specified 
as 
         * AxisService parameters
         */
-       public static Connection createConnection(AxisService axisService) 
throws AxisFault{
+       public static DataSource getDataSource(AxisService axisService) throws 
AxisFault{
                Properties properties = null;           
                // username
                Parameter username = 
axisService.getParameter(DBConstants.JNDI.USERNAME);
@@ -63,14 +61,13 @@
                        return null;
                }               
 
-               // get connection using these properties
+               //get Datasource using these properties
                try {
                        InitialContext context = getContext(properties);
                        Object obj = getJNDIResource(context, 
(String)resource.getValue());
                        if(obj != null){
-                               DataSource ds = (DataSource)obj;
-                               Connection conn = ds.getConnection();
-                               return conn;
+                               DataSource dataSource = (DataSource)obj;
+                               return dataSource;
                        }
                } catch (AxisFault e) {
                        log.error("Error retrieving properties from 
AxisService", e);
@@ -80,12 +77,7 @@
                                        "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;
        }
 

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
   (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/NonSQLQuery.java
   Fri Jan 18 20:49:06 2008
@@ -8,11 +8,11 @@
 import org.wso2.ws.dataservice.DBConstants;
 
 public class NonSQLQuery {
-       boolean hasHeaders = false;
-       int startingRow;
-       int maxRowCount;
-       String[] columnNames; 
-       String[] columnOrder;
+       protected boolean hasHeaders = false;
+       protected int startingRow;
+       protected int maxRowCount;
+       protected String[] columnNames; 
+       protected String[] columnOrder;
        protected String queryType = "";
        private static final Log log = LogFactory.getLog(NonSQLQuery.class);
 
@@ -51,14 +51,14 @@
        public String[] getColumnNames() {
                return columnNames;
        }
-       public void setColumnNames(String[] columnNames) {
-               this.columnNames = columnNames;
+       public void setColumnNames(String[] columnNamesArray) {
+               this.columnNames = columnNamesArray;
        }
        public String[] getColumnOrder() {
                return columnOrder;
        }
-       public void setColumnOrder(String[] columnOrder) {
-               this.columnOrder = columnOrder;
+       public void setColumnOrder(String[] columnOrderArray) {
+               this.columnOrder = columnOrderArray;
        }
        
        public NonSQLQuery(AxisService axisService,String queryType){

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Param.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Param.java
 (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Param.java
 Fri Jan 18 20:49:06 2008
@@ -7,10 +7,10 @@
  */
                
 public class Param {
-       String name;
-       String sqlType;
-       String type;
-       int ordinal;
+       private String name;
+       private String sqlType;
+       private String type;
+       private int ordinal;
        
        String columnName;
        

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Query.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Query.java
 (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Query.java
 Fri Jan 18 20:49:06 2008
@@ -7,8 +7,8 @@
 import org.apache.axiom.om.OMElement;
 
 public class Query {
-       String id;
-       Param[] params;
+       private String id;
+       private Param[] params;
        
        public String getId() {
                return id;
@@ -19,8 +19,11 @@
        public Param[] getParams() {
                return params;
        }
-       public void setParams(Param[] params) {
-               this.params = params;
+       public void setParams(Param[] paramsArray) {
+               params = new Param[paramsArray.length];
+               for (int a = 0; a < paramsArray.length; a++) {
+                       params[a] = paramsArray[a];
+               }
        }
        
        public Param getParam(String name){

Modified: 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Result.java
==============================================================================
--- 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Result.java
        (original)
+++ 
branches/wsas/java/2.2/commons/data-services/src/main/java/org/wso2/ws/dataservice/beans/Result.java
        Fri Jan 18 20:49:06 2008
@@ -8,11 +8,11 @@
 import org.apache.axiom.om.OMElement;
 
 public class Result {    
-    String resultWrapper = ""; //represents element attribute of result element
-    String rowName = ""; //represents rowName attribute of result element
-    String resultSetColumnNames[];
-    String displayColumnNames[];
-    String elementLocalNames[];
+    private String resultWrapper = ""; //represents element attribute of 
result element
+    private String rowName = ""; //represents rowName attribute of result 
element
+    private String resultSetColumnNames[];
+    private String displayColumnNames[];
+    private String elementLocalNames[];
     
     public String getResultWrapper() {
         return resultWrapper;

_______________________________________________
Wsas-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev

Reply via email to