コード例 #1
0
  public void deleteItem(Long itemId, String agent) {
    ItemData item = null;
    try {
      item = (ItemData) getHibernateTemplate().load(ItemData.class, itemId);
    } catch (DataAccessException e) {
      log.warn("unable to retrieve item " + itemId + " due to:" + e);
      return;
    }
    // get list of attachment in item
    AssessmentService service = new AssessmentService();
    List itemAttachmentList = service.getItemResourceIdList(item);
    service.deleteResources(itemAttachmentList);

    int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        SectionDataIfc section = item.getSection();
        // section might be null if you are deleting an item created inside a pool, that's not
        // linked to any assessment.
        if (section != null) {
          Set set = section.getItemSet();
          set.remove(item);
        }
        getHibernateTemplate().delete(item);
        retryCount = 0;
      } catch (Exception e) {
        log.warn("problem deleting item: " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }
  }
コード例 #2
0
 public void deleteSet(Set s) {
   int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
   while (retryCount > 0) {
     try {
       if (s != null) { // need to dissociate with item before deleting in Hibernate 3
         getHibernateTemplate().deleteAll(s);
         retryCount = 0;
       } else {
         retryCount = 0;
       }
     } catch (Exception e) {
       log.warn("problem deleteSet: " + e.getMessage());
       retryCount =
           PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
     }
   }
 }
コード例 #3
0
  /**
   * Get the Id for this SectionFacade.
   *
   * @return org.osid.shared.Id
   */
  org.osid.shared.Id getId() {
    try {
      this.data = (SectionDataIfc) section.getData();
    } catch (AssessmentException ex) {
      throw new DataFacadeException(ex.getMessage());
    }

    PublishedSectionFacadeQueriesAPI publishedSectionFacadeQueries =
        PersistenceService.getInstance().getPublishedSectionFacadeQueries();
    return publishedSectionFacadeQueries.getId(this.data.getSectionId());
  }
