View Javadoc

1   /*
2    * Copyright (c) 2002 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: PooledXindiceAdapter.java,v 1.1.1.1 2004/05/19 14:10:47 pra Exp $
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version
10   * 
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.backsource.xindice;
21  import org.apache.log4j.Logger;
22  /***
23   * This is only here to remember a possible concept, namley to wrap the pool and XindiceAdapter together to not have to write all the long pooling get/leave code every time you need to invoke an XindiceAdapter call.
24   * 1. Make XindicePool an interface.
25   * 2. Implement all methods in XindiceAdapter, see example below.
26   *
27   * @author <a href="mailto:pra@tim.se">Peter Antman</a>
28   * @version $Revision: 1.1.1.1 $
29   */
30  
31  public class PooledXindiceAdapter {
32     private static Logger log = Logger.getLogger( PooledXindiceAdapter.class);
33     XindicePool pool;
34     public PooledXindiceAdapter (XindicePool pool){
35        this.pool = pool;
36     }
37  
38     public void addDocument(String collection,String data, String id) throws XindiceException
39     {
40        XindiceAdapter ad = null;
41        try {
42           // Add document
43           ad = pool.getAdapter( collection );
44           ad.addDocument(data,
45                          id);
46        } catch (XindiceException e) {
47           log.error("Could not add document",e);
48           //e.printStackTrace();
49           throw new XindiceException("Could not add document to collection " + collection + ":" +e,e);
50        }finally {
51           if ( ad != null) {
52              // ALLWAYS leave it back.
53              try {                 
54                 pool.leaveAdapter(ad);
55              } catch (XindiceException e) {
56                 log.error("Could not leave back adapter for collection: " +collection);
57              } // end of try-catch
58           } // end of if ()
59           
60        } // end of finally
61     }
62     
63  }// PooledXindiceAdapter