How to copy list and import as it is in postgresql database in fraction of a second

29 Views Asked by At

I'm having an array list which has more than 1 million of records in it, I want to dump it as the way it is in PostgreSQL database using something built in methods like Copy-manger or any method which will be more faster to import this large amount of data in postgresql

My code is As follows

@Service
public class OrderProcessingService {
    
    @Autowired
    private OrderRepository orderRepository;
    
    public void process_data(String hfrcode, List<Order> order) {
            
    List<Order> orderList = new ArrayList<>(); 
  
    for(var data : order) {
    Order order_data = new Visit();
    order_data .setUuid(UUID.randomUUID().toString());
    order_data .setOrderID(data.getOrderID());
    order_data .setOrderDate(data.getOrderDate());
    order_data .setWeight(data.getWeight());
    order_data .setOrderQuantity(data.getOrderQuantity());
    order_data .setOrderLocation(data.getOrderLocation());
    orderList.add(order_data );
    }

   orderRepository.saveAll(orderList);
 }
} 

Instead of saving the list I want to copy it and dump it into PostgreSQL database so as I can minimize the execution time of importing the data into database.

0

There are 0 best solutions below