Example usage for org.hibernate FlushMode MANUAL

List of usage examples for org.hibernate FlushMode MANUAL

Introduction

In this page you can find the example usage for org.hibernate FlushMode MANUAL.

Prototype

FlushMode MANUAL

To view the source code for org.hibernate FlushMode MANUAL.

Click Source Link

Document

The Session is only ever flushed when Session#flush is explicitly called by the application.

Usage

From source file:org.egov.egf.web.actions.report.TrialBalanceAction.java

License:Open Source License

@Override
public void prepare() {
    persistenceService.getSession().setDefaultReadOnly(true);
    persistenceService.getSession().setFlushMode(FlushMode.MANUAL);
    super.prepare();

    addDropdownData("fundList", masterDataCache.get("egi-fund"));
    addDropdownData("departmentList", masterDataCache.get("egi-department"));
    addDropdownData("functionaryList", masterDataCache.get("egi-functionary"));
    addDropdownData("fieldList", masterDataCache.get("egi-ward"));
    addDropdownData("functionList", masterDataCache.get("egi-function"));

}

From source file:org.egov.ptis.actions.recovery.RecoveryAction.java

License:Open Source License

@ValidationErrorPage(value = "warrantApplicationNew")
public String warrantApplication() {
    LOGGER.debug("RecoveryAction | warrantApplication | Start");
    entityManager.unwrap(Session.class).setFlushMode(FlushMode.MANUAL);
    setupWorkflowDetails();// www.  jav  a2  s . com
    List<WarrantFee> warrantFess = new LinkedList<WarrantFee>();
    for (WarrantFee warrantFee : recovery.getWarrant().getWarrantFees()) {
        EgDemandReason demandReason = (EgDemandReason) persistenceService
                .find(" from EgDemandReason where id=" + warrantFee.getDemandReason().getId());
        warrantFee.setDemandReason(demandReason);
        warrantFess.add(warrantFee);
        LOGGER.debug("RecoveryAction | warrantApplication | Warrant Fee" + warrantFee);
    }
    recovery.getWarrant().getWarrantFees().clear();
    recovery.getWarrant().getWarrantFees().addAll(warrantFess);
    recovery.getBasicProperty()
            .setStatus(getPropStatusByStatusCode(PropertyTaxConstants.RECOVERY_WARRANTPREPARED));
    recovery.setStatus(getEgwStatusForModuleAndCode(PropertyTaxConstants.RECOVERY_MODULE,
            PropertyTaxConstants.RECOVERY_WARRANTPREPARED));
    updateWfstate("Warrant Application");
    LOGGER.debug("RecoveryAction | warrantApplication | end" + recovery.getWarrant());
    entityManager.unwrap(Session.class).flush();
    addActionMessage(getText("warrantApp.success"));

    return MESSAGE;
}

From source file:org.egov.ptis.domain.service.demolition.PropertyDemolitionService.java

License:Open Source License

