Example usage for org.hibernate.type LocaleType INSTANCE

List of usage examples for org.hibernate.type LocaleType INSTANCE

Introduction

In this page you can find the example usage for org.hibernate.type LocaleType INSTANCE.

Prototype

LocaleType INSTANCE

To view the source code for org.hibernate.type LocaleType INSTANCE.

Click Source Link

Usage

From source file:de.rs.hibernate.LocalizedStringType.java

License:Open Source License

@Override
public Type[] getPropertyTypes() {
    return new Type[] { StringType.INSTANCE, LocaleType.INSTANCE };
}

From source file:de.rs.hibernate.LocalizedStringType.java

License:Open Source License

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    //      http://queforum.com/programming-languages-basics/297111-java-usertype-interceptor-handling-i18n-hibernate.html
    //      String text = "";
    //      String rawId = (String) StringType.INSTANCE.nullSafeGet(rs, names, session, owner);
    //      if (rawId != null && rawId.length() > 0) {
    //         Long labelId = Long.parseLong(rawId);
    //         text = LocalizationLabelUtil.getText(labelId, LocaleContextHolder.getLocale());
    //      }//from  www  .j a va2  s.  c  om
    //      return text;
    assert names.length == 2;
    String value = (String) StringType.INSTANCE.nullSafeGet(rs, names[VALUE], session, owner); // already handles null check
    Locale locale = (Locale) LocaleType.INSTANCE.nullSafeGet(rs, names[LOCALE], session, owner); // already handles null check
    return value == null && locale == null ? null : new LocalizedString(value, locale);
}

From source file:de.rs.hibernate.LocalizedStringType.java

License:Open Source License

@Override
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session)
        throws HibernateException, SQLException {
    if (value == null) {
        StringType.INSTANCE.set(st, null, index, session);
        LocaleType.INSTANCE.set(st, null, index + 1, session);
    } else {//ww w  . j a  v a2 s .c  om
        final LocalizedString string = (LocalizedString) value;
        StringType.INSTANCE.set(st, string.getValue(), index, session);
        LocaleType.INSTANCE.set(st, string.getLocale(), index + 1, session);
    }
}

From source file:kr.debop4j.data.hibernate.tools.EntityTool.java

License:Apache License

/**
 * Contains locale./*from w  w  w  . java2s. c o m*/
 *
 * @param entityClass the entity class
 * @param locale      the locale
 * @return the list
 */
public static <T extends ILocaleEntity<TLocaleValue>, TLocaleValue extends ILocaleValue> List<T> containsLocale(
        Class<T> entityClass, Locale locale) {

    String hql = String.format(GET_LIST_BY_LOCALE_KEY, entityClass.getName());
    if (log.isDebugEnabled())
        log.debug("IEntity [{}] ? Locale[{}]    hql=[{}]", entityClass.getName(),
                locale, hql);

    IHibernateDao dao = new HibernateDao();
    return dao.find(entityClass, hql, new HibernateParameter("key", locale, LocaleType.INSTANCE));

}