Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sonar issues #667

Merged
merged 2 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ public abstract class AbstractResourceSession<R extends NodeReadOnlyTrx & NodeCu
*/
private final PageTrxFactory pageTrxFactory;

/**
* ID Generation exception message for duplicate ID.
*/
private final String ID_GENERATION_EXCEPTION = "ID generation is bogus because of duplicate ID.";

/**
* Creates a new instance of this class.
*
Expand Down Expand Up @@ -347,7 +352,7 @@ public synchronized R beginNodeReadOnlyTrx(@NonNegative final int revision) {

// Remember reader for debugging and safe close.
if (nodeTrxMap.put(reader.getId(), reader) != null) {
throw new SirixUsageException("ID generation is bogus because of duplicate ID.");
throw new SirixUsageException(ID_GENERATION_EXCEPTION);
}

return reader;
Expand Down Expand Up @@ -450,7 +455,7 @@ public synchronized W beginNodeTrx(final @NonNegative int maxNodeCount, final @N

// Remember node transaction for debugging and safe close.
if (nodeTrxMap.put(nodeTrxId, (R) wtx) != null || nodePageTrxMap.put(nodeTrxId, pageWtx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}

return wtx;
Expand Down Expand Up @@ -721,7 +726,7 @@ public PageReadOnlyTrx beginPageReadOnlyTrx(final @NonNegative int revision) {

// Remember page transaction for debugging and safe close.
if (pageTrxMap.put(currentPageTrxID, pageReadTrx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}

return pageReadTrx;
Expand All @@ -748,7 +753,7 @@ public synchronized PageTrx beginPageTrx(final @NonNegative int revision) {

// Remember page transaction for debugging and safe close.
if (pageTrxMap.put(currentPageTrxID, pageTrx) != null) {
throw new SirixThreadedException("ID generation is bogus because of duplicate ID.");
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}

return pageTrx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public final class JsonNodeReadOnlyTrxImpl
super(trxId, pageReadTransaction, documentNode, resourceManager, new ItemListImpl());
}

private final String INSERT = "insert";
private final String UPDATE = "update";
private final String DELETE = "delete";
private final String REPLACE = "replace";

@Override
public boolean hasLastChild() {
assertNotClosed();
Expand Down Expand Up @@ -103,10 +108,10 @@ private Consumer<JsonElement> serializeJsonFragmentIfNeeded(final List<JsonObjec
final var diffObject = diff.getAsJsonObject();

final JsonObject diffTupleObject;
if (diffObject.has("insert")) {
diffTupleObject = diffObject.getAsJsonObject("insert");
} else if (diffObject.has("replace")) {
diffTupleObject = diffObject.getAsJsonObject("replace");
if (diffObject.has(INSERT)) {
diffTupleObject = diffObject.getAsJsonObject(INSERT);
} else if (diffObject.has(REPLACE)) {
diffTupleObject = diffObject.getAsJsonObject(REPLACE);
} else {
diffTupleObject = null;
}
Expand Down Expand Up @@ -146,29 +151,29 @@ public List<JsonObject> getUpdateOperationsInSubtreeOfNode(final SirixDeweyID ro

private Comparator<JsonObject> sortByDeweyID() {
return Comparator.comparing(updateOperation -> {
if (updateOperation.has("insert")) {
return getDeweyID(updateOperation, "insert");
} else if (updateOperation.has("delete")) {
return getDeweyID(updateOperation, "delete");
} else if (updateOperation.has("update")) {
return getDeweyID(updateOperation, "update");
} else if (updateOperation.has("replace")) {
return getDeweyID(updateOperation, "replace");
if (updateOperation.has(INSERT)) {
return getDeweyID(updateOperation, INSERT);
} else if (updateOperation.has(DELETE)) {
return getDeweyID(updateOperation, DELETE);
} else if (updateOperation.has(UPDATE)) {
return getDeweyID(updateOperation, UPDATE);
} else if (updateOperation.has(REPLACE)) {
return getDeweyID(updateOperation, REPLACE);
}
throw new IllegalStateException(updateOperation + " not known.");
});
}

private Predicate<JsonObject> filterAncestorOperations(SirixDeweyID rootDeweyId, long maxDepth) {
return updateOperation -> {
if (updateOperation.has("insert")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "insert", maxDepth);
} else if (updateOperation.has("delete")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "delete", maxDepth);
} else if (updateOperation.has("update")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "update", maxDepth);
} else if (updateOperation.has("replace")) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, "replace", maxDepth);
if (updateOperation.has(INSERT)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, INSERT, maxDepth);
} else if (updateOperation.has(DELETE)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, DELETE, maxDepth);
} else if (updateOperation.has(UPDATE)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, UPDATE, maxDepth);
} else if (updateOperation.has(REPLACE)) {
return isDescendatOrSelfOf(rootDeweyId, updateOperation, REPLACE, maxDepth);
} else {
throw new IllegalStateException(updateOperation + " not known.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,6 @@ private JsonNodeTrx insertSubtree(final JsonReader reader, final InsertPosition
commit();
}

// for (final long unused : new DescendantAxis(nodeReadOnlyTrx)) {
// System.out.println(nodeReadOnlyTrx.getDeweyID());
// }
} catch (final IOException e) {
throw new UncheckedIOException(e);
}
Expand Down Expand Up @@ -553,9 +550,6 @@ private JsonNodeTrx insertSubtree(final Item item, final InsertPosition insertio
commit();
}

// for (final long unused : new DescendantAxis(nodeReadOnlyTrx)) {
// System.out.println(nodeReadOnlyTrx.getDeweyID());
// }
});
return this;
}
Expand Down