javax.persistence.Access.value()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(298)

本文整理了Java中javax.persistence.Access.value()方法的一些代码示例,展示了Access.value()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Access.value()方法的具体详情如下:
包路径:javax.persistence.Access
类名称:Access
方法名:value

Access.value介绍

暂无

代码示例

代码示例来源:origin: hibernate/hibernate-orm

  1. private static AccessType getAccessTypeOrNull(AnnotatedElement element) {
  2. if ( element == null ) {
  3. return null;
  4. }
  5. Access elementAccess = element.getAnnotation( Access.class );
  6. return elementAccess == null ? null : elementAccess.value();
  7. }

代码示例来源:origin: hibernate/hibernate-orm

  1. private static AccessType getAccessTypeOrNull(CtMember ctMember) {
  2. Access access = getAnnotationOrNull( ctMember, Access.class );
  3. return access == null ? null : access.value();
  4. }

代码示例来源:origin: querydsl/querydsl

  1. @Override
  2. public VisitorConfig getConfig(TypeElement e, List<? extends Element> elements) {
  3. Access access = e.getAnnotation(Access.class);
  4. if (access != null) {
  5. if (access.value() == AccessType.FIELD) {
  6. return VisitorConfig.FIELDS_ONLY;
  7. } else {
  8. return VisitorConfig.METHODS_ONLY;
  9. }
  10. }
  11. boolean fields = false, methods = false;
  12. for (Element element : elements) {
  13. if (hasRelevantAnnotation(element)) {
  14. fields |= element.getKind().equals(ElementKind.FIELD);
  15. methods |= element.getKind().equals(ElementKind.METHOD);
  16. }
  17. }
  18. return VisitorConfig.get(fields, methods, VisitorConfig.ALL);
  19. }

代码示例来源:origin: hibernate/hibernate-orm

  1. public AccessType getDefaultAccess() throws MappingException {
  2. AccessType accessType = defaultAccess;
  3. AccessType hibernateAccessType = AccessType.DEFAULT;
  4. AccessType jpaAccessType = AccessType.DEFAULT;
  5. org.hibernate.annotations.AccessType accessTypeAnnotation = property.getAnnotation( org.hibernate.annotations.AccessType.class );
  6. if ( accessTypeAnnotation != null ) {
  7. hibernateAccessType = AccessType.getAccessStrategy( accessTypeAnnotation.value() );
  8. }
  9. Access access = property.getAnnotation( Access.class );
  10. if ( access != null ) {
  11. jpaAccessType = AccessType.getAccessStrategy( access.value() );
  12. }
  13. if ( hibernateAccessType != AccessType.DEFAULT
  14. && jpaAccessType != AccessType.DEFAULT
  15. && hibernateAccessType != jpaAccessType ) {
  16. StringBuilder builder = new StringBuilder();
  17. builder.append( property.toString() );
  18. builder.append(
  19. " defines @AccessType and @Access with contradicting values. Use of @Access only is recommended."
  20. );
  21. throw new MappingException( builder.toString() );
  22. }
  23. if ( hibernateAccessType != AccessType.DEFAULT ) {
  24. accessType = hibernateAccessType;
  25. }
  26. else if ( jpaAccessType != AccessType.DEFAULT ) {
  27. accessType = jpaAccessType;
  28. }
  29. return accessType;
  30. }

