Author: drobiazko
Date: Mon Oct  5 21:20:30 2009
New Revision: 822020

URL: http://svn.apache.org/viewvc?rev=822020&view=rev
Log:
TAP5-790: Provide ApplicationStatePersistenceStrategy for Hibernate entities 

Added:
    
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java
   (with props)
    
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java
   (with props)
    tapestry/tapestry5/trunk/tapestry-hibernate/src/test/webapp/SSOEntity.tml
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
    
tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java
    
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernateModule.java
    tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt
    
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/hibernate/integration/TapestryHibernateIntegrationTests.java
    
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java?rev=822020&r1=822019&r2=822020&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategy.java
 Mon Oct  5 21:20:30 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.
@@ -33,7 +33,7 @@
         this.request = request;
     }
 
-    private Session getSession()
+    protected Session getSession()
     {
         return request.getSession(true);
     }
@@ -41,22 +41,27 @@
     @SuppressWarnings("unchecked")
     public <T> T get(Class<T> ssoClass, ApplicationStateCreator<T> creator)
     {
+        return (T) getOrCreate(ssoClass, creator);
+    }
+    
+    protected <T> Object getOrCreate(Class<T> ssoClass, 
ApplicationStateCreator<T> creator)
+    {
         Session session = getSession();
 
         String key = buildKey(ssoClass);
 
-        T sso = (T) session.getAttribute(key);
+        Object sso = session.getAttribute(key);
 
         if (sso == null)
         {
             sso = creator.create();
-            session.setAttribute(key, sso);
+            set(ssoClass, (T) sso);
         }
 
         return sso;
     }
 
-    private <T> String buildKey(Class<T> ssoClass)
+    protected <T> String buildKey(Class<T> ssoClass)
     {
         return PREFIX + ssoClass.getName();
     }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java?rev=822020&r1=822019&r2=822020&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/SessionApplicationStatePersistenceStrategyTest.java
 Mon Oct  5 21:20:30 2009
@@ -88,6 +88,7 @@
 
         train_create(creator, aso);
 
+        train_getSession(request, true, session);
         session.setAttribute(key, aso);
 
         // Then for exists() after

Modified: 
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=822020&r1=822019&r2=822020&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-hibernate-core/src/main/java/org/apache/tapestry5/hibernate/HibernateSymbols.java
 Mon Oct  5 21:20:30 2009
@@ -38,4 +38,11 @@
      * Override to "false" to handle entity value encoding explicitly.
      */
     public static final String PROVIDE_ENTITY_VALUE_ENCODERS = 
"tapestry.hibernate.provide-entity-value-encoders";
+
+    /**
+     * If true, then "entity" persistence strategy is used to store Hibernate 
entities as {...@code Session State Objects}.
+     * 
+     * @since 5.2.0.0
+     */
+    public static final String 
ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED = 
"tapestry.hibernate.entity-session-state-persistence-strategy-enabled";
 }

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=822020&r1=822019&r2=822020&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 Oct  5 21:20:30 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.
@@ -14,9 +14,12 @@
 
 package org.apache.tapestry5.hibernate;
 
+import java.util.Iterator;
+
 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;
@@ -28,6 +31,8 @@
 import org.apache.tapestry5.ioc.services.PropertyAccess;
 import org.apache.tapestry5.ioc.services.TypeCoercer;
 import org.apache.tapestry5.services.AliasContribution;
+import org.apache.tapestry5.services.ApplicationStateContribution;
+import org.apache.tapestry5.services.ApplicationStatePersistenceStrategy;
 import org.apache.tapestry5.services.ComponentClassTransformWorker;
 import org.apache.tapestry5.services.LibraryMapping;
 import org.apache.tapestry5.services.PersistentFieldStrategy;
@@ -35,8 +40,6 @@
 import org.hibernate.Session;
 import org.hibernate.mapping.PersistentClass;
 
