You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2009/01/08 04:56:07 UTC

svn commit: r732600 - in /tapestry/tapestry5/trunk: tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/ tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/ tapestry-hibernate-core/src/site/apt/ tapestry-ioc/...

Author: hlship
Date: Wed Jan  7 19:56:06 2009
New Revision: 732600

URL: http://svn.apache.org/viewvc?rev=732600&view=rev
Log:
TAP5-295: Option to startup Hibernate early, rather than lazily on first request

Added:
    tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java
Modified:
    tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java
    tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java
    tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
    tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java

Modified: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java?rev=732600&r1=732599&r2=732600&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateConstants.java Wed Jan  7 19:56:06 2009
@@ -1,4 +1,4 @@
-//  Copyright 2008 The Apache Software Foundation
+//  Copyright 2008, 2009 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.
@@ -20,15 +20,12 @@
 public class HibernateConstants
 {
     /**
-     * If true (the default), then {@link org.apache.tapestry5.ValueEncoder}s are automatically created for each entity.
-     * Override to "false" to handle entity value encoding explicitly.
+     * @deprecated Use {@link org.apache.tapestry5.hibernate.HibernateSymbols#PROVIDE_ENTITY_VALUE_ENCODERS} instead.
      */
-    public static final String PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL = "tapestry.hibernate.provide-entity-value-encoders";
+    public static final String PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL = HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS;
 
     /**
-     * If true, then the last {@link org.apache.tapestry5.hibernate.HibernateConfigurer} will invoke {@link
-     * 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.
+     * @deprecated Use {@link org.apache.tapestry5.hibernate.HibernateSymbols#DEFAULT_CONFIGURATION} instead
      */
-    public static final String DEFAULT_CONFIGURATION = "tapestry.hibernate.default-configuration";
+    public static final String DEFAULT_CONFIGURATION = HibernateSymbols.DEFAULT_CONFIGURATION;
 }

Modified: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java?rev=732600&r1=732599&r2=732600&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateCoreModule.java Wed Jan  7 19:56:06 2009
@@ -1,4 +1,4 @@
-// Copyright 2008 The Apache Software Foundation
+// Copyright 2008, 2009 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.
@@ -19,8 +19,10 @@
 import org.apache.tapestry5.ioc.OrderedConfiguration;
 import org.apache.tapestry5.ioc.ScopeConstants;
 import org.apache.tapestry5.ioc.ServiceBinder;
+import org.apache.tapestry5.ioc.annotations.Local;
 import org.apache.tapestry5.ioc.annotations.Marker;
 import org.apache.tapestry5.ioc.annotations.Scope;
+import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.ioc.services.PropertyShadowBuilder;
 import org.apache.tapestry5.ioc.services.RegistryShutdownHub;
@@ -47,7 +49,25 @@
 
     public static void contributeFactoryDefaults(MappedConfiguration<String, String> configuration)
     {
-        configuration.add(HibernateConstants.DEFAULT_CONFIGURATION, "true");
+        configuration.add(HibernateSymbols.DEFAULT_CONFIGURATION, "true");
+        configuration.add(HibernateSymbols.EARLY_START_UP, "false");
+    }
+
+    public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration,
+
+                                                 @Symbol(HibernateSymbols.EARLY_START_UP)
+                                                 final boolean earlyStartup,
+
+                                                 final HibernateSessionSource sessionSource)
+    {
+        configuration.add("HibernateStartup", new Runnable()
+        {
+            public void run()
+            {
+                if (earlyStartup)
+                    sessionSource.getConfiguration();
+            }
+        });
     }
 
     public static HibernateEntityPackageManager buildHibernateEntityPackageManager(
@@ -112,6 +132,7 @@
      */
     public static void contributeHibernateSessionSource(OrderedConfiguration<HibernateConfigurer> config,
 
+                                                        @Local
                                                         HibernateConfigurer defaultHibernateConfigurer)
     {
         config.add("Default", defaultHibernateConfigurer);

Added: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java?rev=732600&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java (added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java Wed Jan  7 19:56:06 2009
@@ -0,0 +1,41 @@
+// Copyright 2009 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;
+
+/**
+ * Configuration symbols, for use with contributions to {@link org.apache.tapestry5.ioc.services.ApplicationDefaults}.
+ *
+ * @since 5.1.0.0
+ */
+public class HibernateSymbols
+{
+    /**
+     * If "true", then Hibernate will be started up at application launch, rather than lazily.
+     */
+    public static final String EARLY_START_UP = "tapestry.hibernate.early-startup";
+
+    /**
+     * If true, then the last {@link org.apache.tapestry5.hibernate.HibernateConfigurer} will invoke {@link
+     * 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";
+
+    /**
+     * If true (the default), then {@link 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 = "tapestry.hibernate.provide-entity-value-encoders";
+}

Modified: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java?rev=732600&r1=732599&r2=732600&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/internal/hibernate/DefaultHibernateConfigurer.java Wed Jan  7 19:56:06 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2009 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.
@@ -15,7 +15,7 @@
 package org.apache.tapestry5.internal.hibernate;
 
 import org.apache.tapestry5.hibernate.HibernateConfigurer;
-import org.apache.tapestry5.hibernate.HibernateConstants;
+import org.apache.tapestry5.hibernate.HibernateSymbols;
 import org.apache.tapestry5.ioc.annotations.Symbol;
 import org.hibernate.cfg.Configuration;
 
@@ -27,7 +27,7 @@
     private final boolean defaultConfiguration;
 
     public DefaultHibernateConfigurer(
-            @Symbol(HibernateConstants.DEFAULT_CONFIGURATION)
+            @Symbol(HibernateSymbols.DEFAULT_CONFIGURATION)
             boolean defaultConfiguration)
     {
         this.defaultConfiguration = defaultConfiguration;

Modified: tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt?rev=732600&r1=732599&r2=732600&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt (original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate-core/src/site/apt/conf.apt Wed Jan  7 19:56:06 2009
@@ -66,3 +66,7 @@
 
   [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.
+
+  [tapestry.hibernate.early-startup]
+  If "true", the Hibernate is initialized when the application starts up.  The default is "false", to start Hibernate up lazily, on
+  first use.

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java?rev=732600&r1=732599&r2=732600&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/IntegrationTest.java Wed Jan  7 19:56:06 2009
@@ -1276,7 +1276,7 @@
         catch (RuntimeException ex)
         {
             assertMessageContains(ex,
-                                  "Error invoking service contribution method org.apache.tapestry5.ioc.ConfigurationOverrideModule.contributeStringLookup(MappedConfiguration)",
+                                  "Error invoking service contribution method",
                                   "Contribution key fred has already been overridden");
         }
     }