use of org.hibernate.type.LongType in project BroadleafCommerce by BroadleafCommerce.
the class SparseTranslationOverrideStrategy method getTemplateTranslations.
protected List<Translation> getTemplateTranslations(TranslatedEntity entityType, String entityId, String property, String localeCode) {
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"), property));
restrictions.add(builder.like(root.get("localeCode").as(String.class), localeCode + "%"));
try {
Object testObject = null;
if (restrictAssociation) {
try {
Class<?> type = Class.forName(entityType.getType());
SessionFactory sessionFactory = ((CriteriaBuilderImpl) em.getCriteriaBuilder()).getEntityManagerFactory().getSessionFactory();
Class<?>[] entities = helper.getAllPolymorphicEntitiesFromCeiling(type, sessionFactory, true, true);
// This should already be in level 1 cache and this should not cause a hit to the database.
Map<String, Object> idMetadata = helper.getIdMetadata(entities[entities.length - 1], (HibernateEntityManager) em);
Type idType = (Type) idMetadata.get("type");
if (idType instanceof StringType) {
testObject = em.find(entities[entities.length - 1], entityId);
} else if (idType instanceof LongType) {
testObject = em.find(entities[entities.length - 1], Long.parseLong(entityId));
}
} catch (ClassNotFoundException e) {
throw ExceptionHelper.refineException(e);
}
}
if (extensionManager != null) {
extensionManager.setup(TranslationImpl.class);
extensionManager.refineParameterRetrieve(TranslationImpl.class, testObject, builder, criteria, root, restrictions);
}
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Translation> query = em.createQuery(criteria);
if (extensionManager != null) {
extensionManager.refineQuery(TranslationImpl.class, testObject, query);
}
query.setHint(QueryHints.HINT_CACHEABLE, true);
List response = query.getResultList();
if (extensionManager != null) {
extensionManager.filterResults(TranslationImpl.class, testObject, response);
}
return response;
} finally {
extensionManager.breakdown(TranslationImpl.class);
}
}
use of org.hibernate.type.LongType in project BroadleafCommerce by BroadleafCommerce.
the class GenericEntityDaoImpl method readGenericEntity.
@Override
public <T> T readGenericEntity(Class<T> clazz, Object id) {
clazz = (Class<T>) DynamicDaoHelperImpl.getNonProxyImplementationClassIfNecessary(clazz);
Map<String, Object> md = daoHelper.getIdMetadata(clazz, (HibernateEntityManager) em);
AbstractSingleColumnStandardBasicType type = (AbstractSingleColumnStandardBasicType) md.get("type");
if (type instanceof LongType) {
id = Long.parseLong(String.valueOf(id));
} else if (type instanceof IntegerType) {
id = Integer.parseInt(String.valueOf(id));
}
return em.find(clazz, id);
}
Aggregations