com.gs.fw.common.mithra.MithraManager Java Examples

The following examples show how to use com.gs.fw.common.mithra.MithraManager. 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: TestDb2GeneralTestCases.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void xtestDeadConnectionInTransaction() throws Exception
{
    final Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    // put a break point on the next line, and kill the connection
    System.out.println("kill the connection now!");
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand()
    {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            order.getItems().forceResolve();
            // for a second test, put a break point on the next line and kill the connection
            order.getOrderStatus();
            return null;
        }
    });
}
 
Example #2
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 #3
Source File: TestSimulatedSequence.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testInsertDatedWithDecrementingSequence()
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    Timestamp businessDate = new Timestamp(System.currentTimeMillis());
    DatedWithDescendingSequence balance0 = new DatedWithDescendingSequence(businessDate, InfinityTimestamp.getParaInfinity());
    balance0.setAcmapCode("A");
    balance0.setQuantity(10.0);
    long balanceId0 = balance0.generateAndSetBalanceId();
    balance0.insert();
    assertEquals(1000, balanceId0);

    DatedWithDescendingSequence balance1 = new DatedWithDescendingSequence(businessDate, InfinityTimestamp.getParaInfinity());
    balance1.setAcmapCode("A");
    balance1.setQuantity(10.0);
    long balanceId1 = balance1.generateAndSetBalanceId();
    balance1.insert();
    assertEquals(999, balanceId1);
    tx.commit();

}
 
Example #4
Source File: TestIdentityTable.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testBatchDeleteFromIdentityTable() throws SQLException
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    
    IdentityTableList list = new IdentityTableList();
    for (int i=0; i< TIMES_REPEAT; i++)
    {
        IdentityTable it = this.createNewIdentityTableWithDescription("TEST ROW " + i, i);
        list.add(it);                        
    }
    list.insertAll();

    new IdentityTableList(IdentityTableFinder.all()).deleteAll();
    
    tx.commit();

    assertEquals("Batch delete failed", 0, new IdentityTableList(IdentityTableFinder.all()).size());
}
 
Example #5
Source File: TestIdentityTable.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testMultiUpdateToIdentityTable() throws SQLException
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    
    IdentityTableList list = new IdentityTableList(IdentityTableFinder.all());
    for (int i=0; i< list.size(); i++)
    {
        list.setDescription("UPDATED DESCRIPTION");
    }

    tx.commit();

    list = new IdentityTableList(IdentityTableFinder.all());
    for (IdentityTable it : list)
    {
        assertEquals("Batch update failed", "UPDATED DESCRIPTION", it.getDescription());
    }
}
 
Example #6
Source File: TestIdentityTable.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testBatchUpdateToIdentityTable() throws SQLException
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();

    IdentityTableList list = new IdentityTableList(IdentityTableFinder.all());
    list.setOrderBy(IdentityTableFinder.objectId().ascendingOrderBy());
    for (int i=0; i<list.size(); i++)
    {
        list.get(i).setDescription("TEST ROW " + i);
    }
    
    tx.commit();
    
    list = new IdentityTableList(IdentityTableFinder.all());
    list.setOrderBy(IdentityTableFinder.objectId().ascendingOrderBy());
    for (int i=0; i<list.size(); i++)
    {
        assertTrue("Update failed", list.get(i).getDescription().equals("TEST ROW " + i));
    }
}
 
Example #7
Source File: TestMaxFromTable.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testInsertListWithNoSourceAttribute()
{
    DbsTestEntityList list = new DbsTestEntityList();
    DbsTestEntity entity = null;
    for(int i = 0; i < 10; i++)
    {
        entity = new DbsTestEntity();
        entity.setDescription("DbsTestEntity"+i);
        entity.setName("DbsTestEntity"+i);
        entity.setAccountId("ParaTamsAccount "+i);
        entity.setGroupId(1000+i);
        list.add(entity);
    }
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    list.insertAll();
    tx.commit();
    for(int i = 0; i < list.size(); i++)
    {
        assertTrue(list.getDbsTestEntityAt(i).getId() > 0 && list.getDbsTestEntityAt(i).getId() < 11 );
    }
}
 
Example #8
Source File: TestPostgresGeneralTestCases.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void xtestDeadConnectionInTransaction() throws Exception
{
    final Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    // put a break point on the next line, and kill the connection
    System.out.println("kill the connection now!");
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand()
    {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            order.getItems().forceResolve();
            // for a second test, put a break point on the next line and kill the connection
            order.getOrderStatus();
            return null;
        }
    });
}
 
