@Override public List<?> readData(final EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { DataStore<Object> holder = getDataStore(entitySet); if (holder != null) { return new ArrayList<Object>(holder.read()); } throw new ODataNotFoundException(ODataNotFoundException.ENTITY); }
@Override public List<?> readData(final EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { DataStore<Object> holder = getDataStore(entitySet); if (holder != null) { return new ArrayList<Object>(holder.read()); } throw new ODataNotFoundException(ODataNotFoundException.ENTITY); }
@Override public List<?> readData(final EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { DataStore<Object> holder = getDataStore(entitySet); if (holder != null) { return new ArrayList<Object>(holder.read()); } throw new ODataNotFoundException(ODataNotFoundException.ENTITY); }
/** * 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; }
/** * 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; }
/** * 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 readData(final EdmEntitySet entitySet, final Map<String, Object> keys) throws ODataNotFoundException, EdmException, ODataApplicationException { DataStore<Object> store = getDataStore(entitySet); if (store != null) { Object keyInstance = store.createInstance(); ANNOTATION_HELPER.setKeyFields(keyInstance, keys); Object result = store.read(keyInstance); if (result != null) { return result; } } throw new ODataNotFoundException(ODataNotFoundException.ENTITY); }
@Override public Object readData(final EdmEntitySet entitySet, final Map<String, Object> keys) throws ODataNotFoundException, EdmException, ODataApplicationException { DataStore<Object> store = getDataStore(entitySet); if (store != null) { Object keyInstance = store.createInstance(); ANNOTATION_HELPER.setKeyFields(keyInstance, keys); Object result = store.read(keyInstance); if (result != null) { return result; } } throw new ODataNotFoundException(ODataNotFoundException.ENTITY); }
@Override public Object readData(final EdmEntitySet entitySet, final Map<String, Object> keys) throws ODataNotFoundException, EdmException, ODataApplicationException { DataStore<Object> store = getDataStore(entitySet); if (store != null) { Object keyInstance = store.createInstance(); ANNOTATION_HELPER.setKeyFields(keyInstance, keys); Object result = store.read(keyInstance); if (result != null) { return result; } } throw new ODataNotFoundException(ODataNotFoundException.ENTITY); }
@Override public BinaryData readBinaryData(final EdmEntitySet entitySet, final Object mediaLinkEntryData) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class); Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class); if (data == null && mimeType == null) { DataStore<Object> dataStore = getDataStore(entitySet); Object readEntry = dataStore.read(mediaLinkEntryData); if (readEntry != null) { data = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceContent.class); mimeType = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceMimeType.class); } } return new BinaryData((byte[]) data, String.valueOf(mimeType)); }
@Override public BinaryData readBinaryData(final EdmEntitySet entitySet, final Object mediaLinkEntryData) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class); Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class); if (data == null && mimeType == null) { DataStore<Object> dataStore = getDataStore(entitySet); Object readEntry = dataStore.read(mediaLinkEntryData); if (readEntry != null) { data = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceContent.class); mimeType = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceMimeType.class); } } return new BinaryData((byte[]) data, String.valueOf(mimeType)); }
@Override public BinaryData readBinaryData(final EdmEntitySet entitySet, final Object mediaLinkEntryData) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class); Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class); if (data == null && mimeType == null) { DataStore<Object> dataStore = getDataStore(entitySet); Object readEntry = dataStore.read(mediaLinkEntryData); if (readEntry != null) { data = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceContent.class); mimeType = ANNOTATION_HELPER.getValueForField(readEntry, EdmMediaResourceMimeType.class); } } return new BinaryData((byte[]) data, String.valueOf(mimeType)); }
@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); } }
@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); } }
@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); } }
@Override public void writeBinaryData(final EdmEntitySet entitySet, final Object mediaEntityInstance, final BinaryData binaryData) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { try { DataStore<Object> dataStore = getDataStore(entitySet); Object readEntry = dataStore.read(mediaEntityInstance); if (readEntry == null) { throw new ODataNotFoundException(ODataNotFoundException.ENTITY); } else { ANNOTATION_HELPER.setValueForAnnotatedField( mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData()); ANNOTATION_HELPER.setValueForAnnotatedField( mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType()); } } catch (ODataAnnotationException e) { throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName() + "' with message '" + e.getMessage() + "'.", e); } }
@Override public void writeBinaryData(final EdmEntitySet entitySet, final Object mediaEntityInstance, final BinaryData binaryData) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { try { DataStore<Object> dataStore = getDataStore(entitySet); Object readEntry = dataStore.read(mediaEntityInstance); if (readEntry == null) { throw new ODataNotFoundException(ODataNotFoundException.ENTITY); } else { ANNOTATION_HELPER.setValueForAnnotatedField( mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData()); ANNOTATION_HELPER.setValueForAnnotatedField( mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType()); } } catch (ODataAnnotationException e) { throw new AnnotationRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName() + "' with message '" + e.getMessage() + "'.", e); } }
@Override public void writeBinaryData(final EdmEntitySet entitySet, final Object mediaEntityInstance, final BinaryData binaryData) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { try { DataStore<Object> dataStore = getDataStore(entitySet); Object readEntry = dataStore.read(mediaEntityInstance); if (readEntry == null) { throw new ODataNotFoundException(ODataNotFoundException.ENTITY); } else { ANNOTATION_HELPER.setValueForAnnotatedField( mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData()); ANNOTATION_HELPER.setValueForAnnotatedField( mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType()); } } catch (ODataAnnotationException e) { throw new AnnotationRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName() + "' with message '" + e.getMessage() + "'.", e); } }