use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class InstanceServiceImpl method getEntityRecordsFromLookup.
@Override
public List<BasicEntityRecord> getEntityRecordsFromLookup(Long entityId, String lookupName, Map<String, Object> lookupMap, QueryParams queryParams) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
LookupDto lookup = getLookupByName(entityId, lookupName);
List<FieldDto> fields = entityService.getEntityFieldsForUI(entityId);
Map<String, FieldDto> fieldMap = entityService.getLookupFieldsMapping(entityId, lookupName);
MotechDataService service = getServiceForEntity(entity);
try {
LookupExecutor lookupExecutor = new LookupExecutor(service, lookup, fieldMap);
Object result = lookupExecutor.execute(lookupMap, queryParams);
if (lookup.isSingleObjectReturn()) {
BasicEntityRecord record = instanceToBasicRecord(result, entity, fields, service, EntityType.STANDARD, getRelatedEntitiesFields(fields));
return (record == null) ? new ArrayList<BasicEntityRecord>() : Collections.singletonList(record);
} else {
List instances = (List) result;
return instancesToBasicRecords(instances, entity, fields, service, EntityType.STANDARD);
}
} catch (LookupExecutorException e) {
if (e.getMessageKey() != null) {
throw new LookupExecutionException(e, e.getMessageKey());
} else {
throw new LookupExecutionException(e, LOOKUP_EXCEPTION_MESSAGE_KEY);
}
} catch (RuntimeException e) {
throw new LookupExecutionException(e, LOOKUP_EXCEPTION_MESSAGE_KEY);
}
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class InstanceServiceImpl method deleteSelectedInstances.
@Override
public void deleteSelectedInstances(Long entityId, List<Long> instanceIds) {
EntityDto entity = getEntity(entityId);
validateCredentials(entity);
validateNonEditableProperty(entity);
MotechDataService service = getServiceForEntity(entity);
for (Long instanceId : instanceIds) {
service.delete(ID_FIELD_NAME, instanceId);
}
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class InstanceServiceImpl method countRecords.
@Override
public long countRecords(Long entityId) {
EntityDto entity = getEntity(entityId);
validateCredentialsForReading(entity);
MotechDataService service = getServiceForEntity(entity);
return service.count();
}
use of org.motechproject.mds.service.MotechDataService 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();
}
use of org.motechproject.mds.service.MotechDataService in project motech by motech.
the class MdsStressIT method testPerformance.
@Test
public void testPerformance() throws NotFoundException, CannotCompileException, IOException, InvalidSyntaxException, InterruptedException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
final String serviceName = ClassName.getInterfaceName(FOO_CLASS);
generator.generateDummyEntities(1, 2, 0, true);
Bundle entitiesBundle = OsgiBundleUtils.findBundleBySymbolicName(bundleContext, MDS_ENTITIES_SYMBOLIC_NAME);
assertNotNull(entitiesBundle);
MotechDataService service = (MotechDataService) ServiceRetriever.getService(entitiesBundle.getBundleContext(), serviceName, true);
Class<?> objectClass = entitiesBundle.loadClass(FOO_CLASS);
LOGGER.info("Loaded class: " + objectClass.getName());
stressTestCreating(service, objectClass);
stressTestRetrieval(service);
stressTestUpdating(service);
stressTestDeleting(service);
}
Aggregations