Example #9
Source File: HelloReladomoApp.java    From reladomo with Apache License 2.0 6 votes vote down vote up
private void initialiseReladomo() throws Exception
{
    try
    {
        logger.info("Transaction Timeout is " + MAX_TRANSACTION_TIMEOUT);
        MithraManager mithraManager = MithraManagerProvider.getMithraManager();
        mithraManager.setTransactionTimeout(MAX_TRANSACTION_TIMEOUT);
        // Notification should be configured here. Refer to notification/Notification.html under reladomo-javadoc.jar.
    }
    catch (Exception e)
    {
        logger.error("Unable to initialise Reladomo!", e);
        throw new Exception("Unable to initialise Reladomo!", e);
    }
    logger.info("Reladomo has been initialised!");
}
 
Example #10
Source File: OutgoingAsyncTopicTest.java    From reladomo with Apache License 2.0 6 votes vote down vote up
protected void setupMithra()
{
    final MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    final String mithraRuntimeConfig = "ReladomoJmsTestConfig.xml";
    System.setProperty("h2.additionalArguments", ";MVCC=TRUE");
    mithraTestResource = new MithraTestResource(mithraRuntimeConfig);
    ConnectionManagerForTests connectionManagerForTestTradeDb = ConnectionManagerForTests.getInstance("test_trade_db");
    mithraTestResource.createSingleDatabase(connectionManagerForTestTradeDb);

    this.mithraTestResource.setUp();

    multiThreadedTm = new MultiThreadedTm();
    mithraManager.setJtaTransactionManagerProvider(new JtaProvider()
    {
        @Override
        public TransactionManager getJtaTransactionManager()
        {
            return multiThreadedTm;
        }
    });
    mithraManager.setTransactionTimeout(180); // short timeout for testing topic processor
}
 
Example #11
Source File: ExercisesCrud.java    From reladomo-kata with Apache License 2.0 6 votes vote down vote up
@Test
public void testQ5()
{
    IntSet testIds = IntSets.immutable.of(1, 2);
    CustomerList customers = new CustomerList(CustomerFinder.customerId().in(testIds));
    this.updateCountry(customers, "UK");

    MithraManager.getInstance().clearAllQueryCaches();
    Customer c1 = CustomerFinder.findOne(CustomerFinder.customerId().eq(1));
    Customer c2 = CustomerFinder.findOne(CustomerFinder.customerId().eq(2));

    //check that the two got updated
    Assert.assertEquals("UK", c1.getCountry());
    Assert.assertEquals("UK", c2.getCountry());

    //check that nobody else got updated.
    Verify.assertSize(2, new CustomerList(CustomerFinder.country().eq("UK")));
    Verify.assertSize(3, new CustomerList(CustomerFinder.country().notEq("UK")));
}
 
Example #12
Source File: CustomerResource.java    From reladomo-kata with Apache License 2.0 6 votes vote down vote up
@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
public Response updateCustomer(@PathParam("id") int customerId, Serialized<Customer> serialized)
{
    Customer customerPojo = serialized.getWrapped();
    MithraManager.getInstance().executeTransactionalCommand((tx) -> {
        //locate the customer
        Customer customer = CustomerFinder.findOne(CustomerFinder.customerId().eq(customerId));
        //update names
        customer.setFirstName(customerPojo.getFirstName());
        customer.setLastName(customerPojo.getLastName());
        //delete existing accounts and replace with new accounts
        customer.getAccounts().deleteAll();
        customer.getAccounts().addAll(customerPojo.getAccounts());
        return null;
    });
    return Response.ok().build();
}
 
Example #13
Source File: TestNullRetrieval.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void testDatedObjectDefaultValueForNullAfterInsert()
{
    final TestPositionPrice price  = new TestPositionPrice(new Timestamp(System.currentTimeMillis()));
    price.setAcmapCode("A");
    price.setAccountId("123456789");
    price.setProductId(1);
    price.setCurrency("USD");
    price.setPositionType(1);
    price.setBalanceType(1);
    price.setPriceTypeNull();
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand()
    {

        @Override
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            price.insert();
            return null;
        }
    });
    assertEquals(17, price.getPriceType());
}
 
Example #14
Source File: TestMariaGeneralTestCases.java    From reladomo with Apache License 2.0 6 votes vote down vote up
public void xtestDeadConnectionInTransaction() throws Exception
{
    final Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    // put a break point on the next line, and kill the connection
    System.out.println("kill the connection now!");
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand()
    {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            order.getItems().forceResolve();
            // for a second test, put a break point on the next line and kill the connection
            order.getOrderStatus();
            return null;
        }
    });
}
 
Example #15
Source File: TestOracleGeneralTestCases.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void xtestDeadConnectionInTransaction() throws Exception
{
    final Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    // put a break point on the next line, and kill the connection
    System.out.println("kill the connection now!");
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand() {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            order.getItems().forceResolve();
            // for a second test, put a break point on the next line and kill the connection
            order.getOrderStatus();
            return null;
        }
    });
}
 
