OK, here is my code formatted. There is one-to-one relation between the HostConfiguration and InterfaceConfiguration. Please let me know what is the correct way to dissociate one InterfaceConfiguration and add a new InterfaceConfiguratuon to the HostConfiguration ?
Appreciate your response!
Code:
public class SystemDaoImpl {
// code omiited
@Override
public void setHostConfig(HostConfiguration hostConf) {
HostConfiguration hc = em.find(HostConfiguration.class,
hostConf.getHostname());
if (hc != null) {
InterfaceConfiguration trusted = hc.getTrustedInterface();
InterfaceConfiguration untrusted = hc.getUntrustedInterface();
if (!hostConf.equals(hc)
|| !trusted.equals(hostConf.getTrustedInterface())
|| !untrusted.equals(hostConf.getUntrustedInterface())) {
log.info("removing the existing hostconf");
em.remove(hc);
InterfaceConfiguration.IfConfigPKey tpkey = new InterfaceConfiguration.IfConfigPKey();
tpkey.setType(Type.TRUSTED);
tpkey.setIpAddress(trusted.getIpAddress());
InterfaceConfiguration trusted1 = em.find(
InterfaceConfiguration.class, tpkey);
if (trusted1 != null) {
em.remove(trusted1);
}
InterfaceConfiguration.IfConfigPKey upkey = new InterfaceConfiguration.IfConfigPKey();
tpkey.setType(Type.UNTRUSTED);
tpkey.setIpAddress(untrusted.getIpAddress());
InterfaceConfiguration untrusted1 = em.find(
InterfaceConfiguration.class, upkey);
if (untrusted1 != null) {
em.remove(untrusted1);
}
log.info("now adding the new hostconf: " + hostConf);
em.merge(hostConf);
} else {
log.info("hostConf and existing hostConf are equal");
}
}
}
}