db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/xdocs tutorial3.xml
Date Thu, 05 Jun 2003 10:19:44 GMT
arminw      2003/06/05 03:19:41

  Modified:    xdocs    tutorial3.xml
  Log:
  update code snip
  
  Revision  Changes    Path
  1.21      +25 -29    db-ojb/xdocs/tutorial3.xml
  
  Index: tutorial3.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/tutorial3.xml,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- tutorial3.xml	7 May 2003 21:32:49 -0000	1.20
  +++ tutorial3.xml	5 Jun 2003 10:19:41 -0000	1.21
  @@ -1402,47 +1402,43 @@
   	mechanism. The code of the default implementation looks like follows:
   </p>
   <source><![CDATA[
  -protected ClassDescriptor selectClassDescriptor(
  -    Map row,
  -    ClassDescriptor cld)
  -    throws PersistenceBrokerException
  +protected ClassDescriptor selectClassDescriptor(Map row)
  +                                        throws PersistenceBrokerException
   {
  -    // check if there is an attribute which
  -    // tells us which concrete class
  -    // is to be instantiated
  +    // check if there is an attribute which tells us
  +    // which concrete class is to be instantiated
       FieldDescriptor concreteClassFD =
  -                    cld.getFieldDescriptorByName(
  -                        ClassDescriptor.OJB_CONCRETE_CLASS);
  +        m_cld.getFieldDescriptorByName(
  +            ClassDescriptor.OJB_CONCRETE_CLASS);
   
       if (concreteClassFD == null)
  -        return cld;
  +        return m_cld;
       else
       {
  -        PersistenceBroker broker = null;
           try
           {
  -            String concreteClass =
  -                (String) row.get(concreteClassFD.getColumnName());
  -            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            ClassDescriptor result =
  -                broker.getClassDescriptor(
  -                  Class.forName(
  -                      concreteClass,
  -                      true,
  -                      Thread.currentThread().getContextClassLoader()));
  -            PersistenceBrokerFactory.releaseInstance(broker);
  +            String concreteClass = (String) row.get(
  +                                    concreteClassFD.getColumnName());
  +            if (concreteClass == null ||
  +                                    concreteClass.trim().length() == 0)
  +            {
  +                throw new PersistenceBrokerException(
  +                    "ojbConcreteClass field returned null or 0-length string");
  +            }
  +            else
  +            {
  +                concreteClass = concreteClass.trim();
  +            }
  +            ClassDescriptor result = m_cld.getRepository().
  +                                        getDescriptorFor(concreteClass);
               if (result == null)
  -                result = cld;
  +            {
  +                result = m_cld;
  +            }
               return result;
           }
  -        catch (PersistenceBrokerException e)
  +        catch (PBFactoryException e)
           {
  -            PersistenceBrokerFactory.releaseInstance(broker);
  -            throw e;
  -        }
  -        catch (ClassNotFoundException e)
  -        {
  -            PersistenceBrokerFactory.releaseInstance(broker);
               throw new PersistenceBrokerException(e);
           }
       }
  
  
  

Mime
View raw message