Example usage for org.hibernate Session delete

List of usage examples for org.hibernate Session delete

Introduction

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

Prototype

void delete(Object object);

Source Link

Document

Remove a persistent instance from the datastore.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

@Test
public void testGetUserFromUserIDNmNsSeq() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from ww w  . j a v a2  s . com
    User user = new User("UserIdTest", "Permission", "USER");
    ses.persist(user);
    ses.getTransaction().commit();

    UserIDType uid = new UserIDType();
    UserNameNamespaceSequence seq = new UserNameNamespaceSequence();
    seq.setUserNamespace(user.getNamespace());
    seq.setUserName(user.getName());
    uid.setUserNameNamespaceSequence(seq);

    Method meth = PermissionsSOAPImpl.class.getDeclaredMethod("getUserFromUserID", UserIDType.class,
            Session.class);
    meth.setAccessible(true);
    User loaded = (User) meth.invoke(this.permissions, uid, ses);
    assertNotNull(loaded);

    ses.beginTransaction();
    ses.delete(user);
    ses.getTransaction().commit();

    assertEquals(user.getId().longValue(), loaded.getId().longValue());
    assertEquals(user.getName(), loaded.getName());
    assertEquals(user.getNamespace(), loaded.getNamespace());
    assertEquals(user.getPersona(), loaded.getPersona());

    ses.close();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsSOAPImplTester.java

License:Open Source License

@Test
public void testGetUserFromUserIDQName() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from  ww w  .  j  ava2  s.com*/
    User user = new User("UserIdTest", "Permission", "USER");
    ses.persist(user);
    ses.getTransaction().commit();

    UserIDType uid = new UserIDType();
    uid.setUserQName(user.getNamespace() + ":" + user.getName());

    Method meth = PermissionsSOAPImpl.class.getDeclaredMethod("getUserFromUserID", UserIDType.class,
            Session.class);
    meth.setAccessible(true);
    User loaded = (User) meth.invoke(this.permissions, uid, ses);
    assertNotNull(loaded);

    ses.beginTransaction();
    ses.delete(user);
    ses.getTransaction().commit();

    assertEquals(user.getId().longValue(), loaded.getId().longValue());
    assertEquals(user.getName(), loaded.getName());
    assertEquals(user.getNamespace(), loaded.getNamespace());
    assertEquals(user.getPersona(), loaded.getPersona());

    ses.close();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsTester.java

License:Open Source License

/**
 * Test method for {@link Permissions#deleteUserAssociation(DeleteUserAssociation)}.
 *///from   w  ww.j av a 2 s  . c o m
@Test
public void testDeleteUserAssociation() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    User user = new User("tuser", "ns", "USER");
    ses.save(user);
    UserClass cls = new UserClass();
    cls.setName("tclass");
    ses.save(cls);
    UserAssociation ass = new UserAssociation();
    ass.setId(new UserAssociationId(user.getId(), cls.getId()));
    ass.setUser(user);
    ass.setUserClass(cls);
    ses.save(ass);
    ses.getTransaction().commit();

    DeleteUserAssociation req = new DeleteUserAssociation();
    UserAssociationType assocType = new UserAssociationType();
    req.setDeleteUserAssociation(assocType);
    assocType.setRequestorQName("TESTNS:mdiponio");
    UserIDType uid = new UserIDType();
    uid.setUserQName("ns:tuser");
    assocType.setUser(uid);
    UserClassIDType cid = new UserClassIDType();
    cid.setUserClassName("tclass");
    assocType.setUserClass(cid);

    DeleteUserAssociationResponse resp = this.permissions.deleteUserAssociation(req);
    assertNotNull(resp);

    OperationResponseType op = resp.getDeleteUserAssociationResponse();
    assertNotNull(op);
    assertTrue(op.getSuccessful());
    assertEquals(0, op.getFailureCode());
    assertNull(op.getFailureReason());

    ses.beginTransaction();
    ses.delete(user);
    ses.delete(cls);
    ses.getTransaction().commit();

    OMElement ele = resp.getOMElement(DeleteUserAssociationResponse.MY_QNAME, OMAbstractFactory.getOMFactory());
    assertNotNull(ele);
    String xml = ele.toStringWithConsume();
    assertNotNull(xml);
    assertTrue(xml.contains("<successful>true</successful>"));
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsTester.java

License:Open Source License

/**
 * Test method for {@link Permissions#deleteUserAssociation(DeleteUserAssociation)}.
 */// ww  w  .  j  a v  a 2 s .  c  om
