Search in sources :

Example 11 with PersistenceManager

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());
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager)

Example 12 with PersistenceManager

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;
}
Also used : PersistenceManager(javax.jdo.PersistenceManager)

Example 13 with PersistenceManager

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);
}
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 14 with PersistenceManager

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);
}
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 15 with PersistenceManager

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();
}
Also used : Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)1664 Transaction (javax.jdo.Transaction)1542 Query (javax.jdo.Query)671 List (java.util.List)397 JDOUserException (javax.jdo.JDOUserException)352 Collection (java.util.Collection)309 Iterator (java.util.Iterator)239 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)185 JDOPersistenceManager (org.datanucleus.api.jdo.JDOPersistenceManager)170 Person (org.jpox.samples.models.company.Person)146 Employee (org.jpox.samples.models.company.Employee)128 Manager (org.jpox.samples.models.company.Manager)107 HashSet (java.util.HashSet)101 ArrayList (java.util.ArrayList)85 SQLException (java.sql.SQLException)82 RDBMSStoreManager (org.datanucleus.store.rdbms.RDBMSStoreManager)77 JDOException (javax.jdo.JDOException)74 Extent (javax.jdo.Extent)72 JDOFatalUserException (javax.jdo.JDOFatalUserException)68 JDODataStoreException (javax.jdo.JDODataStoreException)65