db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From baser...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker/metadata RuntimeConfigurationTest.java
Date Mon, 15 Mar 2004 00:32:20 GMT
baserose    2004/03/14 16:32:20

  Modified:    src/java/org/apache/ojb/broker/metadata
                        AttributeDescriptorBase.java ClassDescriptor.java
                        RepositoryXmlHandler.java
               src/java/org/apache/ojb/broker/metadata/fieldaccess
                        PersistentFieldFactory.java
               src/test/org/apache/ojb/broker/metadata
                        RuntimeConfigurationTest.java
  Log:
  Implementing PersistentField per Class descriptors.
  
  If you use the attribute 'persistent-field-class' on your class descriptor, all
  fields on that class desc will use the configured PersistentField,
  Class desc without that attribute will use the PersistentField
  configured @ OJB.properties
  
  Revision  Changes    Path
  1.16      +6 -1      db-ojb/src/java/org/apache/ojb/broker/metadata/AttributeDescriptorBase.java
  
  Index: AttributeDescriptorBase.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/AttributeDescriptorBase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AttributeDescriptorBase.java	11 Mar 2004 18:16:10 -0000	1.15
  +++ AttributeDescriptorBase.java	15 Mar 2004 00:32:20 -0000	1.16
  @@ -50,6 +50,11 @@
           m_PersistentField = PersistentFieldFactory.createPersistentField(c, fieldname);
       }
   
  +	public void setPersistentField(PersistentField pf)
  +	{
  +		m_PersistentField = pf;
  +	}
  +
       /**
        *
        */
  
  
  
  1.81      +22 -2     db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java
  
  Index: ClassDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ClassDescriptor.java,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- ClassDescriptor.java	11 Mar 2004 18:16:10 -0000	1.80
  +++ ClassDescriptor.java	15 Mar 2004 00:32:20 -0000	1.81
  @@ -70,7 +70,9 @@
   public final class ClassDescriptor extends DescriptorBase
       implements Serializable, XmlCapable, IsolationLevels
   {
  -	private static final long serialVersionUID = -5212253607374173965L;
  +	private String persistentFieldClassName;
  +
  +    private static final long serialVersionUID = -5212253607374173965L;
   
       public static final String OJB_CONCRETE_CLASS = "ojbConcreteClass";
       private static final Class[] NO_PARAMS = {};
  @@ -2042,5 +2044,23 @@
                      getStatementsForClass(conMan.getConnectionDescriptor(), this);
           }
           return statementsForClass;
  +    }
  +
  +
  +    /**
  +     * @param pfClassName
  +     */
  +    public void setPersistentFieldClassName(String pfClassName)
  +    {
  +		this.persistentFieldClassName = pfClassName;
  +    }
  +
  +
  +    /**
  +     * @return
  +     */
  +    public String getPersistentFieldClassName()
  +    {
  +		return persistentFieldClassName;
       }
   }
  
  
  
  1.55      +16 -6     db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
  
  Index: RepositoryXmlHandler.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- RepositoryXmlHandler.java	11 Mar 2004 18:16:11 -0000	1.54
  +++ RepositoryXmlHandler.java	15 Mar 2004 00:32:20 -0000	1.55
  @@ -17,6 +17,8 @@
   
   import org.apache.ojb.broker.accesslayer.QueryCustomizer;
   import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentFieldHelper;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldFactory;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  @@ -36,7 +38,7 @@
    * metadata, one for pc object metadata.
    * </p>
    * @author <a href="mailto:thma@apache.org">Thomas Mahler<a>
  - * @author Jakob Bräuchi
  + * @author Jakob Br?uchi
    * @version $Id$
    */
   public class RepositoryXmlHandler
  @@ -308,6 +310,10 @@
                           b = (Boolean.valueOf(refresh)).booleanValue();
                           m_CurrentCLD.setAlwaysRefresh(b);
   
  +						// persistent field
  +						String pfClassName = atts.getValue("persistent-field-class");
  +						if (isDebug) logger.debug("     persistent-field-class: " + pfClassName);
  +						m_CurrentCLD.setPersistentFieldClassName(pfClassName);
   
                           break;
                       }
  @@ -369,12 +375,14 @@
   
                           if (RepositoryElements.TAG_ACCESS_ANONYMOUS.equalsIgnoreCase(strAccess))
                           {
  -                            m_CurrentFLD.setPersistentField(null, fieldName);
  +							AnonymousFieldDescriptor anonymous = (AnonymousFieldDescriptor) m_CurrentFLD; 
  +                            anonymous.setPersistentField(null,fieldName);
                           }
                           else
                           {
                               String classname = m_CurrentCLD.getClassNameOfObject();
  -                            m_CurrentFLD.setPersistentField(ClassHelper.getClass(classname),
fieldName);
  +							PersistentField pf = PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),ClassHelper.getClass(classname),fieldName);
  +                            m_CurrentFLD.setPersistentField(pf);
                           }
   
                           String columnName = atts.getValue(tags.getTagById(COLUMN_NAME));
  @@ -485,7 +493,8 @@
                           else
                           {
                               ord = new ObjectReferenceDescriptor(m_CurrentCLD);
  -                            ord.setPersistentField(m_CurrentCLD.getClassOfObject(), name);
  +                            PersistentField pf = PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),m_CurrentCLD.getClassOfObject(),name);
  +                            ord.setPersistentField(pf);
                           }
                           m_CurrentORD = ord;
   
  @@ -590,7 +599,8 @@
                           // set name attribute
                           name = atts.getValue(tags.getTagById(FIELD_NAME));
                           if (isDebug) logger.debug("     " + tags.getTagById(FIELD_NAME)
+ ": " + name);
  -                        m_CurrentCOD.setPersistentField(m_CurrentCLD.getClassOfObject(),
name);
  +						PersistentField pf = PersistentFieldFactory.createPersistentField(m_CurrentCLD.getPersistentFieldClassName(),m_CurrentCLD.getClassOfObject(),name);
  +                        m_CurrentCOD.setPersistentField(pf);
   
                           // set collection-class attribute
                           String collectionClassName = atts.getValue(tags.getTagById(COLLECTION_CLASS));
  
  
  
  1.10      +18 -12    db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldFactory.java
  
  Index: PersistentFieldFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/fieldaccess/PersistentFieldFactory.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- PersistentFieldFactory.java	11 Mar 2004 18:16:12 -0000	1.9
  +++ PersistentFieldFactory.java	15 Mar 2004 00:32:20 -0000	1.10
  @@ -34,26 +34,32 @@
       private static final Class DEFAULT_PERSISTENT_FIELD_IMPL = PersistentFieldDirectAccessImpl.class;
       private static final Class[] METHOD_PARAMETER_TYPES = {Class.class, String.class};
   
  -    private static Class persistentFieldClass = null;
       private static boolean usesAccessorsAndMutators = false;
       private static boolean usesAccessorsAndMutatorsCheck = false;
   
       /**
        * @throws MetadataException if an erros occours when creating the PersistenteField
        */
  -    public static PersistentField createPersistentField(Class attributeType, String attributeName)
  +	public static PersistentField createPersistentField(Class attributeType, String attributeName)
  +	{
  +		return createPersistentField(null,attributeType,attributeName);
  +	}
  +    
  +    public static PersistentField createPersistentField(String persistentFieldClassName,
Class attributeType, String attributeName)
       {
           try
           {
  -            if (persistentFieldClass == null)
  +            if (persistentFieldClassName == null)
               {
                   synchronized (PersistentFieldFactory.class)
                   {
  -                    persistentFieldClass = getPersistentFieldClass();
  +                    persistentFieldClassName = getDefaultPersistentFieldClassName();
                   }
               }
               Object[] args = {attributeType, attributeName};
  -            return (PersistentField) ClassHelper.newInstance(persistentFieldClass, METHOD_PARAMETER_TYPES,
args);
  +            PersistentField pf = (PersistentField) ClassHelper.newInstance(persistentFieldClassName,
METHOD_PARAMETER_TYPES, args);
  +            return pf;
  +            
           }
           catch (Exception ex)
           {
  @@ -69,17 +75,17 @@
               retval = usesAccessorsAndMutators;
           else
           {
  -            Class clazz = getPersistentFieldClass();
  +            String className = getDefaultPersistentFieldClassName();
               PersistentField field = null;
               try
               {
  -                field = (PersistentField) ClassHelper.newInstance(clazz);
  +                field = (PersistentField) ClassHelper.newInstance(className);
                   usesAccessorsAndMutators = field.usesAccessorsAndMutators();
                   retval = usesAccessorsAndMutators;
               }
               catch (Exception e)
               {
  -                log.error("Cannot verify 'usesAccessorsAndMutators' attribute for class
" + clazz, e);
  +                log.error("Cannot verify 'usesAccessorsAndMutators' attribute for class
" + className, e);
               }
               finally
               {
  @@ -89,7 +95,7 @@
           return retval;
       }
   
  -    private static Class getPersistentFieldClass()
  +    private static String getDefaultPersistentFieldClassName()
       {
           try
           {
  @@ -98,12 +104,12 @@
                               null);
   
               Class clazz = config.getPersistentFieldClass();
  -            return clazz;
  +            return clazz.getName();
           }
           catch (ConfigurationException e)
           {
               log.error("Cannot look-up PersistentField class, use default implementation
instead", e);
  -            return DEFAULT_PERSISTENT_FIELD_IMPL;
  +            return DEFAULT_PERSISTENT_FIELD_IMPL.getName();
           }
       }
   
  
  
  
  1.4       +5 -2      db-ojb/src/test/org/apache/ojb/broker/metadata/RuntimeConfigurationTest.java
  
  Index: RuntimeConfigurationTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/metadata/RuntimeConfigurationTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RuntimeConfigurationTest.java	14 Aug 2003 18:42:40 -0000	1.3
  +++ RuntimeConfigurationTest.java	15 Mar 2004 00:32:20 -0000	1.4
  @@ -4,6 +4,8 @@
   import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.ObjectRepository;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentField;
  +import org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldFactory;
   
   /**
    * Test used to check if it is possible to start OJB
  @@ -48,7 +50,8 @@
           ClassDescriptor cld = new ClassDescriptor(dr);
           cld.setClassOfObject(ObjectRepository.A.class);
           FieldDescriptor fd = new FieldDescriptor(cld, 1);
  -        fd.setPersistentField(ObjectRepository.A.class, "someAField");
  +        PersistentField pf = PersistentFieldFactory.createPersistentField(ObjectRepository.A.class,
"someAField");
  +        fd.setPersistentField(pf);
           cld.addFieldDescriptor(fd);
   
           dr.setClassDescriptor(cld);
  
  
  

---------------------------------------------------------------------
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