Skip to content

Method: getResultStream()

1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.model.query;
19:
20: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
21:
22: import java.util.List;
23: import java.util.stream.Stream;
24:
25: /**
26: * Interface used to control the execution of typed queries.
27: *
28: * @param <X> Query result type
29: */
30: public interface TypedQuery<X> extends Query {
31:
32: /**
33: * {@inheritDoc}
34: */
35: @Override
36: List<X> getResultList();
37:
38: /**
39: * {@inheritDoc}
40: */
41: @Override
42: default Stream<X> getResultStream() {
43: return getResultList().stream();
44: }
45:
46: /**
47: * {@inheritDoc}
48: */
49: @Override
50: X getSingleResult();
51:
52: /**
53: * {@inheritDoc}
54: */
55: @Override
56: TypedQuery<X> setMaxResults(int maxResult);
57:
58: /**
59: * {@inheritDoc}
60: */
61: @Override
62: TypedQuery<X> setFirstResult(int startPosition);
63:
64: /**
65: * {@inheritDoc}
66: */
67: @Override
68: TypedQuery<X> setParameter(int position, Object value);
69:
70: /**
71: * {@inheritDoc}
72: */
73: @Override
74: TypedQuery<X> setParameter(int position, String value, String language);
75:
76: /**
77: * {@inheritDoc}
78: */
79: @Override
80: TypedQuery<X> setParameter(String name, Object value);
81:
82: /**
83: * {@inheritDoc}
84: */
85: @Override
86: TypedQuery<X> setParameter(String name, String value, String language);
87:
88: /**
89: * {@inheritDoc}
90: */
91: @Override
92: <T> TypedQuery<X> setParameter(Parameter<T> parameter, T value);
93:
94: /**
95: * {@inheritDoc}
96: */
97: @Override
98: TypedQuery<X> setParameter(Parameter<String> parameter, String value, String language);
99:
100: /**
101: * {@inheritDoc}
102: */
103: @Override
104: TypedQuery<X> setUntypedParameter(int position, Object value);
105:
106: /**
107: * {@inheritDoc}
108: */
109: @Override
110: TypedQuery<X> setUntypedParameter(String name, Object value);
111:
112: /**
113: * {@inheritDoc}
114: */
115: @Override
116: <T> TypedQuery<X> setUntypedParameter(Parameter<T> parameter, T value);
117:
118: /**
119: * {@inheritDoc}
120: */
121: @Override
122: TypedQuery<X> setHint(String hintName, Object value);
123:
124: /**
125: * Sets descriptor to use with this query.
126: * <p>
127: * The descriptor may specify contexts and languages for the retrieved query results. Note that the descriptor
128: * applies only to results of managed types, i.e. when the result type of the query is a managed type. Otherwise,
129: * the descriptor is ignored.
130: * <p>
131: * Use of descriptor may lead to additional result filtering, e.g. when the individual, which is a result of the
132: * query, does not match criteria in the descriptor (it is in a different context, for instance), it is not returned
133: * by {@link #getResultList()} and {@link #getSingleResult()}.
134: *
135: * @param descriptor The descriptor to use
136: * @return This query instance
137: * @throws NullPointerException If the provided argument is {@code null}
138: */
139: TypedQuery<X> setDescriptor(Descriptor descriptor);
140: }