SB 2.x Migration for portal widget mS
[portal.git] / ecomp-portal-widget-ms / widget-ms / src / main / java / org / onap / portalapp / widget / service / impl / WidgetCatalogServiceImpl.java
index b99863e..f5558e2 100644 (file)
@@ -191,7 +191,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                        Transaction tx = session.beginTransaction();            
                        session.save(newWidgetCatalog);
                        tx.commit();
-                       session.flush();
+                       //session.flush();
                        session.close();
                        updateAppId(newWidgetCatalog.getId(), newWidgetCatalog.getWidgetRoles());
                }
@@ -217,7 +217,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                        Transaction tx = session.beginTransaction();
                        session.update(newWidgetCatalog);
                        tx.commit();
-                       session.flush();
+                       //session.flush();
                        session.close();
                        updateAppId(newWidgetCatalog.getId(), newWidgetCatalog.getWidgetRoles());
                }catch(Exception e){
@@ -244,16 +244,15 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                logger.debug("WidgetCatalogServiceImpl.getWidgetCatalog: result={}", widgets);
                return widgets;
        }
-       
-       
-       
-       
-       
+
        private void updateAppId(long widgetId, Set<RoleApp> roles){
                Session session = sessionFactory.openSession();
                for(RoleApp role: roles){
-                       String sql = "UPDATE ep_widget_catalog_role SET app_id = " + role.getApp().getAppId() + " WHERE widget_id = " + widgetId + " AND ROLE_ID = " + role.getRoleId() ;
+                       String sql = "UPDATE ep_widget_catalog_role SET app_id = :appId WHERE widget_id = :widgetId AND ROLE_ID = :roleId" ;
                        Query query = session.createSQLQuery(sql);
+                       query.setParameter("appId", role.getApp().getAppId());
+                       query.setParameter("widgetId", widgetId);
+                       query.setParameter("roleId", role.getRoleId());
                        query.executeUpdate();
                }
                session.flush();
@@ -269,7 +268,7 @@ public class WidgetCatalogServiceImpl implements WidgetCatalogService {
                
                List<MicroserviceData> widgets = criteria.list();
                logger.debug("WidgetCatalogServiceImpl.getWidgetIdByName: result={}", widgets);
-               session.flush();
+//             session.flush();
                session.close();
                
                return (widgets.size() > 0) ? true : false;