You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2003/10/27 11:46:40 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader DataSourceResourceLoader.java

geirm       2003/10/27 02:46:40

  Modified:    src/java/org/apache/velocity/runtime/resource/loader
                        DataSourceResourceLoader.java
  Log:
  Removed the usage of the deprecated Runtime singleton.  Found by Will
  based on bug 17820.  Thanks Will!
  
  Revision  Changes    Path
  1.9       +25 -21    jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java
  
  Index: DataSourceResourceLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/resource/loader/DataSourceResourceLoader.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DataSourceResourceLoader.java	10 Feb 2002 18:46:58 -0000	1.8
  +++ DataSourceResourceLoader.java	27 Oct 2003 10:46:40 -0000	1.9
  @@ -56,12 +56,11 @@
   
   import java.io.InputStream;
   import java.io.BufferedInputStream;
  -import java.util.Hashtable;
   
   import javax.sql.DataSource;
   import javax.naming.InitialContext;
  +import javax.naming.NamingException;
   
  -import org.apache.velocity.runtime.Runtime;
   import org.apache.velocity.runtime.resource.Resource;
   
   import org.apache.velocity.exception.ResourceNotFoundException;
  @@ -155,7 +154,7 @@
        private InitialContext ctx;
        private DataSource dataSource;
   
  -     public void init( ExtendedProperties configuration)
  +     public void init(ExtendedProperties configuration)
        {
            dataSourceName  = configuration.getString("resource.datasource");
            tableName       = configuration.getString("resource.table");
  @@ -163,10 +162,10 @@
            templateColumn  = configuration.getString("resource.templatecolumn");
            timestampColumn = configuration.getString("resource.timestampcolumn");
   
  -         Runtime.info("Resources Loaded From: " + dataSourceName + "/" + tableName);
  -         Runtime.info( "Resource Loader using columns: " + keyColumn + ", "
  +         rsvc.info("Resources Loaded From: " + dataSourceName + "/" + tableName);
  +         rsvc.info("Resource Loader using columns: " + keyColumn + ", "
                          + templateColumn + " and " + timestampColumn);
  -         Runtime.info("Resource Loader Initalized.");
  +         rsvc.info("Resource Loader Initalized.");
        }
   
        public boolean isSourceModified(Resource resource)
  @@ -187,7 +186,7 @@
         *  @param name name of template
         *  @return InputStream containing template
         */
  -     public synchronized InputStream getResourceStream( String name )
  +     public synchronized InputStream getResourceStream(String name)
            throws ResourceNotFoundException
        {
            if (name == null || name.length() == 0)
  @@ -214,9 +213,9 @@
                        {
                            String msg = "DataSourceResourceLoader Error: cannot find resource "
                                + name;
  -                         Runtime.error(msg );
  +                         rsvc.error(msg);
   
  -                         throw new ResourceNotFoundException (msg);
  +                         throw new ResourceNotFoundException(msg);
                        }
                    }
                    finally
  @@ -234,12 +233,10 @@
                String msg =  "DataSourceResourceLoader Error: database problem trying to load resource "
                    + name + ": " + e.toString();
   
  -             Runtime.error( msg );
  -
  -             throw new ResourceNotFoundException (msg);
  +             rsvc.error(msg);
   
  +             throw new ResourceNotFoundException(msg);
            }
  -
        }
   
       /**
  @@ -272,7 +269,7 @@
                        }
                        else
                        {
  -                         Runtime.error("DataSourceResourceLoader Error: while "
  +                         rsvc.error("DataSourceResourceLoader Error: while "
                                          + i_operation
                                          + " could not find resource " + name);
                        }
  @@ -287,12 +284,19 @@
                    closeDbConnection(conn);
                }
            }
  -         catch(Exception e)
  +         catch(SQLException e)
  +         {
  +             rsvc.error( "DataSourceResourceLoader Error: error while "
  +                 + i_operation + " when trying to load resource "
  +                 + name + ": " + e.toString() );
  +         }
  +         catch(NamingException e)
            {
  -             Runtime.error( "DataSourceResourceLoader Error: error while "
  +             rsvc.error( "DataSourceResourceLoader Error: error while "
                    + i_operation + " when trying to load resource "
                    + name + ": " + e.toString() );
            }
  +
            return 0;
        }
   
  @@ -303,14 +307,14 @@
        *  @return connection
        */
        private Connection openDbConnection()
  -         throws Exception
  +         throws NamingException, SQLException
       {
  -         if(ctx == null)
  +         if (ctx == null)
            {
                ctx = new InitialContext();
            }
   
  -         if(dataSource == null)
  +         if (dataSource == null)
            {
                dataSource = (DataSource)ctx.lookup(dataSourceName);
            }
  @@ -329,7 +333,7 @@
            }
            catch (Exception e)
            {
  -             Runtime.info(
  +             rsvc.info(
                    "DataSourceResourceLoader Quirk: problem when closing connection: "
                    + e.toString());
            }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org