Author: pete.muir(a)jboss.org
Date: 2008-03-31 12:03:04 -0400 (Mon, 31 Mar 2008)
New Revision: 7760
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/Entity.java
branches/Seam_2_0/src/main/org/jboss/seam/Seam.java
branches/Seam_2_0/src/main/org/jboss/seam/contexts/PassivatedEntity.java
branches/Seam_2_0/src/main/org/jboss/seam/contexts/ServerConversationContext.java
branches/Seam_2_0/src/main/org/jboss/seam/contexts/SessionContext.java
branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
branches/Seam_2_0/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java
branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
Log:
Move stuff around
Modified: branches/Seam_2_0/src/main/org/jboss/seam/Entity.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/Entity.java 2008-03-31 14:12:25 UTC (rev
7759)
+++ branches/Seam_2_0/src/main/org/jboss/seam/Entity.java 2008-03-31 16:03:04 UTC (rev
7760)
@@ -15,7 +15,6 @@
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.init.EjbDescriptor;
import org.jboss.seam.init.EjbEntityDescriptor;
-import org.jboss.seam.persistence.PersistenceProvider;
import org.jboss.seam.util.Reflections;
/**
@@ -42,7 +41,10 @@
/**
*
* @param beanClass
+ *
+ * Use Entity.forBean() or Entity.forClass
*/
+ @Deprecated
public Entity(Class<?> beanClass)
{
super(beanClass);
@@ -137,30 +139,30 @@
{
return name;
}
-
+
public static Entity forBean(Object bean)
{
+ return forClass(bean.getClass());
+ }
+
+ public static Entity forClass(Class clazz)
+ {
if (!Contexts.isApplicationContextActive())
{
throw new IllegalStateException("No application context active");
}
+
+ Class entityClass = Seam.getEntityClass(clazz);
- Class beanClass = PersistenceProvider.instance().getBeanClass(bean);
-
- if (beanClass == null)
+ if (entityClass == null)
{
- throw new NotEntityException("Not an entity class: " +
bean.getClass().getName());
+ throw new NotEntityException("Not an entity class: " +
clazz.getName());
}
- return forBeanClass(beanClass);
- }
-
- private static Entity forBeanClass(Class beanClass)
- {
- String name = getModelName(beanClass);
+ String name = getModelName(clazz);
Model model = (Model) Contexts.getApplicationContext().get(name);
if (model == null || !(model instanceof Entity))
{
- Entity entity = new Entity(beanClass);
+ Entity entity = new Entity(clazz);
Contexts.getApplicationContext().set(name, entity);
return entity;
}
@@ -169,24 +171,7 @@
return (Entity) model;
}
}
-
- @Deprecated
- public static Entity forClass(Class clazz)
- {
- if (!Contexts.isApplicationContextActive())
- {
- throw new IllegalStateException("No application context active");
- }
- Class entityClass = PersistenceProvider.getEntityClass(clazz);
-
- if (entityClass == null)
- {
- throw new NotEntityException("Not an entity class: " +
clazz.getName());
- }
- return forBeanClass(entityClass);
- }
-
private void mergeAnnotationAndOrmXml(EjbEntityDescriptor descriptor)
{
// Lookup the name of the Entity from XML, annotation or default
Modified: branches/Seam_2_0/src/main/org/jboss/seam/Seam.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/Seam.java 2008-03-31 14:12:25 UTC (rev
7759)
+++ branches/Seam_2_0/src/main/org/jboss/seam/Seam.java 2008-03-31 16:03:04 UTC (rev
7760)
@@ -24,7 +24,6 @@
import org.jboss.seam.contexts.Lifecycle;
import org.jboss.seam.init.EjbDescriptor;
import org.jboss.seam.init.DeploymentDescriptor;
-import org.jboss.seam.persistence.PersistenceProvider;
import org.jboss.seam.util.Strings;
import org.jboss.seam.web.Session;
@@ -151,19 +150,35 @@
* Get the bean class from a container-generated proxy
* class
*
- * Use PersistenceProvider.instance().getBeanClass(bean) instead
*/
- @Deprecated
- public static Class getEntityClass(Class<?> clazz)
+ public static Class getEntityClass(Class clazz)
{
- return PersistenceProvider.getEntityClass(clazz);
- }
+ while (clazz != null && !Object.class.equals(clazz))
+ {
+ if (clazz.isAnnotationPresent(Entity.class))
+ {
+ return clazz;
+ }
+ else
+ {
+ EjbDescriptor ejbDescriptor = Seam.getEjbDescriptor(clazz.getName());
+ if (ejbDescriptor != null)
+ {
+ return ejbDescriptor.getBeanType() == ComponentType.ENTITY_BEAN ? clazz :
null;
+ }
+ else
+ {
+ clazz = clazz.getSuperclass();
+ }
+ }
+ }
+ return null;
+ }
/**
* Is the class a container-generated proxy class for an
* entity bean?
*/
- @Deprecated
public static boolean isEntityClass(Class<?> clazz)
{
return getEntityClass(clazz)!=null;
Modified: branches/Seam_2_0/src/main/org/jboss/seam/contexts/PassivatedEntity.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/contexts/PassivatedEntity.java 2008-03-31
14:12:25 UTC (rev 7759)
+++ branches/Seam_2_0/src/main/org/jboss/seam/contexts/PassivatedEntity.java 2008-03-31
16:03:04 UTC (rev 7760)
@@ -6,6 +6,7 @@
import org.hibernate.Session;
import org.jboss.seam.Component;
+import org.jboss.seam.Seam;
import org.jboss.seam.persistence.HibernatePersistenceProvider;
import org.jboss.seam.persistence.PersistenceContexts;
import org.jboss.seam.persistence.PersistenceProvider;
@@ -151,7 +152,7 @@
public static PassivatedEntity passivateEntity(Object value)
{
- Class entityClass = PersistenceProvider.getEntityClass(value.getClass());
+ Class entityClass = Seam.getEntityClass(value.getClass());
if (entityClass!=null)
{
for ( String persistenceContextName:
PersistenceContexts.instance().getTouchedContexts() )
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/contexts/ServerConversationContext.java
===================================================================
---
branches/Seam_2_0/src/main/org/jboss/seam/contexts/ServerConversationContext.java 2008-03-31
14:12:25 UTC (rev 7759)
+++
branches/Seam_2_0/src/main/org/jboss/seam/contexts/ServerConversationContext.java 2008-03-31
16:03:04 UTC (rev 7760)
@@ -15,9 +15,9 @@
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.Seam;
import org.jboss.seam.core.Events;
import org.jboss.seam.core.Manager;
-import org.jboss.seam.persistence.PersistenceProvider;
/**
* A conversation context is a logical context that lasts longer than
@@ -155,7 +155,7 @@
else
{
removals.remove(name);
- if ( PersistenceProvider.getEntityClass(value.getClass()) != null )
+ if ( Seam.getEntityClass(value.getClass()) != null )
{
value = new EntityBean(value);
}
Modified: branches/Seam_2_0/src/main/org/jboss/seam/contexts/SessionContext.java
===================================================================
--- branches/Seam_2_0/src/main/org/jboss/seam/contexts/SessionContext.java 2008-03-31
14:12:25 UTC (rev 7759)
+++ branches/Seam_2_0/src/main/org/jboss/seam/contexts/SessionContext.java 2008-03-31
16:03:04 UTC (rev 7760)
@@ -10,7 +10,7 @@
import java.util.Map;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.persistence.PersistenceProvider;
+import org.jboss.seam.Seam;
/**
* Session context - state associated with a user session.
@@ -48,7 +48,7 @@
{
Object attribute = get(name);
boolean dirty = attribute!=null &&
- ( Contexts.isAttributeDirty(attribute) ||
PersistenceProvider.getEntityClass(attribute.getClass()) != null );
+ ( Contexts.isAttributeDirty(attribute) ||
Seam.getEntityClass(attribute.getClass()) != null );
if ( dirty )
{
set(name, attribute);
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
---
branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-31
14:12:25 UTC (rev 7759)
+++
branches/Seam_2_0/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java 2008-03-31
16:03:04 UTC (rev 7760)
@@ -18,6 +18,7 @@
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.type.VersionType;
import org.jboss.seam.Component;
+import org.jboss.seam.Entity;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
@@ -317,7 +318,7 @@
public static Class getEntityClass(Object bean)
{
- Class clazz = PersistenceProvider.getEntityClass(bean.getClass());
+ Class clazz = Entity.forBean(bean).getBeanClass();
if (clazz == null)
{
clazz = Hibernate.getClass(bean);
Modified:
branches/Seam_2_0/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java
===================================================================
---
branches/Seam_2_0/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java 2008-03-31
14:12:25 UTC (rev 7759)
+++
branches/Seam_2_0/src/main/org/jboss/seam/persistence/ManagedEntityIdentityInterceptor.java 2008-03-31
16:03:04 UTC (rev 7760)
@@ -10,6 +10,7 @@
import java.util.Map;
import java.util.Set;
+import org.jboss.seam.Seam;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.intercept.AroundInvoke;
import org.jboss.seam.annotations.intercept.Interceptor;
@@ -139,7 +140,7 @@
return value instanceof List ||
value instanceof Map ||
value instanceof Set ||
- PersistenceProvider.getEntityClass(value.getClass()) != null;
+ Seam.getEntityClass(value.getClass()) != null;
}
private Object getFieldValue(Object bean, Field field) throws Exception
Modified: branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java
===================================================================
---
branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2008-03-31
14:12:25 UTC (rev 7759)
+++
branches/Seam_2_0/src/main/org/jboss/seam/persistence/PersistenceProvider.java 2008-03-31
16:03:04 UTC (rev 7760)
@@ -9,15 +9,12 @@
import javax.transaction.Synchronization;
import org.jboss.seam.Component;
-import org.jboss.seam.ComponentType;
import org.jboss.seam.Entity;
import org.jboss.seam.ScopeType;
-import org.jboss.seam.Seam;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
-import org.jboss.seam.init.EjbDescriptor;
/**
* Abstraction layer for persistence providers (JPA implementations).
* This class provides a working base implementation that can be
@@ -151,33 +148,9 @@
*/
public Class getBeanClass(Object bean)
{
- return getEntityClass(bean.getClass());
+ return Entity.forBean(bean).getBeanClass();
}
- public static Class getEntityClass(Class clazz)
- {
- while (clazz != null && !Object.class.equals(clazz))
- {
- if (clazz.isAnnotationPresent(Entity.class))
- {
- return clazz;
- }
- else
- {
- EjbDescriptor ejbDescriptor = Seam.getEjbDescriptor(clazz.getName());
- if (ejbDescriptor != null)
- {
- return ejbDescriptor.getBeanType() == ComponentType.ENTITY_BEAN ? clazz :
null;
- }
- else
- {
- clazz = clazz.getSuperclass();
- }
- }
- }
- return null;
- }
-
public Method getPostLoadMethod(Object bean, EntityManager entityManager)
{
return Entity.forBean(bean).getPostLoadMethod();
Show replies by date