Java Code Examples for com.gs.fw.common.mithra.MithraTransaction#rollback()

The following examples show how to use com.gs.fw.common.mithra.MithraTransaction#rollback() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDatedBitemporalNull.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testSetOnMultipleObjects()
{
    Timestamp businessDate = new Timestamp(System.currentTimeMillis());
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {

        TinyBalanceNullList list = new TinyBalanceNullList(TinyBalanceNullFinder.acmapCode().eq("A")
                            .and(TinyBalanceNullFinder.businessDate().eq(businessDate)));
        for(int i=0;i<list.size();i++)
        {
            list.getTinyBalanceNullAt(i).setQuantity(100);
        }
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
}
 
Example 2
Source File: TestTransactionalObject.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testRollbackInsert() throws SQLException
{
    int orderId = 11111;
    Order order = new Order();
    order.setOrderId(orderId);
    order.setState("test state");
    order.setDescription("test description");
    order.setUserId(2);
    order.setOrderDate(new Timestamp(System.currentTimeMillis()));
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    order.insert();
    tx.rollback();
    assertTrue(order.isInMemory());

    checkOrderDoesNotExist(orderId);
}
 
Example 3
Source File: MultiThreadingUtil.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void run()
{
    try
    {
        this.wrapped.run();
    }
    catch (Throwable e)
    {
        getLogger().error("error in test runnable ", e);
        causeOfFailure = e;
        MithraTransaction tx = MithraManager.getInstance().getCurrentTransaction();
        if(tx != null)
        {
            tx.rollback();
        }
    }
}
 
Example 4
Source File: TestDetached.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testDetachDeleteRollback()
{
    Order originalOrder = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    Order order = originalOrder.getDetachedCopy();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    order.delete();
    tx.rollback();
    assertEquals(originalOrder.getDescription(), order.getDescription());
}
 
Example 5
Source File: TestDetached.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testIsModifiedInTransactionWithRollback()
{
    Order originalOrder = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    Order order = originalOrder.getDetachedCopy();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    order.setDescription("test 1900");
    assertTrue(order.isModifiedSinceDetachment());
    tx.rollback();
    assertFalse(order.isModifiedSinceDetachment());
}
 
Example 6
Source File: TestDetached.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testIsModifiedInTransactionWithRollbackModifyingMutablePK()
{
    ExchangeRate originalRate = findExchangeRate("A", "USD", 10, new Timestamp(dateTimeFormatter.parseMillis("2004-09-30 18:30:00.0")));
    assertNotNull(originalRate);
    ExchangeRate rate = originalRate.getDetachedCopy();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    assertFalse(rate.isModifiedSinceDetachment());
    rate.setSource(11);
    assertTrue(rate.isModifiedSinceDetachment());
    tx.rollback();
    assertFalse(rate.isModifiedSinceDetachment());
}
 
Example 7
Source File: TestTransactionalClientPortal.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testRollback() throws SQLException
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    assertNotNull(order);
    tx.rollback();
}
 
Example 8
Source File: TestParaDatedBitemporal.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testUpdateUntilTwoTimes() throws SQLException, ParseException
    {
        int balanceId = 60;
        Timestamp firstDate = new Timestamp(timestampFormat.parse("2004-01-17 18:30:00").getTime());
        Timestamp secondDate = new Timestamp(timestampFormat.parse("2005-01-17 18:30:00").getTime());
        Timestamp thirdDate = new Timestamp(timestampFormat.parse("2006-01-17 18:30:00").getTime());
        ParaBalance firstBalance = findParaBalanceForBusinessDate(balanceId, firstDate);
        ParaBalance secondBalance = findParaBalanceForBusinessDate(balanceId, secondDate);
        assertNotNull(firstBalance);
        assertNotNull(secondBalance);
        assertEquals(100, firstBalance.getQuantity(), 0);
        assertEquals(300, secondBalance.getQuantity(), 0);
        MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
        try
        {
            firstBalance.setQuantityUntil(150,secondDate);
//            tx.executeBufferedOperations();
            secondBalance.setQuantityUntil(350,thirdDate);
            tx.commit();
        }
        catch(Throwable t)
        {
            getLogger().error("transaction failed", t);
            tx.rollback();
            fail("transaction failed see exception");
        }
        firstBalance = findParaBalanceForBusinessDate(balanceId, firstDate);
        secondBalance = findParaBalanceForBusinessDate(balanceId, secondDate);
        assertNotNull(firstBalance);
        assertNotNull(secondBalance);
        assertEquals(150, firstBalance.getQuantity(), 0);
        assertEquals(350, secondBalance.getQuantity(), 0);
    }
 
