Search in sources :

Example 1 with ManagedMap

use of cn.taketoday.beans.factory.support.ManagedMap in project today-framework by TAKETODAY.

the class CacheAdviceParser method parseDefinitionSource.

private RootBeanDefinition parseDefinitionSource(Element definition, ParserContext parserContext) {
    Props prop = new Props(definition);
    // add cacheable first
    ManagedMap<TypedStringValue, Collection<CacheOperation>> cacheOpMap = new ManagedMap<>();
    cacheOpMap.setSource(parserContext.extractSource(definition));
    List<Element> cacheableCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHEABLE_ELEMENT);
    for (Element opElement : cacheableCacheMethods) {
        String name = prop.merge(opElement, parserContext.getReaderContext());
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(opElement));
        CacheableOperation.Builder builder = prop.merge(opElement, parserContext.getReaderContext(), new CacheableOperation.Builder());
        builder.setUnless(getAttributeValue(opElement, "unless", ""));
        builder.setSync(Boolean.parseBoolean(getAttributeValue(opElement, "sync", "false")));
        Collection<CacheOperation> col = cacheOpMap.computeIfAbsent(nameHolder, k -> new ArrayList<>(2));
        col.add(builder.build());
    }
    List<Element> evictCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_EVICT_ELEMENT);
    for (Element opElement : evictCacheMethods) {
        String name = prop.merge(opElement, parserContext.getReaderContext());
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(opElement));
        CacheEvictOperation.Builder builder = prop.merge(opElement, parserContext.getReaderContext(), new CacheEvictOperation.Builder());
        String wide = opElement.getAttribute("all-entries");
        if (StringUtils.hasText(wide)) {
            builder.setCacheWide(Boolean.parseBoolean(wide.trim()));
        }
        String after = opElement.getAttribute("before-invocation");
        if (StringUtils.hasText(after)) {
            builder.setBeforeInvocation(Boolean.parseBoolean(after.trim()));
        }
        Collection<CacheOperation> col = cacheOpMap.computeIfAbsent(nameHolder, k -> new ArrayList<>(2));
        col.add(builder.build());
    }
    List<Element> putCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_PUT_ELEMENT);
    for (Element opElement : putCacheMethods) {
        String name = prop.merge(opElement, parserContext.getReaderContext());
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(opElement));
        CachePutOperation.Builder builder = prop.merge(opElement, parserContext.getReaderContext(), new CachePutOperation.Builder());
        builder.setUnless(getAttributeValue(opElement, "unless", ""));
        Collection<CacheOperation> col = cacheOpMap.computeIfAbsent(nameHolder, k -> new ArrayList<>(2));
        col.add(builder.build());
    }
    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchCacheOperationSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(definition));
    attributeSourceDefinition.getPropertyValues().add("nameMap", cacheOpMap);
    return attributeSourceDefinition;
}
Also used : Element(org.w3c.dom.Element) CachePutOperation(cn.taketoday.cache.interceptor.CachePutOperation) CacheableOperation(cn.taketoday.cache.interceptor.CacheableOperation) CacheEvictOperation(cn.taketoday.cache.interceptor.CacheEvictOperation) CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Collection(java.util.Collection) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) TypedStringValue(cn.taketoday.beans.factory.config.TypedStringValue) ManagedMap(cn.taketoday.beans.factory.support.ManagedMap)

Example 2 with ManagedMap

use of cn.taketoday.beans.factory.support.ManagedMap in project today-framework by TAKETODAY.

the class TxAdviceBeanDefinitionParser method parseAttributeSource.

private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) {
    List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT);
    ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap = new ManagedMap<>(methods.size());
    transactionAttributeMap.setSource(parserContext.extractSource(attrEle));
    for (Element methodEle : methods) {
        String name = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE);
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(methodEle));
        RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
        String propagation = methodEle.getAttribute(PROPAGATION_ATTRIBUTE);
        String isolation = methodEle.getAttribute(ISOLATION_ATTRIBUTE);
        String timeout = methodEle.getAttribute(TIMEOUT_ATTRIBUTE);
        String readOnly = methodEle.getAttribute(READ_ONLY_ATTRIBUTE);
        if (StringUtils.hasText(propagation)) {
            attribute.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation);
        }
        if (StringUtils.hasText(isolation)) {
            attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation);
        }
        if (StringUtils.hasText(timeout)) {
            attribute.setTimeoutString(timeout);
        }
        if (StringUtils.hasText(readOnly)) {
            attribute.setReadOnly(Boolean.parseBoolean(methodEle.getAttribute(READ_ONLY_ATTRIBUTE)));
        }
        List<RollbackRuleAttribute> rollbackRules = new ArrayList<>(1);
        if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) {
            String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE);
            addRollbackRuleAttributesTo(rollbackRules, rollbackForValue);
        }
        if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) {
            String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE);
            addNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue);
        }
        attribute.setRollbackRules(rollbackRules);
        transactionAttributeMap.put(nameHolder, attribute);
    }
    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(attrEle));
    attributeSourceDefinition.getPropertyValues().add("nameMap", transactionAttributeMap);
    return attributeSourceDefinition;
}
Also used : NoRollbackRuleAttribute(cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute) RollbackRuleAttribute(cn.taketoday.transaction.interceptor.RollbackRuleAttribute) RuleBasedTransactionAttribute(cn.taketoday.transaction.interceptor.RuleBasedTransactionAttribute) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) TypedStringValue(cn.taketoday.beans.factory.config.TypedStringValue) ManagedMap(cn.taketoday.beans.factory.support.ManagedMap)

Example 3 with ManagedMap

use of cn.taketoday.beans.factory.support.ManagedMap in project today-infrastructure by TAKETODAY.

the class TxAdviceBeanDefinitionParser method parseAttributeSource.

private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) {
    List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT);
    ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap = new ManagedMap<>(methods.size());
    transactionAttributeMap.setSource(parserContext.extractSource(attrEle));
    for (Element methodEle : methods) {
        String name = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE);
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(methodEle));
        RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
        String propagation = methodEle.getAttribute(PROPAGATION_ATTRIBUTE);
        String isolation = methodEle.getAttribute(ISOLATION_ATTRIBUTE);
        String timeout = methodEle.getAttribute(TIMEOUT_ATTRIBUTE);
        String readOnly = methodEle.getAttribute(READ_ONLY_ATTRIBUTE);
        if (StringUtils.hasText(propagation)) {
            attribute.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation);
        }
        if (StringUtils.hasText(isolation)) {
            attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation);
        }
        if (StringUtils.hasText(timeout)) {
            attribute.setTimeoutString(timeout);
        }
        if (StringUtils.hasText(readOnly)) {
            attribute.setReadOnly(Boolean.parseBoolean(methodEle.getAttribute(READ_ONLY_ATTRIBUTE)));
        }
        List<RollbackRuleAttribute> rollbackRules = new ArrayList<>(1);
        if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) {
            String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE);
            addRollbackRuleAttributesTo(rollbackRules, rollbackForValue);
        }
        if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) {
            String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE);
            addNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue);
        }
        attribute.setRollbackRules(rollbackRules);
        transactionAttributeMap.put(nameHolder, attribute);
    }
    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(attrEle));
    attributeSourceDefinition.getPropertyValues().add("nameMap", transactionAttributeMap);
    return attributeSourceDefinition;
}
Also used : NoRollbackRuleAttribute(cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute) RollbackRuleAttribute(cn.taketoday.transaction.interceptor.RollbackRuleAttribute) RuleBasedTransactionAttribute(cn.taketoday.transaction.interceptor.RuleBasedTransactionAttribute) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) TypedStringValue(cn.taketoday.beans.factory.config.TypedStringValue) ManagedMap(cn.taketoday.beans.factory.support.ManagedMap)

Example 4 with ManagedMap

use of cn.taketoday.beans.factory.support.ManagedMap in project today-infrastructure by TAKETODAY.

the class CacheAdviceParser method parseDefinitionSource.

