db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata RepositoryPersistor.java
Date Tue, 22 Apr 2003 20:24:00 GMT
thma        2003/04/22 13:23:59

  Modified:    src/test/org/apache/ojb OJB.properties
               src/java/org/apache/ojb/broker/metadata
                        RepositoryPersistor.java
  Log:
  repairing the RepositoryPersistor so that it safes the serielized repository accross multiple
application starts
  
  Revision  Changes    Path
  1.45      +6 -1      db-ojb/src/test/org/apache/ojb/OJB.properties
  
  Index: OJB.properties
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/OJB.properties,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- OJB.properties	8 Apr 2003 20:19:30 -0000	1.44
  +++ OJB.properties	22 Apr 2003 20:23:59 -0000	1.45
  @@ -14,8 +14,13 @@
   # If the useSerializedRepository entry is set to true, OJB tries to load a
   # serialized version of the repository for performance reasons.
   # if set to false, OJB always loads the xml file
  -useSerializedRepository=false
  +useSerializedRepository=true
   #
  +# If Repository serialization is used the entry serializedRepositoryPath defines the
  +# dirercory where the Repository is written to and read from.
  +# this entry is used only when the useSerializedRepository flag is set to true
  +#
  +serializedRepositoryPath=.
   #
   #----------------------------------------------------------------------------------------
   # PersistenceBrokerFactory / PersistenceBroker
  
  
  
  1.17      +14 -10    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.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- RepositoryPersistor.java	9 Feb 2003 09:21:53 -0000	1.16
  +++ RepositoryPersistor.java	22 Apr 2003 20:23:59 -0000	1.17
  @@ -90,10 +90,9 @@
   {
       private static Logger log = LoggerFactory.getLogger(RepositoryPersistor.class);
   
  -    private static final String SER_FILE_PERFIX = "ojb_repository";
  -    private static final String SER_FILE_SUFFIX = "serialize";
  -    private static File serFile;
  -
  +    private static final String SER_FILE_SUFFIX = "serialized";
  +	private static final String SERIALIZED_REPOSITORY_PATH = "serializedRepositoryPath";
  +	
       private boolean useSerializedRepository = false;
   
       public RepositoryPersistor()
  @@ -166,15 +165,21 @@
       {
           DescriptorRepository result;
           if (useSerializedRepository)
  +        // use serialized repository
           {
  -            if(serFile != null && serFile.length() > 0)
  +        	// build File object pointing to serialized repository location
  +        	Configuration config = OjbConfigurator.getInstance().getConfigurationFor(null);
  +        	String pathPrefix = config.getString(SERIALIZED_REPOSITORY_PATH, ".");
  +        	File serFile = new File(pathPrefix + File.separator + filename + "." + SER_FILE_SUFFIX);
  +
  +            if(serFile.exists() && serFile.length() > 0)
  +            // if file exists load serialized version of repository
               {
                   try
                   {
                       long duration = System.currentTimeMillis();
                       result = deserialize(serFile);
                       log.info("Read serialized repository in "+(System.currentTimeMillis()-duration)+"
ms");
  -                    //return result;
                   }
                   catch (Exception e)
                   {
  @@ -183,16 +188,15 @@
                   }
               }
               else
  +            // if no serialized version exists, read it from xml and write serialized file
               {
  -                serFile = File.createTempFile(SER_FILE_PERFIX, SER_FILE_SUFFIX);
  -                serFile.deleteOnExit();
                   long duration = System.currentTimeMillis();
                   result = (DescriptorRepository) buildRepository(filename, DescriptorRepository.class);
                   log.info("Read repository from file took "+(System.currentTimeMillis()-duration)+"
ms");
                   serialize(result, serFile);
  -
               }
           }
  +        // don't use serialized repository
           else
           {
               long duration = System.currentTimeMillis();
  
  
  

Mime
View raw message