Example usage for org.hibernate Session save

List of usage examples for org.hibernate Session save

Introduction

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

Prototype

Serializable save(Object object);

Source Link

Document

Persist the given transient instance, first assigning a generated identifier.

Usage

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserClassDaoTester.java

License:Open Source License

@Test
public void testDeleteName() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from w  ww . ja  v  a 2  s.co m
    RigType ty = new RigType("type23", 10, false);
    ses.save(ty);
    RigCapabilities caps = new RigCapabilities("a,b");
    ses.save(caps);
    Rig rig = new Rig(ty, caps, "rig23", "http://rig/", new Date(), true, null, false, true, true);
    ses.save(rig);

    User us = new User("user", "userns", "ADMIN");
    ses.save(us);
    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 10);
    uc.setActive(true);
    uc.setKickable(true);
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(true);
    ses.save(uc);
    ResourcePermission perm = new ResourcePermission();
    perm.setUserClass(uc);
    perm.setType("RIG");
    perm.setActivityDetected(false);
    perm.setAllowedExtensions((short) 5);
    perm.setSessionActivityTimeout(300);
    perm.setSessionDuration(3600);
    perm.setExtensionDuration(300);
    perm.setQueueActivityTimeout(300);
    perm.setExpiryTime(new Date());
    perm.setStartTime(new Date());
    perm.setRig(rig);
    ses.save(perm);
    UserAssociationId id = new UserAssociationId(us.getId(), uc.getId());
    UserAssociation assoc = new UserAssociation(id, uc, us);
    ses.save(assoc);
    ses.getTransaction().commit();

    this.dao.delete(this.dao.findByName("clazz"));

    GenericDao<ResourcePermission> rpDao = new GenericDao<ResourcePermission>(ResourcePermission.class);
    assertNull(rpDao.get(perm.getId()));
    ses.refresh(us);
    assertEquals(0, us.getUserAssociations().size());

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

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserClassDaoTester.java

License:Open Source License

@Test
public void testDeleteUserAssociations() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from w w w  . j av a  2  s .c o m

    User us = new User("user", "userns", "ADMIN");
    ses.save(us);
    User us2 = new User("user2", "userns", "ADMIN");
    ses.save(us2);
    User us3 = new User("user3", "userns", "ADMIN");
    ses.save(us3);

    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 10);
    uc.setActive(true);
    uc.setKickable(true);
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(true);
    ses.save(uc);

    UserAssociationId id = new UserAssociationId(us.getId(), uc.getId());
    UserAssociation assoc = new UserAssociation(id, uc, us);
    ses.save(assoc);

    UserAssociationId id2 = new UserAssociationId(us2.getId(), uc.getId());
    UserAssociation assoc2 = new UserAssociation(id2, uc, us2);
    ses.save(assoc2);

    UserAssociationId id3 = new UserAssociationId(us3.getId(), uc.getId());
    UserAssociation assoc3 = new UserAssociation(id3, uc, us3);
    ses.save(assoc3);

    ses.getTransaction().commit();

    this.dao.getSession().refresh(uc);
    assertEquals(uc.getUserAssociations().size(), 3);

    this.dao.deleteUserAssociations(uc);

    this.dao.getSession().refresh(uc);
    assertEquals(uc.getUserAssociations().size(), 0);

    ses.beginTransaction();
    ses.delete(us);
    ses.delete(us2);
    ses.delete(us3);
    ses.delete(uc);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserClassDaoTester.java

License:Open Source License

@Test
public void testDeleteUserClassKeyRef() {
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();// www . java  2s . c  o m

    UserClass uc = new UserClass();
    uc.setName("clazz");
    uc.setPriority((short) 10);
    uc.setActive(true);
    uc.setKickable(true);
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(true);
    ses.save(uc);

    UserClassKey key = new UserClassKey();
    key.generateKey();
    key.setRemaining(1);
    key.setUserClass(uc);
    ses.save(key);

    UserClassKeyConstraint keyConst = new UserClassKeyConstraint();
    keyConst.setClassKey(key);
    keyConst.setName("foo_const");
    keyConst.setValue("bar_const");
    ses.save(keyConst);

    ses.getTransaction().commit();

    this.dao.delete(this.dao.get(uc.getId()));

    int num = (Integer) ses.createCriteria(UserClass.class).add(Restrictions.eq("id", uc.getId()))
            .setProjection(Projections.rowCount()).uniqueResult();
    assertEquals(0, num);

    num = (Integer) ses.createCriteria(UserClassKey.class).add(Restrictions.eq("redeemKey", key.getRedeemKey()))
            .setProjection(Projections.rowCount()).uniqueResult();
    assertEquals(0, num);

    num = (Integer) ses.createCriteria(UserClassKeyConstraint.class)
            .add(Restrictions.eq("classKey.id", key.getId())).setProjection(Projections.rowCount())
            .uniqueResult();
    assertEquals(0, num);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserDaoTester.java

License:Open Source License

@Test
public void testGetUser() {
    User user = new User("tuser", "test", "USER");
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from  ww  w. j av  a 2  s .c  om*/
    ses.save(user);
    ses.getTransaction().commit();
    ses.close();

    User ldUser = this.dao.findByName("test", "tuser");
    assertNotNull(ldUser);

    assertEquals("test", ldUser.getNamespace());
    assertEquals("tuser", ldUser.getName());
    assertEquals("USER", ldUser.getPersona());

    this.dao.delete(ldUser);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserDaoTester.java

License:Open Source License

@Test
public void testGetUserQName() {
    User user = new User("tuser", "test", "USER");
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//from ww  w  .ja va 2 s  .  com
    ses.save(user);
    ses.getTransaction().commit();
    ses.close();

    User ldUser = this.dao.findByQName("test:tuser");
    assertNotNull(ldUser);

    assertEquals("test", ldUser.getNamespace());
    assertEquals("tuser", ldUser.getName());
    assertEquals("USER", ldUser.getPersona());

    this.dao.delete(ldUser);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.dataaccess.dao.tests.UserDaoTester.java

License:Open Source License

@Test
public void testDeleteUser() {
    Session ses = DataAccessActivator.getNewSession();

    ses.beginTransaction();// ww  w  . j a v  a  2s  .  c  o m
    UserClass uc = new UserClass();
    uc.setName("test1");
    uc.setPriority((short) 10);
    uc.setActive(true);
    uc.setBookable(true);
    uc.setQueuable(true);
    uc.setUsersLockable(true);
    ses.save(uc);
    User us = new User("del1", "ns1", "ACADEMIC");
    ses.save(us);
    ses.getTransaction().commit();

    ses.beginTransaction();
    UserAssociation assoc = new UserAssociation();
    assoc.setUser(us);
    assoc.setUserClass(uc);
    UserAssociationId id = new UserAssociationId();
    id.setUserClassId(uc.getId());
    id.setUsersId(us.getId());
    assoc.setId(id);
    ses.save(assoc);
    ses.getTransaction().commit();

    this.dao.delete(us.getId());

    assertNull(this.dao.findByName("ns1", "test1"));

    ses.beginTransaction();
    ses.delete(uc);
    ses.getTransaction().commit();
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserAdminTester.java

License:Open Source License

@Test
public void testEditUserNewNameNSPersona() {
    String name = "tuser";
    String ns = "tuserns";

    User user = new User(name, ns, User.ADMIN);
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();//  ww  w  . j av a2 s . c om
    ses.save(user);
    ses.getTransaction().commit();

    assertTrue(this.admin.editUser(user.getId(), "newName", "newNS", User.USER));

    User edittedUser = this.dao.findByName("newName", "newNS");
    ses.refresh(user);
    assertEquals(user.getName(), edittedUser.getName());
    assertEquals(user.getNamespace(), edittedUser.getNamespace());
    assertEquals(user.getId(), edittedUser.getId());
    assertEquals(user.getPersona(), edittedUser.getPersona());

    this.dao.delete(edittedUser);
}

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserAdminTester.java

License:Open Source License

@Test
public void testEditUserNewPersona() {
    String name = "tuser";
    String ns = "tuserns";

    User user = new User(name, ns, User.ADMIN);
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from  ww  w . ja v  a 2 s.c o  m*/
    ses.save(user);
    ses.getTransaction().commit();

    assertTrue(this.admin.editUser(user.getId(), ns, name, User.USER));

    ses.refresh(user);
    assertEquals(name, user.getName());
    assertEquals(ns, user.getNamespace());
    assertEquals(User.USER, user.getPersona());

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

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserAdminTester.java

License:Open Source License

@Test
public void testEditUserNoNameNoNSPersona() {
    String name = "tuser";
    String ns = "tuserns";

    User user = new User(name, ns, User.ADMIN);
    Session ses = DataAccessActivator.getNewSession();
    ses.beginTransaction();/*from ww  w.  j a  v  a2  s.co m*/
    ses.save(user);
    ses.getTransaction().commit();

    assertTrue(this.admin.editUser(user.getId(), null, null, User.USER));

    ses.refresh(user);
    assertEquals(name, user.getName());
    assertEquals(ns, user.getNamespace());
    assertEquals(User.USER, user.getPersona());

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

From source file:au.edu.uts.eng.remotelabs.schedserver.permissions.impl.tests.UserAdminTester.java

License:Open Source License

@Test
public void testDeleteUser() {
    Session ses = DataAccessActivator.getNewSession();

    ses.beginTransaction();/*  w  w w  . j ava 2 s. co m*/
    UserClass uc = new UserClass();
    uc.setName("test1");
    uc.setPriority((short) 10);
    uc.setActive(true);
    uc.setQueuable(true);
    uc.setBookable(true);
    uc.setUsersLockable(true);
    uc.setKickable(true);
    ses.save(uc);
    User us = new User("del1", "ns1", "ACADEMIC");
    ses.save(us);
    ses.getTransaction().commit();

    ses.beginTransaction();
    UserAssociation assoc = new UserAssociation();
    assoc.setUser(us);
    assoc.setUserClass(uc);
    UserAssociationId id = new UserAssociationId();
    id.setUserClassId(uc.getId());
    id.setUsersId(us.getId());
    assoc.setId(id);
    ses.save(assoc);
    ses.getTransaction().commit();

    this.admin.deleteUser(us.getId());

    assertNull(this.dao.findByName("ns1", "test1"));

    ses.beginTransaction();
    ses.delete(uc);
    ses.getTransaction().commit();
}