-
Notifications
You must be signed in to change notification settings - Fork 1
/
PersistenceLifecycle.java
39 lines (34 loc) · 1.16 KB
/
PersistenceLifecycle.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
import com.google.inject.persist.PersistService;
import play.inject.ApplicationLifecycle;
import javax.inject.Inject;
/**
* Starts persistence support and registers shutdown hook to stop it.
* Both points are correct lifecycle points according to play docs (normal lifecycle binding is deprecated).
*
* @author Vyacheslav Rusakov
* @since 17.06.2016
*/
public class PersistenceLifecycle {
@Inject
public PersistenceLifecycle(final PersistService persist,
final ApplicationLifecycle shutdown) {
preloadOrientEngine();
persist.start();
shutdown.addStopHook(() -> {
persist.stop();
return null;
});
}
/**
* Pre-loads OrientDB using empty (system) TCCL so javax.script engines can be found.
*/
private static void preloadOrientEngine() {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(null);
com.orientechnologies.orient.core.Orient.instance();
} finally {
Thread.currentThread().setContextClassLoader(tccl);
}
}
}