use of org.broadleafcommerce.common.i18n.domain.TranslationImpl in project BroadleafCommerce by BroadleafCommerce.
the class TranslationDaoImpl method readTranslation.
@Override
public Translation readTranslation(TranslatedEntity entityType, String entityId, String fieldName, String localeCode, String localeCountryCode, ResultType stage) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Translation> criteria = builder.createQuery(Translation.class);
Root<TranslationImpl> root = criteria.from(TranslationImpl.class);
criteria.select(root);
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(root.get("entityType"), entityType.getFriendlyType()));
restrictions.add(builder.equal(root.get("entityId"), entityId));
restrictions.add(builder.equal(root.get("fieldName"), fieldName));
restrictions.add(builder.like(root.get("localeCode").as(String.class), localeCode + "%"));
try {
if (extensionManager != null) {
extensionManager.getProxy().setup(TranslationImpl.class, stage);
extensionManager.getProxy().refineParameterRetrieve(TranslationImpl.class, stage, builder, criteria, root, restrictions);
}
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Translation> query = em.createQuery(criteria);
if (extensionManager != null) {
extensionManager.getProxy().refineQuery(TranslationImpl.class, stage, query);
}
query.setHint(QueryHints.HINT_CACHEABLE, true);
List<Translation> translations = query.getResultList();
if (!translations.isEmpty()) {
if (!localeCode.equals(localeCountryCode)) {
return findBestTranslation(localeCountryCode, translations);
} else {
return findSpecificTranslation(localeCountryCode, translations);
}
} else {
return null;
}
} finally {
if (extensionManager != null) {
extensionManager.getProxy().breakdown(TranslationImpl.class, stage);
}
}
}
Aggregations