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/tools/org/apache/ojb/tools/mapping/reversedb2/actions ActionNewOJBRepository.java
Date Tue, 26 Oct 2004 15:27:41 GMT
baserose    2004/10/26 08:27:41

  Modified:    src/java/org/apache/ojb/broker OJB.java
                        PersistenceBrokerFactory.java
               src/java/org/apache/ojb/broker/accesslayer
                        RowReaderDefaultImpl.java
               src/java/org/apache/ojb/broker/core Factories.java
               src/java/org/apache/ojb/broker/metadata ClassDescriptor.java
                        DescriptorRepository.java MetadataManager.java
                        RepositoryElements.java RepositoryPersistor.java
                        RepositoryTags.java RepositoryXmlHandler.java
               src/schema ojbtest-data.dtd ojbtest-data.xml
                        ojbtest-schema.xml
               src/test/org/apache/ojb repository_junit.xml
               src/test/org/apache/ojb/broker AllTests.java
               src/tools/org/apache/ojb/tools/mapping/reversedb2/actions
                        ActionNewOJBRepository.java
  Added:       src/java/org/apache/ojb/broker/core/factory
                        ObjectFactory.java ObjectFactoryDefaultImpl.java
                        ObjectFactoryException.java
                        ObjectFactorySupport.java
               src/java/org/apache/ojb/broker/core/factory/lifecycle
                        Initializable.java
               src/test/org/apache/ojb/broker FactoryTest.java
                        InitializableObject.java
  Log:
  Adding ObjectFactory support.
  Objects that need to be initialized with outsider instances can use a
  specific ObjectFactory to do this.
  
  The usage is simple, just add useObjectFactory="true" into your repository.xml
  other than that, the ClassHelper will continue to be used to create persistent object
  instances for you !
  
  Revision  Changes    Path
  1.3       +20 -7     db-ojb/src/java/org/apache/ojb/broker/OJB.java
  
  Index: OJB.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/OJB.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OJB.java	14 Sep 2004 16:36:14 -0000	1.2
  +++ OJB.java	26 Oct 2004 15:27:39 -0000	1.3
  @@ -6,6 +6,7 @@
   
   import org.apache.ojb.broker.cache.CacheManager;
   import org.apache.ojb.broker.core.Factories;
  +import org.apache.ojb.broker.core.factory.ObjectFactory;
   import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.metadata.ObjectCacheDescriptor;
   import org.apache.ojb.broker.metadata.PersistenceConfigurationDescriptor;
  @@ -13,6 +14,7 @@
   import org.apache.ojb.broker.util.ObjectModification;
   import org.apache.ojb.broker.util.logging.Logger;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
  +import org.apache.ojb.broker.core.factory.ObjectFactoryDefaultImpl;
   
   /* Copyright 2002-2004 The Apache Software Foundation
    *
  @@ -48,12 +50,23 @@
       private HashMap configurationMap;
       private Object dummy = new Object();
   
  -    public OJB()
  -    {
  -        configurationMap = new HashMap();
  -        metadataManager = new MetadataManager();
  -        factories = new Factories();
  -    }
  +	public OJB()
  +	{
  +		initialize(new ObjectFactoryDefaultImpl());
  +	}
  +
  +	public OJB(ObjectFactory objectFactory)
  +	{
  +		initialize(objectFactory);
  +	}
  +
  +	private void initialize(ObjectFactory objectFactory)
  +	{
  +		configurationMap = new HashMap();
  +		factories = new Factories();
  +		factories.setObjectFactory(objectFactory);
  +		metadataManager = new MetadataManager(factories);
  +	}
   
       public Factories getFactories()
       {
  
  
  
  1.26      +40 -11    db-ojb/src/java/org/apache/ojb/broker/PersistenceBrokerFactory.java
  
  Index: PersistenceBrokerFactory.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/PersistenceBrokerFactory.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- PersistenceBrokerFactory.java	14 Aug 2004 08:37:40 -0000	1.25
  +++ PersistenceBrokerFactory.java	26 Oct 2004 15:27:39 -0000	1.26
  @@ -17,7 +17,7 @@
   
   import java.util.List;
   
  -import org.apache.ojb.broker.metadata.MetadataManager;
  +import org.apache.ojb.broker.core.factory.ObjectFactory;
   import org.apache.ojb.broker.util.configuration.Configurator;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   
  @@ -42,13 +42,13 @@
           ojb = ojbInstance;
       }
   
  -    public static OJB getOjb()
  +    public static OJB getOjb(ObjectFactory objectFactory)
       {
           // To preserve OJB 1.0 behavior, we create a default OJB instance if the
           // OJB instance is request but hasn't been configured yet
           if (ojb == null)
           {
  -            ojb = new OJB();
  +            ojb = new OJB(objectFactory);
           }
           return ojb;
       }
  @@ -69,7 +69,7 @@
        */
       public static void setDefaultKey(PBKey key)
       {
  -        getOjb().getMetadataManager().setDefaultPBKey(key);
  +        getOjb(null).getMetadataManager().setDefaultPBKey(key);
       }
   
       /**
  @@ -77,17 +77,33 @@
        */
       public static PBKey getDefaultKey()
       {
  -        return getOjb().getMetadataManager().getDefaultPBKey();
  +        return getOjb(null).getMetadataManager().getDefaultPBKey();
       }
   
  +	/**
  +	 * @see MetadataManager#getDefaultPBKey()
  +	 */
  +	public static PBKey getDefaultKey(ObjectFactory objectfactory)
  +	{
  +		return getOjb(objectfactory).getMetadataManager().getDefaultPBKey();
  +	}
  +
       /**
        * @see OJB#lookupBroker()
        */
       public static PersistenceBroker defaultPersistenceBroker() throws PBFactoryException
       {
  -        return getOjb().lookupBroker();
  +        return getOjb(null).lookupBroker();
       }
   
  +	public static PersistenceBroker defaultPersistenceBroker(ObjectFactory objectFactory)

  +		throws PBFactoryException
  +	{
  +		return getOjb(objectFactory).lookupBroker();
  +	}
  +
  +	
  +
       /**
        * @see OJB#lookupBroker(java.lang.String, java.lang.String, java.lang.String)
        */
  @@ -95,16 +111,29 @@
                                                               String user, String password)
               throws PBFactoryException
       {
  -        return getOjb().lookupBroker(jcdAlias, user, password);
  +        return getOjb(null).lookupBroker(jcdAlias, user, password);
       }
   
  +	public static PersistenceBroker createPersistenceBroker(String jcdAlias,
  +															String user, String password, ObjectFactory objectFactory)
  +			throws PBFactoryException
  +	{
  +		return getOjb(objectFactory).lookupBroker(jcdAlias, user, password);
  +	}
  +
  +	public static PersistenceBroker createPersistenceBroker(PBKey key)
  +			throws PBFactoryException
  +	{
  +		return getOjb(null).lookupBroker(key);
  +	}
  +
       /**
        * @see OJB#lookupBroker(org.apache.ojb.broker.PBKey)
        */
  -    public static PersistenceBroker createPersistenceBroker(PBKey key)
  +    public static PersistenceBroker createPersistenceBroker(PBKey key, ObjectFactory objectFactory)
               throws PBFactoryException
       {
  -        return getOjb().lookupBroker(key);
  +        return getOjb(objectFactory).lookupBroker(key);
       }
   
       /**
  @@ -112,7 +141,7 @@
        */
       public synchronized static void releaseAllInstances()
       {
  -        List list = getOjb().getConfigurations();
  +        List list = getOjb(null).getConfigurations();
           for (int i = 0; i < list.size(); i++)
           {
               ((PersistenceConfiguration) list.get(i)).getPersistenceBrokerFactory().releaseAllInstances();
  
  
  
  1.34      +23 -3     db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java
  
  Index: RowReaderDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/RowReaderDefaultImpl.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- RowReaderDefaultImpl.java	14 Sep 2004 16:03:33 -0000	1.33
  +++ RowReaderDefaultImpl.java	26 Oct 2004 15:27:39 -0000	1.34
  @@ -21,6 +21,8 @@
   import java.util.Map;
   
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.core.factory.ObjectFactory;
  +import org.apache.ojb.broker.core.factory.ObjectFactoryException;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
   import org.apache.ojb.broker.util.ClassHelper;
  @@ -104,7 +106,7 @@
        * be refreshed.
        * @throws PersistenceBrokerException if there ewas an error creating the new object
        */
  -    protected Object buildOrRefreshObject(Map row, ClassDescriptor targetClassDescriptor,
Object targetObject)
  +    protected Object buildOrRefreshObject(Map row, ClassDescriptor targetClassDescriptor,
Object targetObject) throws ObjectFactoryException
       {
           Object result = targetObject;
           FieldDescriptor fmd = null;
  @@ -112,7 +114,16 @@
           if(targetObject == null)
           {
               // 1. create new object instance if needed
  -            result = ClassHelper.buildNewObjectInstance(targetClassDescriptor);
  +			if(targetClassDescriptor.useObjectFactory())
  +			{
  +				ObjectFactory factory = getObjectFactory();
  +				result = factory.getInstanceOf(targetClassDescriptor.getClassOfObject());
  +			}
  +			else
  +			{
  +				result = ClassHelper.buildNewObjectInstance(targetClassDescriptor);	
  +			}
  +            
           }
   
           // 2. fill all scalar attributes of the new object
  @@ -140,6 +151,15 @@
               }
           }
           return result;
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    private ObjectFactory getObjectFactory()
  +    {
  +		return m_cld.getRepository().getFactories().getObjectFactory();
  +
       }
   
       /**
  
  
  
  1.3       +13 -1     db-ojb/src/java/org/apache/ojb/broker/core/Factories.java
  
  Index: Factories.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/core/Factories.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Factories.java	14 Sep 2004 16:16:35 -0000	1.2
  +++ Factories.java	26 Oct 2004 15:27:39 -0000	1.3
  @@ -8,6 +8,7 @@
   import org.apache.ojb.broker.accesslayer.StatementManagerFactory;
   import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorFactory;
   import org.apache.ojb.broker.cache.LocalCache;
  +import org.apache.ojb.broker.core.factory.ObjectFactory;
   import org.apache.ojb.broker.platforms.PlatformFactory;
   import org.apache.ojb.broker.util.factory.ConfigurableFactory;
   
  @@ -43,6 +44,7 @@
       private SqlGeneratorFactory sqlGeneratorFactory;
       private PlatformFactory platformFactory;
       private BatchManagerFactory batchManagerFactory;
  +    private ObjectFactory objectFactory;
   
       public Factories()
       {
  @@ -104,6 +106,16 @@
       {
           return batchManagerFactory;
       }
  +
  +	public ObjectFactory getObjectFactory()
  +	{
  +		return objectFactory;
  +	}
  +
  +	public void setObjectFactory(ObjectFactory objectFactory)
  +	{
  +		this.objectFactory = objectFactory;
  +	}
   
       //======================================================
       // inner classes
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactory.java
  
  Index: ObjectFactory.java
  ===================================================================
  package org.apache.ojb.broker.core.factory;
  
  /**
   * @author <a href="mailto:leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
   *
   */
  public interface ObjectFactory
  {
  	Object getInstanceOf(Class clazz)
  		throws ObjectFactoryException;
  	
  	Object getInstanceOf(String className)
  		throws ObjectFactoryException;
  
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactoryDefaultImpl.java
  
  Index: ObjectFactoryDefaultImpl.java
  ===================================================================
  package org.apache.ojb.broker.core.factory;
  
  /**
   * @author leandro
   *
   */
  public class ObjectFactoryDefaultImpl 
  	extends ObjectFactorySupport
  {
  
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactoryException.java
  
  Index: ObjectFactoryException.java
  ===================================================================
  package org.apache.ojb.broker.core.factory;
  
  import org.apache.ojb.broker.PersistenceBrokerException;
  
  /**
   * @author leandro
   *
   */
  public class ObjectFactoryException 
  	extends PersistenceBrokerException
  {
  
      /**
       * @param string
       * @param e
       */
      public ObjectFactoryException(String msg, Throwable t)
      {
  		super(msg,t);
      }
  
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/core/factory/ObjectFactorySupport.java
  
  Index: ObjectFactorySupport.java
  ===================================================================
  package org.apache.ojb.broker.core.factory;
  
  import org.apache.ojb.broker.core.factory.lifecycle.Initializable;
  
  
  /**
   * @author leandro
   *
   */
  public abstract class ObjectFactorySupport 
  	implements ObjectFactory
  {
  
  
      /* (non-Javadoc)
       * @see org.apache.ojb.broker.core.factory.ObjectFactory#getInstanceOf(java.lang.Class)
       */
      public Object getInstanceOf(Class clazz) 
      	throws ObjectFactoryException
      {
          try
          {
              Object obj = clazz.newInstance();
  			handleLifecycle(obj);
          	return obj;
          }
          catch (Throwable e)
          {
  			throw new ObjectFactoryException("Error creating instance of ["+clazz.getName()+"]",e);
          }
      }
  
      /* (non-Javadoc)
       * @see org.apache.ojb.broker.core.factory.ObjectFactory#getInstanceOf(java.lang.String)
       */
      public Object getInstanceOf(String className) 
      	throws ObjectFactoryException
      {
  		try
          {
              Class clazz = Class.forName(className);
              return getInstanceOf(clazz);
          }
          catch (Throwable e)
          {
  			throw new ObjectFactoryException("Error creating instance of ["+className+"]",e);
          }
      }
  
  	private void handleLifecycle(Object obj)
  		throws Exception
  	{
  		if(obj instanceof Initializable)
  		{
  			((Initializable)obj).initialize();
  		}
  	}
  
  }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/core/factory/lifecycle/Initializable.java
  
  Index: Initializable.java
  ===================================================================
  package org.apache.ojb.broker.core.factory.lifecycle;
  
  /**
   * @author leandro
   *
   */
  public interface Initializable
  {
  
  	void initialize()
  		throws Exception;
  }
  
  
  
  1.94      +14 -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.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- ClassDescriptor.java	25 Sep 2004 14:26:17 -0000	1.93
  +++ ClassDescriptor.java	26 Oct 2004 15:27:39 -0000	1.94
  @@ -70,7 +70,9 @@
   public final class ClassDescriptor extends DescriptorBase
       implements Serializable, XmlCapable, IsolationLevels
   {
  -	private String persistentFieldClassName;
  +	private boolean useObjectFactory;
  +
  +    private String persistentFieldClassName;
   
       private static final long serialVersionUID = -5212253607374173965L;
   
  @@ -1738,6 +1740,16 @@
           }
           setFactoryMethod(newMethod);
       }
  +
  +	public boolean useObjectFactory()
  +	{
  +		return useObjectFactory;
  +	}
  +
  +	public void setUseObjectFactory(boolean value)
  +	{
  +		this.useObjectFactory = value;
  +	}
   
       //---------------------------------------------------------------
       /**
  
  
  
  1.55      +13 -7     db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java
  
  Index: DescriptorRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorRepository.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- DescriptorRepository.java	15 Aug 2004 12:42:28 -0000	1.54
  +++ DescriptorRepository.java	26 Oct 2004 15:27:39 -0000	1.55
  @@ -28,6 +28,7 @@
   import org.apache.commons.lang.builder.ToStringStyle;
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.core.Factories;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  @@ -45,7 +46,8 @@
   public final class DescriptorRepository extends DescriptorBase
           implements Serializable, XmlCapable, IsolationLevels
   {
  -	static final long serialVersionUID = -1556339982311359524L;
  +    private Factories factories;
  +    static final long serialVersionUID = -1556339982311359524L;
       /**
        * The version identifier of the Repository.
        * Used to validate repository.xml against the dtd.
  @@ -72,11 +74,9 @@
       private transient Map m_firstConcreteClassMap;
       private transient Map m_allConcreteSubClass;
   
  -    /**
  -     * Constructor declaration
  -     */
  -    public DescriptorRepository() throws PersistenceBrokerException
  -    {
  +	public DescriptorRepository(Factories factories)
  +	{
  +        this.factories = factories;
           descriptorTable = new HashMap();
           extentTable = new HashMap();
       }
  @@ -85,6 +85,12 @@
       {
           return VERSION;
       }
  +
  +	public Factories getFactories()
  +	{
  +		return factories;
  +	}
  +
   
       /**
        * Add a pair of extent/classdescriptor to the extentTable to gain speed
  
  
  
  1.22      +16 -12    db-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java
  
  Index: MetadataManager.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/MetadataManager.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- MetadataManager.java	14 Aug 2004 08:37:40 -0000	1.21
  +++ MetadataManager.java	26 Oct 2004 15:27:40 -0000	1.22
  @@ -24,6 +24,7 @@
   import org.apache.commons.lang.SerializationUtils;
   import org.apache.ojb.broker.PBKey;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.core.Factories;
   import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   import org.apache.ojb.broker.util.logging.Logger;
  @@ -121,6 +122,8 @@
    */
   public class MetadataManager
   {
  +    private Factories factories;
  +
       private static Logger log = LoggerFactory.getLogger(MetadataManager.class);
   
       private static final String MSG_STR = "* Can't find DescriptorRepository for current
thread, use default one *";
  @@ -133,24 +136,25 @@
       private PBKey defaultPBKey;
   
       // singleton
  -    public MetadataManager()
  +    public MetadataManager(Factories factories)
       {
  -        init();
  +        init(factories);
       }
   
  -    private void init()
  +    private void init(Factories factories)
       {
  +    	this.factories = factories;
           metadataProfiles = new Hashtable();
           String repository = ((PersistenceBrokerConfiguration) OjbConfigurator.getInstance()
                   .getConfigurationFor(null)).getRepositoryFilename();
           try
           {
  -            globalRepository     = new RepositoryPersistor().readDescriptorRepository(repository);
  -            connectionRepository = new RepositoryPersistor().readConnectionRepository(repository);
  +            globalRepository     = new RepositoryPersistor(factories).readDescriptorRepository(repository);
  +            connectionRepository = new RepositoryPersistor(factories).readConnectionRepository(repository);
           }
           catch (FileNotFoundException ex)
           {
  -            globalRepository     = new DescriptorRepository();
  +            globalRepository     = new DescriptorRepository(this.factories);
               connectionRepository = new ConnectionRepository();
               log.info("No repository.xml file found, starting with empty metadata and connection
configuration");
           }
  @@ -167,7 +171,7 @@
       public static synchronized MetadataManager getInstance()
       {
           // we use the setup'd OJB instance
  -        return PersistenceBrokerFactory.getOjb().getMetadataManager();
  +        return PersistenceBrokerFactory.getOjb(null).getMetadataManager();
       }
   
       public PersistenceConfigurationDescriptor getConfigurationFor(PBKey key)
  @@ -323,7 +327,7 @@
       {
           try
           {
  -            RepositoryPersistor persistor = new RepositoryPersistor();
  +            RepositoryPersistor persistor = new RepositoryPersistor(this.factories);
               return persistor.readDescriptorRepository(fileName);
           }
           catch (Exception e)
  @@ -340,7 +344,7 @@
       {
           try
           {
  -            RepositoryPersistor persistor = new RepositoryPersistor();
  +            RepositoryPersistor persistor = new RepositoryPersistor(this.factories);
               return persistor.readDescriptorRepository(inst);
           }
           catch (Exception e)
  @@ -358,7 +362,7 @@
       {
           try
           {
  -            RepositoryPersistor persistor = new RepositoryPersistor();
  +            RepositoryPersistor persistor = new RepositoryPersistor(this.factories);
               return persistor.readConnectionRepository(fileName);
           }
           catch (Exception e)
  @@ -376,7 +380,7 @@
       {
           try
           {
  -            RepositoryPersistor persistor = new RepositoryPersistor();
  +            RepositoryPersistor persistor = new RepositoryPersistor(this.factories);
               return persistor.readConnectionRepository(inst);
           }
           catch (Exception e)
  
  
  
  1.39      +2 -0      db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
  
  Index: RepositoryElements.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- RepositoryElements.java	14 Sep 2004 16:17:41 -0000	1.38
  +++ RepositoryElements.java	26 Oct 2004 15:27:40 -0000	1.39
  @@ -145,6 +145,8 @@
   
       public static final int PROXY_PREFETCHING_LIMIT = 114;
   
  +	public static final int USE_OBJECT_FACTORY = 121;
  +
       // maintain a next id to keep track where we are
       static final int _NEXT = 120;
   
  
  
  
  1.26      +13 -3     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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- RepositoryPersistor.java	11 Aug 2004 00:41:47 -0000	1.25
  +++ RepositoryPersistor.java	26 Oct 2004 15:27:40 -0000	1.26
  @@ -17,6 +17,7 @@
   
   import org.apache.commons.lang.SerializationUtils;
   import org.apache.commons.lang.SystemUtils;
  +import org.apache.ojb.broker.core.Factories;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.configuration.Configurable;
   import org.apache.ojb.broker.util.configuration.Configuration;
  @@ -57,6 +58,8 @@
   {
       // TODO: Refactoring of the metadata reading/handling?
   
  +    private Factories factories;
  +
       private static Logger log = LoggerFactory.getLogger(RepositoryPersistor.class);
   
       private static final String SER_FILE_SUFFIX = "serialized";
  @@ -64,8 +67,15 @@
   
       private boolean useSerializedRepository = false;
   
  -    public RepositoryPersistor()
  +
  +	public RepositoryPersistor()
  +	{
  +		OjbConfigurator.getInstance().configure(this);
  +	}
  +	
  +    public RepositoryPersistor(Factories factories)
       {
  +    	this.factories = factories;
           OjbConfigurator.getInstance().configure(this);
       }
   
  @@ -301,7 +311,7 @@
           if (DescriptorRepository.class.equals(target))
           {
               // create an empty repository:
  -            DescriptorRepository repository = new DescriptorRepository();
  +            DescriptorRepository repository = new DescriptorRepository(this.factories);
               // create handler for building the repository structure
               ContentHandler handler = new RepositoryXmlHandler(repository);
               // tell parser to use our handler:
  
  
  
  1.39      +1 -0      db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
  
  Index: RepositoryTags.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- RepositoryTags.java	14 Sep 2004 16:17:41 -0000	1.38
  +++ RepositoryTags.java	26 Oct 2004 15:27:40 -0000	1.39
  @@ -159,6 +159,7 @@
           table.put("initialization-method", new Integer(INITIALIZATION_METHOD));
           table.put("factory-class", new Integer(FACTORY_CLASS));
           table.put("factory-method", new Integer(FACTORY_METHOD));
  +        table.put("useObjectFactory", new Integer(USE_OBJECT_FACTORY));
   
           table.put("insert-procedure", new Integer(INSERT_PROCEDURE));
           table.put("update-procedure", new Integer(UPDATE_PROCEDURE));
  
  
  
  1.64      +13 -1     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.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- RepositoryXmlHandler.java	16 Sep 2004 18:34:02 -0000	1.63
  +++ RepositoryXmlHandler.java	26 Oct 2004 15:27:40 -0000	1.64
  @@ -293,6 +293,18 @@
                               m_CurrentCLD.setFactoryMethod(factoryMethod);
                           }
   
  +						/*
  +						 * 
  +						 */
  +						String useObjectfactory = atts.getValue(RepositoryTags.getTagById(USE_OBJECT_FACTORY));
  +						if (isDebug)
  +							logger.debug("     " + RepositoryTags.getTagById(USE_OBJECT_FACTORY) + ": " + useObjectfactory);
  +						if(useObjectfactory != null && "true".equalsIgnoreCase(useObjectfactory))
  +						{
  +							m_CurrentCLD.setUseObjectFactory(true);
  +						}
  +						
  +						 
                           // set refresh attribute
                           String refresh = atts.getValue(RepositoryTags.getTagById(REFRESH));
                           if (isDebug) logger.debug("     " + RepositoryTags.getTagById(REFRESH)
+ ": " + refresh);
  
  
  
  1.15      +7 -1      db-ojb/src/schema/ojbtest-data.dtd
  
  Index: ojbtest-data.dtd
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.dtd,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ojbtest-data.dtd	5 Apr 2004 13:58:59 -0000	1.14
  +++ ojbtest-data.dtd	26 Oct 2004 15:27:40 -0000	1.15
  @@ -51,7 +51,8 @@
       Category*,
       Topic*,
       Area*,
  -    ContentQualifier*
  +    ContentQualifier*,
  +	InitializableObject*
   )>
   <!ATTLIST dataset
       name CDATA #REQUIRED
  @@ -332,4 +333,9 @@
   <!ATTLIST ContentQualifier
       ContentId CDATA #REQUIRED
       QualifierId CDATA #REQUIRED
  +>
  +
  +<!ELEMENT InitializableObject EMPTY>
  +<!ATTLIST InitializableObject
  +	Id CDATA #REQUIRED
   >
  
  
  
  1.16      +3 -0      db-ojb/src/schema/ojbtest-data.xml
  
  Index: ojbtest-data.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-data.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ojbtest-data.xml	5 Apr 2004 13:58:59 -0000	1.15
  +++ ojbtest-data.xml	26 Oct 2004 15:27:40 -0000	1.16
  @@ -192,4 +192,7 @@
       <ContentQualifier ContentId="3" QualifierId="2"/>
       <ContentQualifier ContentId="10" QualifierId="20"/>
       <ContentQualifier ContentId="11" QualifierId="11"/>
  +	
  +	<InitializableObject Id="1"/>
  +	<InitializableObject Id="2"/>
   </dataset>
  
  
  
  1.87      +9 -1      db-ojb/src/schema/ojbtest-schema.xml
  
  Index: ojbtest-schema.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/schema/ojbtest-schema.xml,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- ojbtest-schema.xml	1 Oct 2004 16:49:18 -0000	1.86
  +++ ojbtest-schema.xml	26 Oct 2004 15:27:40 -0000	1.87
  @@ -1468,5 +1468,13 @@
       <column name="D_ATTRIB" type="INTEGER" required="false"/>
     </table>
   
  +	<!-- ************ Object Factory tests * START -->
  +	<table name="INITIALIZABLE_OBJECT">
  +		<column name="ID" primaryKey="true" type="BIGINT"/>
  +	</table>
  +	
  +	<!-- ************ Object Factory tests * END -->
  +	
  +	
   
   </database>
  
  
  
  1.124     +10 -1     db-ojb/src/test/org/apache/ojb/repository_junit.xml
  
  Index: repository_junit.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/repository_junit.xml,v
  retrieving revision 1.123
  retrieving revision 1.124
  diff -u -r1.123 -r1.124
  --- repository_junit.xml	21 Aug 2004 10:54:30 -0000	1.123
  +++ repository_junit.xml	26 Oct 2004 15:27:41 -0000	1.124
  @@ -3627,4 +3627,13 @@
           />
       </class-descriptor>
   
  +	<class-descriptor 
  +		class="org.apache.ojb.broker.InitializableObject" 
  +		table="INITIALIZABLE_OBJECT"
  +		useObjectFactory="true">
  +
  +		<field-descriptor name="id" column="ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/>
  +		
  +	</class-descriptor>
  +
   <!-- Mapping of classes used in junit tests and tutorials ends here -->
  
  
  
  1.55      +1 -0      db-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- AllTests.java	10 Oct 2004 15:16:21 -0000	1.54
  +++ AllTests.java	26 Oct 2004 15:27:41 -0000	1.55
  @@ -103,6 +103,7 @@
           suite.addTestSuite(PersistentFieldTest.class);
           suite.addTestSuite(MultithreadedReadTest.class);
           suite.addTestSuite(MetadataMultithreadedTest.class);
  +        suite.addTestSuite(FactoryTest.class);
   
           return suite;
       }
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/FactoryTest.java
  
  Index: FactoryTest.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.ojb.broker.accesslayer.RowReader;
  import org.apache.ojb.broker.accesslayer.RowReaderDefaultImpl;
  import org.apache.ojb.broker.core.factory.ObjectFactory;
  import org.apache.ojb.broker.core.factory.ObjectFactoryException;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.query.QueryByCriteria;
  import org.apache.ojb.broker.query.QueryByCriteria;
  import org.apache.ojb.junit.PBTestCase;
  import org.apache.xml.serialize.IndentPrinter;
  
  /**
   * @author leandro
   *
   */
  public class FactoryTest 
  	extends PBTestCase
  {
  
  //	public void testObjectCreation()
  //		throws Exception
  //	{
  //		PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker(); 
  //		ClassDescriptor cld = pb.getDescriptorRepository().getDescriptorFor(InitializableObject.class);
  //		RowReader rw = new RowReaderDefaultImpl(cld);
  //		Map row = new HashMap();
  //		row.put("ID",new Integer(1));
  //		InitializableObject obj = (InitializableObject) rw.readObjectFrom(row);
  //		assertEquals(1,obj.id);
  //		assertTrue(obj.initCalled);
  //	}
  
  	public void testDefaultObjectFactory()
  		throws Exception
  	{
  		PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker();
  		Query query = new QueryByCriteria(InitializableObject.class);
  		Collection coll = pb.getCollectionByQuery(query);
  		for (Iterator iter = coll.iterator(); iter.hasNext();)
          {
              InitializableObject obj = (InitializableObject) iter.next();
              assertTrue(obj.initCalled);
          }
  	}
  
  	public void testHandledObjectFactory()
  		throws Exception
  	{
  		ObjectFactory factory = new TestFactory();
  		PersistenceBroker pb = PersistenceBrokerFactory.defaultPersistenceBroker(factory);
  		Query query = new QueryByCriteria(InitializableObject.class);
  		Collection coll = pb.getCollectionByQuery(query);
  		for (Iterator iter = coll.iterator(); iter.hasNext();)
  		{
  			InitializableObject obj = (InitializableObject) iter.next();
  			// ** OBS ** : this assertion fails because the ObjectFactory is not handled to the RowReader
instance
  			assertFalse(obj.initCalled);
  		}
  	}
  
  }
  
  class TestFactory
  	implements ObjectFactory
  {
  
      public Object getInstanceOf(Class clazz) 
      	throws ObjectFactoryException
      {
          return new InitializableObject();
      }
  
      public Object getInstanceOf(String className) 
      	throws ObjectFactoryException
      {
  		try
          {
              Class clazz = Class.forName(className);
              return getInstanceOf(clazz);
          }
          catch (ClassNotFoundException e)
          {
  			throw new ObjectFactoryException("Error creating object",e);
          }
  	}
  }	
  
  
  
  1.1                  db-ojb/src/test/org/apache/ojb/broker/InitializableObject.java
  
  Index: InitializableObject.java
  ===================================================================
  package org.apache.ojb.broker;
  
  import org.apache.ojb.broker.core.factory.lifecycle.Initializable;
  
  /**
   * @author leandro
   *
   */
  public class InitializableObject
  	implements Initializable
  {
  	public boolean initCalled;
  	
  	public int id;
  
      public InitializableObject()
  	{
  		//System.out.println("ServiceableObject created");
  	}
  
      /* (non-Javadoc)
       * @see org.apache.ojb.broker.core.factory.lifecycle.Initializable#initialize()
       */
      public void initialize() 
      	throws Exception
      {
  		initCalled = true;
      }
  
  }
  
  
  
  1.2       +3 -1      db-ojb/src/tools/org/apache/ojb/tools/mapping/reversedb2/actions/ActionNewOJBRepository.java
  
  Index: ActionNewOJBRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/tools/org/apache/ojb/tools/mapping/reversedb2/actions/ActionNewOJBRepository.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ActionNewOJBRepository.java	5 May 2004 16:44:28 -0000	1.1
  +++ ActionNewOJBRepository.java	26 Oct 2004 15:27:41 -0000	1.2
  @@ -1,4 +1,6 @@
   package org.apache.ojb.tools.mapping.reversedb2.actions;
  +import org.apache.ojb.broker.core.Factories;
  +import org.apache.ojb.broker.core.factory.ObjectFactoryDefaultImpl;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.tools.mapping.reversedb2.gui.JIFrmOJBRepository;
   /* Copyright 2002-2004 The Apache Software Foundation
  @@ -40,7 +42,7 @@
                   try
                   {
                       // RepositoryPersistor persistor = new RepositoryPersistor ();
  -                    DescriptorRepository repository = new DescriptorRepository();
  +                    DescriptorRepository repository = new DescriptorRepository(new Factories());
                       JIFrmOJBRepository frm = new JIFrmOJBRepository(repository);
                       containingFrame.getContentPane().add(frm);
                       frm.setVisible(true);
  
  
  

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