Skip to content

Method: field(Field)

1: /**
2: * Copyright (C) 2019 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.model.metamodel;
14:
15: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
16:
17: import java.lang.reflect.Field;
18:
19: public class SingularAttributeImpl<X, Y> extends AbstractAttribute<X, Y> implements SingularAttribute<X, Y> {
20:
21: private final Type<Y> type;
22:
23: private SingularAttributeImpl(SingularAttributeBuilder<X, Y> builder) {
24: super(builder);
25: this.type = builder.type;
26: }
27:
28: @Override
29: public Type<Y> getType() {
30: return type;
31: }
32:
33: @Override
34: public boolean isId() {
35: return false;
36: }
37:
38: @Override
39: public boolean isVersion() {
40: throw new UnsupportedOperationException();
41: }
42:
43: @Override
44: public Class<Y> getJavaType() {
45: return type.getJavaType();
46: }
47:
48: @Override
49: public boolean isAssociation() {
50: return getPersistentAttributeType().equals(PersistentAttributeType.OBJECT);
51: }
52:
53: @Override
54: public boolean isCollection() {
55: return false;
56: }
57:
58: @Override
59: public Class<Y> getBindableJavaType() {
60: return type.getJavaType();
61: }
62:
63: @Override
64: public BindableType getBindableType() {
65: return BindableType.SINGULAR_ATTRIBUTE;
66: }
67:
68: public static SingularAttributeBuilder builder(PropertyAttributes config) {
69: return new SingularAttributeBuilder().config(config);
70: }
71:
72: public static final class SingularAttributeBuilder<X, Y> extends AbstractAttributeBuilder<X, Y> {
73: private Type<Y> type;
74:
75: @Override
76: public SingularAttributeBuilder<X, Y> config(PropertyAttributes config) {
77: super.config(config);
78: type((Type<Y>) config.getType());
79: return this;
80: }
81:
82: public SingularAttributeBuilder<X, Y> type(Type<Y> type) {
83: this.type = type;
84: return this;
85: }
86:
87: @Override
88: public SingularAttributeBuilder<X, Y> field(Field field) {
89: super.field(field);
90: return this;
91: }
92:
93: @Override
94: public SingularAttributeBuilder<X, Y> declaringType(ManagedType<X> declaringType) {
95: super.declaringType(declaringType);
96: return this;
97: }
98:
99: @Override
100: public SingularAttributeBuilder<X, Y> inferred(boolean inferred) {
101: super.inferred(inferred);
102: return this;
103: }
104:
105: @Override
106: public SingularAttributeBuilder<X, Y> includeExplicit(boolean includeExplicit) {
107: super.includeExplicit(includeExplicit);
108: return this;
109: }
110:
111: @Override
112: public SingularAttributeBuilder<X, Y> converter(ConverterWrapper converter) {
113: super.converter(converter);
114: return this;
115: }
116:
117: public SingularAttribute<X, Y> build() {
118: return new SingularAttributeImpl<>(this);
119: }
120: }
121: }