Example 9
Source File: TestDatedNonAudited.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testInsertThenIncrementInOneTransaction() throws SQLException
{
    NonAuditedBalanceInterface tb = null;
    Timestamp businessDate = new Timestamp(System.currentTimeMillis());
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        tb = findNonAuditedBalanceForBusinessDate(2000, businessDate);
        assertNull(tb);
        tb = buildNonAuditedBalance(businessDate);
        tb.setAcmapCode("A");
        tb.setBalanceId(2000);
        tb.setQuantity(12.5);
        tb.insert();
        tb.incrementQuantity(1000);
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    int count = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount();
    NonAuditedBalanceInterface fromCache = findNonAuditedBalanceForBusinessDate(2000, businessDate);
    assertSame(tb, fromCache);
    assertEquals(1012.5, tb.getQuantity(), 0);
    fromCache = findNonAuditedBalanceForBusinessDate(2000, InfinityTimestamp.getParaInfinity());
    assertEquals(count, MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount());

    // test the database:
    checker.checkDatedNonAuditedInfinityRow(2000, 1012.5, businessDate);
}
 
Example 10
Source File: TestDatedNonAudited.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testInsertThenIncrementLaterDay() throws SQLException
{
    NonAuditedBalanceInterface tb = null;
    Timestamp businessDate = new Timestamp(System.currentTimeMillis());
    Timestamp lbd = new Timestamp(businessDate.getTime() - 24 * 3600 * 1000);
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        NonAuditedBalanceInterface lbdBalance = findNonAuditedBalanceForBusinessDate(2000, lbd);
        assertNull(lbdBalance);
        lbdBalance = buildNonAuditedBalance(lbd);
        lbdBalance.setAcmapCode("A");
        lbdBalance.setBalanceId(2000);
        lbdBalance.setQuantity(1000);
        lbdBalance.insertWithIncrement();

        tb = findNonAuditedBalanceForBusinessDate(2000, businessDate);
        assertNotNull(tb);
        tb.incrementQuantity(12.5);

        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    int count = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount();
    NonAuditedBalanceInterface fromCache = findNonAuditedBalanceForBusinessDate(2000, businessDate);
    assertSame(tb, fromCache);
    assertEquals(1012.5, tb.getQuantity(), 0);
    fromCache = findNonAuditedBalanceForBusinessDate(2000, InfinityTimestamp.getParaInfinity());
    assertEquals(count, MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount());

    // test the database:
    checker.checkDatedNonAuditedInfinityRow(2000, 1012.5, businessDate);
}
 
Example 11
Source File: TestDatedAuditOnly.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testInsertAll() throws SQLException
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        AuditOnlyBalanceList list = new AuditOnlyBalanceList();
        for(int i=0;i<30;i++)
        {
            AuditOnlyBalance tb = new AuditOnlyBalance(InfinityTimestamp.getParaInfinity());
            tb.setAcmapCode("A");
            tb.setBalanceId(2000+i);
            tb.setQuantity(12.5+i);
            tb.setInterest(22.1+i);
            list.add(tb);
        }
        list.insertAll();
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    for(int i=0;i<30;i++)
    {
        this.checker.checkDatedAuditOnlyInfinityRow(2000+i, 12.5+i, 22.1+i);
    }
}
 
Example 12
Source File: TestParaDatedBitemporal.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testInsertThenIncrementInOneTransaction() throws SQLException
{
    ParaBalance tb = null;
    int balanceId = 4020;
    java.util.Date paraBusinessDate = createParaBusinessDate(new java.util.Date());
    Timestamp businessDate = addDaysAsTimestamp(paraBusinessDate, 1);
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        tb = findParaBalanceForBusinessDate(balanceId, businessDate);
        assertNull(tb);
        tb = new ParaBalance(businessDate, InfinityTimestamp.getParaInfinity());
        tb.setAcmapCode("A");
        tb.setBalanceId(balanceId);
        tb.setQuantity(12.5);
        tb.insert();
        tb.incrementQuantity(1000);
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    int count = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount();
    ParaBalance fromCache = findParaBalanceForBusinessDate(balanceId, businessDate);
    assertSame(tb, fromCache);
    assertEquals(1012.5, tb.getQuantity(), 0);
    fromCache = findParaBalanceForBusinessDate(balanceId, InfinityTimestamp.getParaInfinity());
    assertEquals(count, MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount());

    // test the database:
    checkParaInfinityRow(balanceId, 1012.5, new Timestamp(paraBusinessDate.getTime()));
}
 
