1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.maxur.perfmodel.backend;
17
18 import org.glassfish.hk2.api.Factory;
19 import org.glassfish.hk2.api.ServiceLocator;
20 import org.maxur.perfmodel.backend.infrastructure.DataSourceLevelDbImpl;
21
22 import javax.inject.Inject;
23
24
25
26
27
28
29 public class DataSourceProvider implements Factory<DataSourceLevelDbImpl> {
30
31 private static DataSourceLevelDbImpl ds;
32
33 @Inject
34 private ServiceLocator locator;
35
36 @Override
37 public DataSourceLevelDbImpl provide() {
38 if (ds == null) {
39 ds = new DataSourceLevelDbImpl();
40 locator.inject(ds);
41 ds.init();
42 }
43 return ds;
44 }
45
46 @Override
47 public void dispose(final DataSourceLevelDbImpl instance) {
48 instance.stop();
49 }
50 }