@Transactional(rollbackFor = Throwable.class)
  @Override
  public void saveOrUpdateRecords(ArchivedInferredLocationRecord... records) {
    List<ArchivedInferredLocationRecord> list =
        new ArrayList<ArchivedInferredLocationRecord>(records.length);
    for (ArchivedInferredLocationRecord record : records) list.add(record);
    _template.saveOrUpdateAll(list);

    // LastKnownRecord
    LinkedHashMap<Integer, CcAndInferredLocationRecord> lastKnownRecords =
        new LinkedHashMap<Integer, CcAndInferredLocationRecord>(records.length);
    for (ArchivedInferredLocationRecord record : records) {
      CcLocationReportRecord cc = findRealtimeRecord(record);
      if (cc != null) {
        CcAndInferredLocationRecord lastKnown = new CcAndInferredLocationRecord(record, cc);
        if (validationService.validateLastKnownRecord(lastKnown)) {
          lastKnownRecords.put(lastKnown.getVehicleId(), lastKnown);
        } else {
          discardRecord(lastKnown);
        }
      }
    }
    _template.saveOrUpdateAll(lastKnownRecords.values());
    _template.flush();
    _template.clear();
  }
Пример #2
0
 @Override
 @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
 public boolean delete(Guardian guardian) {
   hibernateTemplate.delete(guardian);
   hibernateTemplate.flush();
   return true;
 }
  private ContentKey storeSimpleContent(String title) {

    ContentEntity content = factory.createContent("MyCategory", "en", "testuser", "0", new Date());
    ContentVersionEntity version = factory.createContentVersion("0", "testuser");

    ContentTypeConfig contentTypeConfig =
        ContentTypeConfigParser.parse(ContentHandlerName.CUSTOM, createSimpleContentTypeConfig());

    CustomContentData contentData = new CustomContentData(contentTypeConfig);

    TextDataEntryConfig titleConfig =
        new TextDataEntryConfig("myTitle", true, title, "contentdata/mytitle");
    contentData.add(new TextDataEntry(titleConfig, "relatedconfig"));

    version.setContentData(contentData);

    UserEntity runningUser = fixture.findUserByName("testuser");

    CreateContentCommand createContentCommand = new CreateContentCommand();
    createContentCommand.setCreator(runningUser);

    createContentCommand.populateCommandWithContentValues(content);
    createContentCommand.populateCommandWithContentVersionValues(version);

    createContentCommand.setBinaryDatas(new ArrayList<BinaryDataAndBinary>());
    createContentCommand.setUseCommandsBinaryDataToAdd(true);

    ContentKey contentKey = contentService.createContent(createContentCommand);

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    return contentKey;
  }
Пример #4
0
  public final void createSample(final SamplePE sample) throws DataAccessException {
    assert sample != null : "Unspecified sample";

    final HibernateTemplate hibernateTemplate = getHibernateTemplate();

    internalCreateSample(
        sample, hibernateTemplate, new ClassValidator<SamplePE>(SamplePE.class), true);
    hibernateTemplate.flush();
  }
Пример #5
0
 /* (non-Javadoc)
  * @see cn.believeus.dao.IBaseDao#delete(java.lang.Class, java.lang.String, java.lang.Object)
  */
 @Override
 public void delete(Class<?> clazz, String property, final Object value) {
   HibernateTemplate ht = getHibernateTemplate();
   List<?> objectList = this.findObjectList(clazz, property, value);
   for (Object entity : objectList) {
     ht.delete(entity);
     ht.flush();
   }
 }
 @Override
 @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
 public void handleException(String content, Throwable error, Date timeReceived) {
   InvalidLocationRecord ilr = new InvalidLocationRecord(content, error, timeReceived);
   _template.saveOrUpdate(ilr);
   // clear from level one cache
   _template.flush();
   _template.evict(ilr);
 }
Пример #7
0
  public final void updateSample(final SamplePE sample) throws DataAccessException {
    assert sample != null : "Unspecified sample";
    validatePE(sample);

    final HibernateTemplate hibernateTemplate = getHibernateTemplate();

    hibernateTemplate.flush();
    if (operationLog.isInfoEnabled()) {
      operationLog.info("UPDATE: sample '" + sample + "'.");
    }
  }
