示例#1
0
 @Test
 public void test_getKeyColumnName() {
   final TypedSqlQuery<I_C_Invoice> query =
       new TypedSqlQuery<I_C_Invoice>(getCtx(), I_C_Invoice.class, null, getTrxName());
   Assert.assertEquals(
       "Invalid key column for " + query, "C_Invoice_ID", query.getKeyColumnName());
 }
示例#2
0
  @Test(expected = DBException.class)
  public void test_getKeyColumnName_CompositePrimaryKey() {
    final TypedSqlQuery<I_M_Cost> query =
        new TypedSqlQuery<I_M_Cost>(getCtx(), I_M_Cost.class, null, getTrxName());

    // shall throw exception
    query.getKeyColumnName();
  }
示例#3
0
  private void test_GuaranteedPOBufferedIterator_changingData(final String trxName)
      throws Exception {
    final Properties ctx = Env.getCtx();

    for (int i = 1; i <= 100; i++) {
      createTestRecord(i, trxName);
    }

    final int iteratorBufferSize = 10;

    final TypedSqlQuery<I_Test> query =
        new TypedSqlQuery<I_Test>(
                ctx, I_Test.class, I_Test.COLUMNNAME_T_Integer + " BETWEEN ? AND ?", trxName)
            .setParameters(20, 60)
            .setOption(Query.OPTION_IteratorBufferSize, iteratorBufferSize)
            .setOrderBy(I_Test.COLUMNNAME_T_Integer);

    final List<I_Test> expectedList = query.list(I_Test.class);
    Assert.assertEquals(60 - 20 + 1, expectedList.size());
    for (int i = 0; i < expectedList.size(); i++) {
      final I_Test item = expectedList.get(i);
      final int expectedInt = 20 + i;
      Assert.assertEquals("Invalid item: " + item, expectedInt, item.getT_Integer());
    }

    @SuppressWarnings("unchecked")
    final POBufferedIterator<I_Test, I_Test> itNotGuaranteed =
        (POBufferedIterator<I_Test, I_Test>) query.iterate(I_Test.class, false);
    Assert.assertEquals(
        "BufferSize not set for " + itNotGuaranteed,
        iteratorBufferSize,
        itNotGuaranteed.getBufferSize());

    @SuppressWarnings("unchecked")
    final GuaranteedPOBufferedIterator<I_Test, I_Test> itGuaranteed =
        (GuaranteedPOBufferedIterator<I_Test, I_Test>) query.iterate(I_Test.class, true);
    Assert.assertEquals(
        "BufferSize not set for " + itGuaranteed, iteratorBufferSize, itGuaranteed.getBufferSize());

    // Change item value (which is included in where clause) and item is not in first buffer:
    {
      final I_Test item = expectedList.get(30);
      item.setT_Integer(10000 + item.getT_Integer());
      InterfaceWrapperHelper.save(item);
    }

    final List<I_Test> itGuaranteedList = getList(itGuaranteed);
    Assert.assertEquals("Guaranteed list shall not be changed", expectedList, itGuaranteedList);

    final List<I_Test> itNotGuaranteedList = getList(itNotGuaranteed);
    Assert.assertThat(
        "Not guaranteed list shall be changed", expectedList, not(equalTo(itNotGuaranteedList)));
  }
示例#4
0
  @Test
  public void test_GuaranteedPOBufferedIterator_simple() {
    final Properties ctx = Env.getCtx();
    final String trxName = ITrx.TRXNAME_None;

    final TypedSqlQuery<I_AD_Table> query =
        new TypedSqlQuery<I_AD_Table>(ctx, I_AD_Table.class, "TableName like ?", trxName)
            .setParameters("AD%")
            .setOrderBy(I_AD_Table.COLUMNNAME_TableName)
            .setLimit(100, 20);

    final List<I_AD_Table> expectedList = query.list(I_AD_Table.class);
    final Iterator<I_AD_Table> it = query.iterate(I_AD_Table.class, true); // guaranteed=true

    final List<I_AD_Table> actualList = getList(it);
    Assert.assertEquals("Not same list", expectedList, actualList);
  }