KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > query > lib > QueryResultUnique


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2005 France Telecom R&D
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  *
21  *
22  * Authors: S.Chassande-Barrioz.
23  * Created on 10 f�vr. 2005
24  *
25  */

26 package org.objectweb.speedo.query.lib;
27
28 import javax.jdo.JDOUserException;
29 import javax.jdo.PersistenceManager;
30
31 import org.objectweb.medor.api.MedorException;
32 import org.objectweb.medor.tuple.api.TupleCollection;
33 import org.objectweb.speedo.api.SpeedoException;
34 import org.objectweb.util.monolog.api.Logger;
35
36 /**
37  * Manages the query result which has to be unique.
38  *
39  * @author S.Chassande-Barrioz
40  */

41 public class QueryResultUnique extends QueryResultCommon {
42
43     /**
44      * Builds a QueryResultList.
45      * @param _tc the tuple collection representing the query result
46      * @param _pm is the peristence manager linked to the query
47      * @param _conns is the connection to the underlying support to close in
48      * same time than the query.
49      * @param _resultClazz is the class encapsulated the result
50      */

51     public QueryResultUnique(TupleCollection _tc,
52             PersistenceManager _pm,
53             Object JavaDoc[] _conns,
54             Class JavaDoc _resultClazz,
55             Class JavaDoc[] _selectedFieldTypes,
56             boolean staticFirstElementIndex,
57             Logger _logger)
58             throws MedorException, SpeedoException {
59         super(_tc, _pm, _conns, _resultClazz, _selectedFieldTypes,
60                 staticFirstElementIndex, _logger);
61     }
62
63     public Object JavaDoc getResult() throws SpeedoException {
64         Object JavaDoc res = null;
65         try {
66             if (!tc.isEmpty()) {
67                 tc.first();
68                 res = getValue(tc.getTuple());
69                 if (tc.next()) {
70                     throw new JDOUserException("More than one result in the query");
71                 }
72             }
73         } catch (MedorException e) {
74             throw new SpeedoException(e);
75         } finally {
76             close();
77         }
78         return res;
79     }
80 }
81
Popular Tags