Hello Yair Zaslavsky,
I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/26337
to review the following change.
Change subject: engine: Introduction of command entity dao
......................................................................
engine: Introduction of command entity dao
Introduction of command entity database support
(upgrade script, stored procedures, DAO, DAO tests)
Change-Id: I463102d85de7558fbcab23585ad6b48cdc35c0a0
Signed-off-by: Yair Zaslavsky <[email protected]>
Signed-off-by: Ravi Nori <[email protected]>
---
M
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
A
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDao.java
A
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java
M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
A
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java
M
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
A packaging/dbscripts/command_entities_sp.sql
A packaging/dbscripts/upgrade/03_05_0160_add_command_entity_table.sql
9 files changed, 304 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/26337/1
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
index b8d519e..cb9baed 100644
---
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
@@ -11,6 +11,7 @@
import org.ovirt.engine.core.common.VdcObjectType;
import org.ovirt.engine.core.common.businessentities.BaseDisk;
import org.ovirt.engine.core.common.businessentities.BusinessEntity;
+import org.ovirt.engine.core.common.businessentities.CommandEntity;
import org.ovirt.engine.core.common.businessentities.DiskImage;
import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
import org.ovirt.engine.core.common.businessentities.DwhHistoryTimekeeping;
@@ -54,6 +55,7 @@
import org.ovirt.engine.core.dao.BaseDiskDao;
import org.ovirt.engine.core.dao.BookmarkDAO;
import org.ovirt.engine.core.dao.BusinessEntitySnapshotDAO;
+import org.ovirt.engine.core.dao.CommandEntityDao;
import org.ovirt.engine.core.dao.DAO;
import org.ovirt.engine.core.dao.DaoFactory;
import org.ovirt.engine.core.dao.DbGroupDAO;
@@ -177,6 +179,7 @@
put(DwhHistoryTimekeeping.class, DwhHistoryTimekeepingDao.class);
put(IscsiBond.class, IscsiBondDao.class);
put(VmInit.class, VmInitDAO.class);
+ put(CommandEntity.class, CommandEntityDao.class);
}
};
@@ -329,6 +332,15 @@
}
/**
+ * Retrieves the singleton instance of {@link CommandEntityDao}.
+ *
+ * @return the dao
+ */
+ public CommandEntityDao getCommandEntityDao() {
+ return getDao(CommandEntityDao.class);
+ }
+
+ /**
* Returns the singleton instance of {@link DbuserDAO}.
*
* @return the dao
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDao.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDao.java
new file mode 100644
index 0000000..f292ecd
--- /dev/null
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDao.java
@@ -0,0 +1,14 @@
+package org.ovirt.engine.core.dao;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.CommandEntity;
+import org.ovirt.engine.core.compat.Guid;
+
+public interface CommandEntityDao extends GenericDao<CommandEntity, Guid> {
+
+ List<CommandEntity> getByParentId(Guid parentId);
+
+ void RemoveCommandByParentId(Guid parentId);
+
+}
diff --git
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java
new file mode 100644
index 0000000..fea162e
--- /dev/null
+++
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java
@@ -0,0 +1,81 @@
+package org.ovirt.engine.core.dao;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.CommandEntity;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils;
+import org.ovirt.engine.core.utils.SerializationFactory;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+public class CommandEntityDaoDbFacadeImpl extends
DefaultGenericDaoDbFacade<CommandEntity, Guid> implements CommandEntityDao {
+
+ private static RowMapper<CommandEntity> mapper = new
RowMapper<CommandEntity>() {
+
+ @Override
+ public CommandEntity mapRow(ResultSet resultSet, int rowNum) throws
SQLException {
+ CommandEntity result = new CommandEntity();
+
result.setId(Guid.createGuidFromString(resultSet.getString("command_id")));
+
result.setCreatedAt(DbFacadeUtils.fromDate(resultSet.getTimestamp("created_at")));
+
result.setCommandType(VdcActionType.forValue(resultSet.getInt("command_type")));
+
result.setParentCommandId(Guid.createGuidFromString(resultSet.getString("parent_command_id")));
+ result.setData(deserializeData(resultSet.getString("data")));
+ return result;
+ }
+ };
+
+ public CommandEntityDaoDbFacadeImpl() {
+ super("CommandEntity");
+ setProcedureNameForGetAll("GetAllFromCommandEntities");
+ }
+
+ @Override
+ protected MapSqlParameterSource createFullParametersMapper(CommandEntity
entity) {
+ return getCustomMapSqlParameterSource().addValue("id", entity.getId())
+ .addValue("command_type", entity.getCommandType())
+ .addValue("parent_command_id", entity.getParentCommandId())
+ .addValue("data", serializeData(entity.getData()))
+ .addValue("created_at", entity.getCreatedAt());
+ }
+
+ @Override
+ protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+ return getCustomMapSqlParameterSource().addValue("command_id", id);
+ }
+
+ @Override
+ protected RowMapper<CommandEntity> createEntityRowMapper() {
+ return mapper;
+ }
+
+ private static String serializeData(Map<String, Object> data) {
+ return SerializationFactory.getSerializer().serialize(data);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Map<String, Object> deserializeData(String payload) {
+ return SerializationFactory.getDeserializer().deserialize(payload,
+ HashMap.class);
+ }
+
+ @Override
+ public List<CommandEntity> getByParentId(Guid parentId) {
+ MapSqlParameterSource parameterSource =
getCustomMapSqlParameterSource().addValue("command_id", parentId);
+ return
getCallsHandler().executeReadList("GetCommandEntitiesByParentId",
+ mapper,
+ parameterSource);
+ }
+
+ @Override
+ public void RemoveCommandByParentId(Guid parentId) {
+ MapSqlParameterSource parameterSource =
getCustomMapSqlParameterSource().addValue("command_id", parentId);
+
getCallsHandler().executeModification("DeleteCommandEntitiesByParentId",
parameterSource);
+ }
+
+}
diff --git
a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
index 19273d7..773066f 100644
--- a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
+++ b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
@@ -1,4 +1,5 @@
BookmarkDAO=org.ovirt.engine.core.dao.BookmarkDAODbFacadeImpl
+CommandEntityDao=org.ovirt.engine.core.dao.CommandEntityDaoDbFacadeImpl
DbUserDAO=org.ovirt.engine.core.dao.DbUserDAODbFacadeImpl
VdsDAO=org.ovirt.engine.core.dao.VdsDAODbFacadeImpl
VdsStaticDAO=org.ovirt.engine.core.dao.VdsStaticDAODbFacadeImpl
diff --git
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java
new file mode 100644
index 0000000..85a3e88
--- /dev/null
+++
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java
@@ -0,0 +1,81 @@
+package org.ovirt.engine.core.dao;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.businessentities.CommandEntity;
+import org.ovirt.engine.core.compat.Guid;
+
+public class CommandEntityDaoTest extends BaseGenericDaoTestCase<Guid,
CommandEntity, CommandEntityDao> {
+
+ @Override
+ protected CommandEntity generateNewEntity() {
+
+ CommandEntity commandEntity = new CommandEntity();
+ commandEntity.setCommandType(VdcActionType.AddVm);
+ commandEntity.setCreatedAt(new Date(System.currentTimeMillis()));
+ commandEntity.setId(Guid.newGuid());
+ commandEntity.setParentCommandId(null);
+ Map<String, Object> data = new HashMap<String, Object>();
+ data.put("name", "oVirt");
+ commandEntity.setData(data);
+ return commandEntity;
+ }
+
+ @Override
+ protected void updateExistingEntity() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected Guid getExistingEntityId() {
+ return FixturesTool.EXISTING_COMMAND_ENTITY_ID;
+ }
+
+ @Override
+ protected CommandEntityDao prepareDao() {
+ return dbFacade.getCommandEntityDao();
+ }
+
+ @Override
+ protected Guid generateNonExistingId() {
+ return Guid.newGuid();
+ }
+
+ @Override
+ protected int getEneitiesTotalCount() {
+ return 3;
+ }
+
+ @Test
+ public void testRemoveByParent() {
+ List<CommandEntity> childCommands =
dbFacade.getCommandEntityDao().getByParentId(getExistingEntityId());
+ assertNotNull(childCommands);
+ assertTrue(childCommands.size() > 0);
+
dbFacade.getCommandEntityDao().RemoveCommandByParentId(getExistingEntityId());
+ List<CommandEntity> childCommandsAfterRemoval =
+
dbFacade.getCommandEntityDao().getByParentId(getExistingEntityId());
+ assertNotNull(childCommandsAfterRemoval);
+ assertEquals(childCommandsAfterRemoval.size(), 0);
+ }
+
+ @Test
+ public void testGetAllByParent() {
+ List<CommandEntity> childCommands =
dbFacade.getCommandEntityDao().getByParentId(getExistingEntityId());
+ assertNotNull(childCommands);
+ assertTrue(childCommands.size() > 0);
+ for (CommandEntity command : childCommands) {
+ assertEquals(command.getParentCommandId(), getExistingEntityId());
+ }
+ }
+
+}
diff --git
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
index e823309..7052a6d 100644
---
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
+++
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
@@ -566,6 +566,7 @@
*/
public static final String STORAGE_CONNECTION_ID =
"0cc146e8-e5ed-482c-8814-270bc48c297e";
+ public static final Guid EXISTING_COMMAND_ENTITY_ID = new
Guid("340fd52b-3400-4cdd-8d3f-c9d03704b0a1");
/**
* Number of VMs on clusters
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 842994f..38962a4 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -46,6 +46,34 @@
</row>
</table>
+ <table name="command_entities">
+ <column>command_id</column>
+ <column>command_type</column>
+ <column>parent_command_id</column>
+ <column>created_at</column>
+ <column>data</column>
+ <row>
+ <value>340fd52b-3400-4cdd-8d3f-c9d03704b0a1</value>
+ <value>230</value> <!-- Remove Disk -->
+ <null/>
+ <value>2010-11-29 15:57:10</value>
+ <null/>
+ </row>
+ <row>
+ <value>340fd52b-3400-4cdd-8d3f-c9d03704b0a2</value>
+ <value>211</value> <!-- Remove Image -->
+ <value>340fd52b-3400-4cdd-8d3f-c9d03704b0a1</value>
+ <value>2010-11-29 15:57:10</value>
+ <null/>
+ </row>
+ <row>
+ <value>340fd52b-3400-4cdd-8d3f-c9d03704b0a3</value>
+ <value>211</value> <!-- Remove Image -->
+ <value>340fd52b-3400-4cdd-8d3f-c9d03704b0a1</value>
+ <value>2010-11-29 15:57:10</value>
+ <null/>
+ </row>
+ </table>
<table name="async_tasks">
<column>task_id</column>
diff --git a/packaging/dbscripts/command_entities_sp.sql
b/packaging/dbscripts/command_entities_sp.sql
new file mode 100644
index 0000000..714eaf9
--- /dev/null
+++ b/packaging/dbscripts/command_entities_sp.sql
@@ -0,0 +1,76 @@
+CREATE OR REPLACE FUNCTION InsertCommandEntity (v_id uuid, v_command_type int,
v_parent_command_id uuid, v_data text, v_created_at timestamp)
+ RETURNS void AS
+$procedure$
+BEGIN
+ BEGIN
+ INSERT INTO command_entities(command_id, command_type,
parent_command_id, data, created_at)
+ VALUES(v_id, v_command_type, v_parent_command_id,
v_data, v_created_at);
+ END;
+
+ RETURN;
+END; $procedure$
+ LANGUAGE plpgsql;
+
+
+CREATE OR REPLACE FUNCTION UpdateCommandEntity (v_id uuid, v_command_type int,
v_parent_command_id uuid, v_data text, v_created_at timestamp)
+ RETURNS void AS
+$procedure$
+BEGIN
+ BEGIN
+ UPDATE command_entities set command_type = v_command_type ,
parent_command_id = v_parent_command_id,
+ data = v_data, created_at = v_created_at where command_id =
v_id;
+ END;
+
+ RETURN;
+END; $procedure$
+ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION GetCommandEntityByCommandEntityId (v_command_id
uuid)
+ RETURNS SETOF command_entities AS
+$procedure$
+BEGIN
+ RETURN QUERY SELECT command_entities.*
+ FROM command_entities
+ WHERE command_id = v_command_id;
+END; $procedure$
+ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION GetCommandEntitiesByParentId (v_command_id uuid)
+ RETURNS SETOF command_entities AS
+$procedure$
+BEGIN
+ RETURN QUERY SELECT command_entities.*
+ FROM command_entities
+ WHERE parent_command_id = v_command_id;
+END; $procedure$
+ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION GetAllFromCommandEntities ()
+ RETURNS SETOF command_entities AS
+$procedure$
+BEGIN
+ RETURN QUERY SELECT * from command_entities;
+END; $procedure$
+ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION DeleteCommandEntity(v_command_id uuid)
+ RETURNS void AS
+$procedure$
+BEGIN
+ BEGIN
+ delete from command_entities where command_id = v_command_id;
+ END;
+ RETURN;
+END; $procedure$
+ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION DeleteCommandEntitiesByParentId(v_command_id uuid)
+ RETURNS void AS
+$procedure$
+BEGIN
+ BEGIN
+ delete from command_entities where parent_command_id =
v_command_id;
+ END;
+ RETURN;
+END; $procedure$
+ LANGUAGE plpgsql;
diff --git
a/packaging/dbscripts/upgrade/03_05_0160_add_command_entity_table.sql
b/packaging/dbscripts/upgrade/03_05_0160_add_command_entity_table.sql
new file mode 100644
index 0000000..e807208
--- /dev/null
+++ b/packaging/dbscripts/upgrade/03_05_0160_add_command_entity_table.sql
@@ -0,0 +1,10 @@
+-- Add command_entities table
+CREATE TABLE command_entities
+(
+ command_id UUID NOT NULL,
+ command_type integer NOT NULL,
+ parent_command_id UUID,
+ data TEXT,
+ created_at TIMESTAMP WITH TIME ZONE,
+ CONSTRAINT pk_command_entities PRIMARY KEY(command_id, parent_command_id)
+);
--
To view, visit http://gerrit.ovirt.org/26337
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I463102d85de7558fbcab23585ad6b48cdc35c0a0
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <[email protected]>
Gerrit-Reviewer: Yair Zaslavsky <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches