Mercurial Hosting > luan
annotate src/luan/modules/lucene/LuanOpDoer.java @ 1567:349eef23a13c
lucene named backup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 14 Nov 2020 20:05:07 -0700 |
parents | 8fbcc4747091 |
children |
rev | line source |
---|---|
1551 | 1 package luan.modules.lucene; |
2 | |
3 import java.io.IOException; | |
4 import java.util.Map; | |
5 import org.apache.lucene.search.Query; | |
6 import goodjava.lucene.api.GoodIndexWriter; | |
7 import goodjava.lucene.logging.OpDoer; | |
8 import goodjava.lucene.logging.BasicOpDoer; | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
9 import luan.Luan; |
1551 | 10 import luan.LuanFunction; |
11 import luan.LuanException; | |
12 import luan.LuanRuntimeException; | |
13 | |
14 | |
15 final class LuanOpDoer implements OpDoer { | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
16 private final Luan luan; |
1551 | 17 private final OpDoer opDoer; |
18 private final LuanFunction fn; | |
19 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
20 LuanOpDoer(GoodIndexWriter writer,Luan luan,LuanFunction fn) { |
1551 | 21 this.opDoer = new BasicOpDoer(writer); |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
22 this.luan = luan; |
1551 | 23 this.fn = fn; |
24 } | |
25 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
26 @Override public void commit() throws IOException { |
1551 | 27 try { |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
28 fn.call(luan,new CommitAction(opDoer)); |
1551 | 29 } catch(LuanException e) { |
30 throw new LuanRuntimeException(e); | |
31 } | |
32 } | |
33 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
34 @Override public void deleteAll(long time) throws IOException { |
1551 | 35 try { |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
36 fn.call(luan,new DeleteAllAction(opDoer,time)); |
1551 | 37 } catch(LuanException e) { |
38 throw new LuanRuntimeException(e); | |
39 } | |
40 } | |
41 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
42 @Override public void deleteDocuments(long time,Query query) throws IOException { |
1551 | 43 try { |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
44 fn.call(luan,new DeleteDocumentsAction(opDoer,time,query)); |
1551 | 45 } catch(LuanException e) { |
46 throw new LuanRuntimeException(e); | |
47 } | |
48 } | |
49 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
50 @Override public void addDocument(long time,Map<String,Object> storedFields) throws IOException { |
1551 | 51 try { |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
52 fn.call(luan,new AddDocumentAction(opDoer,time,storedFields)); |
1551 | 53 } catch(LuanException e) { |
54 throw new LuanRuntimeException(e); | |
55 } | |
56 } | |
57 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
58 @Override public void updateDocument(long time,String keyFieldName,Map<String,Object> storedFields) throws IOException { |
1551 | 59 try { |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
60 fn.call(luan,new UpdateDocumentAction(opDoer,time,keyFieldName,storedFields)); |
1551 | 61 } catch(LuanException e) { |
62 throw new LuanRuntimeException(e); | |
63 } | |
64 } | |
65 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
66 @Override public void tag(long time,String tag) throws IOException { |
1551 | 67 try { |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1556
diff
changeset
|
68 fn.call(luan,new TagAction(opDoer,time,tag)); |
1551 | 69 } catch(LuanException e) { |
70 throw new LuanRuntimeException(e); | |
71 } | |
72 } | |
73 | |
74 public static abstract class Action { | |
75 public final OpDoer opDoer; | |
76 public final String name; | |
77 | |
78 private Action(OpDoer opDoer,String name) { | |
79 this.opDoer = opDoer; | |
80 this.name = name; | |
81 } | |
82 | |
83 public abstract void run() throws IOException; | |
84 } | |
85 | |
86 public static final class CommitAction extends Action { | |
87 | |
88 private CommitAction(OpDoer opDoer) { | |
89 super(opDoer,"commit"); | |
90 } | |
91 | |
92 public void run() throws IOException { | |
93 opDoer.commit(); | |
94 } | |
95 } | |
96 | |
97 public static final class DeleteAllAction extends Action { | |
98 public final long time; | |
99 | |
100 private DeleteAllAction(OpDoer opDoer,long time) { | |
101 super(opDoer,"deleteAll"); | |
102 this.time = time; | |
103 } | |
104 | |
105 public void run() throws IOException { | |
106 opDoer.deleteAll(time); | |
107 } | |
108 } | |
109 | |
110 public static final class DeleteDocumentsAction extends Action { | |
111 public final long time; | |
112 public final Query query; | |
113 | |
114 private DeleteDocumentsAction(OpDoer opDoer,long time,Query query) { | |
115 super(opDoer,"deleteDocuments"); | |
116 this.time = time; | |
117 this.query = query; | |
118 } | |
119 | |
120 public void run() throws IOException { | |
121 opDoer.deleteDocuments(time,query); | |
122 } | |
123 } | |
124 | |
125 public static final class AddDocumentAction extends Action { | |
126 public final long time; | |
127 public final Map<String,Object> storedFields; | |
128 | |
129 private AddDocumentAction(OpDoer opDoer,long time,Map<String,Object> storedFields) { | |
130 super(opDoer,"addDocument"); | |
131 this.time = time; | |
132 this.storedFields = storedFields; | |
133 } | |
134 | |
135 public void run() throws IOException { | |
136 opDoer.addDocument(time,storedFields); | |
137 } | |
138 } | |
139 | |
140 public static final class UpdateDocumentAction extends Action { | |
141 public final long time; | |
142 public final String keyFieldName; | |
143 public final Map<String,Object> storedFields; | |
144 | |
145 private UpdateDocumentAction(OpDoer opDoer,long time,String keyFieldName,Map<String,Object> storedFields) { | |
146 super(opDoer,"updateDocument"); | |
147 this.time = time; | |
148 this.keyFieldName = keyFieldName; | |
149 this.storedFields = storedFields; | |
150 } | |
151 | |
152 public void run() throws IOException { | |
153 opDoer.updateDocument(time,keyFieldName,storedFields); | |
154 } | |
155 } | |
156 | |
157 public static final class TagAction extends Action { | |
158 public final long time; | |
159 public final String tag; | |
160 | |
161 private TagAction(OpDoer opDoer,long time,String tag) { | |
162 super(opDoer,"tag"); | |
163 this.time = time; | |
164 this.tag = tag; | |
165 } | |
166 | |
167 public void run() throws IOException { | |
168 opDoer.tag(time,tag); | |
169 } | |
170 } | |
171 | |
172 } |