我想每天12点将所有数据从原始表复制到重复表。如果我这样做,则发生的任何更改应反映在重复表中。例如,如果我们添加应添加到重复表中的新行。更重要的是,如果更改原始表中的任何列也应反映在重复表中而不添加新行现有的行属性值应更改。
@Override
public void insertDataToTableAtBegining() {
Query itemQuery1 = entitymanager.createNativeQuery("INSERT graph_item SELECT * FROM item WHERE order_id IS NOT NULL");
log.info("Inserting is completed where count is ZERO for item");
itemQuery1.executeUpdate();
Query orderQuery1 = entitymanager.createNativeQuery("INSERT graph_mrk_order SELECT * FROM mrk_order");
log.info("Inserting is completed where count is ZERO for order");
orderQuery1.executeUpdate();
}
@Override
public void insertDataToTable(Date beg, Date end) {
Query itemQuery1;
itemQuery1 = entitymanager.createNativeQuery("INSERT graph_item SELECT * FROM item WHERE create_timestamp BETWEEN '" + beg +"' AND '"+ end +"' WHERE order_id IS NOT NULL");
log.info("Inserting is completed in Daily for item");
itemQuery1.executeUpdate();
Query orderQuery1;
orderQuery1 = entitymanager.createNativeQuery("INSERT graph_mrk_order SELECT * FROM mrk_order WHERE create_timestamp BETWEEN '" + beg +"' AND '"+ end +"'");
log.info("Inserting is completed in Daily for order");
orderQuery1.executeUpdate();
}
答案 0 :(得分:0)
我建议您使用实例化视图,因为它非常适合您的情况,并且您可以保证实例化视图具有原始表中的所有最新行。 在这种情况下,您只需要计划执行物化视图的刷新。