You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2008/11/13 20:00:57 UTC
svn commit: r713788 [2/2] - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: ./
config/ config/xml/ endpoints/dispatch/ registry/url/ util/
util/datasource/ util/datasource/factory/ util/datasource/serializer/
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java?rev=713788&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/JNDIBasedDataSourceRepository.java Thu Nov 13 11:00:56 2008
@@ -0,0 +1,501 @@
+/*
+ * 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.
+ */
+/**
+ * To change this template use File | Settings | File Templates.
+ */
+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.MiscellaneousUtil;
+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 JNDIBasedDataSourceRepository implements DataSourceRepository {
+
+ private static Log log = LogFactory.getLog(JNDIBasedDataSourceRepository.class);
+
+ private static final JNDIBasedDataSourceRepository ourInstance =
+ new JNDIBasedDataSourceRepository();
+ private static InitialContext initialContext;
+ private Properties jndiProperties;
+ private static final Map<String, InitialContext> perDataSourceICMap = new HashMap<String, InitialContext>();
+ private boolean initialized = false;
+
+ public static JNDIBasedDataSourceRepository getInstance() {
+ return ourInstance;
+ }
+
+ public void init(Properties jndiEnv) {
+
+ initialized = true;
+ if (jndiEnv == null || jndiEnv.isEmpty()) {
+ log.warn("");
+ return;
+ }
+ jndiProperties = createJNDIEnvironment(jndiEnv, null);
+ initialContext = createInitialContext(jndiEnv);
+
+ }
+
+ private JNDIBasedDataSourceRepository() {
+ }
+
+ /**
+ * Register a DataSource in the JNDI tree
+ *
+ * @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();
+ String user = information.getUser();
+ String password = information.getPassword();
+ String maxActive = String.valueOf(information.getMaxActive());
+ String maxIdle = String.valueOf(information.getMaxIdle());
+ String maxWait = String.valueOf(information.getMaxWait());
+
+ //populates context tree
+ 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(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 jndiProperties for reference
+ setCommonParameters(ref, information);
+
+ try {
+
+ if (log.isDebugEnabled()) {
+ log.debug("Registering a DataSource with name : " +
+ dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn);
+ }
+
+ context.rebind(dataSourceName, ref);
+ } catch (NamingException e) {
+ String msg = " Error binding name ' " + dataSourceName + " ' to " +
+ "the DataSource(BasicDataSource) reference";
+ handleException(msg, e);
+ }
+
+ } else if (DataSourceInformation.PER_USER_POOL_DATA_SOURCE.equals(dsType)) {
+
+ // Construct DriverAdapterCPDS reference
+ String className = (String) information.getParameter(
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING +
+ DataSourceConfigurationConstants.PROP_CPDS_CLASS_NAME);
+ String factory = (String) information.getParameter(
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING +
+ DataSourceConfigurationConstants.PROP_CPDS_FACTORY);
+ String name = (String) information.getParameter(
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING +
+ DataSourceConfigurationConstants.PROP_CPDS_NAME);
+
+ Reference cpdsRef =
+ new Reference(className, factory, null);
+
+ 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 {
+ context.rebind(name, cpdsRef);
+ } catch (NamingException e) {
+ String msg = "Error binding name '" + name + "' to " +
+ "the DriverAdapterCPDS reference";
+ handleException(msg, e);
+ }
+
+ // Construct PerUserPoolDataSource reference
+ Reference ref =
+ new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource",
+ "org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory",
+ null);
+
+ ref.add(new BinaryRefAddr(
+ DataSourceConfigurationConstants.PROP_JNDI_ENV,
+ MiscellaneousUtil.serialize(jndiProperties)));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_DATA_SOURCE_NAME, name));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_DEFAULTMAXACTIVE, maxActive));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_DEFAULTMAXIDLE, maxIdle));
+ ref.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_DEFAULTMAXWAIT, maxWait));
+
+ //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 jndiProperties : " + jndiEvn);
+ }
+
+ context.rebind(dataSourceName, ref);
+ } catch (NamingException e) {
+ String msg = "Error binding name ' " + dataSourceName + " ' to " +
+ "the PerUserPoolDataSource reference";
+ handleException(msg, e);
+ }
+
+ } else {
+ handleException("Unsupported data source type : " + dsType);
+ }
+ }
+
+ 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 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.");
+ }
+
+ InitialContext context = getCachedInitialContext(dsName);
+ return DataSourceManager.getInstance().find(dsName, context);
+ }
+
+ public void clear() {
+ initialized = false;
+ initialContext = null;
+ jndiProperties.clear();
+ perDataSourceICMap.clear();
+ }
+
+ private InitialContext getCachedInitialContext(String name) {
+ InitialContext context = perDataSourceICMap.get(name);
+ if (context == null) {
+ validateInitialContext(initialContext);
+ context = initialContext;
+ }
+ return context;
+ }
+
+ /**
+ * Helper method to set all default parameter for naming reference of data source
+ *
+ * @param reference The naming reference instance
+ * @param information DataSourceInformation instance
+ */
+ private static void setCommonParameters(Reference reference, DataSourceInformation information) {
+
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_DEFAULTAUTOCOMMIT,
+ String.valueOf(information.isDefaultAutoCommit())));
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_DEFAULTREADONLY,
+ String.valueOf(information.isDefaultReadOnly())));
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_TESTONBORROW,
+ String.valueOf(information.isTestOnBorrow())));
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_TESTONRETURN,
+ String.valueOf(information.isTestOnReturn())));
+ reference.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
+ String.valueOf(information.getTimeBetweenEvictionRunsMillis())));
+ reference.add(new StringRefAddr(DataSourceConfigurationConstants.PROP_NUMTESTSPEREVICTIONRUN,
+ String.valueOf(information.getNumTestsPerEvictionRun())));
+ reference.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_MINEVICTABLEIDLETIMEMILLIS,
+ String.valueOf(information.getMinEvictableIdleTimeMillis())));
+ reference.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_TESTWHILEIDLE,
+ String.valueOf(information.isTestWhileIdle())));
+
+ String validationQuery = information.getValidationQuery();
+
+ if (validationQuery != null && !"".equals(validationQuery)) {
+ reference.add(new StringRefAddr(
+ DataSourceConfigurationConstants.PROP_VALIDATIONQUERY, validationQuery));
+ }
+ }
+
+ /**
+ * Helper method to set all BasicDataSource specific parameter
+ *
+ * @param ref The naming reference instance
+ * @param information DataSourceInformation instance
+ */
+ private static void setBasicDataSourceParameters(Reference ref, DataSourceInformation information) {
+
+ int defaultTransactionIsolation = information.getDefaultTransactionIsolation();
+ String defaultCatalog = information.getDefaultCatalog();
+
+
+ if (defaultTransactionIsolation != -1) {
+ 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
+ (DataSourceConfigurationConstants.PROP_DEFAULTCATALOG, defaultCatalog));
+ }
+ }
+
+ /**
+ * Helper method to create context tree for a given path
+ *
+ * @param initialContext The root context
+ * @param path The path of the resource
+ */
+ private static void populateContextTree(InitialContext initialContext, String path) {
+
+ String[] paths = path.split("/");
+ if (paths != null && paths.length > 1) {
+
+ Context context = initialContext;
+ for (String path1 : paths) {
+
+ try {
+ assert context != null;
+ context = context.createSubcontext(path1);
+ if (context == null) {
+ handleException("sub context " + path1 + " could not be created");
+ }
+
+ } catch (NamingException e) {
+ handleException("Unable to create sub context : " + path1, e);
+ }
+ }
+ }
+ }
+
+ 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.
+ *
+ * @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);
+ }
+
+ private void validateInitialized() {
+ if (!isInitialized()) {
+ handleException("Datasource registry has not been initialized yet");
+ }
+ }
+
+ 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: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java?rev=713788&r1=713787&r2=713788&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationFactory.java Thu Nov 13 11:00:56 2008
@@ -1,279 +1,235 @@
-/*
- * 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.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.DataSourceInformation;
-
-import java.util.Properties;
-
-/**
- * Factory to create a DataSourceInformation based on given properties
- */
-
-public class DataSourceInformationFactory {
-
- 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() {
- }
-
- /**
- * Factory method to create a DataSourceInformation instance based on given properties
- *
- * @param dsName DataSource Name
- * @param properties Properties to create and configure DataSource
- * @return DataSourceInformation instance
- */
- public static DataSourceInformation createDataSourceInformation(String dsName, Properties properties) {
-
- if (dsName == null || "".equals(dsName)) {
- if (log.isDebugEnabled()) {
- log.debug("DataSource name is either empty or null, ignoring..");
- }
- return null;
- }
-
- StringBuffer buffer = new StringBuffer();
- buffer.append(SynapseConstants.SYNAPSE_DATASOURCES);
- buffer.append(DOT_STRING);
- buffer.append(dsName);
- buffer.append(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);
- if (driver == null) {
- handleException(prefix + PROP_DRIVER_CLS_NAME + " cannot be found.");
- }
-
- String url = MiscellaneousUtil.getProperty(properties, prefix + PROP_URL, null);
- if (url == null) {
- handleException(prefix + PROP_URL + " cannot be found.");
- }
-
- DataSourceInformation information = new DataSourceInformation();
-
- information.setDriver(driver);
- information.setUrl(url);
-
- // get other required properties
- String user = (String) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_USER_NAME, "synapse", String.class);
- information.setUser(user);
-
- String password = (String) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_PASSWORD, "synapse", String.class);
-
- information.setPassword(password);
-
- String dataSourceName = (String) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_DSNAME, dsName, String.class);
- information.setName(dataSourceName);
-
- String dsType = (String) MiscellaneousUtil.getProperty(
- properties, prefix + "type", "BasicDataSource", String.class);
-
- information.setType(dsType);
-
- Integer maxActive = (Integer) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_MAXACTIVE,
- GenericObjectPool.DEFAULT_MAX_ACTIVE, Integer.class);
- information.setMaxActive(maxActive);
-
- Integer maxIdle = (Integer) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_MAXIDLE,
- GenericObjectPool.DEFAULT_MAX_IDLE, Integer.class);
- information.setMaxIdle(maxIdle);
-
- Long maxWait = (Long) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_MAXWAIT,
- GenericObjectPool.DEFAULT_MAX_WAIT, Long.class);
-
- information.setMaxWait(maxWait);
-
- // Construct DriverAdapterCPDS reference
- String suffix = PROP_CPDSADAPTER +
- DOT_STRING + "className";
- String className = MiscellaneousUtil.getProperty(properties, prefix + suffix,
- "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS");
- information.addParameter(suffix, className);
- suffix = PROP_CPDSADAPTER +
- DOT_STRING + "factory";
- String factory = MiscellaneousUtil.getProperty(properties, prefix + suffix,
- "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS");
- information.addParameter(suffix, factory);
- suffix = PROP_CPDSADAPTER +
- DOT_STRING + "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);
-
- boolean defaultReadOnly = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_DEFAULTREADONLY, false, Boolean.class);
-
- boolean testOnBorrow = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TESTONBORROW, true, Boolean.class);
-
- boolean testOnReturn = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TESTONRETURN, false, Boolean.class);
-
- long timeBetweenEvictionRunsMillis = (Long) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
- GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, Long.class);
-
- int numTestsPerEvictionRun = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_NUMTESTSPEREVICTIONRUN,
- GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, Integer.class);
-
- long minEvictableIdleTimeMillis = (Long) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_MINEVICTABLEIDLETIMEMILLIS,
- GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, Long.class);
-
- boolean testWhileIdle = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_TESTWHILEIDLE, false, Boolean.class);
-
- String validationQuery = MiscellaneousUtil.getProperty(properties,
- prefix + PROP_VALIDATIONQUERY, null);
-
- int minIdle = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_MINIDLE, GenericObjectPool.DEFAULT_MIN_IDLE, Integer.class);
-
- int initialSize = (Integer) MiscellaneousUtil.getProperty(
- properties, prefix + PROP_INITIALSIZE, 0, Integer.class);
-
- int defaultTransactionIsolation = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_DEFAULTTRANSACTIONISOLATION, -1, Integer.class);
-
- String defaultCatalog = MiscellaneousUtil.getProperty(
- properties, prefix + PROP_DEFAULTCATALOG, null);
-
- boolean accessToUnderlyingConnectionAllowed =
- (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED, false, Boolean.class);
-
- boolean removeAbandoned = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_REMOVEABANDONED, false, Boolean.class);
-
- int removeAbandonedTimeout = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_REMOVEABANDONEDTIMEOUT, 300, Integer.class);
-
- boolean logAbandoned = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_LOGABANDONED, false, Boolean.class);
-
- boolean poolPreparedStatements = (Boolean) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_POOLPREPAREDSTATEMENTS, false, Boolean.class);
-
- int maxOpenPreparedStatements = (Integer) MiscellaneousUtil.getProperty(properties,
- prefix + PROP_MAXOPENPREPAREDSTATEMENTS,
- GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, Integer.class);
-
- information.setDefaultAutoCommit(defaultAutoCommit);
- information.setDefaultReadOnly(defaultReadOnly);
- information.setTestOnBorrow(testOnBorrow);
- information.setTestOnReturn(testOnReturn);
- information.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
- information.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
- information.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
- information.setTestWhileIdle(testWhileIdle);
- information.setValidationQuery(validationQuery);
- information.setMinIdle(minIdle);
- information.setDefaultTransactionIsolation(defaultTransactionIsolation);
- information.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
- information.setRemoveAbandoned(removeAbandoned);
- information.setRemoveAbandonedTimeout(removeAbandonedTimeout);
- information.setLogAbandoned(logAbandoned);
- information.setPoolPreparedStatements(poolPreparedStatements);
- information.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
- information.setInitialSize(initialSize);
- information.setDefaultCatalog(defaultCatalog);
-
- return information;
- }
-
- /**
- * Helper methods for handle errors.
- *
- * @param msg The error message
- */
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-}
+/*
+ * 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.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.commons.pool.impl.GenericObjectPool;
+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;
+
+/**
+ * Factory to create a DataSourceInformation based on given properties
+ */
+
+public class DataSourceInformationFactory {
+
+ private static final Log log = LogFactory.getLog(DataSourceInformationFactory.class);
+
+
+ private DataSourceInformationFactory() {
+ }
+
+ /**
+ * Factory method to create a DataSourceInformation instance based on given properties
+ *
+ * @param dsName DataSource Name
+ * @param properties Properties to create and configure DataSource
+ * @return DataSourceInformation instance
+ */
+ public static DataSourceInformation createDataSourceInformation(String dsName, Properties properties) {
+
+ if (dsName == null || "".equals(dsName)) {
+ if (log.isDebugEnabled()) {
+ log.debug("DataSource name is either empty or null, ignoring..");
+ }
+ return null;
+ }
+
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(DataSourceConfigurationConstants.PROP_SYNAPSE_DATASOURCES);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
+ buffer.append(dsName);
+ buffer.append(DataSourceConfigurationConstants.DOT_STRING);
+
+ // Prefix for getting particular data source's properties
+ String prefix = buffer.toString();
+
+ String driver = MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_DRIVER_CLS_NAME, null);
+ if (driver == null) {
+ handleException(prefix + DataSourceConfigurationConstants.PROP_DRIVER_CLS_NAME + " cannot be found.");
+ }
+
+ String url = MiscellaneousUtil.getProperty(properties, prefix + DataSourceConfigurationConstants.PROP_URL, null);
+ if (url == null) {
+ 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 + DataSourceConfigurationConstants.PROP_USER_NAME, "synapse", String.class);
+ information.setUser(user);
+
+ String password = (String) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_PASSWORD, "synapse", String.class);
+
+ information.setPassword(password);
+
+ String dataSourceName = (String) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_DSNAME, dsName, String.class);
+ information.setDatasourceName(dataSourceName);
+
+ String dsType = (String) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_TYPE,
+ DataSourceConfigurationConstants.PROP_BASIC_DATA_SOURCE, String.class);
+
+ information.setType(dsType);
+
+ Integer maxActive = (Integer) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_MAXACTIVE,
+ GenericObjectPool.DEFAULT_MAX_ACTIVE, Integer.class);
+ information.setMaxActive(maxActive);
+
+ Integer maxIdle = (Integer) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_MAXIDLE,
+ GenericObjectPool.DEFAULT_MAX_IDLE, Integer.class);
+ information.setMaxIdle(maxIdle);
+
+ Long maxWait = (Long) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_MAXWAIT,
+ GenericObjectPool.DEFAULT_MAX_WAIT, Long.class);
+
+ information.setMaxWait(maxWait);
+
+ // Construct DriverAdapterCPDS reference
+ String suffix = DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING + DataSourceConfigurationConstants.PROP_CLASS_NAME;
+ String className = MiscellaneousUtil.getProperty(properties, prefix + suffix,
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER_DRIVER);
+ information.addParameter(suffix, className);
+ suffix = DataSourceConfigurationConstants.PROP_CPDSADAPTER +
+ DataSourceConfigurationConstants.DOT_STRING + DataSourceConfigurationConstants.PROP_FACTORY;
+ String factory = MiscellaneousUtil.getProperty(properties, prefix + suffix,
+ DataSourceConfigurationConstants.PROP_CPDSADAPTER_DRIVER);
+ information.addParameter(suffix, factory);
+ 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 + DataSourceConfigurationConstants.PROP_DEFAULTAUTOCOMMIT, true, Boolean.class);
+
+ boolean defaultReadOnly = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_DEFAULTREADONLY, false, Boolean.class);
+
+ boolean testOnBorrow = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_TESTONBORROW, true, Boolean.class);
+
+ boolean testOnReturn = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_TESTONRETURN, false, Boolean.class);
+
+ long timeBetweenEvictionRunsMillis = (Long) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_TIMEBETWEENEVICTIONRUNSMILLIS,
+ GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, Long.class);
+
+ int numTestsPerEvictionRun = (Integer) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_NUMTESTSPEREVICTIONRUN,
+ GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, Integer.class);
+
+ long minEvictableIdleTimeMillis = (Long) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_MINEVICTABLEIDLETIMEMILLIS,
+ GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, Long.class);
+
+ boolean testWhileIdle = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_TESTWHILEIDLE, false, Boolean.class);
+
+ String validationQuery = MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_VALIDATIONQUERY, null);
+
+ int minIdle = (Integer) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_MINIDLE, GenericObjectPool.DEFAULT_MIN_IDLE,
+ Integer.class);
+
+ int initialSize = (Integer) MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_INITIALSIZE, 0, Integer.class);
+
+ int defaultTransactionIsolation = (Integer) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_DEFAULTTRANSACTIONISOLATION, -1, Integer.class);
+
+ String defaultCatalog = MiscellaneousUtil.getProperty(
+ properties, prefix + DataSourceConfigurationConstants.PROP_DEFAULTCATALOG, null);
+
+ boolean accessToUnderlyingConnectionAllowed =
+ (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED,
+ false, Boolean.class);
+
+ boolean removeAbandoned = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_REMOVEABANDONED, false, Boolean.class);
+
+ int removeAbandonedTimeout = (Integer) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_REMOVEABANDONEDTIMEOUT, 300, Integer.class);
+
+ boolean logAbandoned = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_LOGABANDONED, false, Boolean.class);
+
+ boolean poolPreparedStatements = (Boolean) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_POOLPREPAREDSTATEMENTS, false, Boolean.class);
+
+ int maxOpenPreparedStatements = (Integer) MiscellaneousUtil.getProperty(properties,
+ prefix + DataSourceConfigurationConstants.PROP_MAXOPENPREPAREDSTATEMENTS,
+ GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, Integer.class);
+
+ information.setDefaultAutoCommit(defaultAutoCommit);
+ information.setDefaultReadOnly(defaultReadOnly);
+ information.setTestOnBorrow(testOnBorrow);
+ information.setTestOnReturn(testOnReturn);
+ information.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
+ information.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
+ information.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
+ information.setTestWhileIdle(testWhileIdle);
+ information.setValidationQuery(validationQuery);
+ information.setMinIdle(minIdle);
+ information.setDefaultTransactionIsolation(defaultTransactionIsolation);
+ information.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
+ information.setRemoveAbandoned(removeAbandoned);
+ information.setRemoveAbandonedTimeout(removeAbandonedTimeout);
+ information.setLogAbandoned(logAbandoned);
+ information.setPoolPreparedStatements(poolPreparedStatements);
+ information.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
+ information.setInitialSize(initialSize);
+ information.setDefaultCatalog(defaultCatalog);
+
+ return information;
+ }
+
+ /**
+ * Helper methods for handle errors.
+ *
+ * @param msg The error message
+ */
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java?rev=713788&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationListFactory.java Thu Nov 13 11:00:56 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: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java?rev=713788&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/factory/DataSourceInformationRepositoryFactory.java Thu Nov 13 11:00:56 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: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java?rev=713788&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationListSerializer.java Thu Nov 13 11:00:56 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: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java?rev=713788&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/datasource/serializer/DataSourceInformationSerializer.java Thu Nov 13 11:00:56 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);
+ }
+ }
+}