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

x33g5p2x  于11个月前 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(60)

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

Access.value介绍

暂无

代码示例

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

private static AccessType getAccessTypeOrNull(AnnotatedElement element) {
  if ( element == null ) {
    return null;
  }
  Access elementAccess = element.getAnnotation( Access.class );
  return elementAccess == null ? null : elementAccess.value();
}

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

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

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

@Override
public VisitorConfig getConfig(TypeElement e, List<? extends Element> elements) {
  Access access = e.getAnnotation(Access.class);
  if (access != null) {
    if (access.value() == AccessType.FIELD) {
      return VisitorConfig.FIELDS_ONLY;
    } else {
      return VisitorConfig.METHODS_ONLY;
    }
  }
  boolean fields = false, methods = false;
  for (Element element : elements) {
    if (hasRelevantAnnotation(element)) {
      fields |= element.getKind().equals(ElementKind.FIELD);
      methods |= element.getKind().equals(ElementKind.METHOD);
    }
  }
  return VisitorConfig.get(fields, methods, VisitorConfig.ALL);
}

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

public AccessType getDefaultAccess() throws MappingException {
  AccessType accessType = defaultAccess;
  AccessType hibernateAccessType = AccessType.DEFAULT;
  AccessType jpaAccessType = AccessType.DEFAULT;
  org.hibernate.annotations.AccessType accessTypeAnnotation = property.getAnnotation( org.hibernate.annotations.AccessType.class );
  if ( accessTypeAnnotation != null ) {
    hibernateAccessType = AccessType.getAccessStrategy( accessTypeAnnotation.value() );
  }
  Access access = property.getAnnotation( Access.class );
  if ( access != null ) {
    jpaAccessType = AccessType.getAccessStrategy( access.value() );
  }
  if ( hibernateAccessType != AccessType.DEFAULT
      && jpaAccessType != AccessType.DEFAULT
      && hibernateAccessType != jpaAccessType ) {
    StringBuilder builder = new StringBuilder();
    builder.append( property.toString() );
    builder.append(
        " defines @AccessType and @Access with contradicting values. Use of @Access only is recommended."
    );
    throw new MappingException( builder.toString() );
  }
  if ( hibernateAccessType != AccessType.DEFAULT ) {
    accessType = hibernateAccessType;
  }
  else if ( jpaAccessType != AccessType.DEFAULT ) {
    accessType = jpaAccessType;
  }
  return accessType;
}

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

