Updated Branches: refs/heads/master e26d6e312 -> c83d91bca
Reformat code Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/1a54c61d Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/1a54c61d Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/1a54c61d Branch: refs/heads/master Commit: 1a54c61dd9f6537c3740126cca59a19b9b1afb7a Parents: e26d6e3 Author: Howard M. Lewis Ship <[email protected]> Authored: Wed Feb 5 11:54:38 2014 -0500 Committer: Howard M. Lewis Ship <[email protected]> Committed: Wed Feb 5 11:54:56 2014 -0500 ---------------------------------------------------------------------- ...tityApplicationStatePersistenceStrategy.java | 127 +++++++++---------- 1 file changed, 63 insertions(+), 64 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1a54c61d/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java ---------------------------------------------------------------------- diff --git a/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java b/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java index 4a3f0ab..f6a4eaa 100644 --- a/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java +++ b/tapestry-hibernate/src/main/java/org/apache/tapestry5/internal/hibernate/EntityApplicationStatePersistenceStrategy.java @@ -1,4 +1,4 @@ -// Copyright 2009 The Apache Software Foundation +// Copyright 2009, 2014 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. @@ -11,81 +11,80 @@ // 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; +package org.apache.tapestry5.internal.hibernate; import org.apache.tapestry5.internal.services.SessionApplicationStatePersistenceStrategy; import org.apache.tapestry5.services.ApplicationStateCreator; import org.apache.tapestry5.services.Request; import org.hibernate.HibernateException; +import java.io.Serializable; + /** * 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 +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); - } + 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