Пример #8
0
 /* (non-Javadoc)
  * @see cn.cas.iue.dao.ConsumableDAO#updateConsumable(cn.cas.iue.bean.Consumable)
  */
 @Override
 public void updateConsumable(Consumable consumable) throws Exception {
   // TODO Auto-generated method stub
   try {
     hibernateTemplate.saveOrUpdate(consumable);
     hibernateTemplate.flush();
   } catch (RuntimeException re) {
     // TODO: handle exception
     throw re;
   } finally {
     hibernateTemplate.clear();
   }
 }
  @Transactional(rollbackFor = Throwable.class)
  @Override
  public void saveOrUpdateRecord(ArchivedInferredLocationRecord record) {
    _template.saveOrUpdate(record);

    CcLocationReportRecord cc = findRealtimeRecord(record);
    if (cc != null) {
      CcAndInferredLocationRecord lastKnown = new CcAndInferredLocationRecord(record, cc);
      _template.saveOrUpdate(lastKnown);
    }

    _template.flush();
    _template.clear();
  }
Пример #10
0
  public final void createSamples(final List<SamplePE> samples) throws DataAccessException {
    assert samples != null && samples.size() > 0 : "Unspecified or empty samples.";

    final HibernateTemplate hibernateTemplate = getHibernateTemplate();

    final ClassValidator<SamplePE> classValidator = new ClassValidator<SamplePE>(SamplePE.class);
    for (final SamplePE samplePE : samples) {
      internalCreateSample(samplePE, hibernateTemplate, classValidator, false);
    }
    if (operationLog.isInfoEnabled()) {
      operationLog.info(String.format("ADD: %d samples.", samples.size()));
    }
    hibernateTemplate.flush();
  }
Пример #11
0
 // 出入库更新
 public void updateQuantity(Integer quantity, Integer consumableId) throws Exception {
   // TODO Auto-generated method stub
   try {
     hibernateTemplate.bulkUpdate(
         "update Consumable set quantity=? where consumableId=?",
         new Object[] {quantity, consumableId});
     hibernateTemplate.flush();
   } catch (RuntimeException re) {
     // TODO: handle exception
     throw re;
   } finally {
     hibernateTemplate.clear();
   }
 }
 @RequestMapping(value = "/delete")
 @ResponseBody
 @Transactional(propagation = Propagation.REQUIRED)
 public String delete(@RequestBody HashMap<String, List> map) {
   List<LinkedHashMap> resourceList = (List<LinkedHashMap>) map.get("resource_rows");
   for (int i = 0; i < resourceList.size(); i++) {
     String resource_id = (String) resourceList.get(i).get("resource_id");
     hibernateTemplate
         .getSessionFactory()
         .getCurrentSession()
         .createQuery("delete from SystemResourcesVO where resource_id = '" + resource_id + "'")
         .executeUpdate();
     hibernateTemplate.flush();
   }
   return "00";
 }
Пример #13
0
 @Transactional
 @Override
 public void update(LookFor lookFor) {
   template.saveOrUpdate(lookFor);
   template.flush();
 }
Пример #14
0
 @Transactional
 @Override
 public void delete(LookFor lookFor) {
   template.delete(lookFor);
   template.flush();
 }
Пример #15
0
 /**
  * Create a HibernateTemplate from the SessionFactory and call flush() and clear() on it. Designed
  * to be used after "save" methods in tests: http://issues.appfuse.org/browse/APF-178.
  *
  * @throws org.springframework.beans.BeansException when can't find 'sessionFactory' bean
  */
 protected void flush() throws BeansException {
   HibernateTemplate hibernateTemplate = new HibernateTemplate(sessionFactory);
   hibernateTemplate.flush();
   hibernateTemplate.clear();
 }
Пример #16
0
 @Transactional
 @Override
 public void add(LookFor lookFor) {
   template.save(lookFor);
   template.flush();
 }
Пример #17
0
 public void merge(Object object) {
   HibernateTemplate ht = super.getHibernateTemplate();
   ht.merge(object);
   ht.flush();
 }
Пример #18
0
 public void save(T t) {
   hibernateTemplate.save(t);
   hibernateTemplate.flush();
 }