final Access localAccessAnnotation = xProperty.getAnnotation( Access.class );
if ( localAccessAnnotation == null
    || localAccessAnnotation.value() != javax.persistence.AccessType.FIELD ) {
  continue;
final Access localAccessAnnotation = xProperty.getAnnotation( Access.class );
if ( localAccessAnnotation == null
    || localAccessAnnotation.value() != javax.persistence.AccessType.PROPERTY ) {
  continue;

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

private static AccessType getAccessTypeOrNull(CtClass ctClass) {
  try {
    if ( ctClass.hasAnnotation( Access.class ) ) {
      return ( (Access) ctClass.getAnnotation( Access.class ) ).value();
    }
    else {
      CtClass extendsClass = ctClass.getSuperclass();
      return extendsClass == null ? null : getAccessTypeOrNull( extendsClass );
    }
  }
  catch (ClassNotFoundException e) {
    return null;
  }
  catch (NotFoundException e) {
    return null;
  }
}

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

private AnnotationList doGetAnnotations() {
    AnnotationDescription.Loadable<Access> access = fieldDescription.getDeclaringType().asErasure()
        .getDeclaredAnnotations().ofType( Access.class );
    if ( access != null && access.loadSilent().value() == AccessType.PROPERTY ) {
      Optional<MethodDescription> getter = getGetter();
      if ( getter.isPresent() ) {
        return getter.get().getDeclaredAnnotations();
      }
      else {
        return fieldDescription.getDeclaredAnnotations();
      }
    }
    else if ( access != null && access.loadSilent().value() == AccessType.FIELD ) {
      return fieldDescription.getDeclaredAnnotations();
    }
    else {
      Optional<MethodDescription> getter = getGetter();
      // Note that the order here is important
      List<AnnotationDescription> annotationDescriptions = new ArrayList<>();
      if ( getter.isPresent() ) {
        annotationDescriptions.addAll( getter.get().getDeclaredAnnotations() );
      }
      annotationDescriptions.addAll( fieldDescription.getDeclaredAnnotations() );
      return fieldDescription.getDeclaredAnnotations();
    }
  }
}

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

private static TypeDescription.Generic target(AnnotatedFieldDescription persistentField) {
  AnnotationDescription.Loadable<Access> access = persistentField.getDeclaringType().asErasure().getDeclaredAnnotations().ofType( Access.class );
  if ( access != null && access.loadSilent().value() == AccessType.FIELD ) {
    return persistentField.getType();
  }
  else {
    Optional<MethodDescription> getter = persistentField.getGetter();
    if ( getter.isPresent() ) {
      return getter.get().getReturnType();
    }
    else {
      return persistentField.getType();
    }
  }
}

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

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

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

/**
 * Looks up both Spring Data's and JPA's access type definition annotations on the property or type level to determine
 * the access type to be used. Will consider property-level annotations over type-level ones, favoring the Spring Data
 * ones over the JPA ones if found on the same level. Returns {@literal null} if no explicit annotation can be found
 * falling back to the defaults implemented in the super class.
 *
 * @return
 */
@Nullable
private Boolean detectPropertyAccess() {
  org.springframework.data.annotation.AccessType accessType = findAnnotation(
      org.springframework.data.annotation.AccessType.class);
  if (accessType != null) {
    return Type.PROPERTY.equals(accessType.value());
  }
  Access access = findAnnotation(Access.class);
  if (access != null) {
    return AccessType.PROPERTY.equals(access.value());
  }
  accessType = findPropertyOrOwnerAnnotation(org.springframework.data.annotation.AccessType.class);
  if (accessType != null) {
    return Type.PROPERTY.equals(accessType.value());
  }
  access = findPropertyOrOwnerAnnotation(Access.class);
  if (access != null) {
    return AccessType.PROPERTY.equals(access.value());
  }
  return null;
}

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

private AccessType determineLocalClassDefinedAccessStrategy() {
  AccessType classDefinedAccessType;
  AccessType hibernateDefinedAccessType = AccessType.DEFAULT;
  AccessType jpaDefinedAccessType = AccessType.DEFAULT;
  org.hibernate.annotations.AccessType accessType = xClass.getAnnotation( org.hibernate.annotations.AccessType.class );
  if ( accessType != null ) {
    hibernateDefinedAccessType = AccessType.getAccessStrategy( accessType.value() );
  }
  Access access = xClass.getAnnotation( Access.class );
  if ( access != null ) {
    jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() );
  }
  if ( hibernateDefinedAccessType != AccessType.DEFAULT
      && jpaDefinedAccessType != AccessType.DEFAULT
      && hibernateDefinedAccessType != jpaDefinedAccessType ) {
    throw new MappingException(
        "@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. "
    );
  }
  if ( hibernateDefinedAccessType != AccessType.DEFAULT ) {
    classDefinedAccessType = hibernateDefinedAccessType;
  }
  else {
    classDefinedAccessType = jpaDefinedAccessType;
  }
  return classDefinedAccessType;
}

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

private AccessType determineDefaultAccessType() {
  for (XClass xclass = clazz; xclass != null; xclass = xclass.getSuperclass()) {
    if ( ( xclass.getSuperclass() == null || Object.class.getName().equals( xclass.getSuperclass().getName() ) )
        && ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) )
        && xclass.isAnnotationPresent( Access.class ) ) {
      return AccessType.getAccessStrategy( xclass.getAnnotation( Access.class ).value() );
    }
  }
  // Guess from identifier.
  // FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations, but without an
  //      explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type?
  for (XClass xclass = clazz; xclass != null && !Object.class.getName().equals(xclass.getName()); xclass = xclass.getSuperclass()) {
    if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) {
      for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) {
        final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
        if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
          return AccessType.PROPERTY;
        }
      }
      for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) {
        final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class );
        if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) {
          return AccessType.FIELD;
        }
      }
    }
  }
  throw new AnnotationException( "No identifier specified for entity: " + clazz );
}

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

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

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

