Skip to contentMethod: includeExplicit()
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.model.metamodel;
19:
20: import cz.cvut.kbss.jopa.model.annotations.FetchType;
21:
22: import java.lang.reflect.Field;
23:
24: public class PropertiesSpecificationImpl<X, Y, K, V> implements PropertiesSpecification<X, Y, K, V> {
25: private final ManagedType<X> declaringType;
26: private final FetchType fetchType;
27: private final Field javaField;
28: private final Class<Y> javaType;
29: private final boolean inferred;
30: private final Class<K> propertyIdType;
31: private final Class<V> propertyValueType;
32:
33: private PropertiesSpecificationImpl(PropertiesSpecificationBuilder<X, Y, K, V> builder) {
34: this.declaringType = builder.declaringType;
35: this.fetchType = builder.fetchType;
36: this.javaField = builder.javaField;
37: this.javaType = builder.javaType;
38: this.inferred = builder.inferred;
39: this.propertyIdType = builder.propertyIdType;
40: this.propertyValueType = builder.propertyValueType;
41: }
42:
43: @Override
44: public ManagedType<X> getDeclaringType() {
45: return declaringType;
46: }
47:
48: @Override
49: public FetchType getFetchType() {
50: return fetchType;
51: }
52:
53: @Override
54: public Field getJavaField() {
55: return javaField;
56: }
57:
58: @Override
59: public Class<Y> getJavaType() {
60: return javaType;
61: }
62:
63: @Override
64: public boolean isInferred() {
65: return inferred;
66: }
67:
68: @Override
69: public boolean includeExplicit() {
70: // TODO
71: return true;
72: }
73:
74: @Override
75: public String getName() {
76: return javaField.getName();
77: }
78:
79: @Override
80: public boolean isCollection() {
81: return true;
82: }
83:
84: @Override
85: public Class<K> getPropertyIdentifierType() {
86: return propertyIdType;
87: }
88:
89: @Override
90: public Class<V> getPropertyValueType() {
91: return propertyValueType;
92: }
93:
94: public static <X, Y, K, V> PropertiesSpecificationBuilder declaringType(ManagedType<X> declaringType) {
95: return new PropertiesSpecificationBuilder<X, Y, K, V>().declaringType(declaringType);
96: }
97:
98: public static class PropertiesSpecificationBuilder<X, Y, K, V> {
99: private ManagedType<X> declaringType;
100: private FetchType fetchType;
101: private Field javaField;
102: private Class<Y> javaType;
103: private boolean inferred;
104: private Class<K> propertyIdType;
105: private Class<V> propertyValueType;
106:
107: public PropertiesSpecificationBuilder<X, Y, K, V> declaringType(ManagedType<X> declaringType) {
108: this.declaringType = declaringType;
109: return this;
110: }
111:
112: public PropertiesSpecificationBuilder<X, Y, K, V> fetchType(FetchType fetchType) {
113: this.fetchType = fetchType;
114: return this;
115: }
116:
117: public PropertiesSpecificationBuilder<X, Y, K, V> javaField(Field javaField) {
118: this.javaField = javaField;
119: return this;
120: }
121:
122: public PropertiesSpecificationBuilder<X, Y, K, V> javaType(Class<Y> javaType) {
123: this.javaType = javaType;
124: return this;
125: }
126:
127: public PropertiesSpecificationBuilder<X, Y, K, V> inferred(boolean inferred) {
128: this.inferred = inferred;
129: return this;
130: }
131:
132: public PropertiesSpecificationBuilder<X, Y, K, V> propertyIdType(Class<K> propertyIdType) {
133: this.propertyIdType = propertyIdType;
134: return this;
135: }
136:
137: public PropertiesSpecificationBuilder<X, Y, K, V> propertyValueType(Class<V> propertyValueType) {
138: this.propertyValueType = propertyValueType;
139: return this;
140: }
141:
142: public PropertiesSpecificationImpl<X, Y, K, V> build() {
143: return new PropertiesSpecificationImpl<>(this);
144: }
145: }
146: }