@Transactional
public BasicProperty saveProperty(final Property oldProperty, final Property newProperty,
        final Character status, final String comments, final String workFlowAction, final Long approverPosition,
        final String additionalRule) throws TaxCalculatorExeption {
    PropertyImpl propertyModel;/* www . j  a  v  a  2s  .c  o m*/
    final BasicProperty basicProperty = oldProperty.getBasicProperty();
    final PropertyTypeMaster propTypeMstr = propertyTypeMasterDAO
            .getPropertyTypeMasterByCode(OWNERSHIP_TYPE_VAC_LAND);
    propertyModel = (PropertyImpl) newProperty;
    newProperty.getPropertyDetail().setPropertyTypeMaster(propTypeMstr);
    newProperty.getBasicProperty().setPropOccupationDate(newProperty.getPropertyDetail().getDateOfCompletion());
    final String areaOfPlot = String.valueOf(propertyModel.getPropertyDetail().getSitalArea().getArea());
    propertyModel = propertyService.createProperty(propertyModel, areaOfPlot,
            PROPERTY_MODIFY_REASON_FULL_DEMOLITION,
            propertyModel.getPropertyDetail().getPropertyTypeMaster().getId().toString(), null, null, status,
            null, null, null, null, null, null, null, null, null, null, FALSE);
    if (SOURCE_ONLINE.equalsIgnoreCase(propertyModel.getSource())
            && ApplicationThreadLocals.getUserId() == null)
        ApplicationThreadLocals.setUserId(securityUtils.getCurrentUser().getId());
    final Map<String, Installment> yearwiseInstMap = propertyTaxUtil.getInstallmentsForCurrYear(new Date());
    final Installment installmentFirstHalf = yearwiseInstMap.get(CURRENTYEAR_FIRST_HALF);
    final Installment installmentSecondHalf = yearwiseInstMap.get(CURRENTYEAR_SECOND_HALF);
    Date effectiveDate;
    if (DateUtils.between(new Date(), installmentFirstHalf.getFromDate(), installmentFirstHalf.getToDate()))
        effectiveDate = installmentFirstHalf.getFromDate();
    else
        effectiveDate = installmentSecondHalf.getFromDate();
    propertyModel.setBasicProperty(basicProperty);
    propertyModel.setEffectiveDate(effectiveDate);
    if (!propertyModel.getPropertyDetail().getPropertyTypeMaster().getCode().equals(OWNERSHIP_TYPE_VAC_LAND))
        propertyService.changePropertyDetail(propertyModel, new VacantProperty(), 0);
    propertyModel.getPropertyDetail().setCategoryType(VACANTLAND_PROPERTY_CATEGORY);
    basicProperty.setUnderWorkflow(TRUE);
    propertyModel.setBasicProperty(basicProperty);
    propertyModel.setPropertyModifyReason(DEMOLITION);
    basicProperty.addProperty(propertyModel);
    getSession().setFlushMode(FlushMode.MANUAL);
    transitionWorkFlow(propertyModel, comments, workFlowAction, approverPosition, additionalRule);
    final Installment currInstall = propertyTaxCommonUtils.getCurrentInstallment();

    final Property modProperty = propertyService.createDemand(propertyModel, effectiveDate);
    Ptdemand currPtDmd = null;
    for (final Ptdemand demand : modProperty.getPtDemandSet())
        if ("N".equalsIgnoreCase(demand.getIsHistory()))
            if (demand.getEgInstallmentMaster().equals(currInstall)) {
                currPtDmd = demand;
                break;
            }
    Ptdemand oldCurrPtDmd = null;
    for (final Ptdemand ptDmd : oldProperty.getPtDemandSet())
        if ("N".equalsIgnoreCase(ptDmd.getIsHistory()))
            if (ptDmd.getEgInstallmentMaster().equals(currInstall)) {
                oldCurrPtDmd = ptDmd;
                break;
            }

    Installment effectiveInstall;
    final Module module = moduleDao.getModuleByName(PTMODULENAME);
    effectiveInstall = installmentDao.getInsatllmentByModuleForGivenDate(module, effectiveDate);
    propertyService.addArrDmdDetToCurrentDmd(oldCurrPtDmd, currPtDmd, effectiveInstall, true);
    basicProperty.addProperty(modProperty);
    for (final Ptdemand ptDemand : modProperty.getPtDemandSet())
        propertyPerService.applyAuditing(ptDemand.getDmdCalculations());
    adjustCollection(oldCurrPtDmd, currPtDmd, effectiveInstall);
    propertyService.updateIndexes(propertyModel, APPLICATION_TYPE_DEMOLITION);
    propertyPerService.update(basicProperty);
    getSession().flush();
    return basicProperty;
}

From source file:org.egov.works.web.actions.contractoradvance.SearchContractorAdvanceRequisitionAction.java

License:Open Source License

public String searchList() {
    getPersistenceService().getSession().setDefaultReadOnly(true);
    getPersistenceService().getSession().setFlushMode(FlushMode.MANUAL);
    boolean isError = false;
    if (advanceRequisitionFromDate != null && advanceRequisitionToDate == null) {
        addFieldError("advanceRequisitionToDate", getText("search.advanceRequisitionToDate.null"));
        isError = true;//from w ww.j  a  va  2  s  .  co m
    }
    if (advanceRequisitionToDate != null && advanceRequisitionFromDate == null) {
        addFieldError("startdate", getText("search.advanceRequisitionFromDate.null"));
        isError = true;
    }

    if (!DateUtils.compareDates(advanceRequisitionToDate, advanceRequisitionFromDate)) {
        addFieldError("advanceRequisitionToDate",
                getText("advanceRequisitionFromDate.greaterthan.advanceRequisitionToDate"));
        isError = true;
    }

    if (isError)
        return SEARCH;

    setPageSize(WorksConstants.PAGE_SIZE);
    super.search();

    if (searchResult != null && searchResult.getList() != null && !searchResult.getList().isEmpty())
        setOwnerName();
    return SEARCH;
}

From source file:org.egov.works.web.actions.contractoradvance.SearchEstimateForContractorAdvanceAction.java

License:Open Source License

