Java Doc for JdoTemplate.java in  » J2EE » spring-framework-2.5 » org » springframework » orm » jdo » 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.jdo 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.orm.jdo.JdoAccessor
      org.springframework.orm.jdo.JdoTemplate

JdoTemplate
public class JdoTemplate extends JdoAccessor implements JdoOperations(Code)
Helper class that simplifies JDO data access code, and converts JDOExceptions into Spring DataAccessExceptions, following the org.springframework.dao exception hierarchy.

The central method is execute, supporting JDO access code implementing the JdoCallback interface. It provides JDO PersistenceManager handling such that neither the JdoCallback implementation nor the calling code needs to explicitly care about retrieving/closing PersistenceManagers, or handling JDO lifecycle exceptions.

Typically used to implement data access or business logic services that use JDO within their implementation but are JDO-agnostic in their interface. The latter or code calling the latter only have to deal with business objects, query objects, and org.springframework.dao exceptions.

Can be used within a service implementation via direct instantiation with a PersistenceManagerFactory reference, or get prepared in an application context and given to services as bean reference. Note: The PersistenceManagerFactory should always be configured as bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

This class can be considered as direct alternative to working with the raw JDO PersistenceManager API (through PersistenceManagerFactoryUtils.getPersistenceManager()). The major advantage is its automatic conversion to DataAccessExceptions, the major disadvantage that no checked application exceptions can get thrown from within data access code. Corresponding checks and the actual throwing of such exceptions can often be deferred to after callback execution, though.

LocalPersistenceManagerFactoryBean is the preferred way of obtaining a reference to a specific PersistenceManagerFactory, at least in a non-EJB environment. The Spring application context will manage its lifecycle, initializing and shutting down the factory as part of the application.

Note that lazy loading will just work with an open JDO PersistenceManager, either within a Spring-driven transaction (with JdoTransactionManager or JtaTransactionManager) or within OpenPersistenceManagerInViewFilter/Interceptor. Furthermore, some operations just make sense within transactions, for example: evict, evictAll, flush.

NOTE: This class requires JDO 2.0 or higher, as of Spring 2.5.
author:
   Juergen Hoeller
since:
   03.06.2003
See Also:   JdoTemplate.setPersistenceManagerFactory
See Also:   JdoCallback
See Also:   javax.jdo.PersistenceManager
See Also:   LocalPersistenceManagerFactoryBean
See Also:   JdoTransactionManager
See Also:   org.springframework.transaction.jta.JtaTransactionManager
See Also:   org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
See Also:   org.springframework.orm.jdo.support.OpenPersistenceManagerInViewInterceptor




Constructor Summary
public  JdoTemplate()
     Create a new JdoTemplate instance.
public  JdoTemplate(PersistenceManagerFactory pmf)
     Create a new JdoTemplate instance.
public  JdoTemplate(PersistenceManagerFactory pmf, boolean allowCreate)
     Create a new JdoTemplate instance.

Method Summary
public  ObjectattachCopy(Object detachedEntity)
    
public  CollectionattachCopyAll(Collection detachedEntities)
    
protected  PersistenceManagercreatePersistenceManagerProxy(PersistenceManager pm)
     Create a close-suppressing proxy for the given JDO PersistenceManager.
public  voiddeletePersistent(Object entity)
    
public  voiddeletePersistentAll(Collection entities)
    
public  ObjectdetachCopy(Object entity)
    
public  CollectiondetachCopyAll(Collection entities)
    
public  voidevict(Object entity)
    
public  voidevictAll(Collection entities)
    
public  voidevictAll()
    
public  Objectexecute(JdoCallback action)
    
public  Objectexecute(JdoCallback action, boolean exposeNativePersistenceManager)
     Execute the action specified by the given action object within a PersistenceManager.
public  CollectionexecuteFind(JdoCallback action)
    
public  Collectionfind(Class entityClass)
    
public  Collectionfind(Class entityClass, String filter)
    
public  Collectionfind(Class entityClass, String filter, String ordering)
    
public  Collectionfind(Class entityClass, String filter, String parameters, Object[] values)
    
public  Collectionfind(Class entityClass, String filter, String parameters, Object[] values, String ordering)
    
public  Collectionfind(Class entityClass, String filter, String parameters, Map values)
    
public  Collectionfind(Class entityClass, String filter, String parameters, Map values, String ordering)
    
public  Collectionfind(String language, Object queryObject)
    
public  Collectionfind(String queryString)
    
public  Collectionfind(String queryString, Object[] values)
    
public  Collectionfind(String queryString, Map values)
    
public  CollectionfindByNamedQuery(Class entityClass, String queryName)
    
public  CollectionfindByNamedQuery(Class entityClass, String queryName, Object[] values)
    
public  CollectionfindByNamedQuery(Class entityClass, String queryName, Map values)
    
public  voidflush()
    
public  ObjectgetObjectById(Object objectId)
    
