From 50f5ae5fb26027618b4221948f7ef85fd154e83f Mon Sep 17 00:00:00 2001 From: Hishida Masato Date: Thu, 14 Dec 2023 16:46:26 +0900 Subject: [PATCH] feat: insert or replace --- .../costaccounting/db/CostBenchDbManager.java | 4 ++ .../db/dao/ItemConstructionMasterDao.java | 2 +- .../costaccounting/db/dao/ItemMasterDao.java | 10 ++++- .../db/iceaxe/dao/CostMasterDaoIceaxe.java | 4 +- .../db/iceaxe/dao/FactoryMasterDaoIceaxe.java | 2 +- .../db/iceaxe/dao/IceaxeDao.java | 40 ++++++++++++++----- .../dao/ItemConstructionMasterDaoIceaxe.java | 6 +-- .../dao/ItemManufacturingMasterDaoIceaxe.java | 4 +- .../db/iceaxe/dao/ItemMasterDaoIceaxe.java | 9 ++++- .../dao/MeasurementMasterDaoIceaxe.java | 2 +- .../db/iceaxe/dao/ResultTableDaoIceaxe.java | 4 +- .../db/iceaxe/dao/StockHistoryDaoIceaxe.java | 4 +- .../dao/ItemConstructionMasterDaoJdbc.java | 2 +- .../db/jdbc/dao/ItemMasterDaoJdbc.java | 5 +++ .../tsubakuro/dao/CostMasterDaoTsubakuro.java | 4 +- .../dao/FactoryMasterDaoTsubakuro.java | 2 +- .../ItemConstructionMasterDaoTsubakuro.java | 6 +-- .../ItemManufacturingMasterDaoTsubakuro.java | 4 +- .../tsubakuro/dao/ItemMasterDaoTsubakuro.java | 9 ++++- .../dao/MeasurementMasterDaoTsubakuro.java | 2 +- .../dao/ResultTableDaoTsubakuro.java | 4 +- .../dao/StockHistoryDaoTsubakuro.java | 4 +- .../db/tsubakuro/dao/TsubakuroDao.java | 34 +++++++++++----- .../init/InitialData03ItemMaster.java | 12 +++--- .../online/task/BenchOnlineNewItemTask.java | 4 +- .../costaccounting/util/BenchConst.java | 11 ++++- 26 files changed, 132 insertions(+), 62 deletions(-) diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/CostBenchDbManager.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/CostBenchDbManager.java index aae74493..2e621f0b 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/CostBenchDbManager.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/CostBenchDbManager.java @@ -85,6 +85,10 @@ public boolean isTsurugi() { return this.isTsurugi; } + public DbManagerPurpose getPurpose() { + return this.purpose; + } + // DAO public synchronized MeasurementMasterDao getMeasurementMasterDao() { diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemConstructionMasterDao.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemConstructionMasterDao.java index 0acf81dd..271359c9 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemConstructionMasterDao.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemConstructionMasterDao.java @@ -48,7 +48,7 @@ public interface ItemConstructionMasterDao { */ int insert(ItemConstructionMaster entity); - int[] insertBatch(Collection entityList); + int[] insertBatch(Collection entityList, boolean insertOnly); /** *
diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemMasterDao.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemMasterDao.java
index 9072056b..442f9f06 100755
--- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemMasterDao.java
+++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/dao/ItemMasterDao.java
@@ -40,12 +40,20 @@ public interface ItemMasterDao {
 
     /**
      * 
-     * insert into item_master
+     * insert (or replace) into item_master
      * values(:entity)
      * 
*/ int insert(ItemMaster entity); + /** + *
+     * insert into item_master
+     * values(:entity)
+     * 
+ */ + int insertOnly(ItemMaster entity); + int[] insertBatch(Collection entityList); /** diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/CostMasterDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/CostMasterDaoIceaxe.java index cda0714b..e26c8d4c 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/CostMasterDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/CostMasterDaoIceaxe.java @@ -50,12 +50,12 @@ public int deleteAll() { @Override public int insert(CostMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/FactoryMasterDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/FactoryMasterDaoIceaxe.java index 354197df..3616e244 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/FactoryMasterDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/FactoryMasterDaoIceaxe.java @@ -39,7 +39,7 @@ public int deleteAll() { @Override public int insert(FactoryMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/IceaxeDao.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/IceaxeDao.java index 95aa4b40..5329bc9f 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/IceaxeDao.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/IceaxeDao.java @@ -55,6 +55,7 @@ public abstract class IceaxeDao { private final String tableName; private final List> columnList; private final Supplier entitySupplier; + protected final String insert; protected static void add(List> list, TgBindVariable variable, BiConsumer entitySetter, Function entityGetter, RecordGetter recordGetter) { add(list, variable, entitySetter, entityGetter, recordGetter, false); @@ -70,6 +71,7 @@ public IceaxeDao(CostBenchDbManagerIceaxe dbManager, String tableName, List entityList) { + protected final int[] doInsert(Collection entityList, boolean insertOnly) { // TODO batch insertに切り替え switch (1) { default: case 0: - return doInsertWait(entityList); + return doInsertWait(entityList, insertOnly); case 1: - return doInsertNoWait(entityList); + return doInsertNoWait(entityList, insertOnly); } } - private int[] doInsertWait(Collection entityList) { - var ps = insertCache.get(); + private int[] doInsertWait(Collection entityList, boolean insertOnly) { + var ps = getInsertPs(insertOnly); var result = new int[entityList.size()]; int i = 0; for (var entity : entityList) { @@ -127,12 +129,20 @@ private int[] doInsertWait(Collection entityList) { return result; } - private int[] doInsertNoWait(Collection entityList) { - var ps = insertCache.get(); + private int[] doInsertNoWait(Collection entityList, boolean insertOnly) { + var ps = getInsertPs(insertOnly); return executeAndGetCount(ps, entityList); } - private final CachePreparedStatement insertCache = new CachePreparedStatement<>() { + private TsurugiSqlPreparedStatement getInsertPs(boolean insertOnly) { + if (insertOnly) { + return insertOnlyCache.get(); + } else { + return insertCache.get(); + } + } + + private final CachePreparedStatement insertOnlyCache = new CachePreparedStatement<>() { @Override protected void initialize() { var names = getColumnNames(); @@ -142,6 +152,16 @@ protected void initialize() { } }; + private final CachePreparedStatement insertCache = new CachePreparedStatement<>() { + @Override + protected void initialize() { + var names = getColumnNames(); + var values = columnList.stream().map(c -> c.getSqlName()).collect(Collectors.joining(",")); + this.sql = insert + " into " + tableName + "(" + names + ") values (" + values + ")"; + this.parameterMapping = getEntityParameterMapping(); + } + }; + private TgEntityParameterMapping getEntityParameterMapping() { var parameterMapping = TgEntityParameterMapping.of(); for (var column : columnList) { diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemConstructionMasterDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemConstructionMasterDaoIceaxe.java index 5a0d7f8e..bc539fb4 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemConstructionMasterDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemConstructionMasterDaoIceaxe.java @@ -59,12 +59,12 @@ public int deleteAll() { @Override public int insert(ItemConstructionMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override - public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + public int[] insertBatch(Collection entityList, boolean insertOnly) { + return doInsert(entityList, insertOnly); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemManufacturingMasterDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemManufacturingMasterDaoIceaxe.java index a750bcde..5365ba6b 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemManufacturingMasterDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemManufacturingMasterDaoIceaxe.java @@ -53,12 +53,12 @@ public int deleteAll() { @Override public int insert(ItemManufacturingMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemMasterDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemMasterDaoIceaxe.java index e1c24075..fb399066 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemMasterDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ItemMasterDaoIceaxe.java @@ -60,12 +60,17 @@ public int deleteAll() { @Override public int insert(ItemMaster entity) { - return doInsert(entity); + return doInsert(entity, false); + } + + @Override + public int insertOnly(ItemMaster entity) { + return doInsert(entity, true); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/MeasurementMasterDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/MeasurementMasterDaoIceaxe.java index 9dbb7e54..590cfa70 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/MeasurementMasterDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/MeasurementMasterDaoIceaxe.java @@ -38,7 +38,7 @@ public int deleteAll() { @Override public int insert(MeasurementMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ResultTableDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ResultTableDaoIceaxe.java index 3a0c4063..d00058a3 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ResultTableDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/ResultTableDaoIceaxe.java @@ -131,12 +131,12 @@ protected void initialize() { @Override public int insert(ResultTable entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/StockHistoryDaoIceaxe.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/StockHistoryDaoIceaxe.java index 7e9f3471..af1038fb 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/StockHistoryDaoIceaxe.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/iceaxe/dao/StockHistoryDaoIceaxe.java @@ -43,12 +43,12 @@ public int deleteAll() { @Override public int insert(StockHistory entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemConstructionMasterDaoJdbc.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemConstructionMasterDaoJdbc.java index aa19c4ac..ef3a7653 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemConstructionMasterDaoJdbc.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemConstructionMasterDaoJdbc.java @@ -58,7 +58,7 @@ public int insert(ItemConstructionMaster entity) { } @Override - public int[] insertBatch(Collection entityList) { + public int[] insertBatch(Collection entityList, boolean insertOnly) { return doInsert(entityList); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemMasterDaoJdbc.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemMasterDaoJdbc.java index eb3f58e2..3f5edf15 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemMasterDaoJdbc.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/jdbc/dao/ItemMasterDaoJdbc.java @@ -56,6 +56,11 @@ public int insert(ItemMaster entity) { return doInsert(entity); } + @Override + public int insertOnly(ItemMaster entity) { + return doInsert(entity); + } + @Override public int[] insertBatch(Collection entityList) { return doInsert(entityList); diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/CostMasterDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/CostMasterDaoTsubakuro.java index 98c46033..1f63303a 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/CostMasterDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/CostMasterDaoTsubakuro.java @@ -46,12 +46,12 @@ public int deleteAll() { @Override public int insert(CostMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/FactoryMasterDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/FactoryMasterDaoTsubakuro.java index bc9a1b33..7bcf12da 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/FactoryMasterDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/FactoryMasterDaoTsubakuro.java @@ -35,7 +35,7 @@ public int deleteAll() { @Override public int insert(FactoryMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemConstructionMasterDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemConstructionMasterDaoTsubakuro.java index 0eb78734..04f9dc8d 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemConstructionMasterDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemConstructionMasterDaoTsubakuro.java @@ -49,12 +49,12 @@ public int deleteAll() { @Override public int insert(ItemConstructionMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override - public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + public int[] insertBatch(Collection entityList, boolean insertOnly) { + return doInsert(entityList, insertOnly); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemManufacturingMasterDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemManufacturingMasterDaoTsubakuro.java index 4d174d82..16852f19 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemManufacturingMasterDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemManufacturingMasterDaoTsubakuro.java @@ -45,12 +45,12 @@ public int deleteAll() { @Override public int insert(ItemManufacturingMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemMasterDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemMasterDaoTsubakuro.java index d505577d..6ca45667 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemMasterDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ItemMasterDaoTsubakuro.java @@ -60,12 +60,17 @@ public int deleteAll() { @Override public int insert(ItemMaster entity) { - return doInsert(entity); + return doInsert(entity, false); + } + + @Override + public int insertOnly(ItemMaster entity) { + return doInsert(entity, true); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/MeasurementMasterDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/MeasurementMasterDaoTsubakuro.java index dea58ae3..e07bc2ef 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/MeasurementMasterDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/MeasurementMasterDaoTsubakuro.java @@ -39,7 +39,7 @@ public int deleteAll() { @Override public int insert(MeasurementMaster entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ResultTableDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ResultTableDaoTsubakuro.java index 012cb1b4..f5e8be54 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ResultTableDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/ResultTableDaoTsubakuro.java @@ -101,12 +101,12 @@ public int deleteByProductId(int factoryId, LocalDate date, int productId) { @Override public int insert(ResultTable entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/StockHistoryDaoTsubakuro.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/StockHistoryDaoTsubakuro.java index b75fb24e..efcac80f 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/StockHistoryDaoTsubakuro.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/StockHistoryDaoTsubakuro.java @@ -45,12 +45,12 @@ public int deleteAll() { @Override public int insert(StockHistory entity) { - return doInsert(entity); + return doInsert(entity, false); } @Override public int[] insertBatch(Collection entityList) { - return doInsert(entityList); + return doInsert(entityList, false); } @Override diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/TsubakuroDao.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/TsubakuroDao.java index bba93ee8..8ce553a3 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/TsubakuroDao.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/db/tsubakuro/dao/TsubakuroDao.java @@ -40,6 +40,7 @@ public abstract class TsubakuroDao { private final String tableName; private final List> columnList; private final Supplier entitySupplier; + protected final String insert; protected static void add(List> list, String name, AtomType type, BiConsumer entitySetter, Function entityGetter, BiFunction parameterSupplier, TsubakuroResultSetGetter resultSetGetter) { @@ -56,6 +57,7 @@ public TsubakuroDao(CostBenchDbManagerTsubakuro dbManager, String tableName, Lis this.tableName = tableName; this.columnList = columnList; this.entitySupplier = entitySupplier; + this.insert = BenchConst.sqlInsert(dbManager.getPurpose()); } protected final SqlClient getSqlClient() { @@ -85,13 +87,13 @@ protected final int doDeleteAll() { } } - protected final int doInsert(E entity) { - var ps = getInsertPs(); + protected final int doInsert(E entity, boolean insertOnly) { + var ps = getInsertPs(insertOnly); return executeAndGetCount(ps, entity); } - protected final int[] doInsert(Collection entityList) { - var ps = getInsertPs(); + protected final int[] doInsert(Collection entityList, boolean insertOnly) { + var ps = getInsertPs(insertOnly); var result = new int[entityList.size()]; int i = 0; for (var entity : entityList) { @@ -100,19 +102,31 @@ protected final int[] doInsert(Collection entityList) { return result; } + private PreparedStatement insertOnlyPs; private PreparedStatement insertPs; - private synchronized PreparedStatement getInsertPs() { + private synchronized PreparedStatement getInsertPs(boolean insertOnly) { + if (insertOnly) { + if (this.insertOnlyPs == null) { + this.insertOnlyPs = createInsertPs("insert"); + } + return this.insertOnlyPs; + } + if (this.insertPs == null) { - var names = getColumnNames(); - var values = columnList.stream().map(c -> c.getSqlName()).collect(Collectors.joining(",")); - var sql = "insert into " + tableName + "(" + names + ") values (" + values + ")"; - var placeholders = getInsertPlaceholders(); - this.insertPs = createPreparedStatement(sql, placeholders); + this.insertPs = createInsertPs(this.insert); } return this.insertPs; } + private PreparedStatement createInsertPs(String insert) { + var names = getColumnNames(); + var values = columnList.stream().map(c -> c.getSqlName()).collect(Collectors.joining(",")); + var sql = insert + " into " + tableName + "(" + names + ") values (" + values + ")"; + var placeholders = getInsertPlaceholders(); + return createPreparedStatement(sql, placeholders); + } + private List getInsertPlaceholders() { var placeholders = new ArrayList(columnList.size()); for (var column : columnList) { diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/init/InitialData03ItemMaster.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/init/InitialData03ItemMaster.java index 6b3eeace..6f1db28f 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/init/InitialData03ItemMaster.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/init/InitialData03ItemMaster.java @@ -515,7 +515,7 @@ private void insertItemMasterWorkInProcess(int startId, int endId, ItemMasterDao initializeLossRatio(entity.getIcIId() + entity.getIcParentIId(), entity); - insertItemConstructionMaster(icDao, entity, constructionCount); + insertItemConstructionMaster(icDao, entity, false, constructionCount); } } @@ -575,11 +575,11 @@ protected void execute(int iId, AtomicInteger insertCount) { set.add(random(++seed, workStart, workEnd)); } - insertItemConstructionMasterProduct(iId, set, dbManager.getItemConstructionMasterDao(), insertCount); + insertItemConstructionMasterProduct(iId, set, dbManager.getItemConstructionMasterDao(), false, insertCount); } } - public void insertItemConstructionMasterProduct(int productId, Set workSet, ItemConstructionMasterDao icDao, AtomicInteger insertCount) { + public void insertItemConstructionMasterProduct(int productId, Set workSet, ItemConstructionMasterDao icDao, boolean insertOnly, AtomicInteger insertCount) { for (Integer workId : workSet) { ItemConstructionMaster entity = new ItemConstructionMaster(); entity.setIcIId(workId); @@ -587,7 +587,7 @@ public void insertItemConstructionMasterProduct(int productId, Set work initializeStartEndDate(workId + productId, entity); initializeItemConstructionMasterRandom(random, entity); - insertItemConstructionMaster(icDao, entity, insertCount); + insertItemConstructionMaster(icDao, entity, insertOnly, insertCount); } } @@ -651,9 +651,9 @@ protected void initialize(ItemConstructionMaster entity) { } }; - private void insertItemConstructionMaster(ItemConstructionMasterDao icDao, ItemConstructionMaster entity, AtomicInteger insertCount) { + private void insertItemConstructionMaster(ItemConstructionMasterDao icDao, ItemConstructionMaster entity, boolean insertOnly, AtomicInteger insertCount) { Collection list = AMPLIFICATION_ITEM_CONSTRUCTION.amplify(entity); - icDao.insertBatch(list); + icDao.insertBatch(list, insertOnly); insertCount.addAndGet(list.size()); } diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java index 2f06bdb9..0ae1c9a4 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/online/task/BenchOnlineNewItemTask.java @@ -139,7 +139,7 @@ protected ItemMaster getNewItemMasterMain() { workSet.add(id); } - initialData.insertItemConstructionMasterProduct(item.getIId(), workSet, dbManager.getItemConstructionMasterDao(), new AtomicInteger()); + initialData.insertItemConstructionMasterProduct(item.getIId(), workSet, dbManager.getItemConstructionMasterDao(), true, new AtomicInteger()); return item; } @@ -154,7 +154,7 @@ private ItemMaster insertItemMaster(InitialData03ItemMaster initialData) { entity.setExpiredDate(endDate); try { - itemMasterDao.insert(entity); + itemMasterDao.insertOnly(entity); } catch (UniqueConstraintException e) { LOG.debug("duplicate item_master (insert)", e); if (dbManager.isTsurugi()) { diff --git a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java index a8127438..b06f838d 100755 --- a/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java +++ b/java/cost-accounting-benchmark/src/main/java/com/tsurugidb/benchmark/costaccounting/util/BenchConst.java @@ -17,6 +17,7 @@ import org.slf4j.Logger; +import com.tsurugidb.benchmark.costaccounting.db.CostBenchDbManager.DbManagerPurpose; import com.tsurugidb.benchmark.costaccounting.db.DbmsType; import com.tsurugidb.iceaxe.transaction.option.TgTxOption; @@ -538,6 +539,14 @@ public static String timeCommandResultFile() { // share + public static String sqlInsert(DbManagerPurpose purpose) { + String s = getProperty("sql.insert." + purpose.name().toLowerCase(), null); + if (s != null) { + return s; + } + return getProperty("sql.insert", "insert"); + } + public static boolean useReadArea() { return getPropertyBoolean("use.read-area", true); } @@ -548,7 +557,7 @@ public static boolean useReadArea() { // 例えば原価計算ベンチマークと料金計算ベンチマークのテーブルが同じDBにあるとき、原価計算ベンチマークからは料金計算ベンチマークのテーブルを絶対参照しない。 // こうした絶対参照しないと分かっているテーブルをデフォルトトランザクションオプション(exclusive read area)として定義しておく。 /** Iceaxe default transaction option */ - public static final TgTxOption DEFAULT_TX_OPTION = TgTxOption.ofLTX()/*.addExclusiveReadArea("billing", "contracts", "history")*/; + public static final TgTxOption DEFAULT_TX_OPTION = TgTxOption.ofLTX()/* .addExclusiveReadArea("billing", "contracts", "history") */; // properties