Java Code Examples for javax.persistence.Enumerated

The following examples show how to use javax.persistence.Enumerated. These examples are extracted from open source projects. 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 Project: o2oa   Source File: CheckCore.java    License: 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
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 3
Source Project: cloudbreak   Source File: EnumeratedTest.java    License: 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 4
Source Project: website   Source File: User.java    License: 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 5
Source Project: cia   Source File: AssignmentElement.java    License: 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 6
Source Project: cia   Source File: AssignmentElement.java    License: 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 7
Source Project: cia   Source File: AssignmentElement.java    License: 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 8
Source Project: cia   Source File: PersonElement.java    License: 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 9
Source Project: cia   Source File: PersonElement.java    License: 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 10
Source Project: cia   Source File: VoteDataDto.java    License: 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 11
Source Project: cia   Source File: VoteDataDto.java    License: 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 12
Source Project: cia   Source File: VoteData.java    License: 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 13
Source Project: cia   Source File: VoteData.java    License: 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 14
Source Project: website   Source File: User.java    License: 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 15
Source Project: cia   Source File: Region.java    License: 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 16
Source Project: cia   Source File: Adminregion.java    License: 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 17
Source Project: cia   Source File: LendingType.java    License: 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 18
Source Project: cia   Source File: PersonData.java    License: 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 19
Source Project: cia   Source File: DocumentReferenceData.java    License: 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 20
Source Project: cia   Source File: DocumentPersonReferenceData.java    License: 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 21
Source Project: website   Source File: Product.java    License: 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 22
Source Project: uyuni   Source File: ProjectSource.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the state.
 *
 * @return state
 */
@Enumerated(EnumType.STRING)
@Column
public State getState() {
    return state;
}
 
Example 23
Source Project: uyuni   Source File: EnvironmentTarget.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the status.
 *
 * @return status
 */
@Column
@Enumerated(EnumType.STRING)
public Status getStatus() {
    return status;
}
 
Example 24
Source Project: uyuni   Source File: FilterCriteria.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Gets the type.
 *
 * @return type
 */
@Column(name = "matcher")
@Enumerated(EnumType.STRING)
public Matcher getMatcher() {
    return matcher;
}
 
Example 25
Source Project: uyuni   Source File: NotificationMessage.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get the type of this notification.
 * @return notification type
 */
@Enumerated(EnumType.STRING)
@Column(columnDefinition = "type")
public NotificationType getType() {
    return type;
}
 
Example 26
Source Project: aws-photosharing-example   Source File: Role.java    License: Apache License 2.0 4 votes vote down vote up
@Id
@Enumerated(EnumType.STRING)	
public com.amazon.photosharing.enums.Role getRole() {return this._role;}
 
Example 27
public void prepare(XProperty collectionProperty) {
	// fugly
	if ( prepared ) {
		return;
	}

	if ( collectionProperty == null ) {
		return;
	}

	prepared = true;

	if ( collection.isMap() ) {
		if ( collectionProperty.isAnnotationPresent( MapKeyEnumerated.class ) ) {
			canKeyBeConverted = false;
		}
		else if ( collectionProperty.isAnnotationPresent( MapKeyTemporal.class ) ) {
			canKeyBeConverted = false;
		}
		else if ( collectionProperty.isAnnotationPresent( MapKeyClass.class ) ) {
			canKeyBeConverted = false;
		}
		else if ( collectionProperty.isAnnotationPresent( MapKeyType.class ) ) {
			canKeyBeConverted = false;
		}
	}
	else {
		canKeyBeConverted = false;
	}

	if ( collectionProperty.isAnnotationPresent( ManyToAny.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( OneToMany.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( ManyToMany.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( Enumerated.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( Temporal.class ) ) {
		canElementBeConverted = false;
	}
	else if ( collectionProperty.isAnnotationPresent( CollectionType.class ) ) {
		canElementBeConverted = false;
	}

	// Is it valid to reference a collection attribute in a @Convert attached to the owner (entity) by path?
	// if so we should pass in 'clazzToProcess' also
	if ( canKeyBeConverted || canElementBeConverted ) {
		buildAttributeConversionInfoMaps( collectionProperty, elementAttributeConversionInfoMap, keyAttributeConversionInfoMap );
	}
}
 
Example 28
Source Project: lams   Source File: SimpleValueBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void applyAttributeConverter(XProperty property, ConverterDescriptor attributeConverterDescriptor) {
	if ( attributeConverterDescriptor == null ) {
		return;
	}

	LOG.debugf( "Starting applyAttributeConverter [%s:%s]", persistentClassName, property.getName() );

	if ( property.isAnnotationPresent( Id.class ) ) {
		LOG.debugf( "Skipping AttributeConverter checks for Id attribute [%s]", property.getName() );
		return;
	}

	if ( isVersion ) {
		LOG.debugf( "Skipping AttributeConverter checks for version attribute [%s]", property.getName() );
		return;
	}

	if ( !key && property.isAnnotationPresent( Temporal.class ) ) {
		LOG.debugf( "Skipping AttributeConverter checks for Temporal attribute [%s]", property.getName() );
		return;
	}
	if ( key && property.isAnnotationPresent( MapKeyTemporal.class ) ) {
		LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyTemporal [%s]", property.getName() );
		return;
	}

	if ( !key && property.isAnnotationPresent( Enumerated.class ) ) {
		LOG.debugf( "Skipping AttributeConverter checks for Enumerated attribute [%s]", property.getName() );
		return;
	}
	if ( key && property.isAnnotationPresent( MapKeyEnumerated.class ) ) {
		LOG.debugf( "Skipping AttributeConverter checks for map-key annotated as MapKeyEnumerated [%s]", property.getName() );
		return;
	}

	if ( isAssociation() ) {
		LOG.debugf( "Skipping AttributeConverter checks for association attribute [%s]", property.getName() );
		return;
	}

	this.attributeConverterDescriptor = attributeConverterDescriptor;
}
 
Example 29
Source Project: mybatis-jpa   Source File: ColumnMetaResolver.java    License: Apache License 2.0 4 votes vote down vote up
public static String resolveJdbcAlias(Field field) {

    if (field.isAnnotationPresent(MappedJdbcType.class)) {
      MappedJdbcType jdbcType = field.getAnnotation(MappedJdbcType.class);
      return jdbcType.value().name();
    }

    if (field.isAnnotationPresent(CodeEnum.class)) {
      CodeEnum codeEnum = field.getAnnotation(CodeEnum.class);
      if (Objects.equals(codeEnum.value(), CodeType.INT)) {
        return JdbcType.INTEGER.name();
      }
      if (Objects.equals(codeEnum.value(), CodeType.STRING)) {
        return JdbcType.VARCHAR.name();
      }
    }
    if (field.getType().isEnum()) {
      if (field.isAnnotationPresent(Enumerated.class)) {
        Enumerated enumerated = field.getAnnotation(Enumerated.class);
        if (Objects.equals(enumerated.value(), EnumType.ORDINAL)) {
          return "INTEGER";
        }
      }
      return "VARCHAR";
    }

    Class<?> fieldType = field.getType();

    if (Integer.class.equals(fieldType)) {
      return "INTEGER";
    }
    if (Double.class.equals(fieldType)) {
      return "DOUBLE";
    }
    if (Float.class.equals(fieldType)) {
      return "FLOAT";
    }
    if (String.class.equals(fieldType)) {
      return "VARCHAR";
    }
    if (java.util.Date.class.isAssignableFrom(fieldType)) {
      return "TIMESTAMP";
    }
    return null;
  }
 
Example 30
Source Project: ponto-inteligente-api   Source File: Lancamento.java    License: MIT License 4 votes vote down vote up
@Enumerated(EnumType.STRING)
@Column(name = "tipo", nullable = false)
public TipoEnum getTipo() {
	return tipo;
}