Shireesh Anjal has uploaded a new change for review.
Change subject: engine: Remove multiple entities with single query
......................................................................
engine: Remove multiple entities with single query
Modified the gluster volume, brick and option DAOs to support
mass remove operations. For this,
- New procedures in gluster_volumes_sp.sql to support removal
of multiple entities in a single query
- added removeAll() method in the MassOperationsDao interface
- provided default implementation in
MassOperationsGenericDaoDbFacade
- In this process, fixed a bug in
MassOperationsGenericDaoDbFacade#updateAll(Collection<T>)
- Minor change in affected DAO interfaces / classes
Change-Id: Ia3a1d873807952a154c970860933daa43058cf63
Signed-off-by: Shireesh Anjal <[email protected]>
---
M backend/manager/dbscripts/gluster_volumes_sp.sql
M
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
M
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeOptionEntity.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DefaultGenericDaoDbFacade.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAO.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmNetworkStatisticsDAO.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDAO.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDao.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDao.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
M
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoTest.java
M
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoTest.java
M
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
M
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
21 files changed, 227 insertions(+), 47 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/8118/1
diff --git a/backend/manager/dbscripts/gluster_volumes_sp.sql
b/backend/manager/dbscripts/gluster_volumes_sp.sql
index 137c612..86bb3f7 100644
--- a/backend/manager/dbscripts/gluster_volumes_sp.sql
+++ b/backend/manager/dbscripts/gluster_volumes_sp.sql
@@ -194,6 +194,16 @@
LANGUAGE plpgsql;
+Create or replace FUNCTION DeleteGlusterVolumesByGuids(v_volume_ids
VARCHAR(5000))
+ RETURNS VOID
+ AS $procedure$
+BEGIN
+ DELETE FROM gluster_volumes
+ WHERE id::VARCHAR = any (string_to_array(v_volume_ids,',')::VARCHAR[] );
+END; $procedure$
+LANGUAGE plpgsql;
+
+
Create or replace FUNCTION DeleteGlusterVolumeByName(v_cluster_id UUID,
v_vol_name VARCHAR(1000))
RETURNS VOID
@@ -214,6 +224,14 @@
END; $procedure$
LANGUAGE plpgsql;
+Create or replace FUNCTION DeleteGlusterVolumeBricks(v_ids VARCHAR(5000))
+ RETURNS VOID
+ AS $procedure$
+BEGIN
+ DELETE FROM gluster_volume_bricks
+ WHERE id::VARCHAR = any (string_to_array(v_ids,',')::VARCHAR[] );
+END; $procedure$
+LANGUAGE plpgsql;
Create or replace FUNCTION DeleteGlusterVolumeOption(v_id UUID)
RETURNS VOID
@@ -224,6 +242,15 @@
END; $procedure$
LANGUAGE plpgsql;
+Create or replace FUNCTION DeleteGlusterVolumeOptions(v_ids VARCHAR(5000))
+ RETURNS VOID
+ AS $procedure$
+BEGIN
+ DELETE FROM gluster_volume_options
+ WHERE id::VARCHAR = any (string_to_array(v_ids,',')::VARCHAR[] );
+END; $procedure$
+LANGUAGE plpgsql;
+
Create or replace FUNCTION DeleteGlusterVolumeAccessProtocol(v_volume_id UUID,
v_access_protocol
VARCHAR(32))
diff --git
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
index dfb5076..f018e67 100644
---
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
+++
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterBrickEntity.java
@@ -2,6 +2,7 @@
import javax.validation.constraints.NotNull;
+import org.ovirt.engine.core.common.businessentities.BusinessEntity;
import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
import org.ovirt.engine.core.common.businessentities.VdsStatic;
import org.ovirt.engine.core.common.utils.gluster.GlusterCoreUtil;
@@ -19,7 +20,7 @@
* @see GlusterVolumeEntity
* @see GlusterBrickStatus
*/
-public class GlusterBrickEntity extends IVdcQueryable {
+public class GlusterBrickEntity extends IVdcQueryable implements
BusinessEntity<Guid> {
private static final long serialVersionUID = 7119439284741452278L;
@NotNull(message = "VALIDATION.GLUSTER.BRICK.ID.NOT_NULL", groups = {
RemoveBrick.class })
@@ -146,6 +147,7 @@
* GlusterFS, and hence is generated on the backend side.
* @return id of the brick
*/
+ @Override
public Guid getId() {
return getId(true);
}
@@ -157,6 +159,7 @@
return id;
}
+ @Override
public void setId(Guid id) {
this.id = id;
}
diff --git
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeOptionEntity.java
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeOptionEntity.java
index 66a8281..ae0d261 100644
---
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeOptionEntity.java
+++
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeOptionEntity.java
@@ -2,6 +2,7 @@
import javax.validation.constraints.NotNull;
+import org.ovirt.engine.core.common.businessentities.BusinessEntity;
import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
import org.ovirt.engine.core.common.validation.group.RemoveEntity;
import org.ovirt.engine.core.common.validation.group.gluster.SetVolumeOption;
@@ -14,7 +15,7 @@
*
* @see GlusterVolumeEntity
*/
-public class GlusterVolumeOptionEntity extends IVdcQueryable {
+public class GlusterVolumeOptionEntity extends IVdcQueryable implements
BusinessEntity<Guid> {
private static final long serialVersionUID = 5770623263518245638L;
@NotNull(message = "VALIDATION.GLUSTER.OPTION.ID.NOT_NULL", groups = {
RemoveEntity.class })
@@ -96,6 +97,7 @@
* GlusterFS, and hence is generated on the backend side.
* @return id of the option
*/
+ @Override
public Guid getId() {
if(id == null) {
id = Guid.NewGuid();
@@ -103,6 +105,7 @@
return id;
}
+ @Override
public void setId(Guid id) {
this.id = id;
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DefaultGenericDaoDbFacade.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DefaultGenericDaoDbFacade.java
index 45633cf..d4f8d29 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DefaultGenericDaoDbFacade.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DefaultGenericDaoDbFacade.java
@@ -95,7 +95,11 @@
@Override
public void update(T entity) {
- getCallsHandler().executeModification(getProcedureNameForUpdate(),
createFullParametersMapper(entity));
+ update(entity, getProcedureNameForUpdate());
+ }
+
+ protected void update(T entity, String procedureName) {
+ getCallsHandler().executeModification(procedureName,
createFullParametersMapper(entity));
}
@Override
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAO.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAO.java
index e75329c..bee944c 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAO.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/DiskImageDynamicDAO.java
@@ -3,6 +3,6 @@
import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
import org.ovirt.engine.core.compat.Guid;
-public interface DiskImageDynamicDAO extends GenericDao<DiskImageDynamic,
Guid>, MassOperationsDao<DiskImageDynamic> {
+public interface DiskImageDynamicDAO extends GenericDao<DiskImageDynamic,
Guid>, MassOperationsDao<DiskImageDynamic, Guid> {
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
index 79359da..0012b74 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
@@ -1,5 +1,6 @@
package org.ovirt.engine.core.dao;
+import java.io.Serializable;
import java.util.Collection;
import org.ovirt.engine.core.common.businessentities.BusinessEntity;
@@ -9,8 +10,11 @@
*
* @param T
* the type of entity to perform mass operations on.
+ *
+ * @param <ID>
+ * The type of the entity's id.
*/
-public interface MassOperationsDao<T extends BusinessEntity<?>> {
+public interface MassOperationsDao<T extends BusinessEntity<?>, ID extends
Serializable> {
/**
* Updates the given entities using a more efficient method to update all
of them at once, rather than each at a
@@ -29,4 +33,10 @@
* @param entities
*/
void updateAll(String procedureName, Collection<T> entities);
+
+ /**
+ * Removes the entities with given ids
+ * @param ids
+ */
+ void removeAll(Collection<ID> ids);
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
index b5bb32c..6f3da4a 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
@@ -16,7 +16,7 @@
* The type of the entity's id.
*/
public abstract class MassOperationsGenericDaoDbFacade<T extends
BusinessEntity<ID>, ID extends Serializable>
- extends DefaultGenericDaoDbFacade<T, ID> implements
MassOperationsDao<T> {
+ extends DefaultGenericDaoDbFacade<T, ID> implements
MassOperationsDao<T, ID> {
public MassOperationsGenericDaoDbFacade(String entityStoredProcedureName) {
super(entityStoredProcedureName);
@@ -25,10 +25,6 @@
@Override
public void updateAll(Collection<T> entities) {
updateAll(getProcedureNameForUpdate(),entities);
- for (T entity : entities) {
- getCallsHandler().executeModification(getProcedureNameForUpdate(),
- createFullParametersMapper(entity));
- }
}
@Override
@@ -38,12 +34,15 @@
* In case this parameter is null the default procedure is used.
*/
public void updateAll(String procedureName, Collection<T> entities) {
- if (procedureName == null) {
- procedureName = getProcedureNameForUpdate();
- }
for (T entity : entities) {
- getCallsHandler().executeModification(procedureName,
- createFullParametersMapper(entity));
+ update(entity, procedureName == null ? getProcedureNameForUpdate()
: procedureName);
+ }
+ }
+
+ @Override
+ public void removeAll(Collection<ID> ids) {
+ for (ID id : ids) {
+ remove(id);
}
}
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
index e056b28..40babec 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDeviceDAO.java
@@ -6,7 +6,7 @@
import org.ovirt.engine.core.common.businessentities.VmDeviceId;
import org.ovirt.engine.core.compat.Guid;
-public interface VmDeviceDAO extends GenericDao<VmDevice, VmDeviceId>,
MassOperationsDao<VmDevice> {
+public interface VmDeviceDAO extends GenericDao<VmDevice, VmDeviceId>,
MassOperationsDao<VmDevice, VmDeviceId> {
/**
* Check if the {@link VmDevice} with the given id exists or not.
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
index b940cfd..b120789 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmDynamicDAO.java
@@ -7,7 +7,7 @@
import org.ovirt.engine.core.compat.Guid;
public interface VmDynamicDAO extends GenericDao<VmDynamic, Guid>,
StatusAwareDao<Guid, VMStatus>,
- MassOperationsDao<VmDynamic> {
+ MassOperationsDao<VmDynamic, Guid> {
/**
* Retrieves all running dynamic VMs for the given VDS instance.
*
@@ -24,6 +24,7 @@
* the id
* @return the dynamic vm
*/
+ @Override
VmDynamic get(Guid id);
/**
@@ -32,6 +33,7 @@
* @param vm
* the vm
*/
+ @Override
void update(VmDynamic vm);
/**
@@ -40,6 +42,7 @@
* @param vmDynamic
* the vm
*/
+ @Override
void remove(Guid vm);
/**
@@ -48,6 +51,7 @@
* @param vm
* the vm
*/
+ @Override
void save(VmDynamic vm);
/**
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmNetworkStatisticsDAO.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmNetworkStatisticsDAO.java
index 0026428..cd16479 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmNetworkStatisticsDAO.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmNetworkStatisticsDAO.java
@@ -8,5 +8,5 @@
* {@link VmNetworkStatistics}.
*/
public interface VmNetworkStatisticsDAO extends
GenericDao<VmNetworkStatistics, Guid>,
- MassOperationsDao<VmNetworkStatistics> {
+ MassOperationsDao<VmNetworkStatistics, Guid> {
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDAO.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDAO.java
index ca517be..a00af82 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDAO.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmStatisticsDAO.java
@@ -3,6 +3,6 @@
import org.ovirt.engine.core.common.businessentities.VmStatistics;
import org.ovirt.engine.core.compat.Guid;
-public interface VmStatisticsDAO extends GenericDao<VmStatistics, Guid>,
MassOperationsDao<VmStatistics> {
+public interface VmStatisticsDAO extends GenericDao<VmStatistics, Guid>,
MassOperationsDao<VmStatistics, Guid> {
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDao.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDao.java
index 4d56d62..9d32c1c 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDao.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDao.java
@@ -6,11 +6,12 @@
import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.DAO;
+import org.ovirt.engine.core.dao.MassOperationsDao;
/**
* Interface for DB operations on Gluster Bricks.
*/
-public interface GlusterBrickDao extends DAO {
+public interface GlusterBrickDao extends DAO,
MassOperationsDao<GlusterBrickEntity, Guid> {
public void save(GlusterBrickEntity brick);
public GlusterBrickEntity getById(Guid id);
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
index f1d18dc..c92abea 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoDbFacadeImpl.java
@@ -2,21 +2,28 @@
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Collection;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
import org.ovirt.engine.core.common.utils.EnumUtils;
import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.dao.BaseDAODbFacade;
+import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
-public class GlusterBrickDaoDbFacadeImpl extends BaseDAODbFacade implements
GlusterBrickDao {
+public class GlusterBrickDaoDbFacadeImpl extends
MassOperationsGenericDaoDbFacade<GlusterBrickEntity, Guid> implements
GlusterBrickDao {
// The brick row mapper can't be static as its' type
(GlusterBrickRowMapper) is a non-static inner class
// There will still be a single instance of it, as the DAO itself will be
instantiated only once
private final ParameterizedRowMapper<GlusterBrickEntity> brickRowMapper =
new GlusterBrickRowMapper();
+
+ public GlusterBrickDaoDbFacadeImpl() {
+ super("GlusterBrick");
+ setProcedureNameForGet("GetGlusterBrickById");
+ }
@Override
public void save(GlusterBrickEntity brick) {
@@ -27,6 +34,12 @@
public void removeBrick(Guid brickId) {
getCallsHandler().executeModification("DeleteGlusterVolumeBrick",
getCustomMapSqlParameterSource().addValue("id", brickId));
+ }
+
+ @Override
+ public void removeAll(Collection<Guid> ids) {
+ getCallsHandler().executeModification("DeleteGlusterVolumeBricks",
+ getCustomMapSqlParameterSource().addValue("ids",
StringUtils.join(ids, ',')));
}
@Override
@@ -59,7 +72,7 @@
public GlusterBrickEntity getById(Guid id) {
return getCallsHandler().executeRead(
"GetGlusterBrickById", brickRowMapper,
- getCustomMapSqlParameterSource().addValue("id", id));
+ createIdParameterMapper(id));
}
@Override
@@ -115,4 +128,19 @@
"GetGlusterVolumeBricksByServerGuid", brickRowMapper,
getCustomMapSqlParameterSource().addValue("server_id",
serverId));
}
+
+ @Override
+ protected MapSqlParameterSource
createFullParametersMapper(GlusterBrickEntity brick) {
+ return createBrickParams(brick);
+ }
+
+ @Override
+ protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+ return getCustomMapSqlParameterSource().addValue("id", id);
+ }
+
+ @Override
+ protected ParameterizedRowMapper<GlusterBrickEntity>
createEntityRowMapper() {
+ return brickRowMapper;
+ }
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDao.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDao.java
index e29917b..c1ce5fa 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDao.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDao.java
@@ -5,11 +5,12 @@
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.DAO;
+import org.ovirt.engine.core.dao.MassOperationsDao;
/**
* Interface for DB operations on Gluster Options.
*/
-public interface GlusterOptionDao extends DAO {
+public interface GlusterOptionDao extends DAO,
MassOperationsDao<GlusterVolumeOptionEntity, Guid> {
public void save(GlusterVolumeOptionEntity option);
public GlusterVolumeOptionEntity getById(Guid id);
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
index 3f34590..bd6dc46 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoDbFacadeImpl.java
@@ -2,16 +2,23 @@
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.Collection;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.dao.BaseDAODbFacade;
+import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
-public class GlusterOptionDaoDbFacadeImpl extends BaseDAODbFacade implements
GlusterOptionDao {
+public class GlusterOptionDaoDbFacadeImpl extends
MassOperationsGenericDaoDbFacade<GlusterVolumeOptionEntity, Guid> implements
GlusterOptionDao {
private static final ParameterizedRowMapper<GlusterVolumeOptionEntity>
optionRowMapper = new VolumeOptionRowMapper();
+
+ public GlusterOptionDaoDbFacadeImpl() {
+ super("GlusterOption");
+ setProcedureNameForGet("GetGlusterOptionById");
+ }
@Override
public void save(GlusterVolumeOptionEntity option) {
@@ -33,10 +40,14 @@
}
@Override
+ public void removeAll(Collection<Guid> ids) {
+ getCallsHandler().executeModification("DeleteGlusterVolumeOptions",
+ getCustomMapSqlParameterSource().addValue("ids",
StringUtils.join(ids, ',')));
+ }
+
+ @Override
public GlusterVolumeOptionEntity getById(Guid id) {
- return getCallsHandler().executeRead(
- "GetGlusterOptionById", optionRowMapper,
- getCustomMapSqlParameterSource().addValue("id", id));
+ return getCallsHandler().executeRead("GetGlusterOptionById",
optionRowMapper, createIdParameterMapper(id));
}
@Override
@@ -66,4 +77,19 @@
return option;
}
}
+
+ @Override
+ protected MapSqlParameterSource
createFullParametersMapper(GlusterVolumeOptionEntity option) {
+ return createVolumeOptionParams(option);
+ }
+
+ @Override
+ protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+ return getCustomMapSqlParameterSource().addValue("id", id);
+ }
+
+ @Override
+ protected ParameterizedRowMapper<GlusterVolumeOptionEntity>
createEntityRowMapper() {
+ return optionRowMapper;
+ }
}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
index b544425..b69a258 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
@@ -8,12 +8,13 @@
import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.DAO;
+import org.ovirt.engine.core.dao.MassOperationsDao;
import org.ovirt.engine.core.dao.SearchDAO;
/**
* Interface for DB operations on Gluster Volumes.
*/
-public interface GlusterVolumeDao extends DAO, SearchDAO<GlusterVolumeEntity> {
+public interface GlusterVolumeDao extends DAO, SearchDAO<GlusterVolumeEntity>,
MassOperationsDao<GlusterVolumeEntity, Guid> {
public void save(GlusterVolumeEntity volume);
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
index ca470c9..77320e6 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
@@ -6,16 +6,17 @@
import java.util.HashSet;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
import org.ovirt.engine.core.common.businessentities.gluster.AccessProtocol;
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
+import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
-import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
import org.ovirt.engine.core.common.utils.EnumUtils;
import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.dao.BaseDAODbFacade;
+import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
@@ -23,12 +24,17 @@
/**
* Implementation of the DB Facade for Gluster Volumes.
*/
-public class GlusterVolumeDaoDbFacadeImpl extends BaseDAODbFacade implements
+public class GlusterVolumeDaoDbFacadeImpl extends
MassOperationsGenericDaoDbFacade<GlusterVolumeEntity, Guid> implements
GlusterVolumeDao {
private static final ParameterizedRowMapper<GlusterVolumeEntity>
volumeRowMapper = new GlusterVolumeRowMapper();
private static final ParameterizedRowMapper<AccessProtocol>
accessProtocolRowMapper = new AccessProtocolRowMapper();
private static final ParameterizedRowMapper<TransportType>
transportTypeRowMapper = new TransportTypeRowMapper();
+
+ public GlusterVolumeDaoDbFacadeImpl() {
+ super("GlusterVolume");
+ setProcedureNameForGet("GetGlusterVolumeById");
+ }
@Override
public void save(GlusterVolumeEntity volume) {
@@ -89,6 +95,12 @@
getCustomMapSqlParameterSource()
.addValue("cluster_id", clusterId)
.addValue("vol_name", volName));
+ }
+
+ @Override
+ public void removeAll(Collection<Guid> ids) {
+ getCallsHandler().executeModification("DeleteGlusterVolumesByGuids",
+ getCustomMapSqlParameterSource().addValue("volume_ids",
StringUtils.join(ids, ',')));
}
@Override
@@ -157,16 +169,7 @@
}
private void insertVolumeEntity(GlusterVolumeEntity volume) {
- getCallsHandler().executeModification(
- "InsertGlusterVolume",
- getCustomMapSqlParameterSource()
- .addValue("id", volume.getId())
- .addValue("cluster_id", volume.getClusterId())
- .addValue("vol_name", volume.getName())
- .addValue("vol_type",
EnumUtils.nameOrNull(volume.getVolumeType()))
- .addValue("status",
EnumUtils.nameOrNull(volume.getStatus()))
- .addValue("replica_count", volume.getReplicaCount())
- .addValue("stripe_count", volume.getStripeCount()));
+ getCallsHandler().executeModification("InsertGlusterVolume",
createFullParametersMapper(volume));
}
private void insertVolumeBricks(GlusterVolumeEntity volume) {
@@ -289,4 +292,26 @@
.addValue("replica_count", volume.getReplicaCount())
.addValue("stripe_count", volume.getStripeCount()));
}
+
+ @Override
+ protected MapSqlParameterSource
createFullParametersMapper(GlusterVolumeEntity volume) {
+ return getCustomMapSqlParameterSource()
+ .addValue("id", volume.getId())
+ .addValue("cluster_id", volume.getClusterId())
+ .addValue("vol_name", volume.getName())
+ .addValue("vol_type",
EnumUtils.nameOrNull(volume.getVolumeType()))
+ .addValue("status", EnumUtils.nameOrNull(volume.getStatus()))
+ .addValue("replica_count", volume.getReplicaCount())
+ .addValue("stripe_count", volume.getStripeCount());
+ }
+
+ @Override
+ protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+ return createVolumeIdParams(id);
+ }
+
+ @Override
+ protected ParameterizedRowMapper<GlusterVolumeEntity>
createEntityRowMapper() {
+ return volumeRowMapper;
+ }
}
diff --git
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoTest.java
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoTest.java
index 3c7157c..e6754c8 100644
---
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoTest.java
+++
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterBrickDaoTest.java
@@ -3,7 +3,9 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
@@ -59,6 +61,20 @@
}
@Test
+ public void testRemoveMultiple() {
+ List<GlusterBrickEntity> bricks =
dao.getBricksOfVolume(EXISTING_VOL_ID);
+ assertEquals(2, bricks.size());
+
+ List<Guid> idsToRemove = new ArrayList<Guid>();
+ idsToRemove.add(bricks.get(0).getId());
+ idsToRemove.add(bricks.get(1).getId());
+ dao.removeAll(idsToRemove);
+
+ bricks = dao.getBricksOfVolume(EXISTING_VOL_ID);
+ assertTrue(bricks.isEmpty());
+ }
+
+ @Test
public void testReplaceBrick() {
GlusterBrickEntity firstBrick = dao.getById(EXISTING_BRICK_ID);
assertNotNull(firstBrick);
diff --git
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoTest.java
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoTest.java
index 90ca8d0..11f86b1 100644
---
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoTest.java
+++
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterOptionDaoTest.java
@@ -3,6 +3,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
import org.junit.Test;
import
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
@@ -55,4 +59,18 @@
dao.removeVolumeOption(EXISTING_OPTION_ID);
assertNull(dao.getById(EXISTING_OPTION_ID));
}
+
+ @Test
+ public void testRemoveVolumeOptionMultiple() {
+ List<GlusterVolumeOptionEntity> options =
dao.getOptionsOfVolume(EXISTING_VOL_ID);
+ assertEquals(2, options.size());
+
+ List<Guid> idsToRemove = new ArrayList<Guid>();
+ idsToRemove.add(options.get(0).getId());
+ idsToRemove.add(options.get(1).getId());
+ dao.removeAll(idsToRemove);
+
+ options = dao.getOptionsOfVolume(EXISTING_VOL_ID);
+ assertTrue(options.isEmpty());
+ }
}
diff --git
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
index 7ff1c81..95ff733 100644
---
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
+++
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
@@ -6,6 +6,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -98,6 +99,18 @@
}
@Test
+ public void testRemoveMultiple() {
+ List<Guid> idsToRemove = new ArrayList<Guid>();
+ idsToRemove.add(EXISTING_VOL_DIST_ID);
+ idsToRemove.add(EXISTING_VOL_REPL_ID);
+
+ dao.removeAll(idsToRemove);
+ List<GlusterVolumeEntity> volumes = dao.getByClusterId(CLUSTER_ID);
+
+ assertTrue(volumes.isEmpty());
+ }
+
+ @Test
public void testRemoveByName() {
dao.removeByName(CLUSTER_ID, EXISTING_VOL_REPL_NAME);
List<GlusterVolumeEntity> volumes = dao.getByClusterId(CLUSTER_ID);
diff --git
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index 49d290b..797f427 100644
---
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -1,5 +1,6 @@
package org.ovirt.engine.core.vdsbroker;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -196,8 +197,8 @@
* @param dao
* The DAO used for updating.
*/
- private static <T extends BusinessEntity<?>> void updateAllInTransaction
- (final Collection<T> entities, final MassOperationsDao<T> dao) {
+ private static <T extends BusinessEntity<?>, ID extends Serializable> void
updateAllInTransaction
+ (final Collection<T> entities, final MassOperationsDao<T, ID> dao)
{
updateAllInTransaction(null, entities,dao);
}
@@ -215,8 +216,8 @@
* The DAO used for updating.
*/
- private static <T extends BusinessEntity<?>> void updateAllInTransaction
- (final String procedureName, final Collection<T> entities, final
MassOperationsDao<T> dao) {
+ private static <T extends BusinessEntity<?>, ID extends Serializable> void
updateAllInTransaction
+ (final String procedureName, final Collection<T> entities, final
MassOperationsDao<T, ID> dao) {
if (!entities.isEmpty()) {
TransactionSupport.executeInScope(TransactionScopeOption.Required,
new TransactionMethod<Void>() {
--
To view, visit http://gerrit.ovirt.org/8118
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3a1d873807952a154c970860933daa43058cf63
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Shireesh Anjal <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches