Moti Asayag has uploaded a new change for review. Change subject: engine: Refactor InterfaceDaoDbFacadeImpl ......................................................................
engine: Refactor InterfaceDaoDbFacadeImpl Reduced amount of duplicated code, cleared eclipse warnings and mostly shortening this class. There is still way to go: changing this class to inherit from DefaultGenericDaoDbFacade. Change-Id: I4a46cf2ea27c163ab5ed4fd7c03be37314d9e354 Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java 1 file changed, 37 insertions(+), 87 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/36/22636/1 diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java index d679843..65703af 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java @@ -25,14 +25,7 @@ @Override public void saveStatisticsForVds(VdsNetworkStatistics stats) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("id", stats.getId()) - .addValue("rx_drop", stats.getReceiveDropRate()) - .addValue("rx_rate", stats.getReceiveRate()) - .addValue("tx_drop", stats.getTransmitDropRate()) - .addValue("tx_rate", stats.getTransmitRate()) - .addValue("iface_status", stats.getStatus()) - .addValue("vds_id", stats.getVdsId()); + MapSqlParameterSource parameterSource = createStatisticsParametersMapper(stats); getCallsHandler().executeModification("Insertvds_interface_statistics", parameterSource); } @@ -40,27 +33,8 @@ public void massUpdateInterfacesForVds(List<VdsNetworkInterface> dbIfacesToBatch) { updateAllInBatch("Updatevds_interface", dbIfacesToBatch, new MapSqlParameterMapper<VdsNetworkInterface>() { @Override - public MapSqlParameterSource map(VdsNetworkInterface entity) { - MapSqlParameterSource paramValue = new MapSqlParameterSource().addValue("addr", entity.getAddress()) - .addValue("bond_name", entity.getBondName()) - .addValue("bond_type", entity.getBondType()) - .addValue("gateway", entity.getGateway()) - .addValue("id", entity.getId()) - .addValue("is_bond", entity.getBonded()) - .addValue("bond_opts", entity.getBondOptions()) - .addValue("mac_addr", entity.getMacAddress()) - .addValue("name", entity.getName()) - .addValue("network_name", entity.getNetworkName()) - .addValue("speed", entity.getSpeed()) - .addValue("subnet", entity.getSubnet()) - .addValue("boot_protocol", entity.getBootProtocol()) - .addValue("type", entity.getType()) - .addValue("vds_id", entity.getVdsId()) - .addValue("vlan_id", entity.getVlanId()) - .addValue("mtu", entity.getMtu()) - .addValue("bridged", entity.isBridged()) - .addValue("labels", SerializationFactory.getSerializer().serialize(entity.getLabels())); - return paramValue; + public MapSqlParameterSource map(VdsNetworkInterface nic) { + return createInterfaceParametersMapper(nic); } }); } @@ -68,32 +42,12 @@ public void updateAllInBatch(String procedureName, Collection<VdsNetworkInterface> paramValues, MapSqlParameterMapper<VdsNetworkInterface> mapper) { - getCallsHandler().executeStoredProcAsBatch(procedureName, - paramValues, mapper); + getCallsHandler().executeStoredProcAsBatch(procedureName, paramValues, mapper); } @Override public void saveInterfaceForVds(VdsNetworkInterface stats) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("addr", stats.getAddress()) - .addValue("bond_name", stats.getBondName()) - .addValue("bond_type", stats.getBondType()) - .addValue("gateway", stats.getGateway()) - .addValue("id", stats.getId()) - .addValue("is_bond", stats.getBonded()) - .addValue("bond_opts", stats.getBondOptions()) - .addValue("mac_addr", stats.getMacAddress()) - .addValue("name", stats.getName()) - .addValue("network_name", stats.getNetworkName()) - .addValue("speed", stats.getSpeed()) - .addValue("subnet", stats.getSubnet()) - .addValue("boot_protocol", stats.getBootProtocol()) - .addValue("type", stats.getType()) - .addValue("vds_id", stats.getVdsId()) - .addValue("vlan_id", stats.getVlanId()) - .addValue("mtu", stats.getMtu()) - .addValue("bridged", stats.isBridged()) - .addValue("labels", SerializationFactory.getSerializer().serialize(stats.getLabels())); + MapSqlParameterSource parameterSource = createInterfaceParametersMapper(stats); getCallsHandler().executeModification("Insertvds_interface", parameterSource); } @@ -107,17 +61,10 @@ public void massUpdateStatisticsForVds(Collection<VdsNetworkStatistics> statistics) { List<MapSqlParameterSource> executions = new ArrayList<>(statistics.size()); for (VdsNetworkStatistics stats : statistics) { - executions.add(getCustomMapSqlParameterSource() - .addValue("id", stats.getId()) - .addValue("rx_drop", stats.getReceiveDropRate()) - .addValue("rx_rate", stats.getReceiveRate()) - .addValue("tx_drop", stats.getTransmitDropRate()) - .addValue("tx_rate", stats.getTransmitRate()) - .addValue("iface_status", stats.getStatus()) - .addValue("vds_id", stats.getVdsId())); + executions.add(createStatisticsParametersMapper(stats)); } - getCallsHandler().executeStoredProcAsBatch("Updatevds_interface_statistics", - executions); + + getCallsHandler().executeStoredProcAsBatch("Updatevds_interface_statistics", executions); } /** @@ -129,7 +76,11 @@ * The host's network statistics data. */ private void update(VdsNetworkStatistics stats) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() + getCallsHandler().executeModification("Updatevds_interface_statistics", createStatisticsParametersMapper(stats)); + } + + private MapSqlParameterSource createStatisticsParametersMapper(VdsNetworkStatistics stats) { + return getCustomMapSqlParameterSource() .addValue("id", stats.getId()) .addValue("rx_drop", stats.getReceiveDropRate()) .addValue("rx_rate", stats.getReceiveRate()) @@ -137,34 +88,34 @@ .addValue("tx_rate", stats.getTransmitRate()) .addValue("iface_status", stats.getStatus()) .addValue("vds_id", stats.getVdsId()); - - getCallsHandler().executeModification("Updatevds_interface_statistics", parameterSource); } @Override - public void updateInterfaceForVds(VdsNetworkInterface stats) { - MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("addr", stats.getAddress()) - .addValue("bond_name", stats.getBondName()) - .addValue("bond_type", stats.getBondType()) - .addValue("gateway", stats.getGateway()) - .addValue("id", stats.getId()) - .addValue("is_bond", stats.getBonded()) - .addValue("bond_opts", stats.getBondOptions()) - .addValue("mac_addr", stats.getMacAddress()) - .addValue("name", stats.getName()) - .addValue("network_name", stats.getNetworkName()) - .addValue("speed", stats.getSpeed()) - .addValue("subnet", stats.getSubnet()) - .addValue("boot_protocol", stats.getBootProtocol()) - .addValue("type", stats.getType()) - .addValue("vds_id", stats.getVdsId()) - .addValue("vlan_id", stats.getVlanId()) - .addValue("mtu", stats.getMtu()) - .addValue("bridged", stats.isBridged()) - .addValue("labels", SerializationFactory.getSerializer().serialize(stats.getLabels())); + public void updateInterfaceForVds(VdsNetworkInterface nic) { + getCallsHandler().executeModification("Updatevds_interface", createInterfaceParametersMapper(nic)); + } - getCallsHandler().executeModification("Updatevds_interface", parameterSource); + private MapSqlParameterSource createInterfaceParametersMapper(VdsNetworkInterface nic) { + return getCustomMapSqlParameterSource() + .addValue("addr", nic.getAddress()) + .addValue("bond_name", nic.getBondName()) + .addValue("bond_type", nic.getBondType()) + .addValue("gateway", nic.getGateway()) + .addValue("id", nic.getId()) + .addValue("is_bond", nic.getBonded()) + .addValue("bond_opts", nic.getBondOptions()) + .addValue("mac_addr", nic.getMacAddress()) + .addValue("name", nic.getName()) + .addValue("network_name", nic.getNetworkName()) + .addValue("speed", nic.getSpeed()) + .addValue("subnet", nic.getSubnet()) + .addValue("boot_protocol", nic.getBootProtocol()) + .addValue("type", nic.getType()) + .addValue("vds_id", nic.getVdsId()) + .addValue("vlan_id", nic.getVlanId()) + .addValue("mtu", nic.getMtu()) + .addValue("bridged", nic.isBridged()) + .addValue("labels", SerializationFactory.getSerializer().serialize(nic.getLabels())); } @Override @@ -181,7 +132,6 @@ vdsNetworkInterfaceRowMapper, parameterSource); } - @SuppressWarnings("unchecked") @Override public List<VdsNetworkInterface> getAllInterfacesForVds(Guid id, Guid userID, boolean isFiltered) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() -- To view, visit http://gerrit.ovirt.org/22636 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4a46cf2ea27c163ab5ed4fd7c03be37314d9e354 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches