Package org.olat.core.commons.persistence

Examples of org.olat.core.commons.persistence.DB


  /**
   * TearDown is called after each test
   */
  public void tearDown() {
    try {
      DB db = DBFactory.getJunitInstance();
      db.closeSession();
    } catch (Exception e) {
      log.error("Exception in tearDown(): " + e);
    }
  }
View Full Code Here


  /**
   * TearDown is called after each test
   */
  public void tearDown() {
    try {
      DB db = DBFactory.getInstance();
      db.closeSession();
    } catch (Exception e) {
      log.error("Exception in tearDown(): " + e);
    }
  }
View Full Code Here

  /**
   * TearDown is called after each test
   */
  public void tearDown() {
    try {
      DB db = DBFactory.getInstance();
      db.closeSession();
    } catch (Exception e) {
      log.error("Exception in tearDown(): " + e);
    }
  }
View Full Code Here

  /**
   * TearDown is called after each test
   */
  public void tearDown() {
    try {
      DB db = DBFactory.getInstance();
      db.closeSession();
    } catch (Exception e) {
      log.error("Exception in tearDown(): " + e);
    }
  }
View Full Code Here

  /**
   * TearDown is called after each test
   */
  public void tearDown() {
    try {
      DB db = DBFactory.getInstance();
      db.closeSession();
    } catch (Exception e) {
      log.error("Exception in tearDown(): " + e);
    }
  }
