List of usage examples for org.hibernate Session refresh
void refresh(Object object);
From source file:org.n52.sos.ds.hibernate.dao.OfferingDAO.java
License:Open Source License
/** * Insert or update and get offering/* w w w. j a v a2s. co m*/ * * @param offeringIdentifier * Offering identifier * @param offeringName * Offering name * @param relatedFeatures * Related feature objects * @param observationTypes * Allowed observation type objects * @param featureOfInterestTypes * Allowed featureOfInterest type objects * @param session * Hibernate session * @return Offering object */ public Offering getAndUpdateOrInsertNewOffering(final String offeringIdentifier, final String offeringName, final List<RelatedFeature> relatedFeatures, final List<ObservationType> observationTypes, final List<FeatureOfInterestType> featureOfInterestTypes, final Session session) { TOffering offering = getTOfferingForIdentifier(offeringIdentifier, session); if (offering == null) { offering = new TOffering(); offering.setIdentifier(offeringIdentifier); if (offeringName != null) { offering.setName(offeringName); } else { offering.setName("Offering for the procedure " + offeringIdentifier); } } if (!relatedFeatures.isEmpty()) { offering.setRelatedFeatures(new HashSet<RelatedFeature>(relatedFeatures)); } else { offering.setRelatedFeatures(new HashSet<RelatedFeature>(0)); } if (!observationTypes.isEmpty()) { offering.setObservationTypes(new HashSet<ObservationType>(observationTypes)); } else { offering.setObservationTypes(new HashSet<ObservationType>(0)); } if (!featureOfInterestTypes.isEmpty()) { offering.setFeatureOfInterestTypes(new HashSet<FeatureOfInterestType>(featureOfInterestTypes)); } else { offering.setFeatureOfInterestTypes(new HashSet<FeatureOfInterestType>(0)); } session.saveOrUpdate(offering); session.flush(); session.refresh(offering); return offering; }
From source file:org.n52.sos.ds.hibernate.dao.ProcedureDAO.java
License:Open Source License
/** * Insert and get procedure object/*from ww w . j av a 2s .c om*/ * * @param identifier * Procedure identifier * @param procedureDecriptionFormat * Procedure description format object * @param parentProcedures * Parent procedure identifiers * @param session * Hibernate session * @return Procedure object */ public Procedure getOrInsertProcedure(final String identifier, final ProcedureDescriptionFormat procedureDecriptionFormat, final Collection<String> parentProcedures, final Session session) { Procedure procedure = getProcedureForIdentifierIncludeDeleted(identifier, session); if (procedure == null) { final TProcedure tProcedure = new TProcedure(); tProcedure.setProcedureDescriptionFormat(procedureDecriptionFormat); tProcedure.setIdentifier(identifier); if (CollectionHelper.isNotEmpty(parentProcedures)) { tProcedure.setParents(Sets.newHashSet(getProceduresForIdentifiers(parentProcedures, session))); } procedure = tProcedure; } procedure.setDeleted(false); session.saveOrUpdate(procedure); session.flush(); session.refresh(procedure); return procedure; }
From source file:org.n52.sos.ds.hibernate.dao.series.AbstractSeriesDAO.java
License:Open Source License
protected Series getOrInsert(SeriesIdentifiers identifiers, final Session session) throws CodedException { Criteria criteria = getDefaultAllSeriesCriteria(session); identifiers.addIdentifierRestrictionsToCritera(criteria); LOGGER.debug("QUERY getOrInsertSeries(feature, observableProperty, procedure): {}", HibernateHelper.getSqlString(criteria)); Series series = (Series) criteria.uniqueResult(); if (series == null) { series = getSeriesImpl();//ww w . ja v a 2 s. co m identifiers.addValuesToSeries(series); series.setDeleted(false); series.setPublished(true); session.save(series); session.flush(); session.refresh(series); } else if (series.isDeleted()) { series.setDeleted(false); session.update(series); session.flush(); session.refresh(series); } return series; }
From source file:org.n52.sos.ds.hibernate.dao.UnitDAO.java
License:Open Source License
/** * Insert and get unit object// w w w. j a v a2 s .c o m * * @param unit * Unit * @param session * Hibernate session * @return Unit object */ public Unit getOrInsertUnit(String unit, Session session) { Unit result = getUnit(unit, session); if (result == null) { result = new Unit(); result.setUnit(unit); session.save(result); session.flush(); session.refresh(result); } return result; }
From source file:org.n52.sos.ds.hibernate.HibernateFeatureQueryHandler.java
License:Open Source License
protected FeatureOfInterest insertFeatureOfInterest(final SamplingFeature samplingFeature, final Session session) throws OwsExceptionReport { if (!GeometryHandler.getInstance().isSpatialDatasource()) { throw new NotYetSupportedException("Insertion of full encoded features for non spatial datasources"); }//from w ww .java 2 s.c o m FeatureOfInterestDAO featureOfInterestDAO = new FeatureOfInterestDAO(); final String newId = samplingFeature.getIdentifierCodeWithAuthority().getValue(); FeatureOfInterest feature = getFeatureOfInterest(newId, samplingFeature.getGeometry(), session); if (feature == null) { feature = new TFeatureOfInterest(); featureOfInterestDAO.addIdentifierNameDescription(samplingFeature, feature, session); processGeometryPreSave(samplingFeature, feature, session); if (samplingFeature.isSetXmlDescription()) { feature.setDescriptionXml(samplingFeature.getXmlDescription()); } if (samplingFeature.isSetFeatureType()) { feature.setFeatureOfInterestType(new FeatureOfInterestTypeDAO() .getOrInsertFeatureOfInterestType(samplingFeature.getFeatureType(), session)); } if (samplingFeature.isSetSampledFeatures()) { Set<FeatureOfInterest> parents = Sets .newHashSetWithExpectedSize(samplingFeature.getSampledFeatures().size()); for (AbstractFeature sampledFeature : samplingFeature.getSampledFeatures()) { if (!OGCConstants.UNKNOWN.equals(sampledFeature.getIdentifierCodeWithAuthority().getValue())) { if (sampledFeature instanceof SamplingFeature) { parents.add(insertFeatureOfInterest((SamplingFeature) sampledFeature, session)); } else { parents.add(insertFeatureOfInterest( new SamplingFeature(sampledFeature.getIdentifierCodeWithAuthority()), session)); } } } ((TFeatureOfInterest) feature).setParents(parents); } session.save(feature); session.flush(); session.refresh(feature); featureOfInterestDAO.insertNameAndDescription(feature, samplingFeature, session); // return newId; // } else { // return feature.getIdentifier(); } return feature; }
From source file:org.riotfamily.pages.model.ContentPage.java
License:Apache License
public void refreshIfDetached() { Session session = getSession(); if (!session.contains(this)) { session.refresh(this); }//w w w . j a va 2s . com }
From source file:org.sakaiproject.assignment.impl.persistence.AssignmentRepositoryImpl.java
License:Educational Community License
@Override @Transactional/*w w w .ja v a 2s. c o m*/ public void deleteSubmission(String submissionId) { Session session = sessionFactory.getCurrentSession(); AssignmentSubmission submission = (AssignmentSubmission) session.get(AssignmentSubmission.class, submissionId); if (submission != null) { log.info("Deleting submission {}", submission); Assignment assignment = submission.getAssignment(); // must call refresh here to ensure the collections are initialized before changing, this is due to lazy loaded entities session.refresh(assignment); assignment.getSubmissions().remove(submission); session.update(assignment); session.flush(); } }
From source file:org.sakaiproject.assignment.persistence.AssignmentRepositoryImpl.java
License:Educational Community License
@Override @Transactional//from ww w .j a v a 2 s. c o m public void deleteSubmission(String submissionId) { Session session = sessionFactory.getCurrentSession(); AssignmentSubmission submission = (AssignmentSubmission) session.get(AssignmentSubmission.class, submissionId); if (submission != null) { Assignment assignment = submission.getAssignment(); // must call refresh here to ensure the collections are initialized before changing, this is due to lazy loaded entities session.refresh(assignment); assignment.getSubmissions().remove(submission); session.update(assignment); session.flush(); } }
From source file:org.tsm.concharto.dao.IntegrationTestUserDao.java
License:Apache License
@Test public void roles() { setupRoles();// w w w . j a va2 s . com User user = new User("jonathan", "diner", "jon@tsm.com"); List<Role> roles = userDao.getRoles(); assertEquals(3, roles.size()); user.setRoles(roles); Long id = (Long) userDao.save(user); User returned = userDao.find(id); //Need to refresh for unit tests. In the web controller, we use an interceptor //to keep the session open SessionFactory sessionFactory = eventTesterDao.getSessionFactory(); Session session = SessionFactoryUtils.getSession(sessionFactory, true); session.refresh(returned); assertEquals(roles.size(), returned.getRoles().size()); session.close(); }
From source file:org.unitime.banner.model.BannerSection.java
License:Apache License
public void updateClassSuffixForClassesIfNecessaryRefreshClasses(Session hibSession, boolean refresh) { Boolean control = this.getBannerConfig().getBannerCourse().getCourseOffering(hibSession).isIsControl(); if (control.booleanValue()) { for (Iterator<?> it = this.getBannerSectionToClasses().iterator(); it.hasNext();) { BannerSectionToClass bsc = (BannerSectionToClass) it.next(); Class_ clazz = Class_DAO.getInstance().get(bsc.getClassId(), hibSession); if (clazz != null) { String classSuffix = this.classSuffixFor(clazz, hibSession); if (clazz.getClassSuffix() == null || !clazz.getClassSuffix().equals(classSuffix)) { clazz.setClassSuffix(classSuffix); clazz.setExternalUniqueId(this.externalUniqueIdFor(clazz, hibSession)); hibSession.update(clazz); hibSession.flush();/* w ww . ja v a2 s. co m*/ if (refresh) { hibSession.refresh(clazz); } } } } } }