コード例 #1
0
  private void addEntityCheckCache(SessionFactoryImplementor sessionFactory) throws Exception {
    Item item = new Item("chris", "Chris's Item");
    beginTx();
    try {
      Session s = sessionFactory.openSession();
      s.getTransaction().begin();
      s.persist(item);
      s.getTransaction().commit();
      s.close();
    } catch (Exception e) {
      setRollbackOnlyTx(e);
    } finally {
      commitOrRollbackTx();
    }

    beginTx();
    try {
      Session s = sessionFactory.openSession();
      Item found = (Item) s.load(Item.class, item.getId());
      Statistics stats = sessionFactory.getStatistics();
      log.info(stats.toString());
      assertEquals(item.getDescription(), found.getDescription());
      assertEquals(0, stats.getSecondLevelCacheMissCount());
      assertEquals(1, stats.getSecondLevelCacheHitCount());
      s.delete(found);
      s.close();
    } catch (Exception e) {
      setRollbackOnlyTx(e);
    } finally {
      commitOrRollbackTx();
    }
  }
コード例 #2
0
  @Get("xml")
  public Representation toXml() {
    try {
      DomRepresentation representation = new DomRepresentation(MediaType.TEXT_XML);
      // Generate a DOM document representing the item.
      Document d = representation.getDocument();

      Element eltItem = d.createElement("item");
      d.appendChild(eltItem);
      Element eltName = d.createElement("name");
      eltName.appendChild(d.createTextNode(item.getName()));
      eltItem.appendChild(eltName);

      Element eltDescription = d.createElement("description");
      eltDescription.appendChild(d.createTextNode(item.getDescription()));
      eltItem.appendChild(eltDescription);

      d.normalizeDocument();

      // Returns the XML representation of this document.
      return representation;
    } catch (IOException e) {
      e.printStackTrace();
    }

    return null;
  }
コード例 #3
0
ファイル: MarketService.java プロジェクト: iitc/steam-bot
 /**
  * Retrieves the recent price information for the specified item in the desired currency format.
  *
  * @param item the item to retrieve price information for
  * @param currency the currency to return the prices in
  * @return the recent price information for the specified item
  */
 public PriceHistory lookup(Item item, Currency currency) {
   if (item == null) return null;
   long gameId = item.getGameId();
   if (gameId == -1) return null;
   ItemDescription description = item.getDescription();
   if (description == null) return null;
   if (!description.isTradable()) return null;
   String marketHashName = description.getMarketHashName();
   if (marketHashName == null) return null;
   PriceHistory history;
   try {
     history =
         steam
             .getDataParser()
             .build(
                 PriceHistory.class,
                 steam
                     .getCommunicator()
                     .retrieve(
                         String.format(
                             INVENTORY_PATTERN,
                             (currency == null ? Currency.USD : currency).getToken(),
                             gameId,
                             URLEncoder.encode(marketHashName, "UTF-8")),
                         RequestMethod.GET));
     if (history == null) return null;
     history.setCurrency(currency);
     return history;
   } catch (UnsupportedEncodingException e) {
     return null;
   }
 }
コード例 #4
0
ファイル: Player.java プロジェクト: silentdragoon/Zuul
 /** Returns a string that has the description of the examined item. */
 public String getExamineString(String name) {
   String returnString = "You examine the " + name + ".\n";
   Item temp = inventory.get(name);
   if (temp != null) {
     returnString += "It's " + temp.getDescription() + ".";
     return returnString;
   }
   return "You can only examine items in your inventory.";
 }
コード例 #5
0
  private void itemSelected(java.awt.event.MouseEvent evt) { // GEN-FIRST:event_itemSelected
    int currentSelectedItemIndex = itemList.getSelectedIndex();

    if (currentSelectedItemIndex >= 0) {
      Item tmp = listModel.getElementAt(currentSelectedItemIndex);
      itemTitleTextField.setText(tmp.getTitle());
      itemDescriptionTextArea.setText(tmp.getDescription());
      createItemButton.setText("Update");
    }
  } // GEN-LAST:event_itemSelected
コード例 #6
0
ファイル: RssReader.java プロジェクト: giacomolm/rssconnector
  public ArrayList<Feedback> readFeedbacks(long idPost) {
    RssParser parser = null;
    Rss rss = null;
    // System.out.println("right? "+post);
    try {
      parser = RssParserFactory.createDefault();
      rss = parser.parse(new URL(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost));
    } catch (RssParserException e) {
      System.out.println(boardAddress + "feedbacks?action=READ&FeedbackName=" + idPost);
      System.out.println("RssParserException");
      return null;
    } catch (MalformedURLException e) {
      System.out.println("MalformedURLException");
      return null;
    } catch (IOException e) {
      System.out.println("IOException");
      return null;
    }

    Channel c = rss.getChannel();
    if (c.getItems() == null) {
      System.out.println("Non ci sono Feedback");
      return new ArrayList<Feedback>();
    }
    ArrayList<Item> items = new ArrayList<Item>(c.getItems());
    Iterator<Item> iter = items.iterator();
    ArrayList<Feedback> lista = new ArrayList<Feedback>();
    while (iter.hasNext()) {
      Item x = iter.next();
      String description = "";
      String feed = "";
      Title titolo = Title.AGREE;
      try {
        description = x.getDescription().getText();
      } catch (NullPointerException e) {
      }
      try {
        feed = x.getTitle().getText();
      } catch (NullPointerException e) {
      }
      if (feed != null) {
        if (!feed.isEmpty()) {
          if (feed.equals("AGREE")) titolo = Title.AGREE;
          else if (feed.equals("DISAGREE")) titolo = Title.DISAGREE;
          else if (feed.equals("PARTIALLY_AGREE")) titolo = Title.PARTIALLY_AGREE;
          else if (feed.equals("DETRACTOR")) titolo = Title.DETRACTOR;
          else continue;
        }
      } else continue;
      Date data = getPubDate(x);
      lista.add(new Feedback(description, titolo, data));
    }
    return lista;
  }
コード例 #7
0
  long delete(long id) {
    Item item = findItem(id);
    if (item != null) {
      getStorage().deregister(item);

      long sum = 0;
      for (long description : item.getDescription()) sum += description;

      return sum;
    }
    return 0;
  }
コード例 #8
0
  /**
   * An insert operation to the MDSItemStorage.
   *
   * @param id
   * @param price
   * @param description
   * @param size
   * @return
   */
  int insert(long id, double price, long[] description, int size) {

    if (find(id) != 0) {
      Item previousItem = findItem(id);

      Double previousPrice = previousItem.getPrice();
      List<Long> previousDescription = previousItem.getDescription();

      if (size > 0) {
        Integer previousDescriptionHash = previousItem.getDescriptionHash();

        // Description of item is in description[0..size-1]. copy them into your data structure.
        previousItem.setDescription(size, (size == 0) ? null : description);

        // adjust previousDescription
        getStorage()
            .updateDescriptionDataSet(
                previousItem,
                previousDescription,
                price,
                (previousPrice == price ? null : previousPrice));

        // adjust previousPrice
        getStorage().updatePriceDataSet(previousItem, previousPrice);

        // refresh and re-check associated same-same hash with the previous item.
        getStorage().addressSameSameHashing(previousItem, previousDescriptionHash);
      } else {
        if (previousPrice != price) {
          if (size == 0)
            getStorage().updateDescriptionDataSet(previousItem, null, price, previousPrice);

          // adjust previousPrice
          getStorage().updatePriceDataSet(previousItem, previousPrice);
        }
      }

      return 0;
    }

    // create the Item object.
    Item item = new Item();
    item.setId(id).setPrice(price).setDescription(size, (size == 0) ? null : description);

    // register new item
    getStorage().registerItem(item);

    return 1;
  }
コード例 #9
0
  /**
   * Month conversion from entity object to jaxb model.
   *
   * @param data month entity object
   * @return jaxb model of month
   */
  public static Month transformMonthToModel(org.kaleta.scheduler.backend.entity.Month data) {
    Month model = new Month();

    model.setId(String.valueOf(data.getId()));

    Month.Specification specification = new Month.Specification();
    specification.setName(data.getName());
    specification.setDays(String.valueOf(data.getDaysNumber()));
    specification.setFirstDay(String.valueOf(data.getDayStartsWith()));
    for (Integer day : data.getPublicFreeDays()) {
      Month.Specification.FreeDay freeDay = new Month.Specification.FreeDay();
      freeDay.setDay(String.valueOf(day));
      specification.getFreeDayList().add(freeDay);
    }
    model.setSpecification(specification);

    Month.Schedule schedule = new Month.Schedule();
    for (Task task : data.getTasks()) {
      Month.Schedule.Task taskModel = new Month.Schedule.Task();
      taskModel.setId(String.valueOf(task.getId()));
      taskModel.setType(task.getType());
      taskModel.setDescription(task.getDescription());
      taskModel.setDay(String.valueOf(task.getDay()));
      taskModel.setStarts(task.getStarts().toString());
      taskModel.setDuration(task.getDuration().toString());
      taskModel.setPriority(String.valueOf(task.getPriority()));
      taskModel.setSuccessful(String.valueOf(task.getSuccessful()));
      schedule.getTaskList().add(taskModel);
    }
    model.setSchedule(schedule);

    Month.Accounting accounting = new Month.Accounting();
    for (Item item : data.getItems()) {
      Month.Accounting.Item itemModel = new Month.Accounting.Item();
      itemModel.setId(String.valueOf(item.getId()));
      itemModel.setType(item.getType());
      itemModel.setDescription(item.getDescription());
      itemModel.setDay(String.valueOf(item.getDay()));
      itemModel.setIncome(String.valueOf(item.getIncome()));
      itemModel.setAmount(String.valueOf(item.getAmount()));
      accounting.getItemList().add(itemModel);
    }
    model.setAccounting(accounting);

    return model;
  }
