@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
List<Method> matchingMethods = new ArrayList<>(); for (Method method : methods) { if (isMatch(method.getName(), mappedName)) { matchingMethods.add(method); addTransactionalMethod(method, attr);
/** * Eagerly initializes the specified * {@link #setMethodMap(java.util.Map) "methodMap"}, if any. * @see #initMethodMap(java.util.Map) */ @Override public void afterPropertiesSet() { initMethodMap(this.methodMap); this.eagerlyInitialized = true; this.initialized = true; }
/** * Add an attribute for a transactional method. * <p>Method names can end or start with "*" for matching multiple methods. * @param name class and method name, separated by a dot * @param attr attribute associated with the method * @throws IllegalArgumentException in case of an invalid name */ public void addTransactionalMethod(String name, TransactionAttribute attr) { Assert.notNull(name, "Name must not be null"); int lastDotIndex = name.lastIndexOf('.'); if (lastDotIndex == -1) { throw new IllegalArgumentException("'" + name + "' is not a valid method name: format is FQN.methodName"); } String className = name.substring(0, lastDotIndex); String methodName = name.substring(lastDotIndex + 1); Class<?> clazz = ClassUtils.resolveClassName(className, this.beanClassLoader); addTransactionalMethod(clazz, methodName, attr); }
/** * Add an attribute for a transactional method. * <p>Method names can end or start with "*" for matching multiple methods. * @param name class and method name, separated by a dot * @param attr attribute associated with the method * @throws IllegalArgumentException in case of an invalid name */ public void addTransactionalMethod(String name, TransactionAttribute attr) { Assert.notNull(name, "Name must not be null"); int lastDotIndex = name.lastIndexOf('.'); if (lastDotIndex == -1) { throw new IllegalArgumentException("'" + name + "' is not a valid method name: format is FQN.methodName"); } String className = name.substring(0, lastDotIndex); String methodName = name.substring(lastDotIndex + 1); Class<?> clazz = ClassUtils.resolveClassName(className, this.beanClassLoader); addTransactionalMethod(clazz, methodName, attr); }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
List<Method> matchingMethods = new ArrayList<>(); for (Method method : methods) { if (isMatch(method.getName(), mappedName)) { matchingMethods.add(method); addTransactionalMethod(method, attr);
/** * Add an attribute for a transactional method. * <p>Method names can end or start with "*" for matching multiple methods. * @param name class and method name, separated by a dot * @param attr attribute associated with the method * @throws IllegalArgumentException in case of an invalid name */ public void addTransactionalMethod(String name, TransactionAttribute attr) { Assert.notNull(name, "Name must not be null"); int lastDotIndex = name.lastIndexOf('.'); if (lastDotIndex == -1) { throw new IllegalArgumentException("'" + name + "' is not a valid method name: format is FQN.methodName"); } String className = name.substring(0, lastDotIndex); String methodName = name.substring(lastDotIndex + 1); Class<?> clazz = ClassUtils.resolveClassName(className, this.beanClassLoader); addTransactionalMethod(clazz, methodName, attr); }
/** * Eagerly initializes the specified * {@link #setMethodMap(java.util.Map) "methodMap"}, if any. * @see #initMethodMap(java.util.Map) */ @Override public void afterPropertiesSet() { initMethodMap(this.methodMap); this.eagerlyInitialized = true; this.initialized = true; }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
List<Method> matchingMethods = new ArrayList<>(); for (Method method : methods) { if (isMatch(method.getName(), mappedName)) { matchingMethods.add(method); addTransactionalMethod(method, attr);
/** * Add an attribute for a transactional method. * <p>Method names can end or start with "*" for matching multiple methods. * @param name class and method name, separated by a dot * @param attr attribute associated with the method * @throws IllegalArgumentException in case of an invalid name */ public void addTransactionalMethod(String name, TransactionAttribute attr) { Assert.notNull(name, "Name must not be null"); int lastDotIndex = name.lastIndexOf('.'); if (lastDotIndex == -1) { throw new IllegalArgumentException("'" + name + "' is not a valid method name: format is FQN.methodName"); } String className = name.substring(0, lastDotIndex); String methodName = name.substring(lastDotIndex + 1); Class<?> clazz = ClassUtils.resolveClassName(className, this.beanClassLoader); addTransactionalMethod(clazz, methodName, attr); }
@Override @Nullable public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class<?> targetClass) { if (this.eagerlyInitialized) { return this.transactionAttributeMap.get(method); } else { synchronized (this.transactionAttributeMap) { if (!this.initialized) { initMethodMap(this.methodMap); this.initialized = true; } return this.transactionAttributeMap.get(method); } } }
public void setAsText(String s) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (s == null || "".equals(s)) { // Leave value in property editor <code>null</code> } else { // Use properties editor to tokenize the hold string PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(s); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually TransactionAttributeEditor tae = new TransactionAttributeEditor(); for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String name = (String) iter.next(); String value = props.getProperty(name); // Convert value to a transaction attribute tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute source.addTransactionalMethod(name, attr); } } setValue(source); }
List<Method> matchingMethods = new ArrayList<>(); for (Method method : methods) { if (isMatch(method.getName(), mappedName)) { matchingMethods.add(method); addTransactionalMethod(method, attr);
/** * Add an attribute for a transactional method. * Method names can end or start with "*" for matching multiple methods. * @param name class and method name, separated by a dot * @param attr attribute associated with the method */ public void addTransactionalMethod(String name, TransactionAttribute attr) { int lastDotIndex = name.lastIndexOf("."); if (lastDotIndex == -1) { throw new TransactionUsageException("'" + name + "' is not a valid method name: format is FQN.methodName"); } String className = name.substring(0, lastDotIndex); String methodName = name.substring(lastDotIndex + 1); try { Class clazz = ClassUtils.forName(className); addTransactionalMethod(clazz, methodName, attr); } catch (ClassNotFoundException ex) { throw new TransactionUsageException("Class '" + className + "' not found"); } }
@Override @Nullable public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class<?> targetClass) { if (this.eagerlyInitialized) { return this.transactionAttributeMap.get(method); } else { synchronized (this.transactionAttributeMap) { if (!this.initialized) { initMethodMap(this.methodMap); this.initialized = true; } return this.transactionAttributeMap.get(method); } } }
@Override public void setAsText(String text) throws IllegalArgumentException { MethodMapTransactionAttributeSource source = new MethodMapTransactionAttributeSource(); if (StringUtils.hasLength(text)) { // Use properties editor to tokenize the hold string. PropertiesEditor propertiesEditor = new PropertiesEditor(); propertiesEditor.setAsText(text); Properties props = (Properties) propertiesEditor.getValue(); // Now we have properties, process each one individually. TransactionAttributeEditor tae = new TransactionAttributeEditor(); Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); String value = props.getProperty(name); // Convert value to a transaction attribute. tae.setAsText(value); TransactionAttribute attr = (TransactionAttribute) tae.getValue(); // Register name and attribute. source.addTransactionalMethod(name, attr); } } setValue(source); }
List matchingMethods = new ArrayList(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().equals(mappedName) || isMatch(methods[i].getName(), mappedName)) { matchingMethods.add(methods[i]); addTransactionalMethod(method, attr);
/** * Set a name/attribute map, consisting of "FQCN.method" method names * (e.g. "com.mycompany.mycode.MyClass.myMethod") and TransactionAttribute * instances (or Strings to be converted to TransactionAttribute instances). * @see TransactionAttribute * @see TransactionAttributeEditor */ public void setMethodMap(Map methodMap) { Iterator it = methodMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); // Check whether we need to convert from String to TransactionAttribute. TransactionAttribute attr = null; if (entry.getValue() instanceof TransactionAttribute) { attr = (TransactionAttribute) entry.getValue(); } else { TransactionAttributeEditor editor = new TransactionAttributeEditor(); editor.setAsText(entry.getValue().toString()); attr = (TransactionAttribute) editor.getValue(); } addTransactionalMethod(name, attr); } }