Skip to content

Commit

Permalink
fix: fix sonar issues (#671)
Browse files Browse the repository at this point in the history
* fix: fix sonar issues

* fix: fix sonar issues

* fix: fix sonar issues

* chore: applying sirixDB formatter

---------

Co-authored-by: Naman Dhamani <naman_dhamani@intuit.com>
  • Loading branch information
Naman0133 and kanhaG2608 authored Oct 16, 2023
1 parent 9082514 commit bac04bb
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class AbstractDeweyIDManager<W extends NodeTrx & NodeCursor> {
* Constructor.
* @param nodeTrx the node transaction
*/
public AbstractDeweyIDManager(W nodeTrx) {
protected AbstractDeweyIDManager(W nodeTrx) {
this.nodeTrx = nodeTrx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class AbstractNodeHashing<N extends ImmutableNode, T extends Nod
* @param nodeReadOnlyTrx the internal read-only node trx
* @param pageTrx the page trx
*/
public AbstractNodeHashing(final ResourceConfiguration resourceConfig, final T nodeReadOnlyTrx,
protected AbstractNodeHashing(final ResourceConfiguration resourceConfig, final T nodeReadOnlyTrx,
final PageTrx pageTrx) {
this.hashType = resourceConfig.hashType;
this.nodeReadOnlyTrx = nodeReadOnlyTrx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ public abstract class AbstractNodeTrxImpl<R extends NodeReadOnlyTrx & NodeCursor
* The transaction states.
*/
private enum State {
Running,
RUNNING,

Committing,
COMMITTING,

Committed,
COMMITTED,

Closed
CLOSED
}

protected AbstractNodeTrxImpl(final ThreadFactory threadFactory, final HashType hashType, final IN nodeReadOnlyTrx,
Expand Down Expand Up @@ -188,7 +188,7 @@ protected AbstractNodeTrxImpl(final ThreadFactory threadFactory, final HashType
this.maxNodeCount = maxNodeCount;
this.modificationCount = 0L;

this.state = State.Running;
this.state = State.RUNNING;

if (!afterCommitDelay.isZero()) {
commitScheduler.scheduleWithFixedDelay(() -> commit("autoCommit", null),
Expand All @@ -201,7 +201,7 @@ protected AbstractNodeTrxImpl(final ThreadFactory threadFactory, final HashType
protected abstract W self();

protected void assertRunning() {
if (state != State.Running) {
if (state != State.RUNNING) {
throw new IllegalStateException("Transaction state is not running: " + state);
}
}
Expand Down Expand Up @@ -276,7 +276,7 @@ public W commit(@Nullable final String commitMessage, @Nullable final Instant co
}

runLocked(() -> {
state = State.Committing;
state = State.COMMITTING;

// Execute pre-commit hooks.
for (final PreCommitHook hook : preCommitHooks) {
Expand All @@ -300,9 +300,9 @@ public W commit(@Nullable final String commitMessage, @Nullable final Instant co
// Reinstantiate everything.
if (afterCommitState == AfterCommitState.KEEP_OPEN) {
reInstantiate(getId(), preCommitRevision);
state = State.Running;
state = State.RUNNING;
} else {
state = State.Committed;
state = State.COMMITTED;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,23 +715,27 @@ public PageReadOnlyTrx beginPageReadOnlyTrx(final @NonNegative int revision) {
assertAccess(revision);

final long currentPageTrxID = pageTrxIDCounter.incrementAndGet();
final NodePageReadOnlyTrx pageReadTrx = new NodePageReadOnlyTrx(currentPageTrxID,
this,
lastCommittedUberPage.get(),
revision,
storage.createReader(),
bufferManager,
new RevisionRootPageReader(),
null);

// Remember page transaction for debugging and safe close.
if (pageTrxMap.put(currentPageTrxID, pageReadTrx) != null) {
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
NodePageReadOnlyTrx pageReadTrx = null;
try {
pageReadTrx = new NodePageReadOnlyTrx(currentPageTrxID,
this,
lastCommittedUberPage.get(),
revision,
storage.createReader(),
bufferManager,
new RevisionRootPageReader(),
null);
// Remember page transaction for debugging and safe close.
if (pageTrxMap.put(currentPageTrxID, pageReadTrx) != null) {
throw new SirixThreadedException(ID_GENERATION_EXCEPTION);
}
} catch (Exception e) {
// Handle exception if any
throw e;
} finally {
return pageReadTrx;
}

return pageReadTrx;
}

@Override
public synchronized PageTrx beginPageTrx(final @NonNegative int revision) {
assertAccess(revision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void unlock() {
}
}

@NotNull
@Override
public Condition newCondition() {
if (lock != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ final class JsonNodeTrxImpl extends AbstractNodeTrxImpl<JsonNodeReadOnlyTrx, Jso
*/
private int beforeBulkInsertionRevisionNumber;

/**
* Insert not allowed exception because of absance of parent in array.
*/
private static final String INSERT_NOT_ALLOWED_SINCE_PARENT_NOT_IN_AN_ARRAY_NODE = "Insert is not allowed if parent node is not an array node!";

/**
* Constructor.
*
Expand Down Expand Up @@ -659,7 +664,7 @@ public JsonNodeTrx insertObjectAsLeftSibling() {

if (!nodeHashing.isBulkInsert()) {
if (getParentKind() != NodeKind.ARRAY) {
throw new SirixUsageException("Insert is not allowed if parent node is not an array node!");
throw new SirixUsageException(INSERT_NOT_ALLOWED_SINCE_PARENT_NOT_IN_AN_ARRAY_NODE);
}
}

Expand Down Expand Up @@ -702,7 +707,7 @@ public JsonNodeTrx insertObjectAsRightSibling() {

if (!nodeHashing.isBulkInsert()) {
if (getParentKind() != NodeKind.ARRAY) {
throw new SirixUsageException("Insert is not allowed if parent node is not an array node!");
throw new SirixUsageException(INSERT_NOT_ALLOWED_SINCE_PARENT_NOT_IN_AN_ARRAY_NODE);
}
}

Expand Down Expand Up @@ -1644,7 +1649,7 @@ public JsonNodeTrx insertBooleanValueAsRightSibling(boolean value) {

private void checkPrecondition() {
if (!nodeHashing.isBulkInsert() && getParentKind() != NodeKind.ARRAY) {
throw new SirixUsageException("Insert is not allowed if parent node is not an array node!");
throw new SirixUsageException(INSERT_NOT_ALLOWED_SINCE_PARENT_NOT_IN_AN_ARRAY_NODE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,12 @@ public boolean moveToAttributeByName(final QNm name) {
long attKey = -1;
for (int i = 0; i < element.getAttributeCount(); i++) {
long attributeKey = element.getAttributeKey(i);
if (moveTo(attributeKey) && getName().equals(name)) {
attKey = attributeKey;
break;
if (moveTo(attributeKey)) {
QNm attName = getName();
if (attName != null && attName.equals(name)) {
attKey = attributeKey;
break;
}
}
}
setCurrentNode(currentNode);
Expand Down

0 comments on commit bac04bb

Please sign in to comment.