ScriptsLab
WikiDownloadsSourcesSupport
ScriptsLab
DocumentationDownloadsGitHubDiscord

© 2026 ScriptsLab

Back to src/main/java/com/scriptslab/api/storage
J

StorageProvider.java

Java · 108 lines · 2.4 KB

src/main/java/com/scriptslab/api/storage/StorageProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.scriptslab.api.storage;

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

/**
 * Abstract storage provider interface.
 * Implementations must be thread-safe.
 */
public interface StorageProvider {
    
    /**
     * Gets the provider name.
     * 
     * @return provider name (e.g., "yaml", "json", "sqlite")
     */
    String getName();
    
    /**
     * Initializes the storage provider.
     * 
     * @return future that completes when initialized
     */
    CompletableFuture<Void> initialize();
    
    /**
     * Shuts down the storage provider.
     * 
     * @return future that completes when shut down
     */
    CompletableFuture<Void> shutdown();
    
    /**
     * Saves a value.
     * 
     * @param key storage key
     * @param value value to save
     * @return future that completes when saved
     */
    CompletableFuture<Void> save(String key, Object value);
    
    /**
     * Saves multiple values in a batch.
     * 
     * @param data map of key-value pairs
     * @return future that completes when saved
     */
    CompletableFuture<Void> saveBatch(Map<String, Object> data);
    
    /**
     * Loads a value.
     * 
     * @param key storage key
     * @param type expected type
     * @param <T> type parameter
     * @return future with optional containing value if found
     */
    <T> CompletableFuture<Optional<T>> load(String key, Class<T> type);
    
    /**
     * Loads multiple values.
     * 
     * @param keys keys to load
     * @return future with map of found values
     */
    CompletableFuture<Map<String, Object>> loadBatch(Set<String> keys);
    
    /**
     * Deletes a value.
     * 
     * @param key storage key
     * @return future that completes when deleted
     */
    CompletableFuture<Void> delete(String key);
    
    /**
     * Checks if a key exists.
     * 
     * @param key storage key
     * @return future with true if exists
     */
    CompletableFuture<Boolean> exists(String key);
    
    /**
     * Gets all keys.
     * 
     * @return future with set of all keys
     */
    CompletableFuture<Set<String>> getAllKeys();
    
    /**
     * Clears all data.
     * Use with caution!
     * 
     * @return future that completes when cleared
     */
    CompletableFuture<Void> clear();
    
    /**
     * Checks if the provider is initialized.
     * 
     * @return true if initialized
     */
    boolean isInitialized();
}