From fb121412b6ab16d660b68aa1cb9185328394ad62 Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Thu, 24 Dec 2009 13:26:38 +0000 Subject: [PATCH] HHH-4574 ConnectionProviderFactory.getConnectionProperties() includes extra properties git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18328 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../connection/ConnectionProviderFactory.java | 4 +- .../hibernate/connection/PropertiesTest.java | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/org/hibernate/connection/PropertiesTest.java diff --git a/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java b/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java index 1395e7f3f9..4428f8ff4e 100644 --- a/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java +++ b/core/src/main/java/org/hibernate/connection/ConnectionProviderFactory.java @@ -145,7 +145,7 @@ public final class ConnectionProviderFactory { * Transform JDBC connection properties. * * Passed in the form hibernate.connection.* to the - * format accepted by DriverManager by triming the leading "hibernate.connection". + * format accepted by DriverManager by trimming the leading "hibernate.connection". */ 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) diff --git a/core/src/test/java/org/hibernate/connection/PropertiesTest.java b/core/src/test/java/org/hibernate/connection/PropertiesTest.java new file mode 100644 index 0000000000..60a2759c0b --- /dev/null +++ b/core/src/test/java/org/hibernate/connection/PropertiesTest.java @@ -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")); + } + +}