Package de.oliver.jdb
Class JDB
java.lang.Object
de.oliver.jdb.JDB
The JDB class provides a simple JSON document-based storage system in a specified directory.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDeletes the document(s) at the specified path.<T> TRetrieves a document from the specified path, deserializing it into the given class type.<T> List<T>Retrieves all documents from the specified directory path, deserializing them into the given class type.getDocument(@NotNull String path) Retrieves a document from the specified path.<T> voidSaves the given value as a document at the specified path.
-
Constructor Details
-
JDB
Constructs a new JDB instance with the specified base path.- Parameters:
basePath- the base directory path where documents will be stored
-
-
Method Details
-
get
public <T> T get(@NotNull @NotNull String path, @NotNull @NotNull Class<T> clazz) throws IOException Retrieves a document from the specified path, deserializing it into the given class type.- Type Parameters:
T- the type of the object to be returned- Parameters:
path- the relative path (excluding .json extension) where the document is locatedclazz- the class type to which the document should be deserialized- Returns:
- a JDocument containing the deserialized object and its path, or null if the file does not exist
- Throws:
IOException- if an I/O error occurs during file reading
-
getDocument
Retrieves a document from the specified path.- Parameters:
path- the relative path (excluding .json extension) where the document is located- Returns:
- a JDocument containing the deserialized data or null if the file does not exist
- Throws:
IOException- if an I/O error occurs during file reading
-
getAll
public <T> List<T> getAll(@NotNull @NotNull String path, @NotNull @NotNull Class<T> clazz) throws IOException Retrieves all documents from the specified directory path, deserializing them into the given class type.- Type Parameters:
T- the type of objects to be returned- Parameters:
path- the relative directory path containing the documentsclazz- the class type to which the documents should be deserialized- Returns:
- a List of JDocument objects containing the deserialized objects and their paths, or null if the directory or files do not exist
- Throws:
IOException- if an I/O error occurs during file reading
-
set
Saves the given value as a document at the specified path.- Type Parameters:
T- the type of the object to be saved- Parameters:
path- the relative path (excluding .json extension) where the document will be savedvalue- the object to be saved as a JSON document- Throws:
IOException- if an I/O error occurs during file writing
-
delete
Deletes the document(s) at the specified path.- Parameters:
path- the relative path (excluding .json extension) of the document(s) to be deleted
-