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

The following examples show how to use com.gs.fw.common.mithra.MithraTransaction#commit() . 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: TestSimulatedSequence.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testTransactionRollback()
{
    AccountTransaction accountTransaction0 = new AccountTransaction();

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

    accountTransaction0.setDeskId("A");
    accountTransaction0.setTransactionDescription("Account Transaction 0");
    accountTransaction0.setTransactionDate(new Timestamp(System.currentTimeMillis()));
    int accountTransactionId = accountTransaction0.generateAndSetTransactionId();
    accountTransaction0.insert();

    tx.rollback();
    assertTrue(accountTransactionId != accountTransaction0.getTransactionId());

    tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    accountTransaction0.setDeskId("A");
    accountTransaction0.setTransactionDescription("Account Transaction 0");
    accountTransaction0.setTransactionDate(new Timestamp(System.currentTimeMillis()));
    accountTransaction0.insert();
    tx.commit();
    assertEquals(1002, accountTransaction0.getTransactionId());
}
 
Example 2
Source File: TestTransactionalObject.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testInsertAndUpdateInTransaction() throws SQLException
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    Order order = new Order();
    int orderId = 1017;
    order.setOrderId(orderId);
    Timestamp orderDate = new Timestamp(System.currentTimeMillis());
    order.setOrderDate(orderDate);
    String description = "new order description";
    order.setDescription(description);
    order.insert();

    order.setUserId(17);
    tx.commit();
    checkUserId(17, orderId);
}
 
Example 3
Source File: TestDatedNonAudited.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testInsertThenUpdate()
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    NonAuditedBalanceInterface inserted = null;
    try
    {
        inserted = buildNonAuditedBalance(createTimestamp(tx));
        inserted.setAcmapCode("A");
        inserted.setBalanceId(1234);
        inserted.setQuantity(10);
        inserted.setBusinessDateFrom(new Timestamp(200000000));
        inserted.setBusinessDateTo(this.getInifinity());
        inserted.insert();

        NonAuditedBalanceInterface updated = findNonAuditedBalanceForBusinessDate(1234, createTimestamp(tx));
        updated.setQuantity(20);
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
}
 
Example 4
Source File: TestTransactionalList.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testTransactionalParticipation()
{
    OrderList firstList = new OrderList(OrderFinder.userId().eq(1));
    firstList.forceResolve();
    int originalSize = firstList.size();
    assertTrue(originalSize > 0);
    assertFalse(firstList.isStale());
    Order order = firstList.getOrderAt(0);
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    order.setUserId(order.getUserId()+1000);
    firstList.forceResolve();
    assertTrue(firstList.size() < originalSize); // testing that list was refreshed in transaction
    for(int i=0;i<firstList.size();i++)
    {
        assertTrue(firstList.getOrderAt(i).zIsParticipatingInTransaction(MithraManagerProvider.getMithraManager().getCurrentTransaction()));
    }
    tx.commit();
}
 
Example 5
Source File: TestCopyTransactionalObjectAttributes.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testCopyNonPrimaryKeyAttributesFromInMemoryObjectInTx()
throws Exception
{
    Order newOrder = new Order();
    newOrder.setOrderDate(new Timestamp(System.currentTimeMillis()));
    newOrder.setState("NEW");
    newOrder.setDescription("New Order");
    newOrder.setTrackingId("Tracking Id");
    newOrder.setUserId(9876);
    newOrder.setOrderId(1);

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

    Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    order.copyNonPrimaryKeyAttributesFrom(newOrder);
    tx.commit();
    assertTrue(compareOrderNonPrimaryKeyAttributes(order, newOrder));
}
 
Example 6
Source File: TestTransactionalList.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testPurgeAllAuditOnly()
{
    AuditOnlyBalanceList auditOnlyList = this.getPurgeAllAuditOnlyList(2);

    assertTrue(auditOnlyList.size() > 0);

    //begin transaction
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    auditOnlyList = this.getPurgeAllAuditOnlyList(2);

    auditOnlyList.purgeAll();

    AuditOnlyBalanceList auditOnlyListCheck = this.getPurgeAllAuditOnlyList(2);
    assertEquals(0, auditOnlyListCheck.size());

    tx.commit();
    //end transaction

    auditOnlyListCheck = this.getPurgeAllAuditOnlyList(2);
    assertEquals(0, auditOnlyListCheck.size());
}
 
Example 7
Source File: TestCopyTransactionalObjectAttributes.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testCopyNonPrimaryKeyAttributesFromInMemoryObjectInTx2()
throws Exception
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    Order newOrder = new Order();
    newOrder.setOrderDate(new Timestamp(System.currentTimeMillis()));
    newOrder.setState("NEW");
    newOrder.setDescription("New Order");
    newOrder.setTrackingId("Tracking Id");
    newOrder.setUserId(9876);
    newOrder.setOrderId(1);
    Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    order.copyNonPrimaryKeyAttributesFrom(newOrder);

    tx.commit();
    assertTrue(compareOrderNonPrimaryKeyAttributes(order, newOrder));
}
 
