Java源码示例:org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo

示例1
public Query build(GetEntitySetCountUriInfo uriInfo) throws ODataJPARuntimeException {
  Query query = null;
  try {
    ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo);
    if (listener != null) {
      query = listener.getQuery(uriInfo, em);
      JPQLContext jpqlContext = JPQLContext.getJPQLContext();
      query = getParameterizedQueryForListeners(jpqlContext, query);
    }
    if (query == null) {
      query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount);
    }
  } catch (Exception e) {
    throw ODataJPARuntimeException.throwException(
        ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
  } finally {
    JPQLContext.removeJPQLContext();
    ODataExpressionParser.removePositionalParametersThreadLocal();
  }
  return query;
}
 
示例2
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
		throws ODataException {
	authorization.check(READ, uriParserResultView);
	ODataResponse oDataResponse = null;
	augmentFilter((UriInfoImpl) uriParserResultView);
	try {
		oDataJPAContext.setODataContext(getContext());
		long jpaEntityCount = jpaProcessor.process(uriParserResultView);
		oDataResponse = responseBuilder.build(jpaEntityCount);
	} finally {
		close();
	}
	return oDataResponse;
}
 
示例3
@SuppressWarnings("rawtypes")
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uri_info,
      final String content_type) throws ODataException
{
   // Gets the `collection` part of the URI.
   EdmEntitySet targetES = uri_info.getTargetEntitySet();
   AbstractEntitySet entityset = Model.getEntitySet(targetES.getName());

   // Validity and security checks.
   if (!entityset.isAuthorized(Security.getCurrentUser()) ||
       uri_info.getNavigationSegments().isEmpty() && !entityset.isTopLevel())
   {
      throw new NotAllowedException();
   }

   // Builds the response.
   KeyPredicate startKP =
         (uri_info.getKeyPredicates().isEmpty()) ? null : uri_info.getKeyPredicates().get(0);

   Map<?, ?> results = Navigator.<Map>navigate(uri_info.getStartEntitySet(), startKP,
         uri_info.getNavigationSegments(), Map.class);

   FilterExpression filter = uri_info.getFilter();
   // Skip, Sort and Filter.
   if (results instanceof SubMap && (filter != null))
   {
      SubMapBuilder smb = ((SubMap) results).getSubMapBuilder();
      smb.setFilter(filter);
      results = smb.build();
   }

   return ODataResponse.entity(results.size()).build();
}
 
示例4
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  applySystemQueryOptions(
      uriInfo.getTargetEntitySet(),
      data,
      uriInfo.getFilter(),
      null,
      null,
      null,
      uriInfo.getSkip(),
      uriInfo.getTop());

  return ODataResponse.fromResponse(EntityProvider.writeText(String.valueOf(data.size()))).build();
}
 
示例5
@Override
public long process(final GetEntitySetCountUriInfo resultsView)
    throws ODataJPAModelException, ODataJPARuntimeException {

  JPAQueryBuilder queryBuilder = new JPAQueryBuilder(oDataJPAContext);
  Query query = queryBuilder.build(resultsView);
  List<?> resultList = query.getResultList();
  if (resultList != null && resultList.size() == 1) {
    return Long.valueOf(resultList.get(0).toString());
  }

  return 0;
}
 
