db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/java/org/apache/ojb/broker/ta PersistenceBrokerFactoryDefaultImpl.java
Date Sat, 25 Jan 2003 09:35:51 GMT
arminw      2003/01/25 01:35:50

  Modified:    src/java/org/apache/ojb/broker/singlevm
                        DelegatingPersistenceBroker.java
                        PersistenceBrokerImpl.java
               src/java/org/apache/ojb/broker/ta
                        PersistenceBrokerFactoryDefaultImpl.java
  Log:
  repair #ifdef entry
  add check for default PBKey
  add state check for delegatingPB
  
  Revision  Changes    Path
  1.8       +57 -92    jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/DelegatingPersistenceBroker.java
  
  Index: DelegatingPersistenceBroker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/DelegatingPersistenceBroker.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DelegatingPersistenceBroker.java	15 Jan 2003 10:43:29 -0000	1.7
  +++ DelegatingPersistenceBroker.java	25 Jan 2003 09:35:49 -0000	1.8
  @@ -42,6 +42,16 @@
       }
   
       /**
  +     * All delegated method use this method to
  +     * get the wrapped broker.
  +     */
  +    private PersistenceBroker getBroker()
  +    {
  +        if(broker != null) return broker;
  +        else throw new IllegalStateException("The delegate PersistenceBroker is closed");
  +    }
  +
  +    /**
        * Returns only the wrapped
        * {@link org.apache.ojb.broker.PersistenceBroker} instance
        */
  @@ -50,6 +60,11 @@
           return this.broker;
       }
   
  +    public void setDelegate(PersistenceBroker broker)
  +    {
  +        this.broker = broker;
  +    }
  +
       /**
        * If my underlying {@link org.apache.ojb.broker.PersistenceBroker}
        * is not a {@link DelegatingPersistenceBroker}, returns it,
  @@ -81,266 +96,216 @@
   
       public boolean isClosed()
       {
  -        return ((PBState) broker).isClosed();
  +        return ((PBState) getBroker()).isClosed();
       }
   
       public void setClosed(boolean closed)
       {
  -        ((PBState) broker).setClosed(closed);
  +        ((PBState) getBroker()).setClosed(closed);
       }
   
       public void beginTransaction()
               throws TransactionInProgressException, TransactionAbortedException
       {
  -        broker.beginTransaction();
  +        getBroker().beginTransaction();
       }
   
       public void commitTransaction()
               throws TransactionNotInProgressException, TransactionAbortedException
       {
  -        broker.commitTransaction();
  +        getBroker().commitTransaction();
       }
   
       public void abortTransaction() throws TransactionNotInProgressException
       {
  -        broker.abortTransaction();
  +        getBroker().abortTransaction();
       }
   
       public boolean isInTransaction() throws PersistenceBrokerException
       {
  -        return broker.isInTransaction();
  +        return getBroker().isInTransaction();
       }
   
       public boolean close()
       {
  -        return broker.close();
  +        return getBroker().close();
       }
   
       public SqlGenerator serviceSqlGenerator()
       {
  -        return broker.serviceSqlGenerator();
  +        return getBroker().serviceSqlGenerator();
       }
   
       public JdbcAccess serviceJdbcAccess()
       {
  -        return broker.serviceJdbcAccess();
  +        return getBroker().serviceJdbcAccess();
       }
   
       public void delete(Object obj) throws PersistenceBrokerException
       {
  -        broker.delete(obj);
  +        getBroker().delete(obj);
       }
   
       public void store(Object obj) throws PersistenceBrokerException
       {
  -        broker.store(obj);
  +        getBroker().store(obj);
       }
   
       public void store(Object obj,
                         ObjectModification modification) throws PersistenceBrokerException
       {
  -        broker.store(obj, modification);
  +        getBroker().store(obj, modification);
       }
   
       public PBKey getPBKey()
       {
  -        return broker.getPBKey();
  +        return getBroker().getPBKey();
       }
   
       public void removeFromCache(Object obj) throws PersistenceBrokerException
       {
  -        broker.removeFromCache(obj);
  +        getBroker().removeFromCache(obj);
       }
   
       public void clearCache() throws PersistenceBrokerException
       {
  -        broker.clearCache();
  +        getBroker().clearCache();
       }
   
       public void invalidate(Identity oid) throws PersistenceBrokerException
       {
  -        broker.invalidate(oid);
  +        getBroker().invalidate(oid);
       }
   
       public DescriptorRepository getDescriptorRepository()
       {
  -        return broker.getDescriptorRepository();
  +        return getBroker().getDescriptorRepository();
       }
   
       public void removeAllListeners() throws PersistenceBrokerException
       {
  -        broker.removeAllListeners();
  +        getBroker().removeAllListeners();
       }
   
       public void removeListener(PersistenceBrokerListener listener) throws PersistenceBrokerException
       {
  -        broker.removeListener(listener);
  +        getBroker().removeListener(listener);
       }
   
       public void addListener(PersistenceBrokerListener listener) throws PersistenceBrokerException
       {
  -        broker.addListener(listener);
  +        getBroker().addListener(listener);
       }
   
       public void retrieveReference(Object pInstance, String pAttributeName) throws PersistenceBrokerException
       {
  -        broker.retrieveReference(pInstance, pAttributeName);
  +        getBroker().retrieveReference(pInstance, pAttributeName);
       }
   
       public void retrieveAllReferences(Object pInstance) throws PersistenceBrokerException
       {
  -        broker.retrieveAllReferences(pInstance);
  +        getBroker().retrieveAllReferences(pInstance);
       }
   
       public ConnectionManagerIF serviceConnectionManager()
       {
  -        return broker.serviceConnectionManager();
  +        return getBroker().serviceConnectionManager();
       }
   
       public StatementManagerIF serviceStatementManager()
       {
  -        return broker.serviceStatementManager();
  +        return getBroker().serviceStatementManager();
       }
   
       public SequenceManager serviceSequenceManager()
       {
  -        return broker.serviceSequenceManager();
  +        return getBroker().serviceSequenceManager();
       }
   
       public BrokerHelper serviceBrokerHelper()
       {
  -        return broker.serviceBrokerHelper();
  +        return getBroker().serviceBrokerHelper();
       }
   
       public void fireBrokerEvent(Object instance, int eventId)
       {
  -        broker.fireBrokerEvent(instance, eventId);
  +        getBroker().fireBrokerEvent(instance, eventId);
       }
   
       public Class getExtentClass(Class clazz) throws PersistenceBrokerException
       {
  -        return broker.getExtentClass(clazz);
  +        return getBroker().getExtentClass(clazz);
       }
   
       public Class getTopLevelClass(Class clazz) throws PersistenceBrokerException
       {
  -        return broker.getTopLevelClass(clazz);
  +        return getBroker().getTopLevelClass(clazz);
       }
   
       public boolean hasClassDescriptor(Class clazz)
       {
  -        return broker.hasClassDescriptor(clazz);
  +        return getBroker().hasClassDescriptor(clazz);
       }
   
       public ClassDescriptor getClassDescriptor(Class clazz) throws PersistenceBrokerException
       {
  -        return broker.getClassDescriptor(clazz);
  +        return getBroker().getClassDescriptor(clazz);
       }
   
       public Enumeration getPKEnumerationByQuery(Class primaryKeyClass,
                                                  Query query) throws PersistenceBrokerException
       {
  -        return broker.getPKEnumerationByQuery(primaryKeyClass, query);
  +        return getBroker().getPKEnumerationByQuery(primaryKeyClass, query);
       }
   
       public Object getObjectByQuery(Query query) throws PersistenceBrokerException
       {
  -        return broker.getObjectByQuery(query);
  +        return getBroker().getObjectByQuery(query);
       }
   
       public Object getObjectByIdentity(Identity id) throws PersistenceBrokerException
       {
  -        return broker.getObjectByIdentity(id);
  +        return getBroker().getObjectByIdentity(id);
       }
   
       public Iterator getReportQueryIteratorByQuery(Query query) throws PersistenceBrokerException
       {
  -        return broker.getReportQueryIteratorByQuery(query);
  +        return getBroker().getReportQueryIteratorByQuery(query);
       }
   
       public Iterator getIteratorByQuery(Query query) throws PersistenceBrokerException
       {
  -        return broker.getIteratorByQuery(query);
  +        return getBroker().getIteratorByQuery(query);
       }
   
       public ManageableCollection getCollectionByQuery(Class collectionClass, Query query)
               throws PersistenceBrokerException
       {
  -        return broker.getCollectionByQuery(collectionClass, query);
  +        return getBroker().getCollectionByQuery(collectionClass, query);
       }
   
       public int getCount(Query query) throws PersistenceBrokerException
       {
  -        return broker.getCount(query);
  +        return getBroker().getCount(query);
       }
   
       public Collection getCollectionByQuery(Query query) throws PersistenceBrokerException
       {
  -        return broker.getCollectionByQuery(query);
  +        return getBroker().getCollectionByQuery(query);
       }
   
       public void configure(Configuration pConfig) throws ConfigurationException
       {
  -        broker.configure(pConfig);
  +        getBroker().configure(pConfig);
       }
   
       public org.odbms.Query query()
       {
  -        return broker.query();
  +        return getBroker().query();
       }
   
       public void deleteByQuery(Query query) throws PersistenceBrokerException
       {
  -        broker.deleteByQuery(query);
  +        getBroker().deleteByQuery(query);
       }
  -
  -//    public Object getUniqueObject(Class extent, String attribute) throws PersistenceBrokerException
  -//    {
  -//        ClassDescriptor cld = broker.getClassDescriptor(extent);
  -//        FieldDescriptor fld = cld.getFieldDescriptorByName(attribute);
  -//        return broker.getUniqueObject(fld);
  -//    }
  -//
  -//    public String getUniqueString(Class extent, String attribute) throws PersistenceBrokerException
  -//    {
  -//        ClassDescriptor cld = broker.getClassDescriptor(extent);
  -//        FieldDescriptor fld = cld.getFieldDescriptorByName(attribute);
  -//        return broker.getUniqueString(fld);
  -//    }
  -//
  -//    public long getUniqueLong(Class extent, String attribute) throws PersistenceBrokerException
  -//    {
  -//        ClassDescriptor cld = broker.getClassDescriptor(extent);
  -//        FieldDescriptor fld = cld.getFieldDescriptorByName(attribute);
  -//        return broker.getUniqueLong(fld);
  -//    }
  -//
  -//    public int getUniqueId(Class extent, String attribute) throws PersistenceBrokerException
  -//    {
  -//        ClassDescriptor cld = broker.getClassDescriptor(extent);
  -//        FieldDescriptor fld = cld.getFieldDescriptorByName(attribute);
  -//        return broker.getUniqueId(fld);
  -//    }
  -//
  -//
  -//    public int getUniqueId(FieldDescriptor field) throws PersistenceBrokerException
  -//    {
  -//        return broker.getUniqueId(field);
  -//    }
  -//
  -//    public long getUniqueLong(FieldDescriptor field) throws PersistenceBrokerException
  -//    {
  -//        return broker.getUniqueLong(field);
  -//    }
  -//
  -//    public String getUniqueString(FieldDescriptor field) throws PersistenceBrokerException
  -//    {
  -//        return broker.getUniqueString(field);
  -//    }
  -//
  -//    public Object getUniqueObject(FieldDescriptor field) throws PersistenceBrokerException
  -//    {
  -//        return broker.getUniqueObject(field);
  -//    }
  -
   }
  
  
  
  1.117     +4 -3      jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java
  
  Index: PersistenceBrokerImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/singlevm/PersistenceBrokerImpl.java,v
  retrieving revision 1.116
  retrieving revision 1.117
  diff -u -r1.116 -r1.117
  --- PersistenceBrokerImpl.java	24 Jan 2003 22:42:54 -0000	1.116
  +++ PersistenceBrokerImpl.java	25 Jan 2003 09:35:49 -0000	1.117
  @@ -55,7 +55,6 @@
    */
   
   import java.lang.reflect.Array;
  -import java.lang.reflect.Proxy;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Enumeration;
  @@ -115,6 +114,8 @@
   import org.apache.ojb.broker.util.sequence.SequenceManager;
   import org.apache.ojb.broker.util.sequence.SequenceManagerException;
   import org.apache.ojb.broker.util.sequence.SequenceManagerFactory;
  +//#ifdef JDK13
  +import java.lang.reflect.Proxy;
   //#else
   /*
   import com.develop.java.lang.reflect.Proxy;
  @@ -1560,7 +1561,7 @@
       {
           RsIteratorFactory factory = RsIteratorFactoryImpl.getInstance();
   
  -        return getRsIteratorFromQuery(query, cld, factory);       
  +        return getRsIteratorFromQuery(query, cld, factory);
       }
   
       /**
  
  
  
  1.34      +20 -3     jakarta-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryDefaultImpl.java
  
  Index: PersistenceBrokerFactoryDefaultImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/ta/PersistenceBrokerFactoryDefaultImpl.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- PersistenceBrokerFactoryDefaultImpl.java	15 Jan 2003 10:43:30 -0000	1.33
  +++ PersistenceBrokerFactoryDefaultImpl.java	25 Jan 2003 09:35:50 -0000	1.34
  @@ -123,6 +123,12 @@
   
           this.defaultPBKey = key;
           log.info("Set default PBKey: "+key);
  +        /*
  +        TODO
  +        should we change the default-connection entry
  +        in the jdbcConnectionDescriptor with default-connection=true
  +        when key change?
  +        */
       }
   
       /**
  @@ -257,6 +263,7 @@
        */
       public PersistenceBroker defaultPersistenceBroker(String user, String password) throws
