[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 final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
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 final class LaunchServerConfig {
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 final class LaunchServerConfig {
} 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.nio.file.Paths;
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 class HibernateDaoProvider extends DaoProvider implements Reconfigurable
});
return commands;
}
@Override
public void close() throws Exception {
sessionFactory.close();
}
}