HHH-4574 ConnectionProviderFactory.getConnectionProperties() includes extra properties

git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_3@18329 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Strong Liu 2009-12-24 13:47:11 +00:00
parent 87e0a7751e
commit fd9dfd7641
2 changed files with 56 additions and 2 deletions

View File

@ -145,7 +145,7 @@ public final class ConnectionProviderFactory {
* Transform JDBC connection properties.
*
* Passed in the form <tt>hibernate.connection.*</tt> to the
* format accepted by <tt>DriverManager</tt> by triming the leading "<tt>hibernate.connection</tt>".
* format accepted by <tt>DriverManager</tt> by trimming the leading "<tt>hibernate.connection</tt>".
*/
public static Properties getConnectionProperties(Properties properties) {
@ -153,7 +153,7 @@ public final class ConnectionProviderFactory {
Properties result = new Properties();
while ( iter.hasNext() ) {
String prop = (String) iter.next();
if ( prop.indexOf(Environment.CONNECTION_PREFIX) > -1 && !SPECIAL_PROPERTIES.contains(prop) ) {
if ( prop.startsWith(Environment.CONNECTION_PREFIX) && !SPECIAL_PROPERTIES.contains(prop) ) {
result.setProperty(
prop.substring( Environment.CONNECTION_PREFIX.length()+1 ),
properties.getProperty(prop)

View File

@ -0,0 +1,54 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.connection;
import java.util.Properties;
import junit.framework.TestCase;
/**
* Undocumented
*
* @author kbow
*/
public class PropertiesTest extends TestCase {
public void testProperties() throws Exception {
final Properties props = new Properties();
props.put("rpt.1.hibernate.dialect", "org.hibernate.dialect.DerbyDialect");
props.put("rpt.2.hibernate.connection.driver_class", "org.apache.derby.jdbc.ClientDriver");
props.put("rpt.3.hibernate.connection.url", "jdbc:derby://localhost:1527/db/reports.db");
props.put("rpt.4.hibernate.connection.username", "sa");
props.put("rpt.5.hibernate.connection.password_enc", "76f271db3661fd50082e68d4b953fbee");
props.put("rpt.6.hibernate.connection.password_enc", "76f271db3661fd50082e68d4b953fbee");
props.put("hibernate.connection.create", "true");
final Properties outputProps = ConnectionProviderFactory.getConnectionProperties(props);
assertEquals(1, outputProps.size());
assertEquals("true", outputProps.get("create"));
}
}