-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#112] refactor(core): improve the
EntityStore
interface to add mor…
…e methods (#115) ### What changes were proposed in this pull request? This PR refactors the `EntityStore` to add more interfaces, so that other implementations could leverage this to achieve the specific logics. ### Why are the changes needed? Current EntityStore only has two methods related to store and retrieve, which is not enough to satisfy all the needs for entity storage. So here improved to add more methods. Fix: #112 ### Does this PR introduce _any_ user-facing change? Yes, this change refactors the current `EntityStore` interface to add more methods. ### How was this patch tested? Extends the current UT.
- Loading branch information
Showing
7 changed files
with
228 additions
and
40 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
15 changes: 15 additions & 0 deletions
15
core/src/main/java/com/datastrato/graviton/EntityAlreadyExistsException.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,15 @@ | ||
/* | ||
* Copyright 2023 Datastrato. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.graviton; | ||
|
||
public class EntityAlreadyExistsException extends RuntimeException { | ||
public EntityAlreadyExistsException(String message) { | ||
super(message); | ||
} | ||
|
||
public EntityAlreadyExistsException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
core/src/main/java/com/datastrato/graviton/EntityNotEmptyException.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
35 changes: 35 additions & 0 deletions
35
core/src/main/java/com/datastrato/graviton/EntityStoreFactory.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,35 @@ | ||
/* | ||
* Copyright 2023 Datastrato. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.graviton; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class EntityStoreFactory { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(EntityStore.class); | ||
|
||
// Register EntityStore's short name to its full qualified class name in the map. So that user | ||
// don't need to specify the full qualified class name when creating an EntityStore. | ||
private static final Map<String, String> ENTITY_STORES = ImmutableMap.of(); | ||
|
||
private EntityStoreFactory() {} | ||
|
||
public static EntityStore createEntityStore(Config config) { | ||
String name = config.get(configs.ENTITY_STORE); | ||
String className = ENTITY_STORES.getOrDefault(name, name); | ||
|
||
try { | ||
EntityStore store = (EntityStore) Class.forName(className).newInstance(); | ||
store.initialize(config); | ||
return store; | ||
} catch (Exception e) { | ||
LOG.error("Failed to create and initialize EntityStore by name {}.", name, e); | ||
throw new RuntimeException("Failed to create and initialize EntityStore: " + name, e); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
core/src/main/java/com/datastrato/graviton/util/Executable.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,13 @@ | ||
/* | ||
* Copyright 2023 Datastrato. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.graviton.util; | ||
|
||
import java.io.IOException; | ||
|
||
@FunctionalInterface | ||
public interface Executable<R> { | ||
|
||
R execute() throws IOException; | ||
} |
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