db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata RepositoryPersistor.java
Date Fri, 04 Mar 2005 13:31:06 GMT
brianm      2005/03/04 05:31:06

  Modified:    src/java/org/apache/ojb/broker/metadata
                        RepositoryPersistor.java
  Log:
  Two patches from Ilkka Priha:
  
  Currently, OJB loads the OJB.properties file by getting an input stream from the corresponding
URL. However, if the properties file is embedded in a jar archive, this method locks the corresponding
jar and prevents it from being removed during undeployment of a web application (at least
in Sun jdk under Windows). Some web containers (e.g. Tomcat) have non-standard configuration
options to handle jar resources in a specific way to prevent locking, but a more general solution
is to disable caching in the URL connection before opening the input stream.
  
  The locked jar problem with OJB.properties can also be caused by repository descriptors
embedded in jar archives. The problem is caused by RepositoryPersistor passing a URL path
to InputSource without disabling caching in the corresponding URL connection.
  
  Submitted by:   Ilkka Priha
  
  Revision  Changes    Path
  1.29      +26 -5     db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java
  
  Index: RepositoryPersistor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- RepositoryPersistor.java	14 Nov 2004 09:36:10 -0000	1.28
  +++ RepositoryPersistor.java	4 Mar 2005 13:31:06 -0000	1.29
  @@ -40,6 +40,7 @@
   import java.io.InputStream;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.net.URLConnection;
   import java.util.Date;
   
   /**
  @@ -292,13 +293,33 @@
           arminw:
           strange, when using 'url.openStream()' argument repository
           could not be parsed
  +        ipriha:
  +        parser needs a base url to find referenced entities.
           */
  -        // InputSource source = new InputSource(url.openStream());
  -        
  -        String pathName = url.toString();
  +
  +        String pathName = url.toExternalForm();
           log.info("Building repository from :" + pathName);
           InputSource source = new InputSource(pathName);
  -        return readMetadataFromXML(source, targetRepository);
  +        URLConnection conn = url.openConnection();
  +        conn.setUseCaches(false);
  +        conn.connect();
  +        InputStream in = conn.getInputStream();
  +        source.setByteStream(in);
  +        try
  +		{
  +        	return readMetadataFromXML(source, targetRepository);
  +		}
  +        finally
  +		{
  +        	try
  +			{
  +        		in.close();
  +			}
  +        	catch (IOException x)
  +			{
  +                log.warn("unable to close repository input stream [" + x.getMessage() +
"]", x);
  +			}
  +		}
       }
   
       /**
  
  
  

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


Mime
View raw message