PBFactoryException
       {
  +        if(getDefaultKey() == null) throw new PBFactoryException("There was no default-PBKey
specified");
           return this.createPersistenceBroker(
                   new PBKey(getDefaultKey().getAlias(), user, password));
       }
  @@ -266,6 +273,7 @@
        */
       public PersistenceBroker defaultPersistenceBroker() throws PBFactoryException
       {
  +        if(getDefaultKey() == null) throw new PBFactoryException("There was no default-PBKey
specified");
           return this.createPersistenceBroker(getDefaultKey());
       }
   
  @@ -382,14 +390,23 @@
           }
   
           /**
  -         * no-op - to use this feature, override
  +         * Check if the given PersistenceBroker instance
  +         * was already in transaction.
  +         * Was called when
            * {@link org.apache.ojb.broker.ta.PBPoolInfo#init}
  -         * method. See documentation jakarta-connons-pool api.
  +         * method does set <code>testOnBorrow(true)</code>.
  +         * (Default was false, thus this method wasn't called)
  +         * See documentation jakarta-connons-pool api.
            */
           public boolean validateObject(Object key, Object obj)
           {
               //here we could validate the PB instance
               //if corresponding configuration properties are set
  +            if(((PersistenceBroker) obj).isInTransaction())
  +            {
  +                log.error("Illegal broker state! This broker instance was already in transaction.");
  +                return false;
  +            }
               return true;
           }
   
  
  
  

Mime
View raw message