Example 8
Source File: TestPeerToPeerMithraTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void serverUpdateTinyBalance(String sourceAttribute, int balanceId, Timestamp businessDate, double newQuantity)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    TinyBalance tinyBalance = TinyBalanceFinder.findOne(TinyBalanceFinder.acmapCode().eq(sourceAttribute).and(TinyBalanceFinder.balanceId().eq(balanceId).and(TinyBalanceFinder.businessDate().eq(businessDate).and(TinyBalanceFinder.processingDate().eq(InfinityTimestamp.getParaInfinity())))));
    tinyBalance.setQuantity(newQuantity);
    tx.commit();
}
 
Example 9
Source File: TestDetached.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testDetachDeleteResetInTransactionWithCommit()
{
    Order originalOrder = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    Order order = originalOrder.getDetachedCopy();
    order.delete();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    order.resetFromOriginalPersistentObject();
    tx.commit();
    assertEquals(originalOrder.getDescription(), order.getDescription());
}
 
Example 10
Source File: TestNotificationMessages.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void serverIncrementUntilTinyBalance(String sourceAttribute, int balanceId, Timestamp businessDate, double newQuantity, Timestamp untilTimestamp)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    TinyBalance tinyBalance = TinyBalanceFinder.findOne(TinyBalanceFinder.acmapCode().eq(sourceAttribute).and(TinyBalanceFinder.balanceId().eq(balanceId).and(TinyBalanceFinder.businessDate().eq(businessDate).and(TinyBalanceFinder.processingDate().eq(InfinityTimestamp.getParaInfinity())))));
    tinyBalance.incrementQuantityUntil(newQuantity, untilTimestamp);
    tx.commit();
}
 
Example 11
Source File: TestDetached.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testIsModifiedByAttributeInTransactionWithCommit()
{
    Order originalOrder = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    Order order = originalOrder.getDetachedCopy();
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    order.setDescription("test 1900");
    order.setUserIdNull();
    assertTrue(order.isModifiedSinceDetachment(OrderFinder.description()));
    assertTrue(order.isModifiedSinceDetachment(OrderFinder.userId()));
    tx.commit();
    assertTrue(order.isModifiedSinceDetachment(OrderFinder.description()));
    assertTrue(order.isModifiedSinceDetachment(OrderFinder.userId()));
}
 
Example 12
Source File: TestMultiClientNotificationTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void remoteUpdateTinyBalance(String sourceAttribute, int balanceId, Timestamp businessDate, double newQuantity)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    TinyBalance tinyBalance = TinyBalanceFinder.findOne(TinyBalanceFinder.acmapCode().eq(sourceAttribute).and(TinyBalanceFinder.balanceId().eq(balanceId).and(TinyBalanceFinder.businessDate().eq(businessDate).and(TinyBalanceFinder.processingDate().eq(InfinityTimestamp.getParaInfinity())))));
    tinyBalance.setQuantity(newQuantity);
    tx.commit();
}
 
Example 13
Source File: TestDatedBitemporalOptimisticLocking.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testSetNullAndBack() throws Exception
{
    Timestamp businessDate = new Timestamp(timestampFormat.parse("2002-11-29 00:00:00").getTime());
    int balanceId = 1;
    TinyBalance tb = null;
    tb = findTinyBalanceForBusinessDate(balanceId, businessDate);
    assertNotNull(tb);
    double oldValue = -1;
    MithraTransaction tx = startOptimisticTransaction();
    try
    {
        oldValue = tb.getQuantity();
        TinyBalance copy = tb.getNonPersistentCopy();
        copy.setQuantityNull();
        copy.setQuantity(oldValue);
        tb.copyNonPrimaryKeyAttributesFrom((TinyBalanceAbstract)copy);
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    assertEquals(oldValue, tb.getQuantity(), 0.0);
    TinyBalanceFinder.clearQueryCache();
    tb = findTinyBalanceForBusinessDate(balanceId, businessDate);
    assertEquals(oldValue, tb.getQuantity(), 0.0);
    // test the database:

    this.checker.checkDatedBitemporalInfinityRow(balanceId, oldValue, businessDate);
}
 
Example 14
Source File: TestConnectionManager.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testCommitWithTransaction() throws Exception
{
    MithraTransaction mt = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    String testName = "test";
    Connection connection = getConnection();
    updateUserName(testName, connection);
    connection.close();
    mt.commit();
    assertEquals(getUserName(), testName);
    assertNull(MithraManagerProvider.getMithraManager().getCurrentTransaction());
}
 
Example 15
Source File: TestPeerToPeerMithraTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void serverIncrementUntilTinyBalance(String sourceAttribute, int balanceId, Timestamp businessDate, double newQuantity, Timestamp untilTimestamp)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    TinyBalance tinyBalance = TinyBalanceFinder.findOne(TinyBalanceFinder.acmapCode().eq(sourceAttribute).and(TinyBalanceFinder.balanceId().eq(balanceId).and(TinyBalanceFinder.businessDate().eq(businessDate).and(TinyBalanceFinder.processingDate().eq(InfinityTimestamp.getParaInfinity())))));
    tinyBalance.incrementQuantityUntil(newQuantity, untilTimestamp);
    tx.commit();
}
 
