use of org.motechproject.mds.query.Property 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 org.motechproject.mds.query.Property 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 org.motechproject.mds.query.Property in project motech by motech.
the class HistoryServiceImpl method initQuery.
private Query initQuery(Class<?> historyClass) {
List<Property> properties = new ArrayList<>(3);
// we need only a correct type (not value) that's why we pass dummy values, instead of actual ones
properties.add(PropertyBuilder.create(HistoryTrashClassHelper.currentVersion(historyClass), 1L, Long.class));
PersistenceManager manager = getPersistenceManagerFactory().getPersistenceManager();
Query query = manager.newQuery(historyClass);
QueryUtil.useFilter(query, properties);
return query;
}
use of org.motechproject.mds.query.Property in project motech by motech.
the class HistoryServiceImpl method getSingleHistoryInstance.
@Override
@Transactional
public Object getSingleHistoryInstance(Object instance, Long historyId) {
Class<?> historyClass = HistoryTrashClassHelper.getClass(instance, EntityType.HISTORY, getBundleContext());
Object obj = null;
if (null != historyClass) {
Query query = initQuery(historyClass);
List<Property> properties = new ArrayList<>();
properties.add(PropertyBuilder.create("id", historyId, Long.class));
QueryUtil.useFilter(query, properties);
query.setUnique(true);
obj = query.execute(historyId);
}
return obj;
}
use of org.motechproject.mds.query.Property in project motech by motech.
the class TrashServiceImpl method findTrashById.
@Override
@Transactional
public Object findTrashById(Long trashId, String entityClassName) {
Class<?> trashClass = HistoryTrashClassHelper.getClass(entityClassName, EntityType.TRASH, getBundleContext());
List<Property> properties = new ArrayList<>();
properties.add(PropertyBuilder.create("id", trashId, Long.class));
PersistenceManager manager = getPersistenceManagerFactory().getPersistenceManager();
Query query = manager.newQuery(trashClass);
QueryUtil.useFilter(query, properties);
query.setUnique(true);
return query.execute(trashId);
}
Aggregations