Example usage for javax.persistence EnumType STRING

List of usage examples for javax.persistence EnumType STRING

Introduction

In this page you can find the example usage for javax.persistence EnumType STRING.

Prototype

EnumType STRING

To view the source code for javax.persistence EnumType STRING.

Click Source Link

Document

Persist enumerated type property or field as a string.

Usage

From source file:edu.duke.cabig.c3pr.domain.StudySubject.java

/**
 * Gets the reg workflow status./*from   w w  w  . j  a va2 s.  com*/
 *
 * @return the reg workflow status
 */
@Enumerated(EnumType.STRING)
public RegistrationWorkFlowStatus getRegWorkflowStatus() {
    return regWorkflowStatus;
}

From source file:edu.duke.cabig.c3pr.domain.StudySubject.java

/**
 * Gets the reg data entry status.//from w w w.  j a  v a 2  s  .  c  o m
 *
 * @return the reg data entry status
 */
@Enumerated(EnumType.STRING)
public RegistrationDataEntryStatus getRegDataEntryStatus() {
    return regDataEntryStatus;
}

From source file:edu.duke.cabig.c3pr.domain.Study.java

@Column(name = "status")
@Enumerated(EnumType.STRING)
public CoordinatingCenterStudyStatus getCoordinatingCenterStudyStatus() {
    return coordinatingCenterStudyStatus;
}

From source file:org.orcid.persistence.jpa.entities.ProfileEntity.java

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "locale")
public Locale getLocale() {
    return locale;
}

From source file:edu.duke.cabig.c3pr.domain.Participant.java

@Enumerated(EnumType.STRING)
public ParticipantStateCode getStateCode() {
    return stateCode;
}

From source file:edu.duke.cabig.c3pr.domain.Study.java

@Enumerated(EnumType.STRING)
public ConsentRequired getConsentRequired() {
    return consentRequired;
}

From source file:ca.oson.json.Oson.java

private <E> String enum2Json(FieldData objectDTO) {
    Object value = objectDTO.valueToProcess;
    Class<E> valueType = objectDTO.returnType;
    EnumType enumType = objectDTO.getEnumType();

    if (value == null) {
        return null;
    }//from  ww w  .  j  a  v  a2s.  c o m

    Enum en = (Enum) value;

    try {
        Function function = objectDTO.getSerializer();
        if (function != null) {
            try {
                if (function instanceof DataMapper2JsonFunction) {
                    DataMapper classData = new DataMapper(objectDTO.returnType, value, objectDTO.classMapper,
                            objectDTO.level, getPrettyIndentation());
                    return ((DataMapper2JsonFunction) function).apply(classData);

                } else if (function instanceof Enum2JsonFunction) {
                    return ((Enum2JsonFunction) function).apply(en);

                } else {

                    Object returnedValue = null;
                    if (function instanceof FieldData2JsonFunction) {
                        FieldData2JsonFunction f = (FieldData2JsonFunction) function;
                        FieldData fieldData = objectDTO.clone();
                        returnedValue = f.apply(fieldData);
                    } else {
                        returnedValue = function.apply(value);
                    }

                    if (returnedValue instanceof Optional) {
                        returnedValue = ObjectUtil.unwrap(returnedValue);
                    }

                    if (returnedValue == null) {
                        return null; // just ignore it, right?
                    } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) {
                        en = (Enum) returnedValue;

                    } else {
                        objectDTO.valueToProcess = returnedValue;
                        return object2String(objectDTO);
                    }

                }

            } catch (Exception e) {
            }
        }
    } catch (Exception ex) {
    }

    String name = en.name();

    if (enumType == null || enumType == EnumType.STRING) {

        for (Method method : valueType.getDeclaredMethods()) {
            for (Annotation annotation : method.getDeclaredAnnotations()) {
                String aname = annotation.annotationType().getName();

                switch (aname) {
                case "com.fasterxml.jackson.annotation.JsonValue":
                case "org.codehaus.jackson.annotate.JsonValue":
                    return ObjectUtil.getMethodValue(en, method);

                case "ca.oson.json.annotation.FieldMapper":
                    ca.oson.json.annotation.FieldMapper fieldMapper = (ca.oson.json.annotation.FieldMapper) annotation;
                    if (fieldMapper.jsonValue() != null && fieldMapper.jsonValue() == BOOLEAN.TRUE) {
                        return ObjectUtil.getMethodValue(en, method);
                    }
                }
            }

        }

        for (Field field : valueType.getDeclaredFields()) {
            if (name.equalsIgnoreCase(field.getName())) {
                ca.oson.json.annotation.FieldMapper fieldMapper = field
                        .getAnnotation(ca.oson.json.annotation.FieldMapper.class);
                if (fieldMapper != null) {
                    String aname = fieldMapper.name();
                    if (!StringUtil.isEmpty(aname)) {
                        return aname;
                    }

                } else {
                    for (Annotation annotation : field.getAnnotations()) {
                        String aname = ObjectUtil.getName(annotation);
                        if (!StringUtil.isEmpty(aname)) {
                            return aname;
                        }
                    }
                }
            }
        }

        return name;
    }

    switch (enumType) {
    case STRING:
        return en.name();
    case ORDINAL:
    default:
        return "" + en.ordinal();
    }
}