-import java.util.Iterator;
-
 /**
  * Supplements the services defined by {...@link 
org.apache.tapestry5.hibernate.HibernateCoreModule} with additional
  * services and configuration specific to Tapestry web application.
@@ -46,7 +49,8 @@
 {
     public static void contributeFactoryDefaults(MappedConfiguration<String, 
String> configuration)
     {
-        
configuration.add(HibernateConstants.PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL, 
"true");
+        configuration.add(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS, 
"true");
+        
configuration.add(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED,
 "false");
     }
 
     /**
@@ -76,7 +80,7 @@
      */
     @SuppressWarnings("unchecked")
     public static void contributeValueEncoderSource(MappedConfiguration<Class, 
ValueEncoderFactory> configuration,
-                                                    
@Symbol(HibernateConstants.PROVIDE_ENTITY_VALUE_ENCODERS_SYMBOL)
+                                                    
@Symbol(HibernateSymbols.PROVIDE_ENTITY_VALUE_ENCODERS)
                                                     boolean provideEncoders,
                                                     final 
HibernateSessionSource sessionSource,
                                                     final Session session,
@@ -113,7 +117,45 @@
     public static void contributePersistentFieldManager(
             MappedConfiguration<String, PersistentFieldStrategy> configuration)
     {
-        configuration.addInstance("entity", 
EntityPersistentFieldStrategy.class);
+        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));
+        }
     }
 
     /**

Added: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java?rev=822020&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java
 Mon Oct  5 21:20:30 2009
@@ -0,0 +1,31 @@
+// 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;
+
+import org.apache.tapestry5.PersistenceConstants;
+
+/**
+ * Constants for persistent field strategies.
+ *
+ * @see org.apache.tapestry5.annotations.Persist#value()
+ * 
+ * @since 5.2.0
+ */
+public class HibernatePersistenceConstants extends PersistenceConstants 
+{
+    /**
+     * If the field's value is a Hibernate entity its primary is stored in the 
{...@link org.apache.tapestry5.services.Session}.
+     */
+    public static final String ENTITY = "entity";
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/hibernate/HibernatePersistenceConstants.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java?rev=822020&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java
 Mon Oct  5 21:20:30 2009
@@ -0,0 +1,91 @@
+// 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.internal.hibernate;
+
+import java.io.Serializable;
+
+import 
org.apache.tapestry5.internal.services.SessionApplicationStatePersistenceStrategy;
+import org.apache.tapestry5.services.ApplicationStateCreator;
+import org.apache.tapestry5.services.Request;
+import org.hibernate.HibernateException;
+
+/**
+ * Persists Hibernate entities as SSOs by storing their primary key in the 
{...@link org.apache.tapestry5.services.Session}.
+ * 
+ * @see org.apache.tapestry5.internal.hibernate.PersistedEntity
+ */
+public class EntityApplicationStatePersistenceStrategy extends 
SessionApplicationStatePersistenceStrategy 
+{
+
+       private final org.hibernate.Session hibernateSession;
+
+       public EntityApplicationStatePersistenceStrategy(Request request, 
org.hibernate.Session hibernateSession) 
+       {
+               super(request);
+               this.hibernateSession = hibernateSession;
+       }
+
+       @SuppressWarnings("unchecked")
+       public <T> T get(Class<T> ssoClass, ApplicationStateCreator<T> creator) 
+       {
+               final Object persistedValue =  getOrCreate(ssoClass, creator);
+               
+               if(persistedValue instanceof PersistedEntity)
+               {
+                       final PersistedEntity persisted = (PersistedEntity) 
persistedValue;
+                       
+                       Object restored = 
persisted.restore(this.hibernateSession);
+                       
+                       //shall we maybe throw an exception instead?
+                       if(restored == null)
+                       {
+                               set(ssoClass, null);
+                               return (T) getOrCreate(ssoClass, creator);
+                       }
+
+                       return (T) restored;
+               }
+               
+               return (T) persistedValue;
+       }
+
+       public <T> void set(Class<T> ssoClass, T sso) 
+       {       
+               final String key = buildKey(ssoClass);
+               Object entity;
+               
+               if(sso != null)
+               {
+                       try 
+                       {
+                               final String entityName = 
this.hibernateSession.getEntityName(sso);
+                               final Serializable id = 
this.hibernateSession.getIdentifier(sso);
+       
+                               entity = new PersistedEntity(entityName, id);
+                       } 
+                       catch (final HibernateException ex) 
+                       {
+                               // if entity not attached to a Hibernate 
Session yet, store it as usual sso
+                               entity = sso;
+                       }
+               }
+               else
+               {
+                       entity = sso;
+               }
+               
+               getSession().setAttribute(key, entity);
+       }
+
+}
\ No newline at end of file

Propchange: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt?rev=822020&r1=822019&r2=822020&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt 
(original)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/site/apt/userguide.apt Mon 
Oct  5 21:20:30 2009
@@ -74,6 +74,49 @@
   
   This persistence strategy works with any Hibernate entity that is associated 
with a valid Hibernate Session by persisting only the id
   of the entity. Notice that no onPassivate() method is needed; when the page 
renders the entity is loaded by the id stored in the session.
+  
+Using @SessionState with entities
+
+  The default strategy for persisting Session State Objects is "session". 
Storing a Hibernate entity into a <HttpSession> is problematic 
+  because the stored entity is detached from the Hibernate session. Similar to 
@Persist("entity") you may use the "entity" persistence 
+  strategy to persist Hibernate entities as SSOs:
+  
++----+
+public class Index
+{
+  @SessionState
+  @Property
+  private Person person;
+  
+  ...
+  
+}
++----+  
+
+       For this purpose you need to set the value of the symbol 
<HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED> 
+       to <true>:
+       
++----+
+public class AppModule
+{
+    public static void 
contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
+    {
+        
configuration.add(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED,
 "true");
+    }
+}
++----+  
+
+       Alternatively you can apply the "entity" persistence strategy to a 
single Hibernate entity:
+       
++----+
+public class AppModule
+{
+    public void contributeApplicationStateManager(MappedConfiguration<Class, 
ApplicationStateContribution> configuration)
+    {
+       configuration.add(Person.class, new 
ApplicationStateContribution(HibernatePersistenceConstants.ENTITY));
+    }
+}
++----+  
 
 Committing Changes
 

Modified: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/hibernate/integration/TapestryHibernateIntegrationTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/hibernate/integration/TapestryHibernateIntegrationTests.java?rev=822020&r1=822019&r2=822020&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/hibernate/integration/TapestryHibernateIntegrationTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/apache/tapestry5/hibernate/integration/TapestryHibernateIntegrationTests.java
 Mon Oct  5 21:20:30 2009
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.hibernate.integration;
 
+import org.apache.tapestry5.internal.hibernate.PersistedEntity;
 import org.apache.tapestry5.test.AbstractIntegrationTestSuite;
 import org.example.app0.entities.User;
 import org.testng.annotations.Test;
@@ -67,6 +68,35 @@
         clickAndWait("link=set to transient");
         assertTextPresent("Error persisting");
     }
