[FIX] Hibernate reload fix

This commit is contained in:
Gravit 2020-03-31 10:59:50 +07:00
parent 56e1920a8d
commit 44f3a17973
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 17 additions and 6 deletions

View file

@ -98,7 +98,6 @@ public void reload(ReloadType type) throws Exception {
LogHelper.debug("Init components");
config.components.forEach((k, v) -> {
LogHelper.subDebug("Init component %s", k);
registerObject("component.".concat(k), v);
v.init(this);
});
LogHelper.debug("Init components successful");

View file

@ -152,6 +152,7 @@ public void close(LaunchServer.ReloadType type) {
server.unregisterObject("auth.".concat(pair.name).concat(".provider"), pair.provider);
server.unregisterObject("auth.".concat(pair.name).concat(".handler"), pair.handler);
server.unregisterObject("auth.".concat(pair.name).concat(".texture"), pair.textureProvider);
pair.close();
}
}
if (type.equals(LaunchServer.ReloadType.FULL)) {
@ -169,10 +170,16 @@ public void close(LaunchServer.ReloadType type) {
} catch (Exception e) {
LogHelper.error(e);
}
try {
for (AuthProviderPair p : auth.values()) p.close();
} catch (IOException e) {
LogHelper.error(e);
if(dao != null) {
server.unregisterObject("dao", dao);
if(dao instanceof AutoCloseable)
{
try {
((AutoCloseable) dao).close();
} catch (Exception e) {
LogHelper.error(e);
}
}
}
}

View file

@ -17,7 +17,7 @@
import java.util.HashMap;
import java.util.Map;
public class HibernateDaoProvider extends DaoProvider implements Reconfigurable {
public class HibernateDaoProvider extends DaoProvider implements Reconfigurable, AutoCloseable {
public String driver;
public String url;
public String username;
@ -113,4 +113,9 @@ public void invoke(String... args) throws Exception {
});
return commands;
}
@Override
public void close() throws Exception {
sessionFactory.close();
}
}