Java Doc for PersistenceAnnotationBeanPostProcessor.java in  » J2EE » spring-framework-2.5 » org » springframework » orm » jpa » support » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.5 » org.springframework.orm.jpa.support 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.springframework.jndi.JndiLocatorSupport
   org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor

PersistenceAnnotationBeanPostProcessor
public class PersistenceAnnotationBeanPostProcessor extends JndiLocatorSupport implements InstantiationAwareBeanPostProcessor,DestructionAwareBeanPostProcessor,PriorityOrdered,BeanFactoryAware,Serializable(Code)
BeanPostProcessor that processes javax.persistence.PersistenceUnit and javax.persistence.PersistenceContext annotations, for injection of the corresponding JPA resources javax.persistence.EntityManagerFactory and javax.persistence.EntityManager . Any such annotated fields or methods in any Spring-managed object will automatically be injected.

This post-processor will inject sub-interfaces of EntityManagerFactory and EntityManager if the annotated fields or methods are declared as such. The actual type will be verified early, with the exception of a shared ("transactional") EntityManager reference, where type mismatches might be detected as late as on the first actual invocation.

Note: In the present implementation, PersistenceAnnotationBeanPostProcessor only supports @PersistenceUnit and @PersistenceContext with the "unitName" attribute, or no attribute at all (for the default unit). If those annotations are present with the "name" attribute at the class level, they will simply be ignored, since those only serve as deployment hint (as per the Java EE 5 specification).

This post-processor can either obtain EntityManagerFactory beans defined in the Spring application context (the default), or obtain EntityManagerFactory references from JNDI ("persistence unit references"). In the bean case, the persistence unit name will be matched against the actual deployed unit, with the bean name used as fallback unit name if no deployed name found. Typically, Spring's org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean will be used for setting up such EntityManagerFactory beans. Alternatively, such beans may also be obtained from JNDI, e.g. using the jee:jndi-lookup XML configuration element (with the bean name matching the requested unit name). In both cases, the post-processor definition will look as simple as this:

 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
In the JNDI case, specify the corresponding JNDI names in this post-processor's PersistenceAnnotationBeanPostProcessor.setPersistenceUnits "persistenceUnits" map , typically with matching persistence-unit-ref entries in the Java EE deployment descriptor. By default, those names are considered as resource references (according to the Java EE resource-ref convention), located underneath the "java:comp/env/" namespace. For example:
 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
 <property name="persistenceUnits">
 <map/gt;
 <entry key="unit1" value="persistence/unit1"/>
 <entry key="unit2" value="persistence/unit2"/>
 </map/gt;
 </property>
 </bean>
In this case, the specified persistence units will always be resolved in JNDI rather than as Spring-defined beans. The entire persistence unit deployment, including the weaving of persistent classes, is then up to the Java EE server. Persistence contexts (i.e. EntityManager references) will be built based on those server-provided EntityManagerFactory references, using Spring's own transaction synchronization facilities for transactional EntityManager handling (typically with Spring's @Transactional annotation for demarcation and org.springframework.transaction.jta.JtaTransactionManager as backend).

If you prefer the Java EE server's own EntityManager handling, specify entries in this post-processor's PersistenceAnnotationBeanPostProcessor.setPersistenceContexts "persistenceContexts" map (or PersistenceAnnotationBeanPostProcessor.setExtendedPersistenceContexts "extendedPersistenceContexts" map , typically with matching persistence-context-ref entries in the Java EE deployment descriptor. For example:

 <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor">
 <property name="persistenceContexts">
 <map/gt;
 <entry key="unit1" value="persistence/context1"/>
 <entry key="unit2" value="persistence/context2"/>
 </map/gt;
 </property>
 </bean>
If the application only obtains EntityManager references in the first place, this is all you need to specify. If you need EntityManagerFactory references as well, specify entries for both "persistenceUnits" and "persistenceContexts", pointing to matching JNDI locations.

NOTE: In general, do not inject EXTENDED EntityManagers into STATELESS beans, i.e. do not use @PersistenceContext with type EXTENDED in Spring beans defined with scope 'singleton' (Spring's default scope). Extended EntityManagers are not thread-safe, hence they must not be used in concurrently accessed beans (which Spring-managed singletons usually are).

Note: A default PersistenceAnnotationBeanPostProcessor will be registered by the "context:annotation-config" and "context:component-scan" XML tags. Remove or turn off the default annotation configuration there if you intend to specify a custom PersistenceAnnotationBeanPostProcessor bean definition.
author:
   Rod Johnson
author:
   Juergen Hoeller
since:
   2.0
See Also:   javax.persistence.PersistenceUnit
See Also:   javax.persistence.PersistenceContext




Constructor Summary
public  PersistenceAnnotationBeanPostProcessor()
    

Method Summary
protected  EntityManagerFactoryfindDefaultEntityManagerFactory(String requestingBeanName)
     Find a single default EntityManagerFactory in the Spring application context.
protected  EntityManagerFactoryfindEntityManagerFactory(String unitName, String requestingBeanName)
     Find an EntityManagerFactory with the given name in the current Spring application context, falling back to a single default EntityManagerFactory (if any) in case of no unit name specified.
protected  EntityManagerFactoryfindNamedEntityManagerFactory(String unitName, String requestingBeanName)
     Find an EntityManagerFactory with the given name in the current Spring application context.
public  intgetOrder()
    
protected  EntityManagergetPersistenceContext(String unitName, boolean extended)
     Return a specified persistence context for the given unit name, as defined through the "persistenceContexts" (or "extendedPersistenceContexts") map.
protected  EntityManagerFactorygetPersistenceUnit(String unitName)
     Return a specified persistence unit for the given unit name, as defined through the "persistenceUnits" map.
public  ObjectpostProcessAfterInitialization(Object bean, String beanName)
    
public  booleanpostProcessAfterInstantiation(Object bean, String beanName)
    
public  voidpostProcessBeforeDestruction(Object bean, String beanName)
    
public  ObjectpostProcessBeforeInitialization(Object bean, String beanName)
    
public  ObjectpostProcessBeforeInstantiation(Class beanClass, String beanName)
    
public  PropertyValuespostProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
    
public  voidsetBeanFactory(BeanFactory beanFactory)
    
public  voidsetDefaultPersistenceUnitName(String unitName)
     Specify the default persistence unit name, to be used in case of no unit name specified in an @PersistenceUnit / @PersistenceContext annotation.

This is mainly intended for lookups in the application context, indicating the target persistence unit name (typically matching the bean name), but also applies to lookups in the PersistenceAnnotationBeanPostProcessor.setPersistenceUnits "persistenceUnits" / PersistenceAnnotationBeanPostProcessor.setPersistenceContexts "persistenceContexts" / PersistenceAnnotationBeanPostProcessor.setExtendedPersistenceContexts "extendedPersistenceContexts" map, avoiding the need for duplicated mappings for the empty String there.

Default is to check for a single EntityManagerFactory bean in the Spring application context, if any.

public  voidsetExtendedPersistenceContexts(Map<String, String> extendedPersistenceContexts)
     Specify the extended persistence contexts for EntityManager lookups, as a Map from persistence unit name to persistence context JNDI name (which needs to resolve to an EntityManager instance).

JNDI names specified here should refer to persistence-context-ref entries in the Java EE deployment descriptors, matching the target persistence unit and being set up with persistence context type Extended.

In case of no unit name specified in the annotation, the specified value for the PersistenceAnnotationBeanPostProcessor.setDefaultPersistenceUnitName default persistence unit will be taken (by default, the value mapped to the empty String), or simply the single persistence unit if there is only one.

This is mainly intended for use in a Java EE 5 environment, with all lookup driven by the standard JPA annotations, and all EntityManager references obtained from JNDI.

public  voidsetOrder(int order)
    
public  voidsetPersistenceContexts(Map<String, String> persistenceContexts)
     Specify the transactional persistence contexts for EntityManager lookups, as a Map from persistence unit name to persistence context JNDI name (which needs to resolve to an EntityManager instance).

JNDI names specified here should refer to persistence-context-ref entries in the Java EE deployment descriptors, matching the target persistence unit and being set up with persistence context type Transaction.

In case of no unit name specified in the annotation, the specified value for the PersistenceAnnotationBeanPostProcessor.setDefaultPersistenceUnitName default persistence unit will be taken (by default, the value mapped to the empty String), or simply the single persistence unit if there is only one.

This is mainly intended for use in a Java EE 5 environment, with all lookup driven by the standard JPA annotations, and all EntityManager references obtained from JNDI.

public  voidsetPersistenceUnits(Map<String, String> persistenceUnits)
     Specify the persistence units for EntityManagerFactory lookups, as a Map from persistence unit name to persistence unit JNDI name (which needs to resolve to an EntityManagerFactory instance).

JNDI names specified here should refer to persistence-unit-ref entries in the Java EE deployment descriptor, matching the target persistence unit.

In case of no unit name specified in the annotation, the specified value for the PersistenceAnnotationBeanPostProcessor.setDefaultPersistenceUnitName default persistence unit will be taken (by default, the value mapped to the empty String), or simply the single persistence unit if there is only one.

This is mainly intended for use in a Java EE 5 environment, with all lookup driven by the standard JPA annotations, and all EntityManagerFactory references obtained from JNDI.



Constructor Detail
PersistenceAnnotationBeanPostProcessor
public PersistenceAnnotationBeanPostProcessor()(Code)




Method Detail
findDefaultEntityManagerFactory
protected EntityManagerFactory findDefaultEntityManagerFactory(String requestingBeanName) throws NoSuchBeanDefinitionException(Code)
Find a single default EntityManagerFactory in the Spring application context. the default EntityManagerFactory
throws:
  NoSuchBeanDefinitionException - if there is no single EntityManagerFactory in the context



findEntityManagerFactory
protected EntityManagerFactory findEntityManagerFactory(String unitName, String requestingBeanName) throws NoSuchBeanDefinitionException(Code)
Find an EntityManagerFactory with the given name in the current Spring application context, falling back to a single default EntityManagerFactory (if any) in case of no unit name specified.
Parameters:
  unitName - the name of the persistence unit (may be null or empty)
Parameters:
  requestingBeanName - the name of the requesting bean the EntityManagerFactory
throws:
  NoSuchBeanDefinitionException - if there is no such EntityManagerFactory in the context



findNamedEntityManagerFactory
protected EntityManagerFactory findNamedEntityManagerFactory(String unitName, String requestingBeanName) throws NoSuchBeanDefinitionException(Code)
Find an EntityManagerFactory with the given name in the current Spring application context.
Parameters:
  unitName - the name of the persistence unit (never empty)
Parameters:
  requestingBeanName - the name of the requesting bean the EntityManagerFactory
throws:
  NoSuchBeanDefinitionException - if there is no such EntityManagerFactory in the context



getOrder
public int getOrder()(Code)



getPersistenceContext
protected EntityManager getPersistenceContext(String unitName, boolean extended)(Code)
Return a specified persistence context for the given unit name, as defined through the "persistenceContexts" (or "extendedPersistenceContexts") map.
Parameters:
  unitName - the name of the persistence unit
Parameters:
  extended - whether to obtain an extended persistence context the corresponding EntityManager, or null if none found
See Also:   PersistenceAnnotationBeanPostProcessor.setPersistenceContexts
See Also:   PersistenceAnnotationBeanPostProcessor.setExtendedPersistenceContexts



getPersistenceUnit
protected EntityManagerFactory getPersistenceUnit(String unitName)(Code)
Return a specified persistence unit for the given unit name, as defined through the "persistenceUnits" map.
Parameters:
  unitName - the name of the persistence unit the corresponding EntityManagerFactory,or null if none found
See Also:   PersistenceAnnotationBeanPostProcessor.setPersistenceUnits



postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException(Code)



postProcessAfterInstantiation
public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException(Code)



postProcessBeforeDestruction
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException(Code)



postProcessBeforeInitialization
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException(Code)



postProcessBeforeInstantiation
public Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException(Code)



postProcessPropertyValues
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException(Code)



setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)(Code)



setDefaultPersistenceUnitName
public void setDefaultPersistenceUnitName(String unitName)(Code)
Specify the default persistence unit name, to be used in case of no unit name specified in an @PersistenceUnit / @PersistenceContext annotation.

This is mainly intended for lookups in the application context, indicating the target persistence unit name (typically matching the bean name), but also applies to lookups in the PersistenceAnnotationBeanPostProcessor.setPersistenceUnits "persistenceUnits" / PersistenceAnnotationBeanPostProcessor.setPersistenceContexts "persistenceContexts" / PersistenceAnnotationBeanPostProcessor.setExtendedPersistenceContexts "extendedPersistenceContexts" map, avoiding the need for duplicated mappings for the empty String there.

Default is to check for a single EntityManagerFactory bean in the Spring application context, if any. If there are multiple such factories, either specify this default persistence unit name or explicitly refer to named persistence units in your annotations.




setExtendedPersistenceContexts
public void setExtendedPersistenceContexts(Map<String, String> extendedPersistenceContexts)(Code)
Specify the extended persistence contexts for EntityManager lookups, as a Map from persistence unit name to persistence context JNDI name (which needs to resolve to an EntityManager instance).

JNDI names specified here should refer to persistence-context-ref entries in the Java EE deployment descriptors, matching the target persistence unit and being set up with persistence context type Extended.

In case of no unit name specified in the annotation, the specified value for the PersistenceAnnotationBeanPostProcessor.setDefaultPersistenceUnitName default persistence unit will be taken (by default, the value mapped to the empty String), or simply the single persistence unit if there is only one.

This is mainly intended for use in a Java EE 5 environment, with all lookup driven by the standard JPA annotations, and all EntityManager references obtained from JNDI. No separate EntityManagerFactory bean definitions are necessary in such a scenario, and all EntityManager handling is done by the Java EE 5 server itself.




setOrder
public void setOrder(int order)(Code)



setPersistenceContexts
public void setPersistenceContexts(Map<String, String> persistenceContexts)(Code)
Specify the transactional persistence contexts for EntityManager lookups, as a Map from persistence unit name to persistence context JNDI name (which needs to resolve to an EntityManager instance).

JNDI names specified here should refer to persistence-context-ref entries in the Java EE deployment descriptors, matching the target persistence unit and being set up with persistence context type Transaction.

In case of no unit name specified in the annotation, the specified value for the PersistenceAnnotationBeanPostProcessor.setDefaultPersistenceUnitName default persistence unit will be taken (by default, the value mapped to the empty String), or simply the single persistence unit if there is only one.

This is mainly intended for use in a Java EE 5 environment, with all lookup driven by the standard JPA annotations, and all EntityManager references obtained from JNDI. No separate EntityManagerFactory bean definitions are necessary in such a scenario, and all EntityManager handling is done by the Java EE 5 server itself.




setPersistenceUnits
public void setPersistenceUnits(Map<String, String> persistenceUnits)(Code)
Specify the persistence units for EntityManagerFactory lookups, as a Map from persistence unit name to persistence unit JNDI name (which needs to resolve to an EntityManagerFactory instance).

JNDI names specified here should refer to persistence-unit-ref entries in the Java EE deployment descriptor, matching the target persistence unit.

In case of no unit name specified in the annotation, the specified value for the PersistenceAnnotationBeanPostProcessor.setDefaultPersistenceUnitName default persistence unit will be taken (by default, the value mapped to the empty String), or simply the single persistence unit if there is only one.

This is mainly intended for use in a Java EE 5 environment, with all lookup driven by the standard JPA annotations, and all EntityManagerFactory references obtained from JNDI. No separate EntityManagerFactory bean definitions are necessary in such a scenario.

If no corresponding "persistenceContexts"/"extendedPersistenceContexts" are specified, @PersistenceContext will be resolved to EntityManagers built on top of the EntityManagerFactory defined here. Note that those will be Spring-managed EntityManagers, which implement transaction synchronization based on Spring's facilities. If you prefer the Java EE 5 server's own EntityManager handling, specify corresponding "persistenceContexts"/"extendedPersistenceContexts".




Fields inherited from org.springframework.jndi.JndiLocatorSupport
final public static String CONTAINER_PREFIX(Code)(Java Doc)

Methods inherited from org.springframework.jndi.JndiLocatorSupport
protected String convertJndiName(String jndiName)(Code)(Java Doc)
public boolean isResourceRef()(Code)(Java Doc)
protected Object lookup(String jndiName) throws NamingException(Code)(Java Doc)
protected Object lookup(String jndiName, Class requiredType) throws NamingException(Code)(Java Doc)
public void setResourceRef(boolean resourceRef)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.