You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2014/07/16 11:27:11 UTC
[48/58] [abbrv] git commit: provided the possibility to specify query
options at proxy layer
provided the possibility to specify query options at proxy layer
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/baf2cd10
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/baf2cd10
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/baf2cd10
Branch: refs/heads/master
Commit: baf2cd10984cdd7b036bb1df1ab8f4bcef76e3a1
Parents: 2df9426
Author: fmartelli <fa...@gmail.com>
Authored: Sun Jul 13 18:08:58 2014 +0200
Committer: fmartelli <fa...@gmail.com>
Committed: Sun Jul 13 18:08:58 2014 +0200
----------------------------------------------------------------------
.../ext/proxy/EntityContainerFactory.java | 165 ----------------
.../org/apache/olingo/ext/proxy/Service.java | 165 ++++++++++++++++
.../olingo/ext/proxy/api/AbstractEntitySet.java | 40 +---
.../olingo/ext/proxy/api/AbstractSingleton.java | 7 -
.../olingo/ext/proxy/api/CollectionQuery.java | 71 ++++++-
.../olingo/ext/proxy/api/CommonQuery.java | 45 +++++
.../org/apache/olingo/ext/proxy/api/Filter.java | 131 -------------
.../olingo/ext/proxy/api/SingleQuery.java | 4 +-
.../commons/AbstractInvocationHandler.java | 6 +-
.../commons/AbstractPersistenceManager.java | 6 +-
.../AbstractStructuredInvocationHandler.java | 5 +-
.../EntityContainerInvocationHandler.java | 8 +-
.../proxy/commons/EntityInvocationHandler.java | 44 +++--
.../commons/EntitySetInvocationHandler.java | 130 ++++++++-----
.../ext/proxy/commons/EntitySetIterator.java | 3 +-
.../olingo/ext/proxy/commons/FilterImpl.java | 174 -----------------
.../NonTransactionalPersistenceManagerImpl.java | 4 +-
.../olingo/ext/proxy/commons/SearchImpl.java | 4 +-
.../commons/SingletonInvocationHandler.java | 6 +-
.../TransactionalPersistenceManagerImpl.java | 4 +-
.../olingo/ext/pojogen/AbstractPOJOGenMojo.java | 13 ++
.../src/main/resources/complexCreator.vm | 32 ++++
.../src/main/resources/entityCreator.vm | 37 ++++
.../src/main/resources/entityType.vm | 4 +-
.../olingo/fit/proxy/v3/AbstractTestITCase.java | 14 +-
.../proxy/v3/ActionOverloadingTestITCase.java | 26 +--
.../olingo/fit/proxy/v3/AsyncTestITCase.java | 69 +++----
.../olingo/fit/proxy/v3/ContextTestITCase.java | 188 +++++++++----------
.../fit/proxy/v3/EntityCreateTestITCase.java | 40 ++--
.../fit/proxy/v3/EntityRetrieveTestITCase.java | 18 +-
.../fit/proxy/v3/EntitySetTestITCase.java | 6 +-
.../fit/proxy/v3/EntityUpdateTestITCase.java | 18 +-
.../olingo/fit/proxy/v3/FilterTestITCase.java | 79 ++++----
.../olingo/fit/proxy/v3/InvokeTestITCase.java | 16 +-
.../fit/proxy/v3/MediaEntityTestITCase.java | 16 +-
.../olingo/fit/proxy/v3/OpenTypeTestITCase.java | 14 +-
.../fit/proxy/v3/PrimitiveKeysTestITCase.java | 26 +--
.../olingo/fit/proxy/v3/PropertyTestITCase.java | 8 +-
.../olingo/fit/proxy/v4/AbstractTestITCase.java | 20 +-
.../olingo/fit/proxy/v4/AsyncTestITCase.java | 6 +-
.../proxy/v4/AuthEntityCreateTestITCase.java | 8 +-
.../proxy/v4/AuthEntityRetrieveTestITCase.java | 4 +-
.../v4/BoundOperationInvokeTestITCase.java | 23 +--
.../fit/proxy/v4/DerivedTypeTestITCase.java | 8 +-
.../fit/proxy/v4/EntityCreateTestITCase.java | 39 ++--
.../fit/proxy/v4/EntityRetrieveTestITCase.java | 18 +-
.../fit/proxy/v4/EntitySetTestITCase.java | 4 +-
.../fit/proxy/v4/EntityUpdateTestITCase.java | 25 +--
.../olingo/fit/proxy/v4/FilterTestITCase.java | 48 ++++-
.../fit/proxy/v4/KeyAsSegmentTestITCase.java | 14 +-
.../fit/proxy/v4/MediaEntityTestITCase.java | 18 +-
...TransactionalAuthEntityCreateTestITCase.java | 8 +-
.../NonTransactionalEntityCreateTestITCase.java | 8 +-
.../NonTransactionalEntityUpdateTestITCase.java | 8 +-
.../NonTransactionalMediaEntityTestITCase.java | 8 +-
.../olingo/fit/proxy/v4/OpenTypeTestITCase.java | 14 +-
.../olingo/fit/proxy/v4/PropertyTestITCase.java | 6 +-
.../fit/proxy/v4/SingletonTestITCase.java | 10 +-
.../v4/UnauthorizedEntityCreateTestITCase.java | 8 +-
.../services/odatawcfservice/types/Account.java | 6 +-
.../odatawcfservice/types/CreditCardPI.java | 3 +-
.../types/PaymentInstrument.java | 3 +-
.../odatawcfservice/types/PublicCompany.java | 3 +-
63 files changed, 964 insertions(+), 1002 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
deleted file mode 100644
index 84b4995..0000000
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/EntityContainerFactory.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.ext.proxy;
-
-import java.lang.reflect.Proxy;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.ext.proxy.api.PersistenceManager;
-import org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler;
-import org.apache.olingo.ext.proxy.commons.NonTransactionalPersistenceManagerImpl;
-import org.apache.olingo.ext.proxy.commons.TransactionalPersistenceManagerImpl;
-import org.apache.olingo.ext.proxy.context.Context;
-
-/**
- * Entry point for proxy mode, gives access to entity container instances.
- *
- * @param <C> actual client class
- */
-public final class EntityContainerFactory<C extends CommonEdmEnabledODataClient<?>> {
-
- private static final Map<String, EntityContainerFactory<?>> FACTORY_PER_SERVICEROOT =
- new ConcurrentHashMap<String, EntityContainerFactory<?>>();
-
- private final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>, Object>();
-
- @SuppressWarnings("unchecked")
- private static <C extends CommonEdmEnabledODataClient<?>> EntityContainerFactory<C> getInstance(
- final C client, final boolean transactional) {
-
- if (!FACTORY_PER_SERVICEROOT.containsKey(client.getServiceRoot())) {
- client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON_FULL_METADATA);
- final EntityContainerFactory<C> instance = new EntityContainerFactory<C>(client, transactional);
- FACTORY_PER_SERVICEROOT.put(client.getServiceRoot(), instance);
- }
-
- return (EntityContainerFactory<C>) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot());
- }
-
- /**
- * Gives an OData 3.0 instance for given service root, operating in transactions (with batch requests).
- *
- * @param serviceRoot OData service root
- * @return OData 3.0 instance for given service root, operating in transactions (with batch requests)
- */
- public static EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
- final String serviceRoot) {
-
- return getV3(serviceRoot, true);
- }
-
- /**
- * Gives an OData 3.0 instance for given service root.
- *
- * @param serviceRoot OData service root
- * @param transactional whether operating in transactions (with batch requests) or not
- * @return OData 3.0 instance for given service root
- */
- public static EntityContainerFactory<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
- final String serviceRoot, final boolean transactional) {
-
- return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), transactional);
- }
-
- /**
- * Gives an OData 4.0 instance for given service root, operating in transactions (with batch requests).
- *
- * @param serviceRoot OData service root
- * @return OData 4.0 instance for given service root, operating in transactions (with batch requests)
- */
- public static EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
- final String serviceRoot) {
-
- return getV4(serviceRoot, true);
- }
-
- /**
- * Gives an OData 4.0 instance for given service root.
- *
- * @param serviceRoot OData service root
- * @param transactional whether operating in transactions (with batch requests) or not
- * @return OData 4.0 instance for given service root
- */
- public static EntityContainerFactory<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
- final String serviceRoot, final boolean transactional) {
-
- return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), transactional);
- }
-
- private final CommonEdmEnabledODataClient<?> client;
-
- private final Context context;
-
- private final boolean transactional;
-
- private PersistenceManager persistenceManager;
-
- private EntityContainerFactory(final CommonEdmEnabledODataClient<?> client, final boolean transactional) {
- this.client = client;
- this.context = new Context();
- this.transactional = transactional;
- }
-
- @SuppressWarnings("unchecked")
- public C getClient() {
- return (C) client;
- }
-
- public Context getContext() {
- return context;
- }
-
- public boolean isTransactional() {
- return transactional;
- }
-
- public PersistenceManager getPersistenceManager() {
- synchronized (this) {
- if (persistenceManager == null) {
- persistenceManager = transactional
- ? new TransactionalPersistenceManagerImpl(this)
- : new NonTransactionalPersistenceManagerImpl(this);
- }
- }
- return persistenceManager;
- }
-
- /**
- * Return an initialized concrete implementation of the passed EntityContainer interface.
- *
- * @param <T> interface annotated as EntityContainer
- * @param reference class object of the EntityContainer annotated interface
- * @return an initialized concrete implementation of the passed reference
- * @throws IllegalArgumentException if the passed reference is not an interface annotated as EntityContainer
- */
- public <T> T getEntityContainer(final Class<T> reference) throws IllegalStateException, IllegalArgumentException {
- if (!ENTITY_CONTAINERS.containsKey(reference)) {
- final Object entityContainer = Proxy.newProxyInstance(
- Thread.currentThread().getContextClassLoader(),
- new Class<?>[] {reference},
- EntityContainerInvocationHandler.getInstance(reference, this));
- ENTITY_CONTAINERS.put(reference, entityContainer);
- }
- return reference.cast(ENTITY_CONTAINERS.get(reference));
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java
new file mode 100644
index 0000000..3611090
--- /dev/null
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/Service.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.ext.proxy;
+
+import java.lang.reflect.Proxy;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.olingo.client.api.CommonEdmEnabledODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.ext.proxy.api.PersistenceManager;
+import org.apache.olingo.ext.proxy.commons.EntityContainerInvocationHandler;
+import org.apache.olingo.ext.proxy.commons.NonTransactionalPersistenceManagerImpl;
+import org.apache.olingo.ext.proxy.commons.TransactionalPersistenceManagerImpl;
+import org.apache.olingo.ext.proxy.context.Context;
+
+/**
+ * Entry point for proxy mode, gives access to entity container instances.
+ *
+ * @param <C> actual client class
+ */
+public final class Service<C extends CommonEdmEnabledODataClient<?>> {
+
+ private static final Map<String, Service<?>> FACTORY_PER_SERVICEROOT =
+ new ConcurrentHashMap<String, Service<?>>();
+
+ private final Map<Class<?>, Object> ENTITY_CONTAINERS = new ConcurrentHashMap<Class<?>, Object>();
+
+ @SuppressWarnings("unchecked")
+ private static <C extends CommonEdmEnabledODataClient<?>> Service<C> getInstance(
+ final C client, final boolean transactional) {
+
+ if (!FACTORY_PER_SERVICEROOT.containsKey(client.getServiceRoot())) {
+ client.getConfiguration().setDefaultPubFormat(ODataFormat.JSON_FULL_METADATA);
+ final Service<C> instance = new Service<C>(client, transactional);
+ FACTORY_PER_SERVICEROOT.put(client.getServiceRoot(), instance);
+ }
+
+ return (Service<C>) FACTORY_PER_SERVICEROOT.get(client.getServiceRoot());
+ }
+
+ /**
+ * Gives an OData 3.0 instance for given service root, operating in transactions (with batch requests).
+ *
+ * @param serviceRoot OData service root
+ * @return OData 3.0 instance for given service root, operating in transactions (with batch requests)
+ */
+ public static Service<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
+ final String serviceRoot) {
+
+ return getV3(serviceRoot, true);
+ }
+
+ /**
+ * Gives an OData 3.0 instance for given service root.
+ *
+ * @param serviceRoot OData service root
+ * @param transactional whether operating in transactions (with batch requests) or not
+ * @return OData 3.0 instance for given service root
+ */
+ public static Service<org.apache.olingo.client.api.v3.EdmEnabledODataClient> getV3(
+ final String serviceRoot, final boolean transactional) {
+
+ return getInstance(ODataClientFactory.getEdmEnabledV3(serviceRoot), transactional);
+ }
+
+ /**
+ * Gives an OData 4.0 instance for given service root, operating in transactions (with batch requests).
+ *
+ * @param serviceRoot OData service root
+ * @return OData 4.0 instance for given service root, operating in transactions (with batch requests)
+ */
+ public static Service<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
+ final String serviceRoot) {
+
+ return getV4(serviceRoot, true);
+ }
+
+ /**
+ * Gives an OData 4.0 instance for given service root.
+ *
+ * @param serviceRoot OData service root
+ * @param transactional whether operating in transactions (with batch requests) or not
+ * @return OData 4.0 instance for given service root
+ */
+ public static Service<org.apache.olingo.client.api.v4.EdmEnabledODataClient> getV4(
+ final String serviceRoot, final boolean transactional) {
+
+ return getInstance(ODataClientFactory.getEdmEnabledV4(serviceRoot), transactional);
+ }
+
+ private final CommonEdmEnabledODataClient<?> client;
+
+ private final Context context;
+
+ private final boolean transactional;
+
+ private PersistenceManager persistenceManager;
+
+ private Service(final CommonEdmEnabledODataClient<?> client, final boolean transactional) {
+ this.client = client;
+ this.context = new Context();
+ this.transactional = transactional;
+ }
+
+ @SuppressWarnings("unchecked")
+ public C getClient() {
+ return (C) client;
+ }
+
+ public Context getContext() {
+ return context;
+ }
+
+ public boolean isTransactional() {
+ return transactional;
+ }
+
+ public PersistenceManager getPersistenceManager() {
+ synchronized (this) {
+ if (persistenceManager == null) {
+ persistenceManager = transactional
+ ? new TransactionalPersistenceManagerImpl(this)
+ : new NonTransactionalPersistenceManagerImpl(this);
+ }
+ }
+ return persistenceManager;
+ }
+
+ /**
+ * Return an initialized concrete implementation of the passed EntityContainer interface.
+ *
+ * @param <T> interface annotated as EntityContainer
+ * @param reference class object of the EntityContainer annotated interface
+ * @return an initialized concrete implementation of the passed reference
+ * @throws IllegalArgumentException if the passed reference is not an interface annotated as EntityContainer
+ */
+ public <T> T getEntityContainer(final Class<T> reference) throws IllegalStateException, IllegalArgumentException {
+ if (!ENTITY_CONTAINERS.containsKey(reference)) {
+ final Object entityContainer = Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(),
+ new Class<?>[] {reference},
+ EntityContainerInvocationHandler.getInstance(reference, this));
+ ENTITY_CONTAINERS.put(reference, entityContainer);
+ }
+ return reference.cast(ENTITY_CONTAINERS.get(reference));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
index 71a7392..302096e 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
@@ -24,7 +24,7 @@ import java.io.Serializable;
* Interface for synchronous CRUD operations on an EntitySet.
*/
public interface AbstractEntitySet<
- T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+ T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
extends Iterable<T>, Serializable {
/**
@@ -43,7 +43,7 @@ public interface AbstractEntitySet<
* @return the entity with the given id or null if none found
* @throws IllegalArgumentException in case the given key is null
*/
- T get(KEY key) throws IllegalArgumentException;
+ T getByKey(KEY key) throws IllegalArgumentException;
/**
* Retrieves an entity by its key, considering polymorphism.
@@ -54,7 +54,7 @@ public interface AbstractEntitySet<
* @return the entity with the given id or null if none found
* @throws IllegalArgumentException in case the given key is null
*/
- <S extends T> S get(KEY key, Class<S> reference) throws IllegalArgumentException;
+ <S extends T> S getByKey(KEY key, Class<S> reference) throws IllegalArgumentException;
/**
* Returns the number of entities available.
@@ -64,23 +64,6 @@ public interface AbstractEntitySet<
Long count();
/**
- * Returns all instances.
- *
- * @return all entities
- */
- EC getAll();
-
- /**
- * Returns all instances of the given subtype.
- *
- * @param <S>
- * @param <SEC>
- * @param reference entity collection class to be returned
- * @return all entities of the given subtype
- */
- <S extends T, SEC extends AbstractEntityCollection<S>> SEC getAll(Class<SEC> reference);
-
- /**
* Deletes the entity with the given key.
*
* @param key must not be null
@@ -97,23 +80,6 @@ public interface AbstractEntitySet<
<S extends T> void delete(Iterable<S> entities);
/**
- * Create an instance of <tt>Filter</tt>.
- *
- * @return the new filter instance
- */
- Filter<T, EC> createFilter();
-
- /**
- * Create an instance of <tt>Filter</tt>.
- *
- * @param <S>
- * @param <SEC>
- * @param reference
- * @return the new filter instance
- */
- <S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> createFilter(Class<SEC> reference);
-
- /**
* Create an instance of <tt>Search</tt>.
*
* @return the new search instance
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java
index fb2feca..4468653 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractSingleton.java
@@ -23,11 +23,4 @@ import java.io.Serializable;
public interface AbstractSingleton<
T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
extends Serializable {
-
- /**
- * Retrieves a singleton.
- *
- * @return the singleton
- */
- T get();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java
index 2acd0f1..9be7020 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CollectionQuery.java
@@ -18,13 +18,78 @@
*/
package org.apache.olingo.ext.proxy.api;
-import java.io.Serializable;
+import org.apache.olingo.client.api.uri.URIFilter;
-public interface CollectionQuery<T extends Serializable, EC extends AbstractEntityCollection<T>> {
+public interface CollectionQuery<T extends StructuredType, EC extends AbstractEntityCollection<T>>
+ extends CommonQuery<CollectionQuery<T, EC>> {
/**
+ * Returns all instances.
*
- * @return structured type.
+ * @return all entities
*/
EC execute();
+
+ /**
+ * Returns all instances of the given subtype.
+ *
+ * @param <S>
+ * @param <SEC>
+ * @param reference entity collection class to be returned
+ * @return all entities of the given subtype
+ */
+ <S extends T, SEC extends AbstractEntityCollection<S>> SEC execute(Class<SEC> reference);
+
+ /**
+ * Sets the <tt>$filter</tt> expression.
+ * <br/>
+ * Any of available operators and functions can be embodied here.
+ *
+ * @param filter the <tt>$filter</tt> expression.
+ * @return the same query instance.
+ */
+ CollectionQuery<T, EC> filter(String filter);
+
+ /**
+ * Sets the filter generating the <tt>$filter</tt> expression.
+ *
+ * @param filter filter instance (to be obtained via factory): note that <tt>build()</tt> method will be immediately
+ * invoked.
+ * @return the same query instance.
+ */
+ CollectionQuery<T, EC> filter(URIFilter filter);
+
+ /**
+ * Sets the <tt>$orderBy</tt> expression.
+ *
+ * @param sort sort options.
+ * @return the same query instance.
+ */
+ CollectionQuery<T, EC> orderBy(Sort... sort);
+
+ /**
+ * Sets the <tt>$orderBy</tt> expression.
+ *
+ * @param orderBy the <tt>$orderBy</tt> expression.
+ * @return the same query instance.
+ */
+ CollectionQuery<T, EC> orderBy(String orderBy);
+
+ /**
+ * Sets the maximum number of results to retrieve (<tt>$top</tt>).
+ *
+ * @param top maximum number of results to retrieve
+ * @return the same query instance.
+ * @throws IllegalArgumentException if the argument is negative
+ */
+ CollectionQuery<T, EC> top(int top) throws IllegalArgumentException;
+
+ /**
+ * Sets the position of the first result to retrieve (<tt>$skip</tt>).
+ *
+ * @param skip position of the first result, numbered from 0
+ * @return the same query instance.
+ * @throws IllegalArgumentException if the argument is negative
+ */
+ CollectionQuery<T, EC> skip(int skip) throws IllegalArgumentException;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java
new file mode 100644
index 0000000..4c24bc4
--- /dev/null
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/CommonQuery.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.ext.proxy.api;
+
+public interface CommonQuery<T> {
+
+ /**
+ * Sets <tt>$expand</tt> expression.
+ *
+ * @param expand <tt>$expand</tt> expression items.
+ * @return the same query instance.
+ */
+ T expand(String... expand);
+
+ /**
+ * Sets <tt>$select</tt> expression.
+ *
+ * @param select <tt>$select</tt> expression items.
+ * @return the same query instance.
+ */
+ T select(String... select);
+
+ /**
+ * Remove all query options.
+ *
+ * @return the same query instance.
+ */
+ T clear();
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java
deleted file mode 100644
index 11b3e83..0000000
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Filter.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.ext.proxy.api;
-
-import java.io.Serializable;
-import org.apache.olingo.client.api.uri.URIFilter;
-
-/**
- * Interface used to control filter execution.
- *
- * @param <T> filter result type
- * @param <EC>
- */
-public interface Filter<T extends Serializable, EC extends AbstractEntityCollection<T>> extends Serializable {
-
- /**
- * Sets the <tt>$filter</tt> expression for this filter.
- * <br/>
- * Any of available operators and functions can be embodied here.
- *
- * @param filter the <tt>$filter</tt> expression for this filter
- * @return the same filter instance
- */
- Filter<T, EC> setFilter(String filter);
-
- /**
- * Sets the filter generating the <tt>$filter</tt> expression for this filter.
- *
- * @param filter filter instance (to be obtained via factory): note that <tt>build()</tt> method
- * will be immediately invoked.
- * @return the same filter instance
- */
- Filter<T, EC> setFilter(URIFilter filter);
-
- /**
- * The <tt>$filter</tt> expression for this filter.
- *
- * @return the <tt>$filter</tt> expression for this filter
- */
- String getFilter();
-
- /**
- * Sets the <tt>$orderBy</tt> expression for this filter via sort options.
- *
- * @param sort sort options
- * @return the same filter instance
- */
- Filter<T, EC> setOrderBy(Sort... sort);
-
- /**
- * Sets the <tt>$orderBy</tt> expression for this filter.
- *
- * @param orderBy the <tt>$orderBy</tt> expression for this filter
- * @return the same filter instance
- */
- Filter<T, EC> setOrderBy(String orderBy);
-
- /**
- * The <tt>$orderBy</tt> expression for this filter.
- *
- * @return the <tt>$orderBy</tt> expression for this filter
- */
- String getOrderBy();
-
- /**
- * Sets the maximum number of results to retrieve (<tt>$top</tt>).
- *
- * @param maxResults maximum number of results to retrieve
- * @return the same filter instance
- * @throws IllegalArgumentException if the argument is negative
- */
- Filter<T, EC> setMaxResults(int maxResults) throws IllegalArgumentException;
-
- /**
- * The maximum number of results the filter object was set to retrieve (<tt>$top</tt>). Returns
- * <tt>Integer.MAX_VALUE</tt> if setMaxResults was not applied to the filter object.
- *
- * @return maximum number of results
- */
- int getMaxResults();
-
- /**
- * Sets the position of the first result to retrieve (<tt>$skip</tt>).
- *
- * @param firstResult position of the first result, numbered from 0
- * @return the same filter instance
- * @throws IllegalArgumentException if the argument is negative
- */
- Filter<T, EC> setFirstResult(int firstResult) throws IllegalArgumentException;
-
- /**
- * The position of the first result the filter object was set to retrieve (<tt>$skip</tt>).
- *
- * Returns 0 if <tt>setFirstResult</tt> was not applied to the filter object.
- *
- * @return position of the first result
- */
- int getFirstResult();
-
- /**
- * Executes a <tt>$filter</tt> filter that returns a single result.
- *
- * @return the result
- * @throws NoResultException if there is no result
- * @throws NonUniqueResultException if more than one result
- */
- T getSingleResult() throws NoResultException, NonUniqueResultException;
-
- /**
- * Executes a <tt>$filter</tt> filter and return the filter results as collection.
- *
- * @return an iterable view of the results
- */
- EC getResult();
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java
index 66c7b74..9a43d8b 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/SingleQuery.java
@@ -18,10 +18,10 @@
*/
package org.apache.olingo.ext.proxy.api;
-public interface SingleQuery<T extends StructuredType> {
+public interface SingleQuery<T extends StructuredType> extends CommonQuery<T> {
/**
- *
+ *
* @return structured type.
*/
T load();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
index a35712a..52e356a 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractInvocationHandler.java
@@ -47,7 +47,7 @@ import org.apache.olingo.commons.api.edm.EdmOperation;
import org.apache.olingo.commons.api.edm.EdmReturnType;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.api.OperationType;
import org.apache.olingo.ext.proxy.api.annotations.Operation;
import org.apache.olingo.ext.proxy.api.annotations.Parameter;
@@ -60,11 +60,11 @@ abstract class AbstractInvocationHandler implements InvocationHandler {
private static final long serialVersionUID = 358520026931462958L;
- protected EntityContainerFactory<?> factory;
+ protected Service<?> factory;
protected EntityContainerInvocationHandler containerHandler;
- protected AbstractInvocationHandler(final EntityContainerFactory<?> factory) {
+ protected AbstractInvocationHandler(final Service<?> factory) {
this.factory = factory;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
index d53e68e..e68bfc1 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractPersistenceManager.java
@@ -42,7 +42,7 @@ import org.apache.olingo.commons.api.domain.ODataLinkType;
import org.apache.olingo.commons.api.domain.v4.ODataEntity;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.api.PersistenceManager;
import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty;
import org.apache.olingo.ext.proxy.context.AttachedEntity;
@@ -61,9 +61,9 @@ abstract class AbstractPersistenceManager implements PersistenceManager {
private static final long serialVersionUID = 2065240290461241515L;
- protected final EntityContainerFactory<?> factory;
+ protected final Service<?> factory;
- AbstractPersistenceManager(final EntityContainerFactory<?> factory) {
+ AbstractPersistenceManager(final Service<?> factory) {
this.factory = factory;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
index 0d12d73..b5204cf 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/AbstractStructuredInvocationHandler.java
@@ -115,7 +115,10 @@ public abstract class AbstractStructuredInvocationHandler extends AbstractInvoca
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- if (isSelfMethod(method, args)) {
+ if ("expand".equals(method.getName()) || "select".equals(method.getName())) {
+ invokeSelfMethod(method, args);
+ return proxy;
+ } else if (isSelfMethod(method, args)) {
return invokeSelfMethod(method, args);
} else if ("load".equals(method.getName()) && ArrayUtils.isEmpty(args)) {
load();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
index 56bcc6d..80d3ac3 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityContainerInvocationHandler.java
@@ -22,7 +22,7 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import org.apache.commons.lang3.ArrayUtils;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
import org.apache.olingo.ext.proxy.api.annotations.EntityContainer;
import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
import org.apache.olingo.ext.proxy.api.annotations.Singleton;
@@ -39,14 +39,14 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
private final boolean defaultEC;
public static EntityContainerInvocationHandler getInstance(
- final Class<?> ref, final EntityContainerFactory<?> factory) {
+ final Class<?> ref, final Service<?> factory) {
final EntityContainerInvocationHandler instance = new EntityContainerInvocationHandler(ref, factory);
instance.containerHandler = instance;
return instance;
}
- private EntityContainerInvocationHandler(final Class<?> ref, final EntityContainerFactory<?> factory) {
+ private EntityContainerInvocationHandler(final Class<?> ref, final Service<?> factory) {
super(factory);
final Annotation annotation = ref.getAnnotation(EntityContainer.class);
@@ -60,7 +60,7 @@ public final class EntityContainerInvocationHandler extends AbstractInvocationHa
this.namespace = ((EntityContainer) annotation).namespace();
}
- protected EntityContainerFactory<?> getFactory() {
+ protected Service<?> getFactory() {
return factory;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
index a5b68c0..cd9c936 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntityInvocationHandler.java
@@ -67,7 +67,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
private static final long serialVersionUID = 2629912294765040037L;
- protected URI entityURI;
+ private URI baseURI;
+
+ private CommonURIBuilder<?> uri;
protected final Map<String, Object> propertyChanges = new HashMap<String, Object>();
@@ -109,7 +111,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
return new EntityInvocationHandler(key, entity, entitySetURI, typeRef, containerHandler);
}
- static EntityInvocationHandler getInstance(
+ public static EntityInvocationHandler getInstance(
final CommonODataEntity entity,
final URI entitySetURI,
final Class<?> typeRef,
@@ -128,8 +130,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
super(typeRef, entity, containerHandler);
final Object key = entityKey == null ? CoreUtils.getKey(getClient(), this, typeRef, entity) : entityKey;
- if (key!=null && entity.getEditLink() == null) {
- final CommonURIBuilder<?> uriBuilder = containerHandler.getClient().newURIBuilder(entitySetURI.toASCIIString());
+
+ if (entity.getEditLink() != null) {
+ this.baseURI = entity.getEditLink();
+ this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
+ } else if (key != null) {
+ final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(entitySetURI.toASCIIString());
if (key.getClass().getAnnotation(CompoundKey.class) == null) {
LOG.debug("Append key segment '{}'", key);
@@ -139,10 +145,12 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
uriBuilder.appendKeySegment(getCompoundKey(key));
}
- this.entityURI = uriBuilder.build();
- entity.setEditLink(entityURI);
+ this.uri = uriBuilder;
+ this.baseURI = this.uri.build();
+ entity.setEditLink(this.baseURI);
} else {
- this.entityURI = entity.getEditLink();
+ this.baseURI = null;
+ this.uri = null;
}
this.internal = entity;
@@ -166,8 +174,9 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
CoreUtils.getKey(getClient(), this, typeRef, entity));
// fix for OLINGO-353
- if (this.entityURI == null) {
- this.entityURI = entity.getEditLink();
+ if (this.uri == null) {
+ this.baseURI = entity.getEditLink();
+ this.uri = this.baseURI == null ? null : getClient().newURIBuilder(this.baseURI.toASCIIString());
}
this.streamedPropertyChanges.clear();
@@ -195,7 +204,7 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
}
public URI getEntityURI() {
- return entityURI;
+ return this.baseURI;
}
/**
@@ -514,7 +523,8 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
try {
final ODataEntityRequest<CommonODataEntity> req =
- getClient().getRetrieveRequestFactory().getEntityRequest(entityURI);
+ getClient().getRetrieveRequestFactory().getEntityRequest(uri.build());
+
if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) > 0) {
req.setPrefer(getClient().newPreferences().includeAnnotations("*"));
}
@@ -566,6 +576,18 @@ public class EntityInvocationHandler extends AbstractStructuredInvocationHandler
return map;
}
+ public void expand(final String... expand) {
+ this.uri.expand(expand);
+ }
+
+ public void select(final String... select) {
+ this.uri.select(select);
+ }
+
+ public void clear() {
+ this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
+ }
+
@Override
public String toString() {
return uuid.toString();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
index 28b22ca..b969c03 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
@@ -33,6 +33,7 @@ import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySe
import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.client.api.uri.URIFilter;
import org.apache.olingo.client.api.v3.UnsupportedInV3Exception;
import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.client.api.v4.ODataClient;
@@ -46,9 +47,10 @@ import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
import org.apache.olingo.ext.proxy.api.AbstractEntitySet;
import org.apache.olingo.ext.proxy.api.AbstractSingleton;
-import org.apache.olingo.ext.proxy.api.Filter;
import org.apache.olingo.ext.proxy.api.Search;
import org.apache.olingo.ext.proxy.api.SingleQuery;
+import org.apache.olingo.ext.proxy.api.Sort;
+import org.apache.olingo.ext.proxy.api.StructuredType;
import org.apache.olingo.ext.proxy.api.annotations.EntitySet;
import org.apache.olingo.ext.proxy.context.AttachedEntityStatus;
import org.apache.olingo.ext.proxy.context.EntityContext;
@@ -58,7 +60,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class EntitySetInvocationHandler<
- T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+ T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
extends AbstractInvocationHandler
implements AbstractEntitySet<T, KEY, EC> {
@@ -75,7 +77,9 @@ class EntitySetInvocationHandler<
private Class<EC> collTypeRef = null;
- private final URI uri;
+ private final URI baseURI;
+
+ private CommonURIBuilder<?> uri;
@SuppressWarnings({"rawtypes", "unchecked"})
static EntitySetInvocationHandler getInstance(
@@ -91,14 +95,15 @@ class EntitySetInvocationHandler<
uriBuilder.appendEntitySetSegment(entitySetSegment.toString());
- return new EntitySetInvocationHandler(ref, containerHandler, entitySetName, uriBuilder.build());
+ return new EntitySetInvocationHandler(ref, containerHandler, entitySetName, uriBuilder);
}
@SuppressWarnings({"rawtypes", "unchecked"})
static EntitySetInvocationHandler getInstance(
- final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final URI uri) {
+ final Class<?> ref, final EntityContainerInvocationHandler containerHandler, final URI uri) {;
- return new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(EntitySet.class)).name(), uri);
+ return new EntitySetInvocationHandler(ref, containerHandler, (ref.getAnnotation(EntitySet.class)).name(),
+ containerHandler.getClient().newURIBuilder(uri.toASCIIString()));
}
@SuppressWarnings("unchecked")
@@ -106,17 +111,18 @@ class EntitySetInvocationHandler<
final Class<?> ref,
final EntityContainerInvocationHandler containerHandler,
final String entitySetName,
- final URI uri) {
+ final CommonURIBuilder<?> uri) {
super(containerHandler);
+ this.uri = uri;
+ this.baseURI = uri.build();
+
this.isSingleton = AbstractSingleton.class.isAssignableFrom(ref);
final Type[] entitySetParams = ClassUtils.extractGenericType(ref, AbstractEntitySet.class, AbstractSingleton.class);
this.typeRef = (Class<T>) entitySetParams[0];
this.collTypeRef = (Class<EC>) entitySetParams[2];
-
- this.uri = uri;
}
protected Class<T> getTypeRef() {
@@ -128,12 +134,20 @@ class EntitySetInvocationHandler<
}
protected URI getEntitySetURI() {
- return uri;
+ return this.baseURI;
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
- if (isSelfMethod(method, args)) {
+ if ("filter".equals(method.getName())
+ || "orderBy".equals(method.getName())
+ || "top".equals(method.getName())
+ || "skip".equals(method.getName())
+ || "expand".equals(method.getName())
+ || "select".equals(method.getName())) {
+ invokeSelfMethod(method, args);
+ return proxy;
+ } else if (isSelfMethod(method, args)) {
return invokeSelfMethod(method, args);
} else if (method.getName().startsWith("new") && ArrayUtils.isEmpty(args)) {
if (method.getName().endsWith("Collection")) {
@@ -152,7 +166,7 @@ class EntitySetInvocationHandler<
new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(reference)));
final EntityInvocationHandler handler =
- EntityInvocationHandler.getInstance(entity, uri, reference, containerHandler);
+ EntityInvocationHandler.getInstance(entity, this.baseURI, reference, containerHandler);
getContext().entityContext().attachNew(handler);
return (NE) Proxy.newProxyInstance(
@@ -172,7 +186,7 @@ class EntitySetInvocationHandler<
@Override
public Long count() {
final ODataValueRequest req = getClient().getRetrieveRequestFactory().
- getValueRequest(getClient().newURIBuilder(this.uri.toASCIIString()).count().build());
+ getValueRequest(getClient().newURIBuilder(this.uri.build().toASCIIString()).count().build());
req.setFormat(ODataFormat.TEXT_PLAIN);
return Long.valueOf(req.execute().getBody().asPrimitive().toString());
}
@@ -180,7 +194,7 @@ class EntitySetInvocationHandler<
@Override
public Boolean exists(final KEY key) throws IllegalArgumentException {
try {
- SingleQuery.class.cast(get(key)).load();
+ SingleQuery.class.cast(getByKey(key)).load();
return true;
} catch (Exception e) {
LOG.error("Could not check existence of {}({})", this.uri, key, e);
@@ -189,18 +203,18 @@ class EntitySetInvocationHandler<
}
@Override
- public T get(final KEY key) throws IllegalArgumentException {
- return get(key, typeRef);
+ public T getByKey(final KEY key) throws IllegalArgumentException {
+ return getByKey(key, typeRef);
}
@Override
@SuppressWarnings("unchecked")
- public <S extends T> S get(final KEY key, final Class<S> typeRef) throws IllegalArgumentException {
+ public <S extends T> S getByKey(final KEY key, final Class<S> typeRef) throws IllegalArgumentException {
if (key == null) {
throw new IllegalArgumentException("Null key");
}
- final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), uri, typeRef, key);
+ final EntityUUID uuid = new EntityUUID(containerHandler.getEntityContainerName(), this.baseURI, typeRef, key);
LOG.debug("Ask for '{}({})'", typeRef.getSimpleName(), key);
EntityInvocationHandler handler = getContext().entityContext().getEntity(uuid);
@@ -209,7 +223,7 @@ class EntitySetInvocationHandler<
final CommonODataEntity entity = getClient().getObjectFactory().newEntity(
new FullQualifiedName(containerHandler.getSchemaName(), ClassUtils.getEntityTypeName(typeRef)));
- handler = EntityInvocationHandler.getInstance(key, entity, uri, typeRef, containerHandler);
+ handler = EntityInvocationHandler.getInstance(key, entity, this.baseURI, typeRef, containerHandler);
} else if (isDeleted(handler)) {
// object deleted
@@ -295,19 +309,17 @@ class EntitySetInvocationHandler<
entityCollectionHandler);
}
- @Override
- public EC getAll() {
- return getAll(collTypeRef);
+ public EC execute() {
+ return execute(collTypeRef);
}
@SuppressWarnings("unchecked")
- @Override
- public <S extends T, SEC extends AbstractEntityCollection<S>> SEC getAll(final Class<SEC> collTypeRef) {
+ public <S extends T, SEC extends AbstractEntityCollection<S>> SEC execute(final Class<SEC> collTypeRef) {
final Class<S> ref = (Class<S>) ClassUtils.extractTypeArg(collTypeRef,
AbstractEntitySet.class, AbstractSingleton.class, AbstractEntityCollection.class);
final Class<S> oref = (Class<S>) ClassUtils.extractTypeArg(this.collTypeRef);
- final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(this.uri.toASCIIString());
+ final CommonURIBuilder<?> uriBuilder = getClient().newURIBuilder(this.uri.build().toASCIIString());
final URI entitySetURI;
if (oref.equals(ref)) {
@@ -321,24 +333,11 @@ class EntitySetInvocationHandler<
}
@Override
- public Filter<T, EC> createFilter() {
- return new FilterImpl<T, EC>(getClient(), this.collTypeRef, this.uri, this);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public <S extends T, SEC extends AbstractEntityCollection<S>> Filter<S, SEC> createFilter(
- final Class<SEC> reference) {
-
- return new FilterImpl<S, SEC>(getClient(), reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
- }
-
- @Override
public Search<T, EC> createSearch() {
if (getClient().getServiceVersion().compareTo(ODataServiceVersion.V30) <= 0) {
throw new UnsupportedInV3Exception();
}
- return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collTypeRef, this.uri, this);
+ return new SearchImpl<T, EC>((EdmEnabledODataClient) getClient(), this.collTypeRef, this.baseURI, this);
}
@Override
@@ -350,7 +349,10 @@ class EntitySetInvocationHandler<
throw new UnsupportedInV3Exception();
}
return new SearchImpl<S, SEC>(
- (EdmEnabledODataClient) getClient(), reference, this.uri, (EntitySetInvocationHandler<S, ?, SEC>) this);
+ (EdmEnabledODataClient) getClient(),
+ reference,
+ baseURI,
+ (EntitySetInvocationHandler<S, ?, SEC>) this);
}
@Override
@@ -359,13 +361,13 @@ class EntitySetInvocationHandler<
EntityInvocationHandler entity = entityContext.getEntity(new EntityUUID(
containerHandler.getEntityContainerName(),
- uri,
+ baseURI,
typeRef,
key));
if (entity == null) {
// search for entity
- final T searched = get(key);
+ final T searched = getByKey(key);
entity = (EntityInvocationHandler) Proxy.getInvocationHandler(searched);
entityContext.attach(entity, AttachedEntityStatus.DELETED);
} else {
@@ -393,6 +395,48 @@ class EntitySetInvocationHandler<
@Override
public EntitySetIterator<T, KEY, EC> iterator() {
- return new EntitySetIterator<T, KEY, EC>(getClient().newURIBuilder(this.uri.toASCIIString()).build(), this);
+ return new EntitySetIterator<T, KEY, EC>(getClient().newURIBuilder(this.uri.build().toASCIIString()).build(), this);
+ }
+
+ public void filter(final String filter) {
+ this.uri.filter(filter);
+ }
+
+ public void filter(final URIFilter filter) {
+ this.uri.filter(filter);
+ }
+
+ public void orderBy(final Sort... sort) {
+ final StringBuilder builder = new StringBuilder();
+ for (Sort sortClause : sort) {
+ builder.append(sortClause.getKey()).append(' ').append(sortClause.getValue()).append(',');
+ }
+ builder.deleteCharAt(builder.length() - 1);
+
+ this.uri.orderBy(builder.toString());
+ }
+
+ public void orderBy(final String orderBy) {
+ this.uri.orderBy(orderBy);
+ }
+
+ public void top(final int top) throws IllegalArgumentException {
+ this.uri.top(top);
+ }
+
+ public void skip(final int skip) throws IllegalArgumentException {
+ this.uri.skip(skip);
+ }
+
+ public void expand(final String... expand) {
+ this.uri.expand(expand);
+ }
+
+ public void select(final String... select) {
+ this.uri.select(select);
+ }
+
+ public void clear() {
+ this.uri = getClient().newURIBuilder(baseURI.toASCIIString());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
index 48405e8..7965559 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetIterator.java
@@ -27,8 +27,9 @@ import java.util.NoSuchElementException;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.olingo.commons.api.domain.v4.ODataAnnotation;
import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
+import org.apache.olingo.ext.proxy.api.StructuredType;
-class EntitySetIterator<T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
+class EntitySetIterator<T extends StructuredType, KEY extends Serializable, EC extends AbstractEntityCollection<T>>
implements Iterator<T> {
private final EntitySetInvocationHandler<T, KEY, EC> esi;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java
deleted file mode 100644
index f328ac7..0000000
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/FilterImpl.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.ext.proxy.commons;
-
-import java.io.Serializable;
-import java.net.URI;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.uri.URIFilter;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
-import org.apache.olingo.ext.proxy.api.NoResultException;
-import org.apache.olingo.ext.proxy.api.NonUniqueResultException;
-import org.apache.olingo.ext.proxy.api.Filter;
-import org.apache.olingo.ext.proxy.api.Sort;
-import org.apache.olingo.ext.proxy.utils.ClassUtils;
-
-public class FilterImpl<T extends Serializable, EC extends AbstractEntityCollection<T>> implements Filter<T, EC> {
-
- private static final long serialVersionUID = -300830736753191114L;
-
- private final CommonODataClient<?> client;
-
- private final Class<T> typeRef;
-
- private final Class<EC> collTypeRef;
-
- private final EntitySetInvocationHandler<T, ?, EC> handler;
-
- private final URI baseURI;
-
- private String filter;
-
- private String orderBy;
-
- private Integer maxResults;
-
- private Integer firstResult;
-
- @SuppressWarnings("unchecked")
- FilterImpl(final CommonODataClient<?> client,
- final Class<EC> collTypeRef, final URI baseURI, final EntitySetInvocationHandler<T, ?, EC> handler) {
-
- this.client = client;
- this.typeRef = (Class<T>) ClassUtils.extractTypeArg(collTypeRef);
- this.collTypeRef = collTypeRef;
- this.baseURI = baseURI;
- this.handler = handler;
- }
-
- @Override
- public Filter<T, EC> setFilter(final String filter) {
- this.filter = filter;
- return this;
- }
-
- @Override
- public Filter<T, EC> setFilter(final URIFilter filter) {
- this.filter = filter.build();
- return this;
- }
-
- @Override
- public String getFilter() {
- return filter;
- }
-
- @Override
- public Filter<T, EC> setOrderBy(final Sort... sort) {
- final StringBuilder builder = new StringBuilder();
- for (Sort sortClause : sort) {
- builder.append(sortClause.getKey()).append(' ').append(sortClause.getValue()).append(',');
- }
- builder.deleteCharAt(builder.length() - 1);
-
- this.orderBy = builder.toString();
- return this;
- }
-
- @Override
- public Filter<T, EC> setOrderBy(final String orderBy) {
- this.orderBy = orderBy;
- return this;
- }
-
- @Override
- public String getOrderBy() {
- return orderBy;
- }
-
- @Override
- public Filter<T, EC> setMaxResults(final int maxResults) throws IllegalArgumentException {
- if (maxResults <= 0) {
- throw new IllegalArgumentException("maxResults must be positive");
- }
-
- this.maxResults = maxResults;
- return this;
- }
-
- @Override
- public int getMaxResults() {
- return maxResults;
- }
-
- @Override
- public Filter<T, EC> setFirstResult(final int firstResult) throws IllegalArgumentException {
- if (firstResult <= 0) {
- throw new IllegalArgumentException("firstResult must be positive");
- }
-
- this.firstResult = firstResult;
- return this;
- }
-
- @Override
- public int getFirstResult() {
- return firstResult;
- }
-
- @Override
- public T getSingleResult() throws NoResultException, NonUniqueResultException {
- final EC result = getResult();
- if (result.isEmpty()) {
- throw new NoResultException();
- }
- if (result.size() > 1) {
- throw new NonUniqueResultException();
- }
-
- return result.iterator().next();
- }
-
- @Override
- public EC getResult() {
- CommonURIBuilder<?> uriBuilder = client.newURIBuilder(this.baseURI.toASCIIString());
-
- if(this.client.getConfiguration().isAddressingDerivedTypes()){
- uriBuilder = uriBuilder.appendDerivedEntityTypeSegment(new FullQualifiedName(
- ClassUtils.getNamespace(typeRef), ClassUtils.getEntityTypeName(typeRef)).toString());
- }
- if (StringUtils.isNotBlank(filter)) {
- uriBuilder.filter(filter);
- }
- if (StringUtils.isNotBlank(orderBy)) {
- uriBuilder.orderBy(orderBy);
- }
- if (maxResults != null) {
- uriBuilder.top(maxResults);
- }
- if (firstResult != null) {
- uriBuilder.skip(firstResult);
- }
-
- return handler.fetchWholeEntitySet(uriBuilder.build(), typeRef, collTypeRef);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
index 6f36148..6a0127c 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/NonTransactionalPersistenceManagerImpl.java
@@ -24,7 +24,7 @@ import org.apache.olingo.client.api.communication.request.ODataBatchableRequest;
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.client.api.communication.response.ODataResponse;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
/**
* {@link org.apache.olingo.ext.proxy.api.PersistenceManager} implementation not using OData batch requests: any
@@ -35,7 +35,7 @@ public class NonTransactionalPersistenceManagerImpl extends AbstractPersistenceM
private static final long serialVersionUID = 5082907388513308752L;
- public NonTransactionalPersistenceManagerImpl(final EntityContainerFactory<?> factory) {
+ public NonTransactionalPersistenceManagerImpl(final Service<?> factory) {
super(factory);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
index fb65c6e..b36e4d1 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SearchImpl.java
@@ -18,7 +18,6 @@
*/
package org.apache.olingo.ext.proxy.commons;
-import java.io.Serializable;
import java.net.URI;
import org.apache.commons.lang3.StringUtils;
import org.apache.olingo.client.api.uri.v4.URIBuilder;
@@ -27,9 +26,10 @@ import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.ext.proxy.api.AbstractEntityCollection;
import org.apache.olingo.ext.proxy.api.Search;
+import org.apache.olingo.ext.proxy.api.StructuredType;
import org.apache.olingo.ext.proxy.utils.ClassUtils;
-public class SearchImpl<T extends Serializable, EC extends AbstractEntityCollection<T>> implements Search<T, EC> {
+public class SearchImpl<T extends StructuredType, EC extends AbstractEntityCollection<T>> implements Search<T, EC> {
private static final long serialVersionUID = 4383858176507769973L;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
index bbae0c8..4e6d78b 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/SingletonInvocationHandler.java
@@ -36,7 +36,6 @@ public class SingletonInvocationHandler<
return new SingletonInvocationHandler(ref, containerHandler, singletonName);
}
-
private final EntitySetInvocationHandler<?, ?, ?> entitySetHandler;
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -56,9 +55,8 @@ public class SingletonInvocationHandler<
}
}
- @Override
@SuppressWarnings("unchecked")
- public T get() {
- return (T) this.entitySetHandler.getAll().iterator().next();
+ public T load() {
+ return (T) this.entitySetHandler.execute().iterator().next();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
index 1165830..b64dbfb 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/TransactionalPersistenceManagerImpl.java
@@ -32,7 +32,7 @@ import org.apache.olingo.client.api.communication.response.ODataEntityCreateResp
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
import org.apache.olingo.client.api.communication.response.ODataResponse;
import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
/**
* {@link org.apache.olingo.ext.proxy.api.PersistenceManager} implementation using OData batch requests to implement
@@ -43,7 +43,7 @@ public class TransactionalPersistenceManagerImpl extends AbstractPersistenceMana
private static final long serialVersionUID = -3320312269235907501L;
- public TransactionalPersistenceManagerImpl(final EntityContainerFactory<?> factory) {
+ public TransactionalPersistenceManagerImpl(final Service<?> factory) {
super(factory);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
index ea29767..95bee13 100644
--- a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
+++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractPOJOGenMojo.java
@@ -282,7 +282,10 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs);
}
+ final List<EdmEntityType> entities = new ArrayList<EdmEntityType>();
+
for (EdmEntityType entity : schema.getEntityTypes()) {
+ entities.add(entity);
objs.clear();
objs.put("entityType", entity);
@@ -345,6 +348,16 @@ public abstract class AbstractPOJOGenMojo extends AbstractMojo {
}
}
}
+
+ objs.clear();
+ objs.put("namespace", schema.getNamespace());
+ objs.put("complexes", complexes);
+ parseObj(base, pkg, "complexCreator", "ComplexCreator.java", objs);
+
+ objs.clear();
+ objs.put("namespace", schema.getNamespace());
+ objs.put("entities", entities);
+ parseObj(base, pkg, "entityCreator", "EntityCreator.java", objs);
}
final File metaInf = mkdir("META-INF");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm b/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm
new file mode 100644
index 0000000..af23884
--- /dev/null
+++ b/ext/pojogen-maven-plugin/src/main/resources/complexCreator.vm
@@ -0,0 +1,32 @@
+#*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *#
+package ${package};
+
+import org.apache.olingo.ext.proxy.api.annotations.Namespace;
+import org.apache.olingo.ext.proxy.api.annotations.Property;
+
+@org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
+public interface ComplexCreator {
+ #foreach($complex in $complexes)
+ #set( $type = "${namespace}.${complex.Name}" )
+ @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$complex.Name", type = "$type")
+ $utility.getJavaType($type) new$utility.capitalize($complex.Name)();
+
+ #end
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm b/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm
new file mode 100644
index 0000000..bbb4628
--- /dev/null
+++ b/ext/pojogen-maven-plugin/src/main/resources/entityCreator.vm
@@ -0,0 +1,37 @@
+#*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *#
+package ${package};
+
+import org.apache.olingo.ext.proxy.api.annotations.Namespace;
+import org.apache.olingo.ext.proxy.api.annotations.Property;
+
+@org.apache.olingo.ext.proxy.api.annotations.Namespace("$namespace")
+public interface EntityCreator {
+
+ #foreach($entity in $entities)
+ #set( $type = "${namespace}.${entity.Name}" )
+ #set( $javaType = $utility.getJavaType($type) )
+ @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$entity.Name", type = "$type")
+ $javaType new$utility.capitalize($entity.Name)();
+
+ @org.apache.olingo.ext.proxy.api.annotations.Property(name = "$entity.Name", type = "$type")
+ ${javaType}Collection new${utility.capitalize($entity.Name)}Collection();
+
+ #end
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
----------------------------------------------------------------------
diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
index 73e1e63..70d7cbd 100644
--- a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
+++ b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm
@@ -239,9 +239,11 @@ public interface $utility.capitalize($entityType.Name)
#set( $type = "" )
#end
+ #set ( $javaEntityType = $utility.getJavaType($property.Type) )
+
@org.apache.olingo.ext.proxy.api.annotations.EntitySet(name = "$property.Name", contained = true)
interface $utility.capitalize($property.Name)
- extends AbstractEntitySet<$utility.getJavaType($property.Type), $type, $utility.getJavaType($property.Type)Collection> {
+ extends org.apache.olingo.ext.proxy.api.CollectionQuery<$javaEntityType, ${javaEntityType}Collection>, AbstractEntitySet<$javaEntityType, $type, ${javaEntityType}Collection> {
#foreach( $dos in $utility.getDescendantsOrSelf($utility.getEdmType($property)) )
#set( $djt = $utility.getJavaType($dos) )
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
index bbf077f..a80e1f5 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java
@@ -29,7 +29,7 @@ import java.util.Collections;
import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Aliases;
@@ -62,7 +62,7 @@ public abstract class AbstractTestITCase {
protected static String testLargeModelServiceRootURL;
- protected static EntityContainerFactory<EdmEnabledODataClient> containerFactory;
+ protected static Service<EdmEnabledODataClient> service;
protected static DefaultContainer container;
@@ -75,11 +75,11 @@ public abstract class AbstractTestITCase {
testOpenTypeServiceRootURL = "http://localhost:9080/stub/StaticService/V30/OpenType.svc";
testLargeModelServiceRootURL = "http://localhost:9080/stub/StaticService/V30/Static.svc/large";
- containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL);
- containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
- container = containerFactory.getEntityContainer(DefaultContainer.class);
+ service = Service.getV3(testStaticServiceRootURL);
+ service.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
+ container = service.getEntityContainer(DefaultContainer.class);
assertNotNull(container);
- containerFactory.getContext().detachAll();
+ service.getContext().detachAll();
}
protected Customer getSampleCustomerProfile(
@@ -139,7 +139,7 @@ public abstract class AbstractTestITCase {
}
protected Customer readCustomer(final DefaultContainer container, final int id) {
- final Customer customer = container.getCustomer().get(id).load();
+ final Customer customer = container.getCustomer().getByKey(id).load();
assertNotNull(customer);
assertEquals(Integer.valueOf(id), customer.getCustomerId());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/baf2cd10/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
index b43c842..b3a85ae 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java
@@ -24,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
import org.apache.olingo.client.api.v3.EdmEnabledODataClient;
import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.ext.proxy.EntityContainerFactory;
+import org.apache.olingo.ext.proxy.Service;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer;
import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.Employee;
@@ -41,8 +41,8 @@ import org.junit.Test;
public class ActionOverloadingTestITCase extends AbstractTestITCase {
private DefaultContainer getContainer() {
- final EntityContainerFactory<EdmEnabledODataClient> ecf =
- EntityContainerFactory.getV3(testActionOverloadingServiceRootURL);
+ final Service<EdmEnabledODataClient> ecf =
+ Service.getV3(testActionOverloadingServiceRootURL);
ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM);
return ecf.getEntityContainer(DefaultContainer.class);
}
@@ -54,18 +54,18 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
int res = aocontainer.operations().retrieveProduct();
assertEquals(-10, res);
- containerFactory.getContext().detachAll();
+ service.getContext().detachAll();
- res = aocontainer.getProduct().get(-10).operations().retrieveProduct();
+ res = aocontainer.getProduct().getByKey(-10).operations().retrieveProduct();
assertEquals(-10, res);
- containerFactory.getContext().detachAll();
+ service.getContext().detachAll();
final OrderLineKey key = new OrderLineKey();
key.setOrderId(-10);
key.setProductId(-10);
- res = aocontainer.getOrderLine().get(key).operations().retrieveProduct();
+ res = aocontainer.getOrderLine().getByKey(key).operations().retrieveProduct();
assertEquals(-10, res);
}
@@ -73,7 +73,7 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
public void increaseSalaries() {
final DefaultContainer aocontainer = getContainer();
- EmployeeCollection ecoll = aocontainer.getPerson().getAll(EmployeeCollection.class);
+ EmployeeCollection ecoll = aocontainer.getPerson().execute(EmployeeCollection.class);
assertFalse(ecoll.isEmpty());
Employee empl = ecoll.iterator().next();
@@ -85,13 +85,13 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
ecoll.operations().increaseSalaries(5);
// the invoke above changed the local entities, re-read
- containerFactory.getContext().detachAll();
- ecoll = aocontainer.getPerson().getAll(EmployeeCollection.class);
+ service.getContext().detachAll();
+ ecoll = aocontainer.getPerson().execute(EmployeeCollection.class);
empl = ecoll.iterator().next();
assertEquals(salary + 5, empl.getSalary(), 0);
- SpecialEmployeeCollection secoll = aocontainer.getPerson().getAll(SpecialEmployeeCollection.class);
+ SpecialEmployeeCollection secoll = aocontainer.getPerson().execute(SpecialEmployeeCollection.class);
assertFalse(secoll.isEmpty());
SpecialEmployee sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1];
@@ -103,8 +103,8 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase {
secoll.operations().increaseSalaries(5);
// the invoke above changed the local entities, re-read
- containerFactory.getContext().detachAll();
- secoll = aocontainer.getPerson().getAll(SpecialEmployeeCollection.class);
+ service.getContext().detachAll();
+ secoll = aocontainer.getPerson().execute(SpecialEmployeeCollection.class);
sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1];
assertEquals(salary + 5, sempl.getSalary(), 0);