tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject [3/5] git commit: Move the HibernateModule to a modules package
Date Thu, 16 May 2013 22:00:09 GMT
Move the HibernateModule to a modules package


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/43598e0a
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/43598e0a
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/43598e0a

Branch: refs/heads/master
Commit: 43598e0af84439e67ef2a8abb53e4a9176bd3277
Parents: 4fda4c8
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu May 16 14:35:33 2013 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu May 16 14:35:33 2013 -0700

----------------------------------------------------------------------
 tapestry-hibernate/build.gradle                    |    2 +-
 .../tapestry5/hibernate/HibernateModule.java       |  191 --------------
 .../hibernate/modules/HibernateModule.java         |  195 +++++++++++++++
 .../java/org/example/app0/services/AppModule.java  |    2 +-
 4 files changed, 197 insertions(+), 193 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/43598e0a/tapestry-hibernate/build.gradle
----------------------------------------------------------------------
diff --git a/tapestry-hibernate/build.gradle b/tapestry-hibernate/build.gradle
index 26bbae7..73a6658 100644
--- a/tapestry-hibernate/build.gradle
+++ b/tapestry-hibernate/build.gradle
@@ -12,6 +12,6 @@ dependencies {
 
 jar {
     manifest {
-        attributes 'Tapestry-Module-Classes': 'org.apache.tapestry5.hibernate.HibernateModule'
+        attributes 'Tapestry-Module-Classes': 'org.apache.tapestry5.hibernate.modules.HibernateModule'
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/43598e0a/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
----------------------------------------------------------------------
diff --git a/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
b/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
deleted file mode 100644
index 5d73516..0000000
--- a/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
+++ /dev/null
@@ -1,191 +0,0 @@
-// Copyright 2007-2013 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;
-
-import org.apache.tapestry5.ValueEncoder;
-import org.apache.tapestry5.internal.InternalConstants;
-import org.apache.tapestry5.internal.hibernate.CommitAfterWorker;
-import org.apache.tapestry5.internal.hibernate.EntityApplicationStatePersistenceStrategy;
-import org.apache.tapestry5.internal.hibernate.EntityPersistentFieldStrategy;
-import org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder;
-import org.apache.tapestry5.ioc.Configuration;
-import org.apache.tapestry5.ioc.LoggerSource;
-import org.apache.tapestry5.ioc.MappedConfiguration;
-import org.apache.tapestry5.ioc.OrderedConfiguration;
-import org.apache.tapestry5.ioc.annotations.Contribute;
-import org.apache.tapestry5.ioc.annotations.Primary;
-import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.services.PropertyAccess;
-import org.apache.tapestry5.ioc.services.ServiceOverride;
-import org.apache.tapestry5.ioc.services.TypeCoercer;
-import org.apache.tapestry5.services.ApplicationStateContribution;
-import org.apache.tapestry5.services.ApplicationStatePersistenceStrategy;
-import org.apache.tapestry5.services.PersistentFieldStrategy;
-import org.apache.tapestry5.services.ValueEncoderFactory;
-import org.apache.tapestry5.services.dashboard.DashboardManager;
-import org.apache.tapestry5.services.dashboard.DashboardTab;
-import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
-import org.hibernate.Session;
-import org.hibernate.mapping.PersistentClass;
-
-import java.util.Iterator;
-
-/**
- * Supplements the services defined by {@link org.apache.tapestry5.hibernate.modules.HibernateCoreModule}
with additional
- * services and configuration specific to Tapestry web application.
- */
-public class HibernateModule
-{
-    public static void contributeFactoryDefaults(MappedConfiguration<String, String>
configuration)
-    {
-        configuration.add(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS, "true");
-        configuration.add(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED,
"false");
-    }
-
-    /**
-     * Contributes the package "&lt;root&gt;.entities" to the configuration, so that
it will be scanned for annotated
-     * entity classes.
-     */
-    public static void contributeHibernateEntityPackageManager(Configuration<String>
configuration,
-
-    @Symbol(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM)
-    String appRootPackage)
-    {
-        configuration.add(appRootPackage + ".entities");
-    }
-
-    @Contribute(ServiceOverride.class)
-    public static void provideInjectableSessionObject(MappedConfiguration<Class, Object>
configuration, @HibernateCore
-    Session session)
-    {
-        configuration.add(Session.class, session);
-    }
-
-    /**
-     * Contributes {@link ValueEncoderFactory}s for all registered Hibernate entity classes.
Encoding and decoding are
-     * based on the id property value of the entity using type coercion. Hence, if the id
can be coerced to a String and
-     * back then the entity can be coerced.
-     */
-    @SuppressWarnings("unchecked")
-    public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory>
configuration,
-            @Symbol(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS)
-            boolean provideEncoders, final HibernateSessionSource sessionSource, final Session
session,
-            final TypeCoercer typeCoercer, final PropertyAccess propertyAccess, final LoggerSource
loggerSource)
-    {
-        if (!provideEncoders)
-            return;
-
-        org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
-        Iterator<PersistentClass> mappings = config.getClassMappings();
-        while (mappings.hasNext())
-        {
-            final PersistentClass persistentClass = mappings.next();
-            final Class entityClass = persistentClass.getMappedClass();
-
-            if (entityClass != null)
-            {
-                ValueEncoderFactory factory = new ValueEncoderFactory()
-                {
-                    public ValueEncoder create(Class type)
-                    {
-                        return new HibernateEntityValueEncoder(entityClass, persistentClass,
session, propertyAccess,
-                                typeCoercer, loggerSource.getLogger(entityClass));
-                    }
-                };
-
-                configuration.add(entityClass, factory);
-
-            }
-        }
-    }
-
-    /**
-     * Contributes the following:
-     * <dl>
-     * <dt>entity</dt>
-     * <dd>Stores the id of the entity and reloads from the {@link Session}</dd>
-     * </dl>
-     */
-    public static void contributePersistentFieldManager(
-            MappedConfiguration<String, PersistentFieldStrategy> configuration)
-    {
-        configuration.addInstance(HibernatePersistenceConstants.ENTITY, EntityPersistentFieldStrategy.class);
-    }
-
-    /**
-     * Contributes the following strategy:
-     * <dl>
-     * <dt>entity</dt>
-     * <dd>Stores the id of the entity and reloads from the {@link Session}</dd>
-     * </dl>
-     */
-    public void contributeApplicationStatePersistenceStrategySource(
-            MappedConfiguration<String, ApplicationStatePersistenceStrategy> configuration)
-    {
-        configuration
-                .addInstance(HibernatePersistenceConstants.ENTITY, EntityApplicationStatePersistenceStrategy.class);
-    }
-
-    /**
-     * Contributes {@link ApplicationStateContribution}s for all registered Hibernate entity
classes.
-     * 
-     * @param configuration
-     *            Configuration to contribute
-     * @param entitySessionStatePersistenceStrategyEnabled
-     *            indicates if contribution should take place
-     * @param sessionSource
-     *            creates Hibernate session
-     */
-    public static void contributeApplicationStateManager(
-            MappedConfiguration<Class, ApplicationStateContribution> configuration,
-            @Symbol(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED)
-            boolean entitySessionStatePersistenceStrategyEnabled, HibernateSessionSource
sessionSource)
-    {
-
-        if (!entitySessionStatePersistenceStrategyEnabled)
-            return;
-
-        org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
-        Iterator<PersistentClass> mappings = config.getClassMappings();
-        while (mappings.hasNext())
-        {
-
-            final PersistentClass persistentClass = mappings.next();
-            final Class entityClass = persistentClass.getMappedClass();
-
-            configuration.add(entityClass, new ApplicationStateContribution(HibernatePersistenceConstants.ENTITY));
-        }
-    }
-
-    /**
-     * Adds the CommitAfter annotation work, to process the
-     * {@link org.apache.tapestry5.hibernate.annotations.CommitAfter} annotation.
-     */
-    @Contribute(ComponentClassTransformWorker2.class)
-    @Primary
-    public static void provideCommitAfterAnnotationSupport(
-            OrderedConfiguration<ComponentClassTransformWorker2> configuration)
-    {
-        // If logging is enabled, we want logging to be the first advice, wrapping around
the commit advice.
-
-        configuration.addInstance("CommitAfter", CommitAfterWorker.class, "after:Log");
-    }
-
-    @Contribute(DashboardManager.class)
-    public static void provideHibernateDashboardTab(OrderedConfiguration<DashboardTab>
configuration)
-    {
-        configuration.add("HibernateStatistics", new DashboardTab("Hibernate", "core/HibernateStatistics"));
-    }
-}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/43598e0a/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/modules/HibernateModule.java
----------------------------------------------------------------------
diff --git a/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/modules/HibernateModule.java
b/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/modules/HibernateModule.java
new file mode 100644
index 0000000..a9fb486
--- /dev/null
+++ b/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/modules/HibernateModule.java
@@ -0,0 +1,195 @@
+// Copyright 2007-2013 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.modules;
+
+import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.hibernate.HibernateCore;
+import org.apache.tapestry5.hibernate.HibernatePersistenceConstants;
+import org.apache.tapestry5.hibernate.HibernateSessionSource;
+import org.apache.tapestry5.hibernate.HibernateSymbols;
+import org.apache.tapestry5.internal.InternalConstants;
+import org.apache.tapestry5.internal.hibernate.CommitAfterWorker;
+import org.apache.tapestry5.internal.hibernate.EntityApplicationStatePersistenceStrategy;
+import org.apache.tapestry5.internal.hibernate.EntityPersistentFieldStrategy;
+import org.apache.tapestry5.internal.hibernate.HibernateEntityValueEncoder;
+import org.apache.tapestry5.ioc.Configuration;
+import org.apache.tapestry5.ioc.LoggerSource;
+import org.apache.tapestry5.ioc.MappedConfiguration;
+import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.Primary;
+import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.ioc.services.PropertyAccess;
+import org.apache.tapestry5.ioc.services.ServiceOverride;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
+import org.apache.tapestry5.services.ApplicationStateContribution;
+import org.apache.tapestry5.services.ApplicationStatePersistenceStrategy;
+import org.apache.tapestry5.services.PersistentFieldStrategy;
+import org.apache.tapestry5.services.ValueEncoderFactory;
+import org.apache.tapestry5.services.dashboard.DashboardManager;
+import org.apache.tapestry5.services.dashboard.DashboardTab;
+import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
+import org.hibernate.Session;
+import org.hibernate.mapping.PersistentClass;
+
+import java.util.Iterator;
+
+/**
+ * Supplements the services defined by {@link org.apache.tapestry5.hibernate.modules.HibernateCoreModule}
with additional
+ * services and configuration specific to Tapestry web application.
+ */
+public class HibernateModule
+{
+    public static void contributeFactoryDefaults(MappedConfiguration<String, String>
configuration)
+    {
+        configuration.add(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS, "true");
+        configuration.add(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED,
"false");
+    }
+
+    /**
+     * Contributes the package "&lt;root&gt;.entities" to the configuration, so that
it will be scanned for annotated
+     * entity classes.
+     */
+    public static void contributeHibernateEntityPackageManager(Configuration<String>
configuration,
+
+                                                               @Symbol(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM)
+                                                               String appRootPackage)
+    {
+        configuration.add(appRootPackage + ".entities");
+    }
+
+    @Contribute(ServiceOverride.class)
+    public static void provideInjectableSessionObject(MappedConfiguration<Class, Object>
configuration, @HibernateCore
+    Session session)
+    {
+        configuration.add(Session.class, session);
+    }
+
+    /**
+     * Contributes {@link ValueEncoderFactory}s for all registered Hibernate entity classes.
Encoding and decoding are
+     * based on the id property value of the entity using type coercion. Hence, if the id
can be coerced to a String and
+     * back then the entity can be coerced.
+     */
+    @SuppressWarnings("unchecked")
+    public static void contributeValueEncoderSource(MappedConfiguration<Class, ValueEncoderFactory>
configuration,
+                                                    @Symbol(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS)
+                                                    boolean provideEncoders, final HibernateSessionSource
sessionSource, final Session session,
+                                                    final TypeCoercer typeCoercer, final
PropertyAccess propertyAccess, final LoggerSource loggerSource)
+    {
+        if (!provideEncoders)
+            return;
+
+        org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
+        Iterator<PersistentClass> mappings = config.getClassMappings();
+        while (mappings.hasNext())
+        {
+            final PersistentClass persistentClass = mappings.next();
+            final Class entityClass = persistentClass.getMappedClass();
+
+            if (entityClass != null)
+            {
+                ValueEncoderFactory factory = new ValueEncoderFactory()
+                {
+                    public ValueEncoder create(Class type)
+                    {
+                        return new HibernateEntityValueEncoder(entityClass, persistentClass,
session, propertyAccess,
+                                typeCoercer, loggerSource.getLogger(entityClass));
+                    }
+                };
+
+                configuration.add(entityClass, factory);
+
+            }
+        }
+    }
+
+    /**
+     * Contributes the following:
+     * <dl>
+     * <dt>entity</dt>
+     * <dd>Stores the id of the entity and reloads from the {@link Session}</dd>
+     * </dl>
+     */
+    public static void contributePersistentFieldManager(
+            MappedConfiguration<String, PersistentFieldStrategy> configuration)
+    {
+        configuration.addInstance(HibernatePersistenceConstants.ENTITY, EntityPersistentFieldStrategy.class);
+    }
+
+    /**
+     * Contributes the following strategy:
+     * <dl>
+     * <dt>entity</dt>
+     * <dd>Stores the id of the entity and reloads from the {@link Session}</dd>
+     * </dl>
+     */
+    public void contributeApplicationStatePersistenceStrategySource(
+            MappedConfiguration<String, ApplicationStatePersistenceStrategy> configuration)
+    {
+        configuration
+                .addInstance(HibernatePersistenceConstants.ENTITY, EntityApplicationStatePersistenceStrategy.class);
+    }
+
+    /**
+     * Contributes {@link ApplicationStateContribution}s for all registered Hibernate entity
classes.
+     *
+     * @param configuration
+     *         Configuration to contribute
+     * @param entitySessionStatePersistenceStrategyEnabled
+     *         indicates if contribution should take place
+     * @param sessionSource
+     *         creates Hibernate session
+     */
+    public static void contributeApplicationStateManager(
+            MappedConfiguration<Class, ApplicationStateContribution> configuration,
+            @Symbol(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED)
+            boolean entitySessionStatePersistenceStrategyEnabled, HibernateSessionSource
sessionSource)
+    {
+
+        if (!entitySessionStatePersistenceStrategyEnabled)
+            return;
+
+        org.hibernate.cfg.Configuration config = sessionSource.getConfiguration();
+        Iterator<PersistentClass> mappings = config.getClassMappings();
+        while (mappings.hasNext())
+        {
+
+            final PersistentClass persistentClass = mappings.next();
+            final Class entityClass = persistentClass.getMappedClass();
+
+            configuration.add(entityClass, new ApplicationStateContribution(HibernatePersistenceConstants.ENTITY));
+        }
+    }
+
+    /**
+     * Adds the CommitAfter annotation work, to process the
+     * {@link org.apache.tapestry5.hibernate.annotations.CommitAfter} annotation.
+     */
+    @Contribute(ComponentClassTransformWorker2.class)
+    @Primary
+    public static void provideCommitAfterAnnotationSupport(
+            OrderedConfiguration<ComponentClassTransformWorker2> configuration)
+    {
+        // If logging is enabled, we want logging to be the first advice, wrapping around
the commit advice.
+
+        configuration.addInstance("CommitAfter", CommitAfterWorker.class, "after:Log");
+    }
+
+    @Contribute(DashboardManager.class)
+    public static void provideHibernateDashboardTab(OrderedConfiguration<DashboardTab>
configuration)
+    {
+        configuration.add("HibernateStatistics", new DashboardTab("Hibernate", "core/HibernateStatistics"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/43598e0a/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
----------------------------------------------------------------------
diff --git a/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java b/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
index a2b24a6..0d8d994 100644
--- a/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
+++ b/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
@@ -15,10 +15,10 @@
 package org.example.app0.services;
 
 import org.apache.tapestry5.SymbolConstants;
-import org.apache.tapestry5.hibernate.HibernateModule;
 import org.apache.tapestry5.hibernate.HibernateSymbols;
 import org.apache.tapestry5.hibernate.HibernateTransactionDecorator;
 import org.apache.tapestry5.hibernate.modules.HibernateCoreModule;
+import org.apache.tapestry5.hibernate.modules.HibernateModule;
 import org.apache.tapestry5.ioc.MappedConfiguration;
 import org.apache.tapestry5.ioc.OrderedConfiguration;
 import org.apache.tapestry5.ioc.ServiceBinder;


Mime
View raw message