/** Tests to validate that a session holding JDBC resources will not be allowed to serialize. */
  @Test
  public final void testEnabledFilterSerialization() throws Throwable {
    prepare();
    Session sessionUnderTest = getSessionUnderTest();

    sessionUnderTest.enableFilter("nameIsNull");
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    disconnect(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    byte[] bytes = SerializationHelper.serialize(sessionUnderTest);
    checkSerializedState(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    reconnect(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    disconnect(sessionUnderTest);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    Session s2 = (Session) SerializationHelper.deserialize(bytes);
    checkDeserializedState(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    reconnect(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    disconnect(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));
    reconnect(s2);
    assertNotNull(sessionUnderTest.getEnabledFilter("nameIsNull"));

    release(sessionUnderTest);
    release(s2);
    done();
  }
  @Before("execution(* gov.nih.nci.cagrid.portal.dao.GridServiceDao.get*(..))")
  public void enableFilter() {
    logger.debug("Activating filter :" + filterName);

    Session session = getSession(false);
    if (session != null) {
      Filter filter = session.getEnabledFilter(filterName);
      if (filter == null) {
        filter = session.enableFilter(getFilterName()).setParameter(parameterName, parameterValue);
      }
    } else logger.debug("No hibernate session available. Will not apply filters");
  }
Example #3
0
 public Filter getEnabledFilter(String filterName) {
   return session.getEnabledFilter(filterName);
 }