Liran Zelkha has uploaded a new change for review. Change subject: Fixing SimpleJdbcCallsHandler formatting. Adding usage example in InterfaceDaoDbFacadeImpl ......................................................................
Fixing SimpleJdbcCallsHandler formatting. Adding usage example in InterfaceDaoDbFacadeImpl Change-Id: I631db03381de74672b0804f2673dff49020caaf5 Signed-off-by: [email protected] <[email protected]> --- M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/StoredProcedureMetaData.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/InterfaceDaoDbFacadeImpl.java 3 files changed, 71 insertions(+), 35 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/40/15340/1 diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java index 97a64d4..e957a5f 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java @@ -28,11 +28,12 @@ private ConcurrentMap<String, SimpleJdbcCall> callsMap = new ConcurrentHashMap<String, SimpleJdbcCall>(); - private ConcurrentMap<String, StoredProcedureMetaData> storedProceduresMap = new ConcurrentHashMap<String, StoredProcedureMetaData>(); - private DbEngineDialect dialect; private JdbcTemplate template; + + private ConcurrentMap<String, StoredProcedureMetaData> storedProceduresMap = + new ConcurrentHashMap<String, StoredProcedureMetaData>(); public void setDbEngineDialect(DbEngineDialect dialect) { this.dialect = dialect; @@ -47,8 +48,7 @@ } /** - * Runs a set of stored procedure calls in a batch. Only useful for update - * procedures that return no value + * Runs a set of stored procedure calls in a batch. Only useful for update procedures that return no value * @param procedureName * The procedure name * @param executions diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/StoredProcedureMetaData.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/StoredProcedureMetaData.java index 1545f51..99db22a 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/StoredProcedureMetaData.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/StoredProcedureMetaData.java @@ -2,7 +2,6 @@ import java.util.Map; - public class StoredProcedureMetaData { private String schemaName; private String dbName; 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 63c2fd3..925e846 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 @@ -2,6 +2,7 @@ import java.sql.ResultSet; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -15,10 +16,15 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.NGuid; import org.ovirt.engine.core.dao.BaseDAODbFacade; +import org.ovirt.engine.core.utils.log.Log; +import org.ovirt.engine.core.utils.log.LogFactory; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -public class InterfaceDaoDbFacadeImpl extends BaseDAODbFacade implements InterfaceDao { +public class InterfaceDaoDbFacadeImpl extends BaseDAODbFacade implements + InterfaceDao { + private static final Log log = LogFactory + .getLog(InterfaceDaoDbFacadeImpl.class); @Override public void saveStatisticsForVds(VdsNetworkStatistics stats) { @@ -30,7 +36,8 @@ .addValue("tx_rate", stats.getTransmitRate()) .addValue("iface_status", stats.getStatus()) .addValue("vds_id", stats.getVdsId()); - getCallsHandler().executeModification("Insertvds_interface_statistics", parameterSource); + getCallsHandler().executeModification("Insertvds_interface_statistics", + parameterSource); } @Override @@ -55,7 +62,8 @@ .addValue("mtu", stats.getMtu()) .addValue("bridged", stats.isBridged()); - getCallsHandler().executeModification("Insertvds_interface", parameterSource); + getCallsHandler().executeModification("Insertvds_interface", + parameterSource); } @Override @@ -64,15 +72,29 @@ } @Override - public void massUpdateStatisticsForVds(Collection<VdsNetworkStatistics> statistics) { - for (VdsNetworkStatistics stats : statistics) { - update(stats); + public void massUpdateStatisticsForVds( + Collection<VdsNetworkStatistics> statistics) { + try { + List<MapSqlParameterSource> executions = new ArrayList<MapSqlParameterSource>(); + 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())); + } + getCallsHandler().executeStoredProcAsBatch("Updatevds_interface_statistics", + executions); + } catch (Exception e) { + log.error("Can't update Vds Statistics", e); } } /** * Update the {@link VdsNetworkStatistics} in the DB using the given {@link SimpleJdbcCall}. - * * @param callToUpdate * The call to use. * @param statistics @@ -88,7 +110,8 @@ .addValue("iface_status", stats.getStatus()) .addValue("vds_id", stats.getVdsId()); - getCallsHandler().executeModification("Updatevds_interface_statistics", parameterSource); + getCallsHandler().executeModification("Updatevds_interface_statistics", + parameterSource); } @Override @@ -113,7 +136,8 @@ .addValue("mtu", stats.getMtu()) .addValue("bridged", stats.isBridged()); - getCallsHandler().executeModification("Updatevds_interface", parameterSource); + getCallsHandler().executeModification("Updatevds_interface", + parameterSource); } @Override @@ -122,7 +146,8 @@ } @Override - public List<VdsNetworkInterface> getAllInterfacesWithIpAddress(Guid clusterId, String ipAddress) { + public List<VdsNetworkInterface> getAllInterfacesWithIpAddress( + Guid clusterId, String ipAddress) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("addr", ipAddress).addValue("cluster_id", clusterId); @@ -132,23 +157,25 @@ @SuppressWarnings("unchecked") @Override - public List<VdsNetworkInterface> getAllInterfacesForVds(Guid id, Guid userID, boolean isFiltered) { + public List<VdsNetworkInterface> getAllInterfacesForVds(Guid id, + Guid userID, boolean isFiltered) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_id", id).addValue("user_id", userID).addValue("is_filtered", isFiltered); + .addValue("vds_id", id).addValue("user_id", userID) + .addValue("is_filtered", isFiltered); return getCallsHandler().executeReadList("Getinterface_viewByvds_id", - vdsNetworkInterfaceRowMapper, - parameterSource); + vdsNetworkInterfaceRowMapper, parameterSource); } @Override - public VdsNetworkInterface getManagedInterfaceForVds(Guid id, Guid userID, boolean isFiltered) { + public VdsNetworkInterface getManagedInterfaceForVds(Guid id, Guid userID, + boolean isFiltered) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() - .addValue("vds_id", id).addValue("user_id", userID).addValue("is_filtered", isFiltered); + .addValue("vds_id", id).addValue("user_id", userID) + .addValue("is_filtered", isFiltered); return getCallsHandler().executeRead("GetVdsManagedInterfaceByVdsId", - vdsNetworkInterfaceRowMapper, - parameterSource); + vdsNetworkInterfaceRowMapper, parameterSource); } @Override @@ -156,7 +183,8 @@ MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("id", id); - getCallsHandler().executeModification("Deletevds_interface_statistics", parameterSource); + getCallsHandler().executeModification("Deletevds_interface_statistics", + parameterSource); } @Override @@ -164,21 +192,26 @@ MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource() .addValue("id", id); - getCallsHandler().executeModification("Deletevds_interface", parameterSource); + getCallsHandler().executeModification("Deletevds_interface", + parameterSource); } @Override public List<VdsNetworkInterface> getVdsInterfacesByNetworkId(Guid networkId) { - return getCallsHandler().executeReadList("GetVdsInterfacesByNetworkId", + return getCallsHandler().executeReadList( + "GetVdsInterfacesByNetworkId", vdsNetworkInterfaceRowMapper, - getCustomMapSqlParameterSource().addValue("network_id", networkId)); + getCustomMapSqlParameterSource().addValue("network_id", + networkId)); } @Override public VdsNetworkInterface get(Guid id) { - return getCallsHandler().executeRead("GetVdsInterfaceById", + return getCallsHandler().executeRead( + "GetVdsInterfaceById", vdsNetworkInterfaceRowMapper, - getCustomMapSqlParameterSource().addValue("vds_interface_id", id)); + getCustomMapSqlParameterSource().addValue("vds_interface_id", + id)); } private static final RowMapper<VdsNetworkInterface> vdsNetworkInterfaceRowMapper = @@ -187,13 +220,16 @@ public VdsNetworkInterface mapRow(ResultSet rs, int rowNum) throws SQLException { VdsNetworkInterface entity = createInterface(rs); - entity.getStatistics().setId(Guid.createGuidFromString(rs.getString("id"))); + entity.getStatistics().setId( + Guid.createGuidFromString(rs.getString("id"))); entity.getStatistics().setReceiveRate(rs.getDouble("rx_rate")); entity.getStatistics().setTransmitRate(rs.getDouble("tx_rate")); entity.getStatistics().setReceiveDropRate(rs.getDouble("rx_drop")); entity.getStatistics().setTransmitDropRate(rs.getDouble("tx_drop")); - entity.getStatistics().setStatus(InterfaceStatus.forValue(rs.getInt("iface_status"))); - entity.getStatistics().setVdsId(Guid.createGuidFromString(rs.getString("vds_id"))); + entity.getStatistics().setStatus( + InterfaceStatus.forValue(rs.getInt("iface_status"))); + entity.getStatistics().setVdsId( + Guid.createGuidFromString(rs.getString("vds_id"))); entity.setType((Integer) rs.getObject("type")); entity.setGateway(rs.getString("gateway")); entity.setSubnet(rs.getString("subnet")); @@ -203,7 +239,8 @@ entity.setVdsId(NGuid.createGuidFromString(rs.getString("vds_id"))); entity.setVdsName(rs.getString("vds_name")); entity.setId(Guid.createGuidFromString(rs.getString("id"))); - entity.setBootProtocol(NetworkBootProtocol.forValue(rs.getInt("boot_protocol"))); + entity.setBootProtocol(NetworkBootProtocol.forValue(rs + .getInt("boot_protocol"))); entity.setMtu(rs.getInt("mtu")); entity.setBridged(rs.getBoolean("bridged")); return entity; @@ -212,13 +249,13 @@ /** * Create the correct type according to the row. If the type can't be determined for whatever reason, * {@link VdsNetworkInterface} instance is created & initialized. - * * @param rs * The row representing the entity. * @return The instance of the correct type as represented by the row. * @throws SQLException */ - private VdsNetworkInterface createInterface(ResultSet rs) throws SQLException { + private VdsNetworkInterface createInterface(ResultSet rs) + throws SQLException { VdsNetworkInterface iface; String macAddress = rs.getString("mac_addr"); -- To view, visit http://gerrit.ovirt.org/15340 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I631db03381de74672b0804f2673dff49020caaf5 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Liran Zelkha <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
