use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class ApprovalManager method get.
private Object get(RegistryEntry entry, String idString) {
ResourceInformation resourceInformation = entry.getResourceInformation();
Object id = resourceInformation.parseIdString(idString);
ResourceRepositoryV2 resourceRepository = entry.getResourceRepositoryFacade();
QuerySpec querySpec = new QuerySpec(resourceInformation.getResourceType());
return resourceRepository.findOne((Serializable) id, querySpec);
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class ApprovalRelationshipRepository method findOneTarget.
@Override
public P findOneTarget(Serializable sourceId, String fieldName, QuerySpec querySpec) {
if (relationshipName.equals(fieldName)) {
RegistryEntry resourceEntry = resourceRegistry.getEntry(resourceClass);
RegistryEntry processEntry = resourceRegistry.getEntry(processInfoClass);
String resourceType = resourceEntry.getResourceInformation().getResourceType();
ResourceRepositoryV2 processRepository = (ResourceRepositoryV2) processEntry.getResourceRepository(null).getResourceRepository();
QuerySpec processQuerySpec = querySpec.duplicate();
processQuerySpec.addFilter(new FilterSpec(Arrays.asList(RESOURCE_ID_FIELD), FilterOperator.EQ, sourceId.toString()));
processQuerySpec.addFilter(new FilterSpec(Arrays.asList(RESOURCE_TYPE_FIELD), FilterOperator.EQ, resourceType));
baseFilters.forEach(processQuerySpec::addFilter);
ResourceList list = processRepository.findAll(querySpec);
PreconditionUtil.assertTrue("unique result expected", list.size() <= 1);
return list.isEmpty() ? null : (P) list.get(0);
} else {
throw new UnsupportedOperationException("unknown fieldName '" + fieldName + "'");
}
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaEntityRepository method findOne.
@Override
public final T findOne(I id, QuerySpec querySpec) {
QuerySpec idQuerySpec = querySpec.duplicate();
idQuerySpec.addFilter(new FilterSpec(Arrays.asList(primaryKeyAttr.getName()), FilterOperator.EQ, id));
List<T> results = findAll(idQuerySpec);
return getUnique(results, id);
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaEntityRepository method findAll.
@Override
public final ResourceList<T> findAll(Iterable<I> ids, QuerySpec querySpec) {
QuerySpec idQuerySpec = querySpec.duplicate();
idQuerySpec.addFilter(new FilterSpec(Arrays.asList(primaryKeyAttr.getName()), FilterOperator.EQ, ids));
return findAll(idQuerySpec);
}
use of io.crnk.core.queryspec.QuerySpec in project crnk-framework by crnk-project.
the class JpaEntityRepository method saveInternal.
@SuppressWarnings("unchecked")
private <S extends T> S saveInternal(S resource) {
JpaMapper<Object, T> mapper = repositoryConfig.getMapper();
Object entity = mapper.unmap(resource);
// PATCH reads, updates and saves entities, needs reattachment during
// save since reads do a detach
EntityManager em = module.getEntityManager();
em.persist(entity);
I id = (I) em.getEntityManagerFactory().getPersistenceUnitUtil().getIdentifier(entity);
// fetch again since we may have to fetch tuple data and do DTO mapping
QuerySpec querySpec = new QuerySpec(repositoryConfig.getResourceClass());
PreconditionUtil.verify(id != null, "id not available for entity %s", resource);
return (S) findOne(id, querySpec);
}
Aggregations