/**
* Speedo: an implementation of JDO compliant personality on top of JORM generic
* I/O sub-system.
* Copyright (C) 2001-2005 France Telecom R&D
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
*
* Authors: S.Chassande-Barrioz.
*
*/
package org.objectweb.speedo.query.jdo;
import javax.jdo.JDOUserException;
import javax.jdo.PersistenceManager;
import org.objectweb.medor.api.MedorException;
import org.objectweb.medor.tuple.api.TupleCollection;
import org.objectweb.speedo.api.SpeedoException;
import org.objectweb.util.monolog.api.Logger;
/**
* Manages the query result which has to be unique.
*
* @author S.Chassande-Barrioz
*/
public class JDOQueryResultUnique extends JDOQueryResultCommon {
/**
* Builds a QueryResultList.
* @param _tc the tuple collection representing the query result
* @param _pm is the peristence manager linked to the query
* @param _conns is the connection to the underlying support to close in
* same time than the query.
* @param _resultClazz is the class encapsulated the result
*/
public JDOQueryResultUnique(TupleCollection _tc,
PersistenceManager _pm,
Object[] _conns,
Class _resultClazz,
Class[] _selectedFieldTypes,
boolean staticFirstElementIndex,
boolean returnIdentifierOnly,
Logger _logger)
throws MedorException, SpeedoException {
super(_tc, _pm, _conns, _resultClazz, _selectedFieldTypes,
staticFirstElementIndex, returnIdentifierOnly, _logger);
}
public Object getResult() throws SpeedoException {
Object res = null;
try {
if (!tc.isEmpty()) {
tc.first();
res = getValue(tc.getTuple());
if (tc.next()) {
throw new JDOUserException("More than one result in the query");
}
}
} catch (MedorException e) {
throw new SpeedoException(e);
} finally {
close();
}
return res;
}
}