-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
110 additions
and
63 deletions.
There are no files selected for viewing
54 changes: 0 additions & 54 deletions
54
core/src/main/java/io/github/mmm/entity/id/LongIdMemorySequence.java
This file was deleted.
Oops, something went wrong.
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
8 changes: 7 additions & 1 deletion
8
...github/mmm/entity/id/UuidIdGenerator.java → .../entity/id/generator/UuidIdGenerator.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
25 changes: 25 additions & 0 deletions
25
core/src/main/java/io/github/mmm/entity/id/sequence/IdSequence.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,25 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.entity.id.sequence; | ||
|
||
import io.github.mmm.entity.id.Id; | ||
import io.github.mmm.entity.id.LongId; | ||
import io.github.mmm.entity.id.generator.IdGenerator; | ||
|
||
/** | ||
* Interface for a sequence that can generate the next unique {@link Id#get() primary key} of type {@link Long} for a | ||
* new {@link LongId}. | ||
* | ||
* @see IdGenerator#generate(Id) | ||
*/ | ||
public interface IdSequence { | ||
|
||
/** | ||
* @param template the {@link Id#isTransient() transient} {@link Id} of the {@link io.github.mmm.entity.Entity entity} | ||
* to insert. | ||
* @return the next long value guaranteed to be unique for this sequence. Proper implementations delegate to a | ||
* database sequence. | ||
*/ | ||
long next(Id<?> template); | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
core/src/main/java/io/github/mmm/entity/id/sequence/IdSequenceMemory.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 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.entity.id.sequence; | ||
|
||
import io.github.mmm.entity.id.Id; | ||
|
||
/** | ||
* {@link IdSequence} implementation using an in-memory counter that is NOT persistent. By design this implementation | ||
* can not guarantee correctness. Only use this for pragmatic scenarios e.g. for tests or if you are not using a | ||
* database at all (e.g. also all data is hold in memory for simple apps that persist all data to JSON or the like). | ||
*/ | ||
public final class IdSequenceMemory implements IdSequence { | ||
|
||
private volatile long sequence; | ||
|
||
/** | ||
* The constructor. | ||
*/ | ||
public IdSequenceMemory() { | ||
|
||
this(10_000_000L); // enough room for your own master data | ||
} | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param sequenceStart the start value of the sequence. | ||
*/ | ||
public IdSequenceMemory(long sequenceStart) { | ||
|
||
super(); | ||
this.sequence = sequenceStart; | ||
} | ||
|
||
/** | ||
* @return the current sequence value. | ||
*/ | ||
public long getSequence() { | ||
|
||
return this.sequence; | ||
} | ||
|
||
/** | ||
* @param sequence new value of {@link #getSequence()}. | ||
*/ | ||
public void setSequence(long sequence) { | ||
|
||
this.sequence = sequence; | ||
} | ||
|
||
@Override | ||
public long next(Id<?> template) { | ||
|
||
return this.sequence++; | ||
} | ||
|
||
} |
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