Example 16
Source File: TestDatedNonAudited.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testPurgeAfterMultipleUpdateInsertOperations() throws SQLException, ParseException
{
    int balanceId = 50;

    Timestamp currentBusinessDate = new Timestamp(System.currentTimeMillis());
    Timestamp pastBusinessDate = new Timestamp(timestampFormat.parse("2003-06-01 00:00:00").getTime());
    Timestamp fartherPastBusinessDate = new Timestamp(timestampFormat.parse("2002-06-01 00:00:00").getTime());

    NonAuditedBalanceInterface currentBalance = findNonAuditedBalanceForBusinessDate(balanceId, currentBusinessDate);
    assertNotNull(currentBalance);
    NonAuditedBalanceInterface pastBalance = findNonAuditedBalanceForBusinessDate(balanceId, pastBusinessDate);
    assertNotNull(pastBalance);
    NonAuditedBalanceInterface fartherPastBalance = findNonAuditedBalanceForBusinessDate(balanceId, fartherPastBusinessDate);
    assertNotNull(fartherPastBalance);

    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        pastBalance.incrementInterest(1000);

        Timestamp businessDateTo = new Timestamp(timestampFormat.parse("2002-06-02 00:00:00").getTime());
        NonAuditedBalanceInterface newBalance = buildNonAuditedBalance(fartherPastBusinessDate);
        newBalance.setBalanceId(balanceId);
        newBalance.setBusinessDateTo(businessDateTo);
        newBalance.setAcmapCode("A");
        newBalance.setQuantity(-9999);
        newBalance.setInterest(-5555);
        newBalance.insert();

        newBalance.incrementInterest(100);

        currentBalance.purge();
        assertTrue(currentBalance.zIsParticipatingInTransaction(tx));
        this.checkQuantityThrowsException(pastBalance);

        currentBalance = findNonAuditedBalanceForBusinessDate(balanceId, currentBusinessDate);
        assertNull(currentBalance);
        pastBalance = findNonAuditedBalanceForBusinessDate(balanceId, pastBusinessDate);
        assertNull(pastBalance);
        tx.commit();
    }
    catch(Throwable t)
    {
        getLogger().error("transaction failed", t);
        tx.rollback();
        fail("transaction failed see exception");
    }
    // check the cache:
    currentBalance = findNonAuditedBalanceForBusinessDate(balanceId, currentBusinessDate);
    assertNull(currentBalance);
    pastBalance = findNonAuditedBalanceForBusinessDate(balanceId, pastBusinessDate);
    assertNull(pastBalance);
    fartherPastBalance = findNonAuditedBalanceForBusinessDate(balanceId, fartherPastBusinessDate);
    assertNull(fartherPastBalance);
    // test the database:
    assertEquals(0, this.checker.checkDatedNonAuditedRowCounts(balanceId));
}
 