View Full Code Here

      id1 = JunitTestHelper.createAndPersistIdentityAsUser("one");
      id2 = JunitTestHelper.createAndPersistIdentityAsUser("twoo");
      id3 = JunitTestHelper.createAndPersistIdentityAsUser("three");
      id4 = JunitTestHelper.createAndPersistIdentityAsUser("four");

      DB db = DBFactory.getInstance();
      OLATResourceManager rm = OLATResourceManager.getInstance();
      // create course and persist as OLATResourceImpl
      OLATResourceable resourceable = OresHelper.createOLATResourceableInstance("junitcourse", new Long(456));
      course1 = rm.createOLATResourceInstance(resourceable);
      db.saveObject(course1);

      DBFactory.getInstance().closeSession();
    } catch (Exception e) {
      log.error("Exception in setUp(): " + e);
      e.printStackTrace();
View Full Code Here

   * case if the key of a user is null
   * @throws Exception
   */
  public void testUpdateNewUser() throws Exception {
    UserManager um1 = UserManager.getInstance();
    DB db = DBFactory.getInstance();
    UserImpl u5 = new UserImpl("newuser", "newuser", "new@user.com");
    db.saveObject(u5);
    u5.setProperty(UserConstants.EMAIL, "updated@email.com");
    um1.updateUser(u5);
    um1.loadUserByKey(u5.getKey());
    assertTrue(u5.getProperty(UserConstants.EMAIL, null).equals("updated@email.com"));
  }
View Full Code Here

  /**
   * Test how to order by a certain user field
   */
  public void testOrderByFirstName() {
    DB db = DBFactory.getInstance();
    // join with user to sort by name
    StringBuilder slct = new StringBuilder();
    slct.append("select identity from ");
    slct.append("org.olat.core.id.Identity identity, ");
    slct.append("org.olat.user.UserImpl usr ");
    slct.append("where ");
    slct.append("identity.user = usr.key ");
    slct.append("order by usr.properties['firstName'] desc");
    List results = db.find(slct.toString());
    assertTrue(results.size() == 3);
    Identity found = (Identity) results.get(0);
    assertTrue(found.getKey().equals(i3.getKey()));
  }
View Full Code Here

  /**
   * Test creation of a repository entry.
   */
  public void testRawRepositoryEntryCreate() {
    try {
      DB db = DBFactory.getInstance();
      OLATResourceManager rm = OLATResourceManager.getInstance();
      // create course and persist as OLATResourceImpl
      OLATResourceable resourceable = new OLATResourceable() {
          public String getResourceableTypeName() {  return "Course";}
          public Long getResourceableId() {return new Long(456);}
      };
      OLATResource r =  rm.createOLATResourceInstance(resourceable);
      db.saveObject(r);
 
      // now make a repository entry for this course
      RepositoryEntry d = new RepositoryEntry();
      d.setOlatResource(r);
      d.setResourcename("Lernen mit OLAT");
      d.setInitialAuthor("Florian Gnägi");
      d.setDisplayname("JunitTest_RepositoryEntry");
  // TODO: chg: Remove for 5.3 MetaDataElement because it does not work with mySql 5.0
  //            and it is not used !   
  //             lastmodified of MetaDataElement is null and is not set by hibernate because
  //            it is a child object od RepositoryEntry !
  //            It could be solved with defintion of MetaDataElement.lastmodified IS NULL = false
  //    MetaDataElement v1, v2, v3;
  //    v1 = new MetaDataElement("version", "1.0 alpha");
  //    d.getMetaDataElements().add(v1);
  //    v2 = new MetaDataElement("duration", "2h");
  //    d.getMetaDataElements().add(v2);
  //    v3 = new MetaDataElement("path", "/UNIZH/ID/MELS/");
  //    d.getMetaDataElements().add(v3);
      db.saveObject(d);
    } catch(Exception ex) {
      fail("No Exception allowed. ex=" + ex.getMessage());
    }

  }
View Full Code Here

  }
 
  /**
   */
  public void testQueryReferencableResourcesLimitType() {
    DB db = DBFactory.getInstance();
    OLATResourceManager resm = OLATResourceManager.getInstance();
    RepositoryManager rm = RepositoryManager.getInstance();
    Manager securityManager = ManagerFactory.getManager();
   
    Identity id1 = JunitTestHelper.createAndPersistIdentityAsAuthor("id1");
    Identity id2 = JunitTestHelper.createAndPersistIdentityAsAuthor("id2");

    // generate 5000 repo entries
    int numbRes = 5000;
    long startCreate = System.currentTimeMillis();
    for (int i = 1; i < numbRes; i++) {
      // create course and persist as OLATResourceImpl
      final int ifin = i;
      OLATResourceable resourceable = new OLATResourceable() {
        public String getResourceableTypeName() {  return CourseModule.getCourseTypeName();}
        public Long getResourceableId() {return new Long(ifin);}
      };
      OLATResource r =  resm.createOLATResourceInstance(resourceable);
      db.saveObject(r);
     
      // now make a repository entry for this course
      RepositoryEntry re = rm.createRepositoryEntryInstance("Florian Gnägi", "Lernen mit OLAT " + i, "yo man description bla bla + i");
      re.setDisplayname("JunitTest_RepositoryEntry_" + i);
      re.setOlatResource(r);
      re.setAccess(RepositoryEntry.ACC_OWNERS_AUTHORS);       
      if ((i % 2 > 0)) {
        re.setCanReference(true);
      } else {
        re.setCanReference(false);
      }
      // create security group
      SecurityGroup ownerGroup = securityManager.createAndPersistSecurityGroup();
      // member of this group may modify member's membership
      securityManager.createAndPersistPolicy(ownerGroup, Constants.PERMISSION_ACCESS, ownerGroup);
      // members of this group are always authors also
      securityManager.createAndPersistPolicy(ownerGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_AUTHOR);
      if ((i % 2 > 0)) {
        securityManager.addIdentityToSecurityGroup(id1, ownerGroup);
      } else {
        securityManager.addIdentityToSecurityGroup(id2, ownerGroup);       
      }
      re.setOwnerGroup(ownerGroup);
      // save the repository entry
      rm.saveRepositoryEntry(re);
      // Create course admin policy for owner group of repository entry
      // -> All owners of repository entries are course admins
      securityManager.createAndPersistPolicy(re.getOwnerGroup(), Constants.PERMISSION_ADMIN, re.getOlatResource())
     
      // flush database and hibernate session cache after 10 records to improve performance
      // without this optimization, the first entries will be fast but then the adding new
      // entries will slow down due to the fact that hibernate needs to adjust the size of
      // the session cache permanently. flushing or transactions won't help since the problem
      // is in the session cache.
      if (i%2 == 0) {
        db.closeSession();
        db = DBFactory.getInstance();
      }
    }
    long endCreate = System.currentTimeMillis();
    Tracing.logDebug("created " + numbRes + " repo entries in " + (endCreate - startCreate) + "ms", RepositoryManagerTest.class);
View Full Code Here

TOP

Related Classes of org.olat.core.commons.persistence.DB

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.