[esb-java-dev] svn commit r23858 - in branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse: . config config/xml registry/url util util/datasource util/datasource/factory util/datasource/serializer
indika at wso2.com
indika at wso2.com
Thu Nov 13 10:30:14 PST 2008
Author: indika
Date: Thu Nov 13 10:30:14 2008
New Revision: 23858
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=23858
Log:
DBSource pooling Refactoring , add some funcatinality in order to make datasource creation resuable carbon component
Added:
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryListener.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java
- copied, changed from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java
- copied, changed from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java
- copied, changed from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java
- copied, changed from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java
Removed:
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
Modified:
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/ServerManager.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/MBeanRepository.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolView.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolViewMBean.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformation.java
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/ServerManager.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/ServerManager.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/ServerManager.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/ServerManager.java Thu Nov 13 10:30:14 2008
@@ -20,23 +20,16 @@
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportInDescription;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.AxisModule;
-import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.ListenerManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.synapse.format.BinaryBuilder;
-import org.apache.synapse.format.PlainTextBuilder;
import org.apache.synapse.util.ClasspathURLStreamHandler;
-import org.apache.synapse.util.RMIRegistryController;
-import org.apache.synapse.util.datasource.InMemoryDataSourceRegistry;
-import org.apache.synapse.util.datasource.JNDIBasedDataSourceRegistry;
-import org.apache.synapse.endpoints.dispatch.SALSessions;
import java.io.File;
import java.net.*;
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java Thu Nov 13 10:30:14 2008
@@ -285,8 +285,6 @@
/** Synapse server instance name */
public static final String SERVER_NAME = "serverName";
- public static final String SYNAPSE_DATASOURCES = "synapse.datasources";
-
/** Root for relative path */
public static final String RESOLVE_ROOT = "resolve.root";
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Thu Nov 13 10:30:14 2008
@@ -25,21 +25,22 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.*;
-import org.apache.synapse.util.RMIRegistryController;
-import org.apache.synapse.util.datasource.InMemoryDataSourceRegistry;
-import org.apache.synapse.util.datasource.JNDIBasedDataSourceRegistry;
-import org.apache.synapse.task.TaskDescriptionRepository;
-import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
import org.apache.synapse.config.xml.MediatorFactoryFinder;
import org.apache.synapse.config.xml.endpoints.XMLToEndpointMapper;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.core.axis2.ProxyService;
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.endpoints.dispatch.SALSessions;
-import org.apache.synapse.mediators.base.SequenceMediator;
-import org.apache.synapse.mediators.ListMediator;
import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.ListMediator;
+import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.registry.Registry;
+import org.apache.synapse.task.TaskDescriptionRepository;
+import org.apache.synapse.task.TaskDescriptionRepositoryFactory;
+import org.apache.synapse.util.RMIRegistryController;
+import org.apache.synapse.util.datasource.DataSourceInformationRepository;
+import org.apache.synapse.util.datasource.InMemoryDataSourceRepository;
+import org.apache.synapse.util.datasource.JNDIBasedDataSourceRepository;
import javax.xml.namespace.QName;
import java.io.IOException;
@@ -103,6 +104,8 @@
TaskDescriptionRepositoryFactory.getTaskDescriptionRepository(
SynapseConstants.SYNAPSE_STARTUP_TASK_DESCRIPTIONS_REPOSITORY);
+ private DataSourceInformationRepository dataSourceInformationRepository;
+
/**
* Save the path to the configuration file loaded, to save it later if
* required
@@ -813,8 +816,8 @@
try {
RMIRegistryController.getInstance().removeLocalRegistry();
SALSessions.getInstance().reset();
- InMemoryDataSourceRegistry.getInstance().clear();
- JNDIBasedDataSourceRegistry registry = JNDIBasedDataSourceRegistry.getInstance();
+ InMemoryDataSourceRepository.getInstance().clear();
+ JNDIBasedDataSourceRepository registry = JNDIBasedDataSourceRepository.getInstance();
if (registry.isInitialized()) {
registry.clear();
}
@@ -917,4 +920,12 @@
public TaskDescriptionRepository getTaskDescriptionRepository() {
return repository;
}
+
+ public DataSourceInformationRepository getDataSourceInformationRepository() {
+ return dataSourceInformationRepository;
+ }
+
+ public void setDataSourceInformationRepository(DataSourceInformationRepository dataSourceInformationRepository) {
+ this.dataSourceInformationRepository = dataSourceInformationRepository;
+ }
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java Thu Nov 13 10:30:14 2008
@@ -23,11 +23,12 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.util.datasource.DataSourceRegistrar;
import org.apache.synapse.config.xml.XMLConfigurationBuilder;
import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.mediators.builtin.DropMediator;
import org.apache.synapse.mediators.builtin.LogMediator;
+import org.apache.synapse.util.datasource.DataSourceInformationRepository;
+import org.apache.synapse.util.datasource.factory.DataSourceInformationRepositoryFactory;
import java.io.File;
import java.io.FileInputStream;
@@ -75,12 +76,14 @@
// build the Synapse configuration parsing the XML config file
try {
Properties synapseProperties = loadSynapseProperties();
- DataSourceRegistrar.registerDataSources(synapseProperties);
+ DataSourceInformationRepository repository =
+ DataSourceInformationRepositoryFactory.createDataSourceInformationRepository(synapseProperties);
SynapseConfiguration synCfg
= XMLConfigurationBuilder.getConfiguration(new FileInputStream(configFile));
log.info("Loaded Synapse configuration from : " + configFile);
synCfg.setPathToConfigFile(new File(configFile).getAbsolutePath());
synCfg.setProperties(synapseProperties);
+ synCfg.setDataSourceInformationRepository(repository);
return synCfg;
} catch (FileNotFoundException fnf) {
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java Thu Nov 13 10:30:14 2008
@@ -24,11 +24,11 @@
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.synapse.mediators.db.AbstractDBMediator;
import org.apache.synapse.mediators.db.Statement;
-import org.apache.synapse.util.xpath.SynapseXPath;
-import org.apache.synapse.util.datasource.DataSourceFinder;
-import org.apache.synapse.util.datasource.InMemoryDataSourceRegistry;
-import org.apache.synapse.util.datasource.DBPoolView;
import org.apache.synapse.util.MBeanRepository;
+import org.apache.synapse.util.datasource.DBPoolView;
+import org.apache.synapse.util.datasource.DataSourceManager;
+import org.apache.synapse.util.datasource.DatasourceMBeanRepository;
+import org.apache.synapse.util.xpath.SynapseXPath;
import org.jaxen.JaxenException;
import javax.naming.Context;
@@ -141,9 +141,9 @@
String dsName = getValue(pool, DSNAME_Q);
mediator.addDataSourceProperty(DSNAME_Q, dsName);
- DataSource dataSource = DataSourceFinder.find(dsName);
+ DataSource dataSource = DataSourceManager.getInstance().find(dsName);
if (dataSource != null) {
- MBeanRepository mBeanRepository = InMemoryDataSourceRegistry.getInstance();
+ MBeanRepository mBeanRepository = DatasourceMBeanRepository.getInstance();
Object mBean = mBeanRepository.getMBean(dsName);
if (mBean instanceof DBPoolView) {
mediator.setDbPoolView((DBPoolView) mBean);
@@ -157,7 +157,7 @@
props.put(Context.SECURITY_CREDENTIALS, getValue(pool, PASS_Q));
props.put(Context.PROVIDER_URL, getValue(pool, URL_Q));
- dataSource = DataSourceFinder.find(dsName, props);
+ dataSource = DataSourceManager.getInstance().find(dsName, props);
if (dataSource == null) {
handleException("Cannot find a DataSource for given properties :" + props);
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java Thu Nov 13 10:30:14 2008
@@ -19,8 +19,8 @@
package org.apache.synapse.registry.url;
-import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -180,7 +180,7 @@
}
root = value;
} else {
- handleException("");
+ handleException("Parameter 'root' is null");
}
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/MBeanRepository.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/MBeanRepository.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/MBeanRepository.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/MBeanRepository.java Thu Nov 13 10:30:14 2008
@@ -25,5 +25,9 @@
public void addMBean(String name, Object MBean);
public Object getMBean(String name);
+
+ public void removeMBean(String name);
+
+ public void clear();
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolView.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolView.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolView.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolView.java Thu Nov 13 10:30:14 2008
@@ -19,8 +19,8 @@
package org.apache.synapse.util.datasource;
-import java.util.Map;
import java.util.HashMap;
+import java.util.Map;
/**
@@ -66,7 +66,7 @@
Long currentUsage = connectionsUsage.get(connectionID);
if (currentUsage != null) {
currentUsage += 1;
- connectionsUsage.put(connectionID,currentUsage);
+ connectionsUsage.put(connectionID, currentUsage);
} else {
connectionsUsage.put(connectionID, (long) 1);
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolViewMBean.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolViewMBean.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolViewMBean.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DBPoolViewMBean.java Thu Nov 13 10:30:14 2008
@@ -21,13 +21,17 @@
import java.util.Map;
/**
- *
+ *
*/
public interface DBPoolViewMBean {
-
- public int getNumActive();
- public int getNumIdle();
- public String getName();
- public Map getConnectionUsage();
- public void reset();
+
+ public int getNumActive();
+
+ public int getNumIdle();
+
+ public String getName();
+
+ public Map getConnectionUsage();
+
+ public void reset();
}
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceConfigurationConstants.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource;
+
+/**
+ * To change this template use File | Settings | File Templates.
+ */
+public class DataSourceConfigurationConstants {
+
+ public static final String PROP_USER_NAME = "username";
+ public static final String PROP_PASSWORD = "password";
+ public static final String PROP_DRIVER_CLS_NAME = "driverClassName";
+ public static final String PROP_DSNAME = "dsName";
+ public static final String PROP_URL = "url";
+ public static final String PROP_DRIVER = "driver";
+ public static final String PROP_USER = "user";
+ public static final String PROP_CPDSADAPTER = "cpdsadapter";
+ public static final String PROP_JNDI_ENV = "jndiEnvironment";
+ public static final String PROP_DEFAULTMAXACTIVE = "defaultMaxActive";
+ public static final String PROP_DEFAULTMAXIDLE = "defaultMaxIdle";
+ public static final String PROP_DEFAULTMAXWAIT = "defaultMaxWait";
+ public static final String PROP_DATA_SOURCE_NAME = "dataSourceName";
+ public static final String PROP_CPDS_CLASS_NAME = "className";
+ public static final String PROP_CPDS_FACTORY = "factory";
+ public static final String PROP_CPDS_NAME = "name";
+ public final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
+ public final static String PROP_DEFAULTREADONLY = "defaultReadOnly";
+ public final static String PROP_TESTONBORROW = "testOnBorrow";
+ public final static String PROP_TESTONRETURN = "testOnReturn";
+ public final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS =
+ "timeBetweenEvictionRunsMillis";
+ public final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
+ public final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
+ public final static String PROP_TESTWHILEIDLE = "testWhileIdle";
+ public final static String PROP_VALIDATIONQUERY = "validationQuery";
+ public final static String PROP_MAXACTIVE = "maxActive";
+ public final static String PROP_MAXIDLE = "maxIdle";
+ public final static String PROP_MAXWAIT = "maxWait";
+ public final static String PROP_MINIDLE = "minIdle";
+ public final static String PROP_INITIALSIZE = "initialSize";
+ public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
+ public final static String PROP_DEFAULTCATALOG = "defaultCatalog";
+ public final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED =
+ "accessToUnderlyingConnectionAllowed";
+ public final static String PROP_REMOVEABANDONED = "removeAbandoned";
+ public final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout";
+ public final static String PROP_LOGABANDONED = "logAbandoned";
+ public final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements";
+ public final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements";
+ public final static String PROP_CONNECTIONPROPERTIES = "connectionProperties";
+ public static final String PROP_PROVIDER_PORT = "providerPort";
+ public final static String PROP_REGISTRY = "registry";
+ public final static String PROP_REGISTRY_MEMORY = "memory";
+ public final static String PROP_REGISTRY_JNDI = "JNDI";
+ public static final String PROP_ICFACTORY = "icFactory";
+ public static final String PROP_PROVIDER_URL = "providerUrl";
+ public static final String DOT_STRING = ".";
+ public static final String COMMA_STRING = ",";
+ public static final String PROP_SYNAPSE_DATASOURCES = "synapse.datasources";
+ public static final String PROP_TYPE = "type";
+ public static final String PROP_BASIC_DATA_SOURCE = "BasicDataSource";
+ public static final String PROP_CLASS_NAME = "className";
+ public static final String PROP_CPDSADAPTER_DRIVER
+ = "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS";
+ public static final String PROP_FACTORY = "factory";
+ public static final String PROP_NAME = "name";
+
+}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceFinder.java Thu Nov 13 10:30:14 2008
@@ -18,22 +18,14 @@
*/
package org.apache.synapse.util.datasource;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.SynapseException;
-
import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
import javax.sql.DataSource;
import java.util.Properties;
/**
* Finds a DataSource based on various criteria
*/
-public class DataSourceFinder {
-
- private static final Log log = LogFactory.getLog(DataSourceFinder.class);
+public interface DataSourceFinder {
/**
* Find a DataSource using given name
@@ -41,25 +33,7 @@
* @param name Name of the DataSource to be found
* @return DataSource if found , otherwise null
*/
- public static DataSource find(String name) {
-
- if (name == null || "".equals(name)) {
- handleException("DataSource name cannot be found.");
- }
-
- DataSourceRegistry registry = InMemoryDataSourceRegistry.getInstance();
- DataSource result = registry.lookUp(name);
-
- if (result != null) {
- return result;
- }
-
- registry = JNDIBasedDataSourceRegistry.getInstance();
- if (registry.isInitialized()) {
- return registry.lookUp(name);
- }
- return null;
- }
+ DataSource find(String name);
/**
* Find a DataSource using the given name and JNDI environment properties
@@ -68,19 +42,7 @@
* @param jndiEnv JNDI environment properties
* @return DataSource if found , otherwise null
*/
- public static DataSource find(String dsName, Properties jndiEnv) {
-
- try {
-
- Context context = new InitialContext(jndiEnv);
- return find(dsName, context);
-
- } catch (NamingException e) {
- handleException("Error looking up DataSource : " + dsName +
- " using JNDI properties : " + jndiEnv, e);
- }
- return null;
- }
+ DataSource find(String dsName, Properties jndiEnv);
/**
* Find a DataSource using the given name and naming context
@@ -89,45 +51,6 @@
* @param context Naming Context
* @return DataSource if found , otherwise null
*/
- public static DataSource find(String dsName, Context context) {
-
- try {
- Object dataSourceO = context.lookup(dsName);
- if (dataSourceO != null && dataSourceO instanceof DataSource) {
- return (DataSource) dataSourceO;
- } else {
- handleException("DataSource : " + dsName + " not found when looking up" +
- " using JNDI properties : " + context.getEnvironment());
- }
-
- } catch (NamingException e) {
- handleException(new StringBuilder().append("Error looking up DataSource : ")
- .append(dsName).append(" using JNDI properties : ").
- append(context).toString(), e);
- }
- return null;
- }
-
-
- /**
- * Helper methods for handle errors.
- *
- * @param msg The error message
- */
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- /**
- * Helper methods for handle errors.
- *
- * @param msg The error message
- * @param e The exception
- */
- private static void handleException(String msg, Exception e) {
- log.error(msg, e);
- throw new SynapseException(msg, e);
- }
+ DataSource find(String dsName, Context context);
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformation.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformation.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformation.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformation.java Thu Nov 13 10:30:14 2008
@@ -22,6 +22,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Properties;
/**
* Encapsulates the All information related to a DataSource
@@ -32,7 +33,7 @@
public static final String PER_USER_POOL_DATA_SOURCE = "PerUserPoolDataSource";
private String user;
private String password;
- private String name;
+ private String datasourceName;
private int maxActive = GenericObjectPool.DEFAULT_MAX_ACTIVE;
private int maxIdle = GenericObjectPool.DEFAULT_MAX_IDLE;
private long maxWait = GenericObjectPool.DEFAULT_MAX_WAIT;
@@ -53,6 +54,9 @@
private boolean logAbandoned;
private boolean poolPreparedStatements;
private int maxOpenPreparedStatements;
+ private final Properties properties = new Properties();
+ private String repositoryType;
+ private String alias;
private long timeBetweenEvictionRunsMillis =
GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS;
@@ -158,12 +162,12 @@
this.password = password;
}
- public String getName() {
- return name;
+ public String getDatasourceName() {
+ return datasourceName;
}
- public void setName(String name) {
- this.name = name;
+ public void setDatasourceName(String datasourceName) {
+ this.datasourceName = datasourceName;
}
public int getMaxActive() {
@@ -301,4 +305,32 @@
public void setInitialSize(int initialSize) {
this.initialSize = initialSize;
}
+
+ public Properties getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Properties properties) {
+ this.properties.putAll(properties);
+ }
+
+ public String getRepositoryType() {
+ return repositoryType;
+ }
+
+ public void setRepositoryType(String repositoryType) {
+ this.repositoryType = repositoryType;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public Map<String, Object> getAllParameters() {
+ return this.parameters;
+ }
}
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepository.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource;
+
+import java.util.*;
+
+/**
+ *
+ */
+public class DataSourceInformationRepository {
+
+ private final Map<String, DataSourceInformation> dataSourceInformationMap =
+ new HashMap<String, DataSourceInformation>();
+ private final List<DataSourceInformationRepositoryListener> listeners =
+ new ArrayList<DataSourceInformationRepositoryListener>();
+
+ public void setConfigurationProperties(Properties congurationProperties) {
+ for (DataSourceInformationRepositoryListener listener : listeners) {
+ if (listener != null) {
+ listener.reConfigure(congurationProperties);
+ }
+ }
+ }
+
+ public void addDataSourceInformation(DataSourceInformation dataSourceInformation) {
+ dataSourceInformationMap.put(dataSourceInformation.getAlias(), dataSourceInformation);
+ for (DataSourceInformationRepositoryListener listener : listeners) {
+ if (listener != null) {
+ listener.addDataSourceInformation(dataSourceInformation);
+ }
+ }
+ }
+
+ public DataSourceInformation getDataSourceInformation(String name) {
+ return dataSourceInformationMap.get(name);
+ }
+
+ public DataSourceInformation removeDataSourceInformation(String name) {
+ DataSourceInformation information = dataSourceInformationMap.remove(name);
+ for (DataSourceInformationRepositoryListener listener : listeners) {
+ if (listener != null) {
+ listener.removeDataSourceInformation(information);
+ }
+ }
+ return information;
+ }
+
+ public Iterator<DataSourceInformation> getAllDataSourceInformation() {
+ return dataSourceInformationMap.values().iterator();
+ }
+
+ public void registerDataSourceInformationRepositoryListener(DataSourceInformationRepositoryListener listener) {
+ listeners.add(listener);
+ }
+}
\ No newline at end of file
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryListener.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryListener.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceInformationRepositoryListener.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource;
+
+import java.util.Properties;
+
+/**
+ *
+ */
+public interface DataSourceInformationRepositoryListener {
+
+ void addDataSourceInformation(DataSourceInformation dataSourceInformation);
+
+ void removeDataSourceInformation(DataSourceInformation dataSourceInformation);
+
+ void reConfigure(Properties confProperties);
+}
Copied: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java (from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java)
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java?rev=23858&r1=23792&r2=23858&view=diff
==============================================================================
--- /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceManager.java Thu Nov 13 10:30:14 2008
@@ -20,178 +20,149 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.util.MiscellaneousUtil;
-import org.apache.synapse.util.RMIRegistryController;
-import org.apache.synapse.util.datasource.factory.DataSourceInformationFactory;
+import org.apache.synapse.SynapseException;
import javax.naming.Context;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
import java.util.Properties;
/**
* Utility class to handle data source registration
*/
-public class DataSourceRegistrar {
+public class DataSourceManager implements DataSourceInformationRepositoryListener, DataSourceFinder {
- private static final Log log = LogFactory.getLog(DataSourceRegistrar.class);
+ private static final Log log = LogFactory.getLog(DataSourceManager.class);
- /**
- * The static constants only for constructing key prefix for each property
- */
- private static final String PROP_ICFACTORY = "icFactory";
- private static final String PROP_PROVIDER_URL = "providerUrl";
- private static final String PROP_PROVIDER_PORT = "providerPort";
- private static final String DOT_STRING = ".";
- private final static String PROP_REGISTRY = "registry";
- private final static String PROP_REGISTRY_MEMORY = "memory";
- private final static String PROP_REGISTRY_JNDI = "JNDI";
+ private static final DataSourceManager DATA_SOURCE_MANAGER = new DataSourceManager();
+
+ private static final DataSourceRepository IN_MEMORY_REPOSITORY = InMemoryDataSourceRepository.getInstance();
+ private static final DataSourceRepository JNDI_REPOSITORY = JNDIBasedDataSourceRepository.getInstance();
+
+ private DataSourceManager() {
+ }
+
+ public static DataSourceManager getInstance() {
+ return DATA_SOURCE_MANAGER;
+ }
/**
- * Register data sources in the JNDI context
- * Given properties should contains all the properties need for construct JNDI naming references
+ * Find a DataSource using given name
*
- * @param dsProperties The source properties
+ * @param name Name of the DataSource to be found
+ * @return DataSource if found , otherwise null
*/
- public static void registerDataSources(Properties dsProperties) {
+ public DataSource find(String name) {
- if (dsProperties == null) {
- if (log.isDebugEnabled()) {
- log.debug("DataSource properties cannot be found..");
- }
- return;
+ if (name == null || "".equals(name)) {
+ handleException("DataSource name cannot be found.");
}
- String dataSources = MiscellaneousUtil.getProperty(dsProperties,
- SynapseConstants.SYNAPSE_DATASOURCES, null);
+ DataSource result = IN_MEMORY_REPOSITORY.lookUp(name);
- if (dataSources == null || "".equals(dataSources)) {
- if (log.isDebugEnabled()) {
- log.debug("No DataSources defined for initialization..");
- }
- return;
+ if (result != null) {
+ return result;
}
-
- String[] dataSourcesNames = dataSources.split(",");
- if (dataSourcesNames == null || dataSourcesNames.length == 0) {
- if (log.isDebugEnabled()) {
- log.debug("No DataSource definitions found for initialization..");
- }
- return;
- }
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(SynapseConstants.SYNAPSE_DATASOURCES);
- buffer.append(DOT_STRING);
- // The prefix for root level properties
- String rootPrefix = buffer.toString();
-
- Properties jndiEvn = null;
- //Registering data sources with the initial context
- for (String dsName : dataSourcesNames) {
-
- if (dsName == null) {
- continue;
- }
-
- StringBuffer registryBuffer = new StringBuffer();
- registryBuffer.append(rootPrefix);
- registryBuffer.append(dsName);
- registryBuffer.append(DOT_STRING);
- registryBuffer.append(PROP_REGISTRY);
- String registryKey = registryBuffer.toString();
-
- String registry = MiscellaneousUtil.getProperty(dsProperties,
- registryKey, PROP_REGISTRY_MEMORY);
-
-
- DataSourceInformation information =
- DataSourceInformationFactory.
- createDataSourceInformation(dsName, dsProperties);
-
- DataSourceRegistry dataSourceRegistry;
-
- if (PROP_REGISTRY_JNDI.equals(registry)) {
-
- if (jndiEvn == null) {
- jndiEvn = createJNDIEnvironment(dsProperties, rootPrefix);
- }
- dataSourceRegistry = JNDIBasedDataSourceRegistry.getInstance();
- if (!dataSourceRegistry.isInitialized()) {
- dataSourceRegistry.init(jndiEvn);
- }
- } else {
- dataSourceRegistry = InMemoryDataSourceRegistry.getInstance();
- }
- dataSourceRegistry.register(information);
+ if (JNDI_REPOSITORY.isInitialized()) {
+ return IN_MEMORY_REPOSITORY.lookUp(name);
}
+ return null;
}
- private static Properties createJNDIEnvironment(Properties dsProperties, String rootPrefix) {
+ /**
+ * Find a DataSource using the given name and JNDI environment properties
+ *
+ * @param dsName Name of the DataSource to be found
+ * @param jndiEnv JNDI environment properties
+ * @return DataSource if found , otherwise null
+ */
+ public DataSource find(String dsName, Properties jndiEnv) {
- // setting naming provider
- Properties jndiEvn = new Properties(); //This is needed for PerUserPoolDatasource
+ try {
- String namingFactory = MiscellaneousUtil.getProperty(
- dsProperties, rootPrefix + PROP_ICFACTORY,
- "com.sun.jndi.rmi.registry.RegistryContextFactory");
+ Context context = new InitialContext(jndiEnv);
+ return find(dsName, context);
- jndiEvn.put(Context.INITIAL_CONTEXT_FACTORY, namingFactory);
+ } catch (NamingException e) {
+ handleException("Error looking up DataSource : " + dsName +
+ " using JNDI properties : " + jndiEnv, e);
+ }
+ return null;
+ }
- //Provider URL
- String providerUrl = MiscellaneousUtil.getProperty(
- dsProperties, rootPrefix + PROP_PROVIDER_URL, null);
+ /**
+ * Find a DataSource using the given name and naming context
+ *
+ * @param dsName Name of the DataSource to be found
+ * @param context Naming Context
+ * @return DataSource if found , otherwise null
+ */
+ public DataSource find(String dsName, Context context) {
- if (providerUrl != null && !"".equals(providerUrl)) {
- if (log.isDebugEnabled()) {
- log.debug("Using provided initial context provider url :" + providerUrl);
+ try {
+ Object dataSourceO = context.lookup(dsName);
+ if (dataSourceO != null && dataSourceO instanceof DataSource) {
+ return (DataSource) dataSourceO;
+ } else {
+ handleException("DataSource : " + dsName + " not found when looking up" +
+ " using JNDI properties : " + context.getEnvironment());
}
- } else {
- if (log.isDebugEnabled()) {
- log.debug("No initial context provider url...creaeting a new one");
- }
- String providerHost = "localhost";
- try {
- InetAddress addr = InetAddress.getLocalHost();
- if (addr != null) {
- String hostname = addr.getHostName();
- if (hostname == null) {
- String ipAddr = addr.getHostAddress();
- if (ipAddr != null) {
- providerHost = ipAddr;
- }
- } else {
- providerHost = hostname;
- }
- }
- } catch (UnknownHostException e) {
- log.warn("Unable to determine hostname or IP address.. Using localhost", e);
- }
+ } catch (NamingException e) {
+ handleException(new StringBuilder().append("Error looking up DataSource : ")
+ .append(dsName).append(" using JNDI properties : ").
+ append(context).toString(), e);
+ }
+ return null;
+ }
- // default port for RMI registry
- int port = 2199;
- String providerPort =
- MiscellaneousUtil.getProperty(dsProperties, rootPrefix + PROP_PROVIDER_PORT,
- String.valueOf(port));
- try {
- port = Integer.parseInt(providerPort);
- } catch (NumberFormatException ignored) {
- }
+ public void addDataSourceInformation(DataSourceInformation dataSourceInformation) {
- // Create a RMI local registry
- RMIRegistryController.getInstance().createLocalRegistry(port);
+ if (dataSourceInformation == null) {
+ return;
+ }
+ String repositoryType = dataSourceInformation.getRepositoryType();
+ if (DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
+ JNDI_REPOSITORY.register(dataSourceInformation);
+ } else {
+ IN_MEMORY_REPOSITORY.register(dataSourceInformation);
+ }
+ }
- providerUrl = MiscellaneousUtil.getProperty(dsProperties,
- rootPrefix + PROP_PROVIDER_URL,
- "rmi://" + providerHost + ":" + providerPort);
+ public void removeDataSourceInformation(DataSourceInformation dataSourceInformation) {
+ String repositoryType = dataSourceInformation.getRepositoryType();
+ if (DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
+ JNDI_REPOSITORY.unRegister(dataSourceInformation.getDatasourceName());
+ } else {
+ IN_MEMORY_REPOSITORY.unRegister(dataSourceInformation.getDatasourceName());
}
+ }
- jndiEvn.put(Context.PROVIDER_URL, providerUrl);
+ public void reConfigure(Properties confProperties) {
+ JNDI_REPOSITORY.init(confProperties);
+ IN_MEMORY_REPOSITORY.init(confProperties);
+ }
- log.info("DataSources will be registered in the JNDI context with provider PROP_URL : " +
- providerUrl);
- return jndiEvn;
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ */
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
}
+
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ * @param e The exception
+ */
+ private static void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseException(msg, e);
+ }
+
}
Deleted: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistrar.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=23857
Deleted: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=23857
Copied: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java (from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java)
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java?rev=23858&r1=23792&r2=23858&view=diff
==============================================================================
--- /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRegistry.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DataSourceRepository.java Thu Nov 13 10:30:14 2008
@@ -24,7 +24,7 @@
/**
* Keep all DataSources defined in the Synapse
*/
-public interface DataSourceRegistry {
+public interface DataSourceRepository {
/**
* Initialization with given properties
@@ -47,6 +47,9 @@
* @param information DataSourceInformation instance
*/
void register(DataSourceInformation information);
+
+
+ void unRegister(String name);
/**
* Find and Returns an registered DataSource in the DataSourceRegistry
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/DatasourceMBeanRepository.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,108 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.util.MBeanRegistrar;
+import org.apache.synapse.util.MBeanRepository;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class DatasourceMBeanRepository implements MBeanRepository {
+ private final static Log log = LogFactory.getLog(DataSourceInformationRepository.class);
+
+ private final static Map<String, DBPoolView> dataSourcesMBeans = new HashMap<String, DBPoolView>();
+ private final static DatasourceMBeanRepository DATASOURCE_M_BEAN_REPOSITORY = new DatasourceMBeanRepository();
+ private final static String MBEAN_CATEGORY_DATABASE_CONNECTION_POOL = "DatabaseConnectionPool";
+
+ private DatasourceMBeanRepository() {
+ }
+
+ public static DatasourceMBeanRepository getInstance() {
+ return DATASOURCE_M_BEAN_REPOSITORY;
+ }
+
+ public void addMBean(String name, Object mBean) {
+ assertNull(name, "DataSorce MBean name cannot be found.");
+ assertNull(mBean, "DataSorce MBean cannot be found.");
+ assertFalse(mBean instanceof DBPoolView, "Given MBean instance is not matched " +
+ "with the expected MBean - 'DBPoolView'.");
+ dataSourcesMBeans.put(name, (DBPoolView) mBean);
+ MBeanRegistrar mBeanRegistrar = MBeanRegistrar.getInstance();
+ mBeanRegistrar.registerMBean(mBean, MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, name);
+ }
+
+ public Object getMBean(String name) {
+ assertNull(name, "DataSorce MBean name cannot be found.");
+ return dataSourcesMBeans.get(name);
+ }
+
+ public void removeMBean(String name) {
+ dataSourcesMBeans.remove(name);
+ MBeanRegistrar.getInstance().unRegisterMBean(MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, name);
+ }
+
+ public void clear() {
+ if (!dataSourcesMBeans.isEmpty()) {
+ log.info("UnRegistering DBPool MBeans");
+ for (DBPoolView dbPoolView : dataSourcesMBeans.values()) {
+ if (dbPoolView != null) {
+ removeMBean(dbPoolView.getName());
+ }
+ }
+ dataSourcesMBeans.clear();
+ }
+ }
+
+ private void assertNull(String name, String msg) {
+ if (name == null || "".equals(name)) {
+ handleException(msg);
+ }
+ }
+
+ private void assertNull(Object object, String msg) {
+ if (object == null) {
+ handleException(msg);
+ }
+ }
+
+ private void assertFalse(boolean condition, String msg) {
+ if (!condition) {
+ handleException(msg);
+ }
+ }
+
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ */
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+
+}
Deleted: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=23857
Copied: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java (from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java)
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java?rev=23858&r1=23792&r2=23858&view=diff
==============================================================================
--- /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRegistry.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/InMemoryDataSourceRepository.java Thu Nov 13 10:30:14 2008
@@ -24,9 +24,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.util.datasource.factory.DataSourceFactory;
import org.apache.synapse.util.MBeanRepository;
-import org.apache.synapse.util.MBeanRegistrar;
+import org.apache.synapse.util.datasource.factory.DataSourceFactory;
import javax.sql.DataSource;
import java.util.HashMap;
@@ -36,26 +35,25 @@
/**
* Keeps all DataSources in the memory
*/
-public class InMemoryDataSourceRegistry implements DataSourceRegistry, MBeanRepository {
+public class InMemoryDataSourceRepository implements DataSourceRepository {
- private final static Log log = LogFactory.getLog(InMemoryDataSourceRegistry.class);
+ private final static Log log = LogFactory.getLog(InMemoryDataSourceRepository.class);
- private static final InMemoryDataSourceRegistry ourInstance = new InMemoryDataSourceRegistry();
+ private static final InMemoryDataSourceRepository ourInstance = new InMemoryDataSourceRepository();
private final static Map<String, DataSource> dataSources = new HashMap<String, DataSource>();
- private final static Map<String, DBPoolView> dataSourcesMBeans = new HashMap<String, DBPoolView>();
- private final static String MBEAN_CATEGORY_DATABASE_CONNECTION_POOL = "DatabaseConnectionPool";
+ private final static MBeanRepository REPOSITORY = DatasourceMBeanRepository.getInstance();
- public static InMemoryDataSourceRegistry getInstance() {
+ public static InMemoryDataSourceRepository getInstance() {
return ourInstance;
}
- private InMemoryDataSourceRegistry() {
+ private InMemoryDataSourceRepository() {
}
/**
* Keep DataSource in the Local store
*
- * @see org.apache.synapse.util.datasource.DataSourceRegistry#register(DataSourceInformation)
+ * @see DataSourceRepository#register(DataSourceInformation)
*/
public void register(DataSourceInformation information) {
@@ -74,20 +72,29 @@
return;
}
- String name = information.getName();
+ String name = information.getDatasourceName();
if (log.isDebugEnabled()) {
log.debug("Registering a DatSource with name : " + name + " in Local Pool");
}
- addMBean(name, new DBPoolView(name));
+ REPOSITORY.addMBean(name, new DBPoolView(name));
dataSources.put(name, dataSource);
}
+ public void unRegister(String name) {
+
+ if (name == null || "".equals(name)) {
+ return;
+ }
+ dataSources.remove(name);
+ REPOSITORY.removeMBean(name);
+ }
+
/**
* Get a DataSource from Local store
*
- * @see org.apache.synapse.util.datasource.DataSourceRegistry#lookUp(String)
+ * @see DataSourceRepository#lookUp(String)
*/
public DataSource lookUp(String name) {
@@ -108,16 +115,8 @@
log.info("Clearing all in-memory datasources ");
dataSources.clear();
}
- if (!dataSourcesMBeans.isEmpty()) {
- log.info("UnRegistering DBPool MBeans");
- for (DBPoolView dbPoolView : dataSourcesMBeans.values()) {
- if (dbPoolView != null) {
- MBeanRegistrar.getInstance().unRegisterMBean(
- MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, dbPoolView.getName());
- }
- }
- dataSourcesMBeans.clear();
- }
+ REPOSITORY.clear();
+
}
private static void handleException(String msg) {
@@ -125,36 +124,11 @@
throw new SynapseException(msg);
}
- public void addMBean(String name, Object mBean) {
- assertNull(name, "DataSorce MBean name cannot be found.");
- assertNull(mBean, "DataSorce MBean cannot be found.");
- assertFalse(mBean instanceof DBPoolView, "Given MBean instance is not matched " +
- "with the expected MBean - 'DBPoolView'.");
- dataSourcesMBeans.put(name, (DBPoolView) mBean);
- MBeanRegistrar mBeanRegistrar = MBeanRegistrar.getInstance();
- mBeanRegistrar.registerMBean(mBean, MBEAN_CATEGORY_DATABASE_CONNECTION_POOL, name);
- }
-
- public Object getMBean(String name) {
- assertNull(name, "DataSorce MBean name cannot be found.");
- return dataSourcesMBeans.get(name);
- }
private void assertNull(String name, String msg) {
if (name == null || "".equals(name)) {
handleException(msg);
}
}
-
- private void assertNull(Object object, String msg) {
- if (object == null) {
- handleException(msg);
- }
- }
-
- private void assertFalse(boolean condition, String msg) {
- if (!condition) {
- handleException(msg);
- }
- }
+
}
Deleted: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=23857
Copied: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java (from r23792, /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java)
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java?rev=23858&r1=23792&r2=23858&view=diff
==============================================================================
--- /branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRegistry.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java Thu Nov 13 10:30:14 2008
@@ -25,68 +25,69 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
import org.apache.synapse.util.MiscellaneousUtil;
-import org.apache.synapse.util.datasource.factory.DataSourceInformationFactory;
+import org.apache.synapse.util.RMIRegistryController;
import javax.naming.*;
import javax.sql.DataSource;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
/**
* Keep all DataSources in the JNDI Tree
*/
-public class JNDIBasedDataSourceRegistry implements DataSourceRegistry {
+public class JNDIBasedDataSourceRepository implements DataSourceRepository {
- private static Log log = LogFactory.getLog(JNDIBasedDataSourceRegistry.class);
+ private static Log log = LogFactory.getLog(JNDIBasedDataSourceRepository.class);
- private static final JNDIBasedDataSourceRegistry ourInstance =
- new JNDIBasedDataSourceRegistry();
+ private static final JNDIBasedDataSourceRepository ourInstance =
+ new JNDIBasedDataSourceRepository();
private static InitialContext initialContext;
- private static final Properties indiEnv = new Properties();
+ private Properties jndiProperties;
+ private static final Map<String, InitialContext> perDataSourceICMap = new HashMap<String, InitialContext>();
private boolean initialized = false;
- public static JNDIBasedDataSourceRegistry getInstance() {
+ public static JNDIBasedDataSourceRepository getInstance() {
return ourInstance;
}
public void init(Properties jndiEnv) {
- if (!initialized) {
-
- if (jndiEnv == null) {
- handleException("JNDI environment properties cannot be found");
- }
-
- indiEnv.putAll(jndiEnv);
-
- try {
-
- if (log.isDebugEnabled()) {
- log.debug("Initiating a Naming context with JNDI " +
- "environment properties : " + jndiEnv);
- }
-
- initialContext = new InitialContext(jndiEnv);
- initialized = true;
-
- } catch (NamingException e) {
- handleException("Error creating a InitialConext" +
- " with JNDI env properties : " + jndiEnv);
- }
+ initialized = true;
+ if (jndiEnv == null || jndiEnv.isEmpty()) {
+ log.warn("");
+ return;
}
+ jndiProperties = createJNDIEnvironment(jndiEnv, null);
+ initialContext = createInitialContext(jndiEnv);
+
}
- private JNDIBasedDataSourceRegistry() {
+ private JNDIBasedDataSourceRepository() {
}
/**
* Register a DataSource in the JNDI tree
*
- * @see org.apache.synapse.util.datasource.DataSourceRegistry#register(DataSourceInformation)
+ * @see DataSourceRepository#register(DataSourceInformation)
*/
public void register(DataSourceInformation information) {
validateInitialized();
-
+ String dataSourceName = information.getDatasourceName();
+ validateDSName(dataSourceName);
+ Properties jndiEvn = createJNDIEnvironment(information.getProperties(), information.getAlias());
+
+ InitialContext context = createInitialContext(jndiEvn);
+ if (context == null) {
+ validateInitialContext(initialContext);
+ context = initialContext;
+ jndiEvn = jndiProperties;
+ } else {
+ perDataSourceICMap.put(dataSourceName, context);
+ }
String dsType = information.getType();
String driver = information.getDriver();
String url = information.getUrl();
@@ -95,42 +96,36 @@
String maxActive = String.valueOf(information.getMaxActive());
String maxIdle = String.valueOf(information.getMaxIdle());
String maxWait = String.valueOf(information.getMaxWait());
- String dataSourceName = information.getName();
-
- if (dataSourceName == null || "".equals(dataSourceName)) {
- handleException("Invalid DataSource configuration !! -" +
- "DataSource Name cannot be found ");
- }
//populates context tree
- populateContextTree(initialContext, dataSourceName);
+ populateContextTree(context, dataSourceName);
if (DataSourceInformation.BASIC_DATA_SOURCE.equals(dsType)) {
Reference ref = new Reference("javax.sql.DataSource",
"org.apache.commons.dbcp.BasicDataSourceFactory", null);
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_DRIVER_CLS_NAME, driver));
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_URL, url));
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_USER_NAME, user));
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_PASSWORD, password));
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_MAXACTIVE, maxActive));
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_MAXIDLE, maxIdle));
- ref.add(new StringRefAddr(DataSourceInformationFactory.PROP_MAXWAIT, maxWait));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_DRIVER_CLS_NAME, driver));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_URL, url));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_USER_NAME, user));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_PASSWORD, password));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_MAXACTIVE, maxActive));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_MAXIDLE, maxIdle));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_MAXWAIT, maxWait));
// set BasicDataSource specific parameters
setBasicDataSourceParameters(ref, information);
- //set default properties for reference
+ //set default jndiProperties for reference
setCommonParameters(ref, information);
try {
if (log.isDebugEnabled()) {
log.debug("Registering a DataSource with name : " +
- dataSourceName + " in the JNDI tree with properties : " + indiEnv);
+ dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn);
}
- initialContext.rebind(dataSourceName, ref);
+ context.rebind(dataSourceName, ref);
} catch (NamingException e) {
String msg = " Error binding name ' " + dataSourceName + " ' to " +
"the DataSource(BasicDataSource) reference";
@@ -141,28 +136,28 @@
// Construct DriverAdapterCPDS reference
String className = (String) information.getParameter(
- DataSourceInformationFactory.PROP_CPDSADAPTER +
- DataSourceInformationFactory.DOT_STRING +
- DataSourceInformationFactory.PROP_CPDS_CLASS_NAME);
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING +
+ DataSourceConfigurationConstants.PROP_CPDS_CLASS_NAME);
String factory = (String) information.getParameter(
- DataSourceInformationFactory.PROP_CPDSADAPTER +
- DataSourceInformationFactory.DOT_STRING +
- DataSourceInformationFactory.PROP_CPDS_FACTORY);
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING +
+ DataSourceConfigurationConstants.PROP_CPDS_FACTORY);
String name = (String) information.getParameter(
- DataSourceInformationFactory.PROP_CPDSADAPTER +
- DataSourceInformationFactory.DOT_STRING +
- DataSourceInformationFactory.PROP_CPDS_NAME);
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING +
+ DataSourceConfigurationConstants.PROP_CPDS_NAME);
Reference cpdsRef =
new Reference(className, factory, null);
- cpdsRef.add(new StringRefAddr(DataSourceInformationFactory.PROP_DRIVER, driver));
- cpdsRef.add(new StringRefAddr(DataSourceInformationFactory.PROP_URL, url));
- cpdsRef.add(new StringRefAddr(DataSourceInformationFactory.PROP_USER, user));
- cpdsRef.add(new StringRefAddr(DataSourceInformationFactory.PROP_PASSWORD, password));
+ cpdsRef.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_DRIVER, driver));
+ cpdsRef.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_URL, url));
+ cpdsRef.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_USER, user));
+ cpdsRef.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_PASSWORD, password));
try {
- initialContext.rebind(name, cpdsRef);
+ context.rebind(name, cpdsRef);
} catch (NamingException e) {
String msg = "Error binding name '" + name + "' to " +
"the DriverAdapterCPDS reference";
@@ -176,28 +171,28 @@
null);
ref.add(new BinaryRefAddr(
- DataSourceInformationFactory.PROP_JNDI_ENV,
- MiscellaneousUtil.serialize(indiEnv)));
+ DataSourceConfigurationConstants.PROP_JNDI_ENV,
+ MiscellaneousUtil.serialize(jndiProperties)));
ref.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_DATA_SOURCE_NAME, name));
+ DataSourceConfigurationConstants.PROP_DATA_SOURCE_NAME, name));
ref.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_DEFAULTMAXACTIVE, maxActive));
+ DataSourceConfigurationConstants.PROP_DEFAULTMAXACTIVE, maxActive));
ref.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_DEFAULTMAXIDLE, maxIdle));
+ DataSourceConfigurationConstants.PROP_DEFAULTMAXIDLE, maxIdle));
ref.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_DEFAULTMAXWAIT, maxWait));
+ DataSourceConfigurationConstants.PROP_DEFAULTMAXWAIT, maxWait));
- //set default properties for reference
+ //set default jndiProperties for reference
setCommonParameters(ref, information);
try {
if (log.isDebugEnabled()) {
log.debug("Registering a DataSource with name : " +
- dataSourceName + " in the JNDI tree with properties : " + indiEnv);
+ dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn);
}
- initialContext.rebind(dataSourceName, ref);
+ context.rebind(dataSourceName, ref);
} catch (NamingException e) {
String msg = "Error binding name ' " + dataSourceName + " ' to " +
"the PerUserPoolDataSource reference";
@@ -209,25 +204,48 @@
}
}
+ public void unRegister(String name) {
+
+ InitialContext context = getCachedInitialContext(name);
+ try {
+ context.unbind(name);
+ } catch (NamingException e) {
+ handleException("Error removing a Datasource with name : "+
+ name + " from the JNDI context : "+initialContext,e);
+ }
+ }
+
/**
* Get a DatSource which has been registered in the JNDI tree
*
- * @see org.apache.synapse.util.datasource.DataSourceRegistry#lookUp(String)
+ * @see DataSourceRepository#lookUp(String)
*/
public DataSource lookUp(String dsName) {
validateInitialized();
-
+ validateDSName(dsName);
if (log.isDebugEnabled()) {
log.debug("Getting a DataSource with name : " + dsName + " from the JNDI tree.");
}
- return DataSourceFinder.find(dsName, initialContext);
+
+ InitialContext context = getCachedInitialContext(dsName);
+ return DataSourceManager.getInstance().find(dsName, context);
}
public void clear() {
initialized = false;
initialContext = null;
- indiEnv.clear();
+ jndiProperties.clear();
+ perDataSourceICMap.clear();
+ }
+
+ private InitialContext getCachedInitialContext(String name) {
+ InitialContext context = perDataSourceICMap.get(name);
+ if (context == null) {
+ validateInitialContext(initialContext);
+ context = initialContext;
+ }
+ return context;
}
/**
@@ -238,31 +256,31 @@
*/
private static void setCommonParameters(Reference reference, DataSourceInformation information) {
- reference.add(new StringRefAddr(DataSourceInformationFactory.PROP_DEFAULTAUTOCOMMIT,
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_DEFAULTAUTOCOMMIT,
String.valueOf(information.isDefaultAutoCommit())));
- reference.add(new StringRefAddr(DataSourceInformationFactory.PROP_DEFAULTREADONLY,
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_DEFAULTREADONLY,
String.valueOf(information.isDefaultReadOnly())));
- reference.add(new StringRefAddr(DataSourceInformationFactory.PROP_TESTONBORROW,
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_TESTONBORROW,
String.valueOf(information.isTestOnBorrow())));
- reference.add(new StringRefAddr(DataSourceInformationFactory.PROP_TESTONRETURN,
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_TESTONRETURN,
String.valueOf(information.isTestOnReturn())));
reference.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
+ DataSourceConfigurationConstants.PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
String.valueOf(information.getTimeBetweenEvictionRunsMillis())));
- reference.add(new StringRefAddr(DataSourceInformationFactory.PROP_NUMTESTSPEREVICTIONRUN,
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_NUMTESTSPEREVICTIONRUN,
String.valueOf(information.getNumTestsPerEvictionRun())));
reference.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_MINEVICTABLEIDLETIMEMILLIS,
+ DataSourceConfigurationConstants.PROP_MINEVICTABLEIDLETIMEMILLIS,
String.valueOf(information.getMinEvictableIdleTimeMillis())));
reference.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_TESTWHILEIDLE,
+ DataSourceConfigurationConstants.PROP_TESTWHILEIDLE,
String.valueOf(information.isTestWhileIdle())));
String validationQuery = information.getValidationQuery();
if (validationQuery != null && !"".equals(validationQuery)) {
reference.add(new StringRefAddr(
- DataSourceInformationFactory.PROP_VALIDATIONQUERY, validationQuery));
+ DataSourceConfigurationConstants.PROP_VALIDATIONQUERY, validationQuery));
}
}
@@ -279,45 +297,36 @@
if (defaultTransactionIsolation != -1) {
- ref.add(
- new StringRefAddr(
- DataSourceInformationFactory.PROP_DEFAULTTRANSACTIONISOLATION,
- String.valueOf(defaultTransactionIsolation)));
- }
-
- ref.add(
- new StringRefAddr(DataSourceInformationFactory.PROP_MINIDLE,
- String.valueOf(information.getMaxIdle())));
- ref.add(
- new StringRefAddr(
- DataSourceInformationFactory.PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
- String.valueOf(information.isAccessToUnderlyingConnectionAllowed())));
- ref.add(
- new StringRefAddr(
- DataSourceInformationFactory.PROP_REMOVEABANDONED,
- String.valueOf(information.isRemoveAbandoned())));
- ref.add
- (new StringRefAddr(DataSourceInformationFactory.PROP_REMOVEABANDONEDTIMEOUT,
- String.valueOf(information.getRemoveAbandonedTimeout())));
- ref.add
- (new StringRefAddr(
- DataSourceInformationFactory.PROP_LOGABANDONED,
- String.valueOf(information.isLogAbandoned())));
- ref.add(
- new StringRefAddr(
- DataSourceInformationFactory.PROP_POOLPREPAREDSTATEMENTS,
- String.valueOf(information.isPoolPreparedStatements())));
- ref.add(
- new StringRefAddr(DataSourceInformationFactory.PROP_MAXOPENPREPAREDSTATEMENTS,
- String.valueOf(information.getMaxOpenPreparedStatements())));
- ref.add(
- new StringRefAddr(
- DataSourceInformationFactory.PROP_INITIALSIZE, String.valueOf(
- information.getInitialSize())));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_DEFAULTTRANSACTIONISOLATION,
+ String.valueOf(defaultTransactionIsolation)));
+ }
+
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_MINIDLE,
+ String.valueOf(information.getMaxIdle())));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
+ String.valueOf(information.isAccessToUnderlyingConnectionAllowed())));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_REMOVEABANDONED,
+ String.valueOf(information.isRemoveAbandoned())));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_REMOVEABANDONEDTIMEOUT,
+ String.valueOf(information.getRemoveAbandonedTimeout())));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_LOGABANDONED,
+ String.valueOf(information.isLogAbandoned())));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_POOLPREPAREDSTATEMENTS,
+ String.valueOf(information.isPoolPreparedStatements())));
+ ref.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_MAXOPENPREPAREDSTATEMENTS,
+ String.valueOf(information.getMaxOpenPreparedStatements())));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_INITIALSIZE, String.valueOf(
+ information.getInitialSize())));
if (defaultCatalog != null && !"".equals(defaultCatalog)) {
ref.add(new StringRefAddr
- (DataSourceInformationFactory.PROP_DEFAULTCATALOG, defaultCatalog));
+ (DataSourceConfigurationConstants.PROP_DEFAULTCATALOG, defaultCatalog));
}
}
@@ -349,6 +358,86 @@
}
}
+ private static Properties createJNDIEnvironment(Properties dsProperties, String name) {
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
+ if (name != null && !"".equals(name)) {
+ buffer.append(name);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
+ }
+ // The prefix for root level jndiProperties
+ String rootPrefix = buffer.toString();
+ // setting naming provider
+ Properties jndiEvn = new Properties(); //This is needed for PerUserPoolDatasource
+
+ String namingFactory = MiscellaneousUtil.getProperty(
+ dsProperties, rootPrefix + DataSourceConfigurationConstants.PROP_ICFACTORY,
+ "com.sun.jndi.rmi.registry.RegistryContextFactory");
+
+ jndiEvn.put(Context.INITIAL_CONTEXT_FACTORY, namingFactory);
+
+ //Provider URL
+ String providerUrl = MiscellaneousUtil.getProperty(
+ dsProperties, rootPrefix + DataSourceConfigurationConstants.PROP_PROVIDER_URL, null);
+
+ if (providerUrl != null && !"".equals(providerUrl)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Using provided initial context provider url :" + providerUrl);
+ }
+
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("No initial context provider url...creaeting a new one");
+ }
+ String providerHost = "localhost";
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ if (addr != null) {
+ String hostname = addr.getHostName();
+ if (hostname == null) {
+ String ipAddr = addr.getHostAddress();
+ if (ipAddr != null) {
+ providerHost = ipAddr;
+ }
+ } else {
+ providerHost = hostname;
+ }
+ }
+ } catch (UnknownHostException e) {
+ log.warn("Unable to determine hostname or IP address.. Using localhost", e);
+ }
+
+ // default port for RMI registry
+ int port = 2199;
+ String providerPort =
+ MiscellaneousUtil.getProperty(dsProperties, rootPrefix + DataSourceConfigurationConstants.PROP_PROVIDER_PORT,
+ String.valueOf(port));
+ try {
+ port = Integer.parseInt(providerPort);
+ } catch (NumberFormatException ignored) {
+ }
+
+ // Create a RMI local registry
+ RMIRegistryController.getInstance().createLocalRegistry(port);
+
+ providerUrl = MiscellaneousUtil.getProperty(dsProperties,
+ rootPrefix + DataSourceConfigurationConstants.PROP_PROVIDER_URL,
+ "rmi://" + providerHost + ":" + providerPort);
+ }
+
+ jndiEvn.put(Context.PROVIDER_URL, providerUrl);
+
+ log.info("DataSources will be registered in the JNDI context with provider PROP_URL : " +
+ providerUrl);
+ return jndiEvn;
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
+
/**
* Helper methods for handle errors.
*
@@ -376,7 +465,37 @@
}
}
- public boolean isInitialized() {
- return initialized;
+ private void validateDSName(String dataSourceName) {
+ if (dataSourceName == null || "".equals(dataSourceName)) {
+ handleException("Invalid DataSource configuration !! -" +
+ "DataSource Name cannot be found ");
+ }
+ }
+
+ private void validateInitialContext(InitialContext initialContext) {
+ if (initialContext == null) {
+ handleException("InitialContext cannot be found.");
+ }
+ }
+
+ private InitialContext createInitialContext(Properties jndiEnv) {
+
+ if (jndiEnv == null || jndiEnv.isEmpty()) {
+ return null;
+ }
+ try {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Initiating a Naming context with JNDI " +
+ "environment jndiProperties : " + jndiEnv);
+ }
+
+ return new InitialContext(jndiEnv);
+
+ } catch (NamingException e) {
+ handleException("Error creating a InitialConext" +
+ " with JNDI env jndiProperties : " + jndiEnv);
+ }
+ return null;
}
}
Modified: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java?rev=23858&r1=23857&r2=23858&view=diff
==============================================================================
--- branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java (original)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java Thu Nov 13 10:30:14 2008
@@ -22,9 +22,9 @@
import org.apache.commons.logging.LogFactory;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
-import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
import org.apache.synapse.util.MiscellaneousUtil;
+import org.apache.synapse.util.datasource.DataSourceConfigurationConstants;
import org.apache.synapse.util.datasource.DataSourceInformation;
import java.util.Properties;
@@ -37,55 +37,6 @@
private static final Log log = LogFactory.getLog(DataSourceInformationFactory.class);
- public static final String PROP_ICFACTORY = "icFactory";
- public static final String PROP_PROVIDER_URL = "providerUrl";
- public static final String PROP_PROVIDER_PORT = "providerPort";
- public static final String DOT_STRING = ".";
- public static final String PROP_USER_NAME = "username";
- public static final String PROP_PASSWORD = "password";
- public static final String PROP_DRIVER_CLS_NAME = "driverClassName";
- public static final String PROP_DSNAME = "dsName";
- public static final String PROP_URL = "url";
- public static final String PROP_DRIVER = "driver";
- public static final String PROP_USER = "user";
-
-
- public static final String PROP_CPDSADAPTER = "cpdsadapter";
- public static final String PROP_JNDI_ENV = "jndiEnvironment";
- public static final String PROP_DEFAULTMAXACTIVE = "defaultMaxActive";
- public static final String PROP_DEFAULTMAXIDLE = "defaultMaxIdle";
- public static final String PROP_DEFAULTMAXWAIT = "defaultMaxWait";
- public static final String PROP_DATA_SOURCE_NAME = "dataSourceName";
- public static final String PROP_CPDS_CLASS_NAME = "className";
- public static final String PROP_CPDS_FACTORY = "factory";
- public static final String PROP_CPDS_NAME = "name";
-
- public final static String PROP_DEFAULTAUTOCOMMIT = "defaultAutoCommit";
- public final static String PROP_DEFAULTREADONLY = "defaultReadOnly";
- public final static String PROP_TESTONBORROW = "testOnBorrow";
- public final static String PROP_TESTONRETURN = "testOnReturn";
- public final static String PROP_TIMEBETWEENEVICTIONRUNSMILLIS =
- "timeBetweenEvictionRunsMillis";
- public final static String PROP_NUMTESTSPEREVICTIONRUN = "numTestsPerEvictionRun";
- public final static String PROP_MINEVICTABLEIDLETIMEMILLIS = "minEvictableIdleTimeMillis";
- public final static String PROP_TESTWHILEIDLE = "testWhileIdle";
- public final static String PROP_VALIDATIONQUERY = "validationQuery";
- public final static String PROP_MAXACTIVE = "maxActive";
- public final static String PROP_MAXIDLE = "maxIdle";
- public final static String PROP_MAXWAIT = "maxWait";
-
- public final static String PROP_MINIDLE = "minIdle";
- public final static String PROP_INITIALSIZE = "initialSize";
- public final static String PROP_DEFAULTTRANSACTIONISOLATION = "defaultTransactionIsolation";
- public final static String PROP_DEFAULTCATALOG = "defaultCatalog";
- public final static String PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED =
- "accessToUnderlyingConnectionAllowed";
- public final static String PROP_REMOVEABANDONED = "removeAbandoned";
- public final static String PROP_REMOVEABANDONEDTIMEOUT = "removeAbandonedTimeout";
- public final static String PROP_LOGABANDONED = "logAbandoned";
- public final static String PROP_POOLPREPAREDSTATEMENTS = "poolPreparedStatements";
- public final static String PROP_MAXOPENPREPAREDSTATEMENTS = "maxOpenPreparedStatements";
- public final static String PROP_CONNECTIONPROPERTIES = "connectionProperties";
private DataSourceInformationFactory() {
}
@@ -107,142 +58,146 @@
}
StringBuffer buffer = new StringBuffer();
- buffer.append(SynapseConstants.SYNAPSE_DATASOURCES);
- buffer.append(DOT_STRING);
+ buffer.append(DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
buffer.append(dsName);
- buffer.append(DOT_STRING);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
// Prefix for getting particular data source's properties
String prefix = buffer.toString();
String driver = MiscellaneousUtil.getProperty(
- properties, prefix + PROP_DRIVER_CLS_NAME, null);
+ properties, prefix + DataSourceConfigurationConstants.PROP_DRIVER_CLS_NAME, null);
if (driver == null) {
- handleException(prefix + PROP_DRIVER_CLS_NAME + " cannot be found.");
+ handleException(prefix + DataSourceConfigurationConstants.PROP_DRIVER_CLS_NAME + " cannot be found.");
}
- String url = MiscellaneousUtil.getProperty(properties, prefix + PROP_URL, null);
+ String url = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConfigurationConstants.PROP_URL, null);
if (url == null) {
- handleException(prefix + PROP_URL + " cannot be found.");
+ handleException(prefix + DataSourceConfigurationConstants.PROP_URL + " cannot be found.");
}
DataSourceInformation information = new DataSourceInformation();
+ information.setAlias(dsName);
information.setDriver(driver);
information.setUrl(url);
// get other required properties
String user = (String) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_USER_NAME, "synapse", String.class);
+ properties, prefix + DataSourceConfigurationConstants.PROP_USER_NAME, "synapse", String.class);
information.setUser(user);
String password = (String) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_PASSWORD, "synapse", String.class);
+ properties, prefix + DataSourceConfigurationConstants.PROP_PASSWORD, "synapse", String.class);
information.setPassword(password);
String dataSourceName = (String) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_DSNAME, dsName, String.class);
- information.setName(dataSourceName);
+ properties, prefix + DataSourceConfigurationConstants.PROP_DSNAME, dsName, String.class);
+ information.setDatasourceName(dataSourceName);
String dsType = (String) MiscellaneousUtil.getProperty(
- properties, prefix + "type", "BasicDataSource", String.class);
+ properties, prefix + DataSourceConfigurationConstants.PROP_TYPE,
+ DataSourceConfigurationConstants.PROP_BASIC_DATA_SOURCE, String.class);
information.setType(dsType);
Integer maxActive = (Integer) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_MAXACTIVE,
+ properties, prefix + DataSourceConfigurationConstants.PROP_MAXACTIVE,
GenericObjectPool.DEFAULT_MAX_ACTIVE, Integer.class);
information.setMaxActive(maxActive);
Integer maxIdle = (Integer) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_MAXIDLE,
+ properties, prefix + DataSourceConfigurationConstants.PROP_MAXIDLE,
GenericObjectPool.DEFAULT_MAX_IDLE, Integer.class);
information.setMaxIdle(maxIdle);
Long maxWait = (Long) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_MAXWAIT,
+ properties, prefix + DataSourceConfigurationConstants.PROP_MAXWAIT,
GenericObjectPool.DEFAULT_MAX_WAIT, Long.class);
information.setMaxWait(maxWait);
// Construct DriverAdapterCPDS reference
- String suffix = PROP_CPDSADAPTER +
- DOT_STRING + "className";
+ String suffix = DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING + DataSourceConfigurationConstants.PROP_CLASS_NAME;
String className = MiscellaneousUtil.getProperty(properties, prefix + suffix,
- "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS");
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER_DRIVER);
information.addParameter(suffix, className);
- suffix = PROP_CPDSADAPTER +
- DOT_STRING + "factory";
+ suffix = DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING + DataSourceConfigurationConstants.PROP_FACTORY;
String factory = MiscellaneousUtil.getProperty(properties, prefix + suffix,
- "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS");
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER_DRIVER);
information.addParameter(suffix, factory);
- suffix = PROP_CPDSADAPTER +
- DOT_STRING + "name";
+ suffix = DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING + DataSourceConfigurationConstants.PROP_NAME;
String name = MiscellaneousUtil.getProperty(properties, prefix + suffix,
"cpds");
information.addParameter(suffix, name);
boolean defaultAutoCommit = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_DEFAULTAUTOCOMMIT, true, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_DEFAULTAUTOCOMMIT, true, Boolean.class);
boolean defaultReadOnly = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_DEFAULTREADONLY, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_DEFAULTREADONLY, false, Boolean.class);
boolean testOnBorrow = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TESTONBORROW, true, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_TESTONBORROW, true, Boolean.class);
boolean testOnReturn = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TESTONRETURN, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_TESTONRETURN, false, Boolean.class);
long timeBetweenEvictionRunsMillis = (Long) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
+ prefix + DataSourceConfigurationConstants.PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, Long.class);
int numTestsPerEvictionRun = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_NUMTESTSPEREVICTIONRUN,
+ prefix + DataSourceConfigurationConstants.PROP_NUMTESTSPEREVICTIONRUN,
GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, Integer.class);
long minEvictableIdleTimeMillis = (Long) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_MINEVICTABLEIDLETIMEMILLIS,
+ prefix + DataSourceConfigurationConstants.PROP_MINEVICTABLEIDLETIMEMILLIS,
GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, Long.class);
boolean testWhileIdle = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TESTWHILEIDLE, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_TESTWHILEIDLE, false, Boolean.class);
String validationQuery = MiscellaneousUtil.getProperty(properties,
- prefix + PROP_VALIDATIONQUERY, null);
+ prefix + DataSourceConfigurationConstants.PROP_VALIDATIONQUERY, null);
int minIdle = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_MINIDLE, GenericObjectPool.DEFAULT_MIN_IDLE, Integer.class);
+ prefix + DataSourceConfigurationConstants.PROP_MINIDLE, GenericObjectPool.DEFAULT_MIN_IDLE,
+ Integer.class);
int initialSize = (Integer) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_INITIALSIZE, 0, Integer.class);
+ properties, prefix + DataSourceConfigurationConstants.PROP_INITIALSIZE, 0, Integer.class);
int defaultTransactionIsolation = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_DEFAULTTRANSACTIONISOLATION, -1, Integer.class);
+ prefix + DataSourceConfigurationConstants.PROP_DEFAULTTRANSACTIONISOLATION, -1, Integer.class);
String defaultCatalog = MiscellaneousUtil.getProperty(
- properties, prefix + PROP_DEFAULTCATALOG, null);
+ properties, prefix + DataSourceConfigurationConstants.PROP_DEFAULTCATALOG, null);
boolean accessToUnderlyingConnectionAllowed =
(Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
+ false, Boolean.class);
boolean removeAbandoned = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_REMOVEABANDONED, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_REMOVEABANDONED, false, Boolean.class);
int removeAbandonedTimeout = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_REMOVEABANDONEDTIMEOUT, 300, Integer.class);
+ prefix + DataSourceConfigurationConstants.PROP_REMOVEABANDONEDTIMEOUT, 300, Integer.class);
boolean logAbandoned = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_LOGABANDONED, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_LOGABANDONED, false, Boolean.class);
boolean poolPreparedStatements = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_POOLPREPAREDSTATEMENTS, false, Boolean.class);
+ prefix + DataSourceConfigurationConstants.PROP_POOLPREPAREDSTATEMENTS, false, Boolean.class);
int maxOpenPreparedStatements = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_MAXOPENPREPAREDSTATEMENTS,
+ prefix + DataSourceConfigurationConstants.PROP_MAXOPENPREPAREDSTATEMENTS,
GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, Integer.class);
information.setDefaultAutoCommit(defaultAutoCommit);
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource.factory;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.util.MiscellaneousUtil;
+import org.apache.synapse.util.datasource.DataSourceConfigurationConstants;
+import org.apache.synapse.util.datasource.DataSourceInformation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ *
+ */
+public class DataSourceInformationListFactory {
+
+ private static final Log log = LogFactory.getLog(DataSourceInformationListFactory.class);
+
+ public static List<DataSourceInformation> createDataSourceInformationList(Properties dsProperties) {
+
+ final List<DataSourceInformation> dataSourceInformations = new ArrayList<DataSourceInformation>();
+ if (dsProperties == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("DataSource properties cannot be found..");
+ }
+ return dataSourceInformations;
+ }
+
+ String dataSources = MiscellaneousUtil.getProperty(dsProperties,
+ DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES, null);
+
+ if (dataSources == null || "".equals(dataSources)) {
+ if (log.isDebugEnabled()) {
+ log.debug("No DataSources defined for initialization..");
+ }
+ return dataSourceInformations;
+ }
+
+ String[] dataSourcesNames = dataSources.split(",");
+ if (dataSourcesNames == null || dataSourcesNames.length == 0) {
+ if (log.isDebugEnabled()) {
+ log.debug("No DataSource definitions found for initialization..");
+ }
+ return dataSourceInformations;
+ }
+
+
+ for (String dsName : dataSourcesNames) {
+
+ if (dsName == null) {
+ continue;
+ }
+ DataSourceInformation information =
+ DataSourceInformationFactory.
+ createDataSourceInformation(dsName, dsProperties);
+ if (information == null) {
+ continue;
+ }
+ dataSourceInformations.add(information);
+ }
+ return dataSourceInformations;
+ }
+
+}
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource.factory;
+
+import org.apache.synapse.util.datasource.DataSourceInformation;
+import org.apache.synapse.util.datasource.DataSourceInformationRepository;
+import org.apache.synapse.util.datasource.DataSourceManager;
+
+import java.util.List;
+import java.util.Properties;
+
+/**
+ *
+ */
+public class DataSourceInformationRepositoryFactory {
+
+ public static DataSourceInformationRepository createDataSourceInformationRepository(Properties properties) {
+ List<DataSourceInformation> dataSourceInformations = DataSourceInformationListFactory.createDataSourceInformationList(properties);
+ DataSourceInformationRepository repository = new DataSourceInformationRepository();
+ repository.setConfigurationProperties(properties);
+ repository.registerDataSourceInformationRepositoryListener(DataSourceManager.getInstance());
+ for (DataSourceInformation information : dataSourceInformations) {
+ if (information != null) {
+ repository.addDataSourceInformation(information);
+ }
+ }
+ return repository;
+ }
+}
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource.serializer;
+
+import org.apache.synapse.util.datasource.DataSourceConfigurationConstants;
+import org.apache.synapse.util.datasource.DataSourceInformation;
+
+import java.util.List;
+import java.util.Properties;
+
+/**
+ *
+ */
+public class DataSourceInformationListSerializer {
+
+ public static Properties serialize(List<DataSourceInformation> dataSourceInformationList) {
+ final Properties properties = new Properties();
+ StringBuffer dataSources = new StringBuffer();
+
+ for (DataSourceInformation information : dataSourceInformationList) {
+ if (information != null) {
+ String name = information.getAlias();
+ dataSources.append(name);
+ dataSources.append(DataSourceConfigurationConstants.COMMA_STRING);
+ properties.putAll(DataSourceInformationSerializer.serialize(information));
+ }
+ }
+ properties.put(DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES, dataSources.toString());
+ return properties;
+ }
+}
Added: branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java
URL: http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java?pathrev=23858
==============================================================================
--- (empty file)
+++ branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java Thu Nov 13 10:30:14 2008
@@ -0,0 +1,138 @@
+/*
+ * 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.
+ */
+package org.apache.synapse.util.datasource.serializer;
+
+import org.apache.synapse.util.datasource.DataSourceConfigurationConstants;
+import org.apache.synapse.util.datasource.DataSourceInformation;
+
+import java.util.Properties;
+
+/**
+ *
+ */
+public class DataSourceInformationSerializer {
+
+ public static Properties serialize(DataSourceInformation information) {
+
+ final Properties properties = new Properties();
+
+ String alias = information.getAlias();
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
+ buffer.append(alias);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
+
+ // Prefix for getting particular data source's properties
+ String prefix = buffer.toString();
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_USER,
+ information.getUser());
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_PASSWORD,
+ information.getPassword());
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_MAXACTIVE,
+ String.valueOf(information.getMaxActive()));
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_MAXIDLE,
+ String.valueOf(information.getMaxIdle()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_MAXWAIT,
+ String.valueOf(information.getMaxWait()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_DRIVER_CLS_NAME,
+ String.valueOf(information.getDriver()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_URL,
+ String.valueOf(information.getUrl()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_TYPE,
+ String.valueOf(information.getType()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_DEFAULTAUTOCOMMIT,
+ String.valueOf(information.isDefaultAutoCommit()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_DEFAULTREADONLY,
+ String.valueOf(information.isDefaultReadOnly()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_TESTONBORROW,
+ String.valueOf(information.isTestOnBorrow()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_TESTONRETURN,
+ String.valueOf(information.isTestOnReturn()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_MINIDLE,
+ String.valueOf(information.getMinIdle()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_INITIALSIZE,
+ String.valueOf(information.getInitialSize()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_DEFAULTTRANSACTIONISOLATION,
+ String.valueOf(information.getDefaultTransactionIsolation()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_DEFAULTCATALOG,
+ String.valueOf(information.getDefaultCatalog()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
+ String.valueOf(information.isAccessToUnderlyingConnectionAllowed()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_REMOVEABANDONED,
+ String.valueOf(information.isRemoveAbandoned()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_REMOVEABANDONEDTIMEOUT,
+ String.valueOf(information.getRemoveAbandonedTimeout()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_LOGABANDONED,
+ String.valueOf(information.isLogAbandoned()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_POOLPREPAREDSTATEMENTS,
+ String.valueOf(information.isPoolPreparedStatements()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_MAXOPENPREPAREDSTATEMENTS,
+ String.valueOf(information.getMaxOpenPreparedStatements()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_REGISTRY,
+ String.valueOf(information.getRepositoryType()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
+ String.valueOf(information.getTimeBetweenEvictionRunsMillis()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_NUMTESTSPEREVICTIONRUN,
+ String.valueOf(information.getNumTestsPerEvictionRun()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_MINEVICTABLEIDLETIMEMILLIS,
+ String.valueOf(information.getMinEvictableIdleTimeMillis()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_TESTWHILEIDLE,
+ String.valueOf(information.isTestWhileIdle()));
+
+ addProperty(properties, prefix + DataSourceConfigurationConstants.PROP_VALIDATIONQUERY,
+ String.valueOf(information.getValidationQuery()));
+
+ properties.putAll(information.getAllParameters());
+ properties.putAll(information.getProperties());
+
+ return properties;
+
+ }
+
+ private static void addProperty(Properties properties, String key, String value) {
+ if (value != null && !"".equals(value)) {
+ properties.setProperty(key, value);
+ }
+ }
+}
More information about the Esb-java-dev
mailing list