List of usage examples for org.hibernate Query setString
@Deprecated @SuppressWarnings("unchecked") default Query<R> setString(String name, String val)
From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java
License:Open Source License
/** * create or Update Discovery Result./* w w w .j av a 2s .c o m*/ * @param newResult the result to update. */ public void createOrUpdateDiscoveryResult(DiscoveryResultEntity newResult) throws AsmManagerCheckedException { Session session = null; Transaction tx = null; DiscoveryResultEntity discoveryResultEntity = new DiscoveryResultEntity(); try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); String hql = "from DiscoveryResultEntity where refId = :refId"; Query query = session.createQuery(hql); query.setString("refId", newResult.getRefId()); discoveryResultEntity = (DiscoveryResultEntity) query.setMaxResults(1).uniqueResult(); if (discoveryResultEntity == null) { discoveryResultEntity = new DiscoveryResultEntity(); discoveryResultEntity.setRefId(newResult.getRefId()); discoveryResultEntity.setRefType(newResult.getRefType()); discoveryResultEntity.setParentJobId(newResult.getParentJobId()); discoveryResultEntity.setJobId(newResult.getJobId()); } discoveryResultEntity.setDeviceRefId(newResult.getDeviceRefId()); discoveryResultEntity.setDeviceType(newResult.getDeviceType()); discoveryResultEntity.setStatus(newResult.getStatus()); discoveryResultEntity.setStatusMessage(newResult.getStatusMessage()); discoveryResultEntity.setServiceTag(newResult.getServiceTag()); discoveryResultEntity.setIpaddress(newResult.getIpaddress()); discoveryResultEntity.setModel(newResult.getModel()); //logger.info("serer count and iom count: " + newResult.getServerCount() + " : "+newResult.getIomCount()); discoveryResultEntity.setServerCount(newResult.getServerCount()); discoveryResultEntity.setIomCount(newResult.getIomCount()); discoveryResultEntity.setServerType(newResult.getServerType()); discoveryResultEntity.setHealthState(newResult.getHealthState()); discoveryResultEntity.setHealthStatusMsg(newResult.getHealthStatusMsg()); discoveryResultEntity.setVendor(newResult.getVendor()); discoveryResultEntity.setSystem_id(newResult.getSystem_id()); discoveryResultEntity.setUpdatedDate(new Date()); discoveryResultEntity.setUpdatedBy(_dao.extractUserFromRequest()); discoveryResultEntity.setFacts(newResult.getFacts()); discoveryResultEntity.setUnmanaged(newResult.isUnmanaged()); discoveryResultEntity.setReserved(newResult.isReserved()); discoveryResultEntity.setConfig(newResult.getConfig()); discoveryResultEntity.setDiscoverDeviceType(newResult.getDiscoverDeviceType()); discoveryResultEntity.setServerPoolId(newResult.getServerPoolId()); if (newResult.getFirmwareList() != null) for (FirmwareDeviceInventoryEntity fdie : newResult.getFirmwareList()) { discoveryResultEntity.addFirmwareDeviceInventoryEntity(fdie); } session.saveOrUpdate(discoveryResultEntity); // Commit transaction. tx.commit(); } catch (ConstraintViolationException cve) { logger.warn("Caught exception during discovery result creation: " + cve); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during create discovery result: " + ex); } if (cve.getConstraintName().contains("refid")) { //throw new AsmManagerDAOException(AsmManagerDAOException.REASON_CODE.DUPLICATE_JOBID, cve); throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.DUPLICATE_JOBID, AsmManagerMessages.duplicateRefId(cve.getSQLException().getMessage())); } else { //throw new AsmManagerDAOException(AsmManagerDAOException.REASON_CODE.DUPLICATE_RECORD, cve); throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.DUPLICATE_RECORD, AsmManagerMessages.duplicateRefId(cve.getSQLException().getMessage())); } } catch (Exception e) { logger.warn("Caught exception during update device: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during update device: " + ex); } if (e instanceof AsmManagerCheckedException) { throw e; } throw new AsmManagerInternalErrorException("Error updating the discovery result", "DiscoveryResultDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during update device: " + ex); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java
License:Open Source License
/** * Delete Discovery Result by parent job id. * @param parentJobId the parent job id used to delete from inventory. *///from w ww . ja v a 2 s . c om public void deleteDiscoveryResult(String parentJobId) { Session session = null; Transaction tx = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // execute command. String hql = "delete DiscoveryResultEntity where parentJobId=:parentJobId"; Query query = session.createQuery(hql); query.setString("parentJobId", parentJobId); int rowCount = query.executeUpdate(); logger.debug("Deleted record count=" + rowCount); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during delete discovery result: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during delete discovery result: " + ex); } //throw new AsmManagerDAOException("Caught exception during delete discovery result: ", e); throw new AsmManagerInternalErrorException("Error deleting discovery result", "DiscoveryResultDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during delete discovery result: " + ex); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java
License:Open Source License
public List<DiscoveryResultEntity> getDiscoveryResult(String parentJobId) throws AsmManagerDAOException { Session session = null;/* www. j a v a 2s . c o m*/ Transaction tx = null; List<DiscoveryResultEntity> entityList = new ArrayList<DiscoveryResultEntity>(); try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from DiscoveryResultEntity where parentJobId = :parentJobId order by ipAddress"; Query query = session.createQuery(hql); query.setString("parentJobId", parentJobId); for (Object result : query.list()) { entityList.add((DiscoveryResultEntity) result); } // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get all discovery results: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all discovery results: " + ex); } throw new AsmManagerInternalErrorException("Error Getting Discovery result", "DiscoveryResultDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get all discovery results: " + ex); } } return entityList; }
From source file:com.dell.asm.asmcore.asmmanager.db.DiscoveryResultDAO.java
License:Open Source License
/** * Delete a single Discovery Result record by device id * @param refId device id./*w w w. j a v a 2 s. co m*/ */ public void deleteDiscoveryResultByRefId(String refId) { Session session = null; Transaction tx = null; int rowCount = 0; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // execute command. String hql = "delete DiscoveryResultEntity where refId=:refId"; Query query = session.createQuery(hql); query.setString("refId", refId); rowCount = query.executeUpdate(); logger.debug("Deleted record count=" + rowCount); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during delete discovery result: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during delete discovery result: " + ex); } //throw new AsmManagerDAOException("Caught exception during delete discovery result: ", e); throw new AsmManagerInternalErrorException("Error deleting discovery result", "DiscoveryResultDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during delete discovery result: " + ex); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.FirmwareRepositoryDAO.java
License:Open Source License
public FirmwareRepositoryEntity get(final String id) { if (StringUtils.isBlank(id)) { return null; }/*from www . j ava 2s.c o m*/ Session session = null; Transaction tx = null; try { session = dao.getNewSession(); tx = session.beginTransaction(); final String hql = "from FirmwareRepositoryEntity where id = :id"; final Query query = session.createQuery(hql); query.setString("id", id); return (FirmwareRepositoryEntity) query.uniqueResult(); } catch (Exception e) { logger.warn("Caught exception during get: " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get: " + ex); } throw new AsmManagerInternalErrorException("get", "FirmwareRepositoryDao", e); } finally { dao.cleanupSession(session, "get"); } }
From source file:com.dell.asm.asmcore.asmmanager.db.FirmwareRepositoryDAO.java
License:Open Source License
public void delete(final String firmwareRepositoryId) { if (StringUtils.isBlank(firmwareRepositoryId)) { return;// w w w .j a v a2 s . c om } logger.info("Deleting firmware repository: " + firmwareRepositoryId); Session session = null; Transaction tx = null; try { session = dao.getNewSession(); tx = session.beginTransaction(); String hql = "delete FirmwareRepositoryEntity where id = :id"; Query query = session.createQuery(hql); query.setString("id", firmwareRepositoryId); query.executeUpdate(); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during delete: " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during delete: " + ex); } throw new AsmManagerInternalErrorException("Delete", "FirmewareRepositoryDAO", e); } finally { } }
From source file:com.dell.asm.asmcore.asmmanager.db.FirmwareRepositoryDAO.java
License:Open Source License
public FirmwareRepositoryEntity getCompleteFirmware(String id, boolean bundles, boolean components) { Session session = null;/*from w w w .jav a 2 s .com*/ Transaction tx = null; FirmwareRepositoryEntity firmware = null; try { session = dao.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from FirmwareRepositoryEntity where id = :id"; Query query = session.createQuery(hql); query.setString("id", id); firmware = (FirmwareRepositoryEntity) query.setMaxResults(1).uniqueResult(); if (firmware != null) { hydrateFirmware(firmware, bundles, components); } // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get firmwarerepository for id: " + id + ", " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get by id: " + ex); } throw new AsmManagerInternalErrorException("Retrieve firmwarerepository", "GenericDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during getCompleteFirmware: " + ex); } } return firmware; }
From source file:com.dell.asm.asmcore.asmmanager.db.FirmwareRepositoryDAO.java
License:Open Source License
public FirmwareRepositoryEntity getFirmwareWithUsedBy(String id) { Session session = null;/*from www. j a v a2s .co m*/ Transaction tx = null; FirmwareRepositoryEntity firmware = null; try { session = dao.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from FirmwareRepositoryEntity where id = :id"; Query query = session.createQuery(hql); query.setString("id", id); firmware = (FirmwareRepositoryEntity) query.setMaxResults(1).uniqueResult(); if (firmware != null) { // initialize templates but not deployments as they are eager fetch. Hibernate.initialize(firmware.getTemplates()); } // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during getFirmwareWithUsedBy for id: " + id + ", " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get by id: " + ex); } throw new AsmManagerInternalErrorException("Retrieve getFirmwareWithUsedBy", "GenericDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during getFirmwareWithUsedBy: " + ex); } } return firmware; }
From source file:com.dell.asm.asmcore.asmmanager.db.FirmwareRepositoryDAO.java
License:Open Source License
/** * Will return a list of SoftwareComponentEntities for the given firmware repository where the operating_system * field is not null. /*from w ww .j av a 2 s .co m*/ */ public List<SoftwareComponentEntity> getSoftwareComponentEntitiesWithOperatingSystem(String firmwareRepoId, String operatingSystem) { ArrayList<SoftwareComponentEntity> softwareComponentEntities = new ArrayList<SoftwareComponentEntity>(); Session session = null; Transaction tx = null; try { session = dao.getNewSession(); tx = session.beginTransaction(); String hql = "from SoftwareComponentEntity where firmware_repository = :firmwareRepoId AND operating_system = :operatingSystem"; Query query = session.createQuery(hql); query.setString("firmwareRepoId", firmwareRepoId); query.setString("operatingSystem", operatingSystem); for (Object result : query.list()) { softwareComponentEntities.add((SoftwareComponentEntity) result); } tx.commit(); } catch (Exception e) { logger.warn("Error in getSoftwareComponentEntitiesForFirmwareRepository for firmwareId of " + firmwareRepoId + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn( "Unable to rollback transaction during getSoftwareComponentEntitiesForFirmwareRepository" + ex); } throw new AsmManagerInternalErrorException("getSoftwareComponentEntitiesForFirmwareRepository", "FirmwareRepositoryDAO", e); } finally { dao.cleanupSession(session, "getSoftwareComponentEntitiesForFirmwareRepository"); } return softwareComponentEntities; }
From source file:com.dell.asm.asmcore.asmmanager.db.MapRazorNodeNameToSerialNumberDAO.java
License:Open Source License
/** * Retrieve Device Inventory.// w ww. j a va2s . co m * @return the entity */ public MapRazorNodeNameToSerialNumberEntity getRazorNodeById(String Id) { Session session = null; Transaction tx = null; MapRazorNodeNameToSerialNumberEntity deviceInventoryEntity = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from MapRazorNodeNameToSerialNumberEntity where id = :id"; Query query = session.createQuery(hql); query.setString("id", Id); deviceInventoryEntity = (MapRazorNodeNameToSerialNumberEntity) query.setMaxResults(1).uniqueResult(); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn( "Caught exception during get MapRazorNodeNameToSerialNumberEntity for refId: " + Id + ", " + e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get device: " + ex); } throw new AsmManagerInternalErrorException("Retrieve device", "MapRazorNodeNameToSerialNumberDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get device: " + ex); } } return deviceInventoryEntity; }