javax.persistence.Enumerated Java Examples

The following examples show how to use javax.persistence.Enumerated. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckCore.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void checkEnum(List<Class<?>> classes) throws Exception {
	for (Class<?> cls : classes) {
		List<Field> fields = FieldUtils.getFieldsListWithAnnotation(cls, FieldDescribe.class);
		for (Field field : fields) {
			if (field.getType().isEnum()) {
				Enumerated enumerated = field.getAnnotation(Enumerated.class);
				Column column = field.getAnnotation(Column.class);
				if (null == enumerated || (!Objects.equals(EnumType.STRING, enumerated.value())) || (null == column)
						|| column.length() > 200) {
					System.err.println(String.format("checkEnum error: class: %s, field: %s.", cls.getName(),
							field.getName()));
				}
			}
		}
	}
}
 
Example #2
Source File: EnumeratedTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Test
public void testIfThereAreEnumeratedAnnotations() {
    Reflections reflections = new Reflections("com.sequenceiq",
            new FieldAnnotationsScanner());

    Map<String, Set<String>> enumeratedFields = new HashMap<>();
    reflections.getFieldsAnnotatedWith(Enumerated.class).forEach(field -> {
        try {
            String className = field.getDeclaringClass().getName();
            enumeratedFields.computeIfAbsent(className, key -> new HashSet<>()).add(field.toString());
        } catch (RuntimeException e) {
            // ignore if cannot check fields
        }
    });

    Set<String> fields = new HashSet<>();

    enumeratedFields.forEach((key, value) -> {
        fields.add(key + ": " + String.join(", ", value));
    });

    Assert.assertTrue(
            String.format("Classes with @Enumerated fields: %s%s%s%s", lineSeparator(),
                    String.join(lineSeparator(), fields), lineSeparator(), "Use @Converter instead of @Enumerated"), enumeratedFields.isEmpty());
}
 
Example #3
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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 ) );
	}
}
 
Example #4
Source File: DocumentPersonReferenceData.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the role description.
*
* @return the role description
*/
  @Basic
  @Column(name = "ROLE_DESCRIPTION")
  @Enumerated(EnumType.STRING)
  public DocumentPersonReferenceRoleType getRoleDescription() {
      return roleDescription;
  }
 
Example #5
Source File: User.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(targetClass = Permission.class, fetch = FetchType.EAGER)
@CollectionTable(name = "USER_PERMISSIONS", joinColumns = @JoinColumn(name = "USER_ID"))
@Enumerated(EnumType.STRING)
@Column(name = "permission", nullable = false)
public Set<Permission> getPermissions() {
	return permissions;
}
 
Example #6
Source File: VoteData.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the ballot type.
*
* @return the ballot type
*/
  @Basic
  @Column(name = "BALLOT_TYPE")
  @Enumerated(EnumType.STRING)
  public BallotType getBallotType() {
      return ballotType;
  }
 
Example #7
Source File: VoteData.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the vote.
*
* @return the vote
*/
  @Basic
  @Column(name = "VOTE")
  @Enumerated(EnumType.STRING)
  public VoteDecision getVote() {
      return vote;
  }
 
Example #8
Source File: VoteDataDto.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the ballot type.
*
* @return the ballot type
*/
  @Basic
  @Column(name = "BALLOT_TYPE")
  @Enumerated(EnumType.STRING)
  public BallotType getBallotType() {
      return ballotType;
  }
 
Example #9
Source File: User.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
@CollectionTable(name = "USER_ROLES", joinColumns = @JoinColumn(name = "USER_ID"))
@Enumerated(EnumType.STRING)
@Column(name = "role", nullable = false)
public Set<Role> getRoles() {
	return roles;
}
 
Example #10
Source File: Region.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the value.
*
* @return the value
*/
  @Basic
  @Column(name = "VALUE_")
  @Enumerated(EnumType.STRING)
  public RegionCategory getValue() {
      return value;
  }
 
Example #11
Source File: Adminregion.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the value.
*
* @return the value
*/
  @Basic
  @Column(name = "VALUE_")
  @Enumerated(EnumType.STRING)
  public AdminRegionCategory getValue() {
      return value;
  }
 
Example #12
Source File: LendingType.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the value.
*
* @return the value
*/
  @Basic
  @Column(name = "VALUE_")
  @Enumerated(EnumType.STRING)
  public LendingTypeCategory getValue() {
      return value;
  }
 
Example #13
Source File: PersonData.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the gender.
*
* @return the gender
*/
  @Basic
  @Column(name = "GENDER")
  @Enumerated(EnumType.STRING)
  public SexType getGender() {
      return gender;
  }
 
Example #14
Source File: DocumentReferenceData.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the reference type.
*
* @return the reference type
*/
  @Basic
  @Column(name = "REFERENCE_TYPE")
  @Enumerated(EnumType.STRING)
  public ReferenceType getReferenceType() {
      return referenceType;
  }
 
Example #15
Source File: VoteDataDto.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the vote.
*
* @return the vote
*/
  @Basic
  @Column(name = "VOTE")
  @Enumerated(EnumType.STRING)
  public VoteDecision getVote() {
      return vote;
  }
 
Example #16
Source File: PersonElement.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the status.
*
* @return the status
*/
  @Basic
  @Column(name = "STATUS")
  @Enumerated(EnumType.STRING)
  public RoleStatus getStatus() {
      return status;
  }
 