Example #16
Source File: TestMaxFromTable.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testInsertObjectWithNoSourceAttribute()
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    DbsTestEntity dbsTestEntity = new DbsTestEntity();
    int id = dbsTestEntity.generateAndSetId();
    dbsTestEntity.setDescription("DbsTestEntity"+id);
    dbsTestEntity.setName("DbsTestEntity");
    dbsTestEntity.setAccountId("ParaTamsAccount "+id);
    dbsTestEntity.setGroupId(1234);
    tx.commit();
    assertEquals(1, id);
}
 
Example #17
Source File: TestNullRetrieval.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testDatedObjectDefaultValueForNullAfterInsertWithFind()
{
    final TestPositionPrice price  = new TestPositionPrice(new Timestamp(System.currentTimeMillis()));
    price.setAcmapCode("A");
    price.setAccountId("123456789");
    price.setProductId(1);
    price.setCurrency("USD");
    price.setPositionType(1);
    price.setBalanceType(1);
    price.setPriceTypeNull();
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand()
    {

        @Override
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            price.insert();
            return null;
        }
    });

    TestPositionPrice result = TestPositionPriceFinder.findOne(TestPositionPriceFinder.acmapCode().eq("A")
                                                                       .and(TestPositionPriceFinder.productId().eq(1))
                                                                       .and(TestPositionPriceFinder.accountId().eq("123456789"))
                                                                       .and(TestPositionPriceFinder.businessDate().equalsEdgePoint()));

    assertEquals(17, result.getPriceType());
}
 
Example #18
Source File: MithraTestApp.java    From reladomo with Apache License 2.0 5 votes vote down vote up
private void initialiseMithra() throws Exception
{
    try
    {
        logger.info("Transaction Timeout is " + this.getMaxTransactionTimeout());
        MithraManager mithraManager = MithraManagerProvider.getMithraManager();
        mithraManager.setTransactionTimeout(this.getMaxTransactionTimeout());
    }
    catch (Exception e)
    {
        logger.error("Unable to initialise Mithra!", e);
        throw new Exception("Unable to initialise Mithra!", e);
    }
    logger.info("Mithra has been initialised!");
}
 
Example #19
Source File: CommonVendorTestCases.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testRollback()
{
    final List<Exception> exceptionsList = FastList.newList();
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand<Object>()
    {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            TemporaryContext temporaryContext = OrderDriverFinder.createTemporaryContext();

            try
            {
                Order order = new Order();
                order.setOrderId(1000);
                order.insert();
                if (exceptionsList.isEmpty())
                {
                    MithraBusinessException exception = new MithraBusinessException("Exception");
                    exception.setRetriable(true);
                    exceptionsList.add(exception);
                    throw exception;
                }
                return null;
            }
            finally
            {
                temporaryContext.destroy();
            }
        }
    }, 5);
    assertNotNull(OrderFinder.findOne(OrderFinder.orderId().eq(1000)));
}
 
Example #20
Source File: TestMsSqlGeneralTestCases.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void xtestDeadConnectionInTransaction() throws Exception
{
    final Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    // put a break point on the next line, and kill the connection
    System.out.println("kill the connection now!");
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand() {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            order.getItems().forceResolve();
            // for a second test, put a break point on the next line and kill the connection
            order.getOrderStatus();
            return null;
        }
    });
}
 
Example #21
Source File: TestSybaseGeneralTestCases.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void xtestDeadConnectionInTransaction() throws Exception
{
    final Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    // put a break point on the next line, and kill the connection
    System.out.println("kill the connection now!");
    MithraManager.getInstance().executeTransactionalCommand(new TransactionalCommand() {
        public Object executeTransaction(MithraTransaction tx) throws Throwable
        {
            order.getItems().forceResolve();
            // for a second test, put a break point on the next line and kill the connection
            order.getOrderStatus();
            return null;
        }
    });
}
 
Example #22
Source File: TestInMemoryNonTransactionalObjects.java    From reladomo with Apache License 2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception
{
    if (this.mithraTransaction != null)
    {
        MithraManager.getInstance().removeTransaction(this.mithraTransaction);
        this.mithraTransaction = null;
    }
    super.tearDown();
}
 
Example #23
Source File: TestTransactionalObject.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testQueryInsideTransaction()
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    Order order = OrderFinder.findOne(OrderFinder.orderId().eq(1));
    assertTrue(order.zIsParticipatingInTransaction(tx));
    assertEquals(1, order.getOrderId());
    tx.commit();
    assertNotNull(order);
    assertEquals(1, order.getOrderId());
    MithraPerformanceData data = OrderFinder.getMithraObjectPortal().getPerformanceData();
    assertTrue(data.getDataForFind().getTotalObjects() > 0);
}
 