+    
+    public void sso_entities()
+    {
+       open("/ssoentity");
+        assertEquals(0, getText("//sp...@id='name']").length());
+        assertText("//sp...@id='persistedEntityClassName']", 
User.class.getName());
+        
+        clickAndWait("link=persist entity");
+        assertText("//sp...@id='name']", "name");
+        assertText("//sp...@id='persistedEntityClassName']", 
PersistedEntity.class.getName());
+        
+        // can set back to null
+        clickAndWait("link=set to null");
+        assertEquals(getText("//sp...@id='name']").length(), 0);
+        assertText("//sp...@id='persistedEntityClassName']", 
User.class.getName());
+        
+        clickAndWait("link=persist entity");
+        assertText("//sp...@id='name']", "name");
+        assertText("//sp...@id='persistedEntityClassName']", 
PersistedEntity.class.getName());
+        clickAndWait("link=delete");
+        assertEquals(getText("//sp...@id='name']").length(), 0);
+        assertText("//sp...@id='persistedEntityClassName']", 
User.class.getName());
+        
+        clickAndWait("link=persist entity");
+        assertText("//sp...@id='name']", "name");
+        assertText("//sp...@id='persistedEntityClassName']", 
PersistedEntity.class.getName());
+        clickAndWait("link=set to transient");
+        assertText("//sp...@id='persistedEntityClassName']", 
User.class.getName());
+    }
 
     /**
      * TAPESTRY-2244
@@ -105,7 +135,6 @@
 
     }
 
-
     public void grid()
     {
         start("Grid Demo", "setup");
@@ -119,8 +148,6 @@
         assertText("//t...@class='firstName t-sort-column-descending']", 
"Joe_9");
     }
     
-
-    @Test
     public void hibernate_statistics()
     {
        open(BASE_URL + "hibernate/Statistics");

Added: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java?rev=822020&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java
 Mon Oct  5 21:20:30 2009
@@ -0,0 +1,78 @@
+// 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.example.app0.pages;
+
+import java.util.List;
+
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.annotations.SessionState;
+import org.apache.tapestry5.internal.hibernate.PersistedEntity;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.Request;
+import org.apache.tapestry5.services.Session;
+import org.example.app0.entities.User;
+import org.example.app0.services.UserDAO;
+
+public class SSOEntity 
+{
+    @SessionState
+    @Property
+    private User user;
+
+    @Inject
+    private UserDAO userDAO;
+    
+    @Inject
+    private Request request;
+    
+    void onPersistEntity()
+    {
+        User user = new User();
+        user.setFirstName("name");
+
+        userDAO.add(user);
+
+        this.user = user;
+    }
+    
+    void onSetToNull()
+    {
+        user = null;
+    }
+    
+    void onSetToTransient()
+    {
+        user = new User();
+    }
+    
+    void onDelete()
+    {
+        List<User> users = userDAO.findAll();
+
+        userDAO.delete(users.toArray(new User[0]));
+        System.err.println("DELETED");
+    }
+    
+    public String getPersistedEntityClassName()
+    {
+       Session session = request.getSession(true);
+       
+       Object value = session.getAttribute("sso:"+User.class.getName());
+       
+       System.err.println("getPersistedEntityClassName(): "+value);
+       
+       return value.getClass().getName();
+    }
+}

Propchange: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/pages/SSOEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java?rev=822020&r1=822019&r2=822020&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-hibernate/src/test/java/org/example/app0/services/AppModule.java
 Mon Oct  5 21:20:30 2009
@@ -16,6 +16,7 @@
 
 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.ioc.MappedConfiguration;
 import org.apache.tapestry5.ioc.ServiceBinder;
@@ -33,6 +34,7 @@
     public static void 
contributeApplicationDefaults(MappedConfiguration<String, String> configuration)
     {
         configuration.add(SymbolConstants.PRODUCTION_MODE, "false");
+        
configuration.add(HibernateSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED,
 "true");
     }
 
     @Match("*DAO")

Added: tapestry/tapestry5/trunk/tapestry-hibernate/src/test/webapp/SSOEntity.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-hibernate/src/test/webapp/SSOEntity.tml?rev=822020&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-hibernate/src/test/webapp/SSOEntity.tml 
(added)
+++ tapestry/tapestry5/trunk/tapestry-hibernate/src/test/webapp/SSOEntity.tml 
Mon Oct  5 21:20:30 2009
@@ -0,0 +1,10 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";>
+<body>
+       <p>entity name: <span id="name">${user?.firstName}</span></p>
+       <p>persisted entity class name: <span 
id="persistedEntityClassName">${persistedEntityClassName}</span></p>
+       <p><t:eventlink event="persistEntity">persist entity</t:eventlink></p>
+       <p><t:eventlink event="setToNull">set to null</t:eventlink></p>
+       <p><t:eventlink event="setToTransient">set to 
transient</t:eventlink></p>
+       <p><t:eventlink event="delete">delete</t:eventlink></p>
+</body>
+</html>
\ No newline at end of file


Reply via email to