@Test
  @TestForIssue(jiraKey = "HHH-3694")
  public void testResultTransformerIsAppliedToScrollableResults() throws Exception {
    Session s = openSession();
    Transaction tx = s.beginTransaction();

    PartnerA a = new PartnerA();
    a.setName("Partner A");
    PartnerB b = new PartnerB();
    b.setName("Partner B");
    Contract obj1 = new Contract();
    obj1.setName("Contract");
    obj1.setA(a);
    obj1.setB(b);
    s.save(a);
    s.save(b);
    s.save(obj1);

    tx.commit();
    s.close();

    s = openSession();

    Query q = s.getNamedQuery(Contract.class.getName() + ".testQuery");
    q.setFetchSize(100);
    q.setResultTransformer(
        new ResultTransformer() {

          private static final long serialVersionUID = -5815434828170704822L;

          public Object transformTuple(Object[] arg0, String[] arg1) {
            // return only the PartnerA object from the query
            return arg0[1];
          }

          @SuppressWarnings("unchecked")
          public List transformList(List arg0) {
            return arg0;
          }
        });
    ScrollableResults sr = q.scroll();
    // HANA supports only ResultSet.TYPE_FORWARD_ONLY and
    // does not support java.sql.ResultSet.first()
    if (getDialect() instanceof AbstractHANADialect) {
      sr.next();
    } else {
      sr.first();
    }

    Object[] row = sr.get();
    assertEquals(1, row.length);
    Object obj = row[0];
    assertTrue(obj instanceof PartnerA);
    PartnerA obj2 = (PartnerA) obj;
    assertEquals("Partner A", obj2.getName());
    s.close();
  }
예제 #2
0
 public boolean haveUnresolvedContracts() {
   for (Message message : messages) {
     Contract c = message.getContract();
     if (c != null) {
       if (!c.isResolved()) {
         return true;
       }
     }
   }
   return false;
 }
예제 #3
0
  /**
   * Attempts to fulfill Contract by removing Crop Resources. Fails if not e
   *
   * @param contract
   */
  private void fulfilContract(Contract contract) {
    World world = WorldManager.getInstance().getWorld();
    contract.decrementRepeatCount();
    if (contract.getRepeatCount() > 0) {
      // attempt to remove inventory
      if (world.getStorageManager().getCrops().getQuantity(contract.getResourceType())
          < contract.getAmount()) {
        // failed to supply crops - penalize and break contract.
        LOGGER.info("Contract Failed");
        notifyUser("Contract Failed");
        world.getMoneyHandler().subtractAmount(contract.getPenalty());
        removeContract(contract);
      } else {
        // maybe give small payment?
        LOGGER.info("contract delivered");
        notifyUser("Contract Delivered");
        world.getMoneyHandler().addAmount(150);
        world
            .getStorageManager()
            .getCrops()
            .takeItem(contract.getResourceType(), contract.getAmount());
      }

    } else {
      // the contract has been completed

      // add the reward to bank and remove contract.
      LOGGER.info("contract completed");
      notifyUser("Contract Completed");
      world.getMoneyHandler().addAmount(contract.getReward());
      currentContracts.remove(contract);
    }
  }
예제 #4
0
 /**
  * @param act
  * @return
  */
 private String buildContractUrl(Contract contract) {
   StringBuilder strb = new StringBuilder();
   strb.append(webappUrl);
   strb.append(contractUrlSuffix);
   strb.append(contract.getId());
   return strb.toString();
 }
  public CompareAlgorithms() {

    factories =
        new CutAlgorithmFactory[] {
          Contract.getFactory(), StoerWagner.getFactory(), AdgFastCut.getFactory()
        };
  }
예제 #6
0
 /**
  * Get the date of delivery of one contract.
  *
  * @return the integer of date of delivery
  * @param contract: the contract that need to get delivery date.
  */
 public int getDeliveryDate(Contract contract) {
   World world = WorldManager.getInstance().getWorld();
   int currentDay = world.getTimeManager().getDays();
   int startDay = currentContracts.get(contract);
   int interval = contract.getInterval();
   return (startDay + interval) - currentDay;
 }
예제 #7
0
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("ContractPerson [");
   builder.append(super.toString());
   builder.append(", contract.id=");
   builder.append(contract != null ? contract.getId() : null);
   builder.append(", person.id=");
   builder.append(person != null ? person.getId() : null);
   builder.append("]");
   return builder.toString();
 }
 @Override
 public void calculateRevenueRecognitions(Contract contract) {
   long oneThirdRevenue = contract.getRevenue() / 3;
   long remainder = contract.getRevenue() % 3;
   contract.addRevenueRecognition(
       new RevenueRecognition(oneThirdRevenue, contract.getWhenSigned()));
   contract.addRevenueRecognition(
       new RevenueRecognition(
           oneThirdRevenue, addDays(contract.getWhenSigned(), firstRecognitionOffset)));
   contract.addRevenueRecognition(
       new RevenueRecognition(
           oneThirdRevenue + remainder,
           addDays(contract.getWhenSigned(), secondRecognitionOffset)));
 }
예제 #9
0
 /**
  * Reads and parses XML from a {@code InputStream}.
  *
  * @param in the {@code InputStream} to parse from
  * @return the parsed {@code XMLConfig}
  * @throws ConfigException if the parsing failed
  */
 static XMLConfig read(InputStream in) throws ConfigException {
   Contract.nonNull(in);
   XMLConfig rv = naked();
   try {
     Document xmlDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in);
     return readAndSetupEntriesImpl(rv, xmlDoc);
   } catch (SAXException ex) {
     throw new ConfigException(ex);
   } catch (ParserConfigurationException ex) {
     throw new ConfigException(ex);
   } catch (IOException ex) {
     throw new ConfigException(ex);
   }
 }