Пример #19
0
  // 保存项目工兼职教师人员
  public void saveWageEmpPerson(UserBO user, String wage, String other) throws SysException {

    boolean isnew = user.getUserID() == null ? true : false;
    if (isnew) {
      String sql = "select personnum_sequence.nextval from dual";
      int code = this.jdbcTemplate.queryForInt(sql);
      user.setPersonSeq(code + "");
      user.setComeDate(CommonFuns.getSysDate("yyyy-MM-dd"));
    }
    PersonBO pEdit = null;
    if (!isnew) {
      pEdit = SysCacheTool.findPersonById(user.getUserID());
    }
    OrgBO org = SysCacheTool.findOrgById(user.getDeptId());
    OrgBO superOrg = SysCacheTool.findOrgById(org.getSuperId());
    user.setDeptSort(org.getTreeId());
    user.setMainDeptSort(superOrg.getTreeId());
    user.setOrgId(superOrg.getOrgId());
    if (user.isHasCash()) {
      user.setHasCashStr("1");
    } else {
      user.setHasCashStr("0");
    }
    HibernateTemplate temp = (HibernateTemplate) SysContext.getBean("hibernateTemplate");
    temp.saveOrUpdate(user);
    temp.flush();

    // 添加
    if (isnew) {
      String sql =
          "insert into sys_user_info s (s.person_id,s.login_name,login_pwd,s.is_use) values ('"
              + user.getUserID()
              + "','"
              + user.getName()
              + "','98f6bcd4621d373cade4e832627b4f6',0)";
      this.jdbcTemplate.execute(sql);
      String wageOrgId = superOrg.getOrgId();
      sql =
          "insert into a795 (id,a795701,a795705,a795708,a795710,a795718,a795720,a795725) values ('"
              + user.getUserID()
              + "','"
              + user.getOrgId()
              + "','"
              + user.getOrgId()
              + "','"
              + user.getOrgId()
              + "','"
              + user.getOrgId()
              + "','"
              + user.getOrgId()
              + "','"
              + user.getOrgId()
              + "','"
              + user.getOrgId()
              + "')";
      this.jdbcTemplate.execute(sql);
      sql =
          "insert into a239 (id,a239200,a239201) values ('"
              + user.getUserID()
              + "','"
              + wage
              + "','"
              + other
              + "')";
      this.jdbcTemplate.execute(sql);
    } else {
      String sql =
          "update a239 set a239200='"
              + wage
              + "',a239201='"
              + other
              + "' where id='"
              + user.getUserID()
              + "'";
      this.jdbcTemplate.execute(sql);
    }
  }
Пример #20
0
 public void saveOrUpdata(Object object) {
   HibernateTemplate ht = getHibernateTemplate();
   ht.saveOrUpdate(object);
   ht.flush();
 }
  @Test
  public void testUpdateCurrentVersion() {
    ContentKey relatedContentKey1 = storeSimpleContent("rel1");
    ContentKey relatedContentKey2 = storeSimpleContent("rel2");
    ContentKey relatedContentKey3 = storeSimpleContent("rel3");
    ContentKey relatedContentKey4 = storeSimpleContent("rel4");
    ContentKey relatedContentKey5 = storeSimpleContent("rel5");

    ContentEntity content = factory.createContent("MyCategory", "en", "testuser", "0", new Date());
    ContentVersionEntity version = factory.createContentVersion("0", "testuser");

    ContentTypeConfig contentTypeConfig =
        ContentTypeConfigParser.parse(ContentHandlerName.CUSTOM, configEl);
    CustomContentData contentData = new CustomContentData(contentTypeConfig);
    TextDataEntryConfig titleConfig =
        new TextDataEntryConfig("myTitle", true, "Tittel", "contentdata/mytitle");
    contentData.add(new TextDataEntry(titleConfig, "test title"));

    RelatedContentDataEntryConfig multipleRelatedContentsConfig =
        (RelatedContentDataEntryConfig)
            contentTypeConfig.getInputConfig("myMultipleRelatedContent");

    contentData.add(
        new RelatedContentsDataEntry(multipleRelatedContentsConfig)
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey1))
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey2)));

    RelatedContentDataEntryConfig soleRelatedConfig =
        (RelatedContentDataEntryConfig) contentTypeConfig.getInputConfig("mySoleRelatedContent");

    contentData.add(new RelatedContentDataEntry(soleRelatedConfig, relatedContentKey3));

    version.setContentData(contentData);

    UserEntity runningUser = fixture.findUserByName("testuser");

    CreateContentCommand createContentCommand = new CreateContentCommand();
    createContentCommand.setCreator(runningUser);

    createContentCommand.populateCommandWithContentValues(content);
    createContentCommand.populateCommandWithContentVersionValues(version);

    createContentCommand.setBinaryDatas(new ArrayList<BinaryDataAndBinary>());
    createContentCommand.setUseCommandsBinaryDataToAdd(true);

    ContentKey contentKey = contentService.createContent(createContentCommand);

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    ContentEntity persistedContent = contentDao.findByKey(contentKey);
    assertNotNull(persistedContent);

    ContentVersionEntity persistedVersion = persistedContent.getMainVersion();
    assertNotNull(persistedVersion);

    assertEquals(3, persistedVersion.getRelatedChildren(true).size());

    ContentEntity changedContent =
        factory.createContent("MyCategory", "en", "testuser", "0", new Date());
    changedContent.setKey(contentKey);
    ContentVersionEntity changedVersion = factory.createContentVersion("0", "testuser");
    changedVersion.setKey(persistedVersion.getKey());

    CustomContentData changedCD = new CustomContentData(contentTypeConfig);

    TextDataEntryConfig changedTitleConfig =
        new TextDataEntryConfig("myTitle", true, "Tittel", "contentdata/mytitle");
    changedCD.add(new TextDataEntry(changedTitleConfig, "changed title"));

    changedCD.add(
        new RelatedContentsDataEntry(multipleRelatedContentsConfig)
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey3))
            .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey5)));

    changedCD.add(new RelatedContentDataEntry(soleRelatedConfig, relatedContentKey4));

    changedVersion.setContentData(changedCD);

    UpdateContentCommand updateContentCommand =
        UpdateContentCommand.updateExistingVersion2(persistedVersion.getKey());
    updateContentCommand.setModifier(runningUser);
    updateContentCommand.setUpdateAsMainVersion(false);

    updateContentCommand.populateContentValuesFromContent(persistedContent);
    updateContentCommand.populateContentVersionValuesFromContentVersion(changedVersion);

    contentService.updateContent(updateContentCommand);

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    ContentEntity contentAfterUpdate = contentDao.findByKey(contentKey);
    ContentVersionEntity versionAfterUpdate =
        contentVersionDao.findByKey(persistedVersion.getKey());

    Document contentDataXmlAfterUpdate = versionAfterUpdate.getContentDataAsJDomDocument();

    AssertTool.assertXPathEquals(
        "/contentdata/mysolerelatedcontent/@key",
        contentDataXmlAfterUpdate,
        relatedContentKey4.toString());
    AssertTool.assertXPathEquals(
        "/contentdata/myrelatedcontents/content[1]/@key",
        contentDataXmlAfterUpdate,
        relatedContentKey3.toString());
    AssertTool.assertXPathEquals(
        "/contentdata/myrelatedcontents/content[2]/@key",
        contentDataXmlAfterUpdate,
        relatedContentKey5.toString());

    assertEquals(3, versionAfterUpdate.getRelatedChildren(true).size());
  }
  @RequestMapping(value = "/save")
  @ResponseBody
  @Transactional(propagation = Propagation.REQUIRED)
  public String save(ResourceMgrBean req) {

    // req.setRetStatus("00");
    BeanDebugger.printBeanInfo(req);
    SystemResourcesVO vo = new SystemResourcesVO();
    if (req.getResource_type().equals("00")) { // url 页面路径
      if (req.getIsFunc().equals("00")) { // 功能目录
        vo.setResource_id(UUIDGener.getUUID());
        vo.setResource_name(req.getBrandName() + "_目录");
        vo.setResource_type("url");
        vo.setResource_content("#");
        vo.setResouce_describe(req.getResouce_describe());
        vo.setEnabled(req.getEnabled());
        vo.setParent_menu_id("");
        vo.setLeaf_type("2");
        vo.setSort_str(req.getSort_str());
        vo.setSelfId(req.getBrandName() + "_id");
        vo.setParentId("#mainFuncId");
        vo.setIsDouble(req.getIsDouble());
        vo.setBgColor(req.getBgColor());
        vo.setTileType("icon");
        vo.setImgSrc(req.getImgSrc());
        vo.setBrandName(req.getBrandName());
        vo.setBrandCount("");
        vo.setBadgeColor("");
        vo.setTileHtml("");
        vo.setMenuIcon("");
        vo.setMenuUrl("");
        hibernateTemplate.save(vo);
        hibernateTemplate.flush();
      }
      if (req.getIsFunc().equals("01")) { // 功能菜单
        vo.setResource_id(UUIDGener.getUUID());
        vo.setResource_name(req.getBrandName() + "_菜单");
        vo.setResource_type("url");
        vo.setResource_content(req.getResource_content());
        vo.setResouce_describe(req.getResouce_describe());
        vo.setEnabled(req.getEnabled());
        vo.setParent_menu_id(req.getParent_menu_id());
        vo.setLeaf_type("3");
        vo.setSort_str(req.getSort_str());
        vo.setSelfId("");
        vo.setParentId("#subFuncId");
        vo.setIsDouble(req.getIsDouble());
        vo.setBgColor(req.getBgColor());
        vo.setTileType("icon");
        vo.setImgSrc(req.getImgSrc());
        vo.setBrandName(req.getBrandName());
        vo.setBrandCount("");
        vo.setBadgeColor("");
        vo.setTileHtml("");
        vo.setMenuIcon(req.getImgSrc());
        vo.setMenuUrl("url:" + req.getResource_content());
        hibernateTemplate.save(vo);
        hibernateTemplate.flush();
      }
    }
    if (req.getResource_type().equals("01")) { // .do功能路径
      vo.setResource_id(UUIDGener.getUUID());
      vo.setResource_name("");
      vo.setResource_type("url");
      vo.setResource_content(req.getResource_content());
      vo.setResouce_describe(req.getResouce_describe());
      vo.setEnabled(req.getEnabled());
      vo.setParent_menu_id("");
      vo.setLeaf_type("1");
      vo.setSort_str("");
      vo.setSelfId("");
      vo.setParentId("");
      vo.setIsDouble("");
      vo.setBgColor("");
      vo.setTileType("");
      vo.setImgSrc("");
      vo.setBrandName("");
      vo.setBrandCount("");
      vo.setBadgeColor("");
      vo.setTileHtml("");
      vo.setMenuIcon("");
      vo.setMenuUrl("");
      hibernateTemplate.save(vo);
      hibernateTemplate.flush();
    }
    return "00";
  }
  @Before
  public void before() throws IOException, JDOMException {

    factory = fixture.getFactory();

    fixture.initSystemData();

    StringBuffer configXml = new StringBuffer();
    configXml.append("<config name=\"MyContentType\" version=\"1.0\">");
    configXml.append("     <form>");

    configXml.append("         <title name=\"myTitle\"/>");

    configXml.append("         <block name=\"General\">");

    configXml.append("             <input name=\"myTitle\" required=\"true\" type=\"text\">");
    configXml.append("                 <display>My title</display>");
    configXml.append("                 <xpath>contentdata/mytitle</xpath>");
    configXml.append("             </input>");

    configXml.append("         </block>");

    configXml.append("         <block name=\"Related content\">");

    configXml.append(
        "             <input name=\"myMultipleRelatedContent\" type=\"relatedcontent\" multiple=\"true\">");
    configXml.append("                 <display>My related content</display>");
    configXml.append("                 <xpath>contentdata/myrelatedcontents</xpath>");
    configXml.append("             </input>");

    configXml.append(
        "             <input name=\"mySoleRelatedContent\" type=\"relatedcontent\" multiple=\"false\">");
    configXml.append("                 <display>My sole related content</display>");
    configXml.append("                 <xpath>contentdata/mysolerelatedcontent</xpath>");
    configXml.append("                 <contenttype name=\"MyContentType\"/>");
    configXml.append("             </input>");

    configXml.append("         </block>");
    configXml.append("     </form>");
    configXml.append("</config>");
    configEl = JDOMUtil.parseDocument(configXml.toString()).getRootElement();
    config = XMLDocumentFactory.create(configXml.toString()).getAsJDOMDocument();

    fixture.createAndStoreNormalUserWithUserGroup("testuser", "testuser fullname", "testuserstore");
    hibernateTemplate.save(
        factory.createContentHandler(
            "Custom content", ContentHandlerName.CUSTOM.getHandlerClassShortName()));
    hibernateTemplate.save(
        factory.createContentType(
            "MyContentType", ContentHandlerName.CUSTOM.getHandlerClassShortName(), config));
    hibernateTemplate.save(factory.createUnit("MyUnit"));
    hibernateTemplate.save(
        factory.createCategory(
            "MyCategory", null, "MyContentType", "MyUnit", "testuser", "testuser"));
    hibernateTemplate.save(
        factory.createCategoryAccess(
            "MyCategory", fixture.findUserByName("testuser"), "read, create, approve"));

    hibernateTemplate.flush();
    hibernateTemplate.clear();

    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("127.0.0.1");
    ServletRequestAccessor.setRequest(request);
  }