changeset 1379:87a3738d7cc5

run_in_transaction
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 24 Jul 2019 11:43:04 -0600
parents a503be8b8dce
children 04482e2a6ca3
files conv.txt src/luan/modules/lucene/Lucene.luan src/luan/modules/lucene/LuceneIndex.java src/luan/modules/lucene/Versioning.luan
diffstat 4 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
diff -r a503be8b8dce -r 87a3738d7cc5 conv.txt
--- a/conv.txt	Sun Jul 14 22:26:33 2019 -0600
+++ b/conv.txt	Wed Jul 24 11:43:04 2019 -0600
@@ -1,3 +1,5 @@
+Lucene.update_in_transaction
+
 Lucene.index
 Thread.schedule
 
diff -r a503be8b8dce -r 87a3738d7cc5 src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Sun Jul 14 22:26:33 2019 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Wed Jul 24 11:43:04 2019 -0600
@@ -61,7 +61,7 @@
 	index.delete_all = java_index.delete_all
 	index.delete = java_index.delete
 	index.save = java_index.save
-	index.update_in_transaction = java_index.update_in_transaction
+	index.run_in_transaction = java_index.run_in_transaction
 	index.ensure_open = java_index.ensure_open
 	index.next_id = java_index.nextId
 	index.highlighter = java_index.highlighter
diff -r a503be8b8dce -r 87a3738d7cc5 src/luan/modules/lucene/LuceneIndex.java
--- a/src/luan/modules/lucene/LuceneIndex.java	Sun Jul 14 22:26:33 2019 -0600
+++ b/src/luan/modules/lucene/LuceneIndex.java	Wed Jul 24 11:43:04 2019 -0600
@@ -260,25 +260,26 @@
 		}
 	}
 
-	public void update_in_transaction(LuanFunction fn) throws IOException, LuanException {
+	public Object run_in_transaction(LuanFunction fn) throws IOException, LuanException {
 		boolean commit = !writeLock.isHeldByCurrentThread();
 		writeLock.lock();
 		try {
-			fn.call();
+			Object rtn = fn.call();
 			if(commit) writer.commit();
+			return rtn;
 		} finally {
 			wrote();
 			writeLock.unlock();
 		}
 	}
 
-	public void run_in_lock(LuanFunction fn) throws IOException, LuanException {
+	public Object run_in_lock(LuanFunction fn) throws IOException, LuanException {
 		if( writeLock.isHeldByCurrentThread() )
 			throw new RuntimeException();
 		writeLock.lock();
 		try {
 			synchronized(this) {
-				fn.call();
+				return fn.call();
 			}
 		} finally {
 			wrote();
diff -r a503be8b8dce -r 87a3738d7cc5 src/luan/modules/lucene/Versioning.luan
--- a/src/luan/modules/lucene/Versioning.luan	Sun Jul 14 22:26:33 2019 -0600
+++ b/src/luan/modules/lucene/Versioning.luan	Wed Jul 24 11:43:04 2019 -0600
@@ -23,7 +23,7 @@
 	while doc.version < version do
 		doc.version = integer(doc.version + 1)
 		logger.error("step "..doc.version)
-		db.update_in_transaction( function()
+		db.run_in_transaction( function()
 			local step = steps[doc.version]
 			step and step(db)
 			db.save(doc)