/** * Look-up the given entity name in the EntityManagerFactory and return the class * is describes * @param entityName * @return */ public Class<?> getClass(String entityName) { ClassDescriptor descriptor = getDescriptor(entityName); if (descriptor == null) { return null; } return descriptor.getJavaClass(); }
/** * Look-up the given entity name in the EntityManagerFactory and return the class * is describes * @param entityName * @return */ public Class<?> getClass(String entityName) { ClassDescriptor descriptor = getDescriptor(entityName); if (descriptor == null) { return null; } return descriptor.getJavaClass(); }
private T loadEntity(String href) throws Exception { final String uri = href.replace("\\/", "/"); String entityType = uri.substring(uri.indexOf("/entity/"), uri.lastIndexOf('/')); entityType = entityType.substring(entityType.lastIndexOf("/") + 1); final String entityId = uri.substring(uri.lastIndexOf("/") + 1); final ClassDescriptor descriptor = context.getDescriptor(entityType); final Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId); return getObjectById(entityType, id); }
private T loadEntity(String href) throws Exception { final String uri = href.replace("\\/", "/"); String entityType = uri.substring(uri.indexOf("/entity/"), uri.lastIndexOf('/')); entityType = entityType.substring(entityType.lastIndexOf("/") + 1); final String entityId = uri.substring(uri.lastIndexOf("/") + 1); final ClassDescriptor descriptor = context.getDescriptor(entityType); final Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId); return getObjectById(entityType, id); }
@Override public Object unmarshal(String v) throws Exception { if (v.equals("")){ return null; } String fixedString = v.replace("\\/", "/"); int lastSlash = fixedString.lastIndexOf('/'); String entityType = fixedString.substring((baseURI + context.getName() + "/entity/" ).length(), lastSlash); String entityId = fixedString.substring(lastSlash + 1); ClassDescriptor descriptor = context.getDescriptor(entityType); Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId); return constructObjectForId(entityType, id); }
@Override public Object unmarshal(String v) throws Exception { if (v.equals("")){ return null; } String fixedString = v.replace("\\/", "/"); int lastSlash = fixedString.lastIndexOf('/'); String entityType = fixedString.substring((baseURI + context.getName() + "/entity/" ).length(), lastSlash); String entityId = fixedString.substring(lastSlash + 1); ClassDescriptor descriptor = context.getDescriptor(entityType); Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId); return constructObjectForId(entityType, id); }
public static List<SortableKey> getPrimaryKey(PersistenceContext context, String entityName) { ClassDescriptor descriptor = context.getDescriptor(entityName); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); List<SortableKey> pkIndices = new ArrayList<SortableKey>(); int index = 0; for (DatabaseMapping mapping : pkMappings) { if (!mapping.isMultitenantPrimaryKeyMapping()) { pkIndices.add(new SortableKey(mapping, index)); index++; } } Collections.sort(pkIndices); return pkIndices; }
public static List<SortableKey> getPrimaryKey(PersistenceContext context, String entityName) { ClassDescriptor descriptor = context.getDescriptor(entityName); List<DatabaseMapping> pkMappings = descriptor.getObjectBuilder().getPrimaryKeyMappings(); List<SortableKey> pkIndices = new ArrayList<SortableKey>(); int index = 0; for (DatabaseMapping mapping : pkMappings) { if (!mapping.isMultitenantPrimaryKeyMapping()) { pkIndices.add(new SortableKey(mapping, index)); index++; } } Collections.sort(pkIndices); return pkIndices; }
private Collection loadItems(String href) throws Exception { String uri = href.replace("\\/", "/"); uri = uri.substring(uri.indexOf("entity/")); uri = uri.substring(uri.indexOf("/") + 1); final String[] uriItems = uri.split("/"); final String entityType = uriItems[0]; final String entityId = uriItems[1]; final String attributeName = uriItems[2]; final ClassDescriptor descriptor = context.getDescriptor(entityType); final Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId); final T entity = getObjectById(entityType, id); final DatabaseMapping attributeMapping = descriptor.getMappingForAttributeName(attributeName); if ((attributeMapping == null) || (entity == null)) { throw JPARSException.databaseMappingCouldNotBeFoundForEntityAttribute(attributeName, entityType, entityId, null); } return (Collection) attributeMapping.getRealAttributeValueFromAttribute(attributeMapping.getAttributeValueFromObject(entity), entity, (AbstractSession)context.getServerSession()); }
private Collection loadItems(String href) throws Exception { String uri = href.replace("\\/", "/"); uri = uri.substring(uri.indexOf("entity/")); uri = uri.substring(uri.indexOf("/") + 1); final String[] uriItems = uri.split("/"); final String entityType = uriItems[0]; final String entityId = uriItems[1]; final String attributeName = uriItems[2]; final ClassDescriptor descriptor = context.getDescriptor(entityType); final Object id = IdHelper.buildId(context, descriptor.getAlias(), entityId); final T entity = getObjectById(entityType, id); final DatabaseMapping attributeMapping = descriptor.getMappingForAttributeName(attributeName); if ((attributeMapping == null) || (entity == null)) { throw JPARSException.databaseMappingCouldNotBeFoundForEntityAttribute(attributeName, entityType, entityId, null); } return (Collection) attributeMapping.getRealAttributeValueFromAttribute(attributeMapping.getAttributeValueFromObject(entity), entity, (AbstractSession)context.getServerSession()); }
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; }
/** * A convenience method to create a new dynamic entity of the given type * @param tenantId * @param type * @return */ public DynamicEntity newEntity(Map<String, String> tenantId, String type) { JPADynamicHelper helper = new JPADynamicHelper(getEmf()); DynamicEntity entity; try { entity = helper.newDynamicEntity(type); } catch (IllegalArgumentException e) { ClassDescriptor descriptor = getDescriptor(type); if (descriptor != null) { DynamicType jaxbType = (DynamicType) descriptor.getProperty(DynamicType.DESCRIPTOR_PROPERTY); if (jaxbType != null) { return jaxbType.newDynamicEntity(); } } JPARSLogger.exception("exception_thrown_while_creating_dynamic_entity", new Object[] { type }, e); throw e; } return entity; }
/** * A convenience method to create a new dynamic entity of the given type * @param tenantId * @param type * @return */ public DynamicEntity newEntity(Map<String, String> tenantId, String type) { JPADynamicHelper helper = new JPADynamicHelper(getEmf()); DynamicEntity entity; try { entity = helper.newDynamicEntity(type); } catch (IllegalArgumentException e) { ClassDescriptor descriptor = getDescriptor(type); if (descriptor != null) { DynamicType jaxbType = (DynamicType) descriptor.getProperty(DynamicType.DESCRIPTOR_PROPERTY); if (jaxbType != null) { return jaxbType.newDynamicEntity(); } } JPARSLogger.exception(getSessionLog(), "exception_thrown_while_creating_dynamic_entity", new Object[] { type }, e); throw e; } return entity; }
PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Object entityId = IdHelper.buildId(context, type, id); ClassDescriptor descriptor = context.getDescriptor(type); DatabaseMapping mapping = descriptor.getMappingForAttributeName(attribute); if (!mapping.isForeignReferenceMapping()) {
PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Object entityId = IdHelper.buildId(context, type, id); ClassDescriptor descriptor = context.getDescriptor(type); DatabaseMapping mapping = descriptor.getMappingForAttributeName(attribute); if (!mapping.isForeignReferenceMapping()) {
try { final PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); final ClassDescriptor descriptor = context.getDescriptor(type); if (descriptor == null) { JPARSLogger.error("jpars_could_not_find_class_in_persistence_unit", new Object[] { type, persistenceUnit });
protected Response setOrAddAttributeInternal(String version, String persistenceUnit, String type, String id, String attribute, HttpHeaders headers, UriInfo uriInfo, InputStream in) { JPARSLogger.entering(CLASS_NAME, "setOrAddAttributeInternal", new Object[] { "POST", headers.getMediaType(), version, persistenceUnit, type, id, attribute, uriInfo.getRequestUri().toASCIIString() }); try { PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Object entityId = IdHelper.buildId(context, type, id); String partner = getRelationshipPartner(getMatrixParameters(uriInfo, attribute), getQueryParameters(uriInfo)); ClassDescriptor descriptor = context.getDescriptor(type); DatabaseMapping mapping = descriptor.getMappingForAttributeName(attribute); if (!mapping.isForeignReferenceMapping()) { JPARSLogger.error("jpars_could_not_find_appropriate_mapping_for_update", new Object[] { attribute, type, id, persistenceUnit }); throw JPARSException.databaseMappingCouldNotBeFoundForEntityAttribute(attribute, type, id, persistenceUnit); } Object entity = context.unmarshalEntity(mapping.getReferenceDescriptor().getAlias(), mediaType(headers.getAcceptableMediaTypes()), in); Object result = context.updateOrAddAttribute(getMatrixParameters(uriInfo, persistenceUnit), type, entityId, getQueryParameters(uriInfo), attribute, entity, partner); if (result == null) { JPARSLogger.error("jpars_could_not_update_attribute", new Object[] { attribute, type, id, persistenceUnit }); throw JPARSException.attributeCouldNotBeUpdated(attribute, type, id, persistenceUnit); } return Response.ok(new StreamingOutputMarshaller(context, singleEntityResponse(context, result, uriInfo), headers.getAcceptableMediaTypes())).build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }
try { final PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); final ClassDescriptor descriptor = context.getDescriptor(type); if (descriptor == null) { JPARSLogger.error(context.getSessionLog(), "jpars_could_not_find_class_in_persistence_unit", new Object[] { type, persistenceUnit });
protected Response setOrAddAttributeInternal(String version, String persistenceUnit, String type, String id, String attribute, HttpHeaders headers, UriInfo uriInfo, InputStream in) { JPARSLogger.entering(CLASS_NAME, "setOrAddAttributeInternal", new Object[] { "POST", headers.getMediaType(), version, persistenceUnit, type, id, attribute, uriInfo.getRequestUri().toASCIIString() }); try { PersistenceContext context = getPersistenceContext(persistenceUnit, type, uriInfo.getBaseUri(), version, null); Object entityId = IdHelper.buildId(context, type, id); String partner = getRelationshipPartner(getMatrixParameters(uriInfo, attribute), getQueryParameters(uriInfo)); ClassDescriptor descriptor = context.getDescriptor(type); DatabaseMapping mapping = descriptor.getMappingForAttributeName(attribute); if (!mapping.isForeignReferenceMapping()) { JPARSLogger.error(context.getSessionLog(), "jpars_could_not_find_appropriate_mapping_for_update", new Object[] { attribute, type, id, persistenceUnit }); throw JPARSException.databaseMappingCouldNotBeFoundForEntityAttribute(attribute, type, id, persistenceUnit); } Object entity = context.unmarshalEntity(mapping.getReferenceDescriptor().getAlias(), mediaType(headers.getAcceptableMediaTypes()), in); Object result = context.updateOrAddAttribute(getMatrixParameters(uriInfo, persistenceUnit), type, entityId, getQueryParameters(uriInfo), attribute, entity, partner); if (result == null) { JPARSLogger.error(context.getSessionLog(), "jpars_could_not_update_attribute", new Object[] { attribute, type, id, persistenceUnit }); throw JPARSException.attributeCouldNotBeUpdated(attribute, type, id, persistenceUnit); } return Response.ok(new StreamingOutputMarshaller(context, singleEntityResponse(context, result, uriInfo), headers.getAcceptableMediaTypes())).build(); } catch (Exception ex) { throw JPARSException.exceptionOccurred(ex); } }