Search in sources :

Example 1 with Property

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);
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.query.Property) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Property

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);
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Property(org.motechproject.mds.query.Property) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Property

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;
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.query.Property)

Example 4 with Property

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;
}
Also used : Query(javax.jdo.Query) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.query.Property) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Property

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);
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) ArrayList(java.util.ArrayList) Property(org.motechproject.mds.query.Property) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ArrayList (java.util.ArrayList)6 Property (org.motechproject.mds.query.Property)6 Query (javax.jdo.Query)5 PersistenceManager (javax.jdo.PersistenceManager)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Collection (java.util.Collection)1 DateTime (org.joda.time.DateTime)1 DeliveryStatus (org.motechproject.email.domain.DeliveryStatus)1 MatchesProperty (org.motechproject.mds.query.MatchesProperty)1 RangeProperty (org.motechproject.mds.query.RangeProperty)1 RestrictionProperty (org.motechproject.mds.query.RestrictionProperty)1 SetProperty (org.motechproject.mds.query.SetProperty)1