private Annotation getTableGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) { for ( Element element : elementsForProperty ) { Element subelement = element != null ? element.element( annotationToXml.get( TableGenerator.class ) ) : null; if ( subelement != null ) { return buildTableGeneratorAnnotation( subelement, defaults ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( TableGenerator.class ); } else { return null; } }
private Annotation getSequenceGenerator(List<Element> elementsForProperty, XMLContext.Default defaults) { for ( Element element : elementsForProperty ) { Element subelement = element != null ? element.element( annotationToXml.get( SequenceGenerator.class ) ) : null; if ( subelement != null ) { return buildSequenceGeneratorAnnotation( subelement ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( SequenceGenerator.class ); } else { return null; } }
private SequenceGenerator getSequenceGenerator(Element tree, XMLContext.Default defaults) { Element element = tree != null ? tree.element( annotationToXml.get( SequenceGenerator.class ) ) : null; if ( element != null ) { return buildSequenceGeneratorAnnotation( element ); } else if ( defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( SequenceGenerator.class ); } else { return null; } }
private Transient getTransient(XMLContext.Default defaults) { for ( Element element : elementsForProperty ) { if ( "transient".equals( element.getName() ) ) { AnnotationDescriptor ad = new AnnotationDescriptor( Transient.class ); return AnnotationFactory.create( ad ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( Transient.class ); } else { return null; } }
private MappedSuperclass getMappedSuperclass(Element tree, XMLContext.Default defaults) { if ( tree == null ) { return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation( MappedSuperclass.class ) : null; } else { if ( "mapped-superclass".equals( tree.getName() ) ) { AnnotationDescriptor entity = new AnnotationDescriptor( MappedSuperclass.class ); return AnnotationFactory.create( entity ); } else { return null; //this is not an entity } } }
private Embeddable getEmbeddable(Element tree, XMLContext.Default defaults) { if ( tree == null ) { return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation( Embeddable.class ) : null; } else { if ( "embeddable".equals( tree.getName() ) ) { AnnotationDescriptor entity = new AnnotationDescriptor( Embeddable.class ); return AnnotationFactory.create( entity ); } else { return null; //this is not an entity } } }
private Annotation getMarkerAnnotation( Class<? extends Annotation> clazz, Element element, XMLContext.Default defaults ) { Element subelement = element == null ? null : element.element( annotationToXml.get( clazz ) ); if ( subelement != null ) { return AnnotationFactory.create( new AnnotationDescriptor( clazz ) ); } else if ( defaults.canUseJavaAnnotations() ) { //TODO wonder whether it should be excluded so that user can undone it return getPhysicalAnnotation( clazz ); } else { return null; } }
private void applyPhysicalConvertAnnotations( String attributeNamePrefix, Map<String, Convert> convertAnnotationsMap) { final Convert physicalAnnotation = getPhysicalAnnotation( Convert.class ); if ( physicalAnnotation != null ) { // only add if no XML element named a converter for this attribute final String qualifiedAttributeName = qualifyConverterAttributeName( attributeNamePrefix, physicalAnnotation.attributeName() ); if ( ! convertAnnotationsMap.containsKey( qualifiedAttributeName ) ) { convertAnnotationsMap.put( qualifiedAttributeName, physicalAnnotation ); } } final Converts physicalGroupingAnnotation = getPhysicalAnnotation( Converts.class ); if ( physicalGroupingAnnotation != null ) { for ( Convert convertAnnotation : physicalGroupingAnnotation.value() ) { // again, only add if no XML element named a converter for this attribute final String qualifiedAttributeName = qualifyConverterAttributeName( attributeNamePrefix, convertAnnotation.attributeName() ); if ( ! convertAnnotationsMap.containsKey( qualifiedAttributeName ) ) { convertAnnotationsMap.put( qualifiedAttributeName, convertAnnotation ); } } } }
private Cacheable getCacheable(Element element, XMLContext.Default defaults){ if ( element != null ) { String attValue = element.attributeValue( "cacheable" ); if ( attValue != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( Cacheable.class ); ad.setValue( "value", Boolean.valueOf( attValue ) ); return AnnotationFactory.create( ad ); } } if ( defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( Cacheable.class ); } else { return null; } } /**
private DiscriminatorValue getDiscriminatorValue(Element tree, XMLContext.Default defaults) { Element element = tree != null ? tree.element( "discriminator-value" ) : null; if ( element != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( DiscriminatorValue.class ); copyStringElement( element, ad, "value" ); return AnnotationFactory.create( ad ); } else if ( defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( DiscriminatorValue.class ); } else { return null; } }
private SqlResultSetMappings getSqlResultSetMappings(Element tree, XMLContext.Default defaults) { List<SqlResultSetMapping> results = buildSqlResultsetMappings( tree, defaults, classLoaderAccess ); if ( defaults.canUseJavaAnnotations() ) { SqlResultSetMapping annotation = getPhysicalAnnotation( SqlResultSetMapping.class ); addSqlResultsetMappingIfNeeded( annotation, results ); SqlResultSetMappings annotations = getPhysicalAnnotation( SqlResultSetMappings.class ); if ( annotations != null ) { for ( SqlResultSetMapping current : annotations.value() ) { addSqlResultsetMappingIfNeeded( current, results ); } } } if ( results.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( SqlResultSetMappings.class ); ad.setValue( "value", results.toArray( new SqlResultSetMapping[results.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
/** * @param mergeWithAnnotations Whether to use Java annotations for this * element, if present and not disabled by the XMLContext defaults. * In some contexts (such as an association mapping) merging with * annotations is never allowed. */ private AttributeOverrides mergeAttributeOverrides(XMLContext.Default defaults, List<AttributeOverride> attributes, boolean mergeWithAnnotations) { if ( mergeWithAnnotations && defaults.canUseJavaAnnotations() ) { AttributeOverride annotation = getPhysicalAnnotation( AttributeOverride.class ); addAttributeOverrideIfNeeded( annotation, attributes ); AttributeOverrides annotations = getPhysicalAnnotation( AttributeOverrides.class ); if ( annotations != null ) { for ( AttributeOverride current : annotations.value() ) { addAttributeOverrideIfNeeded( current, attributes ); } } } if ( attributes.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( AttributeOverrides.class ); ad.setValue( "value", attributes.toArray( new AttributeOverride[attributes.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
private NamedQueries getNamedQueries(Element tree, XMLContext.Default defaults) { //TODO avoid the Proxy Creation (@NamedQueries) when possible List<NamedQuery> queries = (List<NamedQuery>) buildNamedQueries( tree, false, defaults, classLoaderAccess ); if ( defaults.canUseJavaAnnotations() ) { NamedQuery annotation = getPhysicalAnnotation( NamedQuery.class ); addNamedQueryIfNeeded( annotation, queries ); NamedQueries annotations = getPhysicalAnnotation( NamedQueries.class ); if ( annotations != null ) { for ( NamedQuery current : annotations.value() ) { addNamedQueryIfNeeded( current, queries ); } } } if ( queries.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( NamedQueries.class ); ad.setValue( "value", queries.toArray( new NamedQuery[queries.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
private NamedEntityGraphs getNamedEntityGraphs(Element tree, XMLContext.Default defaults) { List<NamedEntityGraph> queries = buildNamedEntityGraph( tree, defaults, classLoaderAccess ); if ( defaults.canUseJavaAnnotations() ) { NamedEntityGraph annotation = getPhysicalAnnotation( NamedEntityGraph.class ); addNamedEntityGraphIfNeeded( annotation, queries ); NamedEntityGraphs annotations = getPhysicalAnnotation( NamedEntityGraphs.class ); if ( annotations != null ) { for ( NamedEntityGraph current : annotations.value() ) { addNamedEntityGraphIfNeeded( current, queries ); } } } if ( queries.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( NamedEntityGraphs.class ); ad.setValue( "value", queries.toArray( new NamedEntityGraph[queries.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
private NamedStoredProcedureQueries getNamedStoredProcedureQueries(Element tree, XMLContext.Default defaults) { List<NamedStoredProcedureQuery> queries = buildNamedStoreProcedureQueries( tree, defaults, classLoaderAccess ); if ( defaults.canUseJavaAnnotations() ) { NamedStoredProcedureQuery annotation = getPhysicalAnnotation( NamedStoredProcedureQuery.class ); addNamedStoredProcedureQueryIfNeeded( annotation, queries ); NamedStoredProcedureQueries annotations = getPhysicalAnnotation( NamedStoredProcedureQueries.class ); if ( annotations != null ) { for ( NamedStoredProcedureQuery current : annotations.value() ) { addNamedStoredProcedureQueryIfNeeded( current, queries ); } } } if ( queries.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( NamedStoredProcedureQueries.class ); ad.setValue( "value", queries.toArray( new NamedStoredProcedureQuery[queries.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
private NamedNativeQueries getNamedNativeQueries( Element tree, XMLContext.Default defaults) { List<NamedNativeQuery> queries = (List<NamedNativeQuery>) buildNamedQueries( tree, true, defaults, classLoaderAccess ); if ( defaults.canUseJavaAnnotations() ) { NamedNativeQuery annotation = getPhysicalAnnotation( NamedNativeQuery.class ); addNamedNativeQueryIfNeeded( annotation, queries ); NamedNativeQueries annotations = getPhysicalAnnotation( NamedNativeQueries.class ); if ( annotations != null ) { for ( NamedNativeQuery current : annotations.value() ) { addNamedNativeQueryIfNeeded( current, queries ); } } } if ( queries.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( NamedNativeQueries.class ); ad.setValue( "value", queries.toArray( new NamedNativeQuery[queries.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
/** * @param mergeWithAnnotations Whether to use Java annotations for this * element, if present and not disabled by the XMLContext defaults. * In some contexts (such as an element-collection mapping) merging * with annotations is never allowed. */ private AssociationOverrides getAssociationOverrides(Element tree, XMLContext.Default defaults, boolean mergeWithAnnotations) { List<AssociationOverride> attributes = buildAssociationOverrides( tree, defaults ); if ( mergeWithAnnotations && defaults.canUseJavaAnnotations() ) { AssociationOverride annotation = getPhysicalAnnotation( AssociationOverride.class ); addAssociationOverrideIfNeeded( annotation, attributes ); AssociationOverrides annotations = getPhysicalAnnotation( AssociationOverrides.class ); if ( annotations != null ) { for ( AssociationOverride current : annotations.value() ) { addAssociationOverrideIfNeeded( current, attributes ); } } } if ( attributes.size() > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( AssociationOverrides.class ); ad.setValue( "value", attributes.toArray( new AssociationOverride[attributes.size()] ) ); return AnnotationFactory.create( ad ); } else { return null; } }
private Entity getEntity(Element tree, XMLContext.Default defaults) { if ( tree == null ) { return defaults.canUseJavaAnnotations() ? getPhysicalAnnotation( Entity.class ) : null; } else { if ( "entity".equals( tree.getName() ) ) { AnnotationDescriptor entity = new AnnotationDescriptor( Entity.class ); copyStringAttribute( entity, tree, "name", false ); if ( defaults.canUseJavaAnnotations() && StringHelper.isEmpty( (String) entity.valueOf( "name" ) ) ) { Entity javaAnn = getPhysicalAnnotation( Entity.class ); if ( javaAnn != null ) { entity.setValue( "name", javaAnn.name() ); } } return AnnotationFactory.create( entity ); } else { return null; //this is not an entity } } }
private IdClass getIdClass(Element tree, XMLContext.Default defaults) { Element element = tree == null ? null : tree.element( "id-class" ); if ( element != null ) { Attribute attr = element.attribute( "class" ); if ( attr != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( IdClass.class ); Class clazz; try { clazz = classLoaderAccess.classForName( XMLContext.buildSafeClassName( attr.getValue(), defaults ) ); } catch ( ClassLoadingException e ) { throw new AnnotationException( "Unable to find id-class: " + attr.getValue(), e ); } ad.setValue( "value", clazz ); return AnnotationFactory.create( ad ); } else { throw new AnnotationException( "id-class without class. " + SCHEMA_VALIDATION ); } } else if ( defaults.canUseJavaAnnotations() ) { return getPhysicalAnnotation( IdClass.class ); } else { return null; } }
private Access getAccessType(Element tree, XMLContext.Default defaults) { String access = tree == null ? null : tree.attributeValue( "access" ); if ( access != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( Access.class ); AccessType type; try { type = AccessType.valueOf( access ); } catch ( IllegalArgumentException e ) { throw new AnnotationException( access + " is not a valid access type. Check you xml confguration." ); } ad.setValue( "value", type ); return AnnotationFactory.create( ad ); } else if ( defaults.canUseJavaAnnotations() && isPhysicalAnnotationPresent( Access.class ) ) { return getPhysicalAnnotation( Access.class ); } else if ( defaults.getAccess() != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( Access.class ); ad.setValue( "value", defaults.getAccess() ); return AnnotationFactory.create( ad ); } else { return null; } }