@Test
public void testDeleteUserAssociationID() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    User user = new User("tuser", "ns", "USER");
    ses.save(user);
    UserClass cls = new UserClass();
    cls.setName("tclass");
    ses.save(cls);
    UserAssociation ass = new UserAssociation();
    ass.setId(new UserAssociationId(user.getId(), cls.getId()));
    ass.setUser(user);
    ass.setUserClass(cls);
    ses.save(ass);
    ses.getTransaction().commit();

    DeleteUserAssociation req = new DeleteUserAssociation();
    UserAssociationType assocType = new UserAssociationType();
    req.setDeleteUserAssociation(assocType);
    assocType.setRequestorQName("TESTNS:mdiponio");
    UserIDType uid = new UserIDType();
    uid.setUserID(String.valueOf(user.getId()));
    assocType.setUser(uid);
    UserClassIDType cid = new UserClassIDType();
    cid.setUserClassID(cls.getId().intValue());
    assocType.setUserClass(cid);

    DeleteUserAssociationResponse resp = this.permissions.deleteUserAssociation(req);
    assertNotNull(resp);

    OperationResponseType op = resp.getDeleteUserAssociationResponse();
    assertNotNull(op);
    assertTrue(op.getSuccessful());
    assertEquals(0, op.getFailureCode());
    assertNull(op.getFailureReason());

    ses.beginTransaction();
    ses.delete(user);
    ses.delete(cls);
    ses.getTransaction().commit();

    OMElement ele = resp.getOMElement(DeleteUserAssociationResponse.MY_QNAME, OMAbstractFactory.getOMFactory());
    assertNotNull(ele);
    String xml = ele.toStringWithConsume();
    assertNotNull(xml);
    assertTrue(xml.contains("<successful>true</successful>"));
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsTester.java

License:Open Source License

@Test
public void testGetUserFromUserID() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from  w  w  w . j av  a  2  s . co m*/
    User user = new User("UserIdTest", "Permission", "USER");
    ses.persist(user);
    ses.getTransaction().commit();

    UserIDType uid = new UserIDType();
    uid.setUserID(String.valueOf(user.getId()));

    Method meth = Permissions.class.getDeclaredMethod("getUserFromUserID", UserIDType.class, Session.class);
    meth.setAccessible(true);
    User loaded = (User) meth.invoke(this.permissions, uid, ses);
    assertNotNull(loaded);

    ses.beginTransaction();
    ses.delete(user);
    ses.getTransaction().commit();

    assertEquals(user.getId().longValue(), loaded.getId().longValue());
    assertEquals(user.getName(), loaded.getName());
    assertEquals(user.getNamespace(), loaded.getNamespace());
    assertEquals(user.getPersona(), loaded.getPersona());

    ses.close();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsTester.java

License:Open Source License

@Test
public void testGetUserFromUserIDNmNsSeq() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();// ww  w  . j a v a2  s .  co  m
    User user = new User("UserIdTest", "Permission", "USER");
    ses.persist(user);
    ses.getTransaction().commit();

    UserIDType uid = new UserIDType();
    UserNameNamespaceSequence seq = new UserNameNamespaceSequence();
    seq.setUserNamespace(user.getNamespace());
    seq.setUserName(user.getName());
    uid.setUserNameNamespaceSequence(seq);

    Method meth = Permissions.class.getDeclaredMethod("getUserFromUserID", UserIDType.class, Session.class);
    meth.setAccessible(true);
    User loaded = (User) meth.invoke(this.permissions, uid, ses);
    assertNotNull(loaded);

    ses.beginTransaction();
    ses.delete(user);
    ses.getTransaction().commit();

    assertEquals(user.getId().longValue(), loaded.getId().longValue());
    assertEquals(user.getName(), loaded.getName());
    assertEquals(user.getNamespace(), loaded.getNamespace());
    assertEquals(user.getPersona(), loaded.getPersona());

    ses.close();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.intf.tests.PermissionsTester.java

License:Open Source License

