📄 ejb3overridenannotationreader.java
字号:
clazz = ReflectHelper.classForName( XMLContext.buildSafeClassName( className, defaults ), this.getClass() ); } catch (ClassNotFoundException e) { throw new AnnotationException( "Unable to find " + element.getPath() + "target-entity: " + className, e ); } ad.setValue( "targetEntity", clazz ); } getFetchType( ad, element ); getCascades( ad, element, defaults ); getJoinTable( annotationList, element, defaults ); buildJoinColumns( annotationList, element, defaults ); Annotation annotation = getPrimaryKeyJoinColumns( element, defaults ); addIfNotNull( annotationList, annotation ); copyBooleanAttribute( ad, element, "optional" ); copyStringAttribute( ad, element, "mapped-by", false ); getOrderBy( annotationList, element, defaults ); getMapKey( annotationList, element, defaults ); annotationList.add( AnnotationFactory.create( ad ) ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { Annotation annotation = getJavaAnnotation( annotationType ); if ( annotation != null ) { annotationList.add( annotation ); annotation = overridesDefaultsInJoinTable( annotation, defaults ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( JoinColumn.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( JoinColumns.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( PrimaryKeyJoinColumn.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( PrimaryKeyJoinColumns.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( MapKey.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( OrderBy.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverrides.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverrides.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Lob.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Enumerated.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Temporal.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Column.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Columns.class ); addIfNotNull( annotationList, annotation ); } else if ( isJavaAnnotationPresent( CollectionOfElements.class ) ) { annotation = overridesDefaultsInJoinTable( getJavaAnnotation( CollectionOfElements.class ), defaults ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( JoinColumn.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( JoinColumns.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( PrimaryKeyJoinColumn.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( PrimaryKeyJoinColumns.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( MapKey.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( OrderBy.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverrides.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverrides.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Lob.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Enumerated.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Temporal.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Column.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Columns.class ); addIfNotNull( annotationList, annotation ); } } } private void getOrderBy(List<Annotation> annotationList, Element element, XMLContext.Default defaults) { Element subelement = element != null ? element.element( "order-by" ) : null; if ( subelement != null ) { String orderByString = subelement.getTextTrim(); AnnotationDescriptor ad = new AnnotationDescriptor( OrderBy.class ); if ( StringHelper.isNotEmpty( orderByString ) ) ad.setValue( "value", orderByString ); annotationList.add( AnnotationFactory.create( ad ) ); } } private void getMapKey(List<Annotation> annotationList, Element element, XMLContext.Default defaults) { Element subelement = element != null ? element.element( "map-key" ) : null; if ( subelement != null ) { String mapKeyString = subelement.attributeValue( "name" ); AnnotationDescriptor ad = new AnnotationDescriptor( MapKey.class ); if ( StringHelper.isNotEmpty( mapKeyString ) ) ad.setValue( "name", mapKeyString ); annotationList.add( AnnotationFactory.create( ad ) ); } } private void buildJoinColumns(List<Annotation> annotationList, Element element, XMLContext.Default defaults) { JoinColumn[] joinColumns = getJoinColumns( element, false ); if ( joinColumns.length > 0 ) { AnnotationDescriptor ad = new AnnotationDescriptor( JoinColumns.class ); ad.setValue( "value", joinColumns ); annotationList.add( AnnotationFactory.create( ad ) ); } } private void getCascades(AnnotationDescriptor ad, Element element, XMLContext.Default defaults) { List<Element> elements = element != null ? element.elements( "cascade" ) : new ArrayList<Element>( 0 ); List<CascadeType> cascades = new ArrayList<CascadeType>(); for (Element subelement : elements) { if ( subelement.element( "cascade-all" ) != null ) cascades.add( CascadeType.ALL ); if ( subelement.element( "cascade-persist" ) != null ) cascades.add( CascadeType.PERSIST ); if ( subelement.element( "cascade-merge" ) != null ) cascades.add( CascadeType.MERGE ); if ( subelement.element( "cascade-remove" ) != null ) cascades.add( CascadeType.REMOVE ); if ( subelement.element( "cascade-refresh" ) != null ) cascades.add( CascadeType.REFRESH ); } if ( Boolean.TRUE.equals( defaults.getCascadePersist() ) && !cascades.contains( CascadeType.ALL ) && !cascades.contains( CascadeType.PERSIST ) ) { cascades.add( CascadeType.PERSIST ); } if ( cascades.size() > 0 ) { ad.setValue( "cascade", cascades.toArray( new CascadeType[cascades.size()] ) ); } } private void getEmbedded(List<Annotation> annotationList, XMLContext.Default defaults) { for (Element element : elementsForProperty) { if ( "embedded".equals( element.getName() ) ) { AnnotationDescriptor ad = new AnnotationDescriptor( Embedded.class ); annotationList.add( AnnotationFactory.create( ad ) ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { Annotation annotation = getJavaAnnotation( Embedded.class ); if ( annotation != null ) { annotationList.add( annotation ); annotation = getJavaAnnotation( AttributeOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverrides.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverrides.class ); addIfNotNull( annotationList, annotation ); } } } 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 getJavaAnnotation( Transient.class ); } else { return null; } } private void getVersion(List<Annotation> annotationList, XMLContext.Default defaults) { for (Element element : elementsForProperty) { if ( "version".equals( element.getName() ) ) { Annotation annotation = buildColumns( element ); addIfNotNull( annotationList, annotation ); getTemporal( annotationList, element ); AnnotationDescriptor basic = new AnnotationDescriptor( Version.class ); annotationList.add( AnnotationFactory.create( basic ) ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { //we have nothing, so Java annotations might occurs Annotation annotation = getJavaAnnotation( Version.class ); if ( annotation != null ) { annotationList.add( annotation ); annotation = getJavaAnnotation( Column.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Columns.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Temporal.class ); addIfNotNull( annotationList, annotation ); } } } private void getBasic(List<Annotation> annotationList, XMLContext.Default defaults) { for (Element element : elementsForProperty) { if ( "basic".equals( element.getName() ) ) { Annotation annotation = buildColumns( element ); addIfNotNull( annotationList, annotation ); getTemporal( annotationList, element ); getLob( annotationList, element ); getEnumerated( annotationList, element ); AnnotationDescriptor basic = new AnnotationDescriptor( Basic.class ); getFetchType( basic, element ); copyBooleanAttribute( basic, element, "optional" ); annotationList.add( AnnotationFactory.create( basic ) ); } } if ( elementsForProperty.size() == 0 && defaults.canUseJavaAnnotations() ) { //no annotation presence constraint, basic is the default Annotation annotation = getJavaAnnotation( Basic.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Lob.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Enumerated.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Temporal.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Column.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( Columns.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AttributeOverrides.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverride.class ); addIfNotNull( annotationList, annotation ); annotation = getJavaAnnotation( AssociationOverrides.class ); addIfNotNull( annotationList, annotation ); } } private void getEnumerated(List<Annotation> annotationList, Element element) { Element subElement = element != null ? element.element( "enumerated" ) : null; if ( subElement != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( Enumerated.class ); String enumerated = subElement.getTextTrim(); if ( "ORDINAL".equalsIgnoreCase( enumerated ) ) { ad.setValue( "value", EnumType.ORDINAL ); } else if ( "STRING".equalsIgnoreCase( enumerated ) ) { ad.setValue( "value", EnumType.STRING ); } else if ( StringHelper.isNotEmpty( enumerated ) ) { throw new AnnotationException( "Unknown EnumType: " + enumerated + ". " + SCHEMA_VALIDATION ); } annotationList.add( AnnotationFactory.create( ad ) ); } } private void getLob(List<Annotation> annotationList, Element element) { Element subElement = element != null ? element.element( "lob" ) : null; if ( subElement != null ) { annotationList.add( AnnotationFactory.create( new AnnotationDescriptor( Lob.class ) ) ); } } private void getFetchType(AnnotationDescriptor descriptor, Element element) { String fetchString = element != null ? element.attributeValue( "fetch" ) : null; if ( fetchString != null ) { if ( "eager".equalsIgnoreCase( fetchString ) ) { descriptor.setValue( "fetch", FetchType.EAGER ); } else if ( "lazy".equalsIgnoreCase( fetchString ) ) { descriptor.setValue( "fetch", FetchType.LAZY ); } } } private void getEmbeddedId(List<Annotation> annotationList, XMLContext.Default defaults) { for (Element element : elementsForProperty) { if ( "embedded-id".equals( element.getName() ) ) { if ( isProcessingId( defaults ) ) { Annotation annotation = getAttributeOverrides( element, defaults ); addIfNotNull( annotationList, annotation ); annotation = getAssociationOverrides( element, defaults ); addIfNotNull( annotationList, annotation ); AnnotationDescriptor ad = new AnnotationDescriptor( EmbeddedId.class ); annotationList.add( AnnotationFactory.create( ad ) ); }// else {// if ( defaults.canUseJavaAnnotations() ) {// if ( ! properOverridingOnMetadataNonComplete ) {// //check that id exists on the other attribute// //TODO Id too?// if ( mirroredAttribute == null || ! mirroredAttribute.isAnnotationPresent(// EmbeddedId.class// ) ) {// throw new AnnotationException(// "Cannot override an property with <embedded-id> not having an @EmbeddedId already"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -