antonio     2004/02/21 20:44:18

  Added:       src/blocks/ojb/conf ojb-pb.xroles ojb-pb.xconf
               src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components
                        PBFactory.java PBFactoryImpl.java
  Log:
  Adding PersistenBrokerFactory support.
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/ojb/conf/ojb-pb.xroles
  
  Index: ojb-pb.xroles
  ===================================================================
  <?xml version="1.0"?>
  <xroles xpath="/role-list" unless="[EMAIL 
PROTECTED]'org.apache.cocoon.ojb.broker.components.PBFactory']">
  
    <role name="org.apache.cocoon.ojb.broker.components.PBFactory" 
shorthand="ojb-pb" 
default-class="org.apache.cocoon.ojb.broker.components.PBFactoryImpl"/>
  </xroles>
  
  
  
  1.1                  cocoon-2.1/src/blocks/ojb/conf/ojb-pb.xconf
  
  Index: ojb-pb.xconf
  ===================================================================
  <?xml version="1.0"?>
  
  <xconf xpath="/cocoon" unless="ojb-pb">
    <!-- PersistenceBroker Interface -->
    <ojb-pb logger="core.ojb-pb"/>
  </xconf>
  
  
  
  1.1                  
cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactory.java
  
  Index: PBFactory.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.ojb.broker.components;
  
  import org.apache.avalon.framework.component.Component;
  import org.apache.ojb.broker.PBFactoryException;
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBroker;
  
  /**
   * Interface of the Persistence Broker Factory.
   * It is used to get the Persistence Manager to interact with Persistence 
Broker using OJB.
   * The PersistenceBroker API provides the lowest level access to OJB's 
persistence engine.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Antonio Gallardo</a>
   * @version CVS $Id: PBFactory.java,v 1.1 2004/02/22 04:44:18 antonio Exp $
  */
  public interface PBFactory extends Component
  {
      /**
       * The <code>ROLE</code>
       */
      String ROLE = PBFactory.class.getName();
        
      /**
       * Get the default Persistence BrokerManager.
       * @return a PersistenceBroker Object
       * @throws PBFactoryException - If the operation failed.
       */
      public PersistenceBroker defaultPersistenceBroker()
          throws PBFactoryException;
      
      /**
       * Create a new PersistenceBroker with the given parameters.
       * Using this method we can access diferents datasources.
       * 
       * @param jcdAlias - name of the jdbc connection descriptor to be used.
       * @param user - Datasource user's name
       * @param password - Datasource user's password
       * @return a PersistenceBroker Object
       * @throws PBFactoryException - If the operation failed.
       */
      public PersistenceBroker createPersistenceBroker(String jcdAlias,
              String user, String password) throws PBFactoryException;
      
      /**
       * Create a new PersistenceBroker with the given parameters.
       * @param key - A immutable key that identify the PB instance in pools
       * @return a PersistenceBroker Object
       * @throws PBFactoryException - If the operation failed.
       */
      public PersistenceBroker createPersistenceBroker(PBKey key)
          throws PBFactoryException;
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/ojb/java/org/apache/cocoon/ojb/broker/components/PBFactoryImpl.java
  
  Index: PBFactoryImpl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.ojb.broker.components;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.ojb.components.AbstractOjbImpl;
  import org.apache.ojb.broker.PBFactoryException;
  import org.apache.ojb.broker.PBKey;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  
  /**
  * Implementation of the JdoPMF. Create one PMF and store it for future use
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Antonio Gallardo</a>
   * @version CVS $Id: PBFactoryImpl.java,v 1.1 2004/02/22 04:44:18 antonio Exp 
$
  */
  public class PBFactoryImpl extends AbstractOjbImpl implements PBFactory, 
Configurable, Initializable,
  Disposable, ThreadSafe
  {
      /* (non-Javadoc)
       * @see 
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
       */
      public void configure(Configuration myconf) throws ConfigurationException
      {
                if (this.getLogger().isDebugEnabled())
                        this.getLogger().debug("OJB-JDO: configuration");
      }
  
      /* (non-Javadoc)
       * @see org.apache.avalon.framework.activity.Disposable#dispose()
       */
      public void dispose()
      {
          super.dispose();
                if (this.getLogger().isDebugEnabled())
                        this.getLogger().debug("OJB-PB: Disposed OK!");
      }
  
        /* (non-Javadoc)
         * @see org.apache.avalon.framework.activity.Initializable#initialize()
         */
        public void initialize() throws Exception
        {
          super.initialize();
                try
                {
                        if (this.getLogger().isDebugEnabled()) {
                                this.getLogger().debug("OJB-PB: Started OK!");
              }
                }
                catch (Throwable t)
                {
                        if (this.getLogger().isFatalErrorEnabled()) {
                                this.getLogger().fatalError("OJB-PB: Started 
failed: Cannot create a Persistence Broker Factory.",t);
                        }
                }
        }
  
      /* (non-Javadoc)
       * @see 
org.apache.cocoon.ojb.broker.components.PBFactory#defaultPersistenceBroker()
       */
      public PersistenceBroker defaultPersistenceBroker() throws 
PBFactoryException {
          return PersistenceBrokerFactory.defaultPersistenceBroker();
      }
  
      /* (non-Javadoc)
       * @see 
org.apache.cocoon.ojb.broker.components.PBFactory#createPersistenceBroker(java.lang.String,
 java.lang.String, java.lang.String)
       */
      public PersistenceBroker createPersistenceBroker(String jcdAlias, String 
user, String password) throws PBFactoryException {
          return PersistenceBrokerFactory.createPersistenceBroker(jcdAlias, 
user, password);
      }
  
      /* (non-Javadoc)
       * @see 
org.apache.cocoon.ojb.broker.components.PBFactory#createPersistenceBroker(org.apache.ojb.broker.PBKey)
       */
      public PersistenceBroker createPersistenceBroker(PBKey key) throws 
PBFactoryException {
          return PersistenceBrokerFactory.createPersistenceBroker(key);
      }
  }
  
  
  

Reply via email to