Example 17
Source File: TestParaDatedBitemporal.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testInsertWithIncrementTwiceTodayYesterday() throws SQLException
{
    ParaBalance tb = null;
    int balanceId = 4030;
    java.util.Date paraBusinessDate = createParaBusinessDate(new java.util.Date());
    Timestamp businessDate = new Timestamp(paraBusinessDate.getTime()+24*3600000);
    Timestamp lbd = new Timestamp(paraBusinessDate.getTime());
    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.insertWithIncrement();

        ParaBalance lbdBalance = findParaBalanceForBusinessDate(balanceId, lbd);
        assertNull(lbdBalance);
        lbdBalance = new ParaBalance(lbd, InfinityTimestamp.getParaInfinity());
        lbdBalance.setAcmapCode("A");
        lbdBalance.setBalanceId(balanceId);
        lbdBalance.setQuantity(1000);
        lbdBalance.insertWithIncrement();
        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 18
Source File: TestNotificationMessages.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void serverTerminateAuditedOrderItem(int orderItemId)
{
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    AuditedOrderItemFinder.findOne(AuditedOrderItemFinder.id().eq(orderItemId)).terminate();
    tx.commit();
}
 
Example 19
Source File: SingleQueueExecutorTest.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testWithCorruptedOptimisticLock() throws Exception
{
    Timestamp businessDate = new Timestamp(timestampFormat.parse("2004-08-27 23:59:00.0").getTime());


    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    TinyBalance bal = new TinyBalance(businessDate);
    bal.setAcmapCode ("B");
    bal.setBalanceId (8866);
    bal.setQuantity (30);
    bal.setBusinessDateFrom (Timestamp.valueOf("2004-08-25 23:59:00.0"));
    bal.setBusinessDateTo (Timestamp.valueOf("2004-08-28 23:59:00.0"));
    bal.insert ();
    tx.commit ();

    tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    bal = new TinyBalance(businessDate);
    bal.setAcmapCode ("B");
    bal.setBalanceId (8866);
    bal.setQuantity (700);
    bal.setBusinessDateFrom (Timestamp.valueOf("2004-08-16 23:59:00.0"));
    bal.setBusinessDateTo (Timestamp.valueOf("2004-10-13 23:59:00.0"));
    bal.insert ();
    tx.commit ();


    Operation op = TinyBalanceFinder.acmapCode ().eq("B").and(TinyBalanceFinder.balanceId ().eq(8866)).
            and(TinyBalanceFinder.businessDate().eq(businessDate));
    TinyBalance tinyBalanceDB = TinyBalanceFinder.findOne(op);

    SingleQueueExecutor executor = new SingleQueueExecutor(1, TinyBalanceFinder.balanceId ().ascendingOrderBy(), 10,
            TinyBalanceFinder.getFinderInstance(), 0);

    executor.setUseBulkInsert();

    op = TinyBalanceFinder.acmapCode ().eq("B").and(TinyBalanceFinder.balanceId ().eq(8866)).
            and(TinyBalanceFinder.businessDate().eq(businessDate));
    tinyBalanceDB = TinyBalanceFinder.findOne(op);

    TinyBalance tinyBalance = new TinyBalance(InfinityTimestamp.getParaInfinity());

    executor.addForUpdate(tinyBalanceDB, tinyBalance);
    try
    {
        executor.waitUntilFinished ();
        fail("exception expected");
    } catch (Exception e)
    {
        assertTrue(e.getMessage (), e.getMessage ().contains("Primary Key: acmapCode: 'B' / balanceId: 8866"));
    }

}
 
Example 20
Source File: TestParaDatedBitemporal.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void testInsertThenSetUntilLaterDay() throws SQLException
{
    ParaBalance tb = null;
    int balanceId = 4600;
    java.util.Date paraBusinessDate = createParaBusinessDate(new java.util.Date());
    Timestamp businessDate = addDaysAsTimestamp(paraBusinessDate, 1);
    Timestamp tomorrow = addDaysAsTimestamp(paraBusinessDate, 2);
    Timestamp lbd = new Timestamp(paraBusinessDate.getTime());
    MithraTransaction tx = MithraManagerProvider.getMithraManager().startOrContinueTransaction();
    try
    {
        ParaBalance lbdBalance = findParaBalanceForBusinessDate(balanceId, lbd);
        assertNull(lbdBalance);
        lbdBalance = new ParaBalance(lbd, InfinityTimestamp.getParaInfinity());
        lbdBalance.setAcmapCode("A");
        lbdBalance.setBalanceId(balanceId);
        lbdBalance.setQuantity(1000);
        lbdBalance.insertWithIncrement();

        tb = findParaBalanceForBusinessDate(balanceId, businessDate);
        assertNotNull(tb);
        tb.setQuantityUntil(12.5, tomorrow);

        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(12.5, tb.getQuantity(), 0);
    fromCache = findParaBalanceForBusinessDate(balanceId, InfinityTimestamp.getParaInfinity());
    assertEquals(1000, fromCache.getQuantity(), 0);
    assertEquals(count, MithraManagerProvider.getMithraManager().getDatabaseRetrieveCount());
    tb = null;
    ParaBalanceFinder.clearQueryCache();
    fromCache = findParaBalanceForBusinessDate(balanceId, lbd);
    assertNotNull(fromCache);
    assertEquals(1000, fromCache.getQuantity(), 0);
    fromCache = findParaBalanceForBusinessDate(balanceId, businessDate);
    assertNotNull(fromCache);
    assertEquals(12.5, fromCache.getQuantity(), 0);
    fromCache = findParaBalanceForBusinessDate(balanceId, InfinityTimestamp.getParaInfinity());
    assertNotNull(fromCache);
    assertEquals(1000, fromCache.getQuantity(), 0);

    // test the database:
    checkParaInfinityRow(balanceId, 1000, businessDate);
}