@Test
public void testGetUserFromUserIDQName() throws Exception {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from w w w  .  j av  a 2  s .com*/
    User user = new User("UserIdTest", "Permission", "USER");
    ses.persist(user);
    ses.getTransaction().commit();

    UserIDType uid = new UserIDType();
    uid.setUserQName(user.getNamespace() + ":" + user.getName());

    Method meth = Permissions.class.getDeclaredMethod("getUserFromUserID", UserIDType.class, Session.class);
    meth.setAccessible(true);
    User loaded = (User) meth.invoke(this.permissions, uid, ses);
    assertNotNull(loaded);

    ses.beginTransaction();
    ses.delete(user);
    ses.getTransaction().commit();

    assertEquals(user.getId().longValue(), loaded.getId().longValue());
    assertEquals(user.getName(), loaded.getName());
    assertEquals(user.getNamespace(), loaded.getNamespace());
    assertEquals(user.getPersona(), loaded.getPersona());

    ses.close();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.tests.RigManagementTester.java

License:Open Source License

@Test
public void testGetTypes() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from  w  w  w .j  av  a 2 s .com
    RigType rt = new RigType();
    rt.setName("rigmanagetest");
    ses.save(rt);
    ses.getTransaction().commit();

    GetTypesResponse response = this.service.getTypes(new GetTypes());

    ses.beginTransaction();
    ses.delete(rt);
    ses.getTransaction().commit();

    assertNotNull(response);
    RigTypesType types = response.getGetTypesResponse();
    assertNotNull(response);

    RigTypeType ids[] = types.getTypes();
    assertNotNull(ids);
    assertTrue(ids.length > 0);

    boolean typeFound = false;
    for (RigTypeType ty : ids) {
        assertNotNull(ty.getName());
        if (ty.getName().equals(rt.getName())) {
            typeFound = true;
            assertFalse(ty.getIsOnline());
            assertFalse(ty.getIsAlarmed());
            assertEquals(0, ty.getNumberRigs());
        }
    }

    assertTrue(typeFound);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.tests.RigManagementTester.java

License:Open Source License

/**
 * Test method for {@link au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.RigManagement#getTypeStatus(au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.GetTypeStatus)}.
 *//*from w  w w  . j  av a  2  s . co m*/
@Test
public void testGetTypeStatus() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();
    RigType rt = new RigType();
    rt.setName("rigmanagetest");
    ses.save(rt);
    RigType rt2 = new RigType();
    rt2.setName("rigmanagetest2");
    ses.save(rt2);
    RigCapabilities caps = new RigCapabilities("rig,management,test");
    ses.save(caps);
    Rig r = new Rig();
    r.setOnline(false);
    r.setOfflineReason("test reason");
    r.setName("rigmanagementrig");
    r.setLastUpdateTimestamp(new Date());
    r.setRigCapabilities(caps);
    r.setRigType(rt);
    ses.save(r);
    RigOfflineSchedule ro = new RigOfflineSchedule();
    ro.setActive(true);
    ro.setStartTime(new Date(System.currentTimeMillis() - 60000));
    ro.setEndTime(new Date(System.currentTimeMillis() + 60000));
    ro.setRig(r);
    ro.setReason("testcase");
    ses.save(ro);
    Rig r2 = new Rig();
    r2.setName("rigmanagementrig2");
    r2.setLastUpdateTimestamp(new Date());
    r2.setRigCapabilities(caps);
    r2.setRigType(rt);
    r2.setActive(true);
    r2.setOnline(true);
    r2.setContactUrl("http://remotelabs/rig");
    ses.save(r2);
    Rig r3 = new Rig();
    r3.setName("rigmanagementrig3");
    r3.setLastUpdateTimestamp(new Date());
    r3.setRigCapabilities(caps);
    r3.setRigType(rt2);
    r3.setActive(true);
    r3.setOnline(true);
    r3.setContactUrl("http://remotelabs/rig");
    ses.save(r3);
    ses.getTransaction().commit();

    ses.refresh(rt);
    ses.refresh(r);
    ses.refresh(ro);

    GetTypeStatus request = new GetTypeStatus();
    RigTypeIDType id = new RigTypeIDType();
    id.setName(rt.getName());
    request.setGetTypeStatus(id);

    GetTypeStatusResponse response = this.service.getTypeStatus(request);

    ses.beginTransaction();
    ses.delete(ro);
    ses.delete(r);
    ses.delete(r2);
    ses.delete(r3);
    ses.delete(caps);
    ses.delete(rt);
    ses.delete(rt2);
    ses.getTransaction().commit();

    assertNotNull(response);

    RigTypeType rigType = response.getGetTypeStatusResponse();
    assertEquals(rt.getName(), rigType.getName());
    assertNotNull(rigType);
    assertTrue(rigType.getIsOnline());
    assertFalse(rigType.getIsAlarmed());
    assertEquals(2, rigType.getNumberRigs());

    au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rigs[] = rigType.getRigs();
    assertNotNull(rigs);
    assertEquals(rigs.length, 2);

    for (au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rig : rigs) {
        assertNotNull(r.getName());
        RigTypeIDType rtid = rig.getRigType();
        assertNotNull(rtid);
        assertEquals(rt.getName(), rtid.getName());
        assertEquals(caps.getCapabilities(), rig.getCapabilities());
        assertNull(rig.getLastLogs());
        assertNull(rig.getOfflinePeriods());

        if (rig.getName().equals(r.getName())) {
            assertFalse(rig.getIsRegistered());
            assertFalse(rig.getIsOnline());
            assertFalse(rig.getIsInSession());
            assertFalse(rig.getIsAlarmed());
            assertNull(rig.getSessionUser());
            assertEquals(r.getOfflineReason(), rig.getOfflineReason());
            assertNull(rig.getContactURL());

        } else if (rig.getName().equals(r2.getName())) {
            assertTrue(rig.getIsRegistered());
            assertTrue(rig.getIsOnline());
            assertFalse(rig.getIsInSession());
            assertFalse(rig.getIsAlarmed());
            assertNull(rig.getSessionUser());
            assertNull(rig.getOfflineReason());
            assertEquals(r2.getContactUrl(), rig.getContactURL());
        } else {
            fail("Unknown rig name");
        }
    }
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.tests.RigManagementTester.java

License:Open Source License

@Test
public void testGetRig() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*w w w  .j a v  a  2s .  c  o m*/
    RigType rt = new RigType();
    rt.setName("rigmanagetest");
    ses.save(rt);
    RigCapabilities caps = new RigCapabilities("rig,management,test");
    ses.save(caps);
    Rig r = new Rig();
    r.setActive(true);
    r.setOnline(true);
    r.setContactUrl("foo://bar");
    r.setName("rigmanagementrig");
    r.setLastUpdateTimestamp(new Date());
    r.setRigCapabilities(caps);
    r.setRigType(rt);
    ses.save(r);
    RigOfflineSchedule ro = new RigOfflineSchedule();
    ro.setActive(true);
    ro.setStartTime(new Date(System.currentTimeMillis() - 60000));
    ro.setEndTime(new Date(System.currentTimeMillis() + 60000));
    ro.setRig(r);
    ro.setReason("testcase");
    ses.save(ro);
    RigLog l1 = new RigLog();
    l1.setTimeStamp(new Date());
    l1.setReason("register received");
    l1.setRig(r);
    l1.setOldState(RigLog.NOT_REGISTERED);
    l1.setNewState(RigLog.OFFLINE);
    ses.save(l1);
    RigLog l2 = new RigLog();
    l2.setTimeStamp(new Date(System.currentTimeMillis() + 100000));
    l2.setReason("online received");
    l2.setRig(r);
    l2.setOldState(RigLog.OFFLINE);
    l2.setNewState(RigLog.ONLINE);
    ses.save(l2);
    ses.getTransaction().commit();

    ses.refresh(rt);
    ses.refresh(r);
    ses.refresh(ro);

    GetRig request = new GetRig();
    RigIDType rid = new RigIDType();
    rid.setName(r.getName());
    request.setGetRig(rid);

    GetRigResponse response = this.service.getRig(request);

    ses.beginTransaction();
    ses.delete(l1);
    ses.delete(l2);
    ses.delete(ro);
    ses.delete(r);
    ses.delete(caps);
    ses.delete(rt);
    ses.getTransaction().commit();

    assertNotNull(response);
    au.edu.uts.eng.remotelabs.schedserver.rigmanagement.intf.types.RigType rig = response.getGetRigResponse();
    assertNotNull(rig);

    assertEquals(r.getName(), rig.getName());
    assertEquals(caps.getCapabilities(), rig.getCapabilities());

    RigTypeIDType tid = rig.getRigType();
    assertNotNull(tid);
    assertEquals(rt.getName(), tid.getName());

    assertTrue(rig.getIsOnline());
    assertTrue(rig.getIsRegistered());
    assertFalse(rig.getIsInSession());
    assertNull(rig.getSessionUser());
    assertFalse(rig.getIsAlarmed());
    assertNull(rig.getOfflineReason());
    assertEquals(r.getContactUrl(), rig.getContactURL());

    RigLogType logs[] = rig.getLastLogs();
    assertNotNull(logs);
    assertEquals(2, logs.length);

    RigLogType log = logs[1];
    assertEquals(l1.getReason(), log.getReason());
    assertEquals(log.getOldState(), RigStateType.NOT_REGISTERED);
    assertEquals(log.getNewState(), RigStateType.OFFLINE);

    log = logs[0];
    assertEquals(l2.getReason(), log.getReason());
    assertEquals(log.getOldState(), RigStateType.OFFLINE);
    assertEquals(log.getNewState(), RigStateType.ONLINE);

    OfflinePeriodType offs[] = rig.getOfflinePeriods();
    assertNotNull(offs);
    assertEquals(1, offs.length);

    OfflinePeriodType off = offs[0];
    assertEquals(ro.getId().intValue(), off.getId());
    assertEquals(ro.getReason(), off.getReason());
    assertEquals(ro.getStartTime().getTime(), off.getStart().getTimeInMillis());
    assertEquals(ro.getEndTime().getTime(), off.getEnd().getTimeInMillis());
}