Skip to content

Package: Path

Path

Coverage

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.query.criteria;
16:
17: import cz.cvut.kbss.jopa.model.metamodel.Bindable;
18: import cz.cvut.kbss.jopa.model.metamodel.MapAttribute;
19: import cz.cvut.kbss.jopa.model.metamodel.PluralAttribute;
20: import cz.cvut.kbss.jopa.model.metamodel.SingularAttribute;
21:
22: /**
23: * Represents a simple or compound attribute path from a bound type or
24: * collection, and is a "primitive" expression.
25: *
26: * @param <X>
27: * the type referenced by the path
28: */
29: public interface Path<X> extends Expression<X> {
30:         /**
31:          * Return the bindable object that corresponds to the path expression.
32:          *
33:          * @return bindable object corresponding to the path
34:          */
35:         Bindable<X> getModel();
36:
37:         /**
38:          * Return the parent "node" in the path or null if no parent.
39:          *
40:          * @return parent
41:          */
42:         Path<?> getParentPath();
43:
44:         /**
45:          * Create a path corresponding to the referenced single-valued attribute.
46:          *
47:          * @param attribute
48:          * single-valued attribute
49:          * @return path corresponding to the referenced attribute
50:          **/
51:         <Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
52:
53:         /**
54:          * Create a path corresponding to the referenced collection-valued
55:          * attribute.
56:          *
57:          * @param collection
58:          * collection-valued attribute
59:          * @return expression corresponding to the referenced attribute
60:          **/
61:         <E, C extends java.util.Collection<E>> Expression<C> get(
62:                         PluralAttribute<X, C, E> collection);
63:
64:         /**
65:          * Create a path corresponding to the referenced map-valued attribute.
66:          *
67:          * @param map
68:          * map-valued attribute
69:          * @return expression corresponding to the referenced attribute
70:          **/
71:         <K, V, M extends java.util.Map<K, V>> Expression<M> get(
72:                         MapAttribute<X, K, V> map);
73:
74:         /**
75:          * Create an expression corresponding to the type of the path.
76:          *
77:          * @return expression corresponding to the type of the path
78:          */
79:         Expression<Class<? extends X>> type();
80:
81:         // String-based:
82:         /**
83:          * Create a path corresponding to the referenced attribute. Note:
84:          * Applications using the string-based API may need to specify the type
85:          * resulting from the get operation in order to avoid the use of Path
86:          * variables. For example: CriteriaQuery<Person> q =
87:          * cb.createQuery(Person.class); Root<Person> p = q.from(Person.class);
88:          * q.select(p) .where(cb.isMember("joe", p.<Set<String>>get("nicknames")));
89:          * rather than: CriteriaQuery<Person> q = cb.createQuery(Person.class);
90:          * Root<Person> p = q.from(Person.class); Path<Set<String>> nicknames =
91:          * p.get("nicknames"); q.select(p) .where(cb.isMember("joe", nicknames));
92:          *
93:          * @param attributeName
94:          * name of the attribute
95:          * @return path corresponding to the referenced attribute
96:          * @throws IllegalStateException
97:          * if invoked on a path that corresponds to a basic type
98:          * @throws IllegalArgumentException
99:          * if attribute of the given name does not otherwise exist
100:          **/
101:         <Y> Path<Y> get(String attributeName);
102: }