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.DeviceInventoryDAO.java
License:Open Source License
/** * Retrieve Device Inventory./* ww w.j a va 2 s .com*/ * * @return the entity */ public DeviceInventoryEntity getDeviceInventory(String refId) { Session session = null; Transaction tx = null; DeviceInventoryEntity deviceInventoryEntity = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from DeviceInventoryEntity where refId = :refId"; Query query = session.createQuery(hql); query.setString("refId", refId); deviceInventoryEntity = (DeviceInventoryEntity) query.setMaxResults(1).uniqueResult(); if (deviceInventoryEntity != null) { Hibernate.initialize(deviceInventoryEntity.getDeviceInventoryComplianceEntities()); } this.setFirmwareBasedOnDeployment(deviceInventoryEntity); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get device for refId: " + refId + ", " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.error("Unable to rollback transaction during get device: " + refId, ex); } // not found landed hee // throw new AsmManagerInternalErrorException("Retrieve device", "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get device: " + ex); } } return deviceInventoryEntity; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
public DeviceInventoryEntity getDeviceInventoryByServiceTag(String serviceTag) { Session session = null;// w w w. ja va 2s. c om Transaction tx = null; DeviceInventoryEntity deviceInventoryEntity = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from DeviceInventoryEntity where serviceTag = :serviceTag"; Query query = session.createQuery(hql); query.setString("serviceTag", serviceTag); deviceInventoryEntity = (DeviceInventoryEntity) query.setMaxResults(1).uniqueResult(); this.setFirmwareBasedOnDeployment(deviceInventoryEntity); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get device for serviceTag: " + serviceTag + ", " + e, 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", "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get device: " + ex); } } return deviceInventoryEntity; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
/** * Update Device Inventory.//from w w w .j a v a 2 s . c o m * * @param newDevice the device to update. */ public void updateDeviceInventory(DeviceInventoryEntity newDevice) throws AsmManagerCheckedException { Session session = null; Transaction tx = null; logger.info("DeviceInventoryDAO.updateDeviceInventory for device with refId " + newDevice.getRefId()); logger.info( "DeviceInventoryDAO.updateDeviceInventory for device with ipAddress " + newDevice.getIpAddress()); logger.info( "DeviceInventoryDAO.updateDeviceInventory for device with serviceTag " + newDevice.getServiceTag()); try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); String hql = "from DeviceInventoryEntity where refId = :refId"; Query query = session.createQuery(hql); query.setString("refId", newDevice.getRefId()); DeviceInventoryEntity deviceInventoryEntity = (DeviceInventoryEntity) query.setMaxResults(1) .uniqueResult(); if (deviceInventoryEntity == null) { throw new AsmManagerCheckedException(AsmManagerCheckedException.REASON_CODE.RECORD_NOT_FOUND, AsmManagerMessages.notFound(newDevice.getRefId())); } deviceInventoryEntity.setRefType(newDevice.getRefType()); deviceInventoryEntity.setDeviceType(newDevice.getDeviceType()); deviceInventoryEntity.setManagedState(newDevice.getManagedState()); deviceInventoryEntity.setState(newDevice.getState()); deviceInventoryEntity.setDisplayName(newDevice.getDisplayName()); deviceInventoryEntity.setServiceTag(newDevice.getServiceTag()); deviceInventoryEntity.setIpAddress(newDevice.getIpAddress()); deviceInventoryEntity.setModel(newDevice.getModel()); deviceInventoryEntity.setComplianceCheckDate(newDevice.getComplianceCheckDate()); deviceInventoryEntity.setDiscoveredDate(newDevice.getDiscoveredDate()); deviceInventoryEntity.setHealth(newDevice.getHealth()); deviceInventoryEntity.setHealthMessage(newDevice.getHealthMessage()); deviceInventoryEntity.setInfraTemplateDate(newDevice.getInfraTemplateDate()); deviceInventoryEntity.setInfraTemplateId(newDevice.getInfraTemplateId()); deviceInventoryEntity.setIdentityRefId(newDevice.getIdentityRefId()); deviceInventoryEntity.setInventoryDate(newDevice.getInventoryDate()); deviceInventoryEntity.setServerTemplateDate(newDevice.getServerTemplateDate()); deviceInventoryEntity.setServerTemplateId(newDevice.getServerTemplateId()); deviceInventoryEntity.setConfig(newDevice.getConfig()); deviceInventoryEntity.setSystemId(newDevice.getSystemId()); deviceInventoryEntity.setOsImageType(newDevice.getOsImageType()); deviceInventoryEntity.setOsAdminPassword(newDevice.getOsAdminPassword()); deviceInventoryEntity.setOsIpAddress(newDevice.getOsIpAddress()); deviceInventoryEntity.setFailuresCount(newDevice.getFailuresCount()); deviceInventoryEntity.setCompliant(newDevice.getCompliant()); deviceInventoryEntity.setChassisId(newDevice.getChassisId()); deviceInventoryEntity.setUpdatedDate(new GregorianCalendar()); deviceInventoryEntity.setUpdatedBy(_dao.extractUserFromRequest()); if (newDevice.getDeviceGroupList() != null && !newDevice.getDeviceGroupList().isEmpty()) { deviceInventoryEntity.setDeviceGroupList(newDevice.getDeviceGroupList()); } deviceInventoryEntity.setFacts(newDevice.getFacts()); session.saveOrUpdate(deviceInventoryEntity); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during update device: " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during update device: " + ex); } if (e instanceof StaleObjectStateException) { StaleObjectStateException sose = ((StaleObjectStateException) e); logger.warn("StaleObjectStateException for device with refId " + newDevice.getRefId()); logger.warn("StaleObjectStateException for device with ipAddress " + newDevice.getIpAddress()); logger.warn("StaleObjectStateException for device with serviceTag " + newDevice.getServiceTag()); } if (e instanceof AsmManagerCheckedException) { throw e; } throw new AsmManagerInternalErrorException("Update device", "DeviceInventoryDAO", 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.DeviceInventoryDAO.java
License:Open Source License
/** * Delete Device Inventory by refId.//from w w w. ja va 2 s . c om * * @param refId the refId used to delete from inventory. */ public void deleteDeviceInventory(String refId) { logger.info("Deleting device from inventory: " + refId); Session session = null; Transaction tx = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); String hql = "delete DeviceInventoryEntity where refId = :refId"; Query query = session.createQuery(hql); query.setString("refId", refId); query.executeUpdate(); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during delete device: " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during delete device: " + ex); } throw new AsmManagerInternalErrorException("Delete device", "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during delete device: " + ex); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
/** * Helper method to get the device ref Id based on the Service Tag * * @param serviceTag - a string that is hte service tag of hte device * @return String - the Ref Id of the device *///from w ww . j a v a 2s.c o m public String getRefIdOfDevice(String serviceTag) { logger.info("Retrieving ref Id of Device from inventory with service tag : " + serviceTag); Session session = null; Transaction tx = null; String refIdString = ""; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); String hql = "select refId from DeviceInventoryEntity where serviceTag = :serviceTag"; Query query = session.createQuery(hql); query.setString("serviceTag", serviceTag); refIdString = (String) query.setMaxResults(1).uniqueResult(); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get ref ID from device inventory from service tag: " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction: " + ex); } throw new AsmManagerInternalErrorException("Get Ref Id from Service Tag", "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during ref Id retrieval: " + ex); } } return refIdString; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
public DeviceLastJobStateEntity getLastJob(String deviceRefId, JobType jobType) throws AsmManagerCheckedException { Session session = null;//from w ww. ja v a2s . c o m Transaction tx = null; DeviceLastJobStateEntity lastJob = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from DeviceLastJobStateEntity where deviceRefId = :deviceRefId and jobType = :jobType"; Query query = session.createQuery(hql); query.setString("deviceRefId", deviceRefId); query.setString("jobType", jobType.name()); lastJob = (DeviceLastJobStateEntity) query.setMaxResults(1).uniqueResult(); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during get last job for refId: " + deviceRefId + ", " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get last job: " + ex); } throw new AsmManagerInternalErrorException("Retrieve last job", "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get last job: " + ex); } } return lastJob; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
/** * Create a new or update existing last job state table based on given device ref id * and job type.// ww w .ja v a 2 s . co m * * @param deviceRefId * @param jobType * @param successful * @param description */ public void createOrUpdateLastJob(String deviceRefId, JobType jobType, DeviceState successful, String description) { Session session = null; Transaction tx = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); String hql = "from DeviceLastJobStateEntity where deviceRefId = :deviceRefId and jobType = :jobType"; Query query = session.createQuery(hql); query.setString("deviceRefId", deviceRefId); query.setString("jobType", jobType.name()); DeviceLastJobStateEntity lastJob = (DeviceLastJobStateEntity) query.setMaxResults(1).uniqueResult(); if (lastJob == null) { lastJob = new DeviceLastJobStateEntity(); lastJob.setDeviceRefId(deviceRefId); lastJob.setJobType(jobType); lastJob.setCreatedDate(new GregorianCalendar()); } else { lastJob.setUpdatedDate(new GregorianCalendar()); } lastJob.setDescription(description); lastJob.setJobState(successful); session.saveOrUpdate(lastJob); // Commit transaction. tx.commit(); } catch (Exception e) { logger.warn("Caught exception during create or update last job: ", e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during create or update last job: " + ex); } throw new AsmManagerInternalErrorException("Create or Update Last Job", "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during create or update last job: " + ex); } } }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
/** * Retrieve all from Device Inventory with the given device type. * @return list of entities/*from w w w.j a v a 2 s . co m*/ */ public List<DeviceInventoryEntity> getAllDeviceInventoryByDeviceType(DeviceType deviceType) { Session session = null; Transaction tx = null; List<DeviceInventoryEntity> entityList = new ArrayList<DeviceInventoryEntity>(); try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from DeviceInventoryEntity where deviceType = :deviceType"; Query query = session.createQuery(hql); query.setString("deviceType", deviceType.getValue()); for (Object result : query.list()) { entityList.add((DeviceInventoryEntity) result); } this.setFirmwareBasedOnDeployment(entityList); tx.commit(); } catch (Exception e) { logger.warn( "Caught exception during get all devices by device type in inventory: " + deviceType.getValue(), e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.warn("Unable to rollback transaction during get all devices: " + ex); } throw new AsmManagerInternalErrorException( "Retrieve all devices for deviceType: " + deviceType.getValue(), "DeviceInventoryDAO", e); } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during get all devices: " + ex); } } return entityList; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
public Set<FirmwareDeviceInventoryEntity> getFirmwareDeviceInventoryByRefId(String deviceRefId) { HashSet<FirmwareDeviceInventoryEntity> firmwareDeviceInventory = new HashSet<FirmwareDeviceInventoryEntity>(); Session session = null;//from www . j a v a 2 s . co m Transaction tx = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "from FirmwareDeviceInventoryEntity where device_inventory = :deviceRefId"; Query query = session.createQuery(hql); query.setString("deviceRefId", deviceRefId); for (Object result : query.list()) { firmwareDeviceInventory.add((FirmwareDeviceInventoryEntity) result); } tx.commit(); } catch (Exception e) { logger.warn("Caught exception during getFirmwareDeviceInventoryByRefId with deviceRefId: " + deviceRefId + ", " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.error("Unable to rollback transaction during getFirmwareDeviceInventoryByRefId with refId: " + deviceRefId, ex); } } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during getFirmwareDeviceInventoryByRefId with refId: " + deviceRefId + ex); } } return firmwareDeviceInventory; }
From source file:com.dell.asm.asmcore.asmmanager.db.DeviceInventoryDAO.java
License:Open Source License
public void deleteFirmwareDeviceInventoryForDevice(String deviceRefId, SourceType sourceType) { Session session = null;//w w w . j a va 2s .com Transaction tx = null; try { session = _dao._database.getNewSession(); tx = session.beginTransaction(); // Create and execute command. String hql = "delete " + FirmwareDeviceInventoryEntity.class.getName() + " where device_inventory = :deviceRefId and source = :sourceType"; Query query = session.createQuery(hql); query.setString("deviceRefId", deviceRefId); query.setString("sourceType", sourceType.getValue()); query.executeUpdate(); tx.commit(); } catch (Exception e) { logger.warn("Caught exception during deleteFirmwareDeviceInventoryForDevice with deviceRefId: " + deviceRefId + ", " + e, e); try { if (tx != null) { tx.rollback(); } } catch (Exception ex) { logger.error( "Unable to rollback transaction during deleteFirmwareDeviceInventoryForDevice with refId: " + deviceRefId, ex); } } finally { try { if (session != null) { session.close(); } } catch (Exception ex) { logger.warn("Unable to close session during deleteFirmwareDeviceInventoryForDevice with refId: " + deviceRefId + ex); } } }