Skip to content

Commit

Permalink
Synchronize SELECT in CacheMap
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Jun 19, 2023
1 parent 52a6b16 commit 6eadb47
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
16 changes: 12 additions & 4 deletions jsql/src/main/java/org/jaxdb/jsql/CacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,25 @@ void selectAll() throws IOException, SQLException {

V select(final data.Key key) throws IOException, SQLException {
if (!containsKey(key)) {
select(andEq(key));
addKey(key);
synchronized (this) {
if (!containsKey(key)) {
select(andEq(key));
addKey(key);
}
}
}

return get(key);
}

final V superSelect(final data.Key key) throws IOException, SQLException {
if (!containsKey(key)) {
select(andEq(key));
addKey(key);
synchronized (this) {
if (!containsKey(key)) {
select(andEq(key));
addKey(key);
}
}
}

return superGet(key);
Expand Down
3 changes: 3 additions & 0 deletions jsql/src/main/java/org/jaxdb/jsql/DerbyCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ void compileInsertOnConflict(final data.Column<?>[] columns, final Select.untype
final Condition<?> matchRefinement;
boolean modified = false;
if (select == null) {
if (onConflict == null)
throw new IllegalArgumentException("Derby requires primary columns for INSERT table ON CONFLICT clause");

translateTypes = null;
selectColumnNames = null;
matchRefinement = null;
Expand Down
13 changes: 9 additions & 4 deletions jsql/src/main/java/org/jaxdb/jsql/HashTreeCacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,16 @@ final SortedMap<data.Key,V> select(final data.Key fromKey, final data.Key toKey)
if (fromKey.length() > 1)
throw new UnsupportedOperationException("Composite keys are not yet supported");

final Interval<data.Key>[] diff = diffKeys(fromKey, toKey);
Interval<data.Key>[] diff = diffKeys(fromKey, toKey);
if (diff.length > 0) {
select(where(diff));
hashMask.addAll(diff);
treeMask.addAll(diff);
synchronized (this) {
diff = diffKeys(fromKey, toKey);
if (diff.length > 0) {
select(where(diff));
hashMask.addAll(diff);
treeMask.addAll(diff);
}
}
}

return subMap(fromKey, toKey);
Expand Down
11 changes: 8 additions & 3 deletions jsql/src/main/java/org/jaxdb/jsql/TreeCacheMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,15 @@ final SortedMap<data.Key,V> select(final data.Key fromKey, final data.Key toKey)
if (fromKey.length() > 1)
throw new UnsupportedOperationException("Composite keys are not yet supported");

final Interval<data.Key>[] diff = diffKeys(fromKey, toKey);
Interval<data.Key>[] diff = diffKeys(fromKey, toKey);
if (diff.length > 0) {
select(where(diff));
mask.addAll(diff);
synchronized (this) {
diff = diffKeys(fromKey, toKey);
if (diff.length > 0) {
select(where(diff));
mask.addAll(diff);
}
}
}

return subMap(fromKey, toKey);
Expand Down
7 changes: 4 additions & 3 deletions jsql/src/main/java/org/jaxdb/jsql/data.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -4345,9 +4346,11 @@ public static Key with(final String value) {
private final Object[] values;
private final Column[] columns;

private static final Comparator<Key> comparator = (o1, o2) -> o1.compareTo(o2);

private Key(final Column<?>[] columns, final Object ... values) {
min = this;
c = (o1, o2) -> o1.compareTo(o2);
c = comparator;

this.columns = columns;
this.values = values;
Expand All @@ -4366,8 +4369,6 @@ public int compareTo(final Interval<Key> o) {

final Key key = (Key)o;
final int i$ = length();
if (key == null)
System.out.println();
if (i$ != key.length())
throw new IllegalArgumentException("this.length() (" + i$ + ") != that.length() (" + key.length() + ")");

Expand Down

0 comments on commit 6eadb47

Please sign in to comment.