You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2005/04/10 01:08:45 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata ConnectionRepository.java MetadataManager.java

arminw      2005/04/09 16:08:45

  Modified:    src/java/org/apache/ojb/broker/metadata Tag: OJB_1_0_RELEASE
                        ConnectionRepository.java MetadataManager.java
  Log:
  fix OJB-17, 'default connection' settings now detected automatic by OJB, instead of an error OJB log a warning when someone try to change the 'default connection' at runtime
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.15.2.2  +4 -2      db-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionRepository.java
  
  Index: ConnectionRepository.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/ConnectionRepository.java,v
  retrieving revision 1.15.2.1
  retrieving revision 1.15.2.2
  diff -u -r1.15.2.1 -r1.15.2.2
  --- ConnectionRepository.java	7 Jan 2005 23:00:34 -0000	1.15.2.1
  +++ ConnectionRepository.java	9 Apr 2005 23:08:45 -0000	1.15.2.2
  @@ -173,7 +173,8 @@
           if ("default".equals(jcdAlias))
           {
               jcd.setDefaultConnection(true);
  -            MetadataManager.getInstance().setDefaultPBKey(new PBKey(jcd.getJcdAlias(), jcd.getUserName(), jcd.getPassWord()));
  +            // arminw: MM will search for the default key
  +            // MetadataManager.getInstance().setDefaultPBKey(jcd.getPBKey());
           }
   
           addDescriptor(jcd);
  @@ -210,7 +211,8 @@
           if ("default".equals(jcdAlias))
           {
               jcd.setDefaultConnection(true);
  -            MetadataManager.getInstance().setDefaultPBKey(new PBKey(jcd.getJcdAlias(), jcd.getUserName(), jcd.getPassWord()));
  +            // arminw: MM will search for the default key
  +            // MetadataManager.getInstance().setDefaultPBKey(jcd.getPBKey());
           }
           addDescriptor(jcd);
           return jcd;
  
  
  
  1.19.2.4  +42 -13    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.19.2.3
  retrieving revision 1.19.2.4
  diff -u -r1.19.2.3 -r1.19.2.4
  --- MetadataManager.java	7 Apr 2005 10:10:54 -0000	1.19.2.3
  +++ MetadataManager.java	9 Apr 2005 23:08:45 -0000	1.19.2.4
  @@ -161,7 +161,6 @@
           {
               throw new MetadataException("Can't read repository file '" + repository + "'", ex);
           }
  -        this.defaultPBKey = buildDefaultKey();
       }
   
       /**
  @@ -541,27 +540,42 @@
       }
   
       /**
  -     * Return the default {@link PBKey}.
  +     * Return the default {@link PBKey} used in convinience method
  +     * {@link org.apache.ojb.broker.PersistenceBrokerFactory#defaultPersistenceBroker}.
  +     * <br/>
  +     * If in {@link JdbcConnectionDescriptor} the
  +     * {@link JdbcConnectionDescriptor#isDefaultConnection() default connection}
  +     * is enabled, OJB will detect the default {@link org.apache.ojb.broker.PBKey} by itself.
  +     *
        * @see #setDefaultPBKey
        */
       public PBKey getDefaultPBKey()
       {
  +        if(defaultPBKey == null)
  +        {
  +            defaultPBKey = buildDefaultKey();
  +        }
           return defaultPBKey;
       }
   
       /**
  -     * Set the {@link PBKey} used for convinience method
  +     * Set the {@link PBKey} used in convinience method
        * {@link org.apache.ojb.broker.PersistenceBrokerFactory#defaultPersistenceBroker}.
        * <br/>
  -     * Note: Only allowed to set once by declare a default connection
  -     * in configuration files, or using this method.
  +     * It's only allowed to use one {@link JdbcConnectionDescriptor} with enabled
  +     * {@link JdbcConnectionDescriptor#isDefaultConnection() default connection}. In this case
  +     * OJB will automatically set the default key.
  +     * <br/>
  +     * Note: It's recommended to set this key only once and not to change at runtime
  +     * of OJB to avoid side-effects.
  +     * If set more then one time a warning will be logged.
        * @throws MetadataException if key was set more than one time
        */
       public void setDefaultPBKey(PBKey defaultPBKey)
       {
           if(this.defaultPBKey != null)
           {
  -            throw new MetadataException("Default key is already set. Current key is " + this.defaultPBKey);
  +            log.warn("The used default PBKey change. Current key is " + this.defaultPBKey + ", new key will be " + defaultPBKey);
           }
           this.defaultPBKey = defaultPBKey;
           log.info("Set default PBKey for convenience broker creation: " + defaultPBKey);
  @@ -569,6 +583,7 @@
   
       /**
        * Try to build an default PBKey for convenience PB create method.
  +     *
        * @return PBKey or <code>null</code> if default key was not declared in
        * metadata
        */
  @@ -576,18 +591,32 @@
       {
           List descriptors = connectionRepository().getAllDescriptor();
           JdbcConnectionDescriptor descriptor;
  +        PBKey result = null;
           for (Iterator iterator = descriptors.iterator(); iterator.hasNext();)
           {
               descriptor = (JdbcConnectionDescriptor) iterator.next();
               if (descriptor.isDefaultConnection())
               {
  -                return new PBKey(descriptor.getJcdAlias(), descriptor.getUserName(), descriptor.getPassWord());
  +                if(result != null)
  +                {
  +                    log.error("Found additional connection descriptor with enabled 'default-connection' "
  +                            + descriptor.getPBKey() + ". This is NOT allowed. Will use the first found descriptor " + result
  +                            + " as default connection");
  +                }
  +                else
  +                {
  +                    result = descriptor.getPBKey();
  +                }
               }
           }
  -        log.info("No 'default-connection' attribute set in jdbc-connection-descriptors," +
  -                " thus it's currently not possible to use 'defaultPersistenceBroker()' " +
  -                " convenience method to lookup PersistenceBroker instances. But it's possible"+
  -                " to enable this at runtime using 'setDefaultKey' method.");
  -        return null;
  +
  +        if(result == null)
  +        {
  +            log.info("No 'default-connection' attribute set in jdbc-connection-descriptors," +
  +                    " thus it's currently not possible to use 'defaultPersistenceBroker()' " +
  +                    " convenience method to lookup PersistenceBroker instances. But it's possible"+
  +                    " to enable this at runtime using 'setDefaultKey' method.");
  +        }
  +        return result;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org