Author: hlship
Date: Mon Sep 8 15:36:42 2008
New Revision: 693304
URL: http://svn.apache.org/viewvc?rev=693304&view=rev
Log:
TAPESTRY-2223: Don't require a hibernate.cfg.xml
Added:
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java
Modified:
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/conf.apt
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java
Added:
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java?rev=693304&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java
Mon Sep 8 15:36:42 2008
@@ -0,0 +1,34 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.hibernate;
+
+/**
+ * Defines constants used inside the Tapestry Hibernate intergration.
+ */
+public class HibernateConstants
+{
+ /**
+ * If true (the default), then [EMAIL PROTECTED]
org.apache.tapestry5.ValueEncoder}s are automatically created for each entity.
+ * Override to "false" to handle entity value encoding explicitly.
+ */
+ public static final String PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL =
"tapestry.hibernate.provide-entity-value-encoders";
+
+ /**
+ * If true, then the last [EMAIL PROTECTED]
org.apache.tapestry5.hibernate.HibernateConfigurer} will invoke [EMAIL
PROTECTED]
+ * org.hibernate.cfg.Configuration#configure()}, to read the application's
<code>hibernate.cfg.xml</code>. This
+ * should be set to false for applications that configure exclusively in
code.
+ */
+ public static final String DEFAULT_CONFIGURATION =
"tapestry.hibernate.default-configuration";
+}
Modified:
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java?rev=693304&r1=693303&r2=693304&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
Mon Sep 8 15:36:42 2008
@@ -39,11 +39,6 @@
@SuppressWarnings({"JavaDoc"})
public class HibernateModule
{
- /**
- * If true (the default), then [EMAIL PROTECTED]
org.apache.tapestry5.ValueEncoder}s are automatically created for each entity.
- * Override to "false" to handle entity value encoding explicitly.
- */
- public static final String PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL =
"tapestry.hibernate.provide-entity-value-encoders";
public static void bind(ServiceBinder binder)
{
@@ -53,7 +48,8 @@
public static void contributeFactoryDefaults(MappedConfiguration<String,
String> configuration)
{
- configuration.add(PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL, "true");
+
configuration.add(HibernateConstants.PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL,
"true");
+ configuration.add(HibernateConstants.DEFAULT_CONFIGURATION, "true");
}
public static HibernateEntityPackageManager
buildHibernateEntityPackageManager(
@@ -153,7 +149,7 @@
*/
@SuppressWarnings("unchecked")
public static void contributeValueEncoderSource(MappedConfiguration<Class,
ValueEncoderFactory> configuration,
-
@Symbol(PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL)
+
@Symbol(HibernateConstants.PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL)
boolean provideEncoders,
final
HibernateSessionSource sessionSource,
final Session session,
Modified:
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java?rev=693304&r1=693303&r2=693304&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
Mon Sep 8 15:36:42 2008
@@ -15,6 +15,8 @@
package org.apache.tapestry5.internal.hibernate;
import org.apache.tapestry5.hibernate.HibernateConfigurer;
+import org.apache.tapestry5.hibernate.HibernateConstants;
+import org.apache.tapestry5.ioc.annotations.Symbol;
import org.hibernate.cfg.Configuration;
/**
@@ -22,9 +24,17 @@
*/
public final class DefaultHibernateConfigurer implements HibernateConfigurer
{
+ private final boolean defaultConfiguration;
+
+ public DefaultHibernateConfigurer(
+ @Symbol(HibernateConstants.DEFAULT_CONFIGURATION)
+ boolean defaultConfiguration)
+ {
+ this.defaultConfiguration = defaultConfiguration;
+ }
public void configure(Configuration configuration)
{
- configuration.configure();
+ if (defaultConfiguration) configuration.configure();
}
}
Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/conf.apt
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/conf.apt?rev=693304&r1=693303&r2=693304&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/conf.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/conf.apt Mon Sep
8 15:36:42 2008
@@ -49,3 +49,14 @@
You may add as many packages in this manner as you wish. This option is most
often used when the entities themselves are contained in a library included
within an application, rather than part of the application directly.
+
+Hibernate Symbols
+
+ The Hibernate integration includes a number of
{{{../tapestry-ioc/symbols.html}symbols}} used to control certain features:
+
+ [tapestry.hibernate.provide-entity-value-encoders] If true (the default)
then ValueEncoders are automatically provided for all Hibernate entities
(ValueEncoders are used
+ to encode the primary keys of entities as strings that can be included in
URLs). Set to false if you
+ want direct control over this feature.
+
+ [tapestry.hibernate.default-configuration] If true (the default), then the
application must include a <<<hibernate.cfg.xml>>> file. If your application
configures
+ itself entirely in code, you should set this symbol to false.
Modified:
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java?rev=693304&r1=693303&r2=693304&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurerFilterTest.java
Mon Sep 8 15:36:42 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -22,13 +22,27 @@
@Test
public class DefaultHibernateConfigurerFilterTest
{
- public void testConfigure() throws Exception
+ public void configure_with_default_configuration_on() throws Exception
{
Configuration config = createMock(Configuration.class);
expect(config.configure()).andReturn(config);
+
+ replay(config);
+
+ new DefaultHibernateConfigurer(true).configure(config);
+
+ verify(config);
+ }
+
+ public void configure_with_default_configuration_off() throws Exception
+ {
+ Configuration config = createMock(Configuration.class);
+
replay(config);
- new DefaultHibernateConfigurer().configure(config);
+
+ new DefaultHibernateConfigurer(false).configure(config);
+
verify(config);
}
}
Modified:
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java?rev=693304&r1=693303&r2=693304&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/internal/hibernate/HibernateSessionSourceImplTest.java
Mon Sep 8 15:36:42 2008
@@ -48,7 +48,7 @@
expect(packageManager.getPackageNames()).andReturn(packageNames);
List<HibernateConfigurer> filters = Arrays.asList(
- new DefaultHibernateConfigurer(),
+ new DefaultHibernateConfigurer(true),
new PackageNameHibernateConfigurer(packageManager,
new
ClassNameLocatorImpl(new ClasspathURLConverterImpl())));
@@ -94,5 +94,4 @@
assertTrue(e.getMessage().contains("immutable"));
}
}
-
}