Author: wglass
Date: Fri Oct 14 22:14:12 2005
New Revision: 321293

URL: http://svn.apache.org/viewcvs?rev=321293&view=rev
Log:
No need to check the context if the datasource is passed in.  Thanks to 
Vladimir Terzic for the further patch.  VELOCITY-267

Modified:
    
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java

Modified: 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
URL: 
http://svn.apache.org/viewcvs/jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java?rev=321293&r1=321292&r2=321293&view=diff
==============================================================================
--- 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
 (original)
+++ 
jakarta/velocity/core/trunk/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
 Fri Oct 14 22:14:12 2005
@@ -16,22 +16,20 @@
  * limitations under the License.
  */
 
-import java.io.InputStream;
 import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
 
-import javax.sql.DataSource;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-
-import org.apache.velocity.runtime.log.Log;
-import org.apache.velocity.runtime.resource.Resource;
-import org.apache.velocity.exception.ResourceNotFoundException;
+import javax.sql.DataSource;
 
 import org.apache.commons.collections.ExtendedProperties;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.sql.SQLException;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
 
 /**
  * <P>This is a simple template file loader that loads templates
@@ -320,27 +318,32 @@
      }
 
     /**
-     *   gets connection to the datasource specified through the configuration
+     *  Gets connection to the datasource specified through the configuration
      *  parameters.
      *
      *  @return connection
      */
-     private Connection openDbConnection()
+     private Connection openDbConnection() 
          throws NamingException, SQLException
-    {
-         if (ctx == null)
+     {
+         if (dataSource != null) 
+         {
+            return dataSource.getConnection();
+         }
+         
+         if (ctx == null) 
          {
-             ctx = new InitialContext();
+            ctx = new InitialContext();
          }
 
-         if (dataSource == null)
+         if (dataSource == null) 
          {
-             dataSource = (DataSource)ctx.lookup(dataSourceName);
+            dataSource = (DataSource) ctx.lookup(dataSourceName);
          }
 
          return dataSource.getConnection();
      }
-
+     
     /**
      *  Closes connection to the datasource
      */



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to