Example usage for org.hibernate Filter validate

List of usage examples for org.hibernate Filter validate

Introduction

In this page you can find the example usage for org.hibernate Filter validate.

Prototype

public void validate() throws HibernateException;

Source Link

Document

Perform validation of the filter state.

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);
    }/*from ww w  . ja  va 2  s  .  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;
    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.");
            }// w w  w  . j a  v a 2  s  .co  m
            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:nz.co.nomadconsulting.simplepersistence.TransactionInterceptor.java

License:Apache License

private void enableFilter(final Filter f, final EntityManager entityManager) {
    try {//from ww w .j av  a  2s . c  o m
        if (!(Boolean) expressions.evaluateValueExpression(f.getEnabledExpression())) {
            return;
        }
        final org.hibernate.Filter filter = getSession(entityManager).enableFilter(f.getName());
        for (final Map.Entry<String, String> me : f.getParameters().entrySet()) {
            final Object filterValue = expressions.evaluateValueExpression(me.getValue());
            if (filterValue instanceof Collection) {
                filter.setParameterList(me.getKey(), (Collection<?>) filterValue);
            } else {
                filter.setParameter(me.getKey(), filterValue);
            }
        }
        filter.validate();
    } catch (final NotHibernateException nhe) {
        throw new RuntimeException("bob");
    }
}