-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelationalOrmExample.java
More file actions
51 lines (42 loc) · 1.46 KB
/
RelationalOrmExample.java
File metadata and controls
51 lines (42 loc) · 1.46 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
import nl.hauntedmc.dataprovider.api.DataProviderAPI;
import nl.hauntedmc.dataprovider.api.orm.ORMContext;
import nl.hauntedmc.dataprovider.database.DatabaseType;
import nl.hauntedmc.dataprovider.database.relational.RelationalDatabaseProvider;
import nl.hauntedmc.dataprovider.logging.LoggerAdapter;
import java.util.Optional;
/**
* Example: MySQL registration + ORMContext creation.
*/
public final class RelationalOrmExample {
private ORMContext ormContext;
public void onEnable(DataProviderAPI api, LoggerAdapter logger) {
Optional<RelationalDatabaseProvider> relational = api.registerDatabaseAs(
DatabaseType.MYSQL,
"example",
RelationalDatabaseProvider.class
);
if (relational.isEmpty()) {
logger.error("Could not initialize MySQL connection 'example'.");
return;
}
ormContext = new ORMContext(
"my-plugin",
relational.get().getDataSource(),
logger,
"validate",
PlayerEntity.class,
PlayerProfileEntity.class
);
}
public void onDisable(DataProviderAPI api) {
if (ormContext != null) {
ormContext.shutdown();
ormContext = null;
}
api.unregisterDatabase(DatabaseType.MYSQL, "example");
}
private static final class PlayerEntity {
}
private static final class PlayerProfileEntity {
}
}