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:org.emonocot.model.Taxon.java

/**
 * @return the nomenclaturalStatus
 */
@Enumerated(value = EnumType.STRING)
public NomenclaturalStatus getNomenclaturalStatus() {
    return nomenclaturalStatus;
}

From source file:net.firejack.platform.core.store.BaseStore.java

private Criteria createCriteria(Session session, Integer offset, Integer limit, Object example,
        List<String> nullableAssociations) {
    try {//from   w ww .  ja v  a 2 s.c o m
        Class<?> exampleClass = example.getClass();

        Criteria criteria = session.createCriteria(exampleClass);
        //         Map<String, Criteria> subcriterias = new HashMap<String, Criteria>();

        if (limit != null && limit > -1) {
            criteria.setMaxResults(limit);
        }
        if (offset != null && offset > -1) {
            criteria.setFirstResult(offset);
        }

        Example exampleQuery = createExample(example);
        criteria.add(exampleQuery);

        SessionFactory sessionFactory = getHibernateTemplate().getSessionFactory();
        ClassMetadata meta = sessionFactory.getClassMetadata(exampleClass);
        String[] names = meta.getPropertyNames();
        Type[] propertyTypes = meta.getPropertyTypes();
        for (int i = 0; i < propertyTypes.length; i++) {
            if (propertyTypes[i].isAssociationType() && !propertyTypes[i].isCollectionType()) {
                String name = names[i];
                Object value = PropertyUtils.getProperty(example, name);
                if (value != null) {
                    Example subExample = createExample(value);
                    Criteria subcriteria = criteria.createCriteria(name);
                    //                  subcriterias.put(name, subcriteria);
                    subcriteria.add(subExample);
                } else if (nullableAssociations.contains(name)) {
                    criteria.add(Restrictions.isNull(name));
                }
            } else if (propertyTypes[i].isCollectionType()) {
                String name = names[i];
                Collection values = (Collection) PropertyUtils.getProperty(example, name);
                JoinTable joinTable = getMethodAnnotation(JoinTable.class, example, name);
                if (values != null && values.size() > 0 && joinTable != null) {
                    Table table = getClassAnnotation(Table.class, example);
                    Enumerated enumerated = getMethodAnnotation(Enumerated.class, example, name);
                    Object obj = values.iterator().next();
                    if (obj.getClass().isEnum()) {
                        String sqlWhere = "{alias}.id IN (SELECT DISTINCT id_" + table.name() + " FROM "
                                + joinTable.name() + " WHERE element IN (";
                        List<String> ordinals = new ArrayList<String>();
                        for (Object v : values) {
                            if (enumerated != null && EnumType.STRING.equals(enumerated.value())) {
                                ordinals.add("'" + String.valueOf(((Enum) v).name()) + "'");
                            } else {
                                ordinals.add(String.valueOf(((Enum) v).ordinal()));
                            }
                        }
                        String whereValues = StringUtils.join(ordinals.toArray(), ",");
                        sqlWhere = sqlWhere + whereValues + "))";
                        criteria.add(Restrictions.sqlRestriction(sqlWhere));
                    }
                }
            }
        }
        return criteria;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "names_visibility")
public Visibility getCreditNameVisibility() {
    return creditNameVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "other_names_visibility")
public Visibility getOtherNamesVisibility() {
    return otherNamesVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "biography_visibility")
public Visibility getBiographyVisibility() {
    return biographyVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "keywords_visibility")
public Visibility getKeywordsVisibility() {
    return keywordsVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "external_identifiers_visibility")
public Visibility getExternalIdentifiersVisibility() {
    return externalIdentifiersVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "researcher_urls_visibility")
public Visibility getResearcherUrlsVisibility() {
    return researcherUrlsVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "profile_address_visibility")
public Visibility getProfileAddressVisibility() {
    return profileAddressVisibility;
}

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

@Basic
@Enumerated(EnumType.STRING)
@Column(name = "activities_visibility_default")
public Visibility getActivitiesVisibilityDefault() {
    return activitiesVisibilityDefault;
}