[jboss-svn-commits] JBL Code SVN: r16143 - in labs/jbossesb/trunk/product/rosetta/src/org/jboss: soa/esb/addressing/eprs and 3 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Oct 29 15:00:38 EDT 2007


Author: tcunning
Date: 2007-10-29 15:00:38 -0400 (Mon, 29 Oct 2007)
New Revision: 16143

Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/SqlListenerMapper.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
Log:
bug:JBESB-1050
Adding datasource support to sql-provider.


Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java	2007-10-29 17:54:02 UTC (rev 16142)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/couriers/SqlTableCourier.java	2007-10-29 19:00:38 UTC (rev 16143)
@@ -30,6 +30,10 @@
 import java.sql.SQLException;
 import java.util.UUID;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.sql.DataSource;
+
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.addressing.Call;
 import org.jboss.soa.esb.addressing.MalformedEPRException;
@@ -99,8 +103,8 @@
 			}
 			catch (Exception e)
 			{
-                                _logger.info("Unable to release connection");
-                                _logger.debug("Unable to release connection", e);
+				_logger.info("Unable to release connection");
+                _logger.debug("Unable to release connection", e);
 			}
 		}
 
@@ -197,9 +201,9 @@
 				+ ((millis < 100) ? 100 : millis);
 		do
 		{
-                        try
-                        {
-                                ResultSet RS = getRowList();
+			try
+            {
+                ResultSet RS = getRowList();
 				while (null != RS && RS.next())
 				{
 					String messageId = RS.getString(1);
@@ -216,7 +220,7 @@
 					
 					return result;
 				}
-                        }
+            }
 			catch (SQLException e)
 			{
 				_logger.debug("SQL Exception during pickup", e);
@@ -393,8 +397,19 @@
 		{
 			try
 			{
-				SimpleDataSource DS = new SimpleDataSource(_epr.getDriver(), _epr
-						.getURL(), _epr.getUserName(), _epr.getPassword());
+				DataSource DS = null;
+				if (_epr.getDatasource() == null) {
+					DS = new SimpleDataSource(_epr.getDriver(), 
+						_epr.getURL(), _epr.getUserName(), _epr.getPassword());
+				} else {
+					InitialContext initContext;
+					try {
+						initContext = new InitialContext();
+						DS = (DataSource) initContext.lookup(_epr.getDatasource());
+					} catch (NamingException e) {
+						_logger.error("", e);
+					}
+				}
 				_conn = new JdbcCleanConn(DS);
 			}
 			catch (URISyntaxException ex)
@@ -560,11 +575,9 @@
 	} // ________________________________
 	
 	protected long _pollLatency = 200;
-
 	protected long _sleepForRetries = 3000; // milliseconds
 
 	protected boolean _postDelete, _errorDelete;
-
 	protected boolean _isReceiver;
 
 	protected JDBCEpr _epr;
@@ -572,13 +585,9 @@
 	protected JdbcCleanConn _conn;
 
 	protected PreparedStatement _prepGetList;
-
 	protected PreparedStatement _prepSel4Upd;
-
 	protected PreparedStatement _prepUpdateStatus;
-
 	protected PreparedStatement _prepInsert;
-
 	protected PreparedStatement _prepDelete;
 
 	protected static Logger _logger = Logger.getLogger(SqlTableCourier.class);

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java	2007-10-29 17:54:02 UTC (rev 16142)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/eprs/JDBCEpr.java	2007-10-29 19:00:38 UTC (rev 16143)
@@ -46,7 +46,7 @@
 public class JDBCEpr extends EPR
 {
 	public static final String JDBC_PROTOCOL = "jdbc";
-	
+	public static final String DATASOURCE_TAG = "datasource";
 	public static final String USERNAME_TAG = "username";
 	public static final String PASSWORD_TAG = "password";
 	public static final String SQL_TAG = "sql";
@@ -257,6 +257,22 @@
 	}
 	
 	/**
+	 * Set the JNDI datasource value that is used by this EPR.
+	 * @param datasource JNDI datasource
+	 */
+	public final void setDatasource (String datasource) {
+		getAddr().addExtension(DATASOURCE_TAG, datasource);
+	}
+	
+	/**
+	 * Get the JNDI datasource value that is used by this EPR.
+	 * @return datasource
+	 */
+	public final String getDatasource() {
+		return getAddr().getExtensionValue(DATASOURCE_TAG);
+	}
+	
+	/**
 	 * Set the SQL command that is used by this EPR.
 	 * 
 	 * @param sql the statement.
@@ -342,7 +358,7 @@
 	{
 		return getAddr().getExtensionValue(TABLE_NAME_TAG);
 	}
-	
+		
 	/**
 	 * Set the message id column name that is used by this EPR.
 	 * 

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java	2007-10-29 17:54:02 UTC (rev 16142)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/JdbcCleanConn.java	2007-10-29 19:00:38 UTC (rev 16143)
@@ -62,6 +62,8 @@
 		if (null != m_conn)
 		{
 			m_conn.rollback();
+		} else {
+			throw new SQLException("Connection is null");
 		}
 	}
 

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java	2007-10-29 17:54:02 UTC (rev 16142)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/helpers/persist/SimpleDataSource.java	2007-10-29 19:00:38 UTC (rev 16143)
@@ -26,6 +26,8 @@
 import java.sql.DriverManager;
 import java.sql.SQLException;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.sql.DataSource;
 
 import org.apache.log4j.Logger;
@@ -115,8 +117,8 @@
 	{
 		try
 		{
-         ClassUtil.forName(p_sDriver, getClass());
-         m_sUrl = p_sDbURL;
+			ClassUtil.forName(p_sDriver, getClass());
+			m_sUrl = p_sDbURL;
 			getConnection(p_sUsr, p_sPwd);
 		}
 		catch (ClassNotFoundException ex)
@@ -124,11 +126,11 @@
 			throw new IllegalArgumentException(ex);
 		}
 	} // ________________________________
-
+	
 	public Connection getConnection() throws SQLException
 	{
 		if ((m_oConn == null) || (m_oConn.isClosed())) {
-				m_oConn = getConnection(m_sUsr, m_sPwd);
+			m_oConn = getConnection(m_sUsr, m_sPwd);
 		}
 		
 		if (m_oConn == null) {

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/SqlListenerMapper.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/SqlListenerMapper.java	2007-10-29 17:54:02 UTC (rev 16142)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/config/mappers/SqlListenerMapper.java	2007-10-29 19:00:38 UTC (rev 16143)
@@ -64,11 +64,33 @@
 			throw new ConfigurationException("Invalid bus config [" + listener.getBusidref() + "].  Should be contained within a <sql-provider> instance.  Unexpected exception - this should have caused a validation error!");
 		}
 		
+		if (provider.getDatasource() != null) {
+			if ((provider.getUrl() != null)
+					|| (provider.getUsername() != null)
+					|| (provider.getDriver() != null)) {	
+				throw new ConfigurationException ("Invalid sql-provider configuration : a datasource and a URL/username/password/driver "
+						+ "combination cannot both be defined.   Use only one (datasource or JDBC connection info)." 
+						+ "Datasource : [" + provider.getDatasource() + "] JDBC URL [" + provider.getUrl() + "]");
+			}			
+		} else if (provider.getUrl() == null) {
+			throw new ConfigurationException ("Invalid sql-provider configuration : a datasource or a URL/username/password/driver "
+					+ "combination must be defined.   Use only one (datasource or JDBC connection info).  " 
+					+ "URL was null.");	
+		} else if (provider.getUsername() == null) {
+			throw new ConfigurationException ("Invalid sql-provider configuration :  a datasource or a URL/username/password/driver "
+					+ "combination must be defined.   Use only one (datasource or JDBC connection info).   " 
+					+ "Username was null.");	
+		} else if (provider.getDriver() == null) {
+			throw new ConfigurationException ("Invalid sql-provider configuration : either a datasource or a URL/username/password/driver "
+					+ "combination must be defined.   Use only one (datasource or JDBC connection info).   " 
+					+ "Driver was null.");		
+		}
+		
 		SqlMessageFilter messageFilter = listener.getSqlMessageFilter();
-		if(messageFilter == null) {
+		if(messageFilter == null) { 
 			messageFilter = bus.getSqlMessageFilter();
 			if(messageFilter == null) {
-				throw new ConfigurationException("No <sql-detination> defined on either <sql-listener> [" + listener.getName() + "] or <sql-bus> [" + bus.getBusid() + "].");
+				throw new ConfigurationException("No <sql-destination> defined on either <sql-listener> [" + listener.getName() + "] or <sql-bus> [" + bus.getBusid() + "].");
 			}
 		}
         listenerNode.setAttribute("pollLatencySeconds", String.valueOf(listener.getPollFrequencySeconds()));
@@ -101,6 +123,7 @@
 	}
 
 	private static void mapSqlEprProperties(Element toElement, SqlProvider provider, SqlMessageFilter messageFilter) {
+		toElement.setAttribute(JDBCEpr.DATASOURCE_TAG, provider.getDatasource());
 		toElement.setAttribute(JDBCEpr.URL_TAG, provider.getUrl());
 		toElement.setAttribute(JDBCEpr.DRIVER_TAG, provider.getDriver());
 		toElement.setAttribute(JDBCEpr.USERNAME_TAG, provider.getUsername());

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	2007-10-29 17:54:02 UTC (rev 16142)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/SqlTableGatewayListener.java	2007-10-29 19:00:38 UTC (rev 16143)
@@ -39,6 +39,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import javax.sql.DataSource;
 
 import org.apache.log4j.Logger;
@@ -64,8 +66,6 @@
 import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleThreadState;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.MessagePayloadProxy;
-import org.jboss.soa.esb.message.Body;
-import org.jboss.soa.esb.message.body.content.BytesBody;
 import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.services.registry.RegistryException;
 import org.jboss.soa.esb.services.registry.ServiceNotFoundException;
@@ -300,19 +300,8 @@
         _url = ListenerUtil.getValue(_config, JDBCEpr.URL_TAG, null);
         _user = ListenerUtil.getValue(_config, JDBCEpr.USERNAME_TAG, null);
         _password = ListenerUtil.getValue(_config, JDBCEpr.PASSWORD_TAG, "");
-
-        if (_driver == null)
-        	throw new ConfigurationException("No driver specified!");
+        _datasource = ListenerUtil.getValue(_config, JDBCEpr.DATASOURCE_TAG, null);
         
-        if (_url == null)
-        	throw new ConfigurationException("No url specified!");
-        
-        if (_user == null)
-        	throw new ConfigurationException("No user specified!");
-        
-        if (_password == null)
-        	throw new ConfigurationException("No password specified!");
-        
         _tableName = _config.getAttribute(ListenerTagNames.SQL_TABLE_NAME_TAG);
         if (null == _tableName)
             _tableName = _config.getRequiredAttribute(JDBCEpr.TABLE_NAME_TAG);
@@ -484,9 +473,9 @@
         finally {
             try {
                 oConn.rollback();
+            } catch (final SQLException sqle) {
+            	refreshDatasource();
             }
-            catch (final SQLException sqle) {
-            }
         }
         if (_logger.isDebugEnabled()) {
             _logger.debug("Returning " + oResults.size() + " rows.\n");
@@ -494,6 +483,13 @@
         return oResults;
     } // ________________________________
 
+    public void refreshDatasource() {
+    	_dbConn = null;
+    	if (_datasource != null) {
+    		getDbConn();
+    	}
+    }
+    
     /**
      * Obtain a new database connection with parameter info
      *
@@ -502,9 +498,20 @@
      *                                if problems are encountered
      */
     protected JdbcCleanConn getDbConn() {
+    	DataSource oDS = null;
         if (null == _dbConn) {
-            DataSource oDS = new SimpleDataSource(_driver, _url, _user,
+        	if (_datasource == null) {
+        		oDS = new SimpleDataSource(_driver, _url, _user,
                     _password);
+        	} else {
+				InitialContext initContext;
+				try {
+					initContext = new InitialContext();
+					oDS = (DataSource) initContext.lookup(_datasource);
+				} catch (NamingException e) {
+					_logger.error("", e);
+				}
+        	}
             _dbConn = new JdbcCleanConn(oDS);
         } 
       
@@ -783,7 +790,7 @@
 
     protected Courier _courier;
 
-    protected String _driver, _url, _user, _password;
+    protected String _driver, _url, _user, _password, _datasource;
 
     protected String _tableName, _selectFields, _keyFields;
 




More information about the jboss-svn-commits mailing list