Package org.olat.core.commons.persistence

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


 
  /**
   * @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#deleteAllComments()
   */
  public int deleteAllComments() {
    DB db = DBFactory.getInstance();
    String query;
    Object[] values;
    Type[] types;
    // special query when sub path is null
    if (getOLATResourceableSubPath() == null) {
      query = "from UserCommentImpl where resName=? AND resId=? AND resSubPath is NULL";
      values = new Object[] { getOLATResourceable().getResourceableTypeName(),  getOLATResourceable().getResourceableId() };
      types = new Type[] {Hibernate.STRING, Hibernate.LONG};
    } else {
      query = "from UserCommentImpl where resName=? AND resId=? AND resSubPath=?";
      values = new Object[] { getOLATResourceable().getResourceableTypeName(),  getOLATResourceable().getResourceableId(), getOLATResourceableSubPath() };
      types = new Type[] {Hibernate.STRING, Hibernate.LONG, Hibernate.STRING};
    }
    return db.delete(query, values, types);
  }
View Full Code Here


  public int deleteAllCommentsIgnoringSubPath() {
    // Don't limit to subpath. Ignore if null or not, just delete on the resource
    String query = "from UserCommentImpl where resName=? AND resId=?";
    Object[] values = new Object[] { getOLATResourceable().getResourceableTypeName(),  getOLATResourceable().getResourceableId() };
    Type[] types = new Type[] {Hibernate.STRING, Hibernate.LONG};
    DB db = DBFactory.getInstance();
    return db.delete(query, values, types);   
  }
View Full Code Here

    query.append(" and p.identity is not null");
    query.append(" and ( p.name = '").append(AssessmentManager.SCORE);
    query.append("' or p.name = '").append(AssessmentManager.PASSED);
    query.append("' )");

    DB db = DBFactory.getInstance();
    DBQuery dbq = db.createQuery(query.toString());
    ICourse course = CourseFactory.loadCourse(ores);
    dbq.setLong("resid", course.getResourceableId().longValue());
    dbq.setString("resname", course.getResourceableTypeName());

    List res = dbq.list();
View Full Code Here

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

  public List getResultSets(Long olatResource, String olatResourceDetail, Long repositoryRef, Identity identity) {
    Long olatRes = olatResource;
    String olatResDet = olatResourceDetail;
    Long repRef = repositoryRef;

    DB db = DBFactory.getInstance();

    StringBuilder slct = new StringBuilder();
    slct.append("select rset from ");
    slct.append("org.olat.ims.qti.QTIResultSet rset ");
    slct.append("where ");
    slct.append("rset.olatResource=? ");
    slct.append("and rset.olatResourceDetail=? ");
    slct.append("and rset.repositoryRef=? ");
    if (identity != null) {
      slct.append("and rset.identity.key=? ");
      return db.find(slct.toString(), new Object[] { olatRes, olatResDet, repRef, identity.getKey() }, new Type[] { Hibernate.LONG, Hibernate.STRING,
          Hibernate.LONG, Hibernate.LONG });
    } else {
      return db.find(slct.toString(), new Object[] { olatRes, olatResDet, repRef }, new Type[] { Hibernate.LONG, Hibernate.STRING,
          Hibernate.LONG });
    }
  }
View Full Code Here

  public List selectResults(Long olatResource, String olatResourceDetail, Long repositoryRef, int type) {
    Long olatRes = olatResource;
    String olatResDet = olatResourceDetail;
    Long repRef = repositoryRef;

    DB db = DBFactory.getInstance();
    // join with user to sort by name
    StringBuilder slct = new StringBuilder();
    slct.append("select res from ");
    slct.append("org.olat.ims.qti.QTIResultSet rset, ");
    slct.append("org.olat.ims.qti.QTIResult res, ");
    slct.append("org.olat.core.id.Identity identity, ");
    slct.append("org.olat.user.UserImpl usr ");
    slct.append("where ");
    slct.append("rset.key = res.resultSet ");
    slct.append("and rset.identity = identity.key ");
    slct.append("and identity.user = usr.key ");
    slct.append("and rset.olatResource=? ");
    slct.append("and rset.olatResourceDetail=? ");
    slct.append("and rset.repositoryRef=? ");
     // 1 -> iqtest, 2 -> iqself
    if(type == 1 || type == 2)
        slct.append("order by usr.properties['").append(UserConstants.LASTNAME).append("'] , rset.assessmentID, res.itemIdent");
      //3 -> iqsurv: the alphabetical assortment above could destroy the anonymization
      // if names and quantity of the persons is well-known
    else
        slct.append("order by rset.creationDate, rset.assessmentID, res.itemIdent");

    List results = null;
    results = db.find(slct.toString(), new Object[] { olatRes, olatResDet, repRef }, new Type[] { Hibernate.LONG, Hibernate.STRING,
        Hibernate.LONG });
   
    return results;
  }
