Example usage for org.hibernate Session createQuery

List of usage examples for org.hibernate Session createQuery

Introduction

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

Prototype

@Override
    org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);

Source Link

Usage

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

License:Open Source License

@Test
public void testRemoveRigAlreadyInActive() {
    Session ses = DataAccessActivator.getNewSession();
    RigType type = new RigType("rlrType", 180, false);
    new RigTypeDao(ses).persist(type);
    RigCapabilities caps = new RigCapabilities("rlrA,rlrB");
    new RigCapabilitiesDao(ses).persist(caps);
    Rig rig = new Rig(type, caps, "rlr", "http://rlr", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, false, true);
    rig.setActive(false);/*from www  .ja v  a  2 s  .c  o m*/
    rig.setOnline(true);
    rig.setOfflineReason("foo bar");
    new RigDao(ses).persist(rig);

    assertTrue(this.remove.removeRig("rlr", "Shutting down."));

    ses.refresh(rig);
    assertFalse(rig.isActive());
    assertFalse(rig.isOnline());
    assertNull(rig.getContactUrl());
    assertNotNull(rig.getOfflineReason());
    assertEquals("Shutting down.", 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.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  v a2s .  c  o m
@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);
    Rig tmdOut = new Rig(type, caps, "tm1", "http://tm", new Date(System.currentTimeMillis() - 86400001), // A day ago
            true, null, false, true, true);
    tmdOut.setActive(true);
    tmdOut.setOnline(true);
    tmdOut.setOfflineReason(null);
    RigDao rigDao = new RigDao(ses);
    rigDao.persist(tmdOut);

    this.checker.run();

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

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

    ses.beginTransaction();
    ses.delete(tmdOut);
    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()}.
 *///w w  w . j  a v  a2s .  c  om
@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()}.
 *///from  w  ww.j  a  v  a2s.  c  o m
@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()}.
 *//* w  ww .java  2s  .com*/
@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);//  w  w  w.  ja v  a2  s.  com
    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() - 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 ww w .j  a  v  a2s. c  om
    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 ww  . j a  v  a  2s  .com
    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.  ja  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. *//* w ww .  j a  va 2 s. co  m*/
    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();
}