Example usage for org.hibernate Session refresh

List of usage examples for org.hibernate Session refresh

Introduction

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

Prototype

void refresh(Object object);

Source Link

Document

Re-read the state of the given instance from the underlying database.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.StatusTimeoutCheckerTester.java

License:Open Source License

/**
 * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.StatusTimeoutChecker#run()}.
 *///from   w  ww  .  j a  va  2  s. co m
@Test
public void testTwoTimedOutOneNotTimedOut() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("tmType", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("time,out");
    new RigCapabilitiesDao(ses).persist(caps);

    RigDao rigDao = new RigDao(ses);
    Rig noTmdOut1 = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis() - 295000), // Close  
            true, null, false, true, true);
    rigDao.persist(noTmdOut1);
    Rig tmdOut1 = new Rig(type, caps, "tm2", "http://tm", new Date(System.currentTimeMillis() - 301000), // Just over
            true, null, false, true, true);
    rigDao.persist(noTmdOut1);
    Rig tmdOut2 = new Rig(type, caps, "tm3", "http://tm", new Date(System.currentTimeMillis() - 1000000), true,
            null, false, true, true);
    rigDao.persist(noTmdOut1);
    rigDao.persist(tmdOut1);
    rigDao.persist(tmdOut2);

    this.checker.run();

    ses.refresh(noTmdOut1);
    assertTrue(noTmdOut1.isOnline());
    assertNull(noTmdOut1.getOfflineReason());
    assertTrue(noTmdOut1.isActive());
    assertTrue(noTmdOut1.isManaged());

    ses.refresh(tmdOut1);
    assertFalse(tmdOut1.isOnline());
    assertEquals("Timed out.", tmdOut1.getOfflineReason());
    assertFalse(tmdOut1.isActive());
    assertTrue(tmdOut1.isManaged());

    ses.refresh(tmdOut2);
    assertFalse(tmdOut2.isOnline());
    assertEquals("Timed out.", tmdOut2.getOfflineReason());
    assertFalse(tmdOut2.isActive());
    assertTrue(tmdOut2.isManaged());

    ses.beginTransaction();
    ses.createQuery("DELETE RigLog WHERE rig='" + tmdOut1.getId() + "'").executeUpdate();
    ses.createQuery("DELETE RigLog WHERE rig='" + tmdOut2.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(tmdOut1);
    ses.delete(tmdOut2);
    ses.delete(noTmdOut1);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.StatusTimeoutCheckerTester.java

License:Open Source License

/**
 * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.StatusTimeoutChecker#run()}.
 */// www.jav  a 2 s. c  om
@Test
public void testNoneNoneNoneTimedOut() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("tmType", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("time,out");
    new RigCapabilitiesDao(ses).persist(caps);

    RigDao rigDao = new RigDao(ses);
    Rig noTmdOut1 = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis() - 295000), // Close  
            true, null, false, true, true);
    Rig tmdOut1 = new Rig(type, caps, "tm2", "http://tm", new Date(System.currentTimeMillis() - 296000), // Closer
            true, null, false, true, true);
    Rig tmdOut2 = new Rig(type, caps, "tm3", "http://tm", new Date(System.currentTimeMillis() - 297000), // Closest 
            true, null, false, true, true);
    rigDao.persist(noTmdOut1);
    rigDao.persist(tmdOut1);
    rigDao.persist(tmdOut2);

    this.checker.run();

    ses.refresh(noTmdOut1);
    assertTrue(noTmdOut1.isOnline());
    assertNull(noTmdOut1.getOfflineReason());
    assertTrue(noTmdOut1.isActive());
    assertTrue(noTmdOut1.isManaged());

    ses.refresh(tmdOut1);
    assertTrue(tmdOut1.isOnline());
    assertNull(tmdOut1.getOfflineReason());
    assertTrue(tmdOut1.isActive());
    assertTrue(tmdOut1.isManaged());

    ses.refresh(tmdOut2);
    assertTrue(tmdOut2.isOnline());
    assertNull(tmdOut2.getOfflineReason());
    assertTrue(tmdOut2.isActive());
    assertTrue(tmdOut2.isManaged());

    ses.beginTransaction();
    ses.delete(tmdOut1);
    ses.delete(tmdOut2);
    ses.delete(noTmdOut1);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.StatusTimeoutCheckerTester.java

License:Open Source License

/**
 * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.StatusTimeoutChecker#run()}.
 *//*from  w w  w.j  a  va 2  s .  c om*/
