Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 92313 invoked from network); 9 Apr 2005 23:08:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Apr 2005 23:08:48 -0000 Received: (qmail 14689 invoked by uid 500); 9 Apr 2005 23:08:47 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 14503 invoked by uid 500); 9 Apr 2005 23:08:47 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 14487 invoked by uid 500); 9 Apr 2005 23:08:47 -0000 Received: (qmail 14484 invoked by uid 99); 9 Apr 2005 23:08:47 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sat, 09 Apr 2005 16:08:46 -0700 Received: (qmail 92279 invoked by uid 1510); 9 Apr 2005 23:08:45 -0000 Date: 9 Apr 2005 23:08:45 -0000 Message-ID: <20050409230845.92278.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata ConnectionRepository.java MetadataManager.java X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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}. + *
+ * 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}. *
- * 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. + *
+ * 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 null 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