db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/test/org/apache/ojb/broker/metadata RepositoryPersistorTest.java
Date Thu, 26 Dec 2002 19:34:46 GMT
arminw      2002/12/26 11:34:45

  Modified:    src/java/org/apache/ojb/broker/metadata
                        ConnectionRepository.java DescriptorRepository.java
                        MetadataManager.java RepositoryPersistor.java
               src/test/org/apache/ojb/broker/metadata
                        RepositoryPersistorTest.java
  Log:
  adapt repository reading and writing
  
  Revision  Changes    Path
  1.2       +1 -8      jakarta-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionRepository.java
  
  Index: ConnectionRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConnectionRepository.java	24 Dec 2002 13:14:33 -0000	1.1
  +++ ConnectionRepository.java	26 Dec 2002 19:34:45 -0000	1.2
  @@ -107,11 +107,6 @@
           // use copy to avoid sync problems
           HashMap map = (HashMap) jcdMap.clone();
           StringBuffer buf = new StringBuffer();
  -        buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  -        buf.append(eol);
  -        buf.append("<database-repository>");
  -        buf.append(eol);
  -        buf.append(eol);
           Iterator it = map.values().iterator();
           while (it.hasNext())
           {
  @@ -119,8 +114,6 @@
               buf.append(jcd.toXML());
               buf.append(eol);
           }
  -        buf.append(eol);
  -        buf.append("</database-repository>");
           return buf.toString();
       }
   }
  
  
  
  1.29      +6 -28     jakarta-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- DescriptorRepository.java	24 Dec 2002 15:49:50 -0000	1.28
  +++ DescriptorRepository.java	26 Dec 2002 19:34:45 -0000	1.29
  @@ -395,37 +395,15 @@
       {
           RepositoryTags tags = RepositoryTags.getInstance();
           String eol = SystemUtils.LINE_SEPARATOR;
  +        StringBuffer buf = new StringBuffer();
   
  -        // 1. write XML header
  -        String strReturn = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + eol;
  -
  -        strReturn += "<!DOCTYPE descriptor-repository SYSTEM \"repository.dtd\" [" +
eol;
  -        strReturn += "<!ENTITY database-metadata SYSTEM \""+ConnectionRepository.DATABASE_METADATA_FILENAME+"\">"
+ eol;
  -        strReturn += "<!ENTITY user SYSTEM \"repository_user.xml\">" + eol;
  -        strReturn += "<!ENTITY junit SYSTEM \"repository_junit.xml\">" + eol;
  -        strReturn += "<!ENTITY internal SYSTEM \"repository_internal.xml\"> ]>"
+ eol + eol;
  -
  -        strReturn += "<!-- OJB RepositoryPersistor generated this file on " + new Date().toString()
+ " -->" + eol;
  -
  -        // 1a. write opening tab and attributes
  -        strReturn += tags.getOpeningTagNonClosingById(MAPPING_REPOSITORY) + eol;
  -        strReturn += "  " + tags.getAttribute(REPOSITORY_VERSION, getVersion()) + eol;
  -        strReturn += "  " + tags.getAttribute(ISOLATION_LEVEL, this.getIsolationLevelAsString())
+ eol;
  -
  -        strReturn += ">" + eol;
  -
  -        // 2. Connection stuff was separated in ConnectionRepository, use ENTITY 'database'
attribute
  -        strReturn +=eol+"<!-- include ojb database mapping -->"+eol;
  -        strReturn +="&database-metadata;"+eol+eol;
  -
  -        // 3. write all ClassDescriptors
  +        // write all ClassDescriptors
           Iterator i = this.iterator();
           while (i.hasNext())
           {
  -            strReturn += ((XmlCapable) i.next()).toXML() + eol;
  +            buf.append(((XmlCapable) i.next()).toXML() + eol);
           }
  -        // 4. write closing tag
  -        return strReturn + tags.getClosingTagById(MAPPING_REPOSITORY);
  +        return buf.toString();
       }
   
       /**
  @@ -433,7 +411,7 @@
        * to the corresponding id
        * @return the IsolationLevel literal
        */
  -    private String getIsolationLevelAsString()
  +    protected String getIsolationLevelAsString()
       {
           if (defaultIsolationLevel == IL_READ_UNCOMMITTED)
           {
  
  
  
  1.2       +11 -2     jakarta-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java
  
  Index: MetadataManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MetadataManager.java	24 Dec 2002 13:14:33 -0000	1.1
  +++ MetadataManager.java	26 Dec 2002 19:34:45 -0000	1.2
  @@ -52,11 +52,20 @@
           try
           {
               globalRepository = new RepositoryPersistor().readDescriptorRepository(repository);
  +        }
  +        catch (Exception e)
  +        {
  +            throw new MetadataException(
  +                    "Could not read repository class descriptor data, using repository:
"+repository,e);
  +        }
  +        try
  +        {
               connectionRepository = new RepositoryPersistor().readConnectionRepository(repository);
           }
           catch (Exception e)
           {
  -            throw new MetadataException("Could not read DescriptorRepository data",e);
  +            throw new MetadataException(
  +                    "Could not read jdbc-connection-descriptor data, using repository:
"+repository,e);
           }
       }
   
  
  
  
  1.10      +34 -26    jakarta-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java
  
  Index: RepositoryPersistor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryPersistor.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- RepositoryPersistor.java	24 Dec 2002 13:14:33 -0000	1.9
  +++ RepositoryPersistor.java	26 Dec 2002 19:34:45 -0000	1.10
  @@ -55,6 +55,7 @@
    */
   
   import org.apache.commons.lang.SerializationUtils;
  +import org.apache.commons.lang.SystemUtils;
   import org.apache.ojb.broker.util.configuration.Configurable;
   import org.apache.ojb.broker.util.configuration.Configuration;
   import org.apache.ojb.broker.util.configuration.ConfigurationException;
  @@ -76,6 +77,7 @@
   import java.io.PrintWriter;
   import java.net.MalformedURLException;
   import java.net.URL;
  +import java.util.Date;
   
   /**
    * This class is responsible for reading and writing DescriptorRepository objects
  @@ -108,38 +110,43 @@
       /**
        * Write the {@link DescriptorRepository} to the given file name.
        */
  -    public void writeToFile(DescriptorRepository repository, String filename)
  +    public void writeToFile(DescriptorRepository repository, ConnectionRepository conRepository,
String filename)
       {
  +        RepositoryTags tags = RepositoryTags.getInstance();
           try
           {
               if(log.isDebugEnabled()) log.debug("## Write repository file ##"+
                       repository.toXML()+
                       "## End of repository file ##");
  -            FileOutputStream fos = new FileOutputStream(filename);
  -            PrintWriter pw = new PrintWriter(fos);
  -            pw.print(repository.toXML());
  -            pw.flush();
  -            pw.close();
  -        }
  -        catch (Throwable t)
  -        {
  -            log.fatal("Could not write to file" + filename, t);
  -        }
  -    }
   
  -    /**
  -     * Write the {@link ConnectionRepository} to the given file name.
  -     */
  -    public void writeToFile(ConnectionRepository repository, String filename)
  -    {
  -        try
  -        {
  -            if(log.isDebugEnabled()) log.debug("## Write connection repository file ##"+
  -                    repository.toXML()+
  -                    "## End of repository file ##");
  +
  +            String eol = SystemUtils.LINE_SEPARATOR;
  +            StringBuffer buf = new StringBuffer();
  +            // 1. write XML header
  +            buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + eol);
  +
  +            buf.append("<!DOCTYPE descriptor-repository SYSTEM \"repository.dtd\" >"+
eol + eol);
  +//            strReturn += "<!DOCTYPE descriptor-repository SYSTEM \"repository.dtd\"
[" + eol;
  +//            strReturn += "<!ENTITY database-metadata SYSTEM \""+ConnectionRepository.DATABASE_METADATA_FILENAME+"\">"
+ eol;
  +//            strReturn += "<!ENTITY user SYSTEM \"repository_user.xml\">" + eol;
  +//            strReturn += "<!ENTITY junit SYSTEM \"repository_junit.xml\">" + eol;
  +//            strReturn += "<!ENTITY internal SYSTEM \"repository_internal.xml\">
]>" + eol + eol;
  +
  +            buf.append("<!-- OJB RepositoryPersistor generated this file on " + new
Date().toString() + " -->" + eol);
  +
  +            buf.append(tags.getOpeningTagNonClosingById(RepositoryElements.MAPPING_REPOSITORY)
+ eol);
  +            buf.append("  " + tags.getAttribute(RepositoryElements.REPOSITORY_VERSION,
repository.getVersion()) + eol);
  +            buf.append("  " + tags.getAttribute(RepositoryElements.ISOLATION_LEVEL, repository.getIsolationLevelAsString())
+ eol);
  +            buf.append(">" + eol);
  +
  +            buf.append(eol+eol+conRepository.toXML()+eol+eol);
  +            buf.append(repository.toXML());
  +
  +            buf.append(tags.getClosingTagById(RepositoryElements.MAPPING_REPOSITORY));
  +
               FileOutputStream fos = new FileOutputStream(filename);
               PrintWriter pw = new PrintWriter(fos);
  -            pw.print(repository.toXML());
  +            pw.print(buf.toString());
               pw.flush();
               pw.close();
           }
  @@ -266,7 +273,7 @@
           else if(ConnectionRepository.class.equals(targetRepository))
           {
               reader = p.getXMLReader();
  -            reader.setFeature("http://xml.org/sax/features/validation", false);
  +            // reader.setFeature("http://xml.org/sax/features/validation", false);
               // create an empty repository:
               ConnectionRepository repository = new ConnectionRepository();
               // create handler for building the repository structure
  @@ -277,7 +284,8 @@
               //LoggerFactory.getBootLogger().info("loading XML took " + (stop - start) +
" msecs");
               result = repository;
           }
  -        else throw new MetadataException("Could not build a repository instance for "+targetRepository);
  +        else throw new MetadataException("Could not build a repository instance for '"+targetRepository+
  +            "', try to read data using "+repositoryFileName);
           return result;
       }
   
  
  
  
  1.6       +6 -5      jakarta-ojb/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java
  
  Index: RepositoryPersistorTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RepositoryPersistorTest.java	24 Dec 2002 14:05:36 -0000	1.5
  +++ RepositoryPersistorTest.java	26 Dec 2002 19:34:45 -0000	1.6
  @@ -51,7 +51,7 @@
   	{
   		String filename = "test_respository.xml";
           DescriptorRepository repository = MetadataManager.getInstance().getRepository();
  -
  +        ConnectionRepository conRepository = MetadataManager.getInstance().connectionRepository();
           Iterator iter = repository.iterator();
           int numClasses = 0;
           while (iter.hasNext())
  @@ -61,7 +61,7 @@
           }
   
           RepositoryPersistor persistor = new RepositoryPersistor();
  -        persistor.writeToFile(repository, filename);
  +        persistor.writeToFile(repository, conRepository, filename);
   
           DescriptorRepository second = persistor.readDescriptorRepository(filename);
           iter = second.iterator();
  @@ -79,10 +79,11 @@
   	public void testStoreConnectionRepository() throws Exception
   	{
   		String filename = "test_repository_database.xml";
  -        ConnectionRepository repository = MetadataManager.getInstance().connectionRepository();
  -        int connectionCount = repository.getAllDescriptor().size();
  +        DescriptorRepository repository = MetadataManager.getInstance().getRepository();
  +        ConnectionRepository conRepository = MetadataManager.getInstance().connectionRepository();
  +        int connectionCount = conRepository.getAllDescriptor().size();
           RepositoryPersistor persistor = new RepositoryPersistor();
  -        persistor.writeToFile(repository, filename);
  +        persistor.writeToFile(repository, conRepository, filename);
   
           ConnectionRepository second = persistor.readConnectionRepository(filename);
           int connectionCount2 = second.getAllDescriptor().size();
  
  
  

Mime
View raw message