192

I am trying to use the org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy in my Spring project, but I am not sure how to use it or whether it's exactly what I am looking for. I realize it can help make my DAOs work with a plain JDO PersistenceManagerFactory. Another question is: what happens if the proxy doesn't get made properly? Can I still use it to access my factory to create a transaction aware persistence manager? If the object managed by the factory is a singleton, does this change things? Why not just access the PersistenceManagerFactory directly? Perhaps PersistenceManagerFactoryUtils.getPersistenceManager would be more suited to my needs? Can getObject return null?

megazord
  • 3,210
  • 3
  • 23
  • 31
  • 195
    Lol! Sorry just can't help it I almost cried when I saw the object name. – Eric des Courtis Jan 31 '13 at 22:36
  • 134
    And this, dear children, is why Java should stop taking drugs. – Griwes Jun 25 '13 at 16:35
  • 49
    You know you've been in the Java world too long when names like this one don't seem that unreasonable...! – Brian Jun 26 '13 at 12:18
  • 27
    Guys. Hey guys, listen. You're making the newbie mistake again. Spring Framework is not Java and Java is not Spring framework. Don't confuse them. – Torben Jun 27 '13 at 05:33
  • 49
    Regarding the original question: this is the kind of high quality trolling that I can truly appreciate. – Torben Jun 27 '13 at 05:39
  • 21
    In german there's the word 'Dampfschifffahrtskapitänsmütze' (~steam marine captain cap). A few weeks we lost 'Rindfleischetikettierungsüberwachungsaufgabenübertragungsgesetz' (can't translate this insanity - and it was a law name). I feel homey ;) – gimbar Jun 27 '13 at 09:48
  • 2
    you gotta love java and its object names – cobie Jun 28 '13 at 22:34
  • 16
    Just make sure to use it as a TransactionAwarePersistenceManagerFactoryProxyServiceAPIFacade and you are good. – Ryan Christensen Jun 29 '13 at 00:13
  • 5
    This question was linked on HN. So for historical reasons I am adding the link here https://news.ycombinator.com/item?id=5960512 . – Eric des Courtis Jun 29 '13 at 03:07
  • 4
    Maybe it's me but I kinda like classnames that tell me what this thing is about. JDO defines a `PersistenceManagerFactory` which seems to be a factory creating `PersistenceManagers`. Whatever this exactly is, but the name is clearly speaking. Now with that in mind a `TransactionAwarePersistenceManagerFactoryProxy` is a proxy of the just defined concept to make it (Spring) transaction aware. So to everyone making fun of that: you're probably liking short, ambiguous names much better as you can spend more time trying to remember what the class was meant to do in the first place 3 weeks ago ;). – Oliver Drotbohm Jun 29 '13 at 10:31
  • 5
    @OliverGierke See the link above some people argue that the problem is not the name but the overengineering of the framework. – Eric des Courtis Jun 29 '13 at 15:49
  • 3
    This question makes me think of this blog post: http://chaosinmotion.com/blog/?p=622. It's not Java's fault, but Java perhaps encourages it. – joscarsson Jun 29 '13 at 21:31
  • 1
    Amateurs. Get ye over to the [Enterprisifier](http://projects.haykranen.nl/java/) and build yourself a StubRepositoryWrapperTemplateConsumerAttributeModelInterfaceFailurePool – DNA Jun 30 '13 at 21:52
  • 1
    @joscarsson Interesting blog thanks! – Eric des Courtis Jul 01 '13 at 14:19
  • 9
    For the record, there was an answer (now deleted) with 154 points. It quoted "I am not sure how to use it or whether it's exactly what I am looking for." and replied "Yes." I mourn the deletion of this answer. – sclv Jul 02 '13 at 02:04
  • 6
    @sclv This is a picture of the answer before it got deleted http://picpaste.com/pics/dudebro.1372803290.jpg – Eric des Courtis Jul 02 '13 at 22:14
  • Don't know why some laugh about the class name and earn a lot reputation points for this. How would you name it Eric? Maybe TAPMFactoryProx or just TAPMFP to save characters, but confuse readers of the code more? I think that we should make the names as short as possible, but not shorter. And of course we must ask ourselfs if we encapulate to much different aspects in one class that should be in two or more classes. 1 point for Oliver Gierke. – René Link Jul 05 '13 at 08:26
  • 6
    @RenéLink As rbehrends on HN said. "The problem is not the name, but the ridiculous overdesign of which it is a symptom." – Eric des Courtis Jul 05 '13 at 17:12

1 Answers1

21

Answers are directly available on documentation

I realize it can help make my DAOs work with a plain JDO PersistenceManagerFactory.

Yes. TransactionAwarePersistenceManagerFactoryProxy proxy allows DAOs to work with a plain JDO PersistenceManagerFactory reference, while still participating in Spring's (or a J2EE server's) resource and transaction management. You can surely use it in your app. But without knowing your exact needs, we can't confirm any further.

Can I still use it to access my factory to create a transaction aware persistence manager

DAOs could seamlessly switch between a JNDI PersistenceManagerFactory and this proxy for a local PersistenceManagerFactory.

If the object managed by the factory is a singleton, does this change things? Why not just access the PersistenceManagerFactory directly?

It is usually preferable to write your JDO-based DAOs with Spring's JdoTemplate, offering benefits such as consistent data access exceptions instead of JDOExceptions at the DAO layer. However, Spring's resource and transaction management (and Dependency Injection) will work for DAOs written against the plain JDO API as well.

hlfcoding
  • 2,532
  • 1
  • 21
  • 25
Chand Priyankara
  • 6,739
  • 2
  • 40
  • 63