io.github.jeddict.jpa.spec.ElementCollection Maven / Gradle / Ivy
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2014.01.21 at 01:52:19 PM IST
//
package io.github.jeddict.jpa.spec;
import com.github.javaparser.resolution.UnsolvedSymbolException;
import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration;
import io.github.jeddict.bv.constraints.Constraint;
import io.github.jeddict.bv.constraints.Size;
import io.github.jeddict.jaxb.spec.JaxbVariableType;
import static io.github.jeddict.jcode.JPAConstants.EMBEDDABLE_FQN;
import static io.github.jeddict.jcode.JPAConstants.ENTITY_FQN;
import static io.github.jeddict.jcode.util.JavaUtil.isMap;
import io.github.jeddict.jpa.spec.extend.AssociationOverrideHandler;
import io.github.jeddict.jpa.spec.extend.Attribute;
import io.github.jeddict.jpa.spec.extend.CollectionTypeHandler;
import io.github.jeddict.jpa.spec.extend.ColumnHandler;
import io.github.jeddict.jpa.spec.extend.CompositionAttribute;
import io.github.jeddict.jpa.spec.extend.ConvertContainerHandler;
import io.github.jeddict.jpa.spec.extend.ConvertHandler;
import io.github.jeddict.jpa.spec.extend.EnumTypeHandler;
import io.github.jeddict.jpa.spec.extend.FetchTypeHandler;
import io.github.jeddict.jpa.spec.extend.MapKeyConvertContainerHandler;
import io.github.jeddict.jpa.spec.extend.MapKeyConvertHandler;
import io.github.jeddict.jpa.spec.extend.MapKeyHandler;
import io.github.jeddict.jpa.spec.extend.MapKeyType;
import io.github.jeddict.jpa.spec.extend.SortableAttribute;
import io.github.jeddict.jpa.spec.extend.TemporalTypeHandler;
import io.github.jeddict.jpa.spec.validator.override.AssociationValidator;
import io.github.jeddict.jpa.spec.validator.override.AttributeValidator;
import io.github.jeddict.source.AnnotationExplorer;
import io.github.jeddict.source.MemberExplorer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import jakarta.persistence.MapKeyColumn;
import jakarta.persistence.MapKeyJoinColumn;
import jakarta.xml.bind.Marshaller;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlIDREF;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.XmlType;
import io.github.jeddict.util.StringUtils;
/**
*
*
* @Target({METHOD, FIELD}) @Retention(RUNTIME) public @interface
* ElementCollection { Class targetClass() default void.class; FetchType fetch()
* default LAZY; }
*
*
*
*
* Java class for element-collection complex type.
*
*
* The following schema fragment specifies the expected content contained within
* this class.
*
*
* <complexType name="element-collection">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <choice>
* <element name="order-by" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}order-by" minOccurs="0"/>
* <element name="order-column" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}order-column" minOccurs="0"/>
* </choice>
* <choice>
* <element name="map-key" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}map-key" minOccurs="0"/>
* <sequence>
* <element name="map-key-class" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}map-key-class" minOccurs="0"/>
* <choice>
* <element name="map-key-temporal" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}temporal" minOccurs="0"/>
* <element name="map-key-enumerated" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}enumerated" minOccurs="0"/>
* <sequence>
* <element name="map-key-attribute-override" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}attribute-override" maxOccurs="unbounded" minOccurs="0"/>
* <element name="map-key-convert" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}convert" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </choice>
* <choice>
* <element name="map-key-column" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}map-key-column" minOccurs="0"/>
* <sequence>
* <element name="map-key-join-column" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}map-key-join-column" maxOccurs="unbounded" minOccurs="0"/>
* <element name="map-key-foreign-key" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}foreign-key" minOccurs="0"/>
* </sequence>
* </choice>
* </sequence>
* </choice>
* <choice>
* <sequence>
* <element name="column" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}column" minOccurs="0"/>
* <choice>
* <element name="temporal" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}temporal" minOccurs="0"/>
* <element name="enumerated" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}enumerated" minOccurs="0"/>
* <element name="lob" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}lob" minOccurs="0"/>
* </choice>
* </sequence>
* <sequence>
* <element name="attribute-override" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}attribute-override" maxOccurs="unbounded" minOccurs="0"/>
* <element name="association-override" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}association-override" maxOccurs="unbounded" minOccurs="0"/>
* <element name="convert" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}convert" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </choice>
* <element name="collection-table" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}collection-table" minOccurs="0"/>
* </sequence>
* <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="target-class" type="{http://www.w3.org/2001/XMLSchema}string" />
* <attribute name="fetch" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}fetch-type" />
* <attribute name="access" type="{http://xmlns.jcp.org/xml/ns/persistence/orm}access-type" />
* </restriction>
* </complexContent>
* </complexType>
*
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "element-collection", propOrder = {
"orderBy",
"orderColumn",
"mapKeyColumn",
"mapKeyTemporal",
"mapKeyEnumerated",
"mapKeyAttributeOverride",
"mapKeyConvert",
"mapKeyJoinColumn",
"mapKeyForeignKey",
"column",
"temporal",
"enumerated",
"lob",
"attributeOverride",
"associationOverride",
"convert",
"collectionTable"
})
@XmlRootElement
/**
* For Basic ElementCollection -> TargetClass
* For Embeddable ElementCollection -> ConnectedClass
*/
public class ElementCollection extends CompositionAttribute implements
SortableAttribute, FetchTypeHandler,
ColumnHandler, AssociationOverrideHandler,
CollectionTypeHandler, MapKeyHandler,
TemporalTypeHandler, EnumTypeHandler,
ConvertContainerHandler, ConvertHandler,
MapKeyConvertContainerHandler, MapKeyConvertHandler { //CompositionAttribute/BaseAttributes
@XmlElement(name = "ob")
protected OrderBy orderBy;
@XmlElement(name = "oc")
protected OrderColumn orderColumn;
protected Column column;
protected TemporalType temporal;
protected EnumType enumerated;
protected Lob lob;
@XmlElement(name = "attribute-override")
protected Set attributeOverride;
@XmlElement(name = "association-override")
protected Set associationOverride;
@XmlElement(name = "cn")
protected List convert;
@XmlElement(name = "collection-table")
protected CollectionTable collectionTable;
@XmlAttribute(name = "target-class")
protected String targetClass;
@XmlAttribute(name = "fetch")
protected FetchType fetch;
@XmlAttribute(name = "access")
protected AccessType access;
@XmlAttribute(name = "collection-type")
private String collectionType;
@XmlAttribute(name = "cit")
private String collectionImplType;
@XmlElement(name = "mkcn")
protected List mapKeyConvert;
@XmlAttribute(name = "mkt")
private MapKeyType mapKeyType;
//Existing MapKeyType
@XmlAttribute(name = "mkat-ref")//attribute-ref
@XmlIDREF
private Attribute mapKeyAttribute;
@XmlTransient//@XmlElement(name = "map-key")//Not required
protected MapKey mapKey;//only required in rev-eng and stored to mapKeyAttribute
//New MapKeyType - Basic
@XmlAttribute(name = "mkat")
private String mapKeyAttributeType; //e.g String, int, Enum, Date applicable for basic,enumerated,temporal
@XmlElement(name = "mkc")
protected Column mapKeyColumn;
@XmlElement(name = "mktemp")
protected TemporalType mapKeyTemporal;
@XmlElement(name = "mkenum")
protected EnumType mapKeyEnumerated;
//@XmlElement(name = "map-key-class")//Not required
//protected MapKeyClass mapKeyClass; //rev-eng done and stored to mapKeyAttributeType
//New MapKeyType - Entity
@XmlAttribute(name = "mken-ref")//entity-ref
@XmlIDREF
private Entity mapKeyEntity;
@XmlElement(name = "mkjc")
protected List mapKeyJoinColumn;
@XmlElement(name = "mkfk")
protected ForeignKey mapKeyForeignKey;
//New MapKeyType - Embeddable
@XmlAttribute(name = "mkem-ref")
@XmlIDREF
private Embeddable mapKeyEmbeddable;
@XmlElement(name = "mkao")
protected Set mapKeyAttributeOverride;
public static ElementCollection load(ElementCollection elementCollection, MemberExplorer member) {
AnnotationExplorer annotation = member.getAnnotation(jakarta.persistence.ElementCollection.class).get();
elementCollection.loadAttribute(member);
elementCollection.column = Column.load(member);
elementCollection.temporal = TemporalType.load(member);
elementCollection.enumerated = EnumType.load(member);
elementCollection.lob = Lob.load(member);
elementCollection.attributeOverride = AttributeOverride.load(member);
elementCollection.associationOverride = AssociationOverride.load(member);
elementCollection.collectionTable = CollectionTable.load(member);
elementCollection.orderBy = OrderBy.load(member);
elementCollection.orderColumn = OrderColumn.load(member);
elementCollection.fetch = FetchType.load(annotation);
elementCollection.access = AccessType.load(member);
elementCollection.collectionType = member.getType(); // ?? collection ??
Class collectionTypeClass = null;
try {
collectionTypeClass = Class.forName(elementCollection.collectionType);
} catch (ClassNotFoundException ex) {
}
boolean mapKeyExist = collectionTypeClass != null && Map.class.isAssignableFrom(collectionTypeClass);
Optional targetTypeOpt = annotation.getResolvedClass("targetClass");
ResolvedTypeDeclaration targetType;
if (targetTypeOpt.isPresent()) {
targetType = targetTypeOpt.get();
} else {
Optional targetTypeOpt2 = member.getTypeArgumentDeclaration(mapKeyExist ? 1 : 0);
if (targetTypeOpt2.isPresent()) {
targetType = targetTypeOpt2.get();
elementCollection.setValueConstraints(member.getTypeArgumentBeanValidationConstraints(mapKeyExist ? 1 : 0));
} else {
throw new UnsolvedSymbolException("targetClass or generic type not defined in ElementCollection attribute '" + member.getFieldName() + "'");
}
}
if (targetType instanceof ResolvedReferenceTypeDeclaration
&& ((ResolvedReferenceTypeDeclaration)targetType).hasDirectlyAnnotation(EMBEDDABLE_FQN)) {
Optional embeddableOpt = member.getSource().findEmbeddable(((ResolvedReferenceTypeDeclaration)targetType));
if (!embeddableOpt.isPresent()) {
return null;
}
elementCollection.setConnectedClass(embeddableOpt.get());
} else {
elementCollection.setTargetClass(targetType.getQualifiedName());
}
elementCollection.convert = Convert.load(member, mapKeyExist, false);
if (mapKeyExist) {
elementCollection.mapKeyConvert = Convert.load(member, mapKeyExist, true);
elementCollection.mapKey = MapKey.load(member);
elementCollection.mapKeyType = elementCollection.mapKey != null ? MapKeyType.EXT : MapKeyType.NEW;
ResolvedTypeDeclaration keyType = MapKeyClass.getDeclaredType(member);
if (keyType instanceof ResolvedReferenceTypeDeclaration) {
ResolvedReferenceTypeDeclaration refKeyType = (ResolvedReferenceTypeDeclaration) keyType;
if (refKeyType.hasDirectlyAnnotation(EMBEDDABLE_FQN)) {
Optional embeddableOpt = member.getSource().findEmbeddable(refKeyType);
if (!embeddableOpt.isPresent()) {
return null;
}
elementCollection.mapKeyAttributeType = embeddableOpt.get().getClazz(); //TODO set Embeddable
} else if (refKeyType.hasDirectlyAnnotation(ENTITY_FQN)) {
Optional entityOpt = member.getSource().findEntity(refKeyType);
if (!entityOpt.isPresent()) {
return null;
}
elementCollection.mapKeyAttributeType = entityOpt.get().getClazz(); //TODO set Entity
}
} else {
elementCollection.mapKeyAttributeType = keyType.getQualifiedName();
}
elementCollection.mapKeyColumn = Column.loadMapKey(member);
elementCollection.mapKeyTemporal = TemporalType.loadMapKey(member);
elementCollection.mapKeyEnumerated = EnumType.loadMapKey(member);
elementCollection.mapKeyJoinColumn = JoinColumn.loadMapKey(member);
member.getAnnotation(jakarta.persistence.ForeignKey.class)
.map(ForeignKey::load)
.ifPresent(elementCollection::setMapKeyForeignKey);
elementCollection.mapKeyAttributeOverride = AttributeOverride.load(member);
// TODO if both side are Embeddable then how to diffrentiat MapKeyAttributeOverride and AttributeOverride
// with single @AttributeOverride means there is no @MapKeyAttributeOverride ?
// currently AttributeValidator will remove the invalid
}
return elementCollection;
}
@Override
public void beforeMarshal(Marshaller marshaller) {
super.beforeMarshal(marshaller);
AttributeValidator.filter(this);
AssociationValidator.filter(this);
}
/**
* Gets the value of the orderBy property.
*
* @return possible object is {@link String }
*
*/
@Override
public OrderBy getOrderBy() {
return orderBy;
}
/**
* Sets the value of the orderBy property.
*
* @param value allowed object is {@link String }
*
*/
@Override
public void setOrderBy(OrderBy value) {
this.orderBy = value;
}
/**
* Gets the value of the orderColumn property.
*
* @return possible object is {@link OrderColumn }
*
*/
@Override
public OrderColumn getOrderColumn() {
return orderColumn;
}
/**
* Sets the value of the orderColumn property.
*
* @param value allowed object is {@link OrderColumn }
*
*/
@Override
public void setOrderColumn(OrderColumn value) {
this.orderColumn = value;
}
/**
* Gets the value of the mapKey property.
*
* @return possible object is {@link MapKey }
*
*/
@Override
public MapKey getMapKey() {
return mapKey;
}
/**
* Sets the value of the mapKey property.
*
* @param value allowed object is {@link MapKey }
*
*/
@Override
public void setMapKey(MapKey value) {
this.mapKey = value;
}
/**
* Gets the value of the mapKeyTemporal property.
*
* @return possible object is {@link TemporalType }
*
*/
@Override
public TemporalType getMapKeyTemporal() {
return mapKeyTemporal;
}
/**
* Sets the value of the mapKeyTemporal property.
*
* @param value allowed object is {@link TemporalType }
*
*/
@Override
public void setMapKeyTemporal(TemporalType value) {
this.mapKeyTemporal = value;
}
/**
* Gets the value of the mapKeyEnumerated property.
*
* @return possible object is {@link EnumType }
*
*/
@Override
public EnumType getMapKeyEnumerated() {
return mapKeyEnumerated;
}
/**
* Sets the value of the mapKeyEnumerated property.
*
* @param value allowed object is {@link EnumType }
*
*/
@Override
public void setMapKeyEnumerated(EnumType value) {
this.mapKeyEnumerated = value;
}
/**
* Gets the value of the mapKeyAttributeOverride property.
*
*
* This accessor method returns a reference to the live list, not a
* snapshot. Therefore any modification you make to the returned list will
* be present inside the JAXB object. This is why there is not a
* set
method for the mapKeyAttributeOverride property.
*
*
* For example, to add a new item, do as follows:
*
* getMapKeyAttributeOverride().add(newItem);
*
*
*
*
* Objects of the following type(s) are allowed in the list
* {@link AttributeOverride }
*
*
* @return
*/
@Override
public Set getMapKeyAttributeOverride() {
if (mapKeyAttributeOverride == null) {
mapKeyAttributeOverride = new TreeSet<>();
}
return this.mapKeyAttributeOverride;
}
/**
* Gets the value of the mapKeyColumn property.
*
* @return possible object is {@link MapKeyColumn }
*
*/
@Override
public Column getMapKeyColumn() {
if (mapKeyColumn == null) {
mapKeyColumn = new Column();
}
return mapKeyColumn;
}
/**
* Sets the value of the =property.
*
* @param value allowed object is {@link MapKeyColumn }
*
*/
@Override
public void setMapKeyColumn(Column value) {
this.mapKeyColumn = value;
}
/**
* Gets the value of the mapKeyJoinColumn property.
*
*
* This accessor method returns a reference to the live list, not a
* snapshot. Therefore any modification you make to the returned list will
* be present inside the JAXB object. This is why there is not a
* set
method for the mapKeyJoinColumn property.
*
*
* For example, to add a new item, do as follows:
*
* getMapKeyJoinColumn().add(newItem);
*
*
*
*
* Objects of the following type(s) are allowed in the list
* {@link MapKeyJoinColumn }
*
*
*/
@Override
public List getMapKeyJoinColumn() {
if (mapKeyJoinColumn == null) {
mapKeyJoinColumn = new ArrayList<>();
}
return this.mapKeyJoinColumn;
}
/**
* Gets the value of the mapKeyForeignKey property.
*
* @return possible object is {@link ForeignKey }
*
*/
@Override
public ForeignKey getMapKeyForeignKey() {
return mapKeyForeignKey;
}
/**
* Sets the value of the mapKeyForeignKey property.
*
* @param value allowed object is {@link ForeignKey }
*
*/
@Override
public void setMapKeyForeignKey(ForeignKey value) {
this.mapKeyForeignKey = value;
}
/**
* Gets the value of the column property.
*
* @return possible object is {@link Column }
*
*/
@Override
public Column getColumn() {
if (column == null) {
column = new Column();
}
return column;
}
/**
* Sets the value of the column property.
*
* @param value allowed object is {@link Column }
*
*/
@Override
public void setColumn(Column value) {
this.column = value;
}
/**
* Gets the value of the temporal property.
*
* @return possible object is {@link TemporalType }
*
*/
@Override
public TemporalType getTemporal() {
return temporal;
}
/**
* Sets the value of the temporal property.
*
* @param value allowed object is {@link TemporalType }
*
*/
@Override
public void setTemporal(TemporalType value) {
this.temporal = value;
}
/**
* Gets the value of the enumerated property.
*
* @return possible object is {@link EnumType }
*
*/
@Override
public EnumType getEnumerated() {
return enumerated;
}
/**
* Sets the value of the enumerated property.
*
* @param value allowed object is {@link EnumType }
*
*/
@Override
public void setEnumerated(EnumType value) {
this.enumerated = value;
}
/**
* Gets the value of the lob property.
*
* @return possible object is {@link Lob }
*
*/
public Lob getLob() {
return lob;
}
/**
* Sets the value of the lob property.
*
* @param value allowed object is {@link Lob }
*
*/
public void setLob(Lob value) {
this.lob = value;
}
/**
* Gets the value of the attributeOverride property.
*
*
* This accessor method returns a reference to the live list, not a
* snapshot. Therefore any modification you make to the returned list will
* be present inside the JAXB object. This is why there is not a
* set
method for the attributeOverride property.
*
*
* For example, to add a new item, do as follows:
*
* getAttributeOverride().add(newItem);
*
*
*
*
* Objects of the following type(s) are allowed in the list
* {@link AttributeOverride }
*
*
*/
@Override
public Set getAttributeOverride() {
if (attributeOverride == null) {
attributeOverride = new TreeSet<>();
}
return this.attributeOverride;
}
@Override
public AttributeOverride findAttributeOverride(String name) {
for (AttributeOverride attributeOverride : getAttributeOverride()) {
if (StringUtils.equals(name, attributeOverride.getName())) {
return attributeOverride;
}
}
return null;
}
@Override
public boolean addAttributeOverride(AttributeOverride attributeOverride) {
return getAttributeOverride().add(attributeOverride);
}
@Override
public boolean removeAttributeOverride(AttributeOverride attributeOverride) {
return getAttributeOverride().remove(attributeOverride);
}
/**
* Gets the value of the associationOverride property.
*
*
* This accessor method returns a reference to the live list, not a
* snapshot. Therefore any modification you make to the returned list will
* be present inside the JAXB object. This is why there is not a
* set
method for the associationOverride property.
*
*
* For example, to add a new item, do as follows:
*
* getAssociationOverride().add(newItem);
* {@link AssociationOverride }
*
*
*
*
* Objects of the following type(s) are allowed in the list
*
*
*/
@Override
public Set getAssociationOverride() {
if (associationOverride == null) {
associationOverride = new TreeSet<>();
}
return this.associationOverride;
}
@Override
public AssociationOverride findAssociationOverride(String name) {
for (AssociationOverride associationOverride : getAssociationOverride()) {
if (StringUtils.equals(name, associationOverride.getName())) {
return associationOverride;
}
}
return null;
}
@Override
public boolean addAssociationOverride(AssociationOverride associationOverride) {
return getAssociationOverride().add(associationOverride);
}
@Override
public boolean removeAssociationOverride(AssociationOverride associationOverride) {
return getAssociationOverride().remove(associationOverride);
}
/**
* Used in case of ElementCollection
* Gets the value of the convert property.
*
*
* This accessor method returns a reference to the live list, not a
* snapshot. Therefore any modification you make to the returned list will
* be present inside the JAXB object. This is why there is not a
* set
method for the convert property.
*
*
* For example, to add a new item, do as follows:
*
* getConvert().add(newItem);
*
*
*
*
* Objects of the following type(s) are allowed in the list {@link Convert }
*
*
*/
@Override
public List getConverts() {
if (convert == null) {
convert = new ArrayList<>();
}
return this.convert;
}
@Override
public void setConverts(List converts) {
this.convert = converts;
}
/**
* Used in case of ElementCollection
*
* @return Convert
*/
@Override
public Convert getConvert() {
if (getConverts().isEmpty() || getConverts().get(0) == null) {
getConverts().add(new Convert());
}
if (getConverts().size() > 1) {//clear unused
getConverts().subList(1, getConverts().size()).clear();
}
return getConverts().get(0);
}
@Override
public void setConvert(Convert convert) {
getConverts().set(0, convert);
}
/**
* Gets the value of the mapKeyConvert property.
*
*
* This accessor method returns a reference to the live list, not a
* snapshot. Therefore any modification you make to the returned list will
* be present inside the JAXB object. This is why there is not a
* set
method for the mapKeyConvert property.
*
*
* For example, to add a new item, do as follows:
*
* getMapKeyConvert().add(newItem);
*
*
*
*
* Objects of the following type(s) are allowed in the list {@link Convert }
*
*
*/
@Override
public List getMapKeyConverts() {
if (mapKeyConvert == null) {
mapKeyConvert = new ArrayList<>();
}
return this.mapKeyConvert;
}
@Override
public void setMapKeyConverts(List converts) {
this.mapKeyConvert = converts;
}
/**
* Used in case of ElementCollection
*
* @return Convert
*/
@Override
public Convert getMapKeyConvert() {
if (getMapKeyConverts().isEmpty() || getMapKeyConverts().get(0) == null) {
getMapKeyConverts().add(new Convert());
}
if (getMapKeyConverts().size() > 1) {//clear unused
getMapKeyConverts().subList(1, getMapKeyConverts().size()).clear();
}
return getMapKeyConverts().get(0);
}
@Override
public void setMapKeyConvert(Convert convert) {
getMapKeyConverts().set(0, convert);
}
/**
* Gets the value of the collectionTable property.
*
* @return possible object is {@link CollectionTable }
*
*/
public CollectionTable getCollectionTable() {
if (collectionTable == null) {
collectionTable = new CollectionTable();
}
return collectionTable;
}
/**
* Sets the value of the collectionTable property.
*
* @param value allowed object is {@link CollectionTable }
*
*/
public void setCollectionTable(CollectionTable value) {
this.collectionTable = value;
}
/**
* Gets the value of the targetClass property.
*
* @return possible object is {@link String }
*
*/
public String getTargetClass() {
return targetClass;
}
/**
* Sets the value of the targetClass property.
*
* @param value allowed object is {@link String }
*
*/
public void setTargetClass(String value) {
this.targetClass = value;
}
/**
* Gets the value of the fetch property.
*
* @return possible object is {@link FetchType }
*
*/
@Override
public FetchType getFetch() {
return fetch;
}
/**
* Sets the value of the fetch property.
*
* @param value allowed object is {@link FetchType }
*
*/
@Override
public void setFetch(FetchType value) {
this.fetch = value;
}
/**
* Gets the value of the access property.
*
* @return possible object is {@link AccessType }
*
*/
@Override
public AccessType getAccess() {
return access;
}
/**
* Sets the value of the access property.
*
* @param value allowed object is {@link AccessType }
*
*/
@Override
public void setAccess(AccessType value) {
this.access = value;
}
/**
* @return the collectionType
*/
@Override
public String getCollectionType() {
if (collectionType == null) {
collectionType = List.class.getName();
}
return collectionType;
}
/**
* @param collectionType the collectionType to set
*/
@Override
public void setCollectionType(String collectionType) {
this.collectionType = collectionType;
}
/**
* @return the collectionImplType
*/
@Override
public String getCollectionImplType() {
return collectionImplType;
}
/**
* @param collectionImplType the collectionImplementationType to set
*/
@Override
public void setCollectionImplType(String collectionImplType) {
this.collectionImplType = collectionImplType;
}
@Override
public AttributeOverride getAttributeOverride(String attributePath) {
Set attributeOverrides = getAttributeOverride();
for (AttributeOverride attributeOverride_TMP : attributeOverrides) {
if (attributeOverride_TMP.getName().equals(attributePath)) {
return attributeOverride_TMP;
}
}
AttributeOverride attributeOverride_TMP = new AttributeOverride();
attributeOverride_TMP.setName(attributePath);
attributeOverrides.add(attributeOverride_TMP);
return attributeOverride_TMP;
}
@Override
public AssociationOverride getAssociationOverride(String attributePath) {
Set associationOverrides = getAssociationOverride();
for (AssociationOverride associationOverride_TMP : associationOverrides) {
if (associationOverride_TMP.getName().equals(attributePath)) {
return associationOverride_TMP;
}
}
AssociationOverride attributeOverride_TMP = new AssociationOverride();
attributeOverride_TMP.setName(attributePath);
associationOverrides.add(attributeOverride_TMP);
return attributeOverride_TMP;
}
@Override
public List getJaxbVariableList() {
if (this.getConnectedClass() != null) { //Embedded //Complex
return super.getJaxbVariableList();
} else { //Basic //Simple
return Arrays.asList(JaxbVariableType.values());
}
}
@Override
public String getAttributeType() {
return this.getConnectedClass() != null ? super.getAttributeType() : targetClass;
}
@Override
public boolean isTextAttributeType() {
if (isMap(getCollectionType())) {
return isTextAttributeType(getMapKeyAttributeType());
} else {
return isTextAttributeType(getAttributeType());
}
}
@Override
public boolean isBlobAttributeType() {
return isBlobAttributeType(getAttributeType());
}
@Override
public boolean isPrecisionAttributeType() {
if (isMap(getCollectionType())) {
return isPrecisionAttributeType(getMapKeyAttributeType());
} else {
return isPrecisionAttributeType(getAttributeType());
}
}
@Override
public boolean isScaleAttributeType() {
if (isMap(getCollectionType())) {
return isScaleAttributeType(getMapKeyAttributeType());
} else {
return isScaleAttributeType(getAttributeType());
}
}
@Override
public String getDefaultColumnName() {
return this.getName().toUpperCase();
}
@Override
public String getDefaultMapKeyColumnName() {
return this.getName().toUpperCase()+"_KEY";
}
//used in db modeler element-config.xml expression
@Override
public boolean isTextMapKeyAttributeType() {
return isTextAttributeType(getMapKeyAttributeType());
}
@Override
public boolean isPrecisionpMapKeyAttributeType() {
return isPrecisionAttributeType(getMapKeyAttributeType());
}
@Override
public boolean isScaleMapKeyAttributeType() {
return isScaleAttributeType(getMapKeyAttributeType());
}
@Override
public String getColumnName() {
if (this.getColumn() != null && StringUtils.isNotBlank(this.getColumn().getName())) {
return getColumn().getName();
} else {
return getDefaultColumnName();
}
}
@Override
public String getDataTypeLabel() {
if (getValidatedMapKeyType() == null) {
return String.format("%s<%s>", getCollectionType(), getAttributeType());
} else {
return String.format("%s<%s, %s>", getCollectionType(), getMapKeyDataTypeLabel(), getAttributeType());
}
}
/**
* @return the mapKeyAttribute
*/
@Override
public Attribute getMapKeyAttribute() {
return mapKeyAttribute;
}
/**
* @param mapKeyAttribute the mapKeyAttribute to set
*/
@Override
public void setMapKeyAttribute(Attribute mapKeyAttribute) {
resetMapAttributeExceptExisting();
this.mapKeyAttribute = mapKeyAttribute;
}
@Override
public MapKeyType getValidatedMapKeyType() {
if (mapKeyAttribute != null) {
return MapKeyType.EXT;
} else if (mapKeyAttributeType != null || mapKeyEmbeddable != null || mapKeyEntity != null) {
return MapKeyType.NEW;
}
return null;
}
/**
* @return the mapKeyType
*/
@Override
public MapKeyType getMapKeyType() {
if (mapKeyType == null) {
return MapKeyType.EXT;
}
return mapKeyType;
}
@Override
public void setMapKeyType(MapKeyType mapKeyType) {
this.mapKeyType = mapKeyType;
}
/**
* @return the mapKeyAttributeType
*/
@Override
public String getMapKeyAttributeType() {
return mapKeyAttributeType;
}
/**
* @param mapKeyAttributeType the mapKeyAttributeType to set
*/
@Override
public void setMapKeyAttributeType(String mapKeyAttributeType) {
this.mapKeyAttributeType = mapKeyAttributeType;
}
/**
* @return the mapKeyEntity
*/
@Override
public Entity getMapKeyEntity() {
return mapKeyEntity;
}
/**
* @param mapKeyEntity the mapKeyEntity to set
*/
@Override
public void setMapKeyEntity(Entity mapKeyEntity) {
resetMapAttributeExceptEntity();
this.mapKeyEntity = mapKeyEntity;
}
/**
* @return the mapKeyEmbeddable
*/
@Override
public Embeddable getMapKeyEmbeddable() {
return mapKeyEmbeddable;
}
/**
* @param mapKeyEmbeddable the mapKeyEmbeddable to set
*/
@Override
public void setMapKeyEmbeddable(Embeddable mapKeyEmbeddable) {
resetMapAttributeExceptEmbeddable();
this.mapKeyEmbeddable = mapKeyEmbeddable;
}
@Override
public void resetMapAttribute() {
this.mapKeyAttribute = null;
this.mapKeyEntity = null;
this.mapKeyEmbeddable = null;
this.mapKeyEnumerated = null;
this.mapKeyTemporal = null;
this.mapKeyAttributeType = null;
this.mapKeyColumn = null;
this.mapKeyJoinColumn = null;
this.mapKeyForeignKey = null;
this.mapKeyAttributeOverride = null;
}
public void resetMapAttributeExceptExisting() {
this.mapKeyEntity = null;
this.mapKeyEmbeddable = null;
this.mapKeyEnumerated = null;
this.mapKeyTemporal = null;
this.mapKeyAttributeType = null;
this.mapKeyColumn = null;
this.mapKeyJoinColumn = null;
this.mapKeyForeignKey = null;
this.mapKeyAttributeOverride = null;
}
public void resetMapAttributeExceptBasic() {
this.mapKeyEnumerated = null;
this.mapKeyTemporal = null;
this.mapKeyAttributeType = null;
this.mapKeyColumn = null;
}
public void resetMapAttributeExceptEmbeddable() {
this.mapKeyAttribute = null;
this.mapKeyEntity = null;
this.mapKeyEnumerated = null;
this.mapKeyTemporal = null;
this.mapKeyAttributeType = null;
this.mapKeyColumn = null;
this.mapKeyJoinColumn = null;
this.mapKeyForeignKey = null;
}
public void resetMapAttributeExceptEntity() {
this.mapKeyAttribute = null;
this.mapKeyEmbeddable = null;
this.mapKeyEnumerated = null;
this.mapKeyTemporal = null;
this.mapKeyAttributeType = null;
this.mapKeyColumn = null;
this.mapKeyAttributeOverride = null;
}
@Override
public String getMapKeyDataTypeLabel() {
if (mapKeyAttribute != null) {
return mapKeyAttribute.getDataTypeLabel();
} else if (mapKeyEntity != null) {
return mapKeyEntity.getClazz();
} else if (mapKeyEmbeddable != null) {
return mapKeyEmbeddable.getClazz();
} else if (mapKeyAttributeType != null) {
return mapKeyAttributeType;
}
return null;
}
@Override
public Set> getAttributeConstraintsClass() {
Set> classes = getCollectionTypeConstraintsClass();
classes.add(Size.class);
return classes;
}
@Override
public Set> getKeyConstraintsClass() {
if(!isMap(getCollectionType())){
return Collections.EMPTY_SET;
}
return getConstraintsClass(getMapKeyDataTypeLabel());
}
@Override
public Set> getValueConstraintsClass() {
return getConstraintsClass(getAttributeType());
}
}