changeset 1533:28f06ac6ce39

add not_in_transaction
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 02 Aug 2020 21:17:27 -0600
parents 060ff7695317
children 3289674cc440
files src/luan/modules/lucene/Lucene.luan src/luan/modules/lucene/LuceneIndex.java
diffstat 2 files changed, 31 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
diff -r 060ff7695317 -r 28f06ac6ce39 src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Sun Aug 02 17:01:25 2020 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Sun Aug 02 21:17:27 2020 -0600
@@ -57,9 +57,10 @@
 	index.snapshot = java_index.snapshot
 	index.advanced_search = java_index.advanced_search
 	index.search_in_transaction = java_index.search_in_transaction
-	index.delete_all = java_index.delete_all
-	index.delete = java_index.delete
-	index.save = java_index.save
+	--index.delete_all = java_index.delete_all
+	--index.delete = java_index.delete
+	--index.save = java_index.save
+	index.is_in_transaction = java_index.is_in_transaction
 	index.run_in_transaction = java_index.run_in_transaction
 	index.ensure_open = java_index.ensure_open
 	index.next_id = java_index.nextId
@@ -73,6 +74,29 @@
 	index.force_restore_from_postgres = java_index.force_restore_from_postgres
 	index.check = java_index.check
 
+	function index.not_in_transaction() end
+
+	function index.check_in_transaction()
+		if not index.is_in_transaction() then
+			index.not_in_transaction()
+		end
+	end
+
+	function index.delete_all()
+		index.check_in_transaction()
+		java_index.delete_all()
+	end
+
+	function index.delete(query)
+		index.check_in_transaction()
+		java_index.delete(query)
+	end
+
+	function index.save(doc)
+		index.check_in_transaction()
+		java_index.save(doc)
+	end
+
 	function index.search( query, from, to, options )
 		from or error "missing 'from' parameter"
 		to or error "missing 'to' parameter"
diff -r 060ff7695317 -r 28f06ac6ce39 src/luan/modules/lucene/LuceneIndex.java
--- a/src/luan/modules/lucene/LuceneIndex.java	Sun Aug 02 17:01:25 2020 -0600
+++ b/src/luan/modules/lucene/LuceneIndex.java	Sun Aug 02 21:17:27 2020 -0600
@@ -291,6 +291,10 @@
 		}
 	}
 
+	public boolean is_in_transaction() {
+		return writeLock.isHeldByCurrentThread();
+	}
+
 	public Object run_in_transaction(LuanFunction fn)
 		throws IOException, LuanException, SQLException
 	{