Skip to content

Commit

Permalink
modified state change checks in ArtifactStateExt and AbstractSqlRegis…
Browse files Browse the repository at this point in the history
…tryStorage
  • Loading branch information
renjingxiao committed Sep 28, 2023
1 parent 6bb5ba9 commit c306309
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ public void logIfDeprecated(String groupId, Object artifactId, Object version, A
}

public void applyState(Consumer<ArtifactState> consumer, ArtifactState previousState, ArtifactState newState) {
if (previousState != null) {
if (canTransition(previousState, newState)) {
consumer.accept(newState);
if ( previousState != newState) {
if (previousState != null) {
if (canTransition(previousState, newState)) {
consumer.accept(newState);
} else {
throw new InvalidArtifactStateException(previousState, newState);
}
} else {
throw new InvalidArtifactStateException(previousState, newState);
consumer.accept(newState);
}
} else {
consumer.accept(newState);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,21 +451,15 @@ public void updateArtifactState(String groupId, String artifactId, String versio
/**
* IMPORTANT: Private methods can't be @Transactional. Callers MUST have started a transaction.
*/
private void updateArtifactVersionStateRaw(long globalId, ArtifactState oldState, ArtifactState newState)
throws VersionNotFoundException {
private void updateArtifactVersionStateRaw(long globalId, ArtifactState oldState, ArtifactState newState) {
handles.withHandleNoException(handle -> {
if (oldState != newState) {
artifactStateEx.applyState(s -> {
int rowCount = handle.createUpdate(sqlStatements.updateArtifactVersionState())
.bind(0, s.name())
.bind(1, tenantContext.tenantId())
.bind(2, globalId)
.execute();
if (rowCount == 0) {
throw new VersionNotFoundException(globalId);
}
}, oldState, newState);
}
artifactStateEx.applyState(s -> {
handle.createUpdate(sqlStatements.updateArtifactVersionState())
.bind(0, s.name())
.bind(1, tenantContext.tenantId())
.bind(2, globalId)
.execute();
}, oldState, newState);
return null;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,6 @@ public void deleteGlobalRule(RuleType rule) {


private void updateArtifactState(ArtifactState currentState, String groupId, String artifactId, String version, ArtifactState newState, EditableArtifactMetaDataDto metaData) {
if (currentState == newState) {
return;
}
artifactStateEx.applyState(
s -> {
UUID reqId = ConcurrentUtil.get(submitter.submitArtifactVersion(tenantContext.tenantId(), groupId, artifactId,
Expand Down

0 comments on commit c306309

Please sign in to comment.