Examples of HydrationDescriptor


Examples of org.broadleafcommerce.common.cache.engine.HydrationDescriptor

        populateFromCache(entity, null);
    }

    public static void populateFromCache(Object entity, String propertyName) {
        HydratedCacheManager manager = HydratedCacheEventListenerFactory.getConfiguredManager();
        HydrationDescriptor descriptor = ((HydratedAnnotationManager) manager).getHydrationDescriptor(entity);
        if (!MapUtils.isEmpty(descriptor.getHydratedMutators())) {
            Method[] idMutators = descriptor.getIdMutators();
            String cacheRegion = descriptor.getCacheRegion();
            for (String field : descriptor.getHydratedMutators().keySet()) {
                if (StringUtils.isEmpty(propertyName) || field.equals(propertyName)) {
                    try {
                        Serializable entityId = (Serializable) idMutators[0].invoke(entity);
                        Object hydratedItem = manager.getHydratedCacheElementItem(cacheRegion, getInheritanceHierarchyRoot(entity.getClass()), entityId, field);
                        if (hydratedItem == null) {
                            Method factoryMethod = entity.getClass().getMethod(descriptor.getHydratedMutators().get(field).getFactoryMethod(), new Class[]{});
                            Object fieldVal = factoryMethod.invoke(entity);
                            manager.addHydratedCacheElementItem(cacheRegion, getInheritanceHierarchyRoot(entity.getClass()), entityId, field, fieldVal);
                            hydratedItem = fieldVal;
                        }
                        descriptor.getHydratedMutators().get(field).getMutators()[1].invoke(entity, hydratedItem);
                    } catch (InvocationTargetException e) {
                        if (e.getTargetException() != null && e.getTargetException() instanceof CacheFactoryException) {
                            LOG.warn("Unable to setup the hydrated cache for an entity. " + e.getTargetException().getMessage());
                        } else {
                            throw new RuntimeException("There was a problem while replacing a hydrated cache item - field("+field+") : entity("+entity.getClass().getName()+')', e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.