Example #17
Source File: PersonElement.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the gender.
*
* @return the gender
*/
  @Basic
  @Column(name = "GENDER")
  @Enumerated(EnumType.STRING)
  public SexType getGender() {
      return gender;
  }
 
Example #18
Source File: Product.java    From website with GNU Affero General Public License v3.0 5 votes vote down vote up
@Enumerated(EnumType.STRING)
public ProductAvailabilityStatus getAvailabilityStatus() {
	if (availabilityStatus == null) {
		availabilityStatus = ProductAvailabilityStatus.ON_SALE;
	}
	return availabilityStatus;
}
 
Example #19
Source File: AssignmentElement.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the status.
*
* @return the status
*/
  @Basic
  @Column(name = "STATUS")
  @Enumerated(EnumType.STRING)
  public RoleStatus getStatus() {
      return status;
  }
 
Example #20
Source File: AssignmentElement.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the role code.
*
* @return the role code
*/
  @Basic
  @Column(name = "ROLE_CODE")
  @Enumerated(EnumType.STRING)
  public RoleStatus getRoleCode() {
      return roleCode;
  }
 
Example #21
Source File: AssignmentElement.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
* Gets the org code.
*
* @return the org code
*/
  @Basic
  @Column(name = "ORG_CODE")
  @Enumerated(EnumType.STRING)
  public OrgCode getOrgCode() {
      return orgCode;
  }
 
Example #22
Source File: ImportJob.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Enumerated(EnumType.STRING)
@Column(nullable = false)
public Status getStatus() {
    return status;
}
 
Example #23
Source File: ImportJob.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Enumerated(EnumType.STRING)
public Health getHealth() {
    return health;
}
 
Example #24
Source File: ImportItem.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Enumerated(EnumType.STRING)
public Health getHealth() {
    return health;
}
 
Example #25
Source File: VatRate.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Column(nullable = false)
@Enumerated(EnumType.STRING)
public VatRateType getType() {
	return type;
}
 
Example #26
Source File: AddressContext.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Enumerated(EnumType.STRING)
@Column(length=30)
public AddressContextType getType() {
	return type;
}
 
Example #27
Source File: Licence.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Column(nullable = false)
@Enumerated(EnumType.STRING)
public PageLayout getPageLayout() {
	return pageLayout;
}
 
Example #28
Source File: RuleViolation.java    From cia with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the resource type.
 *
 * @return the resource type
 */
@Enumerated(EnumType.STRING)
   @Column(name = "resource_type")
public ResourceType getResourceType() {
	return resourceType;
}
 
Example #29
Source File: Preview.java    From website with GNU Affero General Public License v3.0 4 votes vote down vote up
@Column(nullable = false)
@Enumerated(EnumType.STRING)
public PageLayout getLayout() {
	return layout;
}
 
Example #30
Source File: JPAAnnotationsConfigurer.java    From oval with Eclipse Public License 2.0 4 votes vote down vote up
protected void initializeChecks(final Column annotation, final Collection<Check> checks, final AccessibleObject fieldOrMethod) {
   /* If the value is generated (annotated with @GeneratedValue) it is allowed to be null
    * before the entity has been persisted, same is true in case of optimistic locking
    * when a field is annotated with @Version.
    * Therefore and because of the fact that there is no generic way to determine if an entity
    * has been persisted already, a not-null check will not be performed for such fields.
    */
   if (!annotation.nullable() //
      && !fieldOrMethod.isAnnotationPresent(GeneratedValue.class) //
      && !fieldOrMethod.isAnnotationPresent(Version.class) //
      && !fieldOrMethod.isAnnotationPresent(NotNull.class) //
      && !containsCheckOfType(checks, NotNullCheck.class) //
   ) {
      checks.add(new NotNullCheck());
   }

   // add Length check based on Column.length parameter, but only:
   if (!fieldOrMethod.isAnnotationPresent(Lob.class) && // if @Lob is not present
      !fieldOrMethod.isAnnotationPresent(Enumerated.class) && // if @Enumerated is not present
      !fieldOrMethod.isAnnotationPresent(Length.class) // if an explicit @Length constraint is not present
   ) {
      final LengthCheck lengthCheck = new LengthCheck();
      lengthCheck.setMax(annotation.length());
      checks.add(lengthCheck);
   }

   // add Range check based on Column.precision/scale parameters, but only:
   if (!fieldOrMethod.isAnnotationPresent(Range.class) // if an explicit @Range is not present
      && annotation.precision() > 0 // if precision is > 0
      && Number.class.isAssignableFrom(fieldOrMethod instanceof Field //
         ? ((Field) fieldOrMethod).getType() //
         : ((Method) fieldOrMethod).getReturnType()) // if numeric field type
   ) {
      /* precision = 6, scale = 2  => -9999.99<=x<=9999.99
       * precision = 4, scale = 1  =>   -999.9<=x<=999.9
       */
      final RangeCheck rangeCheck = new RangeCheck();
      rangeCheck.setMax(Math.pow(10, annotation.precision() - annotation.scale()) - Math.pow(0.1, annotation.scale()));
      rangeCheck.setMin(-1 * rangeCheck.getMax());
      checks.add(rangeCheck);
   }
}