Example usage for org.hibernate Session getEnabledFilter

List of usage examples for org.hibernate Session getEnabledFilter

Introduction

In this page you can find the example usage for org.hibernate Session getEnabledFilter.

Prototype

Filter getEnabledFilter(String filterName);

Source Link

Document

Retrieve a currently enabled filter by name.

Usage

From source file:com.masetta.spann.orm.hibernate.integration.FilterActivationsTest.java

License:Apache License

private Session expectFilterEnable(String filter, boolean alreadyEnabled, Object... params) {
    Session session = expectSessionAccess();
    EasyMock.expect(session.getEnabledFilter(filter))
            .andReturn(alreadyEnabled ? createMock(Filter.class) : null);

    Filter filterMock = createMock(Filter.class);
    EasyMock.expect(session.enableFilter(filter)).andReturn(filterMock);

    for (int i = 0; i < params.length;) {
        filterMock.setParameter((String) params[i++], params[i++]);
        EasyMock.expectLastCall().andReturn(filterMock);
    }//w ww.j  a va2s.  c  o  m

    filterMock.validate();
    EasyMock.expectLastCall();

    return session;
}

From source file:com.masetta.spann.orm.hibernate.support.HibernateSupport.java

License:Apache License

private static List<String> enableFilters(Session session, Collection<FilterActivation> filterList) {

    if (filterList == null || filterList.isEmpty())
        return Collections.emptyList();

    List<String> applied = new ArrayList<String>();
    Filter filter;/*from w w  w.  ja v a 2 s  . c o m*/
    for (FilterActivation f : filterList) {
        String filterName = f.getName();

        Collection<Map.Entry<String, Object>> parameters = f.getParameters();
        // skip filters which are already enabled,
        filter = session.getEnabledFilter(filterName);
        if (filter != null) {
            if (f.getParameters().size() > 0) {
                throw new IllegalArgumentException("Filter '" + f.getName()
                        + "' is already activated. Can not enable filter with different arguments.");
            }
            continue;
        }

        filter = session.enableFilter(filterName);
        applied.add(filterName);
        for (Map.Entry<String, Object> e : parameters) {
            Object value = e.getValue();
            if (value == null) {
                filter.setParameter(e.getKey(), value);
            } else if (value instanceof Collection) {
                filter.setParameterList(e.getKey(), (Collection) value);
            } else if (value.getClass().isArray()) {
                filter.setParameterList(e.getKey(), (Object[]) value);
            } else {
                filter.setParameter(e.getKey(), value);
            }
        }
        filter.validate();
    }
    return applied;
}

From source file:fr.hoteia.qalingo.core.dao.impl.AbstractGenericDaoImpl.java

License:Apache License

void initProductSkuFilter(Session session, Long marketAreaId, Long retailerId) {
    session.enableFilter("filterProductSkuAttributeIsGlobal");
    session.enableFilter("filterProductSkuAttributeByMarketArea").setParameter("marketAreaId", marketAreaId);

    session.enableFilter("filterProductSkuAssetIsGlobal");
    session.enableFilter("filterProductSkuAssetByMarketArea").setParameter("marketAreaId", marketAreaId);

    session.enableFilter("filterProductSkuPriceByMarketAreaAndRetailer");
    session.getEnabledFilter("filterProductSkuPriceByMarketAreaAndRetailer").setParameter("marketAreaId",
            marketAreaId);//  w w w.j a v  a  2 s . c  om
    session.getEnabledFilter("filterProductSkuPriceByMarketAreaAndRetailer").setParameter("retailerId",
            retailerId);

    session.enableFilter("filterProductSkuStockByMarketAreaAndRetailer");
    session.getEnabledFilter("filterProductSkuStockByMarketAreaAndRetailer").setParameter("marketAreaId",
            marketAreaId);
    session.getEnabledFilter("filterProductSkuStockByMarketAreaAndRetailer").setParameter("retailerId",
            retailerId);
}

From source file:it.eng.spagobi.commons.dao.AbstractHibernateDAO.java

License:Mozilla Public License

protected void disableTenantFilter(Session session) {
    Filter filter = session.getEnabledFilter(TENANT_FILTER_NAME);
    if (filter != null) {
        session.disableFilter(TENANT_FILTER_NAME);
    }/*from  www.j  av a2 s .  c  om*/
}

From source file:ome.services.query.Query.java

License:Open Source License

/**
 * standard filter used by many subclasses which uses the
 * {@link PojoOptions#isExperimenter()} and {@link PojoOptions#isGroup()}
 * booleans to see if a filter should be turned on. If both booleans are
 * active, group wins. The constant {@link Parameters#OWNER_ID} or
 * {@link Parameters#GROUP_ID} is then used to define a filter.
 *///from   w w w.ja v a 2 s  . c  o m
protected void ownerOrGroupFilters(Session session, String[] ownerFilters, String[] groupFilters) {

    if (params.isGroup()) {
        for (String filter : groupFilters) {
            if (session.getEnabledFilter(filter) != null) {
                newlyEnabledFilters.add(filter);
            }

            session.enableFilter(filter).setParameter(GROUP_ID, params.getGroup());
        }
    } else if (params.isExperimenter()) {
        for (String filter : ownerFilters) {
            if (session.getEnabledFilter(filter) != null) {
                newlyEnabledFilters.add(filter);
            }

            session.enableFilter(filter).setParameter(OWNER_ID, params.getExperimenter());
        }
    }

}

From source file:org.springframework.orm.hibernate3.HibernateTemplate.java

License:Apache License

@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
    Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
    Filter filter = session.getEnabledFilter(filterName);
    if (filter == null) {
        filter = session.enableFilter(filterName);
    }/*from w ww .ja v a 2s.c om*/
    return filter;
}

From source file:org.springframework.orm.hibernate3.StatelessHibernateTemplate.java

License:Apache License

public Filter enableFilter(String filterName) throws IllegalStateException {
    Session session = SessionFactoryUtils.getSession(getSessionFactory(), false);
    Filter filter = session.getEnabledFilter(filterName);
    if (filter == null) {
        filter = session.enableFilter(filterName);
    }//w  w w  .  j a va 2 s. c  om
    return filter;
}

From source file:org.springframework.orm.hibernate4.HibernateTemplate.java

License:Apache License

@Override
public Filter enableFilter(String filterName) throws IllegalStateException {
    Session session = getSessionFactory().getCurrentSession();
    Filter filter = session.getEnabledFilter(filterName);
    if (filter == null) {
        filter = session.enableFilter(filterName);
    }/*  w ww.j  av a 2s  . c om*/
    return filter;
}