Francesco Romani has uploaded a new change for review.

Change subject: WIP: core: bulk queries for VMConsoleProxyServlet #1
......................................................................

WIP: core: bulk queries for VMConsoleProxyServlet #1

WORK IN PROGRESS

Add bulk queries for UserProfiles

Change-Id: Ic58b0e92ee416fb43661910632970055d3c23e8d
Signed-off-by: Francesco Romani <from...@redhat.com>
---
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/UserProfileView.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAODbFacadeImpl.java
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/user_profiles_sp.sql
5 files changed, 96 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/98/40698/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/UserProfileView.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/UserProfileView.java
new file mode 100644
index 0000000..8eb7863
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/UserProfileView.java
@@ -0,0 +1,32 @@
+package org.ovirt.engine.core.common.businessentities;
+
+import org.ovirt.engine.core.common.utils.ObjectUtils;
+
+
+public class UserProfileView  extends UserProfile {
+
+    private String loginName;
+
+    public void setLoginName(String loginName) { this.loginName = loginName; }
+
+    public String getLoginName() { return loginName; }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        if (!super.equals(o)) return false;
+
+        UserProfileView other = (UserProfileView) o;
+
+        return ObjectUtils.objectsEqual(loginName, other.loginName);
+    }
+
+    @Override
+    public int hashCode() {
+        int result = super.hashCode();
+        result = 31 * result + (loginName != null ? loginName.hashCode() : 0);
+        return result;
+    }
+
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAO.java
index a748af6..da63629 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAO.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.dao;
 
 import org.ovirt.engine.core.common.businessentities.UserProfile;
+import org.ovirt.engine.core.common.businessentities.UserProfileView;
 import org.ovirt.engine.core.compat.Guid;
 
 import java.util.List;
@@ -32,6 +33,13 @@
     List<UserProfile> getAll();
 
     /**
+     * Retrieves all the extended user profiles.
+     *
+     * @return the collection of all extended user profiles
+     */
+    List<UserProfileView> getAllExtended();
+
+    /**
      * Saves the user profile.
      *
      * @param profile
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAODbFacadeImpl.java
index c1aed33..45eadba 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/UserProfileDAODbFacadeImpl.java
@@ -8,6 +8,7 @@
 import javax.inject.Singleton;
 
 import org.ovirt.engine.core.common.businessentities.UserProfile;
+import org.ovirt.engine.core.common.businessentities.UserProfileView;
 import org.ovirt.engine.core.compat.Guid;
 import org.springframework.jdbc.core.RowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -16,17 +17,40 @@
 @Singleton
 public class UserProfileDAODbFacadeImpl extends BaseDAODbFacade implements 
UserProfileDAO {
 
-    private static final class UserProfileRowMapper implements 
RowMapper<UserProfile> {
+    private static abstract class BaseUserProfileRowMapper<T extends 
UserProfile> implements RowMapper<T> {
+
+        protected void map(ResultSet rs, UserProfile profile) throws 
SQLException{
+            profile.setId(getGuidDefaultEmpty(rs, "profile_id"));
+            profile.setUserId(getGuidDefaultEmpty(rs, "user_id"));
+            profile.setSshPublicKey(rs.getString("ssh_public_key"));
+        }
+    }
+
+    private static class UserProfileRowMapper extends 
BaseUserProfileRowMapper<UserProfile> {
+
         public static final UserProfileRowMapper instance = new 
UserProfileRowMapper();
 
         @Override
-        public UserProfile mapRow(ResultSet rs, int rowNum)
-                throws SQLException {
-            UserProfile entity = new UserProfile();
-            entity.setId(getGuidDefaultEmpty(rs, "profile_id"));
-            entity.setUserId(getGuidDefaultEmpty(rs, "user_id"));
-            entity.setSshPublicKey(rs.getString("ssh_public_key"));
-            return entity;
+        public UserProfile mapRow(ResultSet rs, int rowNum) throws 
SQLException {
+            UserProfile profile = new UserProfile();
+            map(rs, profile);
+
+            return profile;
+        }
+    }
+
+    private static class ExtendedUserProfileRowMapper extends 
BaseUserProfileRowMapper<UserProfileView> {
+
+        public static final ExtendedUserProfileRowMapper instance = new 
ExtendedUserProfileRowMapper();
+
+        @Override
+        public UserProfileView mapRow(ResultSet rs, int rowNum) throws 
SQLException {
+            UserProfileView profile = new UserProfileView();
+            map(rs, profile);
+
+            profile.setLoginName(rs.getString("login_name"));
+
+            return profile;
         }
     }
 
@@ -78,4 +102,12 @@
 
         getCallsHandler().executeModification("DeleteUserProfile", 
parameterSource);
     }
+
+    @Override
+    public List<UserProfileView> getAllExtended() {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource();
+        return 
getCallsHandler().executeReadList("GetAllFromExtendedUserProfiles",
+                ExtendedUserProfileRowMapper.instance,
+                parameterSource);
+    }
 }
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 01c1327..3ec0a6f 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -3251,3 +3251,9 @@
     ON host_device.device_name = vm_device.device
     AND vm_static.dedicated_vm_for_vds = host_device.host_id
 WHERE vm_device.type = 'hostdev';
+
+CREATE OR REPLACE VIEW user_profiles_view AS
+SELECT user_profiles.*, users.name AS login_name
+FROM user_profiles
+INNER JOIN users ON user_profiles.user_id = users.user_id;
+
diff --git a/packaging/dbscripts/user_profiles_sp.sql 
b/packaging/dbscripts/user_profiles_sp.sql
index 1aee4d0..3258a3a 100644
--- a/packaging/dbscripts/user_profiles_sp.sql
+++ b/packaging/dbscripts/user_profiles_sp.sql
@@ -104,3 +104,13 @@
     WHERE  profile_id = v_profile_id;
 END; $procedure$
 LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION GetAllFromExtendedUserProfiles() RETURNS SETOF 
user_profiles_view STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT user_profiles_view.*
+      FROM user_profiles_view;
+END; $procedure$
+LANGUAGE plpgsql;


-- 
To view, visit https://gerrit.ovirt.org/40698
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic58b0e92ee416fb43661910632970055d3c23e8d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to