-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
CompositePluralAttributeElementSourceImpl.java
185 lines (165 loc) · 6.33 KB
/
CompositePluralAttributeElementSourceImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.internal.source.hbm;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.EntityMode;
import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.jaxb.spi.hbm.JaxbAnyElement;
import org.hibernate.jaxb.spi.hbm.JaxbCompositeElementElement;
import org.hibernate.jaxb.spi.hbm.JaxbManyToOneElement;
import org.hibernate.jaxb.spi.hbm.JaxbNestedCompositeElementElement;
import org.hibernate.jaxb.spi.hbm.JaxbPropertyElement;
import org.hibernate.jaxb.spi.hbm.JaxbTuplizerElement;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.source.AttributeSource;
import org.hibernate.metamodel.spi.source.CompositePluralAttributeElementSource;
import org.hibernate.metamodel.spi.source.LocalBindingContext;
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
import org.hibernate.metamodel.spi.source.SingularAttributeSource;
/**
* @author Steve Ebersole
* @author Gail Badner
*/
public class CompositePluralAttributeElementSourceImpl
extends AbstractHbmSourceNode
implements CompositePluralAttributeElementSource {
private final JaxbCompositeElementElement compositeElement;
private final Iterable<CascadeStyle> cascadeStyles;
private final List<AttributeSource> attributeSources;
public CompositePluralAttributeElementSourceImpl(
MappingDocument mappingDocument,
JaxbCompositeElementElement compositeElement,
String cascadeString) {
super( mappingDocument );
this.compositeElement = compositeElement;
this.cascadeStyles = Helper.interpretCascadeStyles( cascadeString, bindingContext() );
this.attributeSources = buildAttributeSources( mappingDocument, compositeElement );
}
@Override
public Nature getNature() {
return Nature.AGGREGATE;
}
@Override
public String getClassName() {
return bindingContext().qualifyClassName( compositeElement.getClazz() );
}
@Override
public ValueHolder<Class<?>> getClassReference() {
return bindingContext().makeClassReference( getClassName() );
}
@Override
public String getParentReferenceAttributeName() {
return compositeElement.getParent() != null
? compositeElement.getParent().getName()
: null;
}
@Override
public String getExplicitTuplizerClassName() {
if ( compositeElement.getTuplizer() == null ) {
return null;
}
final EntityMode entityMode = StringHelper.isEmpty( compositeElement.getClazz() ) ? EntityMode.MAP : EntityMode.POJO;
for ( JaxbTuplizerElement tuplizerElement : compositeElement.getTuplizer() ) {
if ( entityMode == EntityMode.parse( tuplizerElement.getEntityMode().value() ) ) {
return tuplizerElement.getClazz();
}
}
return null;
}
@Override
public String getPath() {
// todo : implementing this requires passing in the collection source and being able to resolve the collection's role
return null;
}
@Override
public List<AttributeSource> attributeSources() {
return attributeSources;
}
private static List<AttributeSource> buildAttributeSources(
MappingDocument mappingDocument,
JaxbCompositeElementElement compositeElement) {
List<AttributeSource> attributeSources = new ArrayList<AttributeSource>();
for( final JaxbAnyElement element : compositeElement.getAny() ) {
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
}
for( final JaxbManyToOneElement element : compositeElement.getManyToOne() ) {
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
}
for( final JaxbNestedCompositeElementElement element : compositeElement.getNestedCompositeElement() ) {
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
}
for( final JaxbPropertyElement element : compositeElement.getProperty() ) {
attributeSources.add( buildAttributeSource( mappingDocument, element ) );
}
return attributeSources;
}
@Override
public LocalBindingContext getLocalBindingContext() {
return bindingContext();
}
@Override
public Iterable<CascadeStyle> getCascadeStyles() {
return cascadeStyles;
}
private static AttributeSource buildAttributeSource(
MappingDocument sourceMappingDocument,
JaxbAnyElement attributeElement) {
// todo : implement
throw new NotYetImplementedException();
}
private static SingularAttributeSource buildAttributeSource(
MappingDocument sourceMappingDocument,
JaxbPropertyElement attributeElement) {
return new PropertyAttributeSourceImpl(
sourceMappingDocument,
attributeElement,
null,
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
);
}
private static AttributeSource buildAttributeSource(
MappingDocument sourceMappingDocument,
JaxbManyToOneElement attributeElement) {
return new ManyToOneAttributeSourceImpl(
sourceMappingDocument,
JaxbManyToOneElement.class.cast( attributeElement ),
null,
SingularAttributeBinding.NaturalIdMutability.NOT_NATURAL_ID
);
}
private static AttributeSource buildAttributeSource(
MappingDocument sourceMappingDocument,
JaxbNestedCompositeElementElement attributeElement) {
// todo : implement
throw new NotYetImplementedException();
}
@Override
public Iterable<? extends MetaAttributeSource> getMetaAttributeSources() {
return compositeElement.getMeta();
}
}