01: package net.bagaluten.jca.lucene.connector.impl;
02:
03: import java.io.Serializable;
04: import java.util.logging.Logger;
05:
06: import javax.naming.NamingException;
07: import javax.naming.Reference;
08: import javax.resource.Referenceable;
09: import javax.resource.ResourceException;
10: import javax.resource.spi.ConnectionManager;
11: import javax.resource.spi.ManagedConnectionFactory;
12:
13: import net.bagaluten.jca.lucene.connector.LuceneConnection;
14: import net.bagaluten.jca.lucene.connector.LuceneConnectionFactory;
15:
16: public class LuceneConnectionFactoryImpl implements
17: LuceneConnectionFactory, Serializable, Referenceable {
18:
19: private static final Logger log = Logger
20: .getLogger(LuceneConnectionFactory.class.getName());
21: private static final long serialVersionUID = 6294476955610941204L;
22:
23: /** Managed connection factory */
24: private ManagedConnectionFactory mcf;
25:
26: /** Connection manager */
27: private ConnectionManager cm;
28:
29: /** JNDI reference */
30: private Reference reference;
31:
32: /**
33: * The constructor
34: * @param factory managed connection factory
35: * @param cm connection manager
36: */
37: public LuceneConnectionFactoryImpl(
38: ManagedConnectionFactory factory, ConnectionManager cm) {
39: this .mcf = factory;
40: this .cm = cm;
41: }
42:
43: public LuceneConnection getConnection(String indexName)
44: throws ResourceException {
45: if (indexName == null) {
46: throw new ResourceException(
47: "null not an allowed index name");
48: }
49: log.fine("creating new LuceneConnection for index '"
50: + indexName + "'.");
51: return (LuceneConnection) cm.allocateConnection(mcf,
52: new LuceneConnectionRequestInfo(indexName));
53: }
54:
55: /*
56: * @see javax.resource.Referenceable#setReference(javax.naming.Reference)
57: */
58: public void setReference(Reference reference) {
59: this .reference = reference;
60: }
61:
62: /*
63: * @see javax.naming.Referenceable#getReference()
64: */
65: public Reference getReference() throws NamingException {
66: return reference;
67: }
68:
69: }
|