diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/CommonRetrieveRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/CommonRetrieveRequestFactory.java index 02ca4eeb4..f8d48b329 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/CommonRetrieveRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/CommonRetrieveRequestFactory.java @@ -74,10 +74,13 @@ public interface CommonRetrieveRequestFactory extends Serializable { * Returned request gives the possibility to consume entities iterating on them without parsing and loading in memory * the entire entity set. * + * @param concreate ODataEntitySet implementation. + * @param concrete ODataEntity implementation. * @param uri request URI. * @return new {@link ODataEntitySetIteratorRequest} instance. */ - ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI uri); + + ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI uri); /** * Gets a query request returning a single OData entity. diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java index dd2cf46da..724b6441e 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/ODataEntitySetIteratorRequest.java @@ -19,10 +19,13 @@ package org.apache.olingo.client.api.communication.request.retrieve; import org.apache.olingo.client.api.domain.ODataEntitySetIterator; +import org.apache.olingo.commons.api.domain.CommonODataEntity; +import org.apache.olingo.commons.api.domain.CommonODataEntitySet; import org.apache.olingo.commons.api.format.ODataPubFormat; /** * This class implements an OData EntitySet query request. */ -public interface ODataEntitySetIteratorRequest extends ODataRetrieveRequest { +public interface ODataEntitySetIteratorRequest + extends ODataRetrieveRequest, ODataPubFormat> { } diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v3/RetrieveRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v3/RetrieveRequestFactory.java index 25276fe13..00568bdb8 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v3/RetrieveRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v3/RetrieveRequestFactory.java @@ -21,6 +21,7 @@ package org.apache.olingo.client.api.communication.request.retrieve.v3; import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.CommonRetrieveRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.commons.api.domain.v3.ODataEntity; @@ -33,6 +34,10 @@ public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory { @Override ODataEntitySetRequest getEntitySetRequest(URI uri); + @SuppressWarnings("unchecked") + @Override + ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI uri); + @SuppressWarnings("unchecked") @Override ODataEntityRequest getEntityRequest(URI uri); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java index 8d8184bca..63f351547 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/communication/request/retrieve/v4/RetrieveRequestFactory.java @@ -21,6 +21,7 @@ package org.apache.olingo.client.api.communication.request.retrieve.v4; import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.CommonRetrieveRequestFactory; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.commons.api.domain.v4.ODataEntity; @@ -33,6 +34,10 @@ public interface RetrieveRequestFactory extends CommonRetrieveRequestFactory { @Override ODataEntitySetRequest getEntitySetRequest(URI uri); + @SuppressWarnings("unchecked") + @Override + ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI uri); + @Override ODataEntityRequest getEntityRequest(URI uri); diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java index 66e347646..dd77a4441 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/domain/ODataEntitySetIterator.java @@ -42,7 +42,8 @@ import org.slf4j.LoggerFactory; *
* Please don't forget to call the close()>/ method when not needed any more. */ -public class ODataEntitySetIterator implements Iterator { +public class ODataEntitySetIterator + implements Iterator { /** * Logger. @@ -59,7 +60,7 @@ public class ODataEntitySetIterator implements Iterator { private Entry cached; - private CommonODataEntitySet entitySet; + private ES entitySet; private final ByteArrayOutputStream osFeed; @@ -104,6 +105,7 @@ public class ODataEntitySetIterator implements Iterator { * {@inheritDoc } */ @Override + @SuppressWarnings("unchecked") public boolean hasNext() { if (available && cached == null) { if (format == ODataPubFormat.ATOM) { @@ -114,7 +116,7 @@ public class ODataEntitySetIterator implements Iterator { if (cached == null) { available = false; - entitySet = odataClient.getReader(). + entitySet = (ES) odataClient.getReader(). readEntitySet(new ByteArrayInputStream(osFeed.toByteArray()), format); close(); } @@ -127,9 +129,10 @@ public class ODataEntitySetIterator implements Iterator { * {@inheritDoc } */ @Override - public CommonODataEntity next() { + public E next() { if (hasNext()) { - final CommonODataEntity res = odataClient.getBinder().getODataEntity(cached); + @SuppressWarnings("unchecked") + final E res = (E) odataClient.getBinder().getODataEntity(cached); cached = null; return res; } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractRetrieveRequestFactory.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractRetrieveRequestFactory.java index d8ec0f233..a801953b5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractRetrieveRequestFactory.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/AbstractRetrieveRequestFactory.java @@ -21,7 +21,6 @@ package org.apache.olingo.client.core.communication.request.retrieve; import java.net.URI; import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.CommonODataClient; -import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest; import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest; @@ -39,11 +38,6 @@ public abstract class AbstractRetrieveRequestFactory implements CommonRetrieveRe this.client = client; } - @Override - public ODataEntitySetIteratorRequest getEntitySetIteratorRequest(final URI query) { - return new ODataEntitySetIteratorRequestImpl(client, query); - } - @Override public ODataValueRequest getValueRequest(final URI query) { return new ODataValueRequestImpl(client, query); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java index bfdddef8f..a1e9a8bed 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetIteratorRequestImpl.java @@ -25,14 +25,16 @@ import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; import org.apache.olingo.client.api.domain.ODataEntitySetIterator; +import org.apache.olingo.commons.api.domain.CommonODataEntity; +import org.apache.olingo.commons.api.domain.CommonODataEntitySet; import org.apache.olingo.commons.api.format.ODataPubFormat; /** * This class implements an OData EntitySet query request. */ -public class ODataEntitySetIteratorRequestImpl - extends AbstractODataRetrieveRequest - implements ODataEntitySetIteratorRequest { +public class ODataEntitySetIteratorRequestImpl + extends AbstractODataRetrieveRequest, ODataPubFormat> + implements ODataEntitySetIteratorRequest { private ODataEntitySetIterator feedIterator = null; @@ -42,7 +44,7 @@ public class ODataEntitySetIteratorRequestImpl * @param odataClient client instance getting this request * @param query query to be executed. */ - ODataEntitySetIteratorRequestImpl(final CommonODataClient odataClient, final URI query) { + public ODataEntitySetIteratorRequestImpl(final CommonODataClient odataClient, final URI query) { super(odataClient, ODataPubFormat.class, query); } @@ -50,7 +52,7 @@ public class ODataEntitySetIteratorRequestImpl * {@inheritDoc } */ @Override - public ODataRetrieveResponse execute() { + public ODataRetrieveResponse> execute() { final HttpResponse res = doExecute(); return new ODataEntitySetIteratorResponseImpl(httpClient, res); } @@ -75,9 +77,9 @@ public class ODataEntitySetIteratorRequestImpl */ @Override @SuppressWarnings("unchecked") - public ODataEntitySetIterator getBody() { + public ODataEntitySetIterator getBody() { if (feedIterator == null) { - feedIterator = new ODataEntitySetIterator( + feedIterator = new ODataEntitySetIterator( odataClient, getRawResponse(), ODataPubFormat.fromString(getContentType())); } return feedIterator; diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/RetrieveRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/RetrieveRequestFactoryImpl.java index b32dd305a..394374790 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/RetrieveRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v3/RetrieveRequestFactoryImpl.java @@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.retrieve.v3; import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; @@ -28,6 +29,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkC import org.apache.olingo.client.api.communication.request.retrieve.v3.RetrieveRequestFactory; import org.apache.olingo.client.core.communication.request.retrieve.AbstractRetrieveRequestFactory; import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl; +import org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetIteratorRequestImpl; import org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl; import org.apache.olingo.client.core.communication.request.retrieve.ODataPropertyRequestImpl; import org.apache.olingo.commons.api.domain.v3.ODataEntity; @@ -60,6 +62,12 @@ public class RetrieveRequestFactoryImpl extends AbstractRetrieveRequestFactory return new ODataEntitySetRequestImpl(client, query); } + @SuppressWarnings("unchecked") + @Override + public ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI uri) { + return new ODataEntitySetIteratorRequestImpl(client, uri); + } + @SuppressWarnings("unchecked") @Override public ODataEntityRequest getEntityRequest(final URI query) { diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java index a32a1539c..96419c249 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/v4/RetrieveRequestFactoryImpl.java @@ -20,6 +20,7 @@ package org.apache.olingo.client.core.communication.request.retrieve.v4; import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest; import org.apache.olingo.client.api.communication.request.retrieve.XMLMetadataRequest; @@ -27,6 +28,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.v4.RetrieveRe import org.apache.olingo.client.api.v4.ODataClient; import org.apache.olingo.client.core.communication.request.retrieve.AbstractRetrieveRequestFactory; import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl; +import org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetIteratorRequestImpl; import org.apache.olingo.client.core.communication.request.retrieve.ODataEntitySetRequestImpl; import org.apache.olingo.client.core.communication.request.retrieve.ODataPropertyRequestImpl; import org.apache.olingo.commons.api.domain.v4.ODataEntity; @@ -54,6 +56,12 @@ public class RetrieveRequestFactoryImpl extends AbstractRetrieveRequestFactory return new ODataEntitySetRequestImpl(client, query); } + @SuppressWarnings("unchecked") + @Override + public ODataEntitySetIteratorRequest getEntitySetIteratorRequest(URI uri) { + return new ODataEntitySetIteratorRequestImpl(client, uri); + } + @SuppressWarnings("unchecked") @Override public ODataEntityRequest getEntityRequest(final URI query) { diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java index 446b41df5..0aaed018b 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java @@ -18,6 +18,10 @@ */ package org.apache.olingo.client.core.it.v3; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; @@ -29,12 +33,10 @@ import org.apache.olingo.client.api.domain.ODataEntitySetIterator; import org.apache.olingo.client.api.uri.CommonURIBuilder; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.domain.CommonODataEntitySet; +import org.apache.olingo.commons.api.domain.v3.ODataEntity; import org.apache.olingo.commons.api.domain.v3.ODataEntitySet; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.apache.olingo.commons.core.op.ResourceFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import org.junit.Test; /** @@ -115,12 +117,12 @@ public class EntitySetTestITCase extends AbstractTestITCase { final CommonURIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()); uriBuilder.appendEntitySetSegment("Customer"); - final ODataEntitySetIteratorRequest req = + final ODataEntitySetIteratorRequest req = client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build()); req.setFormat(format); - final ODataRetrieveResponse res = req.execute(); - final ODataEntitySetIterator feedIterator = res.getBody(); + final ODataRetrieveResponse> res = req.execute(); + final ODataEntitySetIterator feedIterator = res.getBody(); assertNotNull(feedIterator); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java index a73ce7aec..c354a1d5e 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java @@ -18,6 +18,10 @@ */ package org.apache.olingo.client.core.it.v4; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.URI; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest; @@ -29,13 +33,10 @@ import org.apache.olingo.client.api.domain.ODataEntitySetIterator; import org.apache.olingo.client.api.uri.CommonURIBuilder; import org.apache.olingo.client.core.uri.URIUtils; import org.apache.olingo.commons.api.domain.CommonODataEntitySet; +import org.apache.olingo.commons.api.domain.v4.ODataEntity; import org.apache.olingo.commons.api.domain.v4.ODataEntitySet; import org.apache.olingo.commons.api.format.ODataPubFormat; import org.apache.olingo.commons.core.op.ResourceFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - import org.junit.Ignore; import org.junit.Test; @@ -124,11 +125,11 @@ public class EntitySetTestITCase extends AbstractTestITCase { final CommonURIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()); uriBuilder.appendEntitySetSegment("People"); - final ODataEntitySetIteratorRequest req = + final ODataEntitySetIteratorRequest req = client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build()); req.setFormat(format); - final ODataRetrieveResponse res = req.execute(); + final ODataRetrieveResponse> res = req.execute(); final ODataEntitySetIterator feedIterator = res.getBody(); assertNotNull(feedIterator);