View Full Code Here

   * @param olatResDet
   * @param repRef
   * @return deleted ResultSets
   */
  public int deleteAllResults(Long olatRes, String olatResDet, Long repRef) {
    DB db = DBFactory.getInstance();

    StringBuilder slct = new StringBuilder();
    slct.append("select rset from ");
    slct.append("org.olat.ims.qti.QTIResultSet rset ");
    slct.append("where ");
    slct.append("rset.olatResource=? ");
    slct.append("and rset.olatResourceDetail=? ");
    slct.append("and rset.repositoryRef=? ");

    List results = null;
    results = db.find(slct.toString(), new Object[] { olatRes, olatResDet, repRef }, new Type[] { Hibernate.LONG, Hibernate.STRING,
        Hibernate.LONG });

    String delRes = "from res in class org.olat.ims.qti.QTIResult where res.resultSet.key = ?";
    String delRset = "from rset in class org.olat.ims.qti.QTIResultSet where rset.key = ?";

    int deletedRset = 0;

    for (Iterator iter = results.iterator(); iter.hasNext();) {
      QTIResultSet rSet = (QTIResultSet) iter.next();
      Long rSetKey = rSet.getKey();
      db.delete(delRes, rSetKey, Hibernate.LONG);
      db.delete(delRset, rSetKey, Hibernate.LONG);
      deletedRset++;
    }
    return deletedRset;
  }
View Full Code Here

    pm.saveProperty(p2);
    getWindowControl().setInfo("Properties<br />TestTransactionalKey-1=doTestNonTransactional_1,<br />TestTransactionalKey-2=doTestNonTransactional_2 created");
  }

  private void doTestTransactional() {
    DB db = DBFactory.getInstance();
    PropertyManager pm = PropertyManager.getInstance();
    Property p1 = pm.createPropertyInstance(null, null, null, propertyCategory, propertyKey1, null, null, "doTestTransactional_1", null);
    pm.saveProperty(p1);
    Property p2 = pm.createPropertyInstance(null, null, null, propertyCategory, propertyKey2, null, null, "doTestTransactional_2", null);
    pm.saveProperty(p2);
View Full Code Here

    pm.saveProperty(p2);
    getWindowControl().setInfo("Properties<br />TestTransactionalKey-1=doTestTransactional_1,<br />TestTransactionalKey-2=doTestTransactional_2 created");
  }

  private void doTestMixTransactional() {
    DB db = DBFactory.getInstance();
    PropertyManager pm = PropertyManager.getInstance();
    Property p1 = pm.createPropertyInstance(null, null, null, propertyCategory, propertyKey1, null, null, "doTestMixTransactional_1", null);
    pm.saveProperty(p1);
    Property p2 = pm.createPropertyInstance(null, null, null, propertyCategory, propertyKey2, null, null, "doTestMixTransactional_2", null);
    pm.saveProperty(p2);
View Full Code Here

    getWindowControl().setError("Should generate error for rollback!");
    Tracing.logError("Should generate error and not reach this code",getClass());
  }

  private void doTestTransactionalError() {
    DB db = DBFactory.getInstance();
    PropertyManager pm = PropertyManager.getInstance();
    Property p1 = pm.createPropertyInstance(null, null, null, propertyCategory, propertyKey1, null, null, "doTestTransactionalError_1", null);
    pm.saveProperty(p1);
    // name is null => generated DB error => rollback
    Property p2 = pm.createPropertyInstance(null, null, null, propertyCategory, null, null, null, "doTestTransactionalError_2", null);
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.