Skip to content

Method: getAttr(String)

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.query.criteria.expressions;
19:
20: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
21: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
22: import cz.cvut.kbss.jopa.model.metamodel.Metamodel;
23: import cz.cvut.kbss.jopa.model.metamodel.SingularAttribute;
24: import cz.cvut.kbss.jopa.model.query.criteria.Path;
25: import cz.cvut.kbss.jopa.query.criteria.PathImpl;
26: import cz.cvut.kbss.jopa.model.query.criteria.CriteriaBuilder;
27:
28: public abstract class AbstractPathExpression<X> extends AbstractExpression<X> implements Path<X> {
29:
30: protected AbstractPathExpression pathSource;
31: protected final Metamodel metamodel;
32:
33: public AbstractPathExpression(Class<X> type, AbstractPathExpression pathSource, Metamodel metamodel,
34: CriteriaBuilder cb) {
35: super(type, cb);
36: this.pathSource = pathSource;
37: this.metamodel = metamodel;
38: }
39:
40: public <Y> Path<Y> getAttr(String attributeName) {
41: final EntityType<X> et = metamodel.entity(type);
42: final FieldSpecification<? super X, ?> fs;
43:• if (et.getIdentifier().getName().equals(attributeName)) {
44: fs = et.getIdentifier();
45:• } else if (et.getTypes() != null && et.getTypes().getName().equals(attributeName)) {
46: fs = et.getTypes();
47: } else {
48: fs = et.getAttribute(attributeName);
49: }
50: return new PathImpl<>(this.metamodel, this, fs, this.cb);
51: }
52:
53: public <Y> Path<Y> getAttr(SingularAttribute<? super X, Y> attribute) {
54: return new PathImpl<>(this.metamodel, this, attribute, this.cb);
55: }
56:
57:
58: public Path<?> getParentPath() {
59: return this.pathSource;
60: }
61:
62: }
63:
64: