-
Notifications
You must be signed in to change notification settings - Fork 4
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
Jonathan Henrique Medeiros
committed
Feb 3, 2024
1 parent
ab07589
commit 2504506
Showing
11 changed files
with
99 additions
and
78 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
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
17 changes: 17 additions & 0 deletions
17
src/main/java/br/com/multidatasources/service/v1/idempotency/Algorithm.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,17 @@ | ||
package br.com.multidatasources.service.v1.idempotency; | ||
|
||
public enum Algorithm { | ||
|
||
SHA_256("SHA-256"); | ||
|
||
private final String value; | ||
|
||
Algorithm(final String value) { | ||
this.value = value; | ||
} | ||
|
||
public String value() { | ||
return this.value; | ||
} | ||
|
||
} |
16 changes: 12 additions & 4 deletions
16
...in/java/br/com/multidatasources/service/v1/idempotency/impl/UUIDIdempotencyGenerator.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 |
---|---|---|
@@ -1,20 +1,28 @@ | ||
package br.com.multidatasources.service.v1.idempotency.impl; | ||
|
||
import br.com.multidatasources.model.IdempotentEntity; | ||
import br.com.multidatasources.service.v1.idempotency.Algorithm; | ||
import br.com.multidatasources.service.v1.idempotency.IdempotencyGenerator; | ||
import br.com.multidatasources.util.JsonUtils; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.UUID; | ||
|
||
@Component | ||
public class UUIDIdempotencyGenerator implements IdempotencyGenerator { | ||
|
||
@Override | ||
public UUID generate(final IdempotentEntity data) { | ||
final var byteBuffer = ByteBuffer.allocate(Long.BYTES); | ||
final var bytes = byteBuffer.putLong(data.hashCode()).array(); | ||
return UUID.nameUUIDFromBytes(bytes); | ||
try { | ||
final var messageDigest = MessageDigest.getInstance(Algorithm.SHA_256.value()); | ||
final var jsonDataBytes = JsonUtils.toJson(data).getBytes(StandardCharsets.UTF_8); | ||
return UUID.nameUUIDFromBytes(messageDigest.digest(jsonDataBytes)); | ||
} catch (final NoSuchAlgorithmException ex) { | ||
throw new IllegalStateException("Algorithm not found", ex); | ||
} | ||
} | ||
|
||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# DATABASE SCHEMA PROPERTIES | ||
schema: | ||
name: master-db | ||
user: sa | ||
pass: sa | ||
|
||
# DATABASE MASTER PROPERTIES | ||
master: | ||
datasource: | ||
host: localhost | ||
url: jdbc:h2:mem:${schema.name};DB_CLOSE_DELAY=-1 | ||
username: ${schema.user} | ||
password: ${schema.pass} | ||
|
||
# DATABASE REPLICA PROPERTIES | ||
replica: | ||
datasource: | ||
host: localhost | ||
url: jdbc:h2:mem:${schema.name};DB_CLOSE_DELAY=-1 | ||
username: ${schema.user} | ||
password: ${schema.pass} |