This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
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
1 parent
9047cfb
commit f521ae5
Showing
21 changed files
with
765 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
5 changes: 5 additions & 0 deletions
5
api/src/main/java/fr/atlasworld/network/api/services/Service.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,5 @@ | ||
package fr.atlasworld.network.api.services; | ||
|
||
public interface Service { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
api/src/main/java/fr/atlasworld/network/api/services/ServiceManager.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,24 @@ | ||
package fr.atlasworld.network.api.services; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Register and work with services. | ||
*/ | ||
public interface ServiceManager { | ||
|
||
/** | ||
* Register a service implementation to the service manager. | ||
* @param serviceClass parent service class. | ||
* @param serviceImpl implementation of the service class. | ||
*/ | ||
<T extends Service> void registerService(Class<T> serviceClass, T serviceImpl); | ||
|
||
/** | ||
* Get a service from the service manager. | ||
* @param serviceClass parent service class. | ||
* @return return the registered service, null if no service we're registered with this class. | ||
*/ | ||
@Nullable | ||
<T extends Service> T getService(Class<T> serviceClass); | ||
} |
48 changes: 48 additions & 0 deletions
48
api/src/main/java/fr/atlasworld/network/api/services/database/Database.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,48 @@ | ||
package fr.atlasworld.network.api.services.database; | ||
|
||
import com.google.errorprone.annotations.CanIgnoreReturnValue; | ||
import fr.atlasworld.network.api.concurrent.action.FutureAction; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Database, loads, saves & processes data from/to the database. | ||
* This service <strong>must</strong> be thread safe. | ||
*/ | ||
public interface Database<E extends DatabaseEntity> { | ||
|
||
/** | ||
* Saves data to the database. If the value already exists, this should override it. | ||
* @param data data to save. | ||
* @return future action of the saving process. | ||
*/ | ||
@CanIgnoreReturnValue | ||
FutureAction<Void> save(@NotNull E data); | ||
|
||
/** | ||
* Loads data from the database or the cache. | ||
* @param id id to the data. | ||
* @return future action of the loading process. | ||
*/ | ||
FutureAction<Optional<E>> load(@NotNull String id); | ||
|
||
/** | ||
* Deletes data in the database. | ||
* @param id id of the data. | ||
* @return future action of the deletion process. | ||
*/ | ||
FutureAction<Void> delete(@NotNull String id); | ||
|
||
/** | ||
* Loads all entries from the database. | ||
* @return future action of the fetch request. | ||
*/ | ||
FutureAction<Stream<E>> stream(); | ||
|
||
/** | ||
* Clear the local cache, executing this may make the system slower. | ||
*/ | ||
void clearCache(); | ||
} |
14 changes: 14 additions & 0 deletions
14
api/src/main/java/fr/atlasworld/network/api/services/database/DatabaseEntity.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,14 @@ | ||
package fr.atlasworld.network.api.services.database; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* A Database entity is a entity that can be uniquely identified by a unique identifier. | ||
*/ | ||
public interface DatabaseEntity { | ||
|
||
/** | ||
* Get unique instance entity id. | ||
*/ | ||
@NotNull String id(); | ||
} |
24 changes: 24 additions & 0 deletions
24
api/src/main/java/fr/atlasworld/network/api/services/database/DatabaseEntityFactory.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,24 @@ | ||
package fr.atlasworld.network.api.services.database; | ||
|
||
import fr.atlasworld.network.api.services.database.exceptions.DatabaseDataTransformationException; | ||
|
||
/** | ||
* Handles the creation and transformation of data from to the database. | ||
*/ | ||
public interface DatabaseEntityFactory<E extends DatabaseEntity> { | ||
|
||
/** | ||
* Creates a Java Object from the database store. | ||
* @param store store from the database. | ||
* @param id id of the data. | ||
* @return new DatabaseEntity. | ||
*/ | ||
E create(DatabaseStore store, String id) throws DatabaseDataTransformationException; | ||
|
||
/** | ||
* Transforms a Java Object into a database store. | ||
* @param store store that gets modified. | ||
* @param obj source java object. | ||
*/ | ||
void toDatabase(DatabaseStore store, E obj) throws DatabaseDataTransformationException; | ||
} |
40 changes: 40 additions & 0 deletions
40
api/src/main/java/fr/atlasworld/network/api/services/database/DatabaseService.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,40 @@ | ||
package fr.atlasworld.network.api.services.database; | ||
|
||
import fr.atlasworld.network.api.services.Service; | ||
import fr.atlasworld.network.api.services.database.exceptions.DatabaseException; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.reflect.Type; | ||
|
||
/** | ||
* Database service, handles the connection and handling of the database. | ||
*/ | ||
public interface DatabaseService extends Service { | ||
|
||
/** | ||
* Connect to the database. | ||
* @throws DatabaseException if connection could not succeed. | ||
*/ | ||
void connect() throws DatabaseException; | ||
|
||
/** | ||
* Close connection with the database. | ||
* @throws DatabaseException if the connection could not be closed, | ||
* if it fails closing the connect properly it will just be skipped. | ||
*/ | ||
void close() throws DatabaseException; | ||
|
||
/** | ||
* Checks if the connections with the database is closed. | ||
* @return true if the connection has been closed. | ||
*/ | ||
boolean closed(); | ||
|
||
/** | ||
* Get a database from the service. | ||
* @param name database name. | ||
* @param type data to DTO from the database. | ||
* @return the specified database. | ||
*/ | ||
<E extends DatabaseEntity> Database<E> getDatabase(@NotNull String name, @NotNull DatabaseEntityFactory<E> factory) throws DatabaseException; | ||
} |
45 changes: 45 additions & 0 deletions
45
api/src/main/java/fr/atlasworld/network/api/services/database/DatabaseStore.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,45 @@ | ||
package fr.atlasworld.network.api.services.database; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Stores database entity data in a simpler easier way to save, to any format. | ||
*/ | ||
public interface DatabaseStore { | ||
|
||
/** | ||
* Put a key and data to the store, if the key already exists value will be overridden. | ||
* @param key data key. | ||
* @param data data. | ||
*/ | ||
void put(@NotNull String key, @NotNull Object data); | ||
|
||
/** | ||
* Checks if the store has a key. | ||
* @param key key to check for. | ||
*/ | ||
boolean has(@NotNull String key); | ||
|
||
/** | ||
* Get data from a key. | ||
* @param key key of the data. | ||
* @param type object type. | ||
*/ | ||
@Nullable | ||
<T> T get(@NotNull String key, @NotNull Type type); | ||
|
||
/** | ||
* Stream data from the store. | ||
*/ | ||
Stream<Map.Entry<String, Object>> stream(); | ||
|
||
/** | ||
* Get the store as a map. | ||
*/ | ||
Map<String, Object> asMap(); | ||
} |
19 changes: 19 additions & 0 deletions
19
...tlasworld/network/api/services/database/exceptions/DatabaseConnectionClosedException.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,19 @@ | ||
package fr.atlasworld.network.api.services.database.exceptions; | ||
|
||
public class DatabaseConnectionClosedException extends DatabaseException { | ||
public DatabaseConnectionClosedException() { | ||
super(); | ||
} | ||
|
||
public DatabaseConnectionClosedException(String message) { | ||
super(message); | ||
} | ||
|
||
public DatabaseConnectionClosedException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public DatabaseConnectionClosedException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...asworld/network/api/services/database/exceptions/DatabaseDataTransformationException.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,18 @@ | ||
package fr.atlasworld.network.api.services.database.exceptions; | ||
|
||
public class DatabaseDataTransformationException extends DatabaseException { | ||
public DatabaseDataTransformationException() { | ||
} | ||
|
||
public DatabaseDataTransformationException(String message) { | ||
super(message); | ||
} | ||
|
||
public DatabaseDataTransformationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public DatabaseDataTransformationException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...c/main/java/fr/atlasworld/network/api/services/database/exceptions/DatabaseException.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,21 @@ | ||
package fr.atlasworld.network.api.services.database.exceptions; | ||
|
||
import java.io.IOException; | ||
|
||
public class DatabaseException extends IOException { | ||
public DatabaseException() { | ||
super(); | ||
} | ||
|
||
public DatabaseException(String message) { | ||
super(message); | ||
} | ||
|
||
public DatabaseException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public DatabaseException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
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
Oops, something went wrong.