comparison src/luan/modules/lucene/LuceneIndex.java @ 1379:87a3738d7cc5

run_in_transaction
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 24 Jul 2019 11:43:04 -0600
parents 709f7498a363
children bc40bc9aab3a
comparison
equal deleted inserted replaced
1378:a503be8b8dce 1379:87a3738d7cc5
258 wrote(); 258 wrote();
259 writeLock.unlock(); 259 writeLock.unlock();
260 } 260 }
261 } 261 }
262 262
263 public void update_in_transaction(LuanFunction fn) throws IOException, LuanException { 263 public Object run_in_transaction(LuanFunction fn) throws IOException, LuanException {
264 boolean commit = !writeLock.isHeldByCurrentThread(); 264 boolean commit = !writeLock.isHeldByCurrentThread();
265 writeLock.lock(); 265 writeLock.lock();
266 try { 266 try {
267 fn.call(); 267 Object rtn = fn.call();
268 if(commit) writer.commit(); 268 if(commit) writer.commit();
269 return rtn;
269 } finally { 270 } finally {
270 wrote(); 271 wrote();
271 writeLock.unlock(); 272 writeLock.unlock();
272 } 273 }
273 } 274 }
274 275
275 public void run_in_lock(LuanFunction fn) throws IOException, LuanException { 276 public Object run_in_lock(LuanFunction fn) throws IOException, LuanException {
276 if( writeLock.isHeldByCurrentThread() ) 277 if( writeLock.isHeldByCurrentThread() )
277 throw new RuntimeException(); 278 throw new RuntimeException();
278 writeLock.lock(); 279 writeLock.lock();
279 try { 280 try {
280 synchronized(this) { 281 synchronized(this) {
281 fn.call(); 282 return fn.call();
282 } 283 }
283 } finally { 284 } finally {
284 wrote(); 285 wrote();
285 writeLock.unlock(); 286 writeLock.unlock();
286 } 287 }