Search in sources :

Example 1 with LocalPersistenceManagerFactoryBean

use of org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean in project motech by motech.

the class MdsDiskSpaceUsageIT method testEudeDiskSpaceUsage.

@Test
public void testEudeDiskSpaceUsage() throws IOException, IllegalAccessException, ClassNotFoundException, InstantiationException, SQLException {
    LOGGER.info("Creating entity");
    generator.generateDummyEntities(ENTITIES, FIELDS, LOOKUPS, true);
    EntityDto entityDto = entityService.getEntityByClassName(Constants.Packages.ENTITY.concat(".").concat(generator.getEntityPrefix()).concat("0"));
    LOGGER.info("Creating {} instances for entity", INSTANCES);
    generator.generateDummyInstances(entityDto.getId(), INSTANCES);
    WebApplicationContext context = ServiceRetriever.getWebAppContext(bundleContext, MDS_BUNDLE_SYMBOLIC_NAME);
    LocalPersistenceManagerFactoryBean dataPersistenceManagerFactoryBean = (LocalPersistenceManagerFactoryBean) context.getBean(BeanFactory.FACTORY_BEAN_PREFIX + "dataPersistenceManagerFactoryBean");
    LocalPersistenceManagerFactoryBean schemaPersistenceManagerFactoryBean = (LocalPersistenceManagerFactoryBean) context.getBean(BeanFactory.FACTORY_BEAN_PREFIX + "persistenceManagerFactoryBean");
    PersistenceManagerFactory dataPersistenceManagerFactory = dataPersistenceManagerFactoryBean.getObject();
    PersistenceManagerFactory schemaPersistenceManagerFactory = schemaPersistenceManagerFactoryBean.getObject();
    JDOConnection dataCon = dataPersistenceManagerFactory.getPersistenceManager().getDataStoreConnection();
    JDOConnection schemaCon = schemaPersistenceManagerFactory.getPersistenceManager().getDataStoreConnection();
    Connection dataNativeCon = (Connection) dataCon.getNativeConnection();
    Connection schemaNativeCon = (Connection) schemaCon.getNativeConnection();
    Statement dataStmt = dataNativeCon.createStatement();
    Statement schemaStmt = schemaNativeCon.createStatement();
    ResultSet dataResultSet = dataStmt.executeQuery(String.format(SQLQUERY, "motechdata"));
    dataResultSet.absolute(1);
    double spaceUsage = dataResultSet.getDouble("MB");
    ResultSet schemaResultSet = schemaStmt.executeQuery(String.format(SQLQUERY, "motechschema"));
    schemaResultSet.absolute(1);
    spaceUsage += schemaResultSet.getDouble("MB");
    LOGGER.info("Disk space usage of Motech Data Services database after creating {} instances is {} MB", INSTANCES, spaceUsage);
    logToFile(spaceUsage);
    Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME);
    MotechDataService service = generator.getService(entitiesBundle.getBundleContext(), entityDto.getClassName());
    service.deleteAll();
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Statement(java.sql.Statement) Bundle(org.osgi.framework.Bundle) LocalPersistenceManagerFactoryBean(org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean) Connection(java.sql.Connection) JDOConnection(javax.jdo.datastore.JDOConnection) ResultSet(java.sql.ResultSet) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory) JDOConnection(javax.jdo.datastore.JDOConnection) MotechDataService(org.motechproject.mds.service.MotechDataService) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 PersistenceManagerFactory (javax.jdo.PersistenceManagerFactory)1 JDOConnection (javax.jdo.datastore.JDOConnection)1 Test (org.junit.Test)1 EntityDto (org.motechproject.mds.dto.EntityDto)1 MotechDataService (org.motechproject.mds.service.MotechDataService)1 Bundle (org.osgi.framework.Bundle)1 LocalPersistenceManagerFactoryBean (org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1