Francesco Romani has uploaded a new change for review. Change subject: WIP: core: bulk queries for VMConsoleProxyServlet ......................................................................
WIP: core: bulk queries for VMConsoleProxyServlet Change-Id: Id60c40f7f7d19d1622ca5fdbe34f2a90942be51d Signed-off-by: Francesco Romani <from...@redhat.com> --- A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/UserProfileView.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmConsole.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, 145 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/20/40620/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/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmConsole.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmConsole.java new file mode 100644 index 0000000..17de99a --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmConsole.java @@ -0,0 +1,54 @@ +package org.ovirt.engine.core.common.businessentities; + +import org.ovirt.engine.core.common.utils.ObjectUtils; +import org.ovirt.engine.core.compat.Guid; + +import javax.validation.constraints.Size; + + +public class VmConsole extends IVdcQueryable { + private static final long serialVersionUID = -2753306386502558044L; // FIXME + + private Guid vm_guid; + + private String vm_name; + + private String address; + + public void setVmGuid(Guid vm_guid) { this.vm_guid = vm_guid; } + + public Guid getVmGuid() { return vm_guid; } + + public void setAddress(String address) { this.address = address; } + + public String getAddress() { return address; } + + public void setVmName(String vm_name) { this.vm_name = vm_name; } + + public String getVmName() { return vm_name; } + + public VmConsole() { + vm_guid = Guid.Empty; + } + + @Override + public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + + return ObjectUtils.objectsEqual(vm_guid, other.vm_guid) && + ObjectUtils.objectsEqual(vm_name, other.vm_name) && + ObjectUtils.objectsEqual(address, other.address); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = prime; + result = prime * result + ((vm_guid == null) ? 0 : vm_guid.hashCode()); + result = prime * result + ((vm_name == null) ? 0 : vm_name.hashCode()); + result = prime * result + ((address == null) ? 0 : address.hashCode()); + return result; + } + +} 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..d4a66e6 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,11 @@ getCallsHandler().executeModification("DeleteUserProfile", parameterSource); } + + 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..2e0e2f3 100644 --- a/packaging/dbscripts/create_views.sql +++ b/packaging/dbscripts/create_views.sql @@ -3251,3 +3251,13 @@ 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; + +CREATE OR REPLACE VIEW vm_consoles AS +SELECT vms.vm_guid, vms.vm_name, vds_interface.addr, '' AS name +FROM vms +INNER JOIN vds_interface ON vms.run_on_vds = vds_interface.vds_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/40620 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id60c40f7f7d19d1622ca5fdbe34f2a90942be51d 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