diff --git a/transactional-demo/pom.xml b/transactional-demo/pom.xml index 3a9cd7e..6faa6d7 100644 --- a/transactional-demo/pom.xml +++ b/transactional-demo/pom.xml @@ -30,6 +30,11 @@ com.alibaba fastjson + + com.google.guava + guava + 20.0 + org.springframework.boot spring-boot-starter-jdbc diff --git a/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/stream流/StreamDemo.java b/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/stream流/StreamDemo.java index cbb01b7..b725e86 100644 --- a/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/stream流/StreamDemo.java +++ b/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/stream流/StreamDemo.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import java.util.*; import java.util.function.BiConsumer; +import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -14,15 +15,27 @@ import java.util.stream.Collectors; public class StreamDemo { public static void main(String[] args) { List list = extracted(100); - //1.字段汇总 - Set collect = list.stream() - .map(DataEntity::getName).collect(Collectors.toSet()); + + for (DataEntity entity : list) { + String classNo = entity.getClassNo(); + } + //1.字段汇总 a->a.getName() DataEntity::getName + Set collect = list.stream() + .map(new Function() { + @Override + public Object apply(DataEntity dataEntity) { + return dataEntity.getName(); + } + }).collect(Collectors.toSet()); //2.条件过滤 List collect1 = list.stream().filter(dataEntity -> dataEntity.getClassNo().equals("NO.3")).collect(Collectors.toList()); //3.分组 Map> map = list.stream().collect(Collectors.groupingBy(dataEntity -> dataEntity.getClassNo())); //4.转换 + //list;->point_code = '001' Map map2 = list.stream().collect(HashMap::new, (k, v) -> k.put(v.getName(), v), HashMap::putAll); + DataEntity dataEntity = map2.get("e4563a6b-94c1-4817-97aa-d66a8b21640f"); + System.out.println(dataEntity.toString()); } diff --git a/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/函数式接口/FuntureDemo.java b/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/函数式接口/FuntureDemo.java index d81835a..0819e94 100644 --- a/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/函数式接口/FuntureDemo.java +++ b/transactional-demo/src/main/java/nl/org/transactionaldemo/server/JDK新特性/函数式接口/FuntureDemo.java @@ -13,21 +13,23 @@ public class FuntureDemo { numProcess.process(3); //2.正常业务处理:文字处理业务中需要引入数字处理业务 - StringProcess process = new StringProcess(); - process.process(); + StringProcess sringprocess = new StringProcess(); + sringprocess.process(); + // NumProcess numProcess = new NumProcess(); + // return "NO."+numProcess.process(3); //3.以参数的形式带入 - process.process(new NumProcess()); + sringprocess.process(new NumProcess()); //4.匿名内部类 - process.process(new Process() { + sringprocess.process(new Process() { @Override public Object process(Object o) { return (Integer)o*2; } }); //5.函数式接口 - process.process((a)-> ((Integer) a)*2); + sringprocess.process((a)-> ((Integer) a)*2); } diff --git a/transactional-demo/src/main/java/nl/org/transactionaldemo/server/事务/编程事务/TransationDemo.java b/transactional-demo/src/main/java/nl/org/transactionaldemo/server/事务/编程事务/TransationDemo.java index dd52ce9..0ade27b 100644 --- a/transactional-demo/src/main/java/nl/org/transactionaldemo/server/事务/编程事务/TransationDemo.java +++ b/transactional-demo/src/main/java/nl/org/transactionaldemo/server/事务/编程事务/TransationDemo.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.CollectionUtils; import java.util.*; @@ -28,7 +29,7 @@ public class TransationDemo { @Autowired private PlatformTransactionManager txManager; -// @Transactional + @Transactional public void creteTask(JSONArray request){ List statusCollent = new ArrayList<>(); @@ -71,7 +72,7 @@ public class TransationDemo { } } -//封装参考 + class TransactionManagerUtil{ public static void main(String[] args) { @@ -96,6 +97,10 @@ class TransactionManagerUtil{ PlatformTransactionManager txManager = null; //SpringContextHolder.getBean(PlatformTransactionManager.class); Map statusMap = new HashMap<>(); List errTask; + + DefaultTransactionDefinition init = new DefaultTransactionDefinition(); + init.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); + TransactionStatus initStatus = txManager.getTransaction(init); try { //创建所有事务集合 Consumer allTransactionConsumer = task -> { @@ -122,6 +127,7 @@ class TransactionManagerUtil{ txManager.commit(value); } } + txManager.commit(initStatus); } return null; }