(TableX<K, ?> table)
| 83 | } |
| 84 | |
| 85 | public static <K extends Comparable<K>> void clearDbTable(TableX<K, ?> table) throws Exception { |
| 86 | var t = System.nanoTime(); |
| 87 | table.__ClearTableCacheUnsafe__(); |
| 88 | //noinspection DataFlowIssue |
| 89 | var dbTable = table.internalGetStorageForTestOnly("IKnownWhatIAmDoing").getDatabaseTable(); |
| 90 | var txnWrap = new Object() { |
| 91 | Database.Transaction txn = dbTable.getDatabase().beginTransaction(); |
| 92 | int n; |
| 93 | int total; |
| 94 | }; |
| 95 | |
| 96 | if (table.isUseRelationalMapping()) { |
| 97 | var sqlKey = new SQLStatement(); |
| 98 | dbTable.walkDatabaseKey(table, k -> { |
| 99 | sqlKey.clear(); |
| 100 | table.encodeKeySQLStatement(sqlKey, k); |
| 101 | var txn = txnWrap.txn; |
| 102 | dbTable.remove(txn, sqlKey); |
| 103 | if (++txnWrap.n >= 10000) { |
| 104 | txn.commit(); |
| 105 | txn.close(); |
| 106 | txnWrap.total += txnWrap.n; |
| 107 | txnWrap.n = 0; |
| 108 | txnWrap.txn = dbTable.getDatabase().beginTransaction(); |
| 109 | } |
| 110 | return true; |
| 111 | }); |
| 112 | } else { |
| 113 | var bb = ByteBuffer.Allocate(0); |
| 114 | ((Database.AbstractKVTable)dbTable).walkKey(k -> { |
| 115 | var txn = txnWrap.txn; |
| 116 | bb.wraps(k); |
| 117 | dbTable.remove(txn, bb); |
| 118 | if (++txnWrap.n >= 10000) { |
| 119 | txn.commit(); |
| 120 | txn.close(); |
| 121 | txnWrap.total += txnWrap.n; |
| 122 | txnWrap.n = 0; |
| 123 | txnWrap.txn = dbTable.getDatabase().beginTransaction(); |
| 124 | } |
| 125 | return true; |
| 126 | }); |
| 127 | } |
| 128 | var txn = txnWrap.txn; |
| 129 | txn.commit(); |
| 130 | txn.close(); |
| 131 | txnWrap.total += txnWrap.n; |
| 132 | logger.info("clear table {}: {}, {} ms", table.getName(), txnWrap.total, (System.nanoTime() - t) / 1_000_000); |
| 133 | } |
| 134 | |
| 135 | public void clearTables() throws Exception { |
| 136 | clearDbTable(app.demo_Module1.getTable1()); |
no test coverage detected