private RootBeanDefinition parseDefinitionSource(Element definition, ParserContext parserContext) {
    Props prop = new Props(definition);
    // add cacheable first
    ManagedMap<TypedStringValue, Collection<CacheOperation>> cacheOpMap = new ManagedMap<>();
    cacheOpMap.setSource(parserContext.extractSource(definition));
    List<Element> cacheableCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHEABLE_ELEMENT);
    for (Element opElement : cacheableCacheMethods) {
        String name = prop.merge(opElement, parserContext.getReaderContext());
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(opElement));
        CacheableOperation.Builder builder = prop.merge(opElement, parserContext.getReaderContext(), new CacheableOperation.Builder());
        builder.setUnless(getAttributeValue(opElement, "unless", ""));
        builder.setSync(Boolean.parseBoolean(getAttributeValue(opElement, "sync", "false")));
        Collection<CacheOperation> col = cacheOpMap.computeIfAbsent(nameHolder, k -> new ArrayList<>(2));
        col.add(builder.build());
    }
    List<Element> evictCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_EVICT_ELEMENT);
    for (Element opElement : evictCacheMethods) {
        String name = prop.merge(opElement, parserContext.getReaderContext());
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(opElement));
        CacheEvictOperation.Builder builder = prop.merge(opElement, parserContext.getReaderContext(), new CacheEvictOperation.Builder());
        String wide = opElement.getAttribute("all-entries");
        if (StringUtils.hasText(wide)) {
            builder.setCacheWide(Boolean.parseBoolean(wide.trim()));
        }
        String after = opElement.getAttribute("before-invocation");
        if (StringUtils.hasText(after)) {
            builder.setBeforeInvocation(Boolean.parseBoolean(after.trim()));
        }
        Collection<CacheOperation> col = cacheOpMap.computeIfAbsent(nameHolder, k -> new ArrayList<>(2));
        col.add(builder.build());
    }
    List<Element> putCacheMethods = DomUtils.getChildElementsByTagName(definition, CACHE_PUT_ELEMENT);
    for (Element opElement : putCacheMethods) {
        String name = prop.merge(opElement, parserContext.getReaderContext());
        TypedStringValue nameHolder = new TypedStringValue(name);
        nameHolder.setSource(parserContext.extractSource(opElement));
        CachePutOperation.Builder builder = prop.merge(opElement, parserContext.getReaderContext(), new CachePutOperation.Builder());
        builder.setUnless(getAttributeValue(opElement, "unless", ""));
        Collection<CacheOperation> col = cacheOpMap.computeIfAbsent(nameHolder, k -> new ArrayList<>(2));
        col.add(builder.build());
    }
    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchCacheOperationSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(definition));
    attributeSourceDefinition.getPropertyValues().add("nameMap", cacheOpMap);
    return attributeSourceDefinition;
}
Also used : Element(org.w3c.dom.Element) CachePutOperation(cn.taketoday.cache.interceptor.CachePutOperation) CacheableOperation(cn.taketoday.cache.interceptor.CacheableOperation) CacheEvictOperation(cn.taketoday.cache.interceptor.CacheEvictOperation) CacheOperation(cn.taketoday.cache.interceptor.CacheOperation) Collection(java.util.Collection) RootBeanDefinition(cn.taketoday.beans.factory.support.RootBeanDefinition) TypedStringValue(cn.taketoday.beans.factory.config.TypedStringValue) ManagedMap(cn.taketoday.beans.factory.support.ManagedMap)

Aggregations

TypedStringValue (cn.taketoday.beans.factory.config.TypedStringValue)4 ManagedMap (cn.taketoday.beans.factory.support.ManagedMap)4 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)4 Element (org.w3c.dom.Element)4 CacheEvictOperation (cn.taketoday.cache.interceptor.CacheEvictOperation)2 CacheOperation (cn.taketoday.cache.interceptor.CacheOperation)2 CachePutOperation (cn.taketoday.cache.interceptor.CachePutOperation)2 CacheableOperation (cn.taketoday.cache.interceptor.CacheableOperation)2 NoRollbackRuleAttribute (cn.taketoday.transaction.interceptor.NoRollbackRuleAttribute)2 RollbackRuleAttribute (cn.taketoday.transaction.interceptor.RollbackRuleAttribute)2 RuleBasedTransactionAttribute (cn.taketoday.transaction.interceptor.RuleBasedTransactionAttribute)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2