GeezerVison is showing github.com — enforce Cursor.renew() to be tied to the same TX · ligi/objectbox-java@2ac2d9b
File tree
Expand file treeCollapse file tree
Open diff view settings
objectbox-java/src/main/java/io/objectbox tests/objectbox-java-test/src/main/java/io/objectbox
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/Box.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -74,7 +74,7 @@ Cursor<T> getReader() { |
74 | 74 | throw new IllegalStateException("Illegal reader TX state"); |
75 | 75 | } |
76 | 76 | tx.renew(); |
77 | | - cursor.renew(tx); |
| 77 | + cursor.renew(); |
78 | 78 | } else { |
79 | 79 | cursor = store.beginReadTx().createCursor(entityClass); |
80 | 80 | threadLocalReader.set(cursor); |
|
Collapse file
Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/Cursor.java +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -116,7 +116,7 @@ protected static native long collect004000(long cursor, long keyIfComplete, int |
116 | 116 |
|
117 | 117 | static native void nativeSetBoxStoreForEntities(long cursor, Object boxStore); |
118 | 118 |
|
119 | | - protected Transaction tx; |
| 119 | + protected final Transaction tx; |
120 | 120 | protected final long cursor; |
121 | 121 | protected final EntityInfo entityInfo; |
122 | 122 | protected final BoxStore boxStoreForEntities; |
@@ -264,9 +264,11 @@ protected <TARGET> Cursor<TARGET> getRelationTargetCursor(Class<TARGET> targetCl |
264 | 264 | return tx.createCursor(targetClass); |
265 | 265 | } |
266 | 266 |
|
267 | | - public void renew(Transaction tx) { |
| 267 | + /** |
| 268 | + * To be used in combination with {@link Transaction#renew()}. |
| 269 | + * */ |
| 270 | + public void renew() { |
268 | 271 | nativeRenew(cursor, tx.internalHandle()); |
269 | | - this.tx = tx; |
270 | 272 | } |
271 | 273 |
|
272 | 274 | @Internal |
|
Collapse file
Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/Transaction.java +5-2Lines changed: 5 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -131,13 +131,16 @@ public void reset() { |
131 | 131 | nativeReset(transaction); |
132 | 132 | } |
133 | 133 |
|
134 | | - /** For read transactions. */ |
| 134 | + /** |
| 135 | + * For read transactions, this releases important native resources that hold on versions of potential old data. |
| 136 | + * To continue, use {@link #renew()}. |
| 137 | + */ |
135 | 138 | public void recycle() { |
136 | 139 | checkOpen(); |
137 | 140 | nativeRecycle(transaction); |
138 | 141 | } |
139 | 142 |
|
140 | | - /** Efficient for read transactions. */ |
| 143 | + /** Renews a previously recycled transaction (see {@link #recycle()}). Efficient for read transactions. */ |
141 | 144 | public void renew() { |
142 | 145 | checkOpen(); |
143 | 146 | initialCommitCount = store.commitCount; |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/main/java/io/objectbox/CursorTest.java +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -316,10 +316,9 @@ public void testRenew() throws IOException { |
316 | 316 |
|
317 | 317 | Transaction transaction = store.beginReadTx(); |
318 | 318 | Cursor<TestEntity> cursor = transaction.createCursor(TestEntity.class); |
319 | | - transaction.close(); |
320 | | - transaction = store.beginReadTx(); |
321 | | - cursor.renew(transaction); |
322 | | - assertSame(transaction, cursor.getTx()); |
| 319 | + transaction.recycle(); |
| 320 | + transaction.renew(); |
| 321 | + cursor.renew(); |
323 | 322 | assertEquals("orange", cursor.get(1).getSimpleString()); |
324 | 323 |
|
325 | 324 | cursor.close(); |
|