GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • objectbox-java/src/main/java/io/objectbox
    • Box.java
    • Cursor.java
    • Transaction.java
  • tests/objectbox-java-test/src/main/java/io/objectbox
    • CursorTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objectbox-java/src/main/java/io/objectbox/Box.java‎

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 numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Cursor<T> getReader() {
7474
throw new IllegalStateException("Illegal reader TX state");
7575
}
7676
tx.renew();
77-
cursor.renew(tx);
77+
cursor.renew();
7878
} else {
7979
cursor = store.beginReadTx().createCursor(entityClass);
8080
threadLocalReader.set(cursor);
Collapse file

‎objectbox-java/src/main/java/io/objectbox/Cursor.java‎

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 numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ protected static native long collect004000(long cursor, long keyIfComplete, int
116116

117117
static native void nativeSetBoxStoreForEntities(long cursor, Object boxStore);
118118

119-
protected Transaction tx;
119+
protected final Transaction tx;
120120
protected final long cursor;
121121
protected final EntityInfo entityInfo;
122122
protected final BoxStore boxStoreForEntities;
@@ -264,9 +264,11 @@ protected <TARGET> Cursor<TARGET> getRelationTargetCursor(Class<TARGET> targetCl
264264
return tx.createCursor(targetClass);
265265
}
266266

267-
public void renew(Transaction tx) {
267+
/**
268+
* To be used in combination with {@link Transaction#renew()}.
269+
* */
270+
public void renew() {
268271
nativeRenew(cursor, tx.internalHandle());
269-
this.tx = tx;
270272
}
271273

272274
@Internal
Collapse file

‎objectbox-java/src/main/java/io/objectbox/Transaction.java‎

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 numberDiff line numberDiff line change
@@ -131,13 +131,16 @@ public void reset() {
131131
nativeReset(transaction);
132132
}
133133

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+
*/
135138
public void recycle() {
136139
checkOpen();
137140
nativeRecycle(transaction);
138141
}
139142

140-
/** Efficient for read transactions. */
143+
/** Renews a previously recycled transaction (see {@link #recycle()}). Efficient for read transactions. */
141144
public void renew() {
142145
checkOpen();
143146
initialCommitCount = store.commitCount;
Collapse file

‎tests/objectbox-java-test/src/main/java/io/objectbox/CursorTest.java‎

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 numberDiff line numberDiff line change
@@ -316,10 +316,9 @@ public void testRenew() throws IOException {
316316

317317
Transaction transaction = store.beginReadTx();
318318
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();
323322
assertEquals("orange", cursor.get(1).getSimpleString());
324323

325324
cursor.close();

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.