@@ -147,10 +147,10 @@ private long getLastEntryInLedgerInternal(long ledgerId) throws IOException {
147147 }
148148
149149 public void addLocation (long ledgerId , long entryId , long location ) throws IOException {
150- Batch batch = locationsDb .newBatch ();
151- addLocation (batch , ledgerId , entryId , location );
152- batch .flush ();
153- batch . close ();
150+ try ( Batch batch = locationsDb .newBatch ()) {
151+ addLocation (batch , ledgerId , entryId , location );
152+ batch .flush ();
153+ }
154154 }
155155
156156 public Batch newBatch () {
@@ -178,18 +178,17 @@ public void updateLocations(Iterable<EntryLocation> newLocations) throws IOExcep
178178 log .debug ("Update locations -- {}" , Iterables .size (newLocations ));
179179 }
180180
181- Batch batch = newBatch ();
182- // Update all the ledger index pages with the new locations
183- for (EntryLocation e : newLocations ) {
184- if (log .isDebugEnabled ()) {
185- log .debug ("Update location - ledger: {} -- entry: {}" , e .ledger , e .entry );
186- }
181+ try ( Batch batch = newBatch ()) {
182+ // Update all the ledger index pages with the new locations
183+ for (EntryLocation e : newLocations ) {
184+ if (log .isDebugEnabled ()) {
185+ log .debug ("Update location - ledger: {} -- entry: {}" , e .ledger , e .entry );
186+ }
187187
188- addLocation (batch , e .ledger , e .entry , e .location );
188+ addLocation (batch , e .ledger , e .entry , e .location );
189+ }
190+ batch .flush ();
189191 }
190-
191- batch .flush ();
192- batch .close ();
193192 }
194193
195194 public void delete (long ledgerId ) throws IOException {
0 commit comments