Java Code Examples for com.gs.fw.common.mithra.MithraManagerProvider#getMithraManager()

The following examples show how to use com.gs.fw.common.mithra.MithraManagerProvider#getMithraManager() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
Source File: TestMithraTestResource.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testReadConfigurationWithTablePartitionManager() throws Exception
{
    MithraManager mithra = MithraManagerProvider.getMithraManager();
    mithra.readConfiguration(getConfigXml("MithraTestTableManagerConfig.xml"));
    mithra.fullyInitialize();
    mithra.cleanUpPrimaryKeyGenerators();
    mithra.cleanUpRuntimeCacheControllers();
}
 
Example 9
Source File: TestMithraTestResource.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void testReadConfiguration() throws Exception
{
    MithraManager mithra = MithraManagerProvider.getMithraManager();
    mithra.readConfiguration(getConfigXml("MithraConfigPartialCache.xml"));
    OrderFinder.getMithraObjectPortal().getCache();
    mithra.cleanUpPrimaryKeyGenerators();
    mithra.cleanUpRuntimeCacheControllers();

}
 
Example 10
Source File: RemoteMithraClientTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void clientVmSetUp() throws Exception
{
    MultiVmTestMithraRemoteServerFactory.setPort(this.getApplicationPort1());
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.setNotificationEventManager(this.createNotificationEventManager());
    mithraManager.readConfiguration(this.getConfigXml("MithraConfigClientCache.xml"));
}
 
Example 11
Source File: CacheReplicationTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception
{
    super.setUp();
    StringPool.getInstance().enableOffHeapSupport();
    StringPool.getInstance().getOrAddToCache("some weird string 1", true);
    StringPool.getInstance().getOrAddToCache("some weird string 2", true);
    StringPool.getInstance().getOrAddToCache("some weird string 3",true);
    PspBasedMithraMasterServerFactory.setPort(this.getApplicationPort1());
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.readConfiguration(this.getConfigXml("MithraConfigReplicantCache.xml"));
}
 
Example 12
Source File: PeerToPeerMithraServerTestCase.java    From reladomo with Apache License 2.0 5 votes vote down vote up
public void setUp() throws Exception
{
    MultiVmTestMithraRemoteServerFactory.setPort(this.getApplicationPort1());
    MithraManagerProvider.getMithraManager().setNotificationEventManager(this.createNotificationEventManager());
    String xmlFile = System.getProperty("mithra.xml.config");

    this.setDefaultServerTimezone();

    MithraTestResource mithraTestResource = new MithraTestResource(xmlFile);
    mithraTestResource.setRestrictedClassList(this.getRestrictedClassList());

    ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstance();
    connectionManager.setPeerToPeer(true);
    connectionManager.setDefaultSource("A");
    connectionManager.setDatabaseType(mithraTestResource.getDatabaseType());

    if (!connectionManager.hasConnectionManagerForSource("A"))
    {
        connectionManager.addConnectionManagerForSource("A");
    }
    if (!connectionManager.hasConnectionManagerForSource("B"))
    {
        connectionManager.addConnectionManagerForSource("B");
    }

    this.setDefaultServerTimezone();

    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.readConfiguration(this.getConfigXml(xmlFile));
}
 
Example 13
Source File: MithraTestResource.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void setUp()
{
    initializeRuntime();
    logger.debug(System.identityHashCode(this) + " MithraTestResource set up with: " + this.configFileName);
    MithraRuntimeConfig mithraRuntimeConfig;
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    configureTransactionManager(mithraManager);

    for (int i = 0; i < mithraRuntimeList.size(); i++)
    {
        mithraRuntimeConfig = mithraRuntimeList.get(i);
        MithraTestConnectionManager connectionManager = (MithraTestConnectionManager) mithraRuntimeConfig.getConnectionManager();
        if (connectionManager != null && !connectionManagersInUse.contains(connectionManager))
        {
            additionalConnectionManagersInUse.add(connectionManager);
        }
    }

    removeRestrictedClassesFromConfig();

    this.setUpDatabases();

    this.setUpPortals();

    try
    {
        if (this.restrictedClasses != null)
        {
            Set<String> notInUse = UnifiedSet.newSet();

            for (Iterator<MithraObjectPortal> it = portals.iterator(); it.hasNext(); )
            {
                String classname = getClassNameFromFinder(it.next().getFinder());
                if (!isUsed(classname))
                {
                    notInUse.add(classname);
                    it.remove();
                }
            }

            if(!notInUse.isEmpty())
            {
                mithraManager.cleanUpRuntimeCacheControllers(notInUse);
            }
        }
    }
    catch (Exception e)
    {
        logger.error("Exception during MithraTestResource setup", e);
        throw new RuntimeException("Exception during MithraTestResource setup", e);
    }
    for (Iterator<List<MithraObject>> it = this.testData.values().iterator(); it.hasNext(); )
    {
        this.insertTestData(it.next());
    }
    mithraManager.loadMithraCache(portals, 2);
    loadPureObjects();


    this.setSetUpCompleted(true);
}
 
Example 14
Source File: BitemporalBankServer.java    From reladomo-kata with Apache License 2.0 4 votes vote down vote up
protected void initReladomo(String runtimeConfigXML) throws Exception
{
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.setTransactionTimeout(60 * 1000);
    loadReladomoXML(runtimeConfigXML);
}
 
Example 15
Source File: BitemporalBankApp.java    From reladomo-kata with Apache License 2.0 4 votes vote down vote up
private void initReladomo() throws Exception
{
    MithraManager mithraManager = MithraManagerProvider.getMithraManager();
    mithraManager.setTransactionTimeout(60 * 1000);
    loadReladomoXML("BitemporalBankRuntimeConfiguration.xml");
}
 
Example 16
Source File: MithraTestResource.java    From reladomo with Apache License 2.0 4 votes vote down vote up
private void initializeMithraManager(MithraConfigurationManager manager)
{
    MithraManager mithra = MithraManagerProvider.getMithraManager();
    mithra.setTransactionTimeout(60); // reset to default
    this.initializeMithraManagerConfigManager(mithra, manager);
}
 
Example 17
Source File: MithraTestResource.java    From reladomo with Apache License 2.0 4 votes vote down vote up
public void tearDown()
{
    logger.debug(System.identityHashCode(this) + " MithraTestResource tear down");
    MithraManager mithra = MithraManagerProvider.getMithraManager();
    try
    {
        while (mithra.isInTransaction())
        {
            logger.error("incomplete transaction. attempting rollback");
            mithra.getCurrentTransaction().rollback();
        }
    }
    catch (MithraTransactionException e)
    {
        logger.error("rollback failed. subsequent tests may cascade fail", e);
    }
    if (testConnectionsOnTearDown)
    {
        if (!ConnectionManagerForTests.getInstance().ensureAllConnectionsReturnedToPool())
        {
            logger.error("all connections were not returned to the pool", new Exception("for tracing"));
        }
    }
    this.tearDownDatabases();
    mithra.cleanUpPrimaryKeyGenerators();
    mithra.cleanUpRuntimeCacheControllers(this.configuredObjects);
    databaseObjectPerConnectionManager.clear(); //todo: make this an instance field.
    connectionManagersInUse.clear();
    tearDownPureObjects();
    restrictedClasses = null;
    testPureFilesInUse = null;
    mithraRuntimeList = null;
    this.configuredObjects.clear();
    additionalConnectionManagersInUse.clear();
    testDataFilesInUse.clear();
    if (portals != null)
    {
        portals.clear();
    }
    MithraReferenceThread.getInstance().runNow();
}