コード例 #4
0
 public ItemFacade saveItem(ItemFacade item) throws DataFacadeException {
   try {
     ItemDataIfc itemdata = (ItemDataIfc) item.getData();
     itemdata.setLastModifiedDate(new Date());
     itemdata.setLastModifiedBy(AgentFacade.getAgentString());
     int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
     while (retryCount > 0) {
       try {
         getHibernateTemplate().saveOrUpdate(itemdata);
         item.setItemId(itemdata.getItemId());
         retryCount = 0;
       } catch (Exception e) {
         log.warn("problem save or update itemdata: " + e.getMessage());
         retryCount =
             PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
       }
     }
     if ((item.getData() != null) && (item.getData().getSection() != null)) {
       AssessmentIfc assessment = item.getData().getSection().getAssessment();
       assessment.setLastModifiedBy(AgentFacade.getAgentString());
       assessment.setLastModifiedDate(new Date());
       retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
       while (retryCount > 0) {
         try {
           getHibernateTemplate().update(assessment);
           retryCount = 0;
         } catch (Exception e) {
           log.warn("problem updating asssessment: " + e.getMessage());
           retryCount =
               PersistenceService.getInstance()
                   .getPersistenceHelper()
                   .retryDeadlock(e, retryCount);
         }
       }
     }
     return item;
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
コード例 #5
0
  public void addItemMetaData(Long itemId, String label, String value) {
    ItemData item = (ItemData) getHibernateTemplate().load(ItemData.class, itemId);
    if (item != null) {
      printItem(item);

      ItemMetaData itemmetadata = new ItemMetaData(item, label, value);
      int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
      while (retryCount > 0) {
        try {
          getHibernateTemplate().save(itemmetadata);
          retryCount = 0;
        } catch (Exception e) {
          log.warn("problem saving itemmetadata: " + e.getMessage());
          retryCount =
              PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
        }
      }
      // item.addItemMetaData(label, value);
      // getHibernateTemplate().saveOrUpdate(item);
    }
  }
コード例 #6
0
  public void deleteItemMetaData(final Long itemId, final String label) {
    // delete metadata by label
    ItemData item = getHibernateTemplate().load(ItemData.class, itemId);

    final HibernateCallback<List<ItemMetaData>> hcb =
        session -> {
          Query q =
              session.createQuery(
                  "from ItemMetaData imd where imd.item.itemId = :id and imd.label = :label");
          q.setLong("id", itemId);
          q.setString("label", label);
          return q.list();
        };
    List<ItemMetaData> itemmetadatalist = getHibernateTemplate().execute(hcb);

    int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        if (item != null) { // need to dissociate with item before deleting in Hibernate 3
          Iterator iter = itemmetadatalist.iterator();
          while (iter.hasNext()) {
            ItemMetaDataIfc meta = (ItemMetaDataIfc) iter.next();
            meta.setItem(null);
          }

          Set set = item.getItemMetaDataSet();
          set.removeAll(itemmetadatalist);
          item.setItemMetaDataSet(set);
          getHibernateTemplate().deleteAll(itemmetadatalist);
          retryCount = 0;
        } else retryCount = 0;
      } catch (Exception e) {
        log.warn("problem delete itemmetadatalist: " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }
  }
コード例 #7
0
  public void remove(Long itemId) {
    ItemData item = (ItemData) getHibernateTemplate().load(ItemData.class, itemId);

    // get list of attachment in section
    AssessmentService service = new AssessmentService();
    List itemAttachmentList = service.getItemResourceIdList(item);
    service.deleteResources(itemAttachmentList);

    int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        getHibernateTemplate().delete(item);
        retryCount = 0;
      } catch (Exception e) {
        log.warn("problem deleting item : " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }
    if (item != null) {
      printItem(item);
    }
  }
コード例 #8
0
  public Long add() {
    ItemData item = new ItemData();
    item.setInstruction("Matching game");
    item.setTypeId(TypeFacade.MATCHING);
    item.setScore(Double.valueOf(10));
    item.setDiscount(Double.valueOf(0));
    item.setHasRationale(Boolean.FALSE);
    item.setStatus(Integer.valueOf(1));
    item.setCreatedBy("1");
    item.setCreatedDate(new Date());
    item.setLastModifiedBy("1");
    item.setLastModifiedDate(new Date());

    // prepare itemText
    item.setItemTextSet(prepareText(item));

    // prepare MetaData
    item.setItemMetaDataSet(prepareMetaData(item));
    item.addItemMetaData("ITEM_OBJECTIVE", "the objective is to ...");

    // prepare feedback
    item.setCorrectItemFeedback("well done!");
    item.setInCorrectItemFeedback("better luck next time!");

    int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        getHibernateTemplate().save(item);
        retryCount = 0;
      } catch (Exception e) {
        log.warn("problem saving item: " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }
    return item.getItemId();
  }
コード例 #9
0
  // is this used by ItemAddListener to save item? -daisyf
  public void deleteItemContent(Long itemId, String agent) {
    ItemData item = (ItemData) getHibernateTemplate().load(ItemData.class, itemId);

    int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        if (item != null) { // need to dissociate with item before deleting in Hibernate 3
          Set set = item.getItemTextSet();
          item.setItemTextSet(new HashSet());
          getHibernateTemplate().deleteAll(set);
          retryCount = 0;
        } else retryCount = 0;
      } catch (Exception e) {
        log.warn("problem deleteItemTextSet: " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }

    retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        if (item != null) { // need to dissociate with item before deleting in Hibernate 3
          Set set = item.getItemMetaDataSet();
          item.setItemMetaDataSet(new HashSet());
          getHibernateTemplate().deleteAll(set);
          retryCount = 0;
        } else retryCount = 0;
      } catch (Exception e) {
        log.warn("problem deleteItemMetaDataSet: " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }

    retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount();
    while (retryCount > 0) {
      try {
        if (item != null) { // need to dissociate with item before deleting in Hibernate 3
          Set set = item.getItemFeedbackSet();
          item.setItemFeedbackSet(new HashSet());
          getHibernateTemplate().deleteAll(set);
          retryCount = 0;
        } else retryCount = 0;
      } catch (Exception e) {
        log.warn("problem deleting ItemFeedbackSet: " + e.getMessage());
        retryCount =
            PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
      }
    }
  }
コード例 #10
0
 public void listType() {
   TypeFacadeQueriesAPI typeFacadeQueries =
       PersistenceService.getInstance().getTypeFacadeQueries();
   TypeFacade f = typeFacadeQueries.getTypeFacadeById(1L);
   log.debug("***facade: " + f.getAuthority());
 }