@Override public void createData(final EdmEntitySet entitySet, final Object data) throws ODataNotImplementedException, EdmException, ODataApplicationException { DataStore<Object> dataStore = getDataStore(entitySet); dataStore.create(data); }
public AnnotationInMemoryDs(final Collection<Class<?>> annotatedClasses, final boolean persistInMemory) throws ODataException { this.persistInMemory = persistInMemory; init(annotatedClasses); }
/** * Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code> * of <code>instance</code>. * * @param instance * @param field * @param value * @throws EdmException */ private void setValueAtNavigationField(final Object instance, final Field field, final Object value) throws EdmException { Class<?> fieldTypeClass = field.getType(); if (Collection.class.isAssignableFrom(fieldTypeClass)) { @SuppressWarnings("unchecked") Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField( instance, field.getName(), EdmNavigationProperty.class); if (collection == null) { collection = new ArrayList<Object>(); setValue(instance, field, collection); } collection.add(value); } else if (fieldTypeClass.isArray()) { throw new AnnotationRuntimeException("Write relations for internal used arrays is not supported."); } else { setValue(instance, field, value); } }
@Override public Object readRelatedData(final EdmEntitySet sourceEntitySet, final Object sourceData, final EdmEntitySet targetEntitySet, final Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<?> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); Field sourceField = navInfo.getFromField(); if (sourceField == null) { throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } List<Object> resultData = readResultData(targetStore, sourceData, sourceField); return extractResultData(targetStore, targetKeys, navInfo, resultData); }
/** * {@inheritDoc} */ @Override public ODataService createAnnotationService(final String modelPackage) throws ODataException { AnnotationEdmProvider edmProvider = new AnnotationEdmProvider(modelPackage); AnnotationInMemoryDs dataSource = new AnnotationInMemoryDs(modelPackage); AnnotationValueAccess valueAccess = new AnnotationValueAccess(); // Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess return RuntimeDelegate.createODataSingleProcessorService(edmProvider, new ListsProcessor(dataSource, valueAccess)); }
@Override public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity, final EdmEntitySet targetEntitySet, final Map<String, Object> targetEntityValues) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { // get common data DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); // get and validate source fields Field sourceField = commonNavInfo.getFromField(); if (sourceField == null) { throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } // get related target entity Object targetEntity = targetStore.createInstance(); ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues); targetEntity = targetStore.read(targetEntity); // set at source setValueAtNavigationField(sourceEntity, sourceField, targetEntity); // set at target Field targetField = commonNavInfo.getToField(); if (targetField != null) { setValueAtNavigationField(targetEntity, targetField, sourceEntity); } }
/** * Read the result data from the target store based on <code>sourceData</code> and <code>sourceField</code> * * @param targetStore * @param sourceData * @param sourceField * @return * @throws DataStoreException */ private List<Object> readResultData(final DataStore<?> targetStore, final Object sourceData, final Field sourceField) throws DataStoreException { Object navigationInstance = getValue(sourceField, sourceData); if (navigationInstance == null) { return Collections.emptyList(); } List<Object> resultData = new ArrayList<Object>(); for (Object targetInstance : targetStore.read()) { if (navigationInstance instanceof Collection) { for (Object object : (Collection<?>) navigationInstance) { if (targetStore.isKeyEqualChecked(targetInstance, object)) { resultData.add(targetInstance); } } } else if (targetStore.isKeyEqualChecked(targetInstance, navigationInstance)) { resultData.add(targetInstance); } } return resultData; }
@Override public Object readRelatedData(final EdmEntitySet sourceEntitySet, final Object sourceData, final EdmEntitySet targetEntitySet, final Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<?> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); final Field sourceField; if(navInfo.isBiDirectional()) { sourceField = navInfo.getToField(); } else { sourceField = navInfo.getFromField(); } if (sourceField == null) { throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } List<Object> resultData = readResultData(targetStore, sourceData, sourceField); return extractResultData(targetStore, targetKeys, navInfo, resultData); }
/** * {@inheritDoc} */ @Override public ODataService createAnnotationService(final String modelPackage) throws ODataException { AnnotationEdmProvider edmProvider = new AnnotationEdmProvider(modelPackage); AnnotationInMemoryDs dataSource = new AnnotationInMemoryDs(modelPackage); AnnotationValueAccess valueAccess = new AnnotationValueAccess(); // Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess return RuntimeDelegate.createODataSingleProcessorService(edmProvider, new ListsProcessor(dataSource, valueAccess)); }
@Override public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity, final EdmEntitySet targetEntitySet, final Map<String, Object> targetEntityValues) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { // get common data DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); // get and validate source fields Field sourceField = commonNavInfo.getFromField(); if (sourceField == null) { throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } // get related target entity Object targetEntity = targetStore.createInstance(); ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues); targetEntity = targetStore.read(targetEntity); // set at source setValueAtNavigationField(sourceEntity, sourceField, targetEntity); // set at target Field targetField = commonNavInfo.getToField(); if (targetField != null) { setValueAtNavigationField(targetEntity, targetField, sourceEntity); } }
/** * Read the result data from the target store based on <code>sourceData</code> and <code>sourceField</code> * * @param targetStore * @param sourceData * @param sourceField * @return * @throws DataStoreException */ private List<Object> readResultData(final DataStore<?> targetStore, final Object sourceData, final Field sourceField) throws DataStoreException { Object navigationInstance = getValue(sourceField, sourceData); if (navigationInstance == null) { return Collections.emptyList(); } List<Object> resultData = new ArrayList<Object>(); for (Object targetInstance : targetStore.read()) { if (navigationInstance instanceof Collection) { for (Object object : (Collection<?>) navigationInstance) { if (targetStore.isKeyEqualChecked(targetInstance, object)) { resultData.add(targetInstance); } } } else if (targetStore.isKeyEqualChecked(targetInstance, navigationInstance)) { resultData.add(targetInstance); } } return resultData; }
@Override public void createData(final EdmEntitySet entitySet, final Object data) throws ODataNotImplementedException, EdmException, ODataApplicationException { DataStore<Object> dataStore = getDataStore(entitySet); dataStore.create(data); }
@Override public Object readRelatedData(final EdmEntitySet sourceEntitySet, final Object sourceData, final EdmEntitySet targetEntitySet, final Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<?> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); final Field sourceField; if(navInfo.isBiDirectional()) { sourceField = navInfo.getToField(); } else { sourceField = navInfo.getFromField(); } if (sourceField == null) { throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } List<Object> resultData = readResultData(targetStore, sourceData, sourceField); return extractResultData(targetStore, targetKeys, navInfo, resultData); }
public AnnotationInMemoryDs(final Collection<Class<?>> annotatedClasses, final boolean persistInMemory) throws ODataException { this.persistInMemory = persistInMemory; init(annotatedClasses); }
/** * {@inheritDoc} */ @Override public ODataService createAnnotationService(final String modelPackage) throws ODataException { AnnotationEdmProvider edmProvider = new AnnotationEdmProvider(modelPackage); AnnotationInMemoryDs dataSource = new AnnotationInMemoryDs(modelPackage); AnnotationValueAccess valueAccess = new AnnotationValueAccess(); // Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess return RuntimeDelegate.createODataSingleProcessorService(edmProvider, new ListsProcessor(dataSource, valueAccess)); }
/** * Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code> * of <code>instance</code>. * * @param instance * @param field * @param value * @throws EdmException */ private void setValueAtNavigationField(final Object instance, final Field field, final Object value) throws EdmException { Class<?> fieldTypeClass = field.getType(); if (Collection.class.isAssignableFrom(fieldTypeClass)) { @SuppressWarnings("unchecked") Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField( instance, field.getName(), EdmNavigationProperty.class); if (collection == null) { collection = new ArrayList<Object>(); setValue(instance, field, collection); } collection.add(value); } else if (fieldTypeClass.isArray()) { throw new ODataRuntimeException("Write relations for internal used arrays is not supported."); } else { setValue(instance, field, value); } }
@Override public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity, final EdmEntitySet targetEntitySet, final Map<String, Object> targetEntityValues) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { // get common data DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); // get and validate source fields Field sourceField = commonNavInfo.getFromField(); if (sourceField == null) { throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } // get related target entity Object targetEntity = targetStore.createInstance(); ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues); targetEntity = targetStore.read(targetEntity); // set at source setValueAtNavigationField(sourceEntity, sourceField, targetEntity); // set at target Field targetField = commonNavInfo.getToField(); if (targetField != null) { setValueAtNavigationField(targetEntity, targetField, sourceEntity); } }
/** * Read the result data from the target store based on <code>sourceData</code> and <code>sourceField</code> * * @param targetStore * @param sourceData * @param sourceField * @return * @throws DataStoreException */ private List<Object> readResultData(final DataStore<?> targetStore, final Object sourceData, final Field sourceField) throws DataStoreException { Object navigationInstance = getValue(sourceField, sourceData); if (navigationInstance == null) { return Collections.emptyList(); } List<Object> resultData = new ArrayList<Object>(); for (Object targetInstance : targetStore.read()) { if (navigationInstance instanceof Collection) { for (Object object : (Collection<?>) navigationInstance) { if (targetStore.isKeyEqualChecked(targetInstance, object)) { resultData.add(targetInstance); } } } else if (targetStore.isKeyEqualChecked(targetInstance, navigationInstance)) { resultData.add(targetInstance); } } return resultData; }
@Override public void createData(final EdmEntitySet entitySet, final Object data) throws ODataNotImplementedException, EdmException, ODataApplicationException { DataStore<Object> dataStore = getDataStore(entitySet); dataStore.create(data); }
public AnnotationInMemoryDs(final Collection<Class<?>> annotatedClasses, final boolean persistInMemory) throws ODataException { this.persistInMemory = persistInMemory; init(annotatedClasses); }