List of usage examples for org.hibernate StatelessSession insert
Serializable insert(Object entity);
From source file:au.org.theark.lims.model.dao.BiospecimenDao.java
License:Open Source License
protected void setSubjectUidSequenceLock(Study study, boolean lock) { // Stateless sessions should be used to avoid locking the record for future update // by getSession(), which relies on the "open session filter" mechanism StatelessSession session = getStatelessSession(); Transaction tx = session.getTransaction(); tx.begin();/*from w w w .j a va 2 s .com*/ BiospecimenUidSequence biospecimenUidSeq = getBiospecimenUidSequence(study); if (biospecimenUidSeq == null) { // create a new record if it doens't exist biospecimenUidSeq = new BiospecimenUidSequence(); biospecimenUidSeq.setStudyNameId(study.getName()); biospecimenUidSeq.setUidSequence(new Integer(0)); biospecimenUidSeq.setInsertLock(lock); session.insert(biospecimenUidSeq); } else { biospecimenUidSeq.setInsertLock(lock); session.update(biospecimenUidSeq); } tx.commit(); session.close(); }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateChannelSeverityDao.java
License:Mozilla Public License
@Override public void insert(List<ChannelSeverity> channelSeverities) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); try {/*from w ww . j a va 2 s. co m*/ for (ChannelSeverity channelSeverity : channelSeverities) { statelessSession.insert(channelSeverity); } } finally { statelessSession.close(); } }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateChannelVulnerabilityDao.java
License:Mozilla Public License
@Override public void saveOrUpdateStateless(ChannelVulnerability channelVulnerability) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); statelessSession.insert(channelVulnerability); statelessSession.close();/*from w ww .j a va 2 s . c o m*/ }
From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateGenericVulnerabilityDao.java
License:Mozilla Public License
@Override public void insertAll(List<GenericVulnerability> vulnerabilityList) { StatelessSession statelessSession = sessionFactory.openStatelessSession(); Transaction transaction = statelessSession.beginTransaction(); try {// w w w. j a va 2 s . com for (GenericVulnerability vulnerability : vulnerabilityList) { statelessSession.insert(vulnerability); } transaction.commit(); } catch (Exception e) { transaction.rollback(); } finally { statelessSession.close(); } }
From source file:com.romeikat.datamessie.core.base.dao.impl.AbstractEntityDao.java
License:Open Source License
/** * Inserts a new entity. If the entity already exists in the database, a copy of it is saved with * a new id./*from w ww.j a v a2 s .c om*/ * * @param statelessSession * @param entity */ @Override public void insert(final StatelessSession statelessSession, final E entity) { statelessSession.insert(entity); }
From source file:edu.psu.iam.cpr.core.database.batch.AccessAccountStatus.java
License:Creative Commons License
/** * This method is used to add a new service to the user service status table. * @param personId contains the person identifier whose information is to be added. * @param userid contains the userid associated with the person identifier. * @param accessAccountServiceType contains the services. *///from w w w . j a v a2s . com public void addService(final long personId, final String userid, final AccessAccountServiceType accessAccountServiceType) { // Do a second check to ensure that the service really is not associated with the user. if (!isServiceActive(personId, userid, accessAccountServiceType)) { // Create the bean. final Date d = getServiceDate(); final String updatedBy = getBatchDataSource().toString(); final StatelessSession session = getDatabaseSession(); final Long consumerKey = getMessagingCore().getBatchMessageConsumerKey(); final UserServiceStatus userServiceStatus = new UserServiceStatus(); userServiceStatus.setPersonId(personId); userServiceStatus.setUserid(userid); userServiceStatus.setMessageConsumerKey(consumerKey); userServiceStatus.setServiceKey(accessAccountServiceType.index()); userServiceStatus.setProvisionDate(d); userServiceStatus.setDeprovisionDate(null); userServiceStatus.setExpirationDate(null); userServiceStatus.setCreatedBy(updatedBy); userServiceStatus.setCreatedOn(d); userServiceStatus.setLastUpdateBy(updatedBy); userServiceStatus.setLastUpdateOn(d); session.insert(userServiceStatus); } }
From source file:edu.psu.iam.cpr.core.database.postprocess.AddressPostProcessor.java
License:Creative Commons License
/** * This method is used to add a new permanent address to the database. * @param db contains the database session. * @param addressType contains the type of address to be added. * @param addressStagingBean contains the address bean. */// w w w.j a v a 2s. c o m public void addAddress(final StatelessSession db, final AddressType addressType, final AddressStaging addressStagingBean) { final Addresses bean = new Addresses(); final Date d = new Date(); bean.setPersonId(addressStagingBean.getPersonId()); bean.setDataTypeKey(addressType.index()); bean.setDocumentTypeKey(null); // get the last group id for this address type for this person so can set the correct group id Long groupId = null; final Query maxQuery = db.createQuery( "select max(groupId) from Addresses where personId = :person_id and dataTypeKey = :data_type_key"); maxQuery.setParameter(PERSON_ID, bean.getPersonId()); maxQuery.setParameter(DATA_TYPE_KEY, bean.getDataTypeKey()); groupId = (Long) maxQuery.list().get(0); if (groupId == null) { groupId = 1L; } else { groupId++; } bean.setGroupId(groupId); bean.setAddressMatchCode(addressStagingBean.getAddressMatchCode()); if (addressStagingBean.getCampusCode() != null) { bean.setCampusCodeKey(campusMap.get(addressStagingBean.getCampusCode())); } if (addressStagingBean.getCountryCodeTwo() != null) { bean.setCountryKey(countryTwoMap.get(addressStagingBean.getCountryCodeTwo())); } else if (addressStagingBean.getCountryCodeThree() != null) { bean.setCountryKey(countryThreeMap.get(addressStagingBean.getCountryCodeThree())); } bean.setProvince(addressStagingBean.getProvince()); bean.setAddress1(addressStagingBean.getAddress1()); bean.setAddress2(addressStagingBean.getAddress2()); bean.setAddress3(addressStagingBean.getAddress3()); bean.setCity(addressStagingBean.getCity()); bean.setCityMatchCode(addressStagingBean.getCityMatchCode()); bean.setState(addressStagingBean.getState()); bean.setPostalCode(addressStagingBean.getPostalCode()); bean.setPrimaryFlag(NO); bean.setVerifiedFlag(NO); bean.setDoNotVerifyFlag(NO); bean.setStartDate(d); bean.setEndDate(null); bean.setCreatedBy(addressStagingBean.getImportFrom()); bean.setCreatedOn(d); bean.setLastUpdateBy(addressStagingBean.getImportFrom()); bean.setLastUpdateOn(d); bean.setImportFrom(addressStagingBean.getImportFrom()); bean.setImportDate(d); db.insert(bean); setNewAddressBean(bean); }
From source file:edu.psu.iam.cpr.core.database.postprocess.NamesPostProcessor.java
License:Creative Commons License
/** * This method is used to add a new legal name to the database. * @param db contains the database session. * @param namesStagingBean contains the names bean. *///from ww w . jav a2 s. c o m public void addName(final StatelessSession db, final NamesStaging namesStagingBean) { final Names bean = new Names(); final Date d = new Date(); bean.setPersonId(namesStagingBean.getPersonId()); bean.setDataTypeKey(NameType.LEGAL_NAME.index()); bean.setDocumentTypeKey(null); bean.setNameMatchCode(namesStagingBean.getNameMatchCode()); bean.setFirstName(namesStagingBean.getFirstName()); bean.setMiddleNames(namesStagingBean.getMiddleNames()); bean.setLastName(namesStagingBean.getLastName()); bean.setSuffix(namesStagingBean.getSuffix()); bean.setStartDate(d); bean.setEndDate(null); bean.setCreatedBy(namesStagingBean.getImportFrom()); bean.setCreatedOn(d); bean.setLastUpdateBy(namesStagingBean.getImportFrom()); bean.setLastUpdateOn(d); bean.setImportFrom(namesStagingBean.getImportFrom()); bean.setImportDate(d); db.insert(bean); setNewNamesBean(bean); }
From source file:edu.psu.iam.cpr.core.messaging.MessagingCore.java
License:Apache License
/** * * @param databaseSession contains the database stateless session * @param changeType contains the type of change notifications * @param msg contains the json message//w ww.j ava2 s.c o m * @throws CprException * @throws JMSException * @throws JSONException */ public void sendNotification(StatelessSession databaseSession, ChangeNotificationType changeType, JsonMessage msg) throws CprException, JMSException, JSONException { final String replyToQueue = CprProperties.INSTANCE.getProperties() .getProperty(CprPropertyName.CPR_JMS_REPLYTO.toString()); final List<VSpNotification> theDest = msgNotificationQueues.get(changeType.toString()); MessageProducer msgSender = null; if (msg == null || msg.getJsonObject().toString().length() == 0) { closeMessaging(); throw new CprException(ReturnType.MESSAGE_CREATION_EXCEPTION); } try { //Create the message to send to the queues TextMessage myTextMsg = null; myTextMsg = jmsSession.createTextMessage(); // Loop through queue list final Iterator<VSpNotification> queueIter = theDest.iterator(); while (queueIter.hasNext()) { VSpNotification currentDestination = queueIter.next(); // Update the JSON message with the message consumer key, message type and change type msg.setValue(MessageKeyName.MESSAGE_CONSUMER_KEY, currentDestination.getMessageConsumerKey()); msg.setValue(MessageKeyName.MESSAGE_TYPE, CprMessageType.CHANGE_NOTIFICATION.toString()); msg.setValue(MessageKeyName.CHANGE_KEY, changeType.toString()); // Store an entry in the message log. MessageLogTable messageLogTable = new MessageLogTable(currentDestination.getWebServiceKey(), currentDestination.getMessageConsumerKey(), currentDestination.getServiceKey(), msg.getJsonObject().toString(), msg.getRequestedBy()); MessageLog mLogBean = messageLogTable.getMessageLogBean(); databaseSession.insert(mLogBean); // Store an entry in the message log history. MessageLogHistoryTable messageLogHistoryTable = new MessageLogHistoryTable( messageLogTable.getMessageLogBean()); MessageLogHistory mLogHistory = messageLogHistoryTable.getMessageLogHistoryBean(); databaseSession.insert(mLogHistory); // once the log is started, the messageLogId is set, add it to the msg to be sent msg.setValue(MessageKeyName.MESSAGE_LOG_ID, mLogBean.getMessageLogKey()); // Add in the JSON information. myTextMsg.setText(msg.getJsonObject().toString()); myTextMsg.setJMSReplyTo(jmsSession.createQueue(replyToQueue)); myTextMsg.setJMSCorrelationID(mLogHistory.getMessageLogHistoryKey().toString()); // Send the message Destination destination = jmsSession.createQueue(currentDestination.getConsumerDestination()); msgSender = jmsSession.createProducer(destination); msgSender.setDeliveryMode(DeliveryMode.PERSISTENT); msgSender.send(myTextMsg); msgSender.close(); // once the message is sent, add an entry in the message log history table for this specific send mLogBean.setSuccessFlag("Y"); mLogBean.setNumberOfTries(1L); mLogBean.setLastUpdateOn(new Date()); databaseSession.update(mLogBean); mLogHistory.setMessageId(myTextMsg.getJMSMessageID()); databaseSession.update(mLogHistory); // Log the successful message delivery to the log4j component. logMessageDelivery(messageLogTable, "SUCCESS"); } } finally { try { if (msgSender != null) { msgSender.close(); } } catch (JMSException e) { } } }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.AbstractAreaDao.java
License:Open Source License
public List<Serializable> bulkInsert(Map<String, List<Property>> features, List<UploadMappingProperty> mapping) throws ServiceException { List<Serializable> invalidGeometryList = new ArrayList<>(); StatelessSession session = (getEntityManager().unwrap(Session.class)).getSessionFactory() .openStatelessSession();/* w w w.j av a2 s. c o m*/ Transaction tx = session.beginTransaction(); try { Query query = session.getNamedQuery(getDisableAreaNamedQuery()); query.executeUpdate(); for (List<Property> properties : features.values()) { Map<String, Object> values = BaseAreaEntity.createAttributesMap(properties); BaseAreaEntity entity = createEntity(values, mapping); if (entity.getName() == null || entity.getCode() == null) { throw new ServiceException("NAME AND CODE FIELD ARE MANDATORY"); } Serializable identifier = session.insert(entity); if (!entity.getGeom().isValid()) { invalidGeometryList.add(identifier); } } log.debug("Commit transaction"); tx.commit(); } catch (Exception e) { tx.rollback(); throw new ServiceException("Rollback transaction", e); } finally { log.debug("Closing session"); session.close(); } return invalidGeometryList; }