[hibernate-commits] Hibernate SVN: r18504 - in annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations: entity and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sun Jan 10 20:20:16 EST 2010


Author: stliu
Date: 2010-01-10 20:20:16 -0500 (Sun, 10 Jan 2010)
New Revision: 18504

Added:
   annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/SystemLevelPropertyUtil.java
Modified:
   annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/entity/PropertyDefaultMappingsTest.java
   annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
Log:
JBPAPP-3379  default hibernate.jdbc.use_streams_for_binary cause two test cases fail on db2

Added: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/SystemLevelPropertyUtil.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/SystemLevelPropertyUtil.java	                        (rev 0)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/SystemLevelPropertyUtil.java	2010-01-11 01:20:16 UTC (rev 18504)
@@ -0,0 +1,118 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.test.annotations;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.hibernate.util.ConfigHelper;
+
+/**
+ * This util class is for setting some system-level properties It is used before
+ * Environment be loaded into jvm.
+ * 
+ * @author Strong Liu <stliu at redhat.com>
+ */
+public class SystemLevelPropertyUtil {
+	/**
+	 * find is the property <tt>prop</tt> is in System properties or in
+	 * hibernate.properties.
+	 * 
+	 * 
+	 * @param prop
+	 * @return
+	 */
+	public static boolean isPropertyExist( Object prop ) {
+		if ( System.getProperties().containsKey( prop ) ) {
+			return true;
+		}
+		return getHibernateProperties().containsKey( prop );
+	}
+	
+	/**
+	 * get the property <tt>prop</tt> value 
+	 * @param prop
+	 * @return
+	 */
+	public static Object getSystemLevelProperty( Object prop ) {
+		if ( !isPropertyExist( prop ) ) {
+			return null;
+		}
+		if ( System.getProperties().containsKey( prop ) ) {
+			return System.getProperties().get( prop );
+		}
+		if ( getHibernateProperties().containsKey( prop ) ) {
+			return getHibernateProperties().get( prop );
+		}
+		return null;
+	}
+
+	private static Properties getHibernateProperties() {
+		Properties properties = new Properties();
+		try {
+			properties.load( findAsResource( "hibernate.properties" )
+					.openStream() );
+		} catch (IOException e) {
+
+		}
+		return properties;
+	}
+
+	/**
+	 * Try to locate a local URL representing the incoming path. This method
+	 * <b>only</b> attempts to locate this URL as a java system resource.
+	 * 
+	 * @param path
+	 *            The path representing the config location.
+	 * @return An appropriate URL or null.
+	 */
+	private static final URL findAsResource( final String path ) {
+		URL url = null;
+
+		// First, try to locate this resource through the current
+		// context classloader.
+		ClassLoader contextClassLoader = Thread.currentThread()
+				.getContextClassLoader();
+		if ( contextClassLoader != null ) {
+			url = contextClassLoader.getResource( path );
+		}
+		if ( url != null )
+			return url;
+
+		// Next, try to locate this resource through this class's classloader
+		url = ConfigHelper.class.getClassLoader().getResource( path );
+		if ( url != null )
+			return url;
+
+		// Next, try to locate this resource through the system classloader
+		url = ClassLoader.getSystemClassLoader().getResource( path );
+
+		// Anywhere else we should look?
+		return url;
+	}
+}

Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/entity/PropertyDefaultMappingsTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/entity/PropertyDefaultMappingsTest.java	2010-01-10 23:41:10 UTC (rev 18503)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/entity/PropertyDefaultMappingsTest.java	2010-01-11 01:20:16 UTC (rev 18504)
@@ -3,7 +3,12 @@
 
 import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.dialect.DB2Dialect;
+import org.hibernate.test.annotations.SystemLevelPropertyUtil;
 import org.hibernate.test.annotations.TestCase;
+import org.hibernate.util.ConfigHelper;
 
 /**
  * @author Emmanuel Bernard
@@ -11,7 +16,17 @@
 public class PropertyDefaultMappingsTest extends TestCase {
 	public PropertyDefaultMappingsTest(String x) {
 		super( x );
+
 	}
+	//https://jira.jboss.org/jira/browse/JBPAPP-3379
+	@Override
+	protected void setUp() throws Exception {
+		String dialect = (String)SystemLevelPropertyUtil.getSystemLevelProperty( "hibernate.dialect" );
+		if(dialect.equals( "org.hibernate.dialect.DB2Dialect" )){
+			System.setProperty( "hibernate.jdbc.use_streams_for_binary" , "false" );
+		}
+		super.setUp();
+	}
 
 	public void testSerializableObject() throws Exception {
 		Session s;

Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java	2010-01-10 23:41:10 UTC (rev 18503)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java	2010-01-11 01:20:16 UTC (rev 18504)
@@ -3,12 +3,25 @@
 
 import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.test.annotations.SystemLevelPropertyUtil;
 import org.hibernate.test.annotations.TestCase;
 
 /**
  * @author Emmanuel Bernard
  */
 public class LobTest extends TestCase {
+	
+	
+	//https://jira.jboss.org/jira/browse/JBPAPP-3379
+	@Override
+	protected void setUp() throws Exception {
+		String dialect = (String)SystemLevelPropertyUtil.getSystemLevelProperty( "hibernate.dialect" );
+		if(dialect.equals( "org.hibernate.dialect.DB2Dialect" )){
+			System.setProperty( "hibernate.jdbc.use_streams_for_binary" , "false" );
+		}
+		super.setUp();
+	}
+
 	public void testSerializableToBlob() throws Exception {
 		Book book = new Book();
 		Editor editor = new Editor();



More information about the hibernate-commits mailing list