Daniel Erez has uploaded a new change for review.

Change subject: core: introduce LibvirtSecretDao
......................................................................

core: introduce LibvirtSecretDao

Added LibvirtSecretDao and corresponding
LibvirtSecretDaoDbFacadeImpl to support CRUD
for LibvirtSecrets.

Change-Id: I33625086f2f7bcaef755b8e75b8ba07f688f33b2
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Daniel Erez <[email protected]>
---
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDaoDbFacadeImpl.java
A packaging/dbscripts/libvirt_secrets_sp.sql
3 files changed, 206 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/41551/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDao.java
new file mode 100644
index 0000000..02c0b78
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDao.java
@@ -0,0 +1,49 @@
+package org.ovirt.engine.core.dao;
+
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+import org.ovirt.engine.core.compat.Guid;
+
+import java.util.List;
+
+/**
+ * <code>LibvirtSecretDao</code> defines a type which performs CRUD operations 
on instances of {@link LibvirtSecret}.
+ */
+public interface LibvirtSecretDao extends DAO, GenericDao<LibvirtSecret, Guid> 
{
+    /**
+     * Retrieves the secret with the specified id.
+     *
+     * @param id the id
+     * @return the engine secret
+     */
+    LibvirtSecret get(Guid id);
+
+    /**
+     * Saves the specified secret
+     *
+     * @param secret the secret
+     */
+    void save(LibvirtSecret secret);
+
+    /**
+     * Updates the specified secret
+     *
+     * @param secret the secret
+     */
+    void update(LibvirtSecret secret);
+
+    /**
+     * Removes the secret with the specified secret_uuid.
+     *
+     * @param secret_uuid
+     */
+    void remove(Guid secret_uuid);
+
+    /**
+     * Retrieves all secrets for the specified provider id.
+     *
+     * @param providerId
+     *            The provider id
+     * @return the list of secrets
+     */
+    List<LibvirtSecret> getAllByProviderId(Guid providerId);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDaoDbFacadeImpl.java
new file mode 100644
index 0000000..118188e
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/LibvirtSecretDaoDbFacadeImpl.java
@@ -0,0 +1,70 @@
+package org.ovirt.engine.core.dao;
+
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+import 
org.ovirt.engine.core.common.businessentities.storage.LibvirtSecretUsageType;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.DbFacadeUtils;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+/**
+ * <code>LibvirtSecretDaoDbFacadeImpl</code> provides an implementation of 
{@link LibvirtSecretDao}.
+ */
+@Named
+@Singleton
+public class LibvirtSecretDaoDbFacadeImpl extends 
DefaultGenericDaoDbFacade<LibvirtSecret, Guid> implements LibvirtSecretDao {
+
+    LibvirtSecretDaoDbFacadeImpl() {
+        super("LibvirtSecret");
+    }
+
+    @Override
+    protected MapSqlParameterSource createFullParametersMapper(LibvirtSecret 
entity) {
+        return createIdParameterMapper(entity.getId())
+                .addValue("secret_value", 
DbFacadeUtils.encryptPassword(entity.getValue()))
+                .addValue("secret_usage_type", entity.getUsageType())
+                .addValue("secret_description", entity.getDescription())
+                .addValue("provider_id", entity.getProviderId())
+                .addValue("creation_date", entity.getCreationDate());
+    }
+
+    @Override
+    protected MapSqlParameterSource createIdParameterMapper(Guid uuid) {
+        return getCustomMapSqlParameterSource().addValue("secret_uuid", uuid);
+    }
+
+    @Override
+    protected RowMapper<LibvirtSecret> createEntityRowMapper() {
+        return LibvirtSecretRowMapper.instance;
+    }
+
+    private static class LibvirtSecretRowMapper implements 
RowMapper<LibvirtSecret> {
+        public static final LibvirtSecretRowMapper instance = new 
LibvirtSecretRowMapper();
+
+        @Override
+        public LibvirtSecret mapRow(ResultSet rs, int rowNum) throws 
SQLException {
+            LibvirtSecret entity = new LibvirtSecret();
+
+            entity.setId(getGuid(rs, "secret_uuid"));
+            
entity.setValue(DbFacadeUtils.decryptPassword(rs.getString("secret_value")));
+            
entity.setUsageType(LibvirtSecretUsageType.forValue(rs.getInt(("secret_usage_type"))));
+            entity.setDescription(rs.getString("secret_description"));
+            entity.setProviderId(getGuid(rs, "provider_id"));
+            
entity.setCreationDate(DbFacadeUtils.fromDate(rs.getTimestamp("creation_date")));
+            return entity;
+        }
+    }
+
+    @Override
+    public List<LibvirtSecret> getAllByProviderId(Guid providerId) {
+        return 
getCallsHandler().executeReadList("GetAllLibvirtSecretsByProviderId",
+                LibvirtSecretRowMapper.instance,
+                getCustomMapSqlParameterSource().addValue("provider_id", 
providerId));
+    }
+}
diff --git a/packaging/dbscripts/libvirt_secrets_sp.sql 
b/packaging/dbscripts/libvirt_secrets_sp.sql
new file mode 100644
index 0000000..185fec1
--- /dev/null
+++ b/packaging/dbscripts/libvirt_secrets_sp.sql
@@ -0,0 +1,87 @@
+----------------------------------------------------------------------
+--  Libvirt Secrets Table
+----------------------------------------------------------------------
+
+Create or replace FUNCTION GetLibvirtSecretByLibvirtSecretId(v_secret_uuid 
UUID)
+RETURNS SETOF libvirt_secrets STABLE
+   AS $procedure$
+BEGIN
+
+   RETURN QUERY SELECT *
+   FROM libvirt_secrets
+   WHERE secret_uuid = v_secret_uuid;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION InsertLibvirtSecret(v_secret_uuid UUID,
+  v_secret_value TEXT,
+  v_secret_usage_type integer,
+  v_secret_description TEXT,
+  v_provider_id UUID,
+  v_creation_date TIMESTAMP WITH TIME ZONE)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+
+   INSERT INTO libvirt_secrets(secret_uuid, secret_value, secret_usage_type, 
secret_description, provider_id, creation_date)
+       VALUES(v_secret_uuid, v_secret_value, v_secret_usage_type, 
v_secret_description, v_provider_id, v_creation_date);
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION UpdateLibvirtSecret(v_secret_uuid UUID,
+  v_secret_value TEXT,
+  v_secret_usage_type integer,
+  v_secret_description TEXT,
+  v_provider_id UUID,
+  v_creation_date TIMESTAMP WITH TIME ZONE)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+
+   UPDATE libvirt_secrets
+   SET secret_uuid = v_secret_uuid, secret_value = v_secret_value, 
secret_usage_type = v_secret_usage_type,
+       secret_description = v_secret_description, provider_id = v_provider_id, 
creation_date = v_creation_date,
+       _update_date = LOCALTIMESTAMP
+   WHERE secret_uuid = v_secret_uuid;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteLibvirtSecret(v_secret_uuid UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+
+    DELETE FROM libvirt_secrets
+    WHERE secret_uuid = v_secret_uuid;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetAllFromLibvirtSecrets()
+RETURNS SETOF libvirt_secrets STABLE
+   AS $procedure$
+BEGIN
+
+   RETURN QUERY SELECT *
+   FROM libvirt_secrets;
+
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetAllLibvirtSecretsByProviderId(v_provider_id UUID)
+RETURNS SETOF libvirt_secrets STABLE
+   AS $procedure$
+BEGIN
+   RETURN QUERY SELECT *
+   FROM libvirt_secrets
+   WHERE provider_id = v_provider_id;
+END; $procedure$
+LANGUAGE plpgsql;
\ No newline at end of file


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

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

Reply via email to