001/* 002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the 005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 006 * which accompanies this distribution. The Eclipse Public License is available 007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License 008 * is available at http://www.eclipse.org/org/documents/edl-v10.php. 009 */ 010package javax.persistence; 011 012import java.util.List; 013 014/** 015 * Interface for extracting the elements of a query result tuple. 016 * 017 * @see TupleElement 018 * @since Java Persistence 2.0 019 */ 020public interface Tuple { 021 /** 022 * Get the value of the specified tuple element. 023 * 024 * @param tupleElement tuple element 025 * @param <X> Type 026 * @return value of tuple element 027 * @throws IllegalArgumentException if tuple element does not correspond to an element in the query result 028 * tuple 029 */ 030 <X> X get(TupleElement<X> tupleElement); 031 032 /** 033 * Get the value of the tuple element to which the specified alias has been assigned. 034 * 035 * @param alias alias assigned to tuple element 036 * @param type of the tuple element 037 * @param <X> Type 038 * @return value of the tuple element 039 * @throws IllegalArgumentException if alias does not correspond to an element in the query result tuple or 040 * element cannot be assigned to the specified type 041 */ 042 <X> X get(String alias, Class<X> type); 043 044 /** 045 * Get the value of the tuple element to which the specified alias has been assigned. 046 * 047 * @param alias alias assigned to tuple element 048 * @return value of the tuple element 049 * @throws IllegalArgumentException if alias does not correspond to an element in the query result tuple 050 */ 051 Object get(String alias); 052 053 /** 054 * Get the value of the element at the specified position in the result tuple. The first position is 0. 055 * 056 * @param i position in result tuple 057 * @param type type of the tuple element 058 * @param <X> Type 059 * @return value of the tuple element 060 * @throws IllegalArgumentException if i exceeds length of result tuple or element cannot be assigned to 061 * the specified type 062 */ 063 <X> X get(int i, Class<X> type); 064 065 /** 066 * Get the value of the element at the specified position in the result tuple. The first position is 0. 067 * 068 * @param i position in result tuple 069 * @return value of the tuple element 070 * @throws IllegalArgumentException if i exceeds length of result tuple 071 */ 072 Object get(int i); 073 074 /** 075 * Return the values of the result tuple elements as an array. 076 * 077 * @return tuple element values 078 */ 079 Object[] toArray(); 080 081 /** 082 * Return the tuple elements. 083 * 084 * @return tuple elements 085 */ 086 List<TupleElement<?>> getElements(); 087}