public String searchList() {
    getPersistenceService().getSession().setDefaultReadOnly(true);
    getPersistenceService().getSession().setFlushMode(FlushMode.MANUAL);
    boolean isError = false;
    if (fromDate != null && toDate == null) {
        addFieldError("enddate", getText("search.endDate.null"));
        isError = true;/*from w w w.  ja v  a2s  .co  m*/
    }
    if (toDate != null && fromDate == null) {
        addFieldError("startdate", getText("search.startDate.null"));
        isError = true;
    }

    if (!DateUtils.compareDates(toDate, fromDate)) {
        addFieldError("enddate", getText("greaterthan.endDate.fromDate"));
        isError = true;
    }

    if (isError)
        return SEARCH;

    setPageSize(WorksConstants.PAGE_SIZE);
    super.search();

    if (searchResult != null && searchResult.getList() != null && !searchResult.getList().isEmpty())
        setTenderType();
    return SEARCH;
}

From source file:org.encuestame.core.cron.IndexRebuilder.java

License:Apache License

/**
 * Reindex domain object.// w w w  .  ja va  2s. c om
 * @param fullTextSession {@link FullTextSession}.
 * @param clazz domain class.
 */
public static void reindex(final FullTextSession fullTextSession, final Class<?> clazz) {
    log.debug(clazz.getName() + " purge index ...");
    //purge all index content.
    fullTextSession.purgeAll(clazz);
    fullTextSession.flushToIndexes();
    fullTextSession.getSearchFactory().optimize(clazz);
    log.debug(clazz.getName() + " starting index ...");
    final long startTime = System.currentTimeMillis();
    fullTextSession.setFlushMode(FlushMode.MANUAL);
    fullTextSession.setCacheMode(CacheMode.IGNORE);
    final Transaction transaction = fullTextSession.beginTransaction();
    //Scrollable results will avoid loading too many objects in memory
    final ScrollableResults results = fullTextSession.createCriteria(clazz).setFetchSize(100)
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY).scroll(ScrollMode.FORWARD_ONLY);
    int index = 0;
    while (results.next()) {
        index++;
        fullTextSession.index(results.get(0));
        if (index % 100 == 0) {
            fullTextSession.flushToIndexes();
            fullTextSession.flush();
            fullTextSession.clear();
        }
    }
    fullTextSession.flushToIndexes();
    fullTextSession.getSearchFactory().optimize(clazz);
    transaction.commit();
    log.debug(clazz.getName() + " Reindex end in " + ((System.currentTimeMillis() - startTime) / 1000.0)
            + " seconds.");
}

From source file:org.endeavour.mgmt.model.persistence.PersistenceManager.java

License:Open Source License

public void beginTransaction() {
    this.session = SessionFactoryManager.getInstance().openSession();
    this.session.setFlushMode(FlushMode.MANUAL);
    this.transaction = session.beginTransaction();
}

From source file:org.eurocarbdb.interceptor.PersistenceLifecycleInterceptor.java

License:Open Source License

/** 
*   Manually flushes the Hibernate session, if there is one, thereby
*   committing unsaved data to the database in the form of inserts/updates. 
*///from w w  w  .  jav  a2 s  .  c o m
public void flush() {
    EntityManager em = getEntityManager();
    if (em instanceof HibernateEntityManager) {
        log.debug("flushing Hibernate session");
        HibernateEntityManager hem = (HibernateEntityManager) em;
        // try 
        // {
        hem.flush(); // allow flush exceptions to be thrown & caught
        // } 
        // catch ( Exception ex ) 
        // {
        //     log.warn("Caught exception while trying to flush data store", ex );
        //     this.exceptionWasThrown = true;
        //     throw ex;
        // } 
        // finally 
        // {
        //     //  change the FlushMode to effectively read-only to render
        //  view to improve Hibernate performance
        log.debug("setting Hibernate flush_mode to MANUAL (ie: read-only)");
        hem.getHibernateSession().setFlushMode(FlushMode.MANUAL);
        // }
    } else
        log.debug("(not a hibernate entity manager)");
}

From source file:org.fornax.cartridges.sculptor.framework.web.hibernate.OpenHibernateSessionInConversationListener.java

License:Apache License

private Session createSession(RequestContext context) {
    Session session = (entityInterceptor != null ? sessionFactory.openSession(entityInterceptor)
            : sessionFactory.openSession());
    session.setFlushMode(FlushMode.MANUAL);
    return session;
}

From source file:org.forzaframework.orm.hibernate3.support.OpenSessionInThreadTask.java

License:Apache License

protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    FlushMode flushMode = FlushMode.MANUAL;
    if (flushMode != null) {
        session.setFlushMode(flushMode);
    }//from   ww  w  . java 2s. co  m
    return session;
}