Ravi Nori has uploaded a new change for review.

Change subject: core : Add user id to Command Entities
......................................................................

core : Add user id to Command Entities

Add user id to command entities table

Change-Id: I7557ef5f082f15af6e9a1806af22e2aeb981645f
Signed-off-by: Ravi Nori <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CommandEntity.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java
M packaging/dbscripts/command_entities_sp.sql
4 files changed, 28 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/37247/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index f07815c..15633e9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -2217,7 +2217,8 @@
     }
 
     private CommandEntity buildCommandEntity(Guid parentCommandId, boolean 
callBackEnabled) {
-        return CommandEntity.buildCommandEntity(getCommandId(),
+        return CommandEntity.buildCommandEntity(getUserId(),
+                getCommandId(),
                 parentCommandId,
                 getExecutionContext() == null || 
getExecutionContext().getJob() == null ? Guid.Empty : 
getExecutionContext().getJob().getId(),
                 getExecutionContext() == null || 
getExecutionContext().getStep() == null ? Guid.Empty : 
getExecutionContext().getStep().getId(),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CommandEntity.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CommandEntity.java
index 23861d3..da709cf 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CommandEntity.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/CommandEntity.java
@@ -12,6 +12,7 @@
 public class CommandEntity implements BusinessEntity<Guid> {
 
     private static final long serialVersionUID = 5293055556971973650L;
+    private Guid userId;
     private Guid commandId;
     private Guid rootCommandId;
     private Guid jobId;
@@ -117,7 +118,8 @@
         this.callBackNotified = callBackNotified;
     }
 
-    public static CommandEntity buildCommandEntity(Guid commandId,
+    public static CommandEntity buildCommandEntity(Guid userId,
+                                                   Guid commandId,
                                                    Guid rootCommandId,
                                                    Guid jobId,
                                                    Guid stepId,
@@ -127,6 +129,7 @@
                                                    boolean callBackEnabled,
                                                    VdcReturnValueBase 
returnValue) {
         CommandEntity entity = new CommandEntity();
+        entity.setUserId(userId);
         entity.setId(commandId);
         entity.setRootCommandId(rootCommandId);
         entity.setJobId(jobId);
@@ -171,4 +174,11 @@
         this.executed = executed;
     }
 
+    public Guid getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Guid userId) {
+        this.userId = userId;
+    }
 }
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
index df4f3fa..dca6dab 100644
--- 
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
@@ -25,6 +25,7 @@
         @Override
         public CommandEntity mapRow(ResultSet resultSet, int rowNum) throws 
SQLException {
             CommandEntity result = new CommandEntity();
+            
result.setUserId(Guid.createGuidFromString(resultSet.getString("user_id")));
             
result.setId(Guid.createGuidFromString(resultSet.getString("command_id")));
             
result.setJobId(Guid.createGuidFromString(resultSet.getString("job_id")));
             
result.setStepId(Guid.createGuidFromString(resultSet.getString("step_id")));
@@ -56,7 +57,8 @@
 
     @Override
     protected MapSqlParameterSource createFullParametersMapper(CommandEntity 
entity) {
-        return getCustomMapSqlParameterSource().addValue("command_id", 
Guid.isNullOrEmpty(entity.getId()) ? Guid.Empty : entity.getId())
+        return getCustomMapSqlParameterSource().addValue("user_id", 
Guid.isNullOrEmpty(entity.getUserId()) ? Guid.Empty : entity.getUserId())
+                .addValue("command_id", Guid.isNullOrEmpty(entity.getId()) ? 
Guid.Empty : entity.getId())
                 .addValue("command_type", entity.getCommandType().getValue())
                 .addValue("root_command_id", 
Guid.isNullOrEmpty(entity.getRootCommandId()) ? Guid.Empty : 
entity.getRootCommandId())
                 .addValue("job_id", Guid.isNullOrEmpty(entity.getJobId()) ? 
Guid.Empty : entity.getJobId())
diff --git a/packaging/dbscripts/command_entities_sp.sql 
b/packaging/dbscripts/command_entities_sp.sql
index 86176c1..73df173 100644
--- a/packaging/dbscripts/command_entities_sp.sql
+++ b/packaging/dbscripts/command_entities_sp.sql
@@ -1,4 +1,5 @@
-CREATE OR REPLACE FUNCTION InsertCommandEntity (v_command_id uuid,
+CREATE OR REPLACE FUNCTION InsertCommandEntity (v_user_id uuid,
+       v_command_id uuid,
        v_command_type int,
        v_root_command_id uuid,
        v_job_id uuid,
@@ -13,13 +14,14 @@
 RETURNS VOID
    AS $procedure$
 BEGIN
-       INSERT INTO command_entities(command_id, command_type, root_command_id, 
job_id, step_id, command_parameters, command_params_class, created_at, status, 
executed, callback_enabled, return_value, return_value_class)
-              VALUES(v_command_id, v_command_type, v_root_command_id, 
v_job_id, v_step_id, v_command_parameters, v_command_params_class, NOW(), 
v_status, v_executed, v_callback_enabled, v_return_value, v_return_value_class);
+       INSERT INTO command_entities(user_id, command_id, command_type, 
root_command_id, job_id, step_id, command_parameters, command_params_class, 
created_at, status, executed, callback_enabled, return_value, 
return_value_class)
+              VALUES(v_user_id, v_command_id, v_command_type, 
v_root_command_id, v_job_id, v_step_id, v_command_parameters, 
v_command_params_class, NOW(), v_status, v_executed, v_callback_enabled, 
v_return_value, v_return_value_class);
 END; $procedure$
 LANGUAGE plpgsql;
 
 
-CREATE OR REPLACE FUNCTION UpdateCommandEntity (v_command_id uuid,
+CREATE OR REPLACE FUNCTION UpdateCommandEntity (v_user_id uuid,
+       v_command_id uuid,
        v_command_type int,
        v_root_command_id uuid,
        v_job_id uuid,
@@ -35,7 +37,8 @@
    AS $procedure$
 BEGIN
       UPDATE command_entities
-      SET command_type = v_command_type ,
+      SET command_type = v_command_type,
+          user_id = v_user_id,
           root_command_id = v_root_command_id,
           job_id = v_job_id,
           step_id = v_step_id,
@@ -87,7 +90,8 @@
 LANGUAGE plpgsql;
 
 
-CREATE OR REPLACE FUNCTION InsertOrUpdateCommandEntity (v_command_id uuid,
+CREATE OR REPLACE FUNCTION InsertOrUpdateCommandEntity (v_user_id uuid,
+       v_command_id uuid,
        v_command_type int,
        v_root_command_id uuid,
        v_job_id uuid,
@@ -103,9 +107,9 @@
    AS $procedure$
 BEGIN
       IF NOT EXISTS (SELECT 1 from command_entities where command_id = 
v_command_id) THEN
-            PERFORM InsertCommandEntity (v_command_id, v_command_type, 
v_root_command_id, v_job_id, v_step_id, v_command_parameters, 
v_command_params_class, v_status, v_executed, v_callback_enabled, 
v_return_value, v_return_value_class);
+            PERFORM InsertCommandEntity (v_user_id, v_command_id, 
v_command_type, v_root_command_id, v_job_id, v_step_id, v_command_parameters, 
v_command_params_class, v_status, v_executed, v_callback_enabled, 
v_return_value, v_return_value_class);
       ELSE
-            PERFORM UpdateCommandEntity (v_command_id, v_command_type, 
v_root_command_id, v_job_id, v_step_id, v_command_parameters, 
v_command_params_class, v_status, v_executed, v_callback_enabled, 
v_return_value, v_return_value_class);
+            PERFORM UpdateCommandEntity (v_user_id, v_command_id, 
v_command_type, v_root_command_id, v_job_id, v_step_id, v_command_parameters, 
v_command_params_class, v_status, v_executed, v_callback_enabled, 
v_return_value, v_return_value_class);
       END IF;
 END; $procedure$
 LANGUAGE plpgsql;


-- 
To view, visit http://gerrit.ovirt.org/37247
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7557ef5f082f15af6e9a1806af22e2aeb981645f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ravi Nori <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to