public  ObjectgetObjectById(Class entityClass, Object idValue)
    
public  booleanisAllowCreate()
     Return if a new PersistenceManager should be created if no thread-bound found.
public  booleanisExposeNativePersistenceManager()
     Return whether to expose the native JDO PersistenceManager to JdoCallback code, or rather a PersistenceManager proxy.
public  ObjectmakePersistent(Object entity)
    
public  CollectionmakePersistentAll(Collection entities)
    
protected  ObjectpostProcessResult(Object result, PersistenceManager pm, boolean existingTransaction)
     Post-process the given result object, which might be a Collection.
public  voidprepareQuery(Query query)
     Prepare the given JDO query object.
public  voidrefresh(Object entity)
    
public  voidrefreshAll(Collection entities)
    
public  voidrefreshAll()
    
public  voidsetAllowCreate(boolean allowCreate)
     Set if a new PersistenceManager should be created when no transactional PersistenceManager can be found for the current thread.
public  voidsetExposeNativePersistenceManager(boolean exposeNativePersistenceManager)
     Set whether to expose the native JDO PersistenceManager to JdoCallback code.


Constructor Detail
JdoTemplate
public JdoTemplate()(Code)
Create a new JdoTemplate instance.



JdoTemplate
public JdoTemplate(PersistenceManagerFactory pmf)(Code)
Create a new JdoTemplate instance.
Parameters:
  pmf - PersistenceManagerFactory to create PersistenceManagers



JdoTemplate
public JdoTemplate(PersistenceManagerFactory pmf, boolean allowCreate)(Code)
Create a new JdoTemplate instance.
Parameters:
  pmf - PersistenceManagerFactory to create PersistenceManagers
Parameters:
  allowCreate - if a non-transactional PersistenceManager should be createdwhen no transactional PersistenceManager can be found for the current thread




Method Detail
attachCopy
public Object attachCopy(Object detachedEntity)(Code)
JdoTemplate.makePersistent(Object)



attachCopyAll
public Collection attachCopyAll(Collection detachedEntities)(Code)
JdoTemplate.makePersistentAll(java.util.Collection)



createPersistenceManagerProxy
protected PersistenceManager createPersistenceManagerProxy(PersistenceManager pm)(Code)
Create a close-suppressing proxy for the given JDO PersistenceManager. Called by the execute method.

The proxy also prepares returned JDO Query objects.
Parameters:
  pm - the JDO PersistenceManager to create a proxy for the PersistenceManager proxy, implementing all interfacesimplemented by the passed-in PersistenceManager object (that is,also implementing all provider-specific extension interfaces)
See Also:   javax.jdo.PersistenceManager.close
See Also:   JdoTemplate.execute(JdoCallback,boolean)
See Also:   JdoTemplate.prepareQuery




deletePersistent
public void deletePersistent(Object entity) throws DataAccessException(Code)



deletePersistentAll
public void deletePersistentAll(Collection entities) throws DataAccessException(Code)



detachCopy
public Object detachCopy(Object entity)(Code)



detachCopyAll
public Collection detachCopyAll(Collection entities)(Code)



evict
public void evict(Object entity) throws DataAccessException(Code)



evictAll
public void evictAll(Collection entities) throws DataAccessException(Code)



evictAll
public void evictAll() throws DataAccessException(Code)



execute
public Object execute(JdoCallback action) throws DataAccessException(Code)



execute
public Object execute(JdoCallback action, boolean exposeNativePersistenceManager) throws DataAccessException(Code)
Execute the action specified by the given action object within a PersistenceManager.
Parameters:
  action - callback object that specifies the JDO action
Parameters:
  exposeNativePersistenceManager - whether to expose the nativeJDO persistence manager to callback code a result object returned by the action, or null
throws:
  org.springframework.dao.DataAccessException - in case of JDO errors



executeFind
public Collection executeFind(JdoCallback action) throws DataAccessException(Code)



find
public Collection find(Class entityClass) throws DataAccessException(Code)



find
public Collection find(Class entityClass, String filter) throws DataAccessException(Code)



find
public Collection find(Class entityClass, String filter, String ordering) throws DataAccessException(Code)



find
public Collection find(Class entityClass, String filter, String parameters, Object[] values) throws DataAccessException(Code)



find
public Collection find(Class entityClass, String filter, String parameters, Object[] values, String ordering) throws DataAccessException(Code)



find
public Collection find(Class entityClass, String filter, String parameters, Map values) throws DataAccessException(Code)



find
public Collection find(Class entityClass, String filter, String parameters, Map values, String ordering) throws DataAccessException(Code)



find
public Collection find(String language, Object queryObject) throws DataAccessException(Code)



find
public Collection find(String queryString) throws DataAccessException(Code)



find
public Collection find(String queryString, Object[] values) throws DataAccessException(Code)



find
public Collection find(String queryString, Map values) throws DataAccessException(Code)



findByNamedQuery
public Collection findByNamedQuery(Class entityClass, String queryName) throws DataAccessException(Code)



findByNamedQuery
public Collection findByNamedQuery(Class entityClass, String queryName, Object[] values) throws DataAccessException(Code)



findByNamedQuery
public Collection findByNamedQuery(Class entityClass, String queryName, Map values) throws DataAccessException(Code)



flush
public void flush() throws DataAccessException(Code)



getObjectById
public Object getObjectById(Object objectId) throws DataAccessException(Code)



getObjectById
public Object getObjectById(Class entityClass, Object idValue) throws DataAccessException(Code)



isAllowCreate
public boolean isAllowCreate()(Code)
Return if a new PersistenceManager should be created if no thread-bound found.



isExposeNativePersistenceManager
public boolean isExposeNativePersistenceManager()(Code)
Return whether to expose the native JDO PersistenceManager to JdoCallback code, or rather a PersistenceManager proxy.



makePersistent
public Object makePersistent(Object entity) throws DataAccessException(Code)



makePersistentAll
public Collection makePersistentAll(Collection entities) throws DataAccessException(Code)



postProcessResult
protected Object postProcessResult(Object result, PersistenceManager pm, boolean existingTransaction)(Code)
Post-process the given result object, which might be a Collection. Called by the execute method.

Default implementation always returns the passed-in Object as-is. Subclasses might override this to automatically detach result collections or even single result objects.
Parameters:
  pm - the current JDO PersistenceManager
Parameters:
  result - the result object (might be a Collection)
Parameters:
  existingTransaction - if executing within an existing transaction(within an existing JDO PersistenceManager that won't be closed immediately) the post-processed result object (can be simply be the passed-in object)
See Also:   JdoTemplate.execute(JdoCallback,boolean)




prepareQuery
public void prepareQuery(Query query) throws JDOException(Code)
Prepare the given JDO query object. To be used within a JdoCallback. Applies a transaction timeout, if any. If you don't use such timeouts, the call is a no-op.

In general, prefer a proxied PersistenceManager instead, which will automatically apply the transaction timeout (through the use of a special PersistenceManager proxy). You need to set the "exposeNativePersistenceManager" property to "false" to activate this. Note that you won't be able to cast to a provider-specific JDO PersistenceManager class anymore then.
Parameters:
  query - the JDO query object
throws:
  JDOException - if the query could not be properly prepared
See Also:   JdoCallback.doInJdo
See Also:   PersistenceManagerFactoryUtils.applyTransactionTimeout
See Also:   JdoTemplate.setExposeNativePersistenceManager




refresh
public void refresh(Object entity) throws DataAccessException(Code)



refreshAll
public void refreshAll(Collection entities) throws DataAccessException(Code)



refreshAll
public void refreshAll() throws DataAccessException(Code)



setAllowCreate
public void setAllowCreate(boolean allowCreate)(Code)
Set if a new PersistenceManager should be created when no transactional PersistenceManager can be found for the current thread.

JdoTemplate is aware of a corresponding PersistenceManager bound to the current thread, for example when using JdoTransactionManager. If allowCreate is true, a new non-transactional PersistenceManager will be created if none found, which needs to be closed at the end of the operation. If false, an IllegalStateException will get thrown in this case.
See Also:   PersistenceManagerFactoryUtils.getPersistenceManager(javax.jdo.PersistenceManagerFactoryboolean)




setExposeNativePersistenceManager
public void setExposeNativePersistenceManager(boolean exposeNativePersistenceManager)(Code)
Set whether to expose the native JDO PersistenceManager to JdoCallback code. Default is "false": a PersistenceManager proxy will be returned, suppressing close calls and automatically applying transaction timeouts (if any).

As there is often a need to cast to a provider-specific PersistenceManager class in DAOs that use provider-specific functionality, the exposed proxy implements all interfaces implemented by the original PersistenceManager. If this is not sufficient, turn this flag to "true".
See Also:   JdoCallback
See Also:   javax.jdo.PersistenceManager
See Also:   JdoTemplate.prepareQuery




Fields inherited from org.springframework.orm.jdo.JdoAccessor
final protected Log logger(Code)(Java Doc)

Methods inherited from org.springframework.orm.jdo.JdoAccessor
public void afterPropertiesSet()(Code)(Java Doc)
public DataAccessException convertJdoAccessException(JDOException ex)(Code)(Java Doc)
protected void flushIfNecessary(PersistenceManager pm, boolean existingTransaction) throws JDOException(Code)(Java Doc)
public JdoDialect getJdoDialect()(Code)(Java Doc)
public PersistenceManagerFactory getPersistenceManagerFactory()(Code)(Java Doc)
public boolean isFlushEager()(Code)(Java Doc)
public void setFlushEager(boolean flushEager)(Code)(Java Doc)
public void setJdoDialect(JdoDialect jdoDialect)(Code)(Java Doc)
public void setPersistenceManagerFactory(PersistenceManagerFactory pmf)(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(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.