代码示例来源:origin: hibernate/hibernate-orm

  1. final Access localAccessAnnotation = xProperty.getAnnotation( Access.class );
  2. if ( localAccessAnnotation == null
  3. || localAccessAnnotation.value() != javax.persistence.AccessType.FIELD ) {
  4. continue;
  5. final Access localAccessAnnotation = xProperty.getAnnotation( Access.class );
  6. if ( localAccessAnnotation == null
  7. || localAccessAnnotation.value() != javax.persistence.AccessType.PROPERTY ) {
  8. continue;

代码示例来源:origin: hibernate/hibernate-orm

  1. private static AccessType getAccessTypeOrNull(CtClass ctClass) {
  2. try {
  3. if ( ctClass.hasAnnotation( Access.class ) ) {
  4. return ( (Access) ctClass.getAnnotation( Access.class ) ).value();
  5. }
  6. else {
  7. CtClass extendsClass = ctClass.getSuperclass();
  8. return extendsClass == null ? null : getAccessTypeOrNull( extendsClass );
  9. }
  10. }
  11. catch (ClassNotFoundException e) {
  12. return null;
  13. }
  14. catch (NotFoundException e) {
  15. return null;
  16. }
  17. }

代码示例来源:origin: hibernate/hibernate-orm

  1. private AnnotationList doGetAnnotations() {
  2. AnnotationDescription.Loadable<Access> access = fieldDescription.getDeclaringType().asErasure()
  3. .getDeclaredAnnotations().ofType( Access.class );
  4. if ( access != null && access.loadSilent().value() == AccessType.PROPERTY ) {
  5. Optional<MethodDescription> getter = getGetter();
  6. if ( getter.isPresent() ) {
  7. return getter.get().getDeclaredAnnotations();
  8. }
  9. else {
  10. return fieldDescription.getDeclaredAnnotations();
  11. }
  12. }
  13. else if ( access != null && access.loadSilent().value() == AccessType.FIELD ) {
  14. return fieldDescription.getDeclaredAnnotations();
  15. }
  16. else {
  17. Optional<MethodDescription> getter = getGetter();
  18. // Note that the order here is important
  19. List<AnnotationDescription> annotationDescriptions = new ArrayList<>();
  20. if ( getter.isPresent() ) {
  21. annotationDescriptions.addAll( getter.get().getDeclaredAnnotations() );
  22. }
  23. annotationDescriptions.addAll( fieldDescription.getDeclaredAnnotations() );
  24. return fieldDescription.getDeclaredAnnotations();
  25. }
  26. }
  27. }

代码示例来源:origin: hibernate/hibernate-orm

  1. private static TypeDescription.Generic target(AnnotatedFieldDescription persistentField) {
  2. AnnotationDescription.Loadable<Access> access = persistentField.getDeclaringType().asErasure().getDeclaredAnnotations().ofType( Access.class );
  3. if ( access != null && access.loadSilent().value() == AccessType.FIELD ) {
  4. return persistentField.getType();
  5. }
  6. else {
  7. Optional<MethodDescription> getter = persistentField.getGetter();
  8. if ( getter.isPresent() ) {
  9. return getter.get().getReturnType();
  10. }
  11. else {
  12. return persistentField.getType();
  13. }
  14. }
  15. }

代码示例来源:origin: hibernate/hibernate-orm

  1. jpaAccessType = AccessType.getAccessStrategy( access.value() );

代码示例来源:origin: spring-projects/spring-data-jpa

  1. /**
  2. * Looks up both Spring Data's and JPA's access type definition annotations on the property or type level to determine
  3. * the access type to be used. Will consider property-level annotations over type-level ones, favoring the Spring Data
  4. * ones over the JPA ones if found on the same level. Returns {@literal null} if no explicit annotation can be found
  5. * falling back to the defaults implemented in the super class.
  6. *
  7. * @return
  8. */
  9. @Nullable
  10. private Boolean detectPropertyAccess() {
  11. org.springframework.data.annotation.AccessType accessType = findAnnotation(
  12. org.springframework.data.annotation.AccessType.class);
  13. if (accessType != null) {
  14. return Type.PROPERTY.equals(accessType.value());
  15. }
  16. Access access = findAnnotation(Access.class);
  17. if (access != null) {
  18. return AccessType.PROPERTY.equals(access.value());
  19. }
  20. accessType = findPropertyOrOwnerAnnotation(org.springframework.data.annotation.AccessType.class);
  21. if (accessType != null) {
  22. return Type.PROPERTY.equals(accessType.value());
  23. }
  24. access = findPropertyOrOwnerAnnotation(Access.class);
  25. if (access != null) {
  26. return AccessType.PROPERTY.equals(access.value());
  27. }
  28. return null;
  29. }

代码示例来源:origin: hibernate/hibernate-orm

  1. private AccessType determineLocalClassDefinedAccessStrategy() {
  2. AccessType classDefinedAccessType;
  3. AccessType hibernateDefinedAccessType = AccessType.DEFAULT;
  4. AccessType jpaDefinedAccessType = AccessType.DEFAULT;
  5. org.hibernate.annotations.AccessType accessType = xClass.getAnnotation( org.hibernate.annotations.AccessType.class );
  6. if ( accessType != null ) {
  7. hibernateDefinedAccessType = AccessType.getAccessStrategy( accessType.value() );
  8. }
  9. Access access = xClass.getAnnotation( Access.class );
  10. if ( access != null ) {
  11. jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() );
  12. }
  13. if ( hibernateDefinedAccessType != AccessType.DEFAULT
  14. && jpaDefinedAccessType != AccessType.DEFAULT
  15. && hibernateDefinedAccessType != jpaDefinedAccessType ) {
  16. throw new MappingException(
  17. "@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. "
  18. );
  19. }
  20. if ( hibernateDefinedAccessType != AccessType.DEFAULT ) {
  21. classDefinedAccessType = hibernateDefinedAccessType;
  22. }
  23. else {
  24. classDefinedAccessType = jpaDefinedAccessType;
  25. }
  26. return classDefinedAccessType;
  27. }

