本文整理匯總了Java中javax.persistence.Enumerated類的典型用法代碼示例。如果您正苦於以下問題:Java Enumerated類的具體用法?Java Enumerated怎麽用?Java Enumerated使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Enumerated類屬於javax.persistence包,在下文中一共展示了Enumerated類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getEnumerated
import javax.persistence.Enumerated; //導入依賴的package包/類
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 ) );
}
}
示例2: checkEnumMapping
import javax.persistence.Enumerated; //導入依賴的package包/類
/**
* Enums must be mapped as String, not ORDINAL.
* @param g
*/
private void checkEnumMapping(Method g) {
if(Enum.class.isAssignableFrom(g.getReturnType())) { // Is type enum?
if(g.getAnnotation(Transient.class) != null)
return;
//-- If the enum has a @Type we will have to assume the type handles mapping correctly (like MappedEnumType)
org.hibernate.annotations.Type ht = g.getAnnotation(Type.class);
if(null == ht) {
//-- No @Type mapping, so this must have proper @Enumerated definition.
Enumerated e = g.getAnnotation(Enumerated.class);
if(null == e) {
problem(Severity.ERROR, "Missing @Enumerated annotation on enum property - this will cause ORDINAL mapping of an enum which is undesirable");
m_enumErrors++;
} else if(e.value() != EnumType.STRING) {
problem(Severity.ERROR, "@Enumerated(ORDINAL) annotation on enum property - this will cause ORDINAL mapping of an enum which is undesirable");
m_enumErrors++;
}
}
}
}
示例3: applyAttributeConverter
import javax.persistence.Enumerated; //導入依賴的package包/類
private void applyAttributeConverter(XProperty property, AttributeConverterDefinition attributeConverterDefinition) {
if ( attributeConverterDefinition == 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 ( property.isAnnotationPresent( Temporal.class ) ) {
LOG.debugf( "Skipping AttributeConverter checks for Temporal attribute [%s]", property.getName() );
return;
}
if ( property.isAnnotationPresent( Enumerated.class ) ) {
LOG.debugf( "Skipping AttributeConverter checks for Enumerated attribute [%s]", property.getName() );
return;
}
if ( isAssociation() ) {
LOG.debugf( "Skipping AttributeConverter checks for association attribute [%s]", property.getName() );
return;
}
this.attributeConverterDefinition = attributeConverterDefinition;
}
示例4: processBeanProperty
import javax.persistence.Enumerated; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Builder<?> processBeanProperty(Builder<?> property, Class<?> beanOrNestedClass) {
property.getAnnotation(Enumerated.class).ifPresent(a -> {
final EnumType enumType = a.value();
if (enumType == EnumType.STRING) {
((Builder) property).converter(PropertyValueConverter.enumByName());
} else {
((Builder) property).converter(PropertyValueConverter.enumByOrdinal());
}
LOGGER.debug(() -> "JpaEnumeratedBeanPropertyPostProcessor: setted property [" + property
+ "] value converter to default enumeration converter using [" + enumType.name() + "] mode");
});
return property;
}
開發者ID:holon-platform,項目名稱:holon-datastore-jpa,代碼行數:16,代碼來源:JpaEnumeratedBeanPropertyPostProcessor.java
示例5: getType
import javax.persistence.Enumerated; //導入依賴的package包/類
/**
* Getter for property type.
*
* @return Value of property type.
*/
@Enumerated(EnumType.STRING)
@Column(nullable = false)
public LogItemType getType() {
return this.type;
}
示例6: createAttribute
import javax.persistence.Enumerated; //導入依賴的package包/類
@Enumerated(EnumType.STRING)
private Attribute createAttribute(String[] parts) {
Boolean oneToMany = false;
Boolean oneToOne = false;
Boolean manyToOne = false;
Boolean manyToMany = false;
Boolean required = false;
Boolean enumString = false;
Boolean enumOrdinal = false;
if (parts.length > 2) {
for (int i = 2; i < parts.length; i++) {
if (this.isRequired(parts[i])) {
required = Boolean.valueOf(parts[i]);
} else if (this.isOneToMany(parts[i])) {
oneToMany = true;
} else if (this.isOneToOne(parts[i])) {
oneToOne = true;
} else if (this.isManyToOne(parts[i])) {
manyToOne = true;
} else if (this.isManyToMany(parts[i])) {
manyToMany = true;
} else if (this.isEnumString(parts[i])) {
enumString = true;
} else if (this.isEnumOrdinal(parts[i])) {
enumOrdinal = true;
}
}
}
return new Attribute(parts[0], parts[1], Util.primeiraMaiuscula(parts[0]), oneToMany, oneToOne, manyToOne, manyToMany, required, enumString, enumOrdinal);
}
示例7: initializeChecks
import javax.persistence.Enumerated; //導入依賴的package包/類
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))
if (!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);
}
}
示例8: getAuthorities
import javax.persistence.Enumerated; //導入依賴的package包/類
/**
*
* @return
*/
@ElementCollection(targetClass=EAuthority.class,fetch=FetchType.EAGER)
@JoinTable(name = "grupo_autorities")
@Enumerated(EnumType.STRING)
@Fetch(FetchMode.SELECT)
public List<EAuthority> getAuthorities() {
return authorities;
}
示例9: getAuthorities
import javax.persistence.Enumerated; //導入依賴的package包/類
@ElementCollection(targetClass=EAuthority.class,fetch=FetchType.EAGER)
@JoinTable(name = "pessoa_autorities")
@Enumerated(EnumType.STRING)
@Fetch(FetchMode.SELECT)
public List<EAuthority> getAuthorities() {
return authorities;
}
示例10: getType
import javax.persistence.Enumerated; //導入依賴的package包/類
/**
* @return type type of KPI
*/
@Enumerated(EnumType.ORDINAL)
@Column(name = "type", unique = false, nullable = false)
@Field(index=org.hibernate.search.annotations.Index.TOKENIZED, store=Store.NO)
public Type getType() {
return this.type;
}
示例11: getTypes
import javax.persistence.Enumerated; //導入依賴的package包/類
/**
*
* @return Return the subjects that this content is about.
*/
@ElementCollection
@Column(name = "type")
@Enumerated(EnumType.STRING)
@Sort(type = SortType.NATURAL)
public SortedSet<DescriptionType> getTypes() {
return types;
}
示例12: getSubjectPart
import javax.persistence.Enumerated; //導入依賴的package包/類
@ElementCollection
@CollectionTable(name="image_SubjectPart", [email protected](name="image_id"))
@Column(name="subjectPart")
@Enumerated(value = EnumType.STRING)
public Set<DescriptionType> getSubjectPart() {
return subjectPart;
}
示例13: getAuthorities
import javax.persistence.Enumerated; //導入依賴的package包/類
/**
*
* @return
*/
@ElementCollection(targetClass=EAuthority.class,fetch=FetchType.EAGER)
@JoinTable
@Enumerated(EnumType.STRING)
@Fetch(FetchMode.SELECT)
public List<EAuthority> getAuthorities() {
return authorities;
}
示例14: getAuthorities
import javax.persistence.Enumerated; //導入依賴的package包/類
@ElementCollection(targetClass=EAuthority.class,fetch=FetchType.EAGER)
@JoinTable
@Enumerated(EnumType.STRING)
@Fetch(FetchMode.SELECT)
public List<EAuthority> getAuthorities() {
return authorities;
}
示例15: prepare
import javax.persistence.Enumerated; //導入依賴的package包/類
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 );
}
}