use of javax.jdo.PersistenceManager in project motech by motech.
the class BaseIT method getAll.
protected <T> List<T> getAll(Class<T> clazz, boolean forSchema) {
PersistenceManager persistenceManager = forSchema ? getPersistenceManager() : getDataPersistenceManager();
Query query = persistenceManager.newQuery(clazz);
return cast(clazz, (Collection) query.execute());
}
use of javax.jdo.PersistenceManager in project motech by motech.
the class HistoryServiceImpl method createRecord.
private <T> Object createRecord(Class<T> historyClass, Object instance, Object existingRecord) {
Object currentHistoryInstance = create(historyClass, instance, existingRecord);
setHistoryProperties(currentHistoryInstance, instance);
PersistenceManager manager = getPersistenceManagerFactory().getPersistenceManager();
LOGGER.debug("Create a new history entry for {}", instance.getClass().getName());
manager.makePersistent(currentHistoryInstance);
return currentHistoryInstance;
}
use of javax.jdo.PersistenceManager in project motech by motech.
the class TrashServiceImpl method countTrashRecords.
@Override
@Transactional
public long countTrashRecords(String className) {
Class<?> trashClass = HistoryTrashClassHelper.getClass(className, EntityType.TRASH, getBundleContext());
Long schemaVersion = getCurrentSchemaVersion(className);
List<Property> properties = new ArrayList<>();
properties.add(PropertyBuilder.create(Constants.Util.SCHEMA_VERSION_FIELD_NAME, schemaVersion, Long.class));
PersistenceManager manager = getPersistenceManagerFactory().getPersistenceManager();
Query query = manager.newQuery(trashClass);
QueryUtil.useFilter(query, properties);
QueryUtil.setCountResult(query);
return (long) query.execute(schemaVersion);
}
use of javax.jdo.PersistenceManager in project motech by motech.
the class TrashServiceImpl method getInstancesFromTrash.
@Override
@Transactional
public Collection getInstancesFromTrash(String className, QueryParams queryParams) {
Class<?> trashClass = HistoryTrashClassHelper.getClass(className, EntityType.TRASH, getBundleContext());
Long schemaVersion = getCurrentSchemaVersion(className);
List<Property> properties = new ArrayList<>();
properties.add(PropertyBuilder.create(Constants.Util.SCHEMA_VERSION_FIELD_NAME, schemaVersion, Long.class));
PersistenceManager manager = getPersistenceManagerFactory().getPersistenceManager();
Query query = manager.newQuery(trashClass);
QueryUtil.setQueryParams(query, queryParams);
QueryUtil.useFilter(query, properties);
return (Collection) query.execute(schemaVersion);
}
use of javax.jdo.PersistenceManager in project motech by motech.
the class ComboboxValueRepository method getComboboxValuesForStringField.
/**
* Retrieves all values for a single-select combobox.
* @param entityDto the entity to which the combobox belongs to
* @param cbFieldDto the field representing the combobox
* @return all values for the combobox currently in the database
*/
public List<String> getComboboxValuesForStringField(EntityDto entityDto, FieldDto cbFieldDto) {
PersistenceManager pm = getPersistenceManager();
// MDS must ensure that these are valid
Query query = pm.newQuery(String.format("SELECT DISTINCT %1$s FROM %2$s WHERE %1$s != null && %1$s.length() > 0 ORDER BY %1$s ASC", cbFieldDto.getBasic().getName(), entityDto.getClassName()));
return (List<String>) query.execute();
}
Aggregations