Example #24
Source File: TestMaxFromTable.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testInsertingDatedObject()
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    Timestamp businessDate = new Timestamp(System.currentTimeMillis());
    DatedWithMax balance = new DatedWithMax(businessDate, InfinityTimestamp.getParaInfinity());
    balance.setAcmapCode("A");
    balance.setQuantity(10.0);
    long balanceId = balance.generateAndSetBalanceId();
    balance.insert();
    assertEquals(1, balanceId);
    tx.commit();

}
 
Example #25
Source File: TestTablePartitionManager.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testExpectedTablesAreCreated() throws Exception
{
    Set<String> createdTables = ConnectionManagerForTestsWithTableManager.getInstance().getCreatedTables();

    UnifiedSet<String> expectedTables = UnifiedSet.newSet();

    for(MithraRuntimeCacheController controller : MithraManager.getInstance().getConfigManager().getRuntimeCacheControllerSet())
    {
        String table = controller.getFinderInstanceFromFinderClass().getMithraObjectPortal().getDatabaseObject().getDefaultTableName();

        if(controller.getFinderInstanceFromFinderClass().getSourceAttributeType() == null )
        {
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table));
        }
        else if(controller.getFinderInstanceFromFinderClass().getSourceAttributeType().isIntSourceAttribute())
        {
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, 0));
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, 1));
        }
        else
        {
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, "A"));
            expectedTables.add(ConnectionManagerForTestsWithTableManager.getInstance().getTableName(table, "B"));
        }
    }

    assertEquals( expectedTables, createdTables );
}
 
Example #26
Source File: RemoteMithraServerTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception
{
    super.setUp();
    MultiVmTestMithraRemoteServerFactory.setPort(this.getApplicationPort1());
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.readConfiguration(this.getConfigXml("MithraConfigClientCache.xml"));
}
 
Example #27
Source File: SimpleBankServer.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
protected void initReladomo(String runtimeConfigXML) throws Exception
{
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.setTransactionTimeout(60 * 1000);
    InputStream stream = loadReladomoXMLFromClasspath(runtimeConfigXML);
    MithraManagerProvider.getMithraManager().readConfiguration(stream);
    stream.close();
}
 
Example #28
Source File: SimpleBankApp.java    From reladomo-kata with Apache License 2.0 5 votes vote down vote up
private void initReladomo() throws Exception
{
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.setTransactionTimeout(60 * 1000);
    InputStream stream = loadReladomoXMLFromClasspath("SimpleBankRuntimeConfiguration.xml");
    MithraManagerProvider.getMithraManager().readConfiguration(stream);
    stream.close();
}
 
Example #29
Source File: ReladomoApplication.java    From tutorials with MIT License 5 votes vote down vote up
public static void main(String[] args) {

        try {
            ReladomoConnectionManager.getInstance().createTables();
        } catch (Exception e1) {
            e1.printStackTrace();
        }

        MithraManager mithraManager = MithraManagerProvider.getMithraManager();
        mithraManager.setTransactionTimeout(120);

        try (InputStream is = ReladomoApplication.class.getClassLoader().getResourceAsStream("ReladomoRuntimeConfig.xml")) {
            MithraManagerProvider.getMithraManager().readConfiguration(is);

            Department department = new Department(1, "IT");
            Employee employee = new Employee(1, "John");
            department.getEmployees().add(employee);
            department.cascadeInsert();

            Department depFound = DepartmentFinder.findByPrimaryKey(1);
            System.out.println("Department Name:" + department.getName());

            Employee empFound = EmployeeFinder.findOne(EmployeeFinder.name().eq("John"));
            System.out.println("Employee Id:" + empFound.getId());
            empFound.setName("Steven");
            empFound.delete();
            Department depDetached = DepartmentFinder.findByPrimaryKey(1).getDetachedCopy();

            mithraManager.executeTransactionalCommand(tx -> {
                Department dep = new Department(2, "HR");
                Employee emp = new Employee(2, "Jim");
                dep.getEmployees().add(emp);
                dep.cascadeInsert();
                return null;
            });
            
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
 
Example #30
Source File: TestIdentityTable.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testOneRowDeleteFromIdentityTable() throws SQLException
{
    MithraTransaction tx = MithraManager.getInstance().startOrContinueTransaction();
    IdentityTableList list = new IdentityTableList(IdentityTableFinder.all());
    list.get(0).delete();        
    tx.commit();

    assertEquals("Delete failed", 2, new IdentityTableList(IdentityTableFinder.all()).size());
}