[jboss-cvs] JBossAS SVN: r96511 - in branches/Branch_5_x: hibernate-int/src/main/org/jboss/hibernate/deployers/metadata and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 18 17:53:20 EST 2009
Author: bstansberry at jboss.com
Date: 2009-11-18 17:53:20 -0500 (Wed, 18 Nov 2009)
New Revision: 96511
Added:
branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/mocks/
branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HarWithStandardPropertiesUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HibernateConfigurationUnitTestCase.java
branches/Branch_5_x/testsuite/src/resources/hibernate/jbas7411/
Modified:
branches/Branch_5_x/component-matrix/pom.xml
branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/deployers/metadata/SessionFactoryMetaData.java
branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/jmx/Hibernate.java
branches/Branch_5_x/testsuite/.classpath
branches/Branch_5_x/testsuite/build.xml
branches/Branch_5_x/testsuite/imports/sections/hibernate.xml
branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/mocks/MockRegion.java
branches/Branch_5_x/thirdparty/pom.xml
Log:
[JBAS-7411] Port from trunk
Modified: branches/Branch_5_x/component-matrix/pom.xml
===================================================================
--- branches/Branch_5_x/component-matrix/pom.xml 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/component-matrix/pom.xml 2009-11-18 22:53:20 UTC (rev 96511)
@@ -1271,6 +1271,19 @@
<artifactId>hibernate-validator-legacy</artifactId>
<version>${version.org.hibernate.validator}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${version.org.hibernate}</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>javassist</groupId>
Modified: branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/deployers/metadata/SessionFactoryMetaData.java
===================================================================
--- branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/deployers/metadata/SessionFactoryMetaData.java 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/deployers/metadata/SessionFactoryMetaData.java 2009-11-18 22:53:20 UTC (rev 96511)
@@ -81,8 +81,7 @@
builder.addPropertyMetaData("sessionFactoryName", getName());
if (properties != null && properties.isEmpty() == false)
{
- for (BaseNamedElement bne : properties)
- builder.addPropertyMetaData(bne.getName(), bne.getValue());
+ builder.addPropertyMetaData("configurationElements", properties);
}
if (depends != null && depends.isEmpty() == false)
{
Modified: branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/jmx/Hibernate.java
===================================================================
--- branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/jmx/Hibernate.java 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/hibernate-int/src/main/org/jboss/hibernate/jmx/Hibernate.java 2009-11-18 22:53:20 UTC (rev 96511)
@@ -22,9 +22,16 @@
package org.jboss.hibernate.jmx;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Collections;
import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+
import javax.naming.InitialContext;
import javax.naming.NamingException;
@@ -43,6 +50,7 @@
import org.jboss.beans.metadata.api.model.FromContext;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.hibernate.ListenerInjector;
+import org.jboss.hibernate.deployers.metadata.BaseNamedElement;
import org.jboss.kernel.plugins.bootstrap.basic.KernelConstants;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.logging.Logger;
@@ -67,56 +75,78 @@
public static final String SESSION_FACTORY_CREATE = "hibernate.sessionfactory.create";
public static final String SESSION_FACTORY_DESTROY = "hibernate.sessionfactory.destroy";
+
+ // Legacy mbean/MC bean configuration attributes "passed through" to Hibernate
+ private static final String DATASOURCE_NAME = "datasourceName";
+ private static final String DIALECT = "dialect";
+ private static final String DEFAULT_SCHEMA = "defaultSchema";
+ private static final String DEFAULT_CATALOG = "defaultCatalog";
+ private static final String SQL_COMMENTS_ENABLED = "sqlCommentsEnabled";
+ private static final String MAX_FETCH_DEPTH = "maxFetchDepth";
+ private static final String JDBC_FETCH_SIZE = "jdbcFetchSize";
+ private static final String JDBC_BATCH_SIZE = "jdbcBatchSize";
+ private static final String BATCH_VERSIONED_DATA_ENABLED = "batchVersionedDataEnabled";
+ private static final String JDBC_SCROLLABLE_RESULT_SET_ENABLED = "jdbcScrollableResultSetEnabled";
+ private static final String GET_GENERATED_KEYS_ENABLED = "getGeneratedKeysEnabled";
+ private static final String STREAMS_FOR_BINARY_ENABLED = "streamsForBinaryEnabled";
+ private static final String HBM2DDL_AUTO = "hbm2ddlAuto";
+ private static final String QUERY_SUBSTITUTIONS = "querySubstitutions";
+ private static final String SHOW_SQL_ENABLED = "showSqlEnabled";
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String SECOND_LEVEL_CACHE_ENABLED = "secondLevelCacheEnabled";
+ private static final String QUERY_CACHE_ENABLED = "queryCacheEnabled";
+ private static final String CACHE_PROVIDER_CLASS = "cacheProviderClass";
+ private static final String CACHE_REGION_FACTORY_CLASS = "cacheRegionFactoryClass";
+ private static final String DEPLOYED_CACHE_JNDI_NAME = "deployedCacheJndiName";
+ private static final String DEPLOYED_CACHE_MANAGER_JNDI_NAME = "deployedCacheManagerJndiName";
+ private static final String MINIMAL_PUTS_ENABLED = "minimalPutsEnabled";
+ private static final String CACHE_REGION_PREFIX = "cacheRegionPrefix";
+ private static final String STRUCTURED_CACHE_ENTRIES_ENABLED = "useStructuredCacheEntriesEnabled";
+ private static final String STAT_GENERATION_ENABLED = "statGenerationEnabled";
+ private static final String REFLECTION_OPTIMIZATION_ENABLED = "reflectionOptimizationEnabled";
- // Configuration attributes "passed through" to Hibernate
- private String datasourceName;
- private String dialect;
- private String defaultSchema;
- private String defaultCatalog;
- private Boolean sqlCommentsEnabled;
- private Integer maxFetchDepth;
- private Integer jdbcFetchSize;
- private Integer jdbcBatchSize;
- private Boolean batchVersionedDataEnabled;
- private Boolean jdbcScrollableResultSetEnabled;
- private Boolean getGeneratedKeysEnabled;
- private Boolean streamsForBinaryEnabled;
- private String hbm2ddlAuto;
- private String querySubstitutions;
- private Boolean showSqlEnabled;
- private String username;
- private String password;
- private Boolean secondLevelCacheEnabled = Boolean.TRUE;
- private Boolean queryCacheEnabled;
- private String cacheProviderClass;
- private String cacheRegionFactoryClass;
- private String deployedCacheJndiName;
- private String deployedCacheManagerJndiName;
- private Boolean minimalPutsEnabled;
- private String cacheRegionPrefix;
- private Boolean structuredCacheEntriesEnabled;
- private Boolean statGenerationEnabled;
- private Boolean reflectionOptimizationEnabled;
-
// Configuration attributes used by the MBean
private String sessionFactoryName;
+ private static final String SESSION_FACTORY_INTERCEPTOR = "sessionFactoryInterceptor";
private String sessionFactoryInterceptor;
+ private static final String LISTENER_INJECTOR = "listenerInjector";
private String listenerInjector;
+ private static final String HAR_URL = "harUrl";
private URL harUrl;
+ private static final String SCAN_FOR_MAPPINGS_ENABLED = "scanForMappingsEnabled";
private boolean scanForMappingsEnabled = false;
// Internal state
+
+ // Storage of injected configuration values
+ private final Map<String, Object> configurationElements = Collections.synchronizedMap(new HashMap<String, Object>());
+ // The actual properties stored in hibernate Configuration object when SessionFactory was built
+ private Properties sessionFactoryProperties;
private VirtualFile root;
private boolean dirty = false;
private Date runningSince;
private SessionFactory sessionFactory;
private String hibernateStatisticsServiceName;
+
+ // For unit testing
+ private boolean bindInJndi = true;
- // back compatible
+ /**
+ * Backward compatible constructor. Usage requires configuring a
+ * {@link #setHarUrl(URL) HAR URL} before calling {@link #start()}.
+ */
public Hibernate()
{
}
-
+
+ /**
+ * Create a new Hibernate instance.
+ *
+ * @param root root file for the deployment. Cannot be <code>null</code>
+ *
+ * @throws IllegalArgumentException if <code>root</code> is <code>null</code>
+ */
public Hibernate(VirtualFile root)
{
if (root == null)
@@ -124,6 +154,22 @@
this.root = root;
}
+ /**
+ * For use in unit testing
+ *
+ * @param root root of the deployment. May be <code>null</code>, in which
+ * case configuring a {@link #setHarUrl(URL) HAR URL} before
+ * calling {@link #start()} is required
+ * @param bindInJndi <code>true</code> if the SessionFactory should be bound
+ * in JNDI (the default); <code>false</code> if not (to
+ * ease basic unit testing)
+ */
+ protected Hibernate(VirtualFile root, boolean bindInJndi)
+ {
+ this.root = root;
+ this.bindInJndi = bindInJndi;
+ }
+
// Injected from underlying MC
private Object beanName;
private KernelController controller;
@@ -139,6 +185,78 @@
{
this.controller = controller;
}
+
+ public Properties getConfigurationProperties()
+ {
+ Properties props = new Properties();
+ if (sessionFactoryProperties == null)
+ {
+ for (Map.Entry<String, Object> coEntry : configurationElements.entrySet())
+ {
+ props.setProperty(coEntry.getKey(), coEntry.getValue().toString());
+ }
+ }
+ else
+ {
+ return new Properties(sessionFactoryProperties);
+ }
+ return props;
+ }
+
+ public Set<BaseNamedElement> getConfigurationElements()
+ {
+ Set<BaseNamedElement> result = new HashSet<BaseNamedElement>();
+ for (Map.Entry<String, Object> entry : configurationElements.entrySet())
+ {
+ BaseNamedElement element = new BaseNamedElement();
+ element.setName(entry.getKey());
+ element.setValue(entry.getValue());
+ result.add(element);
+ }
+ return result;
+ }
+
+ public void setConfigurationElements(Set<BaseNamedElement> elements)
+ {
+ if (elements != null)
+ {
+ for (BaseNamedElement element : elements)
+ {
+ // Handle special elements that don't get passed through to
+ // Hibernate Configuration object
+ String name = element.getName();
+ Object value = element.getValue();
+ if ( SESSION_FACTORY_INTERCEPTOR.equals(name) && value != null )
+ {
+ setSessionFactoryInterceptor(value.toString());
+ }
+ else if ( LISTENER_INJECTOR.equals(name) && value != null )
+ {
+ setListenerInjector(value.toString());
+ }
+ else if ( HAR_URL.equals(name) && value != null )
+ {
+ try
+ {
+ setHarUrl(new URL(value.toString()));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalArgumentException("Value " + value + " for property " + name + " is not a valid URL", e);
+ }
+ }
+ else if ( SCAN_FOR_MAPPINGS_ENABLED.equals(name) && value != null )
+ {
+ setScanForMappingsEnabled(Boolean.valueOf(value.toString()));
+ }
+ else
+ {
+ // The 99% case -- pass through to Hibernate
+ configurationElements.put(element.getName(), element.getValue());
+ }
+ }
+ }
+ }
/**
* Configure Hibernate and bind the <tt>SessionFactory</tt> to JNDI.
@@ -196,13 +314,15 @@
cfg.setInterceptor( interceptorInstance );
}
+ sessionFactoryProperties = new Properties(cfg.getProperties());
+
// Generate sf....
sessionFactory = cfg.buildSessionFactory();
try
{
// Handle stat-mbean creation/registration....
- if ( sessionFactory.getStatistics() != null && sessionFactory.getStatistics().isStatisticsEnabled() )
+ if ( controller != null && sessionFactory.getStatistics() != null && sessionFactory.getStatistics().isStatisticsEnabled() )
{
String serviceName = beanName.toString();
if( serviceName.indexOf("type=service") != -1 )
@@ -257,6 +377,7 @@
sessionFactory.close();
sessionFactory = null;
runningSince = null;
+ sessionFactoryProperties = null;
if ( hibernateStatisticsServiceName != null )
{
@@ -302,77 +423,101 @@
*/
private void transferSettings(Properties settings)
{
- if ( cacheProviderClass == null )
+ // Establish defaults
+ if ( getCacheProviderClass() == null )
{
- cacheProviderClass = "org.hibernate.cache.HashtableCacheProvider";
+ setCacheProviderClass("org.hibernate.cache.HashtableCacheProvider");
}
-
- log.debug( "Using JDBC batch size : " + jdbcBatchSize );
-
- setUnlessNull( settings, Environment.DATASOURCE, datasourceName );
- setUnlessNull( settings, Environment.DIALECT, dialect );
- setUnlessNull( settings, Environment.CACHE_PROVIDER, cacheProviderClass );
- setUnlessNull( settings, Environment.CACHE_REGION_FACTORY, cacheRegionFactoryClass );
- setUnlessNull( settings, Environment.CACHE_REGION_PREFIX, cacheRegionPrefix );
- setUnlessNull( settings, Environment.USE_MINIMAL_PUTS, minimalPutsEnabled );
- setUnlessNull( settings, Environment.HBM2DDL_AUTO, hbm2ddlAuto );
- setUnlessNull( settings, Environment.DEFAULT_SCHEMA, defaultSchema );
- setUnlessNull( settings, Environment.STATEMENT_BATCH_SIZE, jdbcBatchSize );
- setUnlessNull( settings, Environment.USE_SQL_COMMENTS, sqlCommentsEnabled );
-
- setUnlessNull( settings, Environment.STATEMENT_FETCH_SIZE, jdbcFetchSize );
- setUnlessNull( settings, Environment.USE_SCROLLABLE_RESULTSET, jdbcScrollableResultSetEnabled );
- setUnlessNull( settings, Environment.USE_QUERY_CACHE, queryCacheEnabled );
- setUnlessNull( settings, Environment.USE_STRUCTURED_CACHE, structuredCacheEntriesEnabled );
- setUnlessNull( settings, Environment.QUERY_SUBSTITUTIONS, querySubstitutions );
- setUnlessNull( settings, Environment.MAX_FETCH_DEPTH, maxFetchDepth );
- setUnlessNull( settings, Environment.SHOW_SQL, showSqlEnabled );
- setUnlessNull( settings, Environment.USE_GET_GENERATED_KEYS, getGeneratedKeysEnabled );
- setUnlessNull( settings, Environment.USER, username );
- setUnlessNull( settings, Environment.PASS, password );
- setUnlessNull( settings, Environment.BATCH_VERSIONED_DATA, batchVersionedDataEnabled );
- setUnlessNull( settings, Environment.USE_STREAMS_FOR_BINARY, streamsForBinaryEnabled );
- setUnlessNull( settings, Environment.USE_REFLECTION_OPTIMIZER, reflectionOptimizationEnabled );
- setUnlessNull( settings, Environment.GENERATE_STATISTICS, statGenerationEnabled );
-
- setUnlessNull(
- settings, Environment.TRANSACTION_MANAGER_STRATEGY, JBossTransactionManagerLookup.class.getName()
- );
- setUnlessNull( settings, Environment.TRANSACTION_STRATEGY, JTATransactionFactory.class.getName() );
-
- if (this.deployedCacheJndiName != null)
+ if ( getSecondLevelCacheEnabled() == null)
{
- settings.setProperty(org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager.CACHE_RESOURCE_PROP, this.deployedCacheJndiName);
-
- // Implies shared cache region factory
- if (!settings.containsKey(Environment.CACHE_REGION_FACTORY))
- {
- settings.setProperty(Environment.CACHE_REGION_FACTORY, org.hibernate.cache.jbc.JndiSharedJBossCacheRegionFactory.class.getName());
- }
+ setSecondLevelCacheEnabled(Boolean.TRUE);
}
+ if (configurationElements.get(Environment.TRANSACTION_MANAGER_STRATEGY) == null)
+ {
+ configurationElements.put(Environment.TRANSACTION_MANAGER_STRATEGY, JBossTransactionManagerLookup.class.getName());
+ }
+ if (configurationElements.get(Environment.TRANSACTION_STRATEGY) == null)
+ {
+ configurationElements.put(Environment.TRANSACTION_STRATEGY, JTATransactionFactory.class.getName());
+ }
- if (this.deployedCacheManagerJndiName != null)
+ if ( getDeployedCacheJndiName() != null && getCacheRegionFactoryClass() == null)
{
- settings.setProperty(org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, this.deployedCacheManagerJndiName);
-
+ // Implies shared cache region factory
+ configurationElements.put(Environment.CACHE_REGION_FACTORY, org.hibernate.cache.jbc2.JndiSharedJBossCacheRegionFactory.class.getName());
+ }
+
+ if ( getDeployedCacheManagerJndiName() != null && getCacheRegionFactoryClass() == null)
+ {
// Implies multliplexed cache region factory
- if (!settings.containsKey(Environment.CACHE_REGION_FACTORY))
- {
- settings.setProperty(Environment.CACHE_REGION_FACTORY, org.hibernate.cache.jbc.JndiMultiplexedJBossCacheRegionFactory.class.getName());
- }
+ configurationElements.put(Environment.CACHE_REGION_FACTORY, org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory.class.getName());
}
- settings.setProperty( Environment.FLUSH_BEFORE_COMPLETION, "true" );
- settings.setProperty( Environment.AUTO_CLOSE_SESSION, "true" );
-
+ if (configurationElements.get(Environment.FLUSH_BEFORE_COMPLETION) == null)
+ {
+ configurationElements.put( Environment.FLUSH_BEFORE_COMPLETION, "true" );
+ }
+ if (configurationElements.get(Environment.AUTO_CLOSE_SESSION) == null)
+ {
+ configurationElements.put( Environment.AUTO_CLOSE_SESSION, "true" );
+ }
+
// This is really H3-version-specific:
// in 3.0.3 and later, this should be the ConnectionReleaseMode enum;
// in 3.0.2, this is a true/false setting;
// in 3.0 -> 3.0.1, there is no such setting
//
// so we just set them both :)
- settings.setProperty( "hibernate.connection.agressive_release", "true" );
- settings.setProperty( "hibernate.connection.release_mode", "after_statement" );
+ if (configurationElements.get("hibernate.connection.agressive_release") == null)
+ {
+ configurationElements.put( "hibernate.connection.agressive_release", "true" );
+ }
+ if (configurationElements.get("hibernate.connection.release_mode") == null)
+ {
+ configurationElements.put( "hibernate.connection.release_mode", "after_statement" );
+ }
+
+ log.debug( "Using JDBC batch size : " + getJdbcBatchSize() );
+
+ // Translate any legacy "bean property name" elements
+ Map<String, Object> ourConfig = new HashMap<String, Object>(configurationElements);
+
+ setUnlessNull( settings, Environment.DATASOURCE, ourConfig.remove(DATASOURCE_NAME) );
+ setUnlessNull( settings, Environment.DIALECT, ourConfig.remove(DIALECT) );
+ setUnlessNull( settings, Environment.CACHE_PROVIDER, ourConfig.remove(CACHE_PROVIDER_CLASS) );
+ setUnlessNull( settings, Environment.CACHE_REGION_FACTORY, ourConfig.remove(CACHE_REGION_FACTORY_CLASS) );
+ setUnlessNull( settings, Environment.CACHE_REGION_PREFIX, ourConfig.remove(CACHE_REGION_PREFIX) );
+ setUnlessNull( settings, Environment.USE_MINIMAL_PUTS, ourConfig.remove(MINIMAL_PUTS_ENABLED) );
+ setUnlessNull( settings, Environment.HBM2DDL_AUTO, ourConfig.remove(HBM2DDL_AUTO) );
+ setUnlessNull( settings, Environment.DEFAULT_SCHEMA, ourConfig.remove(DEFAULT_SCHEMA) );
+ setUnlessNull( settings, Environment.STATEMENT_BATCH_SIZE, ourConfig.remove(JDBC_BATCH_SIZE) );
+ setUnlessNull( settings, Environment.USE_SQL_COMMENTS, ourConfig.remove(SQL_COMMENTS_ENABLED) );
+
+ setUnlessNull( settings, Environment.STATEMENT_FETCH_SIZE, ourConfig.remove(JDBC_FETCH_SIZE) );
+ setUnlessNull( settings, Environment.USE_SCROLLABLE_RESULTSET, ourConfig.remove(JDBC_SCROLLABLE_RESULT_SET_ENABLED) );
+ setUnlessNull( settings, Environment.USE_QUERY_CACHE, ourConfig.remove(QUERY_CACHE_ENABLED) );
+ setUnlessNull( settings, Environment.USE_STRUCTURED_CACHE, ourConfig.remove(STRUCTURED_CACHE_ENTRIES_ENABLED) );
+ setUnlessNull( settings, Environment.QUERY_SUBSTITUTIONS, ourConfig.remove(QUERY_SUBSTITUTIONS) );
+ setUnlessNull( settings, Environment.MAX_FETCH_DEPTH, ourConfig.remove(MAX_FETCH_DEPTH) );
+ setUnlessNull( settings, Environment.SHOW_SQL, ourConfig.remove(SHOW_SQL_ENABLED) );
+ setUnlessNull( settings, Environment.USE_GET_GENERATED_KEYS, ourConfig.remove(GET_GENERATED_KEYS_ENABLED) );
+ setUnlessNull( settings, Environment.USER, ourConfig.remove(USERNAME) );
+ setUnlessNull( settings, Environment.PASS, ourConfig.remove(PASSWORD) );
+ setUnlessNull( settings, Environment.BATCH_VERSIONED_DATA, ourConfig.remove(BATCH_VERSIONED_DATA_ENABLED) );
+ setUnlessNull( settings, Environment.USE_STREAMS_FOR_BINARY, ourConfig.remove(STREAMS_FOR_BINARY_ENABLED) );
+ setUnlessNull( settings, Environment.USE_REFLECTION_OPTIMIZER, ourConfig.remove(REFLECTION_OPTIMIZATION_ENABLED) );
+ setUnlessNull( settings, Environment.GENERATE_STATISTICS, ourConfig.remove(STAT_GENERATION_ENABLED) );
+ setUnlessNull( settings, Environment.DEFAULT_CATALOG, ourConfig.remove(DEFAULT_CATALOG) );
+ setUnlessNull( settings, Environment.USE_SECOND_LEVEL_CACHE, ourConfig.remove(SECOND_LEVEL_CACHE_ENABLED) );
+ setUnlessNull( settings, org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, ourConfig.remove(DEPLOYED_CACHE_MANAGER_JNDI_NAME));
+ setUnlessNull( settings, org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager.CACHE_RESOURCE_PROP, ourConfig.remove(DEPLOYED_CACHE_JNDI_NAME));
+
+ // Set any remaining properties; presumably these are standard
+ // Hibernate configuration properties
+ for (Map.Entry<String, Object> entry : ourConfig.entrySet())
+ {
+ setUnlessNull( settings, entry.getKey(), entry.getValue() );
+ }
}
/**
@@ -444,28 +589,31 @@
*/
private void bind() throws HibernateException
{
- InitialContext ctx = null;
- try
+ if (bindInJndi)
{
- ctx = new InitialContext();
- Util.bind( ctx, sessionFactoryName, sessionFactory );
- }
- catch ( NamingException e )
- {
- throw new HibernateException( "Unable to bind SessionFactory into JNDI", e );
- }
- finally
- {
- if ( ctx != null )
+ InitialContext ctx = null;
+ try
{
- try
+ ctx = new InitialContext();
+ Util.bind( ctx, sessionFactoryName, sessionFactory );
+ }
+ catch ( NamingException e )
+ {
+ throw new HibernateException( "Unable to bind SessionFactory into JNDI", e );
+ }
+ finally
+ {
+ if ( ctx != null )
{
- ctx.close();
+ try
+ {
+ ctx.close();
+ }
+ catch ( Throwable ignore )
+ {
+ // ignore
+ }
}
- catch ( Throwable ignore )
- {
- // ignore
- }
}
}
}
@@ -477,28 +625,31 @@
*/
private void unbind() throws HibernateException
{
- InitialContext ctx = null;
- try
+ if (bindInJndi)
{
- ctx = new InitialContext();
- Util.unbind( ctx, sessionFactoryName );
- }
- catch ( NamingException e )
- {
- throw new HibernateException( "Unable to unbind SessionFactory from JNDI", e );
- }
- finally
- {
- if ( ctx != null )
+ InitialContext ctx = null;
+ try
{
- try
+ ctx = new InitialContext();
+ Util.unbind( ctx, sessionFactoryName );
+ }
+ catch ( NamingException e )
+ {
+ throw new HibernateException( "Unable to unbind SessionFactory from JNDI", e );
+ }
+ finally
+ {
+ if ( ctx != null )
{
- ctx.close();
+ try
+ {
+ ctx.close();
+ }
+ catch ( Throwable ignore )
+ {
+ // ignore
+ }
}
- catch ( Throwable ignore )
- {
- // ignore
- }
}
}
}
@@ -578,172 +729,157 @@
public String getDatasourceName()
{
- return datasourceName;
+ return getConfigurationElementAsString(DATASOURCE_NAME, Environment.DATASOURCE);
}
public void setDatasourceName(String datasourceName)
{
- this.datasourceName = datasourceName;
- dirty = true;
+ setConfigurationElement(datasourceName, DATASOURCE_NAME, Environment.DATASOURCE);
}
public String getUsername()
{
- return username;
+ return getConfigurationElementAsString(USERNAME, Environment.USER);
}
public void setUsername(String username)
{
- this.username = username;
- dirty = true;
+ setConfigurationElement( username, USERNAME, Environment.USER );
}
public void setPassword(String password)
{
- this.password = password;
- dirty = true;
+ setConfigurationElement( password, PASSWORD, Environment.PASS );
}
public String getDefaultSchema()
{
- return defaultSchema;
+ return getConfigurationElementAsString(DEFAULT_SCHEMA, Environment.DEFAULT_SCHEMA);
}
public void setDefaultSchema(String defaultSchema)
{
- this.defaultSchema = defaultSchema;
- dirty = true;
+ setConfigurationElement(defaultSchema, DEFAULT_SCHEMA, Environment.DEFAULT_SCHEMA);
}
public String getDefaultCatalog()
{
- return defaultCatalog;
+ return getConfigurationElementAsString(DEFAULT_CATALOG, Environment.DEFAULT_CATALOG);
}
public void setDefaultCatalog(String defaultCatalog)
{
- this.defaultCatalog = defaultCatalog;
+ setConfigurationElement( defaultCatalog, DEFAULT_CATALOG, Environment.DEFAULT_CATALOG);
}
public String getHbm2ddlAuto()
{
- return hbm2ddlAuto;
+ return getConfigurationElementAsString(HBM2DDL_AUTO, Environment.HBM2DDL_AUTO);
}
public void setHbm2ddlAuto(String hbm2ddlAuto)
{
- this.hbm2ddlAuto = hbm2ddlAuto;
- dirty = true;
+ setConfigurationElement(hbm2ddlAuto, HBM2DDL_AUTO, Environment.HBM2DDL_AUTO);
}
public String getDialect()
{
- return dialect;
+ return getConfigurationElementAsString(DIALECT, Environment.DIALECT);
}
public void setDialect(String dialect)
{
- this.dialect = dialect;
- dirty = true;
+ setConfigurationElement(dialect, DIALECT, Environment.DIALECT);
}
public Integer getMaxFetchDepth()
{
- return maxFetchDepth;
+ return getConfigurationElementAsInteger(MAX_FETCH_DEPTH, Environment.MAX_FETCH_DEPTH);
}
public void setMaxFetchDepth(Integer maxFetchDepth)
{
- this.maxFetchDepth = maxFetchDepth;
- dirty = true;
+ setConfigurationElement( maxFetchDepth, MAX_FETCH_DEPTH, Environment.MAX_FETCH_DEPTH);
}
public Integer getJdbcBatchSize()
{
- return jdbcBatchSize;
+ return getConfigurationElementAsInteger(JDBC_BATCH_SIZE, Environment.STATEMENT_BATCH_SIZE );
}
public void setJdbcBatchSize(Integer jdbcBatchSize)
{
- this.jdbcBatchSize = jdbcBatchSize;
- dirty = true;
+ setConfigurationElement( jdbcBatchSize, JDBC_BATCH_SIZE, Environment.STATEMENT_BATCH_SIZE );
}
public Integer getJdbcFetchSize()
{
- return jdbcFetchSize;
+ return getConfigurationElementAsInteger(JDBC_FETCH_SIZE, Environment.STATEMENT_FETCH_SIZE);
}
public void setJdbcFetchSize(Integer jdbcFetchSize)
{
- this.jdbcFetchSize = jdbcFetchSize;
- dirty = true;
+ setConfigurationElement(jdbcFetchSize, JDBC_FETCH_SIZE, Environment.STATEMENT_FETCH_SIZE);
}
public Boolean getJdbcScrollableResultSetEnabled()
{
- return jdbcScrollableResultSetEnabled;
+ return getConfigurationElementAsBoolean(JDBC_SCROLLABLE_RESULT_SET_ENABLED, Environment.USE_SCROLLABLE_RESULTSET);
}
public void setJdbcScrollableResultSetEnabled(Boolean jdbcScrollableResultSetEnabled)
{
- this.jdbcScrollableResultSetEnabled = jdbcScrollableResultSetEnabled;
- dirty = true;
+ setConfigurationElement(jdbcScrollableResultSetEnabled, JDBC_SCROLLABLE_RESULT_SET_ENABLED, Environment.USE_SCROLLABLE_RESULTSET);
}
public Boolean getGetGeneratedKeysEnabled()
{
- return getGeneratedKeysEnabled;
+ return getConfigurationElementAsBoolean(GET_GENERATED_KEYS_ENABLED, Environment.USE_GET_GENERATED_KEYS);
}
public void setGetGeneratedKeysEnabled(Boolean getGeneratedKeysEnabled)
{
- this.getGeneratedKeysEnabled = getGeneratedKeysEnabled;
- dirty = true;
+ setConfigurationElement( getGeneratedKeysEnabled, GET_GENERATED_KEYS_ENABLED, Environment.USE_GET_GENERATED_KEYS);
}
public String getQuerySubstitutions()
{
- return querySubstitutions;
+ return getConfigurationElementAsString(QUERY_SUBSTITUTIONS, Environment.QUERY_SUBSTITUTIONS);
}
public void setQuerySubstitutions(String querySubstitutions)
{
- this.querySubstitutions = querySubstitutions;
- dirty = true;
+ setConfigurationElement(querySubstitutions, QUERY_SUBSTITUTIONS, Environment.QUERY_SUBSTITUTIONS);
}
public Boolean getSecondLevelCacheEnabled()
{
- return secondLevelCacheEnabled;
+ return getConfigurationElementAsBoolean(SECOND_LEVEL_CACHE_ENABLED, Environment.USE_SECOND_LEVEL_CACHE);
}
public void setSecondLevelCacheEnabled(Boolean secondLevelCacheEnabled)
{
- this.secondLevelCacheEnabled = secondLevelCacheEnabled;
- dirty = true;
+ setConfigurationElement( secondLevelCacheEnabled, SECOND_LEVEL_CACHE_ENABLED, Environment.USE_SECOND_LEVEL_CACHE);
}
public Boolean getQueryCacheEnabled()
{
- return queryCacheEnabled;
+ return getConfigurationElementAsBoolean(QUERY_CACHE_ENABLED, Environment.USE_QUERY_CACHE);
}
public void setQueryCacheEnabled(Boolean queryCacheEnabled)
{
- this.queryCacheEnabled = queryCacheEnabled;
- dirty = true;
+ setConfigurationElement(queryCacheEnabled, QUERY_CACHE_ENABLED, Environment.USE_QUERY_CACHE);
}
public String getCacheProviderClass()
{
- return cacheProviderClass;
+ return getConfigurationElementAsString(CACHE_PROVIDER_CLASS, Environment.CACHE_PROVIDER);
}
public void setCacheProviderClass(String cacheProviderClass)
{
- this.cacheProviderClass = cacheProviderClass;
- dirty = true;
+ setConfigurationElement(cacheProviderClass,CACHE_PROVIDER_CLASS, Environment.CACHE_PROVIDER);
}
/**
@@ -751,7 +887,7 @@
*/
public String getCacheRegionFactoryClass()
{
- return this.cacheRegionFactoryClass;
+ return getConfigurationElementAsString(CACHE_REGION_FACTORY_CLASS, Environment.CACHE_REGION_FACTORY);
}
/**
@@ -759,61 +895,57 @@
*/
public void setCacheRegionFactoryClass(String regionFactoryClass)
{
- this.cacheRegionFactoryClass = regionFactoryClass;
- dirty = true;
+ setConfigurationElement(regionFactoryClass, CACHE_REGION_FACTORY_CLASS, Environment.CACHE_REGION_FACTORY);
}
public String getCacheRegionPrefix()
{
- return cacheRegionPrefix;
+ return getConfigurationElementAsString(CACHE_REGION_PREFIX, Environment.CACHE_REGION_PREFIX);
}
public void setCacheRegionPrefix(String cacheRegionPrefix)
{
- this.cacheRegionPrefix = cacheRegionPrefix;
- dirty = true;
+ setConfigurationElement(cacheRegionPrefix, CACHE_REGION_PREFIX, Environment.CACHE_REGION_PREFIX);
}
public Boolean getMinimalPutsEnabled()
{
- return minimalPutsEnabled;
+ return getConfigurationElementAsBoolean(MINIMAL_PUTS_ENABLED, Environment.USE_MINIMAL_PUTS);
}
public void setMinimalPutsEnabled(Boolean minimalPutsEnabled)
{
- this.minimalPutsEnabled = minimalPutsEnabled;
- dirty = true;
+ setConfigurationElement(minimalPutsEnabled, MINIMAL_PUTS_ENABLED, Environment.USE_MINIMAL_PUTS);
}
public Boolean getUseStructuredCacheEntriesEnabled()
{
- return structuredCacheEntriesEnabled;
+ return getConfigurationElementAsBoolean(STRUCTURED_CACHE_ENTRIES_ENABLED, Environment.USE_STRUCTURED_CACHE);
}
public void setUseStructuredCacheEntriesEnabled(Boolean structuredCacheEntriesEnabled)
{
- this.structuredCacheEntriesEnabled = structuredCacheEntriesEnabled;
+ setConfigurationElement(structuredCacheEntriesEnabled, STRUCTURED_CACHE_ENTRIES_ENABLED, Environment.USE_STRUCTURED_CACHE);
}
public Boolean getShowSqlEnabled()
{
- return showSqlEnabled;
+ return getConfigurationElementAsBoolean(SHOW_SQL_ENABLED, Environment.SHOW_SQL);
}
public void setShowSqlEnabled(Boolean showSqlEnabled)
{
- this.showSqlEnabled = showSqlEnabled;
- dirty = true;
+ setConfigurationElement( showSqlEnabled, SHOW_SQL_ENABLED, Environment.SHOW_SQL);
}
public Boolean getSqlCommentsEnabled()
{
- return sqlCommentsEnabled;
+ return getConfigurationElementAsBoolean(SQL_COMMENTS_ENABLED, Environment.USE_SQL_COMMENTS);
}
public void setSqlCommentsEnabled(Boolean commentsEnabled)
{
- this.sqlCommentsEnabled = commentsEnabled;
+ setConfigurationElement( commentsEnabled, SQL_COMMENTS_ENABLED, Environment.USE_SQL_COMMENTS);
}
public String getSessionFactoryInterceptor()
@@ -842,7 +974,7 @@
*/
public String getDeployedCacheJndiName()
{
- return this.deployedCacheJndiName;
+ return getConfigurationElementAsString(DEPLOYED_CACHE_JNDI_NAME, org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager.CACHE_RESOURCE_PROP);
}
/**
@@ -850,8 +982,7 @@
*/
public void setDeployedCacheJndiName(String name)
{
- this.deployedCacheJndiName = name;
- dirty = true;
+ setConfigurationElement( name, DEPLOYED_CACHE_JNDI_NAME, org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager.CACHE_RESOURCE_PROP);
}
/**
@@ -859,7 +990,7 @@
*/
public String getDeployedCacheManagerJndiName()
{
- return this.deployedCacheManagerJndiName;
+ return getConfigurationElementAsString(DEPLOYED_CACHE_MANAGER_JNDI_NAME, org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP);
}
/**
@@ -867,51 +998,47 @@
*/
public void setDeployedCacheManagerJndiName(String name)
{
- this.deployedCacheManagerJndiName = name;
- dirty = true;
+ setConfigurationElement( name, DEPLOYED_CACHE_MANAGER_JNDI_NAME, org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP);
}
public Boolean getBatchVersionedDataEnabled()
{
- return batchVersionedDataEnabled;
+ return getConfigurationElementAsBoolean(BATCH_VERSIONED_DATA_ENABLED, Environment.BATCH_VERSIONED_DATA);
}
public void setBatchVersionedDataEnabled(Boolean batchVersionedDataEnabled)
{
- this.batchVersionedDataEnabled = batchVersionedDataEnabled;
- this.dirty = true;
+ setConfigurationElement( batchVersionedDataEnabled, BATCH_VERSIONED_DATA_ENABLED, Environment.BATCH_VERSIONED_DATA);
}
public Boolean getStreamsForBinaryEnabled()
{
- return streamsForBinaryEnabled;
+ return getConfigurationElementAsBoolean(STREAMS_FOR_BINARY_ENABLED, Environment.USE_STREAMS_FOR_BINARY);
}
public void setStreamsForBinaryEnabled(Boolean streamsForBinaryEnabled)
{
- this.streamsForBinaryEnabled = streamsForBinaryEnabled;
- this.dirty = true;
+ setConfigurationElement( streamsForBinaryEnabled, STREAMS_FOR_BINARY_ENABLED, Environment.USE_STREAMS_FOR_BINARY);
}
public Boolean getReflectionOptimizationEnabled()
{
- return reflectionOptimizationEnabled;
+ return getConfigurationElementAsBoolean(REFLECTION_OPTIMIZATION_ENABLED, Environment.USE_REFLECTION_OPTIMIZER);
}
public void setReflectionOptimizationEnabled(Boolean reflectionOptimizationEnabled)
{
- this.reflectionOptimizationEnabled = reflectionOptimizationEnabled;
- this.dirty = true;
+ setConfigurationElement( reflectionOptimizationEnabled, REFLECTION_OPTIMIZATION_ENABLED, Environment.USE_REFLECTION_OPTIMIZER);
}
public Boolean getStatGenerationEnabled()
{
- return statGenerationEnabled;
+ return getConfigurationElementAsBoolean(STAT_GENERATION_ENABLED, Environment.GENERATE_STATISTICS);
}
public void setStatGenerationEnabled(Boolean statGenerationEnabled)
{
- this.statGenerationEnabled = statGenerationEnabled;
+ setConfigurationElement( statGenerationEnabled, STAT_GENERATION_ENABLED, Environment.GENERATE_STATISTICS);
}
public URL getHarUrl()
@@ -934,4 +1061,54 @@
{
this.scanForMappingsEnabled = scanForMappingsEnabled;
}
+
+ private String getConfigurationElementAsString(String beanPropertyName, String hibernateName)
+ {
+ Object element = getConfigurationElement(beanPropertyName, hibernateName);
+ return element == null ? null : element.toString();
+ }
+
+ private Boolean getConfigurationElementAsBoolean(String beanPropertyName, String hibernateName)
+ {
+ Object element = getConfigurationElement(beanPropertyName, hibernateName);
+ if (element instanceof String)
+ {
+ return Boolean.valueOf((String) element);
+ }
+ return (Boolean) element;
+ }
+
+ private Integer getConfigurationElementAsInteger(String beanPropertyName, String hibernateName)
+ {
+ Object element = getConfigurationElement(beanPropertyName, hibernateName);
+ if (element instanceof String)
+ {
+ return Integer.valueOf((String) element);
+ }
+ return (Integer) element;
+ }
+
+ private Object getConfigurationElement(String beanPropertyName, String hibernateName)
+ {
+ Object name = configurationElements.get(beanPropertyName);
+ if (name == null)
+ {
+ name = configurationElements.get(hibernateName);
+ }
+ return name;
+ }
+
+ private void setConfigurationElement(Object value, String beanPropertyName, String hibernateName)
+ {
+ configurationElements.remove(beanPropertyName);
+ if (value == null)
+ {
+ configurationElements.remove(hibernateName);
+ }
+ else
+ {
+ configurationElements.put(hibernateName, value);
+ }
+ dirty = true;
+ }
}
Modified: branches/Branch_5_x/testsuite/.classpath
===================================================================
--- branches/Branch_5_x/testsuite/.classpath 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/testsuite/.classpath 2009-11-18 22:53:20 UTC (rev 96511)
@@ -71,5 +71,7 @@
<classpathentry kind="lib" path="/thirdparty/javax/inject/lib/javax.inject.jar"/>
<classpathentry kind="lib" path="/thirdparty/org/jboss/interceptor/lib/jboss-interceptor-api.jar"/>
<classpathentry kind="lib" path="/thirdparty/org/hibernate/lib/ejb3-persistence.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/hibernate-testing/lib/hibernate-testing.jar" sourcepath="/thirdparty/hibernate-testing/lib/hibernate-testing-sources.jar"/>
+ <classpathentry kind="lib" path="/thirdparty/org/hibernate/lib/hibernate-jbosscache.jar" sourcepath="/thirdparty/org/hibernate/lib/hibernate-jbosscache-sources.jar"/>
<classpathentry kind="output" path="output/eclipse-classes"/>
</classpath>
Modified: branches/Branch_5_x/testsuite/build.xml
===================================================================
--- branches/Branch_5_x/testsuite/build.xml 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/testsuite/build.xml 2009-11-18 22:53:20 UTC (rev 96511)
@@ -172,6 +172,8 @@
<path refid="hsqldb.hsqldb.classpath"/>
<!-- Need hibernate jar for hibernate-based tests -->
<path refid="hibernate3.classpath"/>
+ <path refid="org.hibernate.classpath"/>
+ <path refid="hibernate.testing.classpath"/>
<path refid="odmg.classpath"/>
<path refid="cglib.classpath"/>
<!-- Need spring jar for spring-based tests -->
Modified: branches/Branch_5_x/testsuite/imports/sections/hibernate.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/hibernate.xml 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/testsuite/imports/sections/hibernate.xml 2009-11-18 22:53:20 UTC (rev 96511)
@@ -88,5 +88,23 @@
</metainf>
<include name="hib-ejb2.jar"/>
</jar>
+
+ <jar basedir="${build.classes}" destfile="${build.lib}/hib-jbas7411.har">
+ <metainf dir="${build.resources}/hibernate/jbas7411">
+ <include name="jboss-hibernate.xml"/>
+ <include name="Timers.hbm.xml"/>
+ </metainf>
+ <include name="org/jboss/test/hibernate/SimpleInterceptor.class"/>
+ </jar>
+ <jar basedir="${build.classes}" destfile="${build.lib}/hib-jbas7411.jar">
+ <metainf dir="${build.resources}/hibernate/ejbtimers">
+ <include name="ejb-jar.xml"/>
+ <include name="jboss.xml"/>
+ </metainf>
+ <include name="org/jboss/test/hibernate/timers/**"/>
+ <fileset dir="${build.lib}">
+ <include name="hib-jbas7411.har"/>
+ </fileset>
+ </jar>
</target>
</project>
Copied: branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/mocks (from rev 96509, trunk/testsuite/src/main/org/jboss/test/hibernate/mocks)
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/mocks/MockRegion.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/hibernate/mocks/MockRegion.java 2009-11-18 20:18:22 UTC (rev 96509)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/mocks/MockRegion.java 2009-11-18 22:53:20 UTC (rev 96511)
@@ -111,4 +111,9 @@
return null;
}
+ public boolean contains(Object key)
+ {
+ return false;
+ }
+
}
Copied: branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HarWithStandardPropertiesUnitTestCase.java (from rev 96509, trunk/testsuite/src/main/org/jboss/test/hibernate/test/HarWithStandardPropertiesUnitTestCase.java)
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HarWithStandardPropertiesUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HarWithStandardPropertiesUnitTestCase.java 2009-11-18 22:53:20 UTC (rev 96511)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.hibernate.test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.hibernate.timers.interfaces.ITimersHome;
+import org.jboss.test.hibernate.timers.interfaces.ITimers;
+import org.jboss.test.hibernate.timers.interfaces.Key;
+import org.jboss.test.hibernate.timers.interfaces.Info;
+import org.jboss.test.hibernate.timers.Timers;
+import org.jboss.test.hibernate.timers.TimersID;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.Date;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+/**
+ * Test for JBAS-7411. Deploys a HAR whose -hibernate.xml uses standard
+ * Hibernate property names instead of properties of the
+ * org.jboss.hibernate.jmx.Hibernate class. Validates that it deploys and
+ * creates usable sessions.
+ *
+ * This test borrows the classes from TimersUnitTestCase; just uses a different
+ * jboss-hibernate.xml file.
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 81036 $
+ */
+public class HarWithStandardPropertiesUnitTestCase extends JBossTestCase
+{
+ public HarWithStandardPropertiesUnitTestCase(String name) throws Exception
+ {
+ super(name);
+ }
+
+ /**
+ Setup the test suite.
+ */
+ public static Test suite() throws Exception
+ {
+ return getDeploySetup(HarWithStandardPropertiesUnitTestCase.class, "hib-jbas7411.jar");
+ }
+
+ public void testCurrentSession() throws Throwable
+ {
+ InitialContext ctx = super.getInitialContext();
+ ITimersHome home = (ITimersHome) ctx.lookup("hib-timers/ITimersHome");
+ ITimers bean = null;
+
+ try
+ {
+ bean = home.create();
+
+ int initialCount = bean.listTimers().size();
+
+ TimersID id = new TimersID("testCurrentSession", "*:ejb=None");
+ Timers timer = new Timers(id);
+ Date now = new Date();
+ Long interval = new Long(5*1000);
+ Key key = new Key("key2", 123456789);
+ Info info = new Info(System.getProperties());
+ timer.setInitialDate(now);
+ timer.setInstancePK(serialize(key));
+ timer.setTimerInterval(interval);
+ timer.setInfo(serialize(info));
+
+ bean.persist(timer);
+ log.info("Timers created with id = " + id);
+
+ List timers = bean.listTimers();
+ assertNotNull(timers);
+ assertEquals("Incorrect result size", initialCount + 1, timers.size());
+
+ Timers found = null;
+ Iterator itr = timers.iterator();
+ while (itr.hasNext())
+ {
+ Timers t = (Timers) itr.next();
+ if (id.equals(t.getId()))
+ {
+ found = t;
+ }
+ }
+ assertNotNull("Saved timer found in list", found);
+ Date d = found.getInitialDate();
+ long t0 = (now.getTime() / 1000) * 1000;
+ long t1 = (d.getTime() / 1000) * 1000;
+ assertTrue("Timer.InitialDate("+t1+") == now("+t0+")", t0 == t1);
+ assertTrue("Timer.Id == id", found.getId().equals(id));
+ assertTrue("Timer.TimerInterval == interval", found.getTimerInterval().equals(interval));
+ Object tmp = deserialize(found.getInstancePK());
+ assertTrue("Timer.InstancePK == key", tmp.equals(key));
+ tmp = deserialize(found.getInfo());
+ log.info("Info: "+tmp);
+ assertTrue("Timer.Info == info", tmp.equals(info));
+
+ // Scott forgot to remove the timer
+ bean.delete(timer);
+ }
+ finally
+ {
+ if (bean != null)
+ {
+ try
+ {
+ bean.remove();
+ }
+ catch (Throwable t)
+ {
+ // ignore
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
Copied: branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HibernateConfigurationUnitTestCase.java (from rev 96509, trunk/testsuite/src/main/org/jboss/test/hibernate/test/HibernateConfigurationUnitTestCase.java)
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HibernateConfigurationUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/hibernate/test/HibernateConfigurationUnitTestCase.java 2009-11-18 22:53:20 UTC (rev 96511)
@@ -0,0 +1,333 @@
+/**
+ *
+ */
+package org.jboss.test.hibernate.test;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cache.HashtableCacheProvider;
+import org.hibernate.cfg.Environment;
+import org.hibernate.cfg.Settings;
+import org.hibernate.dialect.HSQLDialect;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.test.tm.TransactionManagerLookupImpl;
+import org.hibernate.transaction.JTATransactionFactory;
+import org.jboss.hibernate.deployers.metadata.BaseNamedElement;
+import org.jboss.hibernate.jmx.Hibernate;
+import org.jboss.test.hibernate.mocks.MockCacheProvider;
+import org.jboss.test.hibernate.mocks.MockInterceptor;
+import org.jboss.test.hibernate.mocks.MockListenerInjector;
+import org.jboss.test.hibernate.mocks.MockRegionFactory;
+
+/**
+ * A HibernateConfigurationUnitTestCase.
+ *
+ * @author Brian Stansberry
+ * @version $Revision: 1.1 $
+ */
+public class HibernateConfigurationUnitTestCase extends TestCase
+{
+ private static long testCount = System.currentTimeMillis();
+
+ private File tempFile = null;
+
+ private Hibernate testee;
+
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ tempFile = File.createTempFile(getClass().getSimpleName() + (testCount++), null);
+ tempFile.mkdirs();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ try
+ {
+ super.tearDown();
+ }
+ finally
+ {
+ if (testee != null)
+ {
+ testee.stop();
+ }
+ }
+
+ }
+ finally
+ {
+ if (tempFile != null && tempFile.exists())
+ {
+ if (!tempFile.delete())
+ {
+ tempFile.deleteOnExit();
+ }
+ }
+ }
+ }
+
+ public void testDefaults() throws Throwable
+ {
+ testee = new TestableHibernate();
+
+ testee.setHarUrl(tempFile.toURI().toURL());
+ testee.setDialect(HSQLDialect.class.getName());
+ Set<BaseNamedElement> config = new HashSet<BaseNamedElement>();
+ config.add(createBaseNamedElement(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName()));
+ config.add(createBaseNamedElement(Environment.USER_TRANSACTION, JTATransactionFactory.DEFAULT_USER_TRANSACTION_NAME));
+ testee.setConfigurationElements(config);
+ testee.start();
+
+ SessionFactory factory = testee.getInstance();
+ assertTrue(factory instanceof SessionFactoryImplementor);
+ Settings settings = ((SessionFactoryImplementor) factory).getSettings();
+ assertTrue(settings.getTransactionFactory() instanceof JTATransactionFactory);
+ assertTrue(settings.isSecondLevelCacheEnabled());
+
+ assertTrue(settings.isFlushBeforeCompletionEnabled());
+ assertTrue(settings.isAutoCloseSessionEnabled());
+
+ Properties props = testee.getConfigurationProperties();
+ assertEquals(HashtableCacheProvider.class.getName(), props.getProperty(Environment.CACHE_PROVIDER));
+ assertEquals("after_statement", props.getProperty("hibernate.connection.release_mode"));
+ // Disabled, as use of JTA causes hibernate to ignore hibernate.connection.release_mode=after_statement
+ //assertEquals(ConnectionReleaseMode.AFTER_STATEMENT, settings.getConnectionReleaseMode());
+ }
+
+ public void testMBeanConfiguration() throws Throwable
+ {
+ testee = new TestableHibernate();
+
+ // Non-Hibernate configs
+ testee.setHarUrl(tempFile.toURI().toURL());
+ testee.setScanForMappingsEnabled(true);
+ testee.setSessionFactoryInterceptor(MockInterceptor.class.getName());
+ testee.setListenerInjector(MockListenerInjector.class.getName());
+
+ testee.setDialect(HSQLDialect.class.getName());
+// testee.setDatasourceName("TestDS");
+ testee.setCacheProviderClass(MockCacheProvider.class.getName());
+ testee.setCacheRegionFactoryClass(MockRegionFactory.class.getName());
+ testee.setCacheRegionPrefix("aprefix");
+ testee.setMinimalPutsEnabled(true);
+ testee.setHbm2ddlAuto("bogus");
+ testee.setSecondLevelCacheEnabled(Boolean.TRUE);
+ testee.setQueryCacheEnabled(Boolean.TRUE);
+ testee.setUseStructuredCacheEntriesEnabled(Boolean.TRUE);
+ testee.setDefaultSchema("schema");
+ testee.setDefaultCatalog("catalog");
+ testee.setJdbcBatchSize(Integer.valueOf(8));
+ testee.setJdbcFetchSize(Integer.valueOf(9));
+ testee.setBatchVersionedDataEnabled(Boolean.TRUE);
+ testee.setMaxFetchDepth(Integer.valueOf(13));
+ testee.setJdbcScrollableResultSetEnabled(Boolean.TRUE);
+ testee.setSqlCommentsEnabled(Boolean.TRUE);
+ testee.setQuerySubstitutions("key=value");
+ testee.setShowSqlEnabled(Boolean.TRUE);
+ testee.setGetGeneratedKeysEnabled(Boolean.TRUE);
+ testee.setStatGenerationEnabled(Boolean.TRUE);
+ testee.setUsername("Brian");
+ testee.setPassword("Brian");
+ testee.setStreamsForBinaryEnabled(Boolean.TRUE);
+ testee.setReflectionOptimizationEnabled(Boolean.TRUE);
+ testee.setDeployedCacheJndiName("java:/test/Cache");
+ testee.setDeployedCacheManagerJndiName("java:/test/CacheManager");
+
+ Set<BaseNamedElement> config = new HashSet<BaseNamedElement>();
+ config.add(createBaseNamedElement(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName()));
+ config.add(createBaseNamedElement(Environment.USER_TRANSACTION, JTATransactionFactory.DEFAULT_USER_TRANSACTION_NAME));
+ config.add(createBaseNamedElement(org.hibernate.cache.jbc.builder.MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, "entities-test"));
+ testee.setConfigurationElements(config);
+
+ testee.start();
+ validate(testee);
+ }
+
+ public void testHibernatePropertyConfiguration() throws Throwable
+ {
+ testee = new TestableHibernate();
+
+ Set<BaseNamedElement> config = new HashSet<BaseNamedElement>();
+
+ config.add(createBaseNamedElement("harUrl", tempFile.toURI().toURL()));
+ config.add(createBaseNamedElement("scanForMappingsEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("sessionFactoryInterceptor", MockInterceptor.class.getName()));
+ config.add(createBaseNamedElement("listenerInjector", MockListenerInjector.class.getName()));
+
+ config.add(createBaseNamedElement(Environment.DIALECT, HSQLDialect.class.getName()));
+ config.add(createBaseNamedElement(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName()));
+ config.add(createBaseNamedElement(Environment.USER_TRANSACTION, JTATransactionFactory.DEFAULT_USER_TRANSACTION_NAME));
+
+// config.add(createBaseNamedElement(Environment.DATASOURCE, "TestDS"));
+ config.add(createBaseNamedElement(Environment.CACHE_PROVIDER, MockCacheProvider.class.getName()));
+ config.add(createBaseNamedElement(Environment.CACHE_REGION_FACTORY, MockRegionFactory.class.getName()));
+ config.add(createBaseNamedElement(Environment.CACHE_REGION_PREFIX, "aprefix"));
+ config.add(createBaseNamedElement(Environment.USE_MINIMAL_PUTS, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.HBM2DDL_AUTO, "bogus"));
+ config.add(createBaseNamedElement(Environment.DEFAULT_SCHEMA, "schema"));
+ config.add(createBaseNamedElement(Environment.DEFAULT_CATALOG, "catalog"));
+ config.add(createBaseNamedElement(Environment.USE_SECOND_LEVEL_CACHE, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.USE_QUERY_CACHE, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.USE_STRUCTURED_CACHE, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.STATEMENT_BATCH_SIZE, Integer.valueOf(8)));
+ config.add(createBaseNamedElement(Environment.STATEMENT_FETCH_SIZE, Integer.valueOf(9)));
+ config.add(createBaseNamedElement(Environment.BATCH_VERSIONED_DATA, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.MAX_FETCH_DEPTH, Integer.valueOf(13)));
+ config.add(createBaseNamedElement(Environment.USE_SCROLLABLE_RESULTSET, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.USE_SQL_COMMENTS, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.QUERY_SUBSTITUTIONS, "key=value"));
+ config.add(createBaseNamedElement(Environment.SHOW_SQL, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.USE_GET_GENERATED_KEYS, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.GENERATE_STATISTICS, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.USER, "Brian"));
+ config.add(createBaseNamedElement(Environment.PASS, "Brian"));
+ config.add(createBaseNamedElement(Environment.USE_STREAMS_FOR_BINARY, Boolean.TRUE));
+ config.add(createBaseNamedElement(Environment.USE_REFLECTION_OPTIMIZER, Boolean.TRUE));
+ config.add(createBaseNamedElement(org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager.CACHE_RESOURCE_PROP, "java:/test/Cache"));
+ config.add(createBaseNamedElement(org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP, "java:/test/CacheManager"));
+ config.add(createBaseNamedElement(org.hibernate.cache.jbc.builder.MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, "entities-test"));
+
+ testee.setConfigurationElements(config);
+ testee.start();
+ validate(testee);
+ }
+
+ public void testLegacyPropertyNames() throws Throwable
+ {
+ testee = new TestableHibernate();
+
+ Set<BaseNamedElement> config = new HashSet<BaseNamedElement>();
+
+ config.add(createBaseNamedElement("harUrl", tempFile.toURI().toURL()));
+ config.add(createBaseNamedElement("scanForMappingsEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("sessionFactoryInterceptor", MockInterceptor.class.getName()));
+ config.add(createBaseNamedElement("listenerInjector", MockListenerInjector.class.getName()));
+
+ config.add(createBaseNamedElement("dialect", HSQLDialect.class.getName()));
+
+ config.add(createBaseNamedElement(Environment.TRANSACTION_MANAGER_STRATEGY, TransactionManagerLookupImpl.class.getName()));
+ config.add(createBaseNamedElement(Environment.USER_TRANSACTION, JTATransactionFactory.DEFAULT_USER_TRANSACTION_NAME));
+
+// config.add(createBaseNamedElement("datasourceName", "TestDS"));
+ config.add(createBaseNamedElement("cacheProviderClass", MockCacheProvider.class.getName()));
+ config.add(createBaseNamedElement("cacheRegionFactoryClass", MockRegionFactory.class.getName()));
+ config.add(createBaseNamedElement("cacheRegionPrefix", "aprefix"));
+ config.add(createBaseNamedElement("minimalPutsEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("hbm2ddlAuto", "bogus"));
+ config.add(createBaseNamedElement("defaultSchema", "schema"));
+ config.add(createBaseNamedElement("defaultCatalog", "catalog"));
+ config.add(createBaseNamedElement("secondLevelCacheEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("queryCacheEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("useStructuredCacheEntriesEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("jdbcBatchSize", Integer.valueOf(8)));
+ config.add(createBaseNamedElement("jdbcFetchSize", Integer.valueOf(9)));
+ config.add(createBaseNamedElement("batchVersionedDataEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("maxFetchDepth", Integer.valueOf(13)));
+ config.add(createBaseNamedElement("jdbcScrollableResultSetEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("sqlCommentsEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("querySubstitutions", "key=value"));
+ config.add(createBaseNamedElement("showSqlEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("getGeneratedKeysEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("statGenerationEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("username", "Brian"));
+ config.add(createBaseNamedElement("password", "Brian"));
+ config.add(createBaseNamedElement("streamsForBinaryEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("reflectionOptimizationEnabled", Boolean.TRUE));
+ config.add(createBaseNamedElement("deployedCacheJndiName", "java:/test/Cache"));
+ config.add(createBaseNamedElement("deployedCacheManagerJndiName", "java:/test/CacheManager"));
+ config.add(createBaseNamedElement(org.hibernate.cache.jbc.builder.MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP, "entities-test"));
+
+ testee.setConfigurationElements(config);
+ testee.start();
+ validate(testee);
+
+ }
+
+ private void validate(Hibernate testee) throws Exception
+ {
+ // Validate getter values on Hibernate object
+ assertEquals(TestableHibernate.class.getSimpleName() + testCount, testee.getSessionFactoryName());
+ assertEquals(tempFile.toURI().toURL(), testee.getHarUrl());
+ assertTrue(testee.isScanForMappingsEnabled());
+ assertEquals(MockInterceptor.class.getName(), testee.getSessionFactoryInterceptor());
+ assertEquals(MockListenerInjector.class.getName(), testee.getListenerInjector());
+
+ // Where we can, validate stuff exposed by hibernate Settings
+ SessionFactory factory = testee.getInstance();
+ assertTrue(factory instanceof SessionFactoryImplementor);
+ Settings settings = ((SessionFactoryImplementor) factory).getSettings();
+
+// assertEquals(TestableHibernate.class.getSimpleName() + testCount, settings.getSessionFactoryName());
+ assertEquals(HSQLDialect.class.getName(), testee.getDialect());
+ assertTrue(settings.getDialect() instanceof HSQLDialect);
+ assertTrue(settings.getTransactionFactory() instanceof JTATransactionFactory);
+ assertTrue(settings.getTransactionManagerLookup() instanceof TransactionManagerLookupImpl);
+ assertTrue(settings.getRegionFactory() instanceof MockRegionFactory);
+ assertEquals("aprefix", settings.getCacheRegionPrefix());
+ assertTrue(settings.isMinimalPutsEnabled());
+ assertTrue(settings.isSecondLevelCacheEnabled());
+ assertTrue(settings.isQueryCacheEnabled());
+ assertTrue(settings.isStructuredCacheEntriesEnabled());
+ assertEquals("schema", settings.getDefaultSchemaName());
+ assertEquals("catalog", settings.getDefaultCatalogName());
+ assertEquals(Integer.valueOf(9), settings.getJdbcFetchSize());
+ assertTrue(settings.isJdbcBatchVersionedData());
+ assertEquals(Integer.valueOf(13), settings.getMaximumFetchDepth());
+ assertTrue(settings.isScrollableResultSetsEnabled());
+ assertTrue(settings.isCommentsEnabled());
+ @SuppressWarnings("unchecked")
+ Map substitutions = settings.getQuerySubstitutions();
+ assertNotNull(substitutions);
+ assertEquals(1, substitutions.size());
+ assertEquals("value", substitutions.get("key"));
+ assertTrue(settings.getSqlStatementLogger().isLogToStdout());
+ assertTrue(settings.isGetGeneratedKeysEnabled());
+ assertTrue(settings.isStatisticsEnabled());
+
+ // For stuff not available via Settings, second best is to check the properties exposed by Hibernate object
+ Properties props = testee.getConfigurationProperties();
+ assertEquals(JTATransactionFactory.DEFAULT_USER_TRANSACTION_NAME, props.getProperty(Environment.USER_TRANSACTION));
+ assertEquals(MockCacheProvider.class.getName(), props.getProperty(Environment.CACHE_PROVIDER));
+ assertEquals("bogus", props.getProperty(Environment.HBM2DDL_AUTO));
+ assertEquals("8", props.getProperty(Environment.STATEMENT_BATCH_SIZE));
+ assertEquals("Brian", props.getProperty(Environment.USER));
+ assertEquals("Brian", props.getProperty(Environment.PASS));
+ assertEquals("true", props.getProperty(Environment.USE_STREAMS_FOR_BINARY));
+ assertEquals("true", props.getProperty(Environment.USE_REFLECTION_OPTIMIZER));
+ assertEquals("java:/test/Cache", props.getProperty(org.hibernate.cache.jbc.builder.JndiSharedCacheInstanceManager.CACHE_RESOURCE_PROP));
+ assertEquals("java:/test/CacheManager", props.getProperty(org.hibernate.cache.jbc.builder.JndiMultiplexingCacheInstanceManager.CACHE_FACTORY_RESOURCE_PROP));
+ assertEquals("entities-test", props.getProperty(org.hibernate.cache.jbc.builder.MultiplexingCacheInstanceManager.ENTITY_CACHE_RESOURCE_PROP));
+ }
+
+ private static BaseNamedElement createBaseNamedElement(String name, Object value)
+ {
+ BaseNamedElement element = new BaseNamedElement();
+ element.setName(name);
+ element.setValue(value);
+ return element;
+ }
+
+ private static class TestableHibernate extends Hibernate
+ {
+ public TestableHibernate()
+ {
+ super(null, false);
+
+ setSessionFactoryName(getClass().getSimpleName() + testCount);
+ }
+ }
+}
Copied: branches/Branch_5_x/testsuite/src/resources/hibernate/jbas7411 (from rev 96509, trunk/testsuite/src/resources/hibernate/jbas7411)
Modified: branches/Branch_5_x/thirdparty/pom.xml
===================================================================
--- branches/Branch_5_x/thirdparty/pom.xml 2009-11-18 22:50:25 UTC (rev 96510)
+++ branches/Branch_5_x/thirdparty/pom.xml 2009-11-18 22:53:20 UTC (rev 96511)
@@ -956,6 +956,13 @@
</mapping>
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <mapping>
+ <componentId>hibernate-testing</componentId>
+ </mapping>
+ </dependency>
+ <dependency>
<groupId>org.hibernate.java-persistence</groupId>
<artifactId>jpa-api</artifactId>
<mapping>
@@ -1360,6 +1367,10 @@
<artifactId>hibernate-jbosscache</artifactId>
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.jboss.interceptor</groupId>
<artifactId>jboss-interceptor-api</artifactId>
</dependency>
More information about the jboss-cvs-commits
mailing list