コード例 #10
0
  public void testWrite() throws Exception {
    FileWriter fw = null;
    File outFile = null;

    try {
      outFile = File.createTempFile("FeedTest", "tmp");
      filesToDelete.add(outFile);
      fw = new FileWriter(outFile);
      Feed feed = new Feed(tempFile);
      feed.write(fw);
      fw.close();

      // Feed feed2 = new Feed(outFile);
      assertEquals("CruiseControl Build Results", feed.getTitle());
      assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink());
      assertEquals(
          "Automated build results for CruiseControl project(s) VERSION_10", feed.getDescription());

      // validate the number of items and the contents of the first item.
      assertEquals(11, feed.getItems().size());
      Item item = (Item) feed.getItems().get(0);
      assertEquals("VERSION_10 build.7 Build Successful", item.getTitle());
      assertEquals(
          "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
              + "VERSION_10?log=log20050817084109Lbuild.7",
          item.getLink());
      assertEquals(
          "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
              + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
              + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
              + "ApplicationServer/PlayTime/default.build"
              + "  by jefferson (deploy the mock object dll)</li></ul>",
          item.getDescription());
    } finally {
      IO.close(fw);
    }
  }
コード例 #11
0
  public void testConstructors() {
    Feed feed = new Feed(tempFile);

    assertEquals("CruiseControl Build Results", feed.getTitle());
    assertEquals("http://MyMachine.MyDomain.com/cruisecontrol/", feed.getLink());
    assertEquals(
        "Automated build results for CruiseControl project(s) VERSION_10", feed.getDescription());

    // validate the number of items and the contents of the first item.
    assertEquals(11, feed.getItems().size());
    Item item = (Item) feed.getItems().get(0);
    assertEquals("VERSION_10 build.7 Build Successful", item.getTitle());
    assertEquals(
        "http://MyMachine.MyDomain.com/cruisecontrol/buildresults/"
            + "VERSION_10?log=log20050817084109Lbuild.7",
        item.getLink());
    assertEquals(
        "<em>Build Time:</em> Wed Aug 17 08:41:09 MDT 2005<br/>"
            + "<em>Label:</em> build.7<br/><em>Modifications: </em>1<br/>"
            + "\n<ul><li>//depot/MyProduct/VERSION_10/dev/main/src/datacenter/"
            + "ApplicationServer/PlayTime/default.build"
            + "  by jefferson (deploy the mock object dll)</li></ul>",
        item.getDescription());
  }
コード例 #12
0
  public void listItems() {

    for (Item item : getItems()) {
      System.out.println(item.getDescription());
    }
  }
コード例 #13
0
ファイル: RssReader.java プロジェクト: giacomolm/rssconnector
  public ArrayList<Post> readPosts(boolean advanced) {
    RssParser parser = null;
    Rss rss = null;
    try {
      parser = RssParserFactory.createDefault();
      System.out.println(boardAddress);
      rss = parser.parse(new URL(boardAddress + "postboard?action=READ"));

    } catch (RssParserException e) {
      System.out.println("RssParserException");
      return null;
    } catch (MalformedURLException e) {
      System.out.println("MalformedURLException");
      return null;
    } catch (IOException e) {
      System.out.println("IOException");
      return null;
    }
    Channel c = rss.getChannel();
    if (c.getItems() == null) {
      System.out.println("Non ci sono Post");
      return new ArrayList<Post>();
    }
    ArrayList<Item> items = new ArrayList<Item>(c.getItems());
    Iterator<Item> iter = items.iterator();
    ArrayList<Post> res = new ArrayList<Post>();
    while (iter.hasNext()) {
      Item i = (Item) iter.next();
      if (advanced) if ((!bannished.equals("")) && (i.getText().indexOf(bannished) != -1)) continue;
      long id = getFeedbackName(i); // id sempre presente
      String titolo = "";
      String link = "";
      String description = "";
      ArrayList<String> categories = new ArrayList<String>();
      String enclosure = "";
      String source = "";
      Date date = getPubDate(i); // data sempre presente
      try {
        titolo = i.getTitle().getText();
      } catch (NullPointerException e) {
      }
      try {
        link = i.getLink().getText();
      } catch (NullPointerException e) {
      }
      try {
        description = i.getDescription().getText();
      } catch (NullPointerException e) {
      }
      try {
        categories = getCategories(i);
      } catch (NullPointerException e) {
      }
      try {
        enclosure = i.getEnclosure().getText();
      } catch (NullPointerException e) {
      }
      try {
        source = i.getSource().getText();
      } catch (NullPointerException e) {
      }
      if (advanced) if (!(match(categories) && timestamp.before(date))) continue;
      Post p =
          new Post(
              id,
              titolo,
              link,
              description,
              "",
              categories,
              enclosure,
              source,
              date,
              readFeedbacks(id));
      res.add(p);
    }
    if (advanced) if (res.size() > 0) timestamp = res.get(res.size() - 1).getPubDate();
    return res;
  }