-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDatabaseManager.java
More file actions
169 lines (146 loc) · 4.61 KB
/
DatabaseManager.java
File metadata and controls
169 lines (146 loc) · 4.61 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.yirankuma.yrdatabase.api;
import com.yirankuma.yrdatabase.api.provider.CacheProvider;
import com.yirankuma.yrdatabase.api.provider.PersistProvider;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
/**
* Main database manager interface.
* Provides unified access to cache and persistence layers.
*
* @author YiranKuma
*/
public interface DatabaseManager extends AutoCloseable {
// ==================== Simple Map API ====================
/**
* Smart get: tries cache first, then persistence layer.
*
* @param table Table name
* @param key Primary key
* @return Data map wrapped in Optional
*/
CompletableFuture<Optional<Map<String, Object>>> get(String table, String key);
/**
* Smart get: tries cache first, then persistence layer.
*
* @param table Table name
* @param key Primary key
* @param TTLSeconds Custom TTL time(Seconds)
* @return Data map wrapped in Optional
*/
CompletableFuture<Optional<Map<String, Object>>> get(String table, String key, int TTLSeconds);
/**
* Smart set: writes to cache with optional delayed persistence.
*
* @param table Table name
* @param key Primary key
* @param data Data to store
* @return Success status
*/
CompletableFuture<Boolean> set(String table, String key, Map<String, Object> data);
/**
* Smart set with cache strategy.
*
* @param table Table name
* @param key Primary key
* @param data Data to store
* @param strategy Cache strategy
* @return Success status
*/
CompletableFuture<Boolean> set(String table, String key, Map<String, Object> data, CacheStrategy strategy);
/**
* Smart set with cache strategy.
*
* @param table Table name
* @param key Primary key
* @param data Data to store
* @param strategy Cache strategy
* @param TTLSeconds Custom TTL time(Seconds)
* @return Success status
*/
CompletableFuture<Boolean> set(String table, String key, Map<String, Object> data, CacheStrategy strategy, int TTLSeconds);
/**
* Persist data from cache to persistence layer and clear cache.
*
* @param table Table name
* @param key Primary key
* @return Success status
*/
CompletableFuture<Boolean> persistAndClear(String table, String key);
/**
* Delete data from both cache and persistence layer.
*
* @param table Table name
* @param key Primary key
* @return Success status
*/
CompletableFuture<Boolean> delete(String table, String key);
/**
* Check if data exists (in cache or persistence layer).
*
* @param table Table name
* @param key Primary key
* @return Existence status
*/
CompletableFuture<Boolean> exists(String table, String key);
/**
* Ensure table exists with the given schema.
*
* @param table Table name
* @param schema Column definitions (name -> SQL type)
* @return Success status
*/
CompletableFuture<Boolean> ensureTable(String table, Map<String, String> schema);
// ==================== Type-safe Repository API ====================
/**
* Get a type-safe repository for entity operations.
*
* @param entityClass Entity class annotated with @Table
* @param <T> Entity type
* @return Repository instance
*/
<T> Repository<T> getRepository(Class<T> entityClass);
// ==================== Direct Provider Access ====================
/**
* Get the cache provider (Redis).
*
* @return Cache provider if available
*/
Optional<CacheProvider> getCacheProvider();
/**
* Get the persistence provider (MySQL/SQLite).
*
* @return Persistence provider if available
*/
Optional<PersistProvider> getPersistProvider();
// ==================== Status ====================
/**
* Initialize the database connections.
*
* @return Future completing with success status
*/
CompletableFuture<Boolean> initialize();
/**
* Flush all pending writes to persistence layer.
*
* @return Future completing when flush is done
*/
CompletableFuture<Void> flush();
/**
* Check if any storage backend is connected.
*
* @return Connection status
*/
boolean isConnected();
/**
* Get detailed database status.
*
* @return Status information
*/
DatabaseStatus getStatus();
/**
* Shutdown and cleanup resources.
*/
@Override
void close();
}