/** * Create the correct type according to the row. * * @param rs The row representing the entity. * @return The instance of the correct type as represented by the row. */ private VdsNetworkInterface createInterface(ResultSet rs) throws SQLException { Integer vlanId = (Integer) rs.getObject("vlan_id"); Boolean isBond = (Boolean) rs.getObject("is_bond"); if (Boolean.TRUE.equals(isBond)) { Bond bond = new Bond(); bond.setBonded(isBond); bond.setBondOptions(rs.getString("bond_opts")); bond.setBondType((Integer) rs.getObject("bond_type")); bond.setActiveSlave(rs.getString("bond_active_slave")); return bond; } if (vlanId != null) { Vlan vlan = new Vlan(); vlan.setVlanId(vlanId); vlan.setBaseInterface(rs.getString("base_interface")); vlan.setBonded(isBond); return vlan; } Nic nic = new Nic(); nic.setBondName(rs.getString("bond_name")); nic.setBonded(isBond); return nic; } };
public Bond toBond() { Bond bond = new Bond(); bond.setId(getId()); bond.setName(getName()); bond.setSlaves(new ArrayList<>(getSlaves())); bond.setBondOptions(getBondOptions()); return bond; }
@Mapping(from = HostNic.class, to = Bond.class) public static Bond map(HostNic model, Bond template) { Bond entity = template == null ? new Bond() : template; if (model.isSetId()) { entity.setId(GuidUtils.asGuid(model.getId())); } if (model.isSetName()) { entity.setName(model.getName()); } if (model.isSetBonding()) { entity.setBonded(true); if (model.getBonding().isSetSlaves()) { entity.getSlaves().clear(); for (HostNic slave : model.getBonding().getSlaves().getHostNics()) { if (slave.isSetName()) { entity.getSlaves().add(slave.getName()); } } } if (model.getBonding().isSetOptions()) { entity.setBondOptions(calculateBondingOptionsString(model)); } } if (model.isSetQos()) { entity.setQos((HostNetworkQos) QosMapper.map(model.getQos(), null)); } return entity; }
entity = template; } else if (model.isSetBonding()) { entity = new Bond(); } else if (model.isSetVlan()) { entity = new Vlan();