Skip to content

Method: type(Type)

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.metamodel;
16:
17: import cz.cvut.kbss.jopa.model.IRI;
18: import cz.cvut.kbss.jopa.model.annotations.CascadeType;
19: import cz.cvut.kbss.jopa.model.annotations.FetchType;
20: import cz.cvut.kbss.jopa.model.annotations.ParticipationConstraint;
21:
22: import java.lang.reflect.Field;
23: import java.lang.reflect.Member;
24:
25: public class SingularAttributeImpl<X, T> implements SingularAttribute<X, T> {
26:
27: private final boolean id;
28:
29: private final String name;
30:
31: private final Type<T> type;
32:
33: private final Field field;
34:
35: private final ManagedType<X> declaringType;
36:
37: private final PersistentAttributeType attributeType;
38:
39: private final IRI iri;
40:
41: private final CascadeType[] cascadeTypes;
42:
43: private final FetchType fetchType;
44:
45: private final boolean inferred;
46:
47: private final boolean includeExplicit;
48:
49: private final boolean readOnly;
50:
51: private final boolean nonEmpty;
52:
53: private ParticipationConstraint[] constraints;
54:
55: private SingularAttributeImpl(SingularAttributeBuilder<X, T> builder) {
56: this.id = builder.id;
57: this.name = builder.name;
58: this.type = builder.type;
59: this.field = builder.field;
60: this.declaringType = builder.declaringType;
61: this.attributeType = builder.attributeType;
62: this.iri = builder.iri;
63: this.cascadeTypes = builder.cascadeTypes;
64: this.fetchType = builder.fetchType;
65: this.inferred = builder.inferred;
66: this.includeExplicit = builder.includeExplicit;
67: this.readOnly = builder.readOnly;
68: this.constraints = builder.constraints;
69: this.nonEmpty = builder.nonEmpty;
70: }
71:
72: @Override
73: public Type<T> getType() {
74: return type;
75: }
76:
77: @Override
78: public boolean isId() {
79: return id;
80: }
81:
82: @Override
83: public boolean isNonEmpty() {
84: return nonEmpty;
85: }
86:
87: @Override
88: public boolean isVersion() {
89: throw new UnsupportedOperationException();
90: }
91:
92: @Override
93: public ManagedType<X> getDeclaringType() {
94: return declaringType;
95: }
96:
97: @Override
98: public Member getJavaMember() {
99: return field;
100: }
101:
102: @Override
103: public Class<T> getJavaType() {
104: return type.getJavaType();
105: }
106:
107: @Override
108: public String getName() {
109: return name;
110: }
111:
112: @Override
113: public PersistentAttributeType getPersistentAttributeType() {
114: return attributeType;
115: }
116:
117: @Override
118: public boolean isAssociation() {
119: return getPersistentAttributeType().equals(
120: PersistentAttributeType.OBJECT);
121: }
122:
123: @Override
124: public boolean isCollection() {
125: return false;
126: }
127:
128: @Override
129: public Class<T> getBindableJavaType() {
130: return type.getJavaType();
131: }
132:
133: @Override
134: public cz.cvut.kbss.jopa.model.metamodel.Bindable.BindableType getBindableType() {
135: return BindableType.SINGULAR_ATTRIBUTE;
136: }
137:
138: @Override
139: public Field getJavaField() {
140: return field;
141: }
142:
143: @Override
144: public IRI getIRI() {
145: return iri;
146: }
147:
148: @Override
149: public CascadeType[] getCascadeTypes() {
150: return cascadeTypes;
151: }
152:
153:
154: @Override
155: public FetchType getFetchType() {
156: return fetchType;
157: }
158:
159:
160: @Override
161: public String toString() {
162: return "SingularAttribute[" + name + "]";
163: }
164:
165: @Override
166: public boolean isInferred() {
167: return inferred;
168: }
169:
170: @Override
171: public ParticipationConstraint[] getConstraints() {
172: return constraints;
173: }
174:
175: @Override
176: public boolean includeExplicit() {
177: return includeExplicit;
178: }
179:
180: @Override
181: public boolean isReadOnly() {
182: return readOnly;
183: }
184:
185: public static SingularAttributeBuilder iri(IRI iri) {
186: return new SingularAttributeBuilder().iri(iri);
187: }
188:
189: public static final class SingularAttributeBuilder<X, T> {
190: private boolean id;
191: private String name;
192: private Type<T> type;
193: private Field field;
194: private ManagedType<X> declaringType;
195: private PersistentAttributeType attributeType;
196: private IRI iri;
197: private CascadeType[] cascadeTypes;
198: private FetchType fetchType;
199: private boolean inferred;
200: private boolean includeExplicit;
201: private boolean readOnly;
202: private boolean nonEmpty = false;
203: private ParticipationConstraint[] constraints;
204:
205: public SingularAttributeBuilder identifier(boolean isId) {
206: this.id = isId;
207: return this;
208: }
209:
210: public SingularAttributeBuilder name(String name) {
211: this.name = name;
212: return this;
213: }
214:
215: public SingularAttributeBuilder type(Type<T> type) {
216: this.type = type;
217: return this;
218: }
219:
220: public SingularAttributeBuilder field(Field field) {
221: this.field = field;
222: return this;
223: }
224:
225: public SingularAttributeBuilder declaringType(ManagedType<X> declaringType) {
226: this.declaringType = declaringType;
227: return this;
228: }
229:
230: public SingularAttributeBuilder attributeType(PersistentAttributeType attributeType) {
231: this.attributeType = attributeType;
232: return this;
233: }
234:
235: public SingularAttributeBuilder iri(IRI iri) {
236: this.iri = iri;
237: return this;
238: }
239:
240: public SingularAttributeBuilder<X, T> cascadeTypes(CascadeType[] cascadeTypes) {
241: this.cascadeTypes = cascadeTypes;
242: return this;
243: }
244:
245: public SingularAttributeBuilder<X, T> fetchType(FetchType fetchType) {
246: this.fetchType = fetchType;
247: return this;
248: }
249:
250: public SingularAttributeBuilder<X, T> inferred(boolean inferred) {
251: this.inferred = inferred;
252: return this;
253: }
254:
255: public SingularAttributeBuilder<X, T> includeExplicit(boolean includeExplicit) {
256: this.includeExplicit = includeExplicit;
257: return this;
258: }
259:
260: public SingularAttributeBuilder<X, T> readOnly(boolean readOnly) {
261: this.readOnly = readOnly;
262: return this;
263: }
264:
265: public SingularAttributeBuilder<X, T> constraints(ParticipationConstraint[] constraints) {
266: this.constraints = constraints;
267: return this;
268: }
269:
270: public SingularAttributeBuilder<X, T> nonEmpty(boolean nonEmpty) {
271: this.nonEmpty = nonEmpty;
272: return this;
273: }
274:
275: public SingularAttribute<X, T> build() {
276: return new SingularAttributeImpl<>(this);
277: }
278: }
279: }