예제 #10
0
  private boolean checkDialog() {
    if (Contract.askUser()) {
      if (user != null) {
        model
            .createResource(Vocab.Agreement)
            .addProperty(Vocab.licensee, user)
            .addProperty(Vocab.software, software)
            .addProperty(Vocab.licensor, "Hewlett-Packard Development Company, LP")
            .addProperty(Vocab.agreementDate, model.createTypedLiteral(Calendar.getInstance()));

        try {
          FileOutputStream fos = new FileOutputStream(license);
          model.write(fos, "RDF/XML-ABBREV");
          fos.close();
        } catch (IOException e) {
          // ignore
        }
      }
      return true;
    }
    return false;
  }
예제 #11
0
 /**
  * Reads and parses XML from a {@code String}.
  *
  * @param strXML the {@code String} to parse from
  * @return the parsed {@code XMLConfig}
  * @throws ConfigException if the parsing failed
  */
 static XMLConfig parse(String strXML) throws ConfigException {
   Contract.nonNull(strXML);
   return read((Reader) new StringReader(strXML));
 }
예제 #12
0
  /**
   * Method persistCandleSeries.
   *
   * @param candleSeries CandleSeries
   * @throws Exception
   */
  public synchronized void persistCandleSeries(CandleSeries candleSeries) throws Exception {
    Candle transientInstance = null;
    try {
      if (candleSeries.isEmpty()) return;

      EntityManager entityManager = EntityManagerHelper.getEntityManager();
      entityManager.getTransaction().begin();
      Tradingday tradingday = null;
      Contract contract = findContractById(candleSeries.getContract().getIdContract());
      for (int i = 0; i < candleSeries.getItemCount(); i++) {

        CandleItem candleItem = (CandleItem) candleSeries.getDataItem(i);
        if (null != candleItem.getCandle().getIdCandle()) {
          Candle instance = entityManager.find(Candle.class, candleItem.getCandle().getIdCandle());
          if (instance.equals(candleItem.getCandle())) {
            continue;
          } else {
            // This should never happen.
            throw new Exception(
                "Count: "
                    + i
                    + " Symbol: "
                    + candleSeries.getSymbol()
                    + "candleid: "
                    + candleItem.getCandle().getIdCandle()
                    + " open: "
                    + candleItem.getCandle().getStartPeriod());
          }
        }

        if (!candleItem.getCandle().getTradingday().equals(tradingday)) {

          if (null == candleItem.getCandle().getTradingday().getIdTradingDay()) {
            tradingday =
                findTradingdayByDate(
                    candleItem.getCandle().getTradingday().getOpen(),
                    candleItem.getCandle().getTradingday().getClose());
          } else {
            tradingday =
                findTradingdayById(candleItem.getCandle().getTradingday().getIdTradingDay());
          }

          if (null == tradingday) {
            entityManager.persist(candleItem.getCandle().getTradingday());
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
            tradingday = candleItem.getCandle().getTradingday();
          } else {
            Integer idTradingday = tradingday.getIdTradingDay();
            Integer idContract = contract.getIdContract();
            Integer barSize = candleSeries.getBarSize();
            String hqlDelete =
                "delete Candle where idContract = :idContract and idTradingday = :idTradingday and barSize = :barSize";
            entityManager
                .createQuery(hqlDelete)
                .setParameter("idContract", idContract)
                .setParameter("idTradingday", idTradingday)
                .setParameter("barSize", barSize)
                .executeUpdate();
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
          }
        }

        transientInstance = candleItem.getCandle();
        transientInstance.setTradingday(tradingday);
        transientInstance.setContract(contract);
        entityManager.persist(transientInstance);

        // Commit every 50 rows
        if ((Math.floor(i / 50d) == (i / 50d)) && (i > 0)) {
          entityManager.getTransaction().commit();
          entityManager.getTransaction().begin();
        }
      }
      entityManager.getTransaction().commit();
    } catch (RuntimeException re) {
      EntityManagerHelper.logError("Error persistCandleSeries failed :" + re.getMessage(), re);
      EntityManagerHelper.rollback();
      throw re;
    } finally {
      EntityManagerHelper.close();
    }
  }
 @Override
 void calculateRevenueRecognitions(Contract contract) {
   contract.addRevenueRecognition(
       new RevenueRecognition(contract.getRevenue(), contract.getWhenSigned()));
 }
예제 #14
0
  /** create a Contract from our info */
  public Contract getContract() {
    Contract c = new Contract();
    c.m_conId = m_conid;
    c.m_symbol = m_symbol;
    c.m_secType = m_secType.toString();
    c.m_expiry = m_expiry;
    c.m_strike = m_strike;
    c.m_right = m_right.getApiString();
    c.m_multiplier = m_multiplier;
    c.m_exchange = m_exchange;
    c.m_primaryExch = m_primaryExch;
    c.m_currency = m_currency;
    c.m_localSymbol = m_localSymbol;
    c.m_tradingClass = m_tradingClass;
    c.m_primaryExch = m_primaryExch;
    c.m_secIdType = m_secIdType.getApiString();
    c.m_secId = m_secId;

    if (m_underComp != null) {
      c.m_underComp = new UnderComp();
      c.m_underComp.m_conId = m_underComp.conid();
      c.m_underComp.m_delta = m_underComp.delta();
      c.m_underComp.m_price = m_underComp.price();
    }

    c.m_comboLegs = new Vector<ComboLeg>();
    for (NewComboLeg leg : m_comboLegs) {
      c.m_comboLegs.add(leg.getComboLeg());
    }

    return c;
  }