package io.shardingjdbc.example.orchestration.spring.boot.jpa.service;

import io.shardingjdbc.example.orchestration.spring.boot.jpa.entity.Order;
import io.shardingjdbc.example.orchestration.spring.boot.jpa.entity.OrderItem;
import io.shardingjdbc.example.orchestration.spring.boot.jpa.repository.OrderItemRepository;
import io.shardingjdbc.example.orchestration.spring.boot.jpa.repository.OrderRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DemoService {
    
    @Resource
    private OrderRepository orderRepository;
    
    @Resource
    private OrderItemRepository orderItemRepository;
    
    public void demo() {
        while (true) {
            List<Long> orderIds = new ArrayList<>(10);
            List<Long> orderItemIds = new ArrayList<>(10);
            System.out.println("1.Insert--------------");
            for (int i = 0; i < 10; i++) {
                Order order = new Order();
                order.setUserId(51);
                order.setStatus("INSERT_TEST");
                long orderId = orderRepository.save(order).getOrderId();
                orderIds.add(orderId);
                OrderItem item = new OrderItem();
                item.setOrderId(orderId);
                item.setUserId(51);
                item.setStatus("INSERT_TEST");
                orderItemIds.add(orderItemRepository.save(item).getOrderItemId());
            }
            List<OrderItem> orderItems = orderItemRepository.findAll();
            System.out.println(orderItemRepository.findAll());
            System.out.println("2.Delete--------------");
            if (orderItems.size() > 0) {
                for (Long each : orderItemIds) {
                    orderItemRepository.delete(each);
                }
                for (Long each : orderIds) {
                    orderRepository.delete(each);
                }
            }
            System.out.println(orderItemRepository.findAll());
            try {
                Thread.sleep(5000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}

@@ -741,35 +741,8 @@
 ) %7B%0A
-        while (true) %7B%0A    
     
@@ -792,28 +792,24 @@
 0);%0A        
- 
-   
 List%3CLong%3E o
@@ -843,36 +843,32 @@
 %3C%3E(10);%0A        
-    
 System.out.print
@@ -901,28 +901,24 @@
 %22);%0A        
-  
-  
 for (int i =
@@ -944,28 +944,24 @@
             
-    
 Order order 
@@ -971,28 +971,24 @@
 ew Order();%0A
-    
             
@@ -1012,36 +1012,32 @@
 1);%0A            
-    
 order.setStatus(
@@ -1044,36 +1044,32 @@
 %22INSERT_TEST%22);%0A
-    
             long
@@ -1129,28 +1129,24 @@
             
- 
-   
 orderIds.add
@@ -1148,36 +1148,32 @@
 s.add(orderId);%0A
-    
             Orde
@@ -1206,36 +1206,32 @@
 ();%0A            
-  
-  
 item.setOrderId(
@@ -1244,36 +1244,32 @@
 d);%0A            
-    
 item.setUserId(5
@@ -1276,36 +1276,32 @@
 1);%0A            
-   
- 
 item.setStatus(%22
@@ -1307,36 +1307,32 @@
 %22INSERT_TEST%22);%0A
-    
             orde
@@ -1394,36 +1394,32 @@
 mId());%0A        
-    
 %7D%0A            Li
@@ -1408,28 +1408,24 @@
   %7D%0A        
- 
-   
 List%3COrderIt
@@ -1472,36 +1472,32 @@
 dAll();%0A        
-    
 System.out.print
@@ -1531,36 +1531,32 @@
 All());%0A        
-  
-  
 System.out.print
@@ -1593,20 +1593,16 @@
         
-    
 if (orde
@@ -1626,36 +1626,32 @@
 ) %7B%0A            
-   
- 
 for (Long each :
@@ -1663,28 +1663,24 @@
 rItemIds) %7B%0A
-    
             
@@ -1709,36 +1709,32 @@
 y.delete(each);%0A
-    
             %7D%0A  
@@ -1735,36 +1735,32 @@
   %7D%0A            
-    
 for (Long each :
@@ -1768,28 +1768,24 @@
 orderIds) %7B%0A
-    
             
@@ -1830,32 +1830,26 @@
         
- 
-   %7D%0A  
+%7D%0A
         
   %7D%0A    
@@ -1840,30 +1840,26 @@
         
-  %7D%0A  
+%7D%0A
         
   System
@@ -1846,26 +1846,24 @@
   %7D%0A        
-  
 System.out.p
@@ -1904,171 +1904,8 @@
 ());
-%0A            try %7B%0A                Thread.sleep(5000L);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D
 %0A%0A  

remove while true for example