Skip to content

Package: Path

Path

Coverage

1: /**
2: * Copyright (C) 2011 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:
16: package cz.cvut.kbss.jopa.model.query.criteria;
17:
18: import cz.cvut.kbss.jopa.model.metamodel.Bindable;
19: import cz.cvut.kbss.jopa.model.metamodel.MapAttribute;
20: import cz.cvut.kbss.jopa.model.metamodel.PluralAttribute;
21: import cz.cvut.kbss.jopa.model.metamodel.SingularAttribute;
22:
23: /**
24: * Represents a simple or compound attribute path from a bound type or
25: * collection, and is a "primitive" expression.
26: *
27: * @param <X>
28: * the type referenced by the path
29: */
30: public interface Path<X> extends Expression<X> {
31:         /**
32:          * Return the bindable object that corresponds to the path expression.
33:          *
34:          * @return bindable object corresponding to the path
35:          */
36:         Bindable<X> getModel();
37:
38:         /**
39:          * Return the parent "node" in the path or null if no parent.
40:          *
41:          * @return parent
42:          */
43:         Path<?> getParentPath();
44:
45:         /**
46:          * Create a path corresponding to the referenced single-valued attribute.
47:          *
48:          * @param attribute
49:          * single-valued attribute
50:          * @return path corresponding to the referenced attribute
51:          **/
52:         <Y> Path<Y> get(SingularAttribute<? super X, Y> attribute);
53:
54:         /**
55:          * Create a path corresponding to the referenced collection-valued
56:          * attribute.
57:          *
58:          * @param collection
59:          * collection-valued attribute
60:          * @return expression corresponding to the referenced attribute
61:          **/
62:         <E, C extends java.util.Collection<E>> Expression<C> get(
63:                         PluralAttribute<X, C, E> collection);
64:
65:         /**
66:          * Create a path corresponding to the referenced map-valued attribute.
67:          *
68:          * @param map
69:          * map-valued attribute
70:          * @return expression corresponding to the referenced attribute
71:          **/
72:         <K, V, M extends java.util.Map<K, V>> Expression<M> get(
73:                         MapAttribute<X, K, V> map);
74:
75:         /**
76:          * Create an expression corresponding to the type of the path.
77:          *
78:          * @return expression corresponding to the type of the path
79:          */
80:         Expression<Class<? extends X>> type();
81:
82:         // String-based:
83:         /**
84:          * Create a path corresponding to the referenced attribute. Note:
85:          * Applications using the string-based API may need to specify the type
86:          * resulting from the get operation in order to avoid the use of Path
87:          * variables. For example: CriteriaQuery<Person> q =
88:          * cb.createQuery(Person.class); Root<Person> p = q.from(Person.class);
89:          * q.select(p) .where(cb.isMember("joe", p.<Set<String>>get("nicknames")));
90:          * rather than: CriteriaQuery<Person> q = cb.createQuery(Person.class);
91:          * Root<Person> p = q.from(Person.class); Path<Set<String>> nicknames =
92:          * p.get("nicknames"); q.select(p) .where(cb.isMember("joe", nicknames));
93:          *
94:          * @param attributeName
95:          * name of the attribute
96:          * @return path corresponding to the referenced attribute
97:          * @throws IllegalStateException
98:          * if invoked on a path that corresponds to a basic type
99:          * @throws IllegalArgumentException
100:          * if attribute of the given name does not otherwise exist
101:          **/
102:         <Y> Path<Y> get(String attributeName);
103: }