MCPcopy Create free account
hub / github.com/e2wugui/zeze / Database

Class Database

ZezeJava/ZezeJava/src/main/java/Zeze/Transaction/Database.java:29–737  ·  view source on GitHub ↗

数据访问的效率主要来自TableCache的命中。根据以往的经验,命中率是很高的。 所以数据库层就不要求很高的效率。马马虎虎就可以了。

Source from the content-addressed store, hash-verified

27 * 所以数据库层就不要求很高的效率。马马虎虎就可以了。
28 */
29public abstract class Database extends ReentrantLock {
30 protected static final @NotNull Logger logger = LogManager.getLogger(Database.class);
31
32 // 当数据库对Key长度有限制时,使用这个常量。这个数字来自 PolarDb-X。其中MySql 8是3072.
33 // 以后需要升级时,修改这个常量。但是对于已经存在的表,需要自己完成Alter。
34 public static final int eMaxKeyLength = 3070;
35
36 static {
37 ShutdownHook.init();
38 }
39
40 private final ConcurrentHashMap<String, Zeze.Transaction.Table> tables = new ConcurrentHashMap<>();
41 private final ArrayList<Storage<?, ?>> storages = new ArrayList<>();
42 private final @NotNull DatabaseConf conf;
43 private final @NotNull String databaseUrl;
44 private Operates directOperates;
45 private final Application zeze;
46
47 public Database(@Nullable Application zeze, @NotNull DatabaseConf conf) {
48 this.zeze = zeze;
49 this.conf = conf;
50 databaseUrl = conf.getDatabaseUrl();
51 }
52
53 public void __add_storage__(@Nullable Storage<?, ?> storage) {
54 if (storage != null)
55 storages.add(storage);
56 }
57
58 void replaceStorage(@Nullable Storage<?, ?> exist, @Nullable Storage<?, ?> replace) {
59 if (replace == null) {
60 for (var i = 0; i < storages.size(); ++i) {
61 if (storages.get(i) == exist) {
62 storages.remove(i);
63 break;
64 }
65 }
66 } else {
67 for (var i = 0; i < storages.size(); ++i) {
68 if (storages.get(i) == exist) {
69 storages.set(i, replace);
70 break;
71 }
72 }
73 }
74 }
75
76 public @NotNull Application getZeze() {
77 return zeze;
78 }
79
80 public final @NotNull Collection<Zeze.Transaction.Table> getTables() {
81 return tables.values();
82 }
83
84 public final @Nullable Zeze.Transaction.Table getTable(@NotNull String name) {
85 return tables.get(name);
86 }

Callers

nothing calls this directly

Calls 1

initMethod · 0.95

Tested by

no test coverage detected