@Test
public void testOneTimedout() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("tmType", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("time,out");
    new RigCapabilitiesDao(ses).persist(caps);

    RigDao rigDao = new RigDao(ses);
    Rig noTmdOut1 = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis() - 295000), // Close  
            true, null, false, true, true);
    Rig tmdOut1 = new Rig(type, caps, "tm2", "http://tm", new Date(System.currentTimeMillis() - 1000000), true,
            null, false, true, true);
    tmdOut1.setActive(false);
    Rig tmdOut2 = new Rig(type, caps, "tm3", "http://tm", new Date(System.currentTimeMillis() - 1000000), true,
            null, false, true, true);
    rigDao.persist(noTmdOut1);
    rigDao.persist(tmdOut1);
    rigDao.persist(tmdOut2);

    this.checker.run();

    ses.refresh(noTmdOut1);
    assertTrue(noTmdOut1.isOnline());
    assertNull(noTmdOut1.getOfflineReason());
    assertTrue(noTmdOut1.isActive());
    assertTrue(noTmdOut1.isManaged());

    ses.refresh(tmdOut1);
    assertTrue(tmdOut1.isOnline());
    assertNull(tmdOut1.getOfflineReason());
    assertFalse(tmdOut1.isActive());
    assertTrue(tmdOut1.isManaged());

    ses.refresh(tmdOut2);
    assertFalse(tmdOut2.isOnline());
    assertEquals("Timed out.", tmdOut2.getOfflineReason());
    assertFalse(tmdOut2.isActive());
    assertTrue(tmdOut2.isManaged());

    ses.beginTransaction();
    ses.createQuery("DELETE RigLog WHERE rig='" + tmdOut2.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(tmdOut1);
    ses.delete(tmdOut2);
    ses.delete(noTmdOut1);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.StatusTimeoutCheckerTester.java

License:Open Source License

/**
 * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.StatusTimeoutChecker#run()}.
 *//*  www  .  ja  va  2s  .  co m*/
@Test
public void testDiffTm() {
    StatusTimeoutChecker tmChecker = new StatusTimeoutChecker(120);

    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("tmType", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("time,out");
    new RigCapabilitiesDao(ses).persist(caps);

    RigDao rigDao = new RigDao(ses);
    Rig noTmdOut1 = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis() - 119000), // Close  
            true, null, false, true, true);
    Rig tmdOut1 = new Rig(type, caps, "tm2", "http://tm", new Date(System.currentTimeMillis() - 10000000), true,
            null, false, true, true);
    tmdOut1.setManaged(false);
    Rig tmdOut2 = new Rig(type, caps, "tm3", "http://tm", new Date(System.currentTimeMillis() - 180000), true,
            null, false, true, true);
    rigDao.persist(noTmdOut1);
    rigDao.persist(tmdOut1);
    rigDao.persist(tmdOut2);

    tmChecker.run();

    ses.refresh(noTmdOut1);
    assertTrue(noTmdOut1.isOnline());
    assertNull(noTmdOut1.getOfflineReason());
    assertTrue(noTmdOut1.isActive());
    assertTrue(noTmdOut1.isManaged());

    ses.refresh(tmdOut1);
    assertTrue(tmdOut1.isOnline());
    assertNull(tmdOut1.getOfflineReason());
    assertTrue(tmdOut1.isActive());
    assertFalse(tmdOut1.isManaged());

    ses.refresh(tmdOut2);
    assertFalse(tmdOut2.isOnline());
    assertEquals("Timed out.", tmdOut2.getOfflineReason());
    assertFalse(tmdOut2.isActive());
    assertTrue(tmdOut2.isManaged());

    ses.beginTransaction();
    ses.createQuery("DELETE RigLog WHERE rig='" + tmdOut2.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(tmdOut1);
    ses.delete(tmdOut2);
    ses.delete(noTmdOut1);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java

License:Open Source License

@Test
public void testUpdateStatus() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("ulrsTypr", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("ulrsA,urlsB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "urls", "http://urls", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);
    new RigDao(ses).persist(rig);

    assertTrue(this.update.updateStatus("urls", true, null));

    ses.refresh(rig);
    assertTrue(rig.isActive());//w w  w .  j a v a2  s  . c o  m
    assertTrue(rig.isOnline());
    assertNull(rig.getOfflineReason());

    Date ts = rig.getLastUpdateTimestamp();
    assertNotNull(ts);
    assertTrue(new Date().after(ts));
    assertTrue(new Date(System.currentTimeMillis() - 50000).before(ts));

    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rig);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java

License:Open Source License

@Test
public void testUpdateStatusGoodToBad() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("ulrsTypr", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("ulrsA,urlsB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "urls", "http://urls", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);

    /* Good. *//*from  w  w w .  ja va  2 s.  c o m*/
    rig.setOnline(true);
    rig.setOfflineReason(null);
    new RigDao(ses).persist(rig);

    assertTrue(this.update.updateStatus("urls", false, "Broken."));

    ses.refresh(rig);
    assertTrue(rig.isActive());
    assertFalse(rig.isOnline());
    assertNotNull(rig.getOfflineReason());
    assertEquals("Broken.", rig.getOfflineReason());

    Date ts = rig.getLastUpdateTimestamp();
    assertNotNull(ts);
    assertTrue(new Date().after(ts));
    assertTrue(new Date(System.currentTimeMillis() - 5000).before(ts));

    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rig);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java

License:Open Source License

@Test
public void testUpdateStatusBadToGood() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("ulrsTypr", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("ulrsA,urlsB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "urls", "http://urls", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);

    /* Bad. *//*from   w  w w . j  ava 2s  .c  om*/
    rig.setOnline(false);
    rig.setOfflineReason("Broken");
    new RigDao(ses).persist(rig);

    assertTrue(this.update.updateStatus("urls", true, null));

    ses.refresh(rig);
    assertTrue(rig.isActive());
    assertTrue(rig.isOnline());
    assertNull(rig.getOfflineReason());

    Date ts = rig.getLastUpdateTimestamp();
    assertNotNull(ts);
    assertTrue(new Date().after(ts));
    assertTrue(new Date(System.currentTimeMillis() - 5000).before(ts));

    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rig);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java

License:Open Source License

@Test
public void testUpdateStatusGoodToBadInActive() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("ulrsTypr", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("ulrsA,urlsB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "urls", "http://urls", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);

    /* Good. *///from w w  w. j  a v a  2s . c  o m
    rig.setOnline(true);
    rig.setOfflineReason(null);
    rig.setActive(false);
    new RigDao(ses).persist(rig);

    assertTrue(this.update.updateStatus("urls", false, "Broken."));

    ses.refresh(rig);
    assertTrue(rig.isActive());
    assertFalse(rig.isOnline());
    assertNotNull(rig.getOfflineReason());
    assertEquals("Broken.", rig.getOfflineReason());

    Date ts = rig.getLastUpdateTimestamp();
    assertNotNull(ts);
    assertTrue(new Date().after(ts));
    assertTrue(new Date(System.currentTimeMillis() - 5000).before(ts));

    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rig);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java

License:Open Source License

@Test
public void testUpdateStatusBadToGoodInActive() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("ulrsTypr", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("ulrsA,urlsB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "urls", "http://urls", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);

    /* Bad. *///from w w  w.  j  ava  2 s  . c  om
    rig.setOnline(false);
    rig.setOfflineReason("Broken");
    rig.setActive(false);
    new RigDao(ses).persist(rig);

    assertTrue(this.update.updateStatus("urls", true, null));

    ses.refresh(rig);
    assertTrue(rig.isActive());
    assertTrue(rig.isOnline());
    assertNull(rig.getOfflineReason());

    Date ts = rig.getLastUpdateTimestamp();
    assertNotNull(ts);
    assertTrue(new Date().after(ts));
    assertTrue(new Date(System.currentTimeMillis() - 5000).before(ts));

    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rig);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.impl.tests.UpdateLocalRigStatusTester.java

License:Open Source License

@Test
public void testUpdateStatusInActiveNotContactURL() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("ulrsTypr", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("ulrsA,urlsB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "urls", null, new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);

    /* Bad. *//*from   w w w  .  j  av  a2s .co  m*/
    rig.setOnline(false);
    rig.setOfflineReason("Broken");
    rig.setActive(false);
    new RigDao(ses).persist(rig);

    assertFalse(this.update.updateStatus("urls", true, null));
    assertNotNull(this.update.getFailedReason());

    ses.refresh(rig);
    assertFalse(rig.isActive());
    assertFalse(rig.isOnline());
    assertNotNull(rig.getOfflineReason());

    ses.beginTransaction();
    ses.createQuery("DELETE FROM RigLog WHERE rig='" + rig.getId() + "'").executeUpdate();
    ses.getTransaction().commit();

    ses.beginTransaction();
    ses.delete(rig);
    ses.delete(type);
    ses.delete(caps);
    ses.getTransaction().commit();
}