Example 13
Source File: TestDatedNonAudited.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testInsertForRecovery() throws SQLException, ParseException
{
    int balanceId = 230;

    Timestamp fromBusinessDate = new Timestamp(timestampFormat.parse("2003-06-01 06:30:00").getTime());
    Timestamp queryBusinessDate = new Timestamp(timestampFormat.parse("2003-06-02 06:30:00").getTime());
    Timestamp toBusinessDate = new Timestamp(timestampFormat.parse("2003-06-03 06:30:00").getTime());

    NonAuditedBalanceInterface testQuery = this.findNonAuditedBalanceForBusinessDate(balanceId, queryBusinessDate);
    assertNull(testQuery);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        NonAuditedBalanceInterface recoveredBalance = buildNonAuditedBalance(fromBusinessDate);
        recoveredBalance.setAcmapCode("A");
        recoveredBalance.setBalanceId(balanceId);
        recoveredBalance.setInterest(10000);
        recoveredBalance.setQuantity(20000);
        recoveredBalance.setBusinessDateFrom(fromBusinessDate);
        recoveredBalance.setBusinessDateTo(toBusinessDate);
        recoveredBalance.insertForRecovery();

        testQuery = this.findNonAuditedBalanceForBusinessDate(balanceId, queryBusinessDate);
        assertNotNull(testQuery);

        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    testQuery = this.findNonAuditedBalanceForBusinessDate(balanceId, queryBusinessDate);
    assertNotNull(testQuery);

    // test the database:
    assertEquals(1, this.checker.checkDatedNonAuditedRowCounts(balanceId));
}
 
Example 14
Source File: TestDatedBitemporalNull.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testTerminateAllCustomInz() throws SQLException, ParseException
{
    TinyBalanceNullList list = TinyBalanceNullFinder.findMany(TinyBalanceNullFinder.acmapCode().eq("A").and(TinyBalanceNullFinder.balanceId().greaterThan(1))
        .and(TinyBalanceNullFinder.businessDate().eq(new Timestamp(System.currentTimeMillis()))));

    assertTrue(list.size() > 1);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();

    try
    {
        tx.setProcessingStartTime(timestampFormat.parse("2002-11-29 00:00:00").getTime());
        list.terminateAll();
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }

    list = TinyBalanceNullFinder.findMany(TinyBalanceNullFinder.acmapCode().eq("A").and(TinyBalanceNullFinder.balanceId().greaterThan(1))
        .and(TinyBalanceNullFinder.businessDate().eq(new Timestamp(System.currentTimeMillis()))));
    assertEquals(0, list.size());

    list = TinyBalanceNullFinder.findMany(TinyBalanceNullFinder.acmapCode().eq("A").and(TinyBalanceNullFinder.balanceId().greaterThan(1))
        .and(TinyBalanceNullFinder.businessDate().eq(new Timestamp(System.currentTimeMillis())))
        .and(TinyBalanceNullFinder.processingDate().eq(new Timestamp(timestampFormat.parse("2002-11-28 00:00:00").getTime()))));
    assertEquals(0, list.size());

    Connection con = this.getConnection();
    String sql = "select count(*) from TINY_BALANCE_NULL where BALANCE_ID > 1 and " +
            "OUT_Z is null and THRU_Z is null";
    PreparedStatement ps = con.prepareStatement(sql);
    ResultSet rs = ps.executeQuery();
    assertTrue(rs.next());
    int count = rs.getInt(1);
    rs.close();
    ps.close();
    con.close();
    assertEquals(0, count);
}
 
Example 15
Source File: TestDatedAuditOnly.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testInsertForRecovery() throws SQLException, ParseException
{
    int balanceId = 230;

    Timestamp fromProcessingDate = new Timestamp(timestampFormat.parse("2003-06-01 05:31:00").getTime());
    Timestamp queryProcessingDate = new Timestamp(timestampFormat.parse("2003-06-01 05:45:00").getTime());
    Timestamp toProcessingDate = new Timestamp(timestampFormat.parse("2003-06-01 06:11:00").getTime());

    AuditOnlyBalance testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
    assertNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
    assertNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
    assertNull(testQuery);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        AuditOnlyBalance recoveredBalance = new AuditOnlyBalance(fromProcessingDate);
        recoveredBalance.setAcmapCode("A");
        recoveredBalance.setBalanceId(balanceId);
        recoveredBalance.setInterest(10000);
        recoveredBalance.setQuantity(20000);
        recoveredBalance.setProcessingDateFrom(fromProcessingDate);
        recoveredBalance.setProcessingDateTo(toProcessingDate);
        recoveredBalance.insertForRecovery();

        testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
        assertNotNull(testQuery);
        testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
        assertNotNull(testQuery);
        testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
        assertNull(testQuery);

        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
    assertNotNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
    assertNotNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
    assertNull(testQuery);

    // test the database:
    this.checker.checkDatedAuditOnlyTimestampRow(balanceId, 20000, 10000, queryProcessingDate);
}
 
