/** * A part of the facade over the JPA API * Find an entity with the given name and id in JPA * @param tenantId * @param entityName * @param id * @return */ public Object find(Map<String, String> tenantId, String entityName, Object id) { return find(tenantId, entityName, id, null); }
/** * A part of the facade over the JPA API * Find an entity with the given name and id in JPA * @param entityName * @param id * @return */ public Object find(String entityName, Object id) { return find(null, entityName, id); }
/** * A part of the facade over the JPA API * Find an entity with the given name and id in JPA * @param tenantId * @param entityName * @param id * @return */ public Object find(Map<String, String> tenantId, String entityName, Object id) { return find(tenantId, entityName, id, null); }
/** * A part of the facade over the JPA API * Find an entity with the given name and id in JPA * @param entityName * @param id * @return */ public Object find(String entityName, Object id) { return find(null, entityName, id); }
private Object getObjectById(String entityType, Object id) throws Exception { Object entity = context.find(null, entityType, id, null); if (entity != null) { return entity; } // It is an error if the object referred by a link doesn't exist, so throw exception throw JPARSException.objectReferredByLinkDoesNotExist(entityType, id); } }
@SuppressWarnings("unchecked") private T getObjectById(String entityType, Object id) throws Exception { final Object entity = context.find(null, entityType, id, null); if (entity != null) { return (T)entity; } // It is an error if the object referred by a link doesn't exist, so throw exception throw JPARSException.objectReferredByLinkDoesNotExist(entityType, id); } }
private T getObjectById(String entityType, Object id) throws Exception { final Object entity = context.find(null, entityType, id, null); if (entity != null) { return (T)entity; } // It is an error if the object referred by a link doesn't exist, so throw exception throw JPARSException.objectReferredByLinkDoesNotExist(entityType, id); } }
private Object getObjectById(String entityType, Object id) throws Exception { Object entity = context.find(null, entityType, id, null); if (entity != null) { return entity; } // It is an error if the object referred by a link doesn't exist, so throw exception throw JPARSException.objectReferredByLinkDoesNotExist(entityType, id); } }
private T getObjectById(String entityType, Object id) throws Exception { final Object entity = context.find(null, entityType, id, null); if (entity != null) { return (T)entity; } // It is an error if the object referred by a link doesn't exist, so throw exception throw JPARSException.objectReferredByLinkDoesNotExist(entityType, id); } }
@SuppressWarnings("unchecked") private T getObjectById(String entityType, Object id) throws Exception { final Object entity = context.find(null, entityType, id, null); if (entity != null) { return (T)entity; } // It is an error if the object referred by a link doesn't exist, so throw exception throw JPARSException.objectReferredByLinkDoesNotExist(entityType, id); } }
protected Object constructObjectForId(String entityType, Object id){ FetchGroup fetchGroup = new FetchGroup(); ClassDescriptor descriptor = context.getDescriptor(entityType); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); for (DatabaseMapping mapping: pkMappings){ fetchGroup.addAttribute(mapping.getAttributeName()); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(QueryHints.FETCH_GROUP, fetchGroup); properties.put(QueryHints.CACHE_USAGE, CacheUsage.CheckCacheOnly); Object entity = context.find(null, entityType, id, properties); if (entity == null){ return IdHelper.buildObjectShell(context, entityType, id); } return entity; }
protected Object constructObjectForId(String entityType, Object id){ FetchGroup fetchGroup = new FetchGroup(); ClassDescriptor descriptor = context.getDescriptor(entityType); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); for (DatabaseMapping mapping: pkMappings){ fetchGroup.addAttribute(mapping.getAttributeName()); } Map<String, Object> properties = new HashMap<String, Object>(); properties.put(QueryHints.FETCH_GROUP, fetchGroup); properties.put(QueryHints.CACHE_USAGE, CacheUsage.CheckCacheOnly); Object entity = context.find(null, entityType, id, properties); if (entity == null){ return IdHelper.buildObjectShell(context, entityType, id); } return entity; }
protected Response findInternal(String version, String persistenceUnit, String type, String id, HttpHeaders headers, UriInfo uriInfo) { JPARSLogger.entering(CLASS_NAME, "findInternal", new Object[] { "GET", version, persistenceUnit, type, id, uriInfo.getRequestUri().toASCIIString() }); try { final PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); final Map<String, String> discriminators = getMatrixParameters(uriInfo, persistenceUnit); final Object entityId = IdHelper.buildId(context, type, id); final Object entity = context.find(discriminators, type, entityId, getQueryParameters(uriInfo)); if (entity == null) { JPARSLogger.error("jpars_could_not_find_entity_for_key", new Object[] { type, id, persistenceUnit }); throw JPARSException.entityNotFound(type, id, persistenceUnit); } // Fields filtering if (context.getSupportedFeatureSet().isSupported(Feature.FIELDS_FILTERING)) { final FieldsFilteringValidator fieldsFilteringValidator = new FieldsFilteringValidator(uriInfo); if (fieldsFilteringValidator.isFeatureApplicable()) { final StreamingOutputMarshaller marshaller = new StreamingOutputMarshaller(context, singleEntityResponse(context, entity, uriInfo), headers.getAcceptableMediaTypes(), fieldsFilteringValidator.getFilter()); return Response.ok(marshaller).build(); } } return Response.ok(new StreamingOutputMarshaller(context, singleEntityResponse(context, entity, uriInfo), headers.getAcceptableMediaTypes())).build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
protected Response findInternal(String version, String persistenceUnit, String type, String id, HttpHeaders headers, UriInfo uriInfo) { JPARSLogger.entering(CLASS_NAME, "findInternal", new Object[] { "GET", version, persistenceUnit, type, id, uriInfo.getRequestUri().toASCIIString() }); try { final PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); final Map<String, String> discriminators = getMatrixParameters(uriInfo, persistenceUnit); final Object entityId = IdHelper.buildId(context, type, id); final Object entity = context.find(discriminators, type, entityId, getQueryParameters(uriInfo)); if (entity == null) { JPARSLogger.error(context.getSessionLog(), "jpars_could_not_find_entity_for_key", new Object[] { type, id, persistenceUnit }); throw JPARSException.entityNotFound(type, id, persistenceUnit); } // Fields filtering if (context.getSupportedFeatureSet().isSupported(Feature.FIELDS_FILTERING)) { final FieldsFilteringValidator fieldsFilteringValidator = new FieldsFilteringValidator(uriInfo); if (fieldsFilteringValidator.isFeatureApplicable()) { final StreamingOutputMarshaller marshaller = new StreamingOutputMarshaller(context, singleEntityResponse(context, entity, uriInfo), headers.getAcceptableMediaTypes(), fieldsFilteringValidator.getFilter()); return Response.ok(marshaller).build(); } } return Response.ok(new StreamingOutputMarshaller(context, singleEntityResponse(context, entity, uriInfo), headers.getAcceptableMediaTypes())).build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
} else { Object realListItemId = IdHelper.buildId(this, referenceDescriptor.getAlias(), listItemId); Object member = this.find(referenceDescriptor.getAlias(), realListItemId); ((Collection) attributeValue).remove(member);
} else { Object realListItemId = IdHelper.buildId(this, referenceDescriptor.getAlias(), listItemId); Object member = this.find(referenceDescriptor.getAlias(), realListItemId); ((Collection) attributeValue).remove(member);
Object entity = context.find(discriminators, type, entityId, getQueryParameters(uriInfo)); Object result = context.removeAttribute(getMatrixParameters(uriInfo, persistenceUnit), type, entityId, attribute, listItemId, entity, partner);
Object entity = context.find(discriminators, type, entityId, getQueryParameters(uriInfo)); Object result = context.removeAttribute(getMatrixParameters(uriInfo, persistenceUnit), type, entityId, attribute, listItemId, entity, partner);