Author: indika
Date: Sun Nov 16 07:39:16 2008
New Revision: 24010
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=24010
Log:
fix an issue with JNDI after refactoring
Added:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java
- copied, changed from r24000,
/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceManager.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java
- copied, changed from r24000,
/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
Removed:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceManager.java
Modified:
branches/synapse/1.2.wso2v1/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractDBMediatorFactory.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/MBeanRepository.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/PropertyHelper.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DatasourceMBeanRepository.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/InMemoryDataSourceRepository.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java
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=24010&r1=24009&r2=24010&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
Sun Nov 16 07:39:16 2008
@@ -24,8 +24,9 @@
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.synapse.commons.util.MBeanRepository;
import org.apache.synapse.commons.util.datasource.DBPoolView;
-import org.apache.synapse.commons.util.datasource.DataSourceManager;
+import org.apache.synapse.commons.util.datasource.DataSourceFinder;
import org.apache.synapse.commons.util.datasource.DatasourceMBeanRepository;
+import
org.apache.synapse.commons.util.datasource.RepositoryBasedDataSourceFinder;
import org.apache.synapse.mediators.db.AbstractDBMediator;
import org.apache.synapse.mediators.db.Statement;
import org.apache.synapse.util.xpath.SynapseXPath;
@@ -141,7 +142,12 @@
String dsName = getValue(pool, DSNAME_Q);
mediator.addDataSourceProperty(DSNAME_Q, dsName);
- DataSource dataSource = DataSourceManager.getInstance().find(dsName);
+
+ DataSource dataSource = null;
+ RepositoryBasedDataSourceFinder finder =
RepositoryBasedDataSourceFinder.getInstance();
+ if (finder.isInitialized()) {
+ dataSource =
RepositoryBasedDataSourceFinder.getInstance().find(dsName);
+ }
if (dataSource != null) {
MBeanRepository mBeanRepository =
DatasourceMBeanRepository.getInstance();
Object mBean = mBeanRepository.getMBean(dsName);
@@ -157,7 +163,7 @@
props.put(Context.SECURITY_CREDENTIALS, getValue(pool, PASS_Q));
props.put(Context.PROVIDER_URL, getValue(pool, URL_Q));
- dataSource = DataSourceManager.getInstance().find(dsName, props);
+ dataSource = DataSourceFinder.find(dsName, props);
if (dataSource == null) {
handleException("Cannot find a DataSource for given properties :"
+ props);
}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/MBeanRepository.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/MBeanRepository.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/MBeanRepository.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/MBeanRepository.java
Sun Nov 16 07:39:16 2008
@@ -25,9 +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/utils/src/main/java/org/apache/synapse/commons/util/PropertyHelper.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/PropertyHelper.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/PropertyHelper.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/PropertyHelper.java
Sun Nov 16 07:39:16 2008
@@ -40,9 +40,10 @@
/**
* Find and invoke the setter method with the name of form setXXX passing
in the value given
* on the POJO object
+ *
* @param name name of the setter field
- * @param val value to be set
- * @param obj POJO instance
+ * @param val value to be set
+ * @param obj POJO instance
*/
public static void setInstanceProperty(String name, Object val, Object
obj) {
@@ -110,9 +111,9 @@
/**
* This method will set the static property discribed in the OMElement to
the specified object.
* This Object should have the setter method for the specified property
name
- *
+ *
* @param property - OMElement specifying the property to be built in to
the object
- * @param o - Object to which the specified property will be set.
+ * @param o - Object to which the specified property will be set.
*/
public static void setStaticProperty(OMElement property, Object o) {
@@ -154,13 +155,13 @@
/**
* This method will check the given OMElement represent either a static
property or not
- *
+ *
* @param property - OMElement to be checked for the static property
* @return boolean true if the elemet represents a static property element
false otherwise
*/
public static boolean isStaticProperty(OMElement property) {
return "property".equals(property.getLocalName().toLowerCase())
- && (property.getAttributeValue(new QName("expression")) == null);
+ && (property.getAttributeValue(new QName("expression")) ==
null);
}
private static void handleException(String message, Throwable e) {
@@ -171,5 +172,5 @@
private static void handleException(String message) {
log.error(message);
throw new SynapseUtilException(message);
- }
+ }
}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/RMIRegistryController.java
Sun Nov 16 07:39:16 2008
@@ -24,7 +24,8 @@
return ourInstance;
}
- private RMIRegistryController() {}
+ private RMIRegistryController() {
+ }
/**
* Creates a RMI local registry with given port
@@ -50,7 +51,7 @@
log.info("Removing the RMI registy instance from the RMI
runtime ");
UnicastRemoteObject.unexportObject(localRegistry, true);
} catch (NoSuchObjectException e) {
- String msg = "Error when stoping localregistry(RMI)";
+ String msg = "Error when stopping localregistry(RMI)";
handleException(msg, e);
}
}
Added:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java?pathrev=24010
==============================================================================
--- (empty file)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
Sun Nov 16 07:39:16 2008
@@ -0,0 +1,104 @@
+/*
+ * 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.commons.util.datasource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.util.SynapseUtilException;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+import java.util.Properties;
+
+/**
+ *
+ */
+public class DataSourceFinder {
+
+ private static Log log = LogFactory.getLog(DataSourceFinder.class);
+
+ /**
+ * 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 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;
+ }
+
+ /**
+ * 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 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 SynapseUtilException(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 SynapseUtilException(msg, e);
+ }
+}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepository.java
Sun Nov 16 07:39:16 2008
@@ -22,7 +22,10 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.util.SynapseUtilException;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
/**
*
@@ -34,12 +37,10 @@
private final Map<String, DataSourceInformation> dataSourceInformationMap =
new HashMap<String, DataSourceInformation>();
- private final List<DataSourceInformationRepositoryListener> listeners =
- new ArrayList<DataSourceInformationRepositoryListener>();
+ private DataSourceInformationRepositoryListener listener;
public void setConfigurationProperties(Properties congurationProperties) {
-
- for (DataSourceInformationRepositoryListener listener : listeners) {
+ if (listener != null) {
listener.reConfigure(congurationProperties);
}
}
@@ -49,7 +50,7 @@
assertNull(dataSourceInformation, "DataSource information is null");
dataSourceInformationMap.put(dataSourceInformation.getAlias(),
dataSourceInformation);
- for (DataSourceInformationRepositoryListener listener : listeners) {
+ if (assertListerNotNull()) {
listener.addDataSourceInformation(dataSourceInformation);
}
}
@@ -69,7 +70,7 @@
assertNull(information, "There is no datasource information instance
for given name :" + name);
- for (DataSourceInformationRepositoryListener listener : listeners) {
+ if (assertListerNotNull()) {
listener.removeDataSourceInformation(information);
}
return information;
@@ -80,11 +81,35 @@
return dataSourceInformationMap.values().iterator();
}
- public void
registerDataSourceInformationRepositoryListener(DataSourceInformationRepositoryListener
listener) {
+ public void setRepositoryListener(DataSourceInformationRepositoryListener
listener) {
assertNull(listener, "Provided
'DataSourceInformationRepositoryListener' instance is null");
- listeners.add(listener);
+ if (this.listener != null) {
+ handleException("There is a
'DataSourceInformationRepositoryListener' associated with
'DataSourceInformationRepository'");
+ }
+ this.listener = listener;
+ }
+
+ public void removeRepositoryListener() {
+ this.listener = null;
+ }
+
+ public DataSourceInformationRepositoryListener getRepositoryListener() {
+ return this.listener;
+ }
+
+ private boolean assertListerNotNull() {
+ if (listener == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Cannot find a
'DataSourceInformationRepositoryListener'.");
+ }
+ return false;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Using 'DataSourceInformationRepositoryListener' as :" +
listener);
+ }
+ return true;
}
private static void handleException(String msg) {
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceInformationRepositoryHelper.java
Sun Nov 16 07:39:16 2008
@@ -36,8 +36,10 @@
private static final Log log =
LogFactory.getLog(DataSourceInformationRepositoryHelper.class);
public static void
initializeDataSourceInformationRepository(AxisConfiguration axisConfiguration,
Properties properties) {
-
- initializeDataSourceInformationRepository(axisConfiguration,
properties, DataSourceManager.getInstance());
+ DataSourceRepositoryManager listener =
DataSourceRepositoryManager.getInstance();
+ RepositoryBasedDataSourceFinder finder =
RepositoryBasedDataSourceFinder.getInstance();
+ finder.init(listener);
+ initializeDataSourceInformationRepository(axisConfiguration,
properties, listener);
}
public static void
initializeDataSourceInformationRepository(AxisConfiguration axisConfiguration,
Properties properties, DataSourceInformationRepositoryListener listener) {
Deleted:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceManager.java
URL: http://wso2.org/svn/browse/wso2/None?pathrev=24009
Copied:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java
(from r24000,
/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceManager.java)
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java?rev=24010&r1=24000&r2=24010&view=diff
==============================================================================
---
/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceManager.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceRepositoryManager.java
Sun Nov 16 07:39:16 2008
@@ -22,29 +22,26 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.util.SynapseUtilException;
-import javax.naming.Context;
-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 DataSourceManager implements
DataSourceInformationRepositoryListener, DataSourceFinder {
+public class DataSourceRepositoryManager implements
DataSourceInformationRepositoryListener {
- private static final Log log = LogFactory.getLog(DataSourceManager.class);
+ private static final Log log =
LogFactory.getLog(DataSourceRepositoryManager.class);
- private static final DataSourceManager DATA_SOURCE_MANAGER = new
DataSourceManager();
+ private static final DataSourceRepositoryManager
DATA_SOURCE_REPOSITORY_MANAGER = new DataSourceRepositoryManager();
private static final DataSourceRepository IN_MEMORY_REPOSITORY =
InMemoryDataSourceRepository.getInstance();
private static final DataSourceRepository JNDI_REPOSITORY =
JNDIBasedDataSourceRepository.getInstance();
- private DataSourceManager() {
+ public DataSourceRepositoryManager() {
}
- public static DataSourceManager getInstance() {
- return DATA_SOURCE_MANAGER;
+ public static DataSourceRepositoryManager getInstance() {
+ return DATA_SOURCE_REPOSITORY_MANAGER;
}
/**
@@ -53,7 +50,7 @@
* @param name Name of the DataSource to be found
* @return DataSource if found , otherwise null
*/
- public DataSource find(String name) {
+ public DataSource getDataSource(String name) {
if (name == null || "".equals(name)) {
handleException("DataSource name cannot be found.");
@@ -70,58 +67,12 @@
return null;
}
- /**
- * 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) {
-
- 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;
- }
-
- /**
- * 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) {
-
- 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;
- }
-
public void addDataSourceInformation(DataSourceInformation
dataSourceInformation) {
if (dataSourceInformation == null) {
return;
}
-
+
String repositoryType = dataSourceInformation.getRepositoryType();
if
(DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
JNDI_REPOSITORY.register(dataSourceInformation);
@@ -131,9 +82,9 @@
}
public void removeDataSourceInformation(DataSourceInformation
dataSourceInformation) {
-
+
String repositoryType = dataSourceInformation.getRepositoryType();
-
+
if
(DataSourceConfigurationConstants.PROP_REGISTRY_JNDI.equals(repositoryType)) {
JNDI_REPOSITORY.unRegister(dataSourceInformation.getDatasourceName());
} else {
@@ -142,11 +93,16 @@
}
public void reConfigure(Properties confProperties) {
-
+
JNDI_REPOSITORY.init(confProperties);
IN_MEMORY_REPOSITORY.init(confProperties);
}
+ public void clear() {
+ IN_MEMORY_REPOSITORY.clear();
+ JNDI_REPOSITORY.clear();
+ }
+
/**
* Helper methods for handle errors.
*
@@ -157,15 +113,4 @@
throw new SynapseUtilException(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 SynapseUtilException(msg, e);
- }
-
}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DatasourceMBeanRepository.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DatasourceMBeanRepository.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DatasourceMBeanRepository.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DatasourceMBeanRepository.java
Sun Nov 16 07:39:16 2008
@@ -31,7 +31,7 @@
*
*/
public class DatasourceMBeanRepository implements MBeanRepository {
-
+
private final static Log log =
LogFactory.getLog(DatasourceMBeanRepository.class);
private final static Map<String, DBPoolView> dataSourcesMBeans = new
HashMap<String, DBPoolView>();
@@ -46,7 +46,7 @@
}
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 " +
@@ -57,19 +57,19 @@
}
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()) {
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/InMemoryDataSourceRepository.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/InMemoryDataSourceRepository.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/InMemoryDataSourceRepository.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/InMemoryDataSourceRepository.java
Sun Nov 16 07:39:16 2008
@@ -83,8 +83,8 @@
}
public void unRegister(String name) {
-
- assertNull(name,"Name of the datasource to be removed is empty or
null");
+
+ assertNull(name, "Name of the datasource to be removed is empty or
null");
dataSources.remove(name);
REPOSITORY.removeMBean(name);
}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/JNDIBasedDataSourceRepository.java
Sun Nov 16 07:39:16 2008
@@ -44,7 +44,7 @@
private static final JNDIBasedDataSourceRepository ourInstance =
new JNDIBasedDataSourceRepository();
- private static InitialContext initialContext;
+ private InitialContext initialContext;
private Properties jndiProperties;
private static final Map<String, InitialContext> perDataSourceICMap = new
HashMap<String, InitialContext>();
private boolean initialized = false;
@@ -63,7 +63,7 @@
if (isValid(jndiEnv)) {
jndiProperties = createJNDIEnvironment(jndiEnv, null);
- initialContext = createInitialContext(jndiEnv);
+ initialContext = createInitialContext(jndiProperties);
}
}
@@ -80,16 +80,30 @@
validateInitialized();
String dataSourceName = information.getDatasourceName();
validateDSName(dataSourceName);
- Properties jndiEvn =
createJNDIEnvironment(information.getProperties(), information.getAlias());
-
- InitialContext context = createInitialContext(jndiEvn);
+ Properties properties = information.getProperties();
+
+ InitialContext context = null;
+ Properties jndiEvn = null;
+
+ if (properties != null && !properties.isEmpty()) {
+ jndiEvn = createJNDIEnvironment(properties,
information.getAlias());
+ context = createInitialContext(jndiEvn);
+ }
if (context == null) {
+
validateInitialContext(initialContext);
context = initialContext;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Cannot create a name context with jndi properties :
" + jndiEvn);
+ log.debug("Using system-wide jndi properties : " +
jndiProperties);
+ }
+
jndiEvn = jndiProperties;
} else {
perDataSourceICMap.put(dataSourceName, context);
}
+
String dsType = information.getType();
String driver = information.getDriver();
String url = information.getUrl();
@@ -174,7 +188,7 @@
ref.add(new BinaryRefAddr(
DataSourceConfigurationConstants.PROP_JNDI_ENV,
- MiscellaneousUtil.serialize(jndiProperties)));
+ MiscellaneousUtil.serialize(jndiEvn)));
ref.add(new StringRefAddr(
DataSourceConfigurationConstants.PROP_DATA_SOURCE_NAME,
name));
ref.add(new StringRefAddr(
@@ -231,7 +245,7 @@
}
InitialContext context = getCachedInitialContext(dsName);
- return DataSourceManager.getInstance().find(dsName, context);
+ return DataSourceFinder.find(dsName, context);
}
public void clear() {
Copied:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java
(from r24000,
/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java)
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java?rev=24010&r1=24000&r2=24010&view=diff
==============================================================================
---
/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/DataSourceFinder.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/RepositoryBasedDataSourceFinder.java
Sun Nov 16 07:39:16 2008
@@ -18,14 +18,33 @@
*/
package org.apache.synapse.commons.util.datasource;
-import javax.naming.Context;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.commons.util.SynapseUtilException;
+
import javax.sql.DataSource;
-import java.util.Properties;
/**
- * Finds a DataSource based on various criteria
+ * Finds a DataSource from DataSourceRepositories
*/
-public interface DataSourceFinder {
+public class RepositoryBasedDataSourceFinder {
+
+ private final static Log log =
LogFactory.getLog(InMemoryDataSourceRepository.class);
+ private DataSourceRepositoryManager dataSourceRepositoryManager;
+ private boolean initialized;
+ private static final RepositoryBasedDataSourceFinder
REPOSITORY_BASED_DATA_SOURCE_FINDER = new RepositoryBasedDataSourceFinder();
+
+ private RepositoryBasedDataSourceFinder() {
+ }
+
+ public static RepositoryBasedDataSourceFinder getInstance() {
+ return REPOSITORY_BASED_DATA_SOURCE_FINDER;
+ }
+
+ public void init(DataSourceRepositoryManager dataSourceRepositoryManager) {
+ this.dataSourceRepositoryManager = dataSourceRepositoryManager;
+ this.initialized = true;
+ }
/**
* Find a DataSource using given name
@@ -33,24 +52,44 @@
* @param name Name of the DataSource to be found
* @return DataSource if found , otherwise null
*/
- DataSource find(String name);
+ public DataSource find(String name) {
+ assertInitialized();
+ if (name == null || "".equals(name)) {
+ handleException("DataSource name cannot be found.");
+ }
+
+ return dataSourceRepositoryManager.getDataSource(name);
+ }
+
/**
- * Find a DataSource using the given name and JNDI environment properties
+ * Helper methods for handle errors.
*
- * @param dsName Name of the DataSource to be found
- * @param jndiEnv JNDI environment properties
- * @return DataSource if found , otherwise null
+ * @param msg The error message
*/
- DataSource find(String dsName, Properties jndiEnv);
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseUtilException(msg);
+ }
/**
- * Find a DataSource using the given name and naming context
+ * Helper methods for handle errors.
*
- * @param dsName Name of the DataSource to be found
- * @param context Naming Context
- * @return DataSource if found , otherwise null
+ * @param msg The error message
+ * @param e The exception
*/
- DataSource find(String dsName, Context context);
-
+ private static void handleException(String msg, Exception e) {
+ log.error(msg, e);
+ throw new SynapseUtilException(msg, e);
+ }
+
+ private void assertInitialized() {
+ if (!initialized) {
+ handleException("RepositoryBasedDataSourceFinder has not been
initialized with a 'DataSourceRepositoryManager' instance ");
+ }
+ }
+
+ public boolean isInitialized() {
+ return initialized;
+ }
}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationFactory.java
Sun Nov 16 07:39:16 2008
@@ -218,7 +218,6 @@
information.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
information.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
information.setTestWhileIdle(testWhileIdle);
- information.setValidationQuery(validationQuery);
information.setMinIdle(minIdle);
information.setDefaultTransactionIsolation(defaultTransactionIsolation);
information.setAccessToUnderlyingConnectionAllowed(accessToUnderlyingConnectionAllowed);
@@ -228,8 +227,14 @@
information.setPoolPreparedStatements(poolPreparedStatements);
information.setMaxOpenPreparedStatements(maxOpenPreparedStatements);
information.setInitialSize(initialSize);
- information.setDefaultCatalog(defaultCatalog);
+ if (validationQuery != null && !"".equals(validationQuery)) {
+ information.setValidationQuery(validationQuery);
+ }
+
+ if (defaultCatalog != null && !"".equals(defaultCatalog)) {
+ information.setDefaultCatalog(defaultCatalog);
+ }
return information;
}
Modified:
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java
URL:
http://wso2.org/svn/browse/wso2/branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java?rev=24010&r1=24009&r2=24010&view=diff
==============================================================================
---
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java
(original)
+++
branches/synapse/1.2.wso2v1/modules/utils/src/main/java/org/apache/synapse/commons/util/datasource/factory/DataSourceInformationRepositoryFactory.java
Sun Nov 16 07:39:16 2008
@@ -21,7 +21,7 @@
import org.apache.synapse.commons.util.datasource.DataSourceInformation;
import
org.apache.synapse.commons.util.datasource.DataSourceInformationRepository;
import
org.apache.synapse.commons.util.datasource.DataSourceInformationRepositoryListener;
-import org.apache.synapse.commons.util.datasource.DataSourceManager;
+import org.apache.synapse.commons.util.datasource.DataSourceRepositoryManager;
import java.util.List;
import java.util.Properties;
@@ -33,16 +33,16 @@
public static DataSourceInformationRepository
createDataSourceInformationRepository(Properties properties) {
- return createDataSourceInformationRepository(properties,
DataSourceManager.getInstance());
+ return createDataSourceInformationRepository(properties,
DataSourceRepositoryManager.getInstance());
}
public static DataSourceInformationRepository
createDataSourceInformationRepository(Properties properties,
DataSourceInformationRepositoryListener listener) {
- List<DataSourceInformation> dataSourceInformations =
DataSourceInformationListFactory.createDataSourceInformationList(properties);
+ List<DataSourceInformation> sourceInformationList =
DataSourceInformationListFactory.createDataSourceInformationList(properties);
DataSourceInformationRepository repository = new
DataSourceInformationRepository();
- repository.registerDataSourceInformationRepositoryListener(listener);
+ repository.setRepositoryListener(listener);
repository.setConfigurationProperties(properties);
- for (DataSourceInformation information : dataSourceInformations) {
+ for (DataSourceInformation information : sourceInformationList) {
if (information != null) {
repository.addDataSourceInformation(information);
}
_______________________________________________
Esb-java-dev mailing list
[email protected]
http://mailman.wso2.org/cgi-bin/mailman/listinfo/esb-java-dev