Search in sources :

Example 11 with LongType

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);
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) SessionFactory(org.hibernate.SessionFactory) Translation(org.broadleafcommerce.common.i18n.domain.Translation) LongType(org.hibernate.type.LongType) TranslationImpl(org.broadleafcommerce.common.i18n.domain.TranslationImpl) StringType(org.hibernate.type.StringType) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) StringType(org.hibernate.type.StringType) LongType(org.hibernate.type.LongType) ResultType(org.broadleafcommerce.common.extension.ResultType) Type(org.hibernate.type.Type) ArrayList(java.util.ArrayList) List(java.util.List)

Example 12 with LongType

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);
}
Also used : IntegerType(org.hibernate.type.IntegerType) LongType(org.hibernate.type.LongType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType)

Aggregations

LongType (org.hibernate.type.LongType)12 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 StringType (org.hibernate.type.StringType)5 org.hibernate (org.hibernate)4 PipelineId (com.thoughtworks.go.server.ui.PipelineId)3 CollectionUtil (com.thoughtworks.go.server.util.CollectionUtil)3 HibernateCallback (org.springframework.orm.hibernate3.HibernateCallback)3 ModificationForPipeline (com.thoughtworks.go.server.ui.ModificationForPipeline)2 ResultType (org.broadleafcommerce.common.extension.ResultType)2 Type (org.hibernate.type.Type)2 AbstractMaterial (com.thoughtworks.go.config.materials.AbstractMaterial)1 MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)1 Materials (com.thoughtworks.go.config.materials.Materials)1 com.thoughtworks.go.domain (com.thoughtworks.go.domain)1 com.thoughtworks.go.domain.materials (com.thoughtworks.go.domain.materials)1 DependencyMaterialInstance (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialInstance)1 CacheKeyGenerator (com.thoughtworks.go.server.cache.CacheKeyGenerator)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 FeedModifier (com.thoughtworks.go.server.dao.FeedModifier)1 Database (com.thoughtworks.go.server.database.Database)1