db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql OjbStoreManager.java OjbStoreConnector.java OjbFieldManager.java OjbStoreFatalInternalException.java OjbStorePMF.java OjbExtent.java
Date Tue, 24 Dec 2002 12:06:01 GMT
thma        2002/12/24 04:06:01

  Added:       src/jdori/org/apache/ojb/jdori/sql OjbStoreManager.java
                        OjbStoreConnector.java OjbFieldManager.java
                        OjbStoreFatalInternalException.java
                        OjbStorePMF.java OjbExtent.java
  Log:
  clean up
  
  Revision  Changes    Path
  1.1                  jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbStoreManager.java
  
  Index: OjbStoreManager.java
  ===================================================================
  package org.apache.ojb.jdori.sql;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.lang.reflect.Field;
  import java.util.BitSet;
  import java.util.Iterator;
  
  import javax.jdo.Extent;
  import javax.jdo.JDOFatalInternalException;
  import javax.jdo.JDOUserException;
  import javax.jdo.spi.PersistenceCapable;
  
  import org.apache.ojb.broker.Identity;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  
  import com.sun.jdori.Connector;
  import com.sun.jdori.FieldManager;
  import com.sun.jdori.PersistenceManagerInternal;
  import com.sun.jdori.StateManagerInternal;
  import com.sun.jdori.StoreManager;
  import com.sun.jdori.common.model.jdo.RuntimeJDOModelFactoryImpl;
  import com.sun.jdori.common.query.BasicQueryResult;
  import com.sun.jdori.model.jdo.JDOClass;
  import com.sun.jdori.model.jdo.JDOModel;
  import com.sun.jdori.model.jdo.JDOModelException;
  import com.sun.jdori.query.QueryResult;
  import com.sun.jdori.query.QueryResultHelper;
  
  
  /**
   * StoreManager represents the datastore to the rest of the JDO components.
   * It provides the means to write and read instances, to get the extent of
   * classes, and to get the object id for a persistence capable object.
   *
   * @author Thomas Mahler
   */
  class OjbStoreManager implements StoreManager
  {
      private final OjbStorePMF pmf;
      private final OjbStoreConnector connector;
  
      private boolean optimistic;
  
      /** the logger used for debugging*/
      private Logger logger = LoggerFactory.getLogger("JDO");
      
      OjbStoreManager(OjbStorePMF pmf)
      {
          this.pmf = pmf;
          this.connector = new OjbStoreConnector(pmf);
      }
  
  
      /**
       * @see com.sun.jdori.StoreManager#getConnector
       */
      public Connector getConnector()
      {
          return connector;
      }
  
      /**
       * @see com.sun.jdori.StoreManager#getConnector(String userid,
       * String password)
       */
      public Connector getConnector(String userid, String password)
      {
          throw new JDOUserException("Not implemented"); 
      }
  
      /**
      * @see com.sun.jdori.StoreManager#insert(BitSet, BitSet, StateManagerInternal)
      */
      public synchronized int insert(
          BitSet loadedFields,
          BitSet dirtyFields,
          StateManagerInternal sm)
      {
  
          try
          {
              logger.debug("OjbStoreManager.insert");
              PersistenceBroker broker = connector.getBroker();
              Object instance = sm.getObject();
              broker.store(instance, ObjectModificationDefaultImpl.INSERT);
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "insert", ex); 
          }
          dirtyFields.xor(dirtyFields);
          return StateManagerInternal.FLUSHED_COMPLETE;
      }
  
      /**
      * @see com.sun.jdori.StoreManager#update(BitSet, BitSet, StateManagerInternal)
      */
      public synchronized int update(
          BitSet loadedFields,
          BitSet dirtyFields,
          StateManagerInternal sm)
      {
  
          try
          {
          	logger.debug("OjbStoreManager.update");
              PersistenceBroker broker = connector.getBroker();
              fetch(sm, null);
              Object instance = sm.getObject();
              broker.store(instance, ObjectModificationDefaultImpl.UPDATE);
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "update", ex); 
          }
          dirtyFields.xor(dirtyFields);
          return StateManagerInternal.FLUSHED_COMPLETE;
      }
  
      /**
       * @see com.sun.jdori.StoreManager#verifyFields(BitSet, BitSet, StateManagerInternal)
       */
      public synchronized int verifyFields(
          BitSet ignoredFields,
          BitSet fieldsToVerify,
          StateManagerInternal sm)
      {
          fieldsToVerify.xor(fieldsToVerify);
          return StateManagerInternal.FLUSHED_COMPLETE;
      }
  
  
      /**
       * @see com.sun.jdori.StoreManager#delete(BitSet, BitSet, StateManagerInternal)
       */
      public synchronized int delete(
          BitSet loadedFields,
          BitSet dirtyFields,
          StateManagerInternal sm)
      {
      	Identity oid = (Identity)sm.getInternalObjectId();
      	logger.debug("OjbStoreManager.delete(" + oid + ")");
          try
          {
          	fetch(sm,null);
              connector.getBroker().delete(sm.getObject());
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "delete", ex); 
          }
          dirtyFields.xor(dirtyFields);
          return StateManagerInternal.FLUSHED_COMPLETE;
      }
  
      /**
      * @see com.sun.jdori.StoreManager#fetch
      */
      public synchronized void fetch(StateManagerInternal sm, int fieldNums[])
      {
          PersistenceBroker broker = connector.getBroker();
          try
          {
              Identity oid = (Identity) sm.getInternalObjectId();
              if (oid == null)
              {
                  Object instance = sm.getObject();
                  oid = new Identity(instance);
              }
              broker.removeFromCache(oid);
              PersistenceCapable pc = (PersistenceCapable) broker.getObjectByIdentity(oid);
  
              JDOClass jdoClass = this.getJDOClass(pc.getClass());
              if (fieldNums == null)
              {
                  fieldNums = jdoClass.getManagedFieldNumbers();
              }
  
              FieldManager fm = new OjbFieldManager(pc, broker);
              sm.replaceFields(fieldNums, fm);
  
              getConnector().flush();
          }
  
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "fetch", ex); 
          }
      }
  
      JDOClass getJDOClass(Class c)
      {
          JDOClass rc = null;
          try
          {
              ClassLoader cl = c.getClassLoader();
              JDOModel m = RuntimeJDOModelFactoryImpl.getInstance().getJDOModel(cl);
              rc = m.getJDOClass(c.getName());
          }
          catch (JDOModelException ex)
          {
              throw new JDOFatalInternalException("Not a JDO class: " + c.getName()); 
          }
          return rc;
      }
  
      /**
       * @see com.sun.jdori.StoreManager#getExtent
       */
      public synchronized Extent getExtent(
          Class pcClass,
          boolean subclasses,
          PersistenceManagerInternal pm)
      {
          PersistenceBroker broker = connector.getBroker();
          return new OjbExtent(pcClass, broker);
      }
  
      /**
       * @see com.sun.jdori.StoreManager#createObjectId
       */
      public synchronized Object createObjectId(
          StateManagerInternal sm,
          PersistenceManagerInternal pm)
      {
          PersistenceCapable obj = sm.getObject();
          Identity oid = new Identity(obj);
          return oid;
      }
  
      /**
       * @see com.sun.jdori.StoreManager#createObjectId
       */
      public synchronized Object createInternalObjectId(
          StateManagerInternal sm,
          PersistenceCapable pc,
          Object oid,
          Class cls,
          PersistenceManagerInternal pm)
      {
          return new Identity(pc);
      }
  
      /**
       * @see com.sun.jdori.StoreManager#getExternalObjectId(Object oid,
       * PersistenceCapable pc)
       */
      public synchronized Object getExternalObjectId(Object objectId, PersistenceCapable pc)
      {
          return new Identity(pc);
      }
  
      /**
       * @see com.sun.jdori.StoreManager#copyKeyFieldsFromObjectId
       */
      public void copyKeyFieldsFromObjectId(StateManagerInternal sm, Class pcClass)
      {
          new Identity(sm.getObject());
      }
  
      /**
       * @see com.sun.jdori.StoreManager#hasActualPCClass
       */
      public boolean hasActualPCClass(Object objectId)
      {
          boolean rc = true;
          return rc;
      }
  
      /**
       * @see com.sun.jdori.StoreManager#getInternalObjectId
       */
      public synchronized Object getInternalObjectId(Object objectId, PersistenceManagerInternal pm)
      {
          return objectId;
      }
  
      /**
       * @see com.sun.jdori.StoreManager#getPCClassForOid
       */
      public synchronized Class getPCClassForOid(Object objectId, PersistenceManagerInternal pm)
      {
          return ((Identity) objectId).getObjectsClass();
      }
  
      /**
       * @see com.sun.jdori.StoreManager#newObjectIdInstance
       */
      public Object newObjectIdInstance(Class pcClass, String str)
      {
          return Identity.fromByteArray(str.getBytes());
      }
  
      /**
       * @see com.sun.jdori.StoreManager#flush
       */
      public void flush(Iterator it, PersistenceManagerInternal pm)
      {
          this.optimistic = pm.currentTransaction().getOptimistic();
          boolean err = false;
  
          while (it.hasNext())
          {
              StateManagerInternal sm = (StateManagerInternal) it.next();
              logger.debug("OjbStoreManager.flush: " + sm.getInternalObjectId() + ", " + getLCState(sm));
              sm.preStore();
              sm.replaceSCOFields();
              sm.flush(this);
              if (!sm.isFlushed())
              {
                  err = true;
                  break;
              }
          }
  
          logger.debug("OjbStoreManager.flush: end, err=" + err);
  
          if (err)
          {
              throw new JDOFatalInternalException("Error in flush");
          }
      }
  
  	/**
  	 * @return the LifeCycleState of a StateManager instance
  	 */
  	protected Object getLCState(StateManagerInternal sm)
  	{
  		// unfortunately the LifeCycleState classes ar package private.
  		// so we have to do some dirty reflection hack to access them
          try
          {
              Field myLC = sm.getClass().getDeclaredField("myLC");
              myLC.setAccessible(true);
              return myLC.get(sm);
          }
          catch (NoSuchFieldException e)
          {
          	return e;
          }
          catch (IllegalAccessException e)
          {
          	return e;
          }	
  	}
  
      /**
       * @see com.sun.jdori.StoreManager#newObjectIdInstance
       */
      public QueryResult newQueryResult(QueryResultHelper queryResultHelper)
      {
          return new BasicQueryResult(queryResultHelper);
      }
  
  }
  
  
  
  1.1                  jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbStoreConnector.java
  
  Index: OjbStoreConnector.java
  ===================================================================
  package org.apache.ojb.jdori.sql;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.jdo.JDODataStoreException;
  
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.broker.util.logging.Logger;
  import org.apache.ojb.broker.util.logging.LoggerFactory;
  
  import com.sun.jdori.Connector;
  
  /**
   * OjbStoreConnector represents a OJB PB connection
   *
   * @author Thomas Mahler
   */
  class OjbStoreConnector implements Connector
  {
      /** 
       * rollback only flag
  	 */
      private boolean rollbackOnlyFlag = false;
  
      /**
       * Datasource to which this Connector writes its Message.
       */
      private final OjbStorePMF pmf;
  
      /**
       * broker represents the backend store.
       */
      PersistenceBroker broker = null;
  
      /**
       * if true underlying connection can be released
       */
      private boolean connectionReadyForRelease = true;
  
      /**
       * the logger used for debugging
       */
      private Logger logger = LoggerFactory.getLogger("JDO");
  
      OjbStoreConnector(OjbStorePMF pmf)
      {
          this.pmf = pmf;
      }
  
  
      /**
       * @see com.sun.jdori.Connector#begin
       */
      public void begin(boolean optimistic)
      {
          assertNotRollbackOnly();
  
          connectionReadyForRelease = false;
          logger.debug("OjbStoreConnector.begin: connectionReadyForRelease=" + connectionReadyForRelease);
  
          // obtain a fresh broker and open a tx on it 
          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
          broker.beginTransaction();
      }
  
      /**
       * @see com.sun.jdori.Connector#beforeCompletion
       */
      public void beforeCompletion()
      {
          assertNotRollbackOnly();
          // Nothing to do.
      }
  
      /**
       * @see com.sun.jdori.Connector#flush
       */
      public void flush()
      {
          assertNotRollbackOnly();
          logger.debug("OjbStoreConnector.flush: " + "connectionReadyForRelease=" + connectionReadyForRelease);
          // thma: noop?
      }
  
      /**
       * @see com.sun.jdori.Connector#commit
       */
      public synchronized void commit()
      {
          assertNotRollbackOnly();
  
          try
          {
              logger.debug("OjbStoreConnector.commit"); 
              broker.commitTransaction();
              broker.close();
              broker = null;
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "commit", ex); 
          }
          finally
          {
              connectionReadyForRelease = true;
          }
      }
  
      /**
       * @see com.sun.jdori.Connector#rollback
       */
      public synchronized void rollback()
      {
          logger.debug("OjbStoreConnector.rollback");
  
          if (!rollbackOnlyFlag)
          {
              try
              {
                  broker.abortTransaction();
                  broker.close();
                  broker = null;
              }
              catch (Exception ex)
              {
                  throw new OjbStoreFatalInternalException(getClass(), "rollback", ex); 
              }
              finally
              {
                  connectionReadyForRelease = true;
              }
          }
      }
  
      /**
       * @see com.sun.jdori.Connector#setRollbackOnly
       */
      public void setRollbackOnly()
      {
          rollbackOnlyFlag = true;
      }
  
      /**
       * @see com.sun.jdori.Connector#getRollbackOnly
       */
      public boolean getRollbackOnly()
      {
          return rollbackOnlyFlag;
      }
  
      private void assertNotRollbackOnly()
      {
          if (rollbackOnlyFlag)
          {
              throw new JDODataStoreException("Rollback Only !");
          }
      }
  
      /**
       * Returns the broker.
       * @return PersistenceBroker
       */
      public PersistenceBroker getBroker()
      {
          return broker;
      }
  
      /**
       * Sets the broker.
       * @param broker The broker to set
       */
      public void setBroker(PersistenceBroker broker)
      {
          this.broker = broker;
      }
  
  }
  
  
  
  1.1                  jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbFieldManager.java
  
  Index: OjbFieldManager.java
  ===================================================================
  package org.apache.ojb.jdori.sql;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.jdo.JDOFatalInternalException;
  import javax.jdo.spi.PersistenceCapable;
  
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  
  import com.sun.jdori.FieldManager;
  import com.sun.jdori.common.model.jdo.RuntimeJDOModelFactoryImpl;
  import com.sun.jdori.model.jdo.JDOClass;
  import com.sun.jdori.model.jdo.JDOField;
  import com.sun.jdori.model.jdo.JDOModel;
  import com.sun.jdori.model.jdo.JDOModelException;
  
  /**
   * @author Thomas Mahler
   */
  public class OjbFieldManager implements FieldManager
  {
  
      private PersistenceCapable pc;
  
      private PersistenceBroker broker;
  
      /**
       * Constructor for OjbFieldManager.
       */
      public OjbFieldManager()
      {
          super();
      }
  
      /**
       * Constructor for OjbFieldManager.
       */
      public OjbFieldManager(PersistenceCapable pPc)
      {
          pc = pPc;
      }
  
      /**
       * Constructor for OjbFieldManager.
       */
      public OjbFieldManager(PersistenceCapable pPc, PersistenceBroker pBroker)
      {
          pc = pPc;
          broker = pBroker;
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeBooleanField(int, boolean)
       */
      public void storeBooleanField(int fieldNum, boolean value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchBooleanField(int)
       */
      public boolean fetchBooleanField(int fieldNum)
      {
          Boolean value = (Boolean) getValue(fieldNum);
          return value.booleanValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeCharField(int, char)
       */
      public void storeCharField(int fieldNum, char value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchCharField(int)
       */
      public char fetchCharField(int fieldNum)
      {
          Character value = (Character) getValue(fieldNum);
          return value.charValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeByteField(int, byte)
       */
      public void storeByteField(int fieldNum, byte value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchByteField(int)
       */
      public byte fetchByteField(int fieldNum)
      {
          Byte value = (Byte) getValue(fieldNum);
          return value.byteValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeShortField(int, short)
       */
      public void storeShortField(int fieldNum, short value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchShortField(int)
       */
      public short fetchShortField(int fieldNum)
      {
          Short value = (Short) getValue(fieldNum);
          return value.shortValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeIntField(int, int)
       */
      public void storeIntField(int fieldNum, int value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchIntField(int)
       */
      public int fetchIntField(int fieldNum)
      {
          Integer value = (Integer) getValue(fieldNum);
          return value.intValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeLongField(int, long)
       */
      public void storeLongField(int fieldNum, long value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchLongField(int)
       */
      public long fetchLongField(int fieldNum)
      {
          Long value = (Long) getValue(fieldNum);
          return value.longValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeFloatField(int, float)
       */
      public void storeFloatField(int fieldNum, float value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchFloatField(int)
       */
      public float fetchFloatField(int fieldNum)
      {
          Float value = (Float) getValue(fieldNum);
          return value.floatValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeDoubleField(int, double)
       */
      public void storeDoubleField(int fieldNum, double value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchDoubleField(int)
       */
      public double fetchDoubleField(int fieldNum)
      {
          Double value = (Double) getValue(fieldNum);
          return value.doubleValue();
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeStringField(int, String)
       */
      public void storeStringField(int fieldNum, String value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchStringField(int)
       */
      public String fetchStringField(int fieldNum)
      {
          String value = (String) getValue(fieldNum);
          return value;
      }
  
      /**
       * @see com.sun.jdori.FieldManager#storeObjectField(int, Object)
       */
      public void storeObjectField(int fieldNum, Object value)
      {
      }
  
      /**
       * @see com.sun.jdori.FieldManager#fetchObjectField(int)
       */
      public Object fetchObjectField(int fieldNum)
      {
          Object value = getValue(fieldNum);
          return value;
      }
  
      /**
       * Returns the pc.
       * @return PersistenceCapable
       */
      public PersistenceCapable getPc()
      {
          return pc;
      }
  
      /**
       * Sets the pc.
       * @param pc The pc to set
       */
      public void setPc(PersistenceCapable pc)
      {
          this.pc = pc;
      }
  
      JDOClass getJDOClass(Class c)
      {
          JDOClass rc = null;
          try
          {
              ClassLoader cl = c.getClassLoader();
              JDOModel m = RuntimeJDOModelFactoryImpl.getInstance().getJDOModel(cl);
              rc = m.getJDOClass(c.getName());
          }
          catch (JDOModelException ex)
          {
              throw new JDOFatalInternalException("Not a JDO class: " + c.getName());
          }
          return rc;
      }
  
      String getAttributeName(int fieldNum)
      {
          JDOClass jdoClass = getJDOClass(pc.getClass());
          JDOField jdoField = jdoClass.getField(fieldNum);
          String attributeName = jdoField.getName();
          return attributeName;
      }
  
      Object getValue(int fieldNum)
      {
          String attributeName = getAttributeName(fieldNum);
  
          ClassDescriptor cld = broker.getClassDescriptor(pc.getClass());
          FieldDescriptor fld = cld.getFieldDescriptorByName(attributeName);
          Object value = fld.getPersistentField().get(pc);
          return value;
      }
  
  }
  
  
  
  1.1                  jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbStoreFatalInternalException.java
  
  Index: OjbStoreFatalInternalException.java
  ===================================================================
  package org.apache.ojb.jdori.sql;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import javax.jdo.JDOFatalInternalException;
  
  /**
  * This is exception indicates internal errors
  *
  * @author Thomas Mahler
  */
  public class OjbStoreFatalInternalException extends JDOFatalInternalException
  {
      /**
       * @param className class in which the exception is thrown.
       * @param methodName method throwing the exception.
       */
      OjbStoreFatalInternalException(Class clazz, String methodName, String msg)
      {
          super(clazz.getName() + "." + methodName + ": " + msg);
      }
  
      /**
       * @param className class in which the exception is thrown.
       * @param methodName method throwing the exception.
       * @param nested nested Exception
       */
      OjbStoreFatalInternalException(Class clazz, String methodName, Exception nested)
      {
          super(clazz.getName() + "." + methodName, new Exception[] { nested });
      }
  
      /**
       * @param className class in which the exception is thrown.
       * @param methodName method throwing the exception.
       * @param msg the error message
       * @param nested nested Exception
       */
      OjbStoreFatalInternalException(Class clazz, String methodName, String msg, Exception nested)
      {
          super(clazz.getName() + "." + methodName + ": " + msg, new Exception[] { nested });
      }
  }
  
  
  
  1.1                  jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbStorePMF.java
  
  Index: OjbStorePMF.java
  ===================================================================
  package org.apache.ojb.jdori.sql;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.HashMap;
  import java.util.Properties;
  
  import javax.jdo.JDOException;
  import javax.jdo.PersistenceManager;
  import javax.jdo.spi.PersistenceCapable;
  
  import org.apache.ojb.broker.Identity;
  
  import com.sun.jdori.StoreManager;
  import com.sun.jdori.TranscriberFactory;
  import com.sun.jdori.common.PersistenceManagerFactoryImpl;
  import com.sun.jdori.common.PersistenceManagerImpl;
  
  /**
   * PMF for OjbStore implementation
   * @author thma
   *
   */
  public class OjbStorePMF extends PersistenceManagerFactoryImpl
  {
      private final HashMap storeManagers = new HashMap();
  
      private static HashMap trackedClassesMap = getTrackedClasses();
  
  
      /**
       * Constructor for PMF.
       */
      public OjbStorePMF()
      {
          super();
      }
  
      /**
       * Constructor for PMF.
       * @param URL
       * @param userName
       * @param password
       * @param driverName
       */
      public OjbStorePMF(String URL, String userName, String password, String driverName)
      {
          super(URL, userName, password, driverName);
      }
  
      private static HashMap getTrackedClasses()
      {
          HashMap classMap = new HashMap();
          // java.util.Date and java.sql classes:
          classMap.put(java.util.Date.class, com.sun.jdori.common.sco.Date.class);
          classMap.put(com.sun.jdori.common.sco.Date.class, com.sun.jdori.common.sco.Date.class);
          classMap.put(java.sql.Date.class, com.sun.jdori.common.sco.SqlDate.class);
          classMap.put(
              com.sun.jdori.common.sco.SqlDate.class,
              com.sun.jdori.common.sco.SqlDate.class);
          classMap.put(java.sql.Time.class, com.sun.jdori.common.sco.SqlTime.class);
          classMap.put(
              com.sun.jdori.common.sco.SqlTime.class,
              com.sun.jdori.common.sco.SqlTime.class);
          classMap.put(java.sql.Timestamp.class, com.sun.jdori.common.sco.SqlTimestamp.class);
          classMap.put(
              com.sun.jdori.common.sco.SqlTimestamp.class,
              com.sun.jdori.common.sco.SqlTimestamp.class);
  
          // java.util.Set
          classMap.put(java.util.HashSet.class, com.sun.jdori.common.sco.HashSet.class);
          classMap.put(java.util.AbstractSet.class, com.sun.jdori.common.sco.HashSet.class);
          classMap.put(java.util.Set.class, com.sun.jdori.common.sco.HashSet.class);
          classMap.put(
              com.sun.jdori.common.sco.HashSet.class,
              com.sun.jdori.common.sco.HashSet.class);
  
          // java.util.List
          classMap.put(java.util.ArrayList.class, com.sun.jdori.common.sco.ArrayList.class);
          classMap.put(java.util.AbstractList.class, com.sun.jdori.common.sco.ArrayList.class);
          classMap.put(java.util.List.class, com.sun.jdori.common.sco.ArrayList.class);
          classMap.put(java.util.AbstractCollection.class, com.sun.jdori.common.sco.ArrayList.class);
          classMap.put(java.util.Collection.class, com.sun.jdori.common.sco.ArrayList.class);
          classMap.put(
              com.sun.jdori.common.sco.ArrayList.class,
              com.sun.jdori.common.sco.ArrayList.class);
  
          // java.util.Vector
          classMap.put(java.util.Vector.class, com.sun.jdori.common.sco.Vector.class);
          classMap.put(com.sun.jdori.common.sco.Vector.class, com.sun.jdori.common.sco.Vector.class);
  
          // java.util.SortedSet
          classMap.put(java.util.TreeSet.class, com.sun.jdori.common.sco.TreeSet.class);
          classMap.put(java.util.SortedSet.class, com.sun.jdori.common.sco.TreeSet.class);
          classMap.put(
              com.sun.jdori.common.sco.TreeSet.class,
              com.sun.jdori.common.sco.TreeSet.class);
  
          // java.util.LinkedList
          classMap.put(java.util.LinkedList.class, com.sun.jdori.common.sco.LinkedList.class);
          classMap.put(
              java.util.AbstractSequentialList.class,
              com.sun.jdori.common.sco.LinkedList.class);
          classMap.put(
              com.sun.jdori.common.sco.LinkedList.class,
              com.sun.jdori.common.sco.LinkedList.class);
  
          // java.util.Map
          classMap.put(java.util.Map.class, com.sun.jdori.common.sco.HashMap.class);
          classMap.put(java.util.AbstractMap.class, com.sun.jdori.common.sco.HashMap.class);
          classMap.put(java.util.HashMap.class, com.sun.jdori.common.sco.HashMap.class);
          classMap.put(
              com.sun.jdori.common.sco.HashMap.class,
              com.sun.jdori.common.sco.HashMap.class);
  
          // java.util.Hashtable
          classMap.put(java.util.Hashtable.class, com.sun.jdori.common.sco.Hashtable.class);
          classMap.put(
              com.sun.jdori.common.sco.Hashtable.class,
              com.sun.jdori.common.sco.Hashtable.class);
  
          // java.util.SortedMap
          classMap.put(java.util.SortedMap.class, com.sun.jdori.common.sco.TreeMap.class);
          classMap.put(java.util.TreeMap.class, com.sun.jdori.common.sco.TreeMap.class);
          classMap.put(
              com.sun.jdori.common.sco.TreeMap.class,
              com.sun.jdori.common.sco.TreeMap.class);
  
          return classMap;
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#getOptionArray()
       */
      protected String[] getOptionArray()
      {
      	String[] optionsA = {""};
          return optionsA;
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#createPersistenceManager(String, String)
       */
      protected PersistenceManager createPersistenceManager(String userid, String password)
      {
  
          PersistenceManager result = null;
          try
          {
              result = new PersistenceManagerImpl(this, userid, password);
          }
          catch (JDOException ex)
          {
              throw ex;
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(
                  getClass(),
                  "createPersistenceManager(userid, password)",
                  ex);
          }
          return result;
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#setPMFClassProperty(Properties)
       */
      protected void setPMFClassProperty(Properties props)
      {
          props.setProperty("javax.jdo.PersistenceManagerFactoryClass", this.getClass().getName());
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#encrypt(String)
       */
      protected String encrypt(String s)
      {
          return s;
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#decrypt(String)
       */
      protected String decrypt(String s)
      {
          return s;
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#setCFProperties(Properties)
       */
      protected void setCFProperties(Properties p)
      {
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#getCFFromProperties(Properties)
       */
      protected void getCFFromProperties(Properties p)
      {
      }
  
      /**
       * @see com.sun.jdori.common.PersistenceManagerFactoryImpl#isConnectionFactoryConfigured()
       */
      protected boolean isConnectionFactoryConfigured()
      {
          return true;
      }
  
      /**
       * @see com.sun.jdori.PersistenceManagerFactoryInternal#getTranscriberFactory()
       */
      public TranscriberFactory getTranscriberFactory()
      {
          return null;
      }
  
      /**
       * @see com.sun.jdori.PersistenceManagerFactoryInternal#getObjectIdClass(Class)
       */
      public Class getObjectIdClass(Class cls)
      {
          Class result = null;
          if (null != cls && PersistenceCapable.class.isAssignableFrom(cls))
          {
              result = Identity.class;
          }
          return result;
      }
  
      /**
       * @see com.sun.jdori.PersistenceManagerFactoryInternal#getStoreManager(PersistenceManager)
       */
      public StoreManager getStoreManager(PersistenceManager pm)
      {
          OjbStoreManager result = null;
          try
          {
              result = (OjbStoreManager) storeManagers.get(pm);
              if (null == result)
              {
                  result = new OjbStoreManager(this);
                  storeManagers.put(pm, result);
              }
          }
          catch (JDOException ex)
          {
              throw ex;
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "getStoreManager", ex);
          }
          return result;
      }
  
      /**
       * @see com.sun.jdori.PersistenceManagerFactoryInternal#releaseStoreManager(PersistenceManager)
       */
      public void releaseStoreManager(PersistenceManager pm)
      {
          try
          {
              storeManagers.remove(pm);
          }
          catch (JDOException ex)
          {
              throw ex;
          }
          catch (Exception ex)
          {
              throw new OjbStoreFatalInternalException(getClass(), "releaseStoreManager", ex);
          }
      }
  
      /**
       * @see com.sun.jdori.PersistenceManagerFactoryInternal#getTrackedClass(Class)
       */
      public Class getTrackedClass(Class type)
      {
          return (Class) trackedClassesMap.get(type);
      }
  
  }
  
  
  
  1.1                  jakarta-ojb/src/jdori/org/apache/ojb/jdori/sql/OjbExtent.java
  
  Index: OjbExtent.java
  ===================================================================
  package org.apache.ojb.jdori.sql;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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" and "Apache Software Foundation" and
   *    "Apache ObjectRelationalBridge" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache ObjectRelationalBridge", 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import java.util.Iterator;
  
  import javax.jdo.PersistenceManager;
  
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.accesslayer.RsIterator;
  import org.apache.ojb.broker.metadata.ClassDescriptor;
  import org.apache.ojb.broker.query.Criteria;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.query.QueryFactory;
  
  /**
   * @see javax.jdo.Extent
   * @author Thomas Mahler
   */
  public class OjbExtent implements javax.jdo.Extent
  {
      private RsIterator iterator;
      private Class clazz;
      private PersistenceBroker broker;
  
      /**
       * Constructor for OjbExtent.
       */
      public OjbExtent(Class pClazz, PersistenceBroker pBroker)
      {
          clazz = pClazz;
          Criteria selectExtent = null;
          Query q = QueryFactory.newQuery(clazz, selectExtent);
          broker = pBroker;
          iterator = (RsIterator) broker.getIteratorByQuery(q);
      }
  
      /**
       * @see javax.jdo.Extent#iterator()
       */
      public Iterator iterator()
      {
          return iterator;
      }
  
      /**
       * @see javax.jdo.Extent#hasSubclasses()
       */
      public boolean hasSubclasses()
      {
          ClassDescriptor cld = broker.getClassDescriptor(clazz);
          return cld.isExtent();
      }
  
      /**
       * @see javax.jdo.Extent#getCandidateClass()
       */
      public Class getCandidateClass()
      {
          return clazz;
      }
  
      /**
       * @see javax.jdo.Extent#getPersistenceManager()
       */
      public PersistenceManager getPersistenceManager()
      {
          return null;
      }
  
      /**
       * @see javax.jdo.Extent#closeAll()
       */
      public void closeAll()
      {
          iterator.releaseDbResources();
      }
  
      /**
       * @see javax.jdo.Extent#close(Iterator)
       */
      public void close(Iterator it)
      {
          iterator.releaseDbResources();
      }
  
  }
  
  
  

Mime
View raw message