代码示例来源:origin: hibernate/hibernate-orm

  1. private AccessType determineDefaultAccessType() {
  2. for (XClass xclass = clazz; xclass != null; xclass = xclass.getSuperclass()) {
  3. if ( ( xclass.getSuperclass() == null || Object.class.getName().equals( xclass.getSuperclass().getName() ) )
  4. && ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) )
  5. && xclass.isAnnotationPresent( Access.class ) ) {
  6. return AccessType.getAccessStrategy( xclass.getAnnotation( Access.class ).value() );
  7. }
  8. }
  9. // Guess from identifier.
  10. // FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations, but without an
  11. // explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type?
  12. for (XClass xclass = clazz; xclass != null && !Object.class.getName().equals(xclass.getName()); xclass = xclass.getSuperclass()) {
  13. if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) {
  14. for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) {
  15. final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
  16. if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
  17. return AccessType.PROPERTY;
  18. }
  19. }
  20. for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) {
  21. final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
  22. if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
  23. return AccessType.FIELD;
  24. }
  25. }
  26. }
  27. }
  28. throw new AnnotationException( "No identifier specified for entity: " + clazz );
  29. }

代码示例来源:origin: org.hibernate/hibernate-annotations

  1. AccessType accessType = AccessType.getAccessStrategy( access.value() );
  2. if ( accessType == AccessType.PROPERTY ) {
  3. log.warn( "Placing @Access(AccessType.PROPERTY) on a field does not have any effect." );
  4. AccessType accessType = AccessType.getAccessStrategy( access.value() );
  5. if ( accessType == AccessType.FIELD ) {
  6. log.warn( "Placing @Access(AccessType.FIELD) on a field does not have any effect." );

代码示例来源:origin: hibernate/hibernate-orm

  1. @Test
  2. public void testAllAttributes() throws Exception {
  3. reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
  4. assertAnnotationPresent( ManyToOne.class );
  5. assertAnnotationNotPresent( JoinColumn.class );
  6. assertAnnotationNotPresent( JoinColumns.class );
  7. assertAnnotationNotPresent( JoinTable.class );
  8. assertAnnotationPresent( Id.class );
  9. assertAnnotationPresent( MapsId.class );
  10. assertAnnotationPresent( Access.class );
  11. ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
  12. assertEquals( 0, relAnno.cascade().length );
  13. assertEquals( FetchType.LAZY, relAnno.fetch() );
  14. assertFalse( relAnno.optional() );
  15. assertEquals( Entity3.class, relAnno.targetEntity() );
  16. assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() );
  17. assertEquals(
  18. AccessType.PROPERTY, reader.getAnnotation( Access.class )
  19. .value()
  20. );
  21. }

代码示例来源:origin: org.hibernate/hibernate-annotations

  1. public AccessType getDefaultAccess() throws MappingException {
  2. AccessType accessType = defaultAccess;
  3. AccessType hibernateAccessType = AccessType.DEFAULT;
  4. AccessType jpaAccessType = AccessType.DEFAULT;
  5. org.hibernate.annotations.AccessType accessTypeAnnotation = property.getAnnotation( org.hibernate.annotations.AccessType.class );
  6. if ( accessTypeAnnotation != null ) {
  7. hibernateAccessType = AccessType.getAccessStrategy( accessTypeAnnotation.value() );
  8. }
  9. Access access = property.getAnnotation( Access.class );
  10. if ( access != null ) {
  11. jpaAccessType = AccessType.getAccessStrategy( access.value() );
  12. }
  13. if ( hibernateAccessType != AccessType.DEFAULT
  14. && jpaAccessType != AccessType.DEFAULT
  15. && hibernateAccessType != jpaAccessType ) {
  16. StringBuilder builder = new StringBuilder();
  17. builder.append( property.toString() );
  18. builder.append(
  19. " defines @AccessType and @Access with contradicting values. Use of @Access only is recommended."
  20. );
  21. throw new MappingException( builder.toString() );
  22. }
  23. if ( hibernateAccessType != AccessType.DEFAULT ) {
  24. accessType = hibernateAccessType;
  25. }
  26. else if ( jpaAccessType != AccessType.DEFAULT ) {
  27. accessType = jpaAccessType;
  28. }
  29. return accessType;
  30. }

代码示例来源:origin: hibernate/hibernate-orm

  1. @Test
  2. public void testAllAttributes() throws Exception {
  3. reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
  4. assertAnnotationPresent( ManyToMany.class );
  5. assertAnnotationNotPresent( OrderBy.class );
  6. assertAnnotationNotPresent( OrderColumn.class );
  7. assertAnnotationNotPresent( MapKey.class );
  8. assertAnnotationNotPresent( MapKeyClass.class );
  9. assertAnnotationNotPresent( MapKeyTemporal.class );
  10. assertAnnotationNotPresent( MapKeyEnumerated.class );
  11. assertAnnotationNotPresent( MapKeyColumn.class );
  12. assertAnnotationNotPresent( MapKeyJoinColumns.class );
  13. assertAnnotationNotPresent( MapKeyJoinColumn.class );
  14. assertAnnotationNotPresent( JoinTable.class );
  15. assertAnnotationPresent( Access.class );
  16. ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
  17. assertEquals( 0, relAnno.cascade().length );
  18. assertEquals( FetchType.EAGER, relAnno.fetch() );
  19. assertEquals( "field2", relAnno.mappedBy() );
  20. assertEquals( Entity3.class, relAnno.targetEntity() );
  21. assertEquals(
  22. AccessType.PROPERTY, reader.getAnnotation( Access.class )
  23. .value()
  24. );
  25. }

代码示例来源:origin: hibernate/hibernate-orm

  1. assertEquals(
  2. AccessType.PROPERTY, reader.getAnnotation( Access.class )
  3. .value()
  4. );

代码示例来源:origin: org.hibernate/hibernate-annotations

  1. jpaAccessType = AccessType.getAccessStrategy( access.value() );

代码示例来源:origin: org.hibernate/hibernate-annotations

  1. private AccessType determineClassDefinedAccessStrategy() {
  2. AccessType classDefinedAccessType;
  3. AccessType hibernateDefinedAccessType = AccessType.DEFAULT;
  4. AccessType jpaDefinedAccessType = AccessType.DEFAULT;
  5. org.hibernate.annotations.AccessType accessType = xClass.getAnnotation( org.hibernate.annotations.AccessType.class );
  6. if ( accessType != null ) {
  7. hibernateDefinedAccessType = AccessType.getAccessStrategy( accessType.value() );
  8. }
  9. Access access = xClass.getAnnotation( Access.class );
  10. if ( access != null ) {
  11. jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() );
  12. }
  13. if ( hibernateDefinedAccessType != AccessType.DEFAULT
  14. && jpaDefinedAccessType != AccessType.DEFAULT
  15. && hibernateDefinedAccessType != jpaDefinedAccessType ) {
  16. throw new MappingException(
  17. "@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. "
  18. );
  19. }
  20. if ( hibernateDefinedAccessType != AccessType.DEFAULT ) {
  21. classDefinedAccessType = hibernateDefinedAccessType;
  22. }
  23. else {
  24. classDefinedAccessType = jpaDefinedAccessType;
  25. }
  26. return classDefinedAccessType;
  27. }

代码示例来源:origin: org.apache.openjpa/openjpa-all

  1. public boolean includes(AnnotatedElement obj) {
  2. Access access = obj.getAnnotation(Access.class);
  3. return access != null && access.value().equals(target);
  4. }
  5. }

相关文章