Example 16
Source File: TestDatedAuditOnly.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testTerminateDualInsertTerminateOther() throws SQLException, ParseException
{
    int orderItemId = 1;
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        AuditedOrderItem item = AuditedOrderItemFinder.findOne(AuditedOrderItemFinder.id().eq(orderItemId));
        AuditedOrderItem other = AuditedOrderItemFinder.findOne(AuditedOrderItemFinder.id().eq(2));
        AuditedOrderItem forInsert = item.getNonPersistentCopy();
        item.terminate();

        AuditedOrderItem moreInsert = forInsert.getNonPersistentCopy();
        moreInsert.setId(1000);
        moreInsert.insert();

        // buffer the two insert
        Order order = new Order();
        order.setOrderId(1000);
        order.insert();

        forInsert.setQuantity(1234);
        forInsert.insert();

        other.terminate();

        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    AuditedOrderItem fromCache = AuditedOrderItemFinder.findOne(AuditedOrderItemFinder.id().eq(orderItemId));
    assertNotNull(fromCache);
    // test the database:
    fromCache = AuditedOrderItemFinder.findOneBypassCache(AuditedOrderItemFinder.id().eq(orderItemId));
    assertNotNull(fromCache);
    assertEquals(1234, fromCache.getQuantity(), 0);
}
 
Example 17
Source File: TestDatedAuditOnly.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testPurgeMultipleTimes() throws SQLException, ParseException
{
    int balanceId = 2;
    AuditOnlyBalance currentBalance = getInfinityBalance(balanceId);
    assertNotNull(currentBalance);
    AuditOnlyBalance pastBalance = getBalanceForYear(balanceId, 2003);
    assertNotNull(pastBalance);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        //Assert the purge
        currentBalance.purge();
        currentBalance = getInfinityBalance(balanceId);
        assertNull(currentBalance);
        pastBalance = getBalanceForYear(balanceId, 2003);
        assertNull(pastBalance);

        //Insert again
        AuditOnlyBalance newBalance = new AuditOnlyBalance(InfinityTimestamp.getParaInfinity());
        newBalance.setAcmapCode("A");
        newBalance.setBalanceId(balanceId);
        newBalance.setInterest(10000);
        newBalance.setQuantity(20000);
        newBalance.insert();

        currentBalance = getInfinityBalance(balanceId);
        assertNotNull(currentBalance);
        pastBalance = getBalanceForYear(balanceId, 2003);
        assertNull(pastBalance);

        //Purge again
        currentBalance.purge();
        currentBalance = getInfinityBalance(balanceId);
        assertNull(currentBalance);
        pastBalance = getBalanceForYear(balanceId, 2003);
        assertNull(pastBalance);

        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    currentBalance = getInfinityBalance(balanceId);
    assertNull(currentBalance);
    pastBalance = getBalanceForYear(balanceId, 2003);
    assertNull(pastBalance);
    // test the database:
    assertEquals(0, this.checker.checkDatedAuditOnlyRowCounts(balanceId));
}
 
Example 18
Source File: TestDatedAuditOnly.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testPurgeForNestedTransaction() throws SQLException, ParseException
{
    int balanceId = 2;
    AuditOnlyBalance currentBalance = getInfinityBalance(balanceId);
    assertNotNull(currentBalance);
    AuditOnlyBalance pastBalance = getBalanceForYear(balanceId, 2003);
    assertNotNull(pastBalance);
    AuditOnlyBalance futureBalance = getFutureBalance(balanceId);
    assertNotNull(futureBalance);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    MithraTransaction nestedTx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        currentBalance.purge();
        assertTrue(currentBalance.zIsParticipatingInTransaction(nestedTx));

        this.checkQuantityThrowsException(futureBalance);
        this.checkQuantityThrowsException(pastBalance);

        currentBalance = getInfinityBalance(balanceId);
        assertNull(currentBalance);
        futureBalance = getFutureBalance(balanceId);
        assertNull(futureBalance);
        pastBalance = getBalanceForYear(balanceId, 2003);
        assertNull(pastBalance);
        nestedTx.commit();
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    currentBalance = getInfinityBalance(balanceId);
    assertNull(currentBalance);
    futureBalance = getFutureBalance(balanceId);
    assertNull(futureBalance);
    pastBalance = getBalanceForYear(balanceId, 2003);
    assertNull(pastBalance);
    // test the database:
    assertEquals(0, this.checker.checkDatedAuditOnlyRowCounts(balanceId));
}
 
