27

I have written a JCA resource adapter before.

However, now I find myself in a position of having to write one solely to get access to the BootstrapContext and its associated WorkManager, and effectively for no other reason.

If I'm reading the specification correctly--and that's my question--it looks like if I want someone to be able to use my resource adapter in a spec-compliant fashion, I still need to implement ManagedConnectionFactory, because it would appear that only user connection factories vended by ManagedConnectionFactory implementations are eligible for injection via the @Resource annotation.

Go ahead, read it again; I'll wait. :-)

In a perfect world, I'd like to write my ResourceAdapter implementation, annotate it with @Connector, specify all the @ConfigProperty bits, pack it up in a .rar file, and be done with it.

However, it looks to me like the specification effectively mandates that all communication between the consumer (a stateless EJB in my case) and the resource adapter module is supposed to be accomplished through a user connection factory.

For example, section 6.10.1 says:

A resource adapter must provide implementations of the following interfaces:

  • javax.resource.spi.ManagedConnectionFactory
  • javax.resource.spi.ManagedConnection
  • javax.resource.spi.ManagedConnectionMetaData

But section 18--the section on annotations--doesn't seem to provide for enforcing this in any meaningful way.

Is this indeed the case? I suppose it must be, but I'd be curious to hear from people who have put together a 1.6 resource adapter.

Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
  • it was long time ago, 2004, when i had to implement a ResourceAdapter, the ManagedConnectionFactory was necessary, I hardly believe anything was changed since. – bestsss Jan 19 '11 at 15:36

1 Answers1

3

"This section outlines requirements for the connection management contract."

Is it legal, using only JCA 1.6 annotations, to simply define a ResourceAdapter implementation with--basically--nothing else in the module?

Yes. this is fine.

The specification indicates in section 19.2 that an outbound resource adapter (which this would be) must {handwave handwave} make use of the connection management,

transaction management and security management contracts. In all three cases, I just want to indicate--preferably by omitting annotations and/or code--that I don't suppo'r't any of them

If you do not need outbound communication capabilities, you do not have to define them (connection-factory, managed-connection-factory etc.,)

Is it sufficient to simply build a POJO that implements ResourceAdapter, annotate it with @Connector, and go from there?

Yes.

Can I then inject such a POJO into my EJB using the @Resource annotation?

I do not think "ResourceAdapter" Java Bean can be injected using @Resource annotation. Whenever the resource-adapter is deployed / enabled / server is started,

GlassFish will bootstrap the resource-adapter.

Community
  • 1
  • 1
Shahid Karimi
  • 4,096
  • 17
  • 62
  • 104
  • 3
    OK, but the question above doesn't ask whether it's possible to build a connectionless ResourceAdapter. I see from your answer (and others) that you can do this, but if you want your end users to be able to use it, then my question is: is it necessary to supply a connection factory? – Laird Nelson Jan 22 '11 at 15:46
  • What do you mean by use it ? You need to get it activated by the AS. The most obvious mechanism to do this is inject a ConnectionFactory into a `@Startup @Stateless` EJB. Now you get assurance your JCA bootstrap is invoked with the deployment. For communication maybe AdministeredObject is another mechanism to control it, if the notion of a "message" doesn't sit well with you. – Darryl Miles Sep 24 '15 at 23:55