List of usage examples for org.hibernate Session evict
void evict(Object object);
From source file:org.meveo.grieg.invoiceConverter.task.ValidatedInvoiceProcessorTask.java
License:Open Source License
/** * Save GriegValidatedInvoiceInputHistory with results of input processing. * // www .j av a 2 s.c o m * @param taskExecution * Processing context object that holds all information how did. */ @Override protected void persistInputHistory(TaskExecution<GriegTicket> taskExecution) { try { String inputName = taskExecution.getInputObject().getName(); if (logger.isDebugEnabled()) { logger.debug(String.format("Updating GriegValidatedInvoiceInputHistory entity for source %s", inputName)); } InputHistory inputHistory = taskExecution.getInputHistory(); Long inputHistoryId = inputHistory.getId(); EntityManager em = MeveoPersistence.getEntityManager(); org.hibernate.Session session = (Session) em.getDelegate(); session.evict(inputHistory); session.createQuery("update InputHistory set INPUT_TYPE = :newType where id = :id") .setString("newType", "GRIEG_VALIDATED").setLong("id", inputHistoryId).executeUpdate(); GriegValidatedInvoiceInputHistory validatedInvoiceInputHistory = em .find(GriegValidatedInvoiceInputHistory.class, inputHistoryId); validatedInvoiceInputHistory.setName(inputName); validatedInvoiceInputHistory.setAnalysisStartDate(taskExecution.getStartTime()); validatedInvoiceInputHistory.setAnalysisEndDate(taskExecution.getEndTime()); validatedInvoiceInputHistory.setParsedTickets(taskExecution.getParsedTicketsCount()); validatedInvoiceInputHistory.setRejectedTickets(taskExecution.getRejectedTicketsCount()); validatedInvoiceInputHistory.setSucceededTickets(taskExecution.getProcessedTicketsCount()); validatedInvoiceInputHistory.setProvider(taskExecution.getProvider()); em.merge(validatedInvoiceInputHistory); if (logger.isDebugEnabled()) { logger.debug(String.format( "Inserting GriegValidatedInvoiceInputHistory entity for source %s completed successfuly", inputName)); } } catch (Exception e) { logger.error("Could not save batch process ", e); } }
From source file:org.meveo.oudaya.InvoicerTask.java
License:Open Source License
/** * Persist OudayaInput with results of input processing. * // w w w. j a v a 2s .c o m * @param taskExecution * Processing context object that holds all information how did. * process go. * @param result * Processing result. */ protected void persistInputHistory(TaskExecution<InvoicingTicket> taskExecution) { try { String inputName = taskExecution.getInputObject().getName(); InputHistory inputHistory = taskExecution.getInputHistory(); Long inputHistoryId = inputHistory.getId(); logger.info(String.format("Updating OudayaInputHistory inputHistoryId %s", inputHistoryId)); EntityManager em = MeveoPersistence.getEntityManager(); org.hibernate.Session session = (Session) em.getDelegate(); session.evict(inputHistory); OudayaInputHistory oudayaInputHistory = em.find(OudayaInputHistory.class, inputHistoryId); logger.info(String.format("Updating OudayaInputHistory name= %s", oudayaInputHistory != null ? oudayaInputHistory.getName() : null)); if (oudayaInputHistory == null) { Date startTime = new Date(); oudayaInputHistory = new OudayaInputHistory(); oudayaInputHistory.setName(inputName); oudayaInputHistory.setAnalysisStartDate(startTime); oudayaInputHistory.setVersion(1); } oudayaInputHistory.setName(inputName); oudayaInputHistory.setAnalysisStartDate(taskExecution.getStartTime()); oudayaInputHistory.setAnalysisEndDate(taskExecution.getEndTime()); oudayaInputHistory.setParsedTickets(taskExecution.getParsedTicketsCount()); oudayaInputHistory.setRejectedTickets(taskExecution.getRejectedTicketsCount()); oudayaInputHistory.setSucceededTickets(taskExecution.getProcessedTicketsCount()); oudayaInputHistory.setProvider(taskExecution.getProvider()); if (!MeveoPersistence.getEntityManager().getTransaction().isActive()) { MeveoPersistence.getEntityManager().getTransaction().begin(); } em.merge(oudayaInputHistory); session.createQuery("update InputHistory set INPUT_TYPE = :newType where id = :id") .setString("newType", "OUDAYA").setLong("id", inputHistoryId).executeUpdate(); logger.info(String.format("Inserting OudayaInputHistory entity for source %s completed successfuly", inputName)); } catch (Exception e) { logger.error("Could not save batch process ", e); } }
From source file:org.meveo.rating.task.RaterTask.java
License:Open Source License
/** * Save VertinaInputHistory with results of input processing. * //from w w w .j a v a2 s . c o m * @param taskExecution * Processing context object that holds all information how did. */ protected void persistInputHistory(TaskExecution<RatingTicket> taskExecution) { try { String inputName = taskExecution.getInputObject().getName(); if (logger.isDebugEnabled()) { logger.debug(String.format("Updating VertinaInputHistory entity for source %s", inputName)); } InputHistory inputHistory = taskExecution.getInputHistory(); Long inputHistoryId = inputHistory.getId(); EntityManager em = MeveoPersistence.getEntityManager(); org.hibernate.Session session = (Session) em.getDelegate(); session.evict(inputHistory); session.createQuery("update InputHistory set INPUT_TYPE = :newType where id = :id") .setString("newType", "VERTINA").setLong("id", inputHistoryId).executeUpdate(); VertinaInputHistory vertinaInputHistory = em.find(VertinaInputHistory.class, inputHistoryId); vertinaInputHistory.setName(inputName); vertinaInputHistory.setAnalysisStartDate(taskExecution.getStartTime()); vertinaInputHistory.setAnalysisEndDate(taskExecution.getEndTime()); vertinaInputHistory.setParsedTickets(taskExecution.getParsedTicketsCount()); vertinaInputHistory.setRejectedTickets(taskExecution.getRejectedTicketsCount()); vertinaInputHistory.setSucceededTickets(taskExecution.getProcessedTicketsCount()); vertinaInputHistory.setProvider(taskExecution.getProvider()); em.merge(vertinaInputHistory); if (logger.isDebugEnabled()) { logger.debug(String.format( "Inserting VertinaInputHistory entity for source %s completed successfuly", inputName)); } } catch (Exception e) { logger.error("Could not save batch process ", e); } }
From source file:org.meveo.vertina.RaterTask.java
License:Open Source License
/** * Save VertinaInputHistory with results of input processing. * //from ww w . ja v a 2s. c o m * @param taskExecution * Processing context object that holds all information how did. */ @Override protected void persistInputHistory(TaskExecution<VertinaTicket> taskExecution) { try { String inputName = taskExecution.getInputObject().getName(); if (logger.isDebugEnabled()) { logger.debug(String.format("Updating VertinaInputHistory entity for source %s", inputName)); } InputHistory inputHistory = taskExecution.getInputHistory(); Long inputHistoryId = inputHistory.getId(); EntityManager em = MeveoPersistence.getEntityManager(); org.hibernate.Session session = (Session) em.getDelegate(); session.evict(inputHistory); session.createQuery("update InputHistory set INPUT_TYPE = :newType where id = :id") .setString("newType", "VERTINA").setLong("id", inputHistoryId).executeUpdate(); VertinaInputHistory vertinaInputHistory = em.find(VertinaInputHistory.class, inputHistoryId); vertinaInputHistory.setName(inputName); vertinaInputHistory.setAnalysisStartDate(taskExecution.getStartTime()); vertinaInputHistory.setAnalysisEndDate(taskExecution.getEndTime()); vertinaInputHistory.setParsedTickets(taskExecution.getParsedTicketsCount()); vertinaInputHistory.setRejectedTickets(taskExecution.getRejectedTicketsCount()); vertinaInputHistory.setSucceededTickets(taskExecution.getProcessedTicketsCount()); vertinaInputHistory.setProvider(taskExecution.getProvider()); em.merge(vertinaInputHistory); if (logger.isDebugEnabled()) { logger.debug(String.format( "Inserting VertinaInputHistory entity for source %s completed successfuly", inputName)); } } catch (Exception e) { logger.error("Could not save batch process ", e); } }
From source file:org.mifos.accounts.savings.business.SavingsBOIntegrationTest.java
License:Open Source License
public void testSuccessfulFlagSave() throws Exception { Session session = StaticHibernateUtil.getSessionTL(); StaticHibernateUtil.startTransaction(); createInitialObjects();//from ww w . ja v a2 s . c o m savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1"); savings = helper.createSavingsAccount("000X00000000013", savingsOffering, group, AccountStates.SAVINGS_ACC_APPROVED, userContext); savings.setUserContext(TestObjectFactory.getContext()); savings.changeStatus(AccountState.SAVINGS_CANCELLED.getValue(), null, ""); savings.setUserContext(this.userContext); AccountStateEntity state = (AccountStateEntity) session.get(AccountStateEntity.class, (short) 15); for (AccountStateFlagEntity flag : state.getFlagSet()) { AccountTestUtils.addAccountFlag(flag, savings); } savings.update(); StaticHibernateUtil.commitTransaction(); StaticHibernateUtil.closeSession(); session = StaticHibernateUtil.getSessionTL(); SavingsBO savingsNew = (SavingsBO) (session.get(SavingsBO.class, Integer.valueOf(savings.getAccountId()))); Assert.assertEquals(savingsNew.getAccountFlags().size(), 3); session.evict(savingsNew); StaticHibernateUtil.closeSession(); }
From source file:org.mifos.accounts.savings.persistence.SavingsBOIntegrationTest.java
License:Open Source License
@Test public void testSuccessfulFlagSave() throws Exception { Session session = StaticHibernateUtil.getSessionTL(); StaticHibernateUtil.startTransaction(); createInitialObjects();// w w w .jav a 2 s. c o m savingsOffering = helper.createSavingsOffering("dfasdasd1", "sad1"); savings = helper.createSavingsAccount("000X00000000013", savingsOffering, group, AccountStates.SAVINGS_ACC_APPROVED, userContext); savings.setUserContext(TestObjectFactory.getContext()); PersonnelBO loggedInUser = IntegrationTestObjectMother.testUser(); savings.changeStatus(AccountState.SAVINGS_CANCELLED, null, "", loggedInUser); savings.setUserContext(this.userContext); AccountStateEntity state = (AccountStateEntity) session.get(AccountStateEntity.class, (short) 15); for (AccountStateFlagEntity flag : state.getFlagSet()) { AccountTestUtils.addAccountFlag(flag, savings); } savings.update(); session = StaticHibernateUtil.getSessionTL(); SavingsBO savingsNew = (SavingsBO) (session.get(SavingsBO.class, Integer.valueOf(savings.getAccountId()))); Assert.assertEquals(savingsNew.getAccountFlags().size(), 3); session.evict(savingsNew); }
From source file:org.n52.sos.ds.hibernate.util.HibernateObservationUtilities.java
License:Open Source License
/** * Create SOS internal observation from Observation objects * /* w w w . j av a2s .c o m*/ * @param responseFormat * * @param observations * List of Observation objects * @param request * the request * @param session * Hibernate session * @return SOS internal observation * * * @throws OwsExceptionReport * * If an error occurs */ public static List<OmObservation> createSosObservationsFromObservations( final Collection<Observation> observations, final String version, final String resultModel, final Session session) throws OwsExceptionReport { final List<OmObservation> observationCollection = new ArrayList<OmObservation>(0); final Map<String, AbstractFeature> features = new HashMap<String, AbstractFeature>(0); final Map<String, AbstractPhenomenon> obsProps = new HashMap<String, AbstractPhenomenon>(0); final Map<String, SosProcedureDescription> procedures = new HashMap<String, SosProcedureDescription>(0); final Map<Integer, OmObservationConstellation> observationConstellations = new HashMap<Integer, OmObservationConstellation>( 0); if (observations != null) { // now iterate over resultset and create Measurement for each row for (final Observation hObservation : observations) { // check remaining heap size and throw exception if minimum is // reached SosHelper.checkFreeMemory(); final FeatureOfInterest hFeatureOfInterest = hObservation.getFeatureOfInterest(); // TODO get full description final Procedure hProcedure = hObservation.getProcedure(); final String procedureIdentifier = hProcedure.getIdentifier(); SosProcedureDescription procedure; if (procedures.containsKey(procedureIdentifier)) { procedure = procedures.get(procedureIdentifier); } else { if (getConfiguration().getActiveProfile().isEncodeProcedureInObservation()) { procedure = new HibernateProcedureConverter().createSosProcedureDescription(hProcedure, procedureIdentifier, hProcedure.getProcedureDescriptionFormat().getProcedureDescriptionFormat(), version, session); } else { procedure = new SosProcedureDescriptionUnknowType(procedureIdentifier, hProcedure.getProcedureDescriptionFormat().getProcedureDescriptionFormat(), null); } procedures.put(procedureIdentifier, procedure); } // feature of interest final String foiID = hFeatureOfInterest.getIdentifier(); if (!features.containsKey(foiID)) { final AbstractFeature featureByID = getConfiguration().getFeatureQueryHandler() .getFeatureByID(foiID, session, version, -1); features.put(foiID, featureByID); } // phenomenon final ObservableProperty hObservableProperty = hObservation.getObservableProperty(); final String phenID = hObservation.getObservableProperty().getIdentifier(); final String description = hObservation.getObservableProperty().getDescription(); if (!obsProps.containsKey(phenID)) { obsProps.put(phenID, new OmObservableProperty(phenID, description, null, null)); } // TODO: add offering ids to response if needed later. // String offeringID = // hObservationConstellation.getOffering().getIdentifier(); // String mimeType = SosConstants.PARAMETER_NOT_SET; final Value<?> value = getValueFromObservation(hObservation); if (value != null) { if (hObservation.getUnit() != null) { value.setUnit(hObservation.getUnit().getUnit()); } checkOrSetObservablePropertyUnit(obsProps.get(phenID), value.getUnit()); final OmObservationConstellation obsConst = new OmObservationConstellation(procedure, obsProps.get(phenID), features.get(foiID)); /* get the offerings to find the templates */ if (obsConst.getOfferings() == null) { final HashSet<String> offerings = new HashSet<String>( getCache().getOfferingsForObservableProperty( obsConst.getObservableProperty().getIdentifier())); offerings.retainAll( getCache().getOfferingsForProcedure(obsConst.getProcedure().getIdentifier())); obsConst.setOfferings(offerings); } final int obsConstHash = obsConst.hashCode(); if (!observationConstellations.containsKey(obsConstHash)) { if (StringHelper.isNotEmpty(resultModel)) { obsConst.setObservationType(resultModel); } final ObservationConstellation hObservationConstellation = getObservationConstellation( hProcedure, hObservableProperty, hObservation.getOfferings(), session); if (hObservationConstellation != null) { final String observationType = hObservationConstellation.getObservationType() .getObservationType(); obsConst.setObservationType(observationType); } observationConstellations.put(obsConstHash, obsConst); } final OmObservation sosObservation = createNewObservation(observationConstellations, hObservation, value, obsConstHash); observationCollection.add(sosObservation); session.evict(hObservation); // TODO check for ScrollableResult vs setFetchSize/setMaxResult // + setFirstResult } } } return observationCollection; }
From source file:org.nextframework.persistence.QueryBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") /**//from w w w . j a va 2 s . com * Exceuta a query e retorna um nico resultado */ public E unique() { if (from == null) { throw new NullPointerException("query with null from clause"); } QueryBuilderResultTranslator qbt = getQueryBuilderResultTranslator(); final boolean useUnique = qbt == null; Object execute = hibernateSessionProvider.execute(new HibernateCommand() { public Object doInHibernate(Session session) { Query query = createQuery(session); if (maxResults != Integer.MIN_VALUE) { if (maxResults != 1) { throw new IllegalArgumentException("Method unique of " + QueryBuilder.class.getSimpleName() + " must be used with maxResults set to 1"); } query.setMaxResults(maxResults); } if (firstResult != Integer.MIN_VALUE) { query.setFirstResult(firstResult); } Object uniqueResult; if (useUnique) { uniqueResult = query.uniqueResult(); } else { uniqueResult = query.list(); } try { initializeProxys(uniqueResult); } catch (RuntimeException e) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); throw new RuntimeException("Erro ao inicializar Proxys (Colees). " + stackTrace[7], e); } if (uniqueResult != null && !uniqueResult.getClass().getName().startsWith("java") && !uniqueResult.getClass().isArray()) { //only evict entities //TODO check with hibernate if the result is an entity session.evict(uniqueResult); } return uniqueResult; } }); if (qbt != null) {//ORGANIZAR.. TEM 2 LUGARES COM CDIGO IGUAL if (execute instanceof List) { execute = organizeListWithResultTranslator(qbt, (List) execute); if (((List) execute).size() == 0) { execute = null; } else { execute = ((List) execute).get(0); } } else { execute = organizeUniqueResultWithTranslator(qbt, (Object[]) execute); } } return (E) execute; }
From source file:org.opengoss.dao.hibernate.DataAccessor.java
License:Apache License
public void evict(final Object entity) throws DaoException { execute(new IAccessorCallback() { public Object call(Session session) throws HibernateException { session.evict(entity); return null; }/* ww w .j a v a 2 s. co m*/ }); }
From source file:org.openhie.openempi.dao.hibernate.PersonDaoHibernate.java
License:Open Source License
public Person loadPersonForUpdate(final Integer personId) { return (Person) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { @SuppressWarnings("unchecked") List<Person> persons = session.createCriteria(Person.class).add(Expression.idEq(personId)) .add(Restrictions.isNull("dateVoided")).list(); if (persons.size() == 0) { return null; }/*from ww w .jav a 2 s. c o m*/ Person p = persons.get(0); removeDeletedIdentifiers(p); session.evict(p); return p; } }); }