Example 19
Source File: TestDatedNonAudited.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testMultiKeyUpdateSameBusinesDay() throws SQLException, ParseException
    {
        Timestamp businessDate = new Timestamp(timestampFormat.parse("2005-01-25 18:30:00.0").getTime());
        TestAgeBalanceSheetRunRateInterface rate = findTestAgeBalanceSheetRunRate(businessDate);
        assertNotNull(rate);
        double newValue = 0;
        double newPrice = 0;
        MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
        try
        {
            newValue = rate.getValue()*1.2;
            newPrice = rate.getPrice()*1.3;
            rate.setValue(newValue);
            rate.setPrice(newPrice);
//            NonAuditedBalance fromCache = findNonAuditedBalanceForBusinessDate(balanceId, new Timestamp(businessDate.getTime()+1000));
//
//            tb.setQuantity(12.5);
//            assertTrue(fromCache.getQuantity() == 12.5);
//            assertTrue(tb.zIsParticipatingInTransaction(tx));
//            int count = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount();
//            fromCache = findNonAuditedBalanceForBusinessDate(balanceId, businessDate);
//            assertSame(tb, fromCache);
//            fromCache = findNonAuditedBalanceForBusinessDate(balanceId, new Timestamp(businessDate.getTime()+1000));
//            assertNotSame(tb, fromCache);
//            assertTrue(fromCache.getQuantity() == 12.5);
//            assertEquals(count, MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount());
            tx.commit();
        }
        catch(Throwable t)
        {
            getLogger().error("transaction failed", t);
            tx.rollback();
            fail("transaction failed see exception");
        }
        // check the cache:
//        int count = MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount();
//        NonAuditedBalance fromCache = findNonAuditedBalanceForBusinessDate(balanceId, businessDate);
//        assertSame(tb, fromCache);
//        assertTrue(fromCache.getQuantity() == 12.5);
//        fromCache = findNonAuditedBalanceForBusinessDate(balanceId, InfinityTimestamp.getParaInfinity());
//        assertTrue(fromCache.getQuantity() == 12.5);
//        assertEquals(count, MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount());

        // test the database:

//        checker.checkDatedNonAuditedInfinityRow(balanceId, 12.5, businessDate);
    }
 
Example 20
Source File: TestDatedAuditOnly.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testInsertForRecoveryThenPurge() throws SQLException, ParseException
{
    int balanceId = 230;

    Timestamp fromProcessingDate = new Timestamp(timestampFormat.parse("2003-06-01 05:31:00").getTime());
    Timestamp queryProcessingDate = new Timestamp(timestampFormat.parse("2003-06-01 05:45:00").getTime());
    Timestamp toProcessingDate = new Timestamp(timestampFormat.parse("2003-06-01 06:11:00").getTime());

    AuditOnlyBalance testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
    assertNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
    assertNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
    assertNull(testQuery);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        AuditOnlyBalance recoveredBalance = new AuditOnlyBalance(fromProcessingDate);
        recoveredBalance.setAcmapCode("A");
        recoveredBalance.setBalanceId(balanceId);
        recoveredBalance.setInterest(10000);
        recoveredBalance.setQuantity(20000);
        recoveredBalance.setProcessingDateFrom(fromProcessingDate);
        recoveredBalance.setProcessingDateTo(toProcessingDate);
        recoveredBalance.insertForRecovery();

        testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
        assertNotNull(testQuery);
        testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
        assertNotNull(testQuery);
        testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
        assertNull(testQuery);

        recoveredBalance.purge();

        testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
        assertNull(testQuery);
        testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
        assertNull(testQuery);
        testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
        assertNull(testQuery);

        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    testQuery = this.getBalanceForTime(balanceId, queryProcessingDate);
    assertNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, fromProcessingDate);
    assertNull(testQuery);
    testQuery = this.getBalanceForTime(balanceId, toProcessingDate);
    assertNull(testQuery);

    // test the database:
    assertEquals(0, this.checker.checkDatedAuditOnlyRowCounts(balanceId));
}