List of usage examples for org.hibernate Session refresh
void refresh(Object object);
From source file:org.javamexico.dao.hib3.QuestionDAO.java
License:Open Source License
@Transactional public void addTag(String tag, Pregunta p) { Session sess = sfact.getCurrentSession(); @SuppressWarnings("unchecked") List<TagPregunta> tags = sess.createCriteria(TagPregunta.class).add(Restrictions.ilike("tag", tag)) .setMaxResults(1).list();// w w w .j av a2s.c o m TagPregunta utag = null; if (tags.size() == 0) { utag = new TagPregunta(); utag.setTag(tag); sess.save(utag); sess.flush(); } else { utag = tags.get(0); } if (p.getTags() == null) { sess.refresh(p); } p.getTags().add(utag); sess.update(p); p.getTags().size(); }
From source file:org.javamexico.dao.hib3.UsuarioDAO.java
License:Open Source License
@Transactional public void addTag(String tag, Usuario u) { Session sess = sfact.getCurrentSession(); @SuppressWarnings("unchecked") List<TagUsuario> tags = sess.createCriteria(TagUsuario.class).add(Restrictions.ilike("tag", tag)) .setFetchSize(1).list();/* w w w . j a va 2 s .c o m*/ TagUsuario utag = null; if (tags.size() == 0) { utag = new TagUsuario(); utag.setTag(tag); sess.save(utag); sess.flush(); } else { utag = tags.get(0); } if (u.getTags() == null) { sess.refresh(u); } utag.setCount(utag.getCount() + 1); sess.update(utag); u.getTags().add(utag); sess.update(u); u.getTags().size(); }
From source file:org.jboss.dashboard.workspace.CopyManagerImpl.java
License:Apache License
public Section copy(final Section section, final WorkspaceImpl workspace, final SectionCopyOption sco) throws Exception { final Section[] results = new Section[] { null }; HibernateTxFragment txFragment = new HibernateTxFragment() { protected void txFragment(Session session) throws Exception { SectionCopyOption copyOption = sco; log.debug("Copying section " + section.getId() + " to Workspace " + workspace.getId()); if (copyOption == null) { if (workspace.getId().equals(section.getWorkspace().getId())) copyOption = CopyOption.DEFAULT_SECTION_COPY_OPTION_SAME_WORKSPACE; else copyOption = CopyOption.DEFAULT_SECTION_COPY_OPTION_OTHER_WORKSPACE; }/* w w w . jav a 2 s. com*/ Section sectionCopy = (Section) section.clone(); sectionCopy.setPosition(-1); //Let the workspace decide the position later sectionCopy.setWorkspace(workspace); boolean copyingToSameWorkspace = workspace.getId().equals(section.getWorkspace().getId()); if (copyingToSameWorkspace) {//Section in same workspace-> can't reuse the id sectionCopy.setId(null); } else {//Section in different workspace-> can reuse the url sectionCopy.setFriendlyUrl(section.getFriendlyUrl()); } if (log.isDebugEnabled()) log.debug("Storing basic section copy to workspace " + workspace.getId()); UIServices.lookup().getSectionsManager().store(sectionCopy); // Add to destination workspace if (log.isDebugEnabled()) log.debug("Adding cloned section (" + sectionCopy.getId() + ") to workspace " + workspace.getId()); workspace.addSection(sectionCopy); UIServices.lookup().getWorkspacesManager().store(workspace); //Resources copyResources(section, sectionCopy); // Panels inside section LayoutRegion[] regions = section.getLayout().getRegions(); log.debug("Regions in section are " + Arrays.asList(regions)); Map<String, PanelInstance> panelInstanceMappings = new HashMap<String, PanelInstance>(); for (LayoutRegion region : regions) { Panel[] panels = section.getPanels(region); if (log.isDebugEnabled()) log.debug("Copying " + panels.length + " panels in region " + region); for (int j = 0; panels != null && j < panels.length; j++) { Panel panelClone = null; PanelInstance instanceClone = panels[j].getInstance(); String panelInstanceId = panels[j].getInstanceId().toString(); if (copyOption.isDuplicatePanelInstance(panelInstanceId)) { //Duplicate Panel instance for this panel. if (panelInstanceMappings.containsKey(panelInstanceId)) { instanceClone = panelInstanceMappings.get(panelInstanceId); } else { instanceClone = copy(panels[j].getInstance(), workspace); panelInstanceMappings.put(panelInstanceId, instanceClone); } } panelClone = copy(panels[j], sectionCopy, null, instanceClone); if (panelClone == null) log.error("Panel " + panels[j].getPanelId() + " failed to copy itself to Section " + sectionCopy.getId()); } } copyPermissions(section, sectionCopy); session.flush(); session.refresh(sectionCopy); // To fix bug 2011 results[0] = sectionCopy; } }; synchronized (("workspace_" + workspace.getDbid()).intern()) { txFragment.execute(); } return results[0]; }
From source file:org.kitodo.data.database.persistence.BatchDAO.java
License:Open Source License
/** * The function reattach() reattaches a batch to a Hibernate session, i.e. for * accessing properties that are lazy loaded. * * @param batch//from ww w . j a va 2s . c o m * object to reattach * @return the batch */ public static Batch reattach(Batch batch) { Session session = Helper.getHibernateSession(); session.refresh(batch); return batch; }
From source file:org.molasdin.wbase.hibernate.BasicHibernateRepository.java
License:Apache License
@Override public void refresh(final T o) { support().run(new org.molasdin.wbase.transaction.Transactional<HibernateEngine, Void>() { @Override/*from w ww . j a v a2 s . c o m*/ public Void run(Transaction<HibernateEngine> tx) throws Exception { Session session = tx.engine().session(); attachRaw(o, session); session.refresh(o); return null; } }); }
From source file:org.n52.sos.ds.hibernate.dao.CodespaceDAO.java
License:Open Source License
/** * Insert and/or get codespace object/*from w ww . j av a2s .c o m*/ * * @param codespace * Codespace identifier * @param session * Hibernate session * @return Codespace object */ public Codespace getOrInsertCodespace(final String codespace, final Session session) { Codespace result = getCodespace(codespace, session); if (result == null) { result = new Codespace(); result.setCodespace(codespace); session.save(result); session.flush(); session.refresh(result); } return result; }
From source file:org.n52.sos.ds.hibernate.dao.ereporting.EReportingAssessmentTypeDAO.java
License:Open Source License
public EReportingAssessmentType getOrInsert(AssessmentType assessmentType, Session session) { EReportingAssessmentType eReportingAssessmentType = getEReportingAssessmentType(assessmentType, session); if (eReportingAssessmentType == null) { eReportingAssessmentType = new EReportingAssessmentType(); eReportingAssessmentType.setAssessmentType(assessmentType.getId()); eReportingAssessmentType.setUri(assessmentType.getConceptURI()); session.saveOrUpdate(eReportingAssessmentType); session.flush();/*from w w w .ja v a 2s.c o m*/ session.refresh(eReportingAssessmentType); } return eReportingAssessmentType; }
From source file:org.n52.sos.ds.hibernate.dao.ereporting.EReportingSamplingPointDAO.java
License:Open Source License
/** * Get or insert {@link AqdSamplingPoint} * //from w w w .ja v a 2 s .c om * @param samplingPoint * {@link AqdSamplingPoint} to insert * @param session * Hibernate session * @return The resulting {@link EReportingSamplingPoint} */ public EReportingSamplingPoint getOrInsert(AqdSamplingPoint samplingPoint, Session session) { Criteria c = getDefaultCriteria(session); c.add(Restrictions.eq(EReportingSamplingPoint.IDENTIFIER, samplingPoint.getIdentifier())); LOGGER.debug("QUERY getOrIntert(samplingPoint): {}", HibernateHelper.getSqlString(c)); EReportingSamplingPoint eReportingSamplingPoint = (EReportingSamplingPoint) c.uniqueResult(); if (eReportingSamplingPoint == null) { eReportingSamplingPoint = new EReportingSamplingPoint(); addIdentifierNameDescription(samplingPoint, eReportingSamplingPoint, session); eReportingSamplingPoint.setAssessmentType( new EReportingAssessmentTypeDAO().getOrInsert(samplingPoint.getAssessmentType(), session)); session.save(eReportingSamplingPoint); session.flush(); session.refresh(eReportingSamplingPoint); } return eReportingSamplingPoint; }
From source file:org.n52.sos.ds.hibernate.dao.ObservablePropertyDAO.java
License:Open Source License
/** * Insert and/or get observable property objects for SOS observable * properties//from www . j a va 2 s .c om * * @param observableProperty * SOS observable properties * @param session * Hibernate session * @return Observable property objects */ public List<ObservableProperty> getOrInsertObservableProperty( final List<OmObservableProperty> observableProperty, final Session session) { final List<String> identifiers = new ArrayList<String>(observableProperty.size()); for (final OmObservableProperty sosObservableProperty : observableProperty) { identifiers.add(sosObservableProperty.getIdentifierCodeWithAuthority().getValue()); } final List<ObservableProperty> obsProps = getObservableProperties(identifiers, session); for (final OmObservableProperty sosObsProp : observableProperty) { boolean exists = false; for (final ObservableProperty obsProp : obsProps) { if (obsProp.getIdentifier().equals(sosObsProp.getIdentifierCodeWithAuthority().getValue())) { exists = true; break; } } if (!exists) { final ObservableProperty obsProp = new ObservableProperty(); addIdentifierNameDescription(sosObsProp, obsProp, session); session.save(obsProp); session.flush(); session.refresh(obsProp); obsProps.add(obsProp); } } return obsProps; }
From source file:org.n52.sos.ds.hibernate.dao.ObservationConstellationDAO.java
License:Open Source License
/** * Insert or update and get observation constellation for procedure, * observable property and offering/* w w w . java2 s .c o m*/ * * @param procedure * Procedure object * @param observableProperty * Observable property object * @param offering * Offering object * @param hiddenChild * Is observation constellation hidden child * @param session * Hibernate session * @return Observation constellation object */ public ObservationConstellation checkOrInsertObservationConstellation(Procedure procedure, ObservableProperty observableProperty, Offering offering, boolean hiddenChild, Session session) { Criteria criteria = session.createCriteria(ObservationConstellation.class) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(ObservationConstellation.OFFERING, offering)) .add(Restrictions.eq(ObservationConstellation.OBSERVABLE_PROPERTY, observableProperty)) .add(Restrictions.eq(ObservationConstellation.PROCEDURE, procedure)) .add(Restrictions.eq(ObservationConstellation.HIDDEN_CHILD, hiddenChild)); LOGGER.debug( "QUERY checkOrInsertObservationConstellation(procedure, observableProperty, offering, hiddenChild): {}", HibernateHelper.getSqlString(criteria)); ObservationConstellation obsConst = (ObservationConstellation) criteria.uniqueResult(); if (obsConst == null) { obsConst = new ObservationConstellation(); obsConst.setObservableProperty(observableProperty); obsConst.setProcedure(procedure); obsConst.setOffering(offering); obsConst.setDeleted(false); obsConst.setHiddenChild(hiddenChild); session.save(obsConst); session.flush(); session.refresh(obsConst); } else if (obsConst.getDeleted()) { obsConst.setDeleted(false); session.save(obsConst); session.flush(); session.refresh(obsConst); } return obsConst; }