01: /**
02: * Speedo: an implementation of JDO compliant personality on top of JORM generic
03: * I/O sub-system.
04: * Copyright (C) 2001-2005 France Telecom R&D
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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: *
24: */package org.objectweb.speedo.query.jdo;
25:
26: import javax.jdo.JDOUserException;
27: import javax.jdo.PersistenceManager;
28:
29: import org.objectweb.medor.api.MedorException;
30: import org.objectweb.medor.tuple.api.TupleCollection;
31: import org.objectweb.speedo.api.SpeedoException;
32: import org.objectweb.util.monolog.api.Logger;
33:
34: /**
35: * Manages the query result which has to be unique.
36: *
37: * @author S.Chassande-Barrioz
38: */
39: public class JDOQueryResultUnique extends JDOQueryResultCommon {
40:
41: /**
42: * Builds a QueryResultList.
43: * @param _tc the tuple collection representing the query result
44: * @param _pm is the peristence manager linked to the query
45: * @param _conns is the connection to the underlying support to close in
46: * same time than the query.
47: * @param _resultClazz is the class encapsulated the result
48: */
49: public JDOQueryResultUnique(TupleCollection _tc,
50: PersistenceManager _pm, Object[] _conns,
51: Class _resultClazz, Class[] _selectedFieldTypes,
52: boolean staticFirstElementIndex,
53: boolean returnIdentifierOnly, Logger _logger)
54: throws MedorException, SpeedoException {
55: super (_tc, _pm, _conns, _resultClazz, _selectedFieldTypes,
56: staticFirstElementIndex, returnIdentifierOnly, _logger);
57: }
58:
59: public Object getResult() throws SpeedoException {
60: Object res = null;
61: try {
62: if (!tc.isEmpty()) {
63: tc.first();
64: res = getValue(tc.getTuple());
65: if (tc.next()) {
66: throw new JDOUserException(
67: "More than one result in the query");
68: }
69: }
70: } catch (MedorException e) {
71: throw new SpeedoException(e);
72: } finally {
73: close();
74: }
75: return res;
76: }
77: }
|