Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/javers/javers/issues/186
fixed concurrency issue in CommitSeqGenerator
- Loading branch information
1 parent
619ba40
commit 9ccc152
Showing
10 changed files
with
141 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
javers-core/src/main/java/org/javers/core/commit/HandedOutIds.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.javers.core.commit; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author bartosz.walacik | ||
*/ | ||
class HandedOutIds { | ||
private static final Logger logger = LoggerFactory.getLogger(HandedOutIds.class); | ||
|
||
private int limit = 5; | ||
|
||
private List<CommitId> handedOutList = new ArrayList<>(); | ||
|
||
void put (CommitId handedOut) { | ||
if (handedOutList.size() == limit) { | ||
handedOutList.remove(limit - 1); | ||
} | ||
|
||
int found = findIndex(handedOut.getMajorId()); | ||
|
||
if (found < 0){ | ||
handedOutList.add(0, handedOut); | ||
} else { | ||
handedOutList.remove(found); | ||
handedOutList.add(found, handedOut); | ||
} | ||
} | ||
|
||
private int findIndex(Long majorId){ | ||
for (int i=0; i<handedOutList.size(); i++){ | ||
CommitId c = handedOutList.get(i); | ||
if (c.getMajorId() == majorId){ | ||
return i; | ||
} | ||
|
||
if (c.getMajorId() < majorId){ | ||
return -1; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
CommitId get(Long majorId) { | ||
for (CommitId id : handedOutList){ | ||
if (id.getMajorId() == majorId){ | ||
return id; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters