Yair Zaslavsky has uploaded a new change for review.

Change subject: Core: Changing EntityMapSqlMapper
......................................................................

Core: Changing EntityMapSqlMapper

Changing this class to support mapping of objects
of any class.
The motivation is that we might to run batch jobs on constructs
that are not business entities (for example - a touple of
Guid,Guid,VdcObjectType to mark AsyncTask entity association -
I prefer not to have redundant code for creation business
entity for that)
In addition, the code for using the mapper was moved to the
CallsHandler, as MassOPerationsDao relies on a generic type
which extends BusinessEntity

Change-Id: I06291792ab70928de39fc2d12c40d4b2d247a2eb
Signed-off-by: Yair Zaslavsky <[email protected]>
---
D 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/EntityToMapSqlParameterMapper.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/MapSqlParameterMapper.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
5 files changed, 63 insertions(+), 46 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/16202/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/EntityToMapSqlParameterMapper.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/EntityToMapSqlParameterMapper.java
deleted file mode 100644
index e0fec6d..0000000
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/EntityToMapSqlParameterMapper.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package org.ovirt.engine.core.dal.dbbroker;
-
-import org.ovirt.engine.core.common.businessentities.BusinessEntity;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
-
-public interface EntityToMapSqlParameterMapper<T extends BusinessEntity<?>> {
-    public MapSqlParameterSource map(T entity);
-}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/MapSqlParameterMapper.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/MapSqlParameterMapper.java
new file mode 100644
index 0000000..ce2872f
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/MapSqlParameterMapper.java
@@ -0,0 +1,7 @@
+package org.ovirt.engine.core.dal.dbbroker;
+
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+public interface MapSqlParameterMapper<T> {
+    public MapSqlParameterSource map(T entity);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
index acde18b..f06587f 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/SimpleJdbcCallsHandler.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.core.dal.dbbroker;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -36,8 +38,11 @@
 
     /**
      * Runs a set of stored procedure calls in a batch. Only useful for update 
procedures that return no value
-     * @param procedureName the procedure name
-     * @param executions a list of parameter maps
+     *
+     * @param procedureName
+     *            the procedure name
+     * @param executions
+     *            a list of parameter maps
      * @return
      */
     public void executeStoredProcAsBatch(final String procName,
@@ -45,6 +50,24 @@
             throws DataAccessException {
 
         template.execute(new BatchProcedureExecutionConnectionCallback(this, 
procName, executions));
+    }
+
+    /**
+     * Runs a set of stored procedure calls in a batch. Only useful for update 
procedures that return no value
+     * @param procedureName the procedure name
+     * @param paramValues list of objects to be converted to {@link 
MapSqlParameterSource}
+     * @param mapper mapper to use to convert the param value objects to 
{@liunk MapSqlParameterSource}
+     */
+    public <T> void executeStoredProcAsBatch(final String procedureName,
+            Collection<T> paramValues,
+            MapSqlParameterMapper<T> mapper) {
+        List<MapSqlParameterSource> sqlParams = new ArrayList<>();
+
+        for (T param : paramValues) {
+            sqlParams.add(mapper.map(param));
+        }
+
+        executeStoredProcAsBatch(procedureName, sqlParams);
     }
 
     public Map<String, Object> executeModification(final String procedureName, 
final MapSqlParameterSource paramSource) {
@@ -95,18 +118,18 @@
             final RowMapper<?> mapper,
             final MapSqlParameterSource parameterSource) {
         return new CallCreator() {
-                @Override
-                public SimpleJdbcCall createCall() {
-                    SimpleJdbcCall call =
-                            (SimpleJdbcCall) 
dialect.createJdbcCallForQuery(template).withProcedureName(procedureName);
-                    
call.returningResultSet(BaseDAODbFacade.RETURN_VALUE_PARAMETER, mapper);
-                    // Pass mapper information (only parameter names) in order 
to supply all the needed
-                    // metadata information for compilation.
-                    call.getInParameterNames().addAll(
-                            
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource).keySet());
-                    return call;
-                }
-            };
+            @Override
+            public SimpleJdbcCall createCall() {
+                SimpleJdbcCall call =
+                        (SimpleJdbcCall) 
dialect.createJdbcCallForQuery(template).withProcedureName(procedureName);
+                
call.returningResultSet(BaseDAODbFacade.RETURN_VALUE_PARAMETER, mapper);
+                // Pass mapper information (only parameter names) in order to 
supply all the needed
+                // metadata information for compilation.
+                call.getInParameterNames().addAll(
+                        
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource).keySet());
+                return call;
+            }
+        };
     }
 
     CallCreator createCallForModification(final String procedureName) {
@@ -125,13 +148,14 @@
     }
 
     /**
-     * Creates a call object and compiles its metadata, if not found in the 
map.
-     * Bare in mind the existence check if not atomic, so at worst case few 
more redundant information schema calls
-     * * will be made.
-     * The compilation is done at the scope of the method in order to avoid 
concurrency issues upon first time usage of
-     * the stored procedure.
-     * @param procedureName stored proceudre name
-     * @param callCreator calls creator object
+     * Creates a call object and compiles its metadata, if not found in the 
map. Bare in mind the existence check if not
+     * atomic, so at worst case few more redundant information schema calls * 
will be made. The compilation is done at
+     * the scope of the method in order to avoid concurrency issues upon first 
time usage of the stored procedure.
+     *
+     * @param procedureName
+     *            stored proceudre name
+     * @param callCreator
+     *            calls creator object
      * @return simple JDBC call object
      */
     protected SimpleJdbcCall getCall(String procedureName, CallCreator 
callCreator) {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
index afebf02..a40308c 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsDao.java
@@ -4,7 +4,7 @@
 import java.util.Collection;
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
-import org.ovirt.engine.core.dal.dbbroker.EntityToMapSqlParameterMapper;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 
 /**
  * Data Access Object which supports mass operations for the given entity type.
@@ -26,25 +26,28 @@
      */
     void updateAll(Collection<T> entities);
 
-
     /**
      * Updates the given entities using a more efficient method to update all 
of them at once, rather than each at a
      * time.
-     * @param procedureName procedure name for update
+     *
+     * @param procedureName
+     *            procedure name for update
      * @param entities
      */
     void updateAll(String procedureName, Collection<T> entities);
 
     /**
      * Removes the entities with given ids
+     *
      * @param ids
      */
     void removeAll(Collection<ID> ids);
 
     /**
      * Calls an update stored procedure multiple timse in a batch
+     *
      * @param procedureName
      * @param entities
      */
-    void updateAllInBatch(String procedureName, Collection<T> paramValues, 
EntityToMapSqlParameterMapper<T> mapper);
+    void updateAllInBatch(String procedureName, Collection<T> paramValues, 
MapSqlParameterMapper<T> mapper);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
index a65dd39..dcff3f5 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/MassOperationsGenericDaoDbFacade.java
@@ -1,13 +1,10 @@
 package org.ovirt.engine.core.dao;
 
 import java.io.Serializable;
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
-import org.ovirt.engine.core.dal.dbbroker.EntityToMapSqlParameterMapper;
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
 
 /**
  * Implementation for the {@link MassOperationsDao} which provides a default
@@ -28,7 +25,7 @@
 
     @Override
     public void updateAll(Collection<T> entities) {
-        updateAll(getProcedureNameForUpdate(),entities);
+        updateAll(getProcedureNameForUpdate(), entities);
     }
 
     @Override
@@ -51,15 +48,9 @@
      */
     public void updateAllInBatch(String procedureName,
             Collection<T> paramValues,
-            EntityToMapSqlParameterMapper<T> mapper) {
-        List<MapSqlParameterSource> sqlParams = new ArrayList<>();
-
-        for (T param : paramValues) {
-            sqlParams.add(mapper.map(param));
-        }
-
+            MapSqlParameterMapper<T> mapper) {
         getCallsHandler().executeStoredProcAsBatch(procedureName == null ? 
getProcedureNameForUpdate() : procedureName,
-                sqlParams);
+                paramValues, mapper);
     }
 
     @Override


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

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

Reply via email to