示例6
@Test
public void buildGetEntitySetCountTest() {
  try {
    assertNotNull(builder.build((GetEntitySetCountUriInfo) mockURIInfoWithListener(false)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
示例7
@Test
public void buildQueryCountEntitySet() {
  EdmMapping mapping = (EdmMapping) mockMapping();
  try {
    assertNotNull(builder.build((GetEntitySetCountUriInfo) mockURIInfoForEntitySetCount(mapping)));
  } catch (ODataException e) {
    fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
  }
}
 
示例8
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
    throws ODataException {
  ODataResponse oDataResponse = null;
  try {
    oDataJPAContext.setODataContext(getContext());
    long jpaEntityCount = jpaProcessor.process(uriParserResultView);
    oDataResponse = responseBuilder.build(jpaEntityCount);
  } finally {
    close();
  }
  return oDataResponse;
}
 
示例9
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
    throws ODataException {
  ArrayList<Object> data = new ArrayList<Object>();
  try {
    data.addAll((List<?>) retrieveData(
        uriInfo.getStartEntitySet(),
        uriInfo.getKeyPredicates(),
        uriInfo.getFunctionImport(),
        mapFunctionParameters(uriInfo.getFunctionImportParameters()),
        uriInfo.getNavigationSegments()));
  } catch (final ODataNotFoundException e) {
    data.clear();
  }

  applySystemQueryOptions(
      uriInfo.getTargetEntitySet(),
      data,
      uriInfo.getFilter(),
      null,
      null,
      null,
      uriInfo.getSkip(),
      uriInfo.getTop());

  return ODataResponse.fromResponse(EntityProvider.writeText(String.valueOf(data.size()))).build();
}
 
示例10
@Override
public ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType)
    throws ODataException {
  return countEntitySet((GetEntitySetCountUriInfo) uriInfo, contentType);
}
 
示例11
public void getCount(GetEntitySetUriInfo uriInfo) throws ODataJPARuntimeException {
  JPAQueryInfo queryInfo = new JPAQueryInfo();
  Query query = null;
  UriInfoImpl info = (UriInfoImpl)uriInfo;
  boolean count = info.isCount();
  info.setCount(true);
  try {
    ODataJPAQueryExtensionEntityListener listener = getODataJPAQueryEntityListener((UriInfo) uriInfo);
    if (listener != null) {
      query = listener.getQuery((GetEntitySetCountUriInfo)uriInfo, em);
      if(query != null){
        JPQLContextType contextType = determineJPQLContextType(info, UriInfoType.GetEntitySetCount);
        JPQLContext jpqlContext = buildJPQLContext(contextType, info);
        JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build();
        jpqlContext.setJPQLStatement(jpqlStatement.toString());
        query = getParameterizedQueryForListeners(jpqlContext, query);
      }
    }
    if (query == null) {
      query = buildQuery((UriInfo) uriInfo, UriInfoType.GetEntitySetCount);
    } else {
      queryInfo.setTombstoneQuery(true);
    }
  } catch (Exception e) {
    throw ODataJPARuntimeException.throwException(
        ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
  } finally {
    JPQLContext.removeJPQLContext();
    ODataExpressionParser.removePositionalParametersThreadLocal();
  }
  queryInfo.setQuery(query);
  Query countQuery = queryInfo.getQuery();
  List<Object> countList = countQuery.getResultList();
  info.setCount(count);
  if(countList!= null && !countList.isEmpty()){
    String countNumber = countList.get(0).toString();
    Map<String, String> customQueryOptions = new HashMap<String, String>();
    customQueryOptions.put("count", countNumber);
    info.setCustomQueryOptions(customQueryOptions);
  }
}
 
示例12
private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
  return getLocalUriInfo();
}
 
示例13
@Override
public long process(GetEntitySetCountUriInfo requestView) throws ODataJPAModelException, ODataJPARuntimeException {
  // TODO Auto-generated method stub
  return 0;
}
 
示例14
private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
  return getLocalUriInfo();
}
 
示例15
@Override
public Query getQuery(GetEntitySetCountUriInfo uriInfo, EntityManager em) {
  return query;
}
 
示例16
@Override
public Query getQuery(GetEntitySetCountUriInfo uriInfo, EntityManager em) {
  return query;
}
 
示例17
@Override
public ODataResponse countEntitySet(GetEntitySetCountUriInfo uriInfo, String contentType) throws ODataException {
  // this method is not needed.
  return null;
}
 
示例18
@Override
public ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType)
    throws ODataException {
  return countEntitySet((GetEntitySetCountUriInfo) uriInfo, contentType);
}
 
示例19
/**
 * @see EntitySetProcessor
 */
@Override
public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
    throws ODataException {
  throw new ODataNotImplementedException();
}
 
示例20
/**
 * Override this method to build JPA Query for OData request - GetEntitySet Count; SELECT COUNT(*)
 * @param uriInfo is a reference to OData request
 * @param em is a reference to {@link javax.persistence.EntityManager}
 * @return an instance of type {@link javax.persistence.Query}
 */
public Query getQuery(GetEntitySetCountUriInfo uriInfo, EntityManager em) throws ODataJPARuntimeException {
  return null;
}
 
示例21
/**
 * Counts the number of requested entities.
 * @param uriInfo information about the request URI
 * @param contentType the content type of the response
 * @return an {@link ODataResponse} object
 * @throws ODataException
 */
ODataResponse countEntitySet(GetEntitySetCountUriInfo uriInfo, String contentType) throws ODataException;
 
示例22
/**
 * Processes OData request for fetching Entity count. The method returns JPA Entity count
 * 
 * @param requestView
 * OData request for counting an entity set
 * @return long value representing count of JPA entity set
 * 
 * @throws ODataJPAModelException
 * @throws ODataJPARuntimeException
 */

public long process(GetEntitySetCountUriInfo requestView)
    throws ODataJPAModelException, ODataJPARuntimeException;