- et.begin();
- final Query query = em.createQuery("select b from BrmsGroupInfo as b where b.controllerName = :cn");
- query.setParameter("cn", name);
- final List<?> groupList = query.getResultList();
- BrmsGroupInfo brmsGroupInfo = null;
- if (!groupList.isEmpty()) {
- LOGGER.info("Controller name already Existing in DB. Will be updating the DB Values" + name);
- brmsGroupInfo = (BrmsGroupInfo) groupList.get(0);
- }
- if (brmsGroupInfo == null) {
- brmsGroupInfo = new BrmsGroupInfo();
+ try {
+ et.begin();
+ final TypedQuery<BrmsGroupInfo> query = em
+ .createQuery("select b from BrmsGroupInfo as b where b.controllerName = :cn", BrmsGroupInfo.class);
+ query.setParameter("cn", name);
+ final List<BrmsGroupInfo> groupList = query.getResultList();
+ BrmsGroupInfo brmsGroupInfo = null;
+ if (!groupList.isEmpty()) {
+ LOGGER.info("Controller name already Existing in DB. Will be updating the DB Values" + name);
+ brmsGroupInfo = groupList.get(0);
+ }
+ if (brmsGroupInfo == null) {
+ brmsGroupInfo = new BrmsGroupInfo();
+ }
+ brmsGroupInfo.setControllerName(name);
+ brmsGroupInfo.setGroupId(dependency.getGroupId());
+ brmsGroupInfo.setArtifactId(dependency.getArtifactId());
+ brmsGroupInfo.setVersion(dependency.getVersion());
+ em.persist(brmsGroupInfo);
+ em.flush();
+ et.commit();
+
+ final ArrayList<Object> values = new ArrayList<>();
+ values.add(dependency);
+ groupMap.put(name, values);
+ } catch (final Exception exception) {
+ LOGGER.error("Unable add/update policy group to database for controller name: " + name, exception);
+ et.rollback();
+ throw exception;