@Test
public void testAllAttributes() throws Exception {
  reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
  assertAnnotationPresent( ManyToOne.class );
  assertAnnotationNotPresent( JoinColumn.class );
  assertAnnotationNotPresent( JoinColumns.class );
  assertAnnotationNotPresent( JoinTable.class );
  assertAnnotationPresent( Id.class );
  assertAnnotationPresent( MapsId.class );
  assertAnnotationPresent( Access.class );
  ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
  assertEquals( 0, relAnno.cascade().length );
  assertEquals( FetchType.LAZY, relAnno.fetch() );
  assertFalse( relAnno.optional() );
  assertEquals( Entity3.class, relAnno.targetEntity() );
  assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() );
  assertEquals(
      AccessType.PROPERTY, reader.getAnnotation( Access.class )
      .value()
  );
}

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

public AccessType getDefaultAccess() throws MappingException {
  AccessType accessType = defaultAccess;
  AccessType hibernateAccessType = AccessType.DEFAULT;
  AccessType jpaAccessType = AccessType.DEFAULT;
  org.hibernate.annotations.AccessType accessTypeAnnotation = property.getAnnotation( org.hibernate.annotations.AccessType.class );
  if ( accessTypeAnnotation != null ) {
    hibernateAccessType = AccessType.getAccessStrategy( accessTypeAnnotation.value() );
  }
  Access access = property.getAnnotation( Access.class );
  if ( access != null ) {
    jpaAccessType = AccessType.getAccessStrategy( access.value() );
  }
  if ( hibernateAccessType != AccessType.DEFAULT
      && jpaAccessType != AccessType.DEFAULT
      && hibernateAccessType != jpaAccessType ) {
    StringBuilder builder = new StringBuilder();
    builder.append( property.toString() );
    builder.append(
        " defines @AccessType and @Access with contradicting values. Use of @Access only is recommended."
    );
    throw new MappingException( builder.toString() );
  }
  if ( hibernateAccessType != AccessType.DEFAULT ) {
    accessType = hibernateAccessType;
  }
  else if ( jpaAccessType != AccessType.DEFAULT ) {
    accessType = jpaAccessType;
  }
  return accessType;
}

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

@Test
public void testAllAttributes() throws Exception {
  reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
  assertAnnotationPresent( ManyToMany.class );
  assertAnnotationNotPresent( OrderBy.class );
  assertAnnotationNotPresent( OrderColumn.class );
  assertAnnotationNotPresent( MapKey.class );
  assertAnnotationNotPresent( MapKeyClass.class );
  assertAnnotationNotPresent( MapKeyTemporal.class );
  assertAnnotationNotPresent( MapKeyEnumerated.class );
  assertAnnotationNotPresent( MapKeyColumn.class );
  assertAnnotationNotPresent( MapKeyJoinColumns.class );
  assertAnnotationNotPresent( MapKeyJoinColumn.class );
  assertAnnotationNotPresent( JoinTable.class );
  assertAnnotationPresent( Access.class );
  ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
  assertEquals( 0, relAnno.cascade().length );
  assertEquals( FetchType.EAGER, relAnno.fetch() );
  assertEquals( "field2", relAnno.mappedBy() );
  assertEquals( Entity3.class, relAnno.targetEntity() );
  assertEquals(
      AccessType.PROPERTY, reader.getAnnotation( Access.class )
      .value()
  );
}

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

assertEquals(
    AccessType.PROPERTY, reader.getAnnotation( Access.class )
    .value()
);

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

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

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

private AccessType determineClassDefinedAccessStrategy() {
  AccessType classDefinedAccessType;
  AccessType hibernateDefinedAccessType = AccessType.DEFAULT;
  AccessType jpaDefinedAccessType = AccessType.DEFAULT;
  org.hibernate.annotations.AccessType accessType = xClass.getAnnotation( org.hibernate.annotations.AccessType.class );
  if ( accessType != null ) {
    hibernateDefinedAccessType = AccessType.getAccessStrategy( accessType.value() );
  }
  Access access = xClass.getAnnotation( Access.class );
  if ( access != null ) {
    jpaDefinedAccessType = AccessType.getAccessStrategy( access.value() );
  }
  if ( hibernateDefinedAccessType != AccessType.DEFAULT
      && jpaDefinedAccessType != AccessType.DEFAULT
      && hibernateDefinedAccessType != jpaDefinedAccessType ) {
    throw new MappingException(
        "@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. "
    );
  }
  if ( hibernateDefinedAccessType != AccessType.DEFAULT ) {
    classDefinedAccessType = hibernateDefinedAccessType;
  }
  else {
    classDefinedAccessType = jpaDefinedAccessType;
  }
  return classDefinedAccessType;
}

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

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

相关文章

最新文章

更多