Omer Frenkel has uploaded a new change for review.

Change subject: core: add get*Type to template DAO
......................................................................

core: add get*Type to template DAO

Change-Id: Ic9f0eef1e61b51cc941b8dd9403f5733a69f9dfc
Signed-off-by: Omer Frenkel <[email protected]>
---
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
4 files changed, 153 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/12280/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
index 98333ee..e24b873 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAO.java
@@ -4,6 +4,8 @@
 import java.util.Map;
 
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
+import org.ovirt.engine.core.common.businessentities.ImageType;
+import org.ovirt.engine.core.common.businessentities.InstanceType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
 import org.ovirt.engine.core.compat.Guid;
@@ -125,4 +127,20 @@
      * @return the list of VmTemplates
      */
     List<VmTemplate> getAllForNetwork(Guid networkId);
+
+    /**
+     * Retrieve the instance type with the given id
+     * @param id
+     *            the instance type id
+     * @return the instance type
+     */
+    InstanceType getInstanceType(Guid id);
+
+    /**
+     * Retrieve the image type with the given id
+     * @param id
+     *            the image type id
+     * @return the image type
+     */
+    ImageType getImageType(Guid id);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
index 7452857..e0c7ab1 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/VmTemplateDAODbFacadeImpl.java
@@ -9,6 +9,8 @@
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
+import org.ovirt.engine.core.common.businessentities.ImageType;
+import org.ovirt.engine.core.common.businessentities.InstanceType;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
 import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum;
 import org.ovirt.engine.core.common.businessentities.TemplateType;
@@ -32,6 +34,22 @@
         return get(id, null, false);
     }
 
+    public InstanceType getInstanceType(Guid id) {
+        VmTemplate result = get(id);
+        if (result != null && result.getTemplateType() != 
TemplateType.INSTANCE_TYPE) {
+            result = null;
+        }
+        return result;
+    }
+
+    public ImageType getImageType(Guid id) {
+        VmTemplate result = get(id);
+        if (result != null && result.getTemplateType() != 
TemplateType.IMAGE_TYPE) {
+            result = null;
+        }
+        return result;
+    }
+
     @Override
     public VmTemplate get(Guid id, Guid userID, boolean isFiltered) {
         return getCallsHandler().executeRead("GetVmTemplateByVmtGuid",
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
index 7a62876..f5684c5 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/VmTemplateDAOTest.java
@@ -14,6 +14,7 @@
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.Transformer;
 import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.InstanceType;
 import org.ovirt.engine.core.common.businessentities.VmTemplate;
 import org.ovirt.engine.core.common.businessentities.VmTemplateStatus;
 import org.ovirt.engine.core.compat.Guid;
@@ -25,6 +26,8 @@
     private static final Guid DELETABLE_TEMPLATE_ID = new 
Guid("1b85420c-b84c-4f29-997e-0eb674b40b80");
     private static final Guid STORAGE_DOMAIN_ID = new 
Guid("72e3a666-89e1-4005-a7ca-f7548004a9ab");
     private static final Guid VDS_GROUP_ID = new 
Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1");
+    private static final Guid EXISTING_INSTANCE_TYPE_ID = new 
Guid("99408929-82cf-4dc7-a532-9d998063fa95");
+    private static final Guid EXISTING_IMAGE_TYPE_ID = new 
Guid("5849b030-626e-47cb-ad90-3ce782d831b3");
 
     private VmTemplateDAO dao;
 
@@ -67,6 +70,28 @@
     }
 
     /**
+     * Ensures that the template returned is instance type.
+     */
+    @Test
+    public void testGetInstanceType() {
+        InstanceType result = dao.getInstanceType(EXISTING_INSTANCE_TYPE_ID);
+
+        assertNotNull(result);
+        assertEquals(EXISTING_INSTANCE_TYPE_ID, result.getId());
+    }
+
+    /**
+     * Ensures that the template returned is instance type.
+     */
+    @Test
+    public void testGetImageType() {
+        InstanceType result = dao.getInstanceType(EXISTING_IMAGE_TYPE_ID);
+
+        assertNotNull(result);
+        assertEquals(EXISTING_IMAGE_TYPE_ID, result.getId());
+    }
+
+    /**
      * Ensures that all templates are returned.
      */
     @Test
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 1b9490e..887af4d 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -1259,6 +1259,98 @@
             <null />
             <null />
         </row>
+         <row>
+            <value>99408929-82cf-4dc7-a532-9d998063fa95</value>
+            <value>INSTACE_TYPE</value>
+            <value>1</value>
+            <value>512</value>
+            <value>00000000-0000-0000-0000-000000000000</value>
+            <value>1</value>
+            <null />
+            <value>eba797fb-8e3b-4777-b63c-92e7a5957d7c</value>
+            <value></value>
+            <value>2010-11-21 16:39:27</value>
+            <value>0</value>
+            <value>1</value>
+            <value>false</value> <!-- allow_console_reconnect -->
+            <null />
+            <value>0</value>
+            <value>1</value>
+            <value>1</value>
+            <value>0</value>
+            <value>1</value>
+            <value>GMT standard time</value>
+            <value>0</value>
+            <value>1</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
+            <value>0</value>
+            <value>0</value>
+            <value>12</value>
+            <value>0</value>
+            <value>0</value>
+            <value></value>
+            <value>0</value>
+            <value></value>
+            <value></value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
+            <null />
+            <null />
+            <null />
+        </row>
+         <row>
+            <value>5849b030-626e-47cb-ad90-3ce782d831b3</value>
+            <value>IMAGE_TYPE</value>
+            <value>1</value>
+            <value>512</value>
+            <value>00000000-0000-0000-0000-000000000000</value>
+            <value>1</value>
+            <null />
+            <value>eba797fb-8e3b-4777-b63c-92e7a5957d7c</value>
+            <value></value>
+            <value>2010-11-21 16:39:27</value>
+            <value>0</value>
+            <value>1</value>
+            <value>false</value> <!-- allow_console_reconnect -->
+            <null />
+            <value>0</value>
+            <value>1</value>
+            <value>1</value>
+            <value>0</value>
+            <value>1</value>
+            <value>GMT standard time</value>
+            <value>0</value>
+            <value>1</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
+            <value>0</value>
+            <value>0</value>
+            <value>12</value>
+            <value>0</value>
+            <value>0</value>
+            <value></value>
+            <value>0</value>
+            <value></value>
+            <value></value>
+            <value>0</value>
+            <value>0</value>
+            <null />
+            <null />
+            <null />
+            <value>1</value>
+            <null />
+            <null />
+            <null />
+        </row>
 
         <!-- VMS -->
         <row>


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

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

Reply via email to