You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2014/01/02 13:46:48 UTC
[01/47] [OLINGO-83] Renamed test packages
Updated Branches:
refs/heads/ODataServlet 80379ec10 -> 33ae8e8a2
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
new file mode 100644
index 0000000..8e5e794
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+*
+*/
+@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Teams")
+public class Team extends RefBase {
+ @EdmProperty(type = EdmType.BOOLEAN)
+ private Boolean isScrumTeam;
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Team() {
+ super(-1, null);
+ }
+
+ public Team(final int id, final String name) {
+ super(id, name);
+ }
+
+ public Boolean isScrumTeam() {
+ return isScrumTeam;
+ }
+
+ public void setScrumTeam(final Boolean isScrumTeam) {
+ this.isScrumTeam = isScrumTeam;
+ }
+
+ public void addEmployee(final Employee e) {
+ employees.add(e);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
deleted file mode 100644
index 5059327..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.data;
-
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationInMemoryDs;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataStore;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource.BinaryData;
-import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.core.annotation.model.Building;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.Photo;
-import org.apache.olingo.odata2.core.annotation.model.Room;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-/**
- *
- */
-public class AnnotationsInMemoryDsTest {
-
- private final AnnotationInMemoryDs datasource;
- private final AnnotationEdmProvider edmProvider;
- private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
-
- public AnnotationsInMemoryDsTest() throws ODataException {
- datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
- edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
- }
-
- @Test
- @Ignore
- public void multiThreadedSyncOnBuildingsTest() throws Exception {
- final EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- CountDownLatch latch;
-
- List<Thread> threads = new ArrayList<Thread>();
- int max = 500;
-
- latch = new CountDownLatch(max);
- for (int i = 0; i < max; i++) {
- threads.add(createBuildingThread(latch, datasource, edmEntitySet, String.valueOf("10")));
- }
-
- for (Thread thread : threads) {
- thread.start();
- }
-
- latch.await(60, TimeUnit.SECONDS);
-
- DataStore<Building> ds = datasource.getDataStore(Building.class);
- Collection<Building> buildings = ds.read();
- Assert.assertEquals(max, buildings.size());
- }
-
- @org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet
- @org.apache.olingo.odata2.api.annotation.edm.EdmEntityType
- private static class SimpleEntity {
- @EdmKey
- @EdmProperty
- public Integer id;
- @EdmProperty
- public String name;
- }
-
- @Test
- @Ignore
- public void multiThreadedSyncCreateReadTest() throws Exception {
- Collection<Class<?>> ac = new ArrayList<Class<?>>();
- ac.add(SimpleEntity.class);
- final AnnotationInMemoryDs localDs = new AnnotationInMemoryDs(SimpleEntity.class.getPackage().getName(), true);
- final AnnotationEdmProvider localProvider = new AnnotationEdmProvider(ac);
- final EdmEntitySet edmEntitySet = createMockedEdmEntitySet(localProvider, "SimpleEntitySet");
- final CountDownLatch latch;
-
- List<Thread> threads = new ArrayList<Thread>();
- int max = 500;
- latch = new CountDownLatch(max);
- for (int i = 0; i < max; i++) {
- Runnable run = new Runnable() {
- @Override
- public void run() {
- SimpleEntity se = new SimpleEntity();
- se.id = Integer.valueOf(String.valueOf(System.currentTimeMillis()).substring(8));
- se.name = "Name: " + System.currentTimeMillis();
- try {
- localDs.createData(edmEntitySet, se);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }finally{
- latch.countDown();
- }
- }
- };
-
- threads.add(new Thread(run));
- }
-
- for (Thread thread : threads) {
- thread.start();
- }
-
- latch.await(60, TimeUnit.SECONDS);
-
- DataStore<SimpleEntity> ds = localDs.getDataStore(SimpleEntity.class);
- Collection<SimpleEntity> buildings = ds.read();
- Assert.assertEquals(max, buildings.size());
- }
-
- private Thread createBuildingThread(final CountDownLatch latch, final DataSource datasource,
- final EdmEntitySet edmEntitySet, final String id) {
- Runnable run = new Runnable() {
- @Override
- public void run() {
- Building building = new Building();
- building.setName("Common Building - " + System.currentTimeMillis());
- building.setId(id);
- try {
- datasource.createData(edmEntitySet, building);
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new RuntimeException(ex);
- } finally {
- latch.countDown();
- }
- }
- };
-
- return new Thread(run);
- }
-
- @Test
- public void readBinaryData() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
- Photo photo = new Photo();
- photo.setName("SomePic");
- photo.setType("PNG");
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- photo.setImage(image);
- photo.setImageType("image/png");
- photoDataStore.create(photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Name", "SomePic");
- keys.put("ImageFormat", "PNG");
- Photo toReadPhoto = (Photo) datasource.readData(entitySet, keys);
-
- // execute
- BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
-
- // validate
- Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
- Assert.assertArrayEquals(image, readBinaryData.getData());
- Assert.assertEquals("image/png", readBinaryData.getMimeType());
- }
-
- @Test
- public void readBinaryDataDirect() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
- Photo photo = new Photo();
- photo.setName("SomePic");
- photo.setType("PNG");
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- photo.setImage(image);
- photo.setImageType("image/png");
- photoDataStore.create(photo);
-
- Photo toReadPhoto = new Photo();
- toReadPhoto.setName("SomePic");
- toReadPhoto.setType("PNG");
- toReadPhoto.setImage(null);
- toReadPhoto.setImageType(null);
-
- BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
-
- Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
- Assert.assertArrayEquals(image, readBinaryData.getData());
- Assert.assertEquals("image/png", readBinaryData.getMimeType());
- }
-
-
- @Test
- public void writeBinaryData() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
-
- Photo toWritePhoto = new Photo();
- toWritePhoto.setName("SomePic");
- toWritePhoto.setType("PNG");
- photoDataStore.create(toWritePhoto);
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- String mimeType = "image/png";
- BinaryData writeBinaryData = new BinaryData(image, mimeType);
- // execute
- datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
-
- // validate
- Photo photoKey = new Photo();
- photoKey.setName("SomePic");
- photoKey.setType("PNG");
- Photo storedPhoto = photoDataStore.read(photoKey);
- Assert.assertEquals("binary", new String(storedPhoto.getImage(), Charset.defaultCharset()));
- Assert.assertArrayEquals(image, storedPhoto.getImage());
- Assert.assertEquals("image/png", storedPhoto.getImageType());
- }
-
- @Test(expected=ODataNotFoundException.class)
- public void writeBinaryDataNotFound() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- Photo toWritePhoto = new Photo();
- toWritePhoto.setName("SomePic");
- toWritePhoto.setType("PNG");
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- String mimeType = "image/png";
- BinaryData writeBinaryData = new BinaryData(image, mimeType);
- // execute
- datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
- }
-
-
- @Test
- public void newDataObject() throws Exception {
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
- Room room = (Room) datasource.newDataObject(roomsEntitySet);
-
- Assert.assertNotNull(room);
- }
-
- @Test
- public void readEntity() throws Exception {
- EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 3;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- building.getRooms().addAll(rooms);
- datasource.createData(buildingsEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- // execute
- Object relatedData = datasource.readData(buildingsEntitySet, keys);
-
- // validate
- Building readBuilding = (Building) relatedData;
- Assert.assertEquals("Common Building", readBuilding.getName());
- Assert.assertEquals("1", readBuilding.getId());
-
- Collection<Room> relatedRooms = readBuilding.getRooms();
- Assert.assertEquals(roomsCount, relatedRooms.size());
- for (Room room : relatedRooms) {
- Assert.assertNotNull(room.getId());
- Assert.assertTrue(room.getName().matches("Room \\d*"));
- Assert.assertEquals("Common Building", room.getBuilding().getName());
- }
- }
-
- @Test
- public void readEntities() throws Exception {
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 11;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- // execute
- Object relatedData = datasource.readData(roomsEntitySet);
-
- // validate
- @SuppressWarnings("unchecked")
- Collection<Room> relatedRooms = (Collection<Room>) relatedData;
- Assert.assertEquals(roomsCount, relatedRooms.size());
- for (Room room : relatedRooms) {
- Assert.assertNotNull(room.getId());
- Assert.assertTrue(room.getName().matches("Room \\d*"));
- Assert.assertEquals("Common Building", room.getBuilding().getName());
- }
- }
-
-
- @Test
- @SuppressWarnings("unchecked")
- public void readRelatedEntities() throws Exception {
- EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 10;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- building.getRooms().addAll(rooms);
- datasource.createData(buildingsEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(buildingsEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
-
- // execute
- Object relatedData = datasource.readRelatedData(
- buildingsEntitySet, building, roomsEntitySet, Collections.EMPTY_MAP);
-
- // validate
- Assert.assertTrue("Result is no collection.", relatedData instanceof Collection);
- Collection<Room> relatedRooms = (Collection<Room>) relatedData;
- Assert.assertEquals(roomsCount, relatedRooms.size());
- for (Room room : relatedRooms) {
- Assert.assertNotNull(room.getId());
- Assert.assertTrue(room.getName().matches("Room \\d*"));
- Assert.assertEquals("Common Building", room.getBuilding().getName());
- }
- }
-
- @Test
- public void readRelatedTargetEntity() throws Exception {
- EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 10;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- building.getRooms().addAll(rooms);
- datasource.createData(buildingsEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(buildingsEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
-
- // execute
- Map<String, Object> targetKeys = new HashMap<String, Object>();
- targetKeys.put("Id", 3);
- Object relatedData = datasource.readRelatedData(
- buildingsEntitySet, building, roomsEntitySet, targetKeys);
-
- // validate
- Assert.assertTrue("Result is no Room.", relatedData instanceof Room);
- Room relatedRoom = (Room) relatedData;
- Assert.assertEquals("3", relatedRoom.getId());
- Assert.assertEquals("Room 3", relatedRoom.getName());
- Assert.assertEquals("Common Building", relatedRoom.getBuilding().getName());
- }
-
- @Test
- public void createSimpleEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
-
- Building building = new Building();
- building.setName("Common Building");
- datasource.createData(edmEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
- }
-
- @Test
- public void createSimpleEntityWithOwnKey() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
-
- Building building = new Building();
- building.setName("Common Building");
- AnnotationHelper ah = new AnnotationHelper();
- ah.setValueForProperty(building, "Id", "42");
- datasource.createData(edmEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "42");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("42", read.getId());
- }
-
- @Test
- public void createSimpleEntityWithDuplicateKey() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- AnnotationHelper ah = new AnnotationHelper();
-
- Building building = new Building();
- building.setName("Common Building");
- ah.setValueForProperty(building, "Id", "42");
- datasource.createData(edmEntitySet, building);
- //
- Building buildingDuplicate = new Building();
- buildingDuplicate.setName("Duplicate Building");
- ah.setValueForProperty(buildingDuplicate, "Id", "42");
- datasource.createData(edmEntitySet, buildingDuplicate);
-
- Map<String, Object> keys42 = new HashMap<String, Object>();
- keys42.put("Id", "42");
- Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
- Assert.assertEquals("Common Building", read42.getName());
- Assert.assertEquals("42", read42.getId());
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Duplicate Building", read.getName());
- Assert.assertEquals("1", read.getId());
- }
-
- @Test
- public void createEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
-
- Photo photo = new Photo();
- photo.setName("BigPicture");
- photo.setType("PNG");
- photo.setImageUri("https://localhost/image.png");
- photo.setImageType("image/png");
- datasource.createData(edmEntitySet, photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("ImageFormat", "PNG");
- keys.put("Name", "BigPicture");
-
- Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("PNG", read.getType());
- Assert.assertEquals("image/png", read.getImageType());
- Assert.assertEquals("https://localhost/image.png", read.getImageUri());
- }
-
- @Test
- public void createAndUpdateEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
-
- Photo photo = new Photo();
- final String nameKeyValue = "BigPicture";
- final String typeKeyValue = "PNG";
- photo.setName(nameKeyValue);
- photo.setType(typeKeyValue);
- photo.setImageUri("https://localhost/image.png");
- photo.setImageType("image/png");
- datasource.createData(edmEntitySet, photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Name", "BigPicture");
- keys.put("ImageFormat", "PNG");
-
- Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("PNG", read.getType());
- Assert.assertEquals("image/png", read.getImageType());
- Assert.assertEquals("https://localhost/image.png", read.getImageUri());
-
- // update
- Photo updatedPhoto = new Photo();
- updatedPhoto.setName(nameKeyValue);
- updatedPhoto.setType(typeKeyValue);
- updatedPhoto.setImageUri("https://localhost/image.jpg");
- updatedPhoto.setImageType("image/jpg");
- datasource.updateData(edmEntitySet, updatedPhoto);
-
- Map<String, Object> updatedKeys = new HashMap<String, Object>();
- updatedKeys.put("Name", nameKeyValue);
- updatedKeys.put("ImageFormat", typeKeyValue);
-
- Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
- Assert.assertEquals("BigPicture", readUpdated.getName());
- Assert.assertEquals("PNG", readUpdated.getType());
- Assert.assertEquals("image/jpg", readUpdated.getImageType());
- Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
- }
-
-
- @Test
- public void deleteSimpleEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- DataStore<Building> datastore = datasource.getDataStore(Building.class);
-
- Building building = new Building();
- building.setName("Common Building");
- datastore.create(building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
-
- //
- datasource.deleteData(edmEntitySet, keys);
-
- // validate
- try {
- Building readAfterDelete = (Building) datasource.readData(edmEntitySet, keys);
- Assert.fail("Expected " + ODataNotFoundException.class + "was not thrown for '" + readAfterDelete + "'.");
- } catch (ODataNotFoundException e) { }
- }
-
- @Test(expected=ODataRuntimeException.class)
- public void unknownEntitySetForEntity() throws Exception {
- String entitySetName = "Unknown";
- FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
- //
- datasource.readData(edmEntitySet, keys);
- }
-
- @Test(expected=ODataRuntimeException.class)
- public void unknownEntitySetForEntities() throws Exception {
- String entitySetName = "Unknown";
- FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- //
- datasource.readData(edmEntitySet);
- }
-
-
- private EdmEntitySet createMockedEdmEntitySet(final String entitySetName) throws ODataException {
- return createMockedEdmEntitySet(edmProvider, entitySetName);
- }
-
- private EdmEntitySet createMockedEdmEntitySet(AnnotationEdmProvider edmProvider, final String entitySetName)
- throws ODataException {
- EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
- FullQualifiedName entityType = entitySet.getEntityType();
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- return edmEntitySet;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
deleted file mode 100644
index 2f9a1e7..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ /dev/null
@@ -1,462 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.annotation.model.Building;
-import org.apache.olingo.odata2.core.annotation.model.City;
-import org.apache.olingo.odata2.core.annotation.model.Employee;
-import org.apache.olingo.odata2.core.annotation.model.Location;
-import org.apache.olingo.odata2.core.annotation.model.Manager;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.Photo;
-import org.apache.olingo.odata2.core.annotation.model.RefBase;
-import org.apache.olingo.odata2.core.annotation.model.Room;
-import org.apache.olingo.odata2.core.annotation.model.Team;
-import org.junit.Test;
-
-/**
- *
- */
-public class AnnotationEdmProviderTest {
-
- @EdmEntityType
- @EdmEntitySet
- private static final class GeneratedNamesTestClass {}
-
- @EdmComplexType
- private static final class GeneratedNamesComplexTestClass {}
-
- @EdmEntityType(namespace = "MyTestNamespace")
- @EdmEntitySet(container = "MyTestContainer")
- private static final class DefinedNamesTestClass {}
-
- private final AnnotationEdmProvider aep;
- private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
-
- public AnnotationEdmProviderTest() {
- annotatedClasses.add(RefBase.class);
- annotatedClasses.add(Building.class);
- annotatedClasses.add(City.class);
- annotatedClasses.add(Employee.class);
- annotatedClasses.add(Location.class);
- annotatedClasses.add(Manager.class);
- annotatedClasses.add(Photo.class);
- annotatedClasses.add(Room.class);
- annotatedClasses.add(Team.class);
-
- aep = new AnnotationEdmProvider(annotatedClasses);
- }
-
- @Test
- public void defaultNamespaceGeneration() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(GeneratedNamesTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- EntityType testType = localAep.getEntityType(new FullQualifiedName(
- GeneratedNamesTestClass.class.getPackage().getName(),
- GeneratedNamesTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testType);
- assertEquals("GeneratedNamesTestClass", testType.getName());
- assertNull("This should not have a base type", testType.getBaseType());
- }
-
- @Test
- public void defaultNamespaceGenerationComplexType() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- ComplexType testType = localAep.getComplexType(new FullQualifiedName(
- GeneratedNamesComplexTestClass.class.getPackage().getName(),
- GeneratedNamesComplexTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testType);
- assertEquals("GeneratedNamesComplexTestClass", testType.getName());
- assertNull("This should not have a base type", testType.getBaseType());
- }
-
- @Test
- public void defaultContainerNameGeneration() throws ODataException {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- AnnotationEdmProvider localAep =
- new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
-
- EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
- assertNotNull(containerInfo);
- assertEquals("DefaultContainer", containerInfo.getName());
- }
-
- @Test
- public void defaultNamespaceDefined() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(DefinedNamesTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
- DefinedNamesTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testClass);
- assertEquals("DefinedNamesTestClass", testClass.getName());
- assertNull("This should not have a base type", testClass.getBaseType());
- }
-
- @Test
- public void defaultContainerNameDefined() throws ODataException {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
-
- EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
- assertNotNull(containerInfo);
- assertEquals("MyTestContainer", containerInfo.getName());
- }
-
- @Test
- public void loadAnnotatedClassesFromPackage() throws Exception {
- AnnotationEdmProvider localAep = new AnnotationEdmProvider("org.apache.olingo.odata2.core.annotation.model");
-
- // validate employee
- EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- assertEquals("Employee", employee.getName());
- final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
- assertEquals(1, employeeKeys.size());
- assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(6, employee.getProperties().size());
- assertEquals(3, employee.getNavigationProperties().size());
-
- List<Schema> schemas = localAep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
- assertTrue(info.isDefaultEntityContainer());
- }
-
- @Test
- public void annotationProviderBasic() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
- assertTrue(info.isDefaultEntityContainer());
-
- FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
- assertNull(funImp);
-
- final FullQualifiedName associationFqn = new FullQualifiedName(
- ModelSharedConstants.NAMESPACE_1, "NoAssociation");
- Association noAssociation = aep.getAssociation(associationFqn);
- assertNull(noAssociation);
-
- AssociationSet noAssociationSet = aep.getAssociationSet(
- ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
- assertNull(noAssociationSet);
-
- AssociationSet asBuildingRooms = aep.getAssociationSet(
- ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
- assertNotNull(asBuildingRooms);
- assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
- assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
- assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
- assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
- }
-
- @Test
- public void annotationProviderGetDefaultContainer() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = aep.getEntityContainerInfo(null);
- assertTrue(info.isDefaultEntityContainer());
- assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
- }
-
- @Test
- public void schemaBasic() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
-
- Schema schema = schemas.get(0);
- List<EntityContainer> containers = schema.getEntityContainers();
- assertEquals(1, containers.size());
- EntityContainer container = containers.get(0);
- assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
- final List<EntitySet> entitySets = container.getEntitySets();
- assertEquals(6, entitySets.size());
-
- List<Association> associations = schema.getAssociations();
- assertEquals(4, associations.size());
- for (Association association : associations) {
- assertNotNull(association.getName());
- validateAssociation(association);
- }
- }
-
- private FullQualifiedName defaultFqn(final String name) {
- return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
- }
-
- private void validateAssociation(final Association association) {
- String name = association.getName();
- if (name.equals("r_Employee-r_Room")) {
- validateAssociation(association,
- "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if (name.equals("BuildingRooms")) {
- validateAssociation(association,
- "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
- "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
- } else if (name.equals("ManagerEmployees")) {
- validateAssociation(association,
- "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if (name.equals("TeamEmployees")) {
- validateAssociation(association,
- "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else {
- fail("Got unknown association to validate with name '" + name + "'.");
- }
- }
-
- private void validateAssociation(final Association association,
- final String fromRole, final EdmMultiplicity fromMulti, final FullQualifiedName fromType,
- final String toRole, final EdmMultiplicity toMulti, final FullQualifiedName toType) {
-
- AssociationEnd[] ends = new AssociationEnd[] { association.getEnd1(), association.getEnd2() };
- for (AssociationEnd associationEnd : ends) {
- if (associationEnd.getRole().equals(fromRole)) {
- validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
- } else if (associationEnd.getRole().equals(toRole)) {
- validateAssociationEnd(associationEnd, toRole, toMulti, toType);
- } else {
- fail("Unexpected navigation end '" + associationEnd.getRole()
- + "' for association with name '" + association.getName() + "'.");
- }
- }
- }
-
- private void validateAssociationEnd(final AssociationEnd associationEnd,
- final String role, final EdmMultiplicity multiplicity, final FullQualifiedName type) {
- assertEquals(role, associationEnd.getRole());
- assertEquals(multiplicity, associationEnd.getMultiplicity());
- assertEquals(type, associationEnd.getType());
- }
-
- @Test
- public void entitySetTeams() throws Exception {
- // validate teams
- EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
- assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
- assertEquals("Team", teams.getEntityType().getName());
- }
-
- @Test
- public void entityTypeEmployee() throws Exception {
- // validate employee
- EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- assertEquals("Employee", employee.getName());
- final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
- assertEquals(1, employeeKeys.size());
- assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(6, employee.getProperties().size());
- assertEquals(3, employee.getNavigationProperties().size());
-
- for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
- if (navigationProperty.getName().equals("ne_Manager")) {
- validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
- } else if (navigationProperty.getName().equals("ne_Team")) {
- validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
- } else if (navigationProperty.getName().equals("ne_Room")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
- } else {
- fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
- }
- }
- }
-
- @Test
- public void entityTypeTeam() throws Exception {
- // validate team
- EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
- assertEquals("Team", team.getName());
- assertEquals("Base", team.getBaseType().getName());
- assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
-
- assertEquals(1, team.getProperties().size());
- assertEquals(1, team.getNavigationProperties().size());
- NavigationProperty navigationProperty = team.getNavigationProperties().get(0);
- validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
- }
-
- @Test
- public void entityTypePhotoWithTwoKeyProperties() throws Exception {
- // validate team
- EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
- assertEquals("Photo", photo.getName());
- final List<Property> properties = photo.getProperties();
- assertEquals(5, properties.size());
- assertTrue(containsProperty(properties, "Name"));
- assertTrue(containsProperty(properties, "ImageFormat"));
- assertTrue(containsProperty(properties, "MimeType"));
- assertTrue(containsProperty(properties, "ImageUrl"));
- assertTrue(containsProperty(properties, "Image"));
- assertFalse(photo.isAbstract());
- assertTrue(photo.isHasStream());
-
- Key photoKey = photo.getKey();
- List<PropertyRef> keyReferences = photoKey.getKeys();
- assertEquals(2, keyReferences.size());
- PropertyRef name = getPropertyRef(keyReferences, "Name");
- assertEquals("Name", name.getName());
- PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
- assertEquals("ImageFormat", imageFormat.getName());
-
-// assertEquals(0, photo.getNavigationProperties().size());
- assertNull(photo.getNavigationProperties());
- }
-
- @Test
- public void entityTypeAbstractBaseType() throws Exception {
- // validate employee
- EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
- assertEquals("Base", baseType.getName());
- final List<PropertyRef> keys = baseType.getKey().getKeys();
- assertEquals(1, keys.size());
- assertEquals("Id", keys.get(0).getName());
- assertEquals(2, baseType.getProperties().size());
- assertTrue(baseType.isAbstract());
-
- // validate base for team
- EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
- assertEquals("Team", team.getName());
- assertEquals("Base", team.getBaseType().getName());
- assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
- }
-
- @Test
- public void complexTypeLocation() throws Exception {
- // validate employee
- EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- final List<Property> properties = employee.getProperties();
- Property location = null;
- for (Property property : properties) {
- if (property.getName().equals("Location")) {
- location = property;
- }
- }
- assertNotNull(location);
- assertEquals("Location", location.getName());
-
- // validate location complex type
- ComplexType locationType = aep.getComplexType(
- new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
- assertEquals("c_Location", locationType.getName());
- assertEquals(2, locationType.getProperties().size());
- }
-
- @Test
- public void entityTypeRoomWithNavigation() throws Exception {
- // validate employee
- EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
- assertEquals("Room", room.getName());
- assertEquals("Base", room.getBaseType().getName());
- assertEquals(2, room.getProperties().size());
- final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
- assertEquals(2, navigationProperties.size());
-
- for (NavigationProperty navigationProperty : navigationProperties) {
- if (navigationProperty.getName().equals("nr_Employees")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
- } else if (navigationProperty.getName().equals("nr_Building")) {
- validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
- } else {
- fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
- }
- }
- }
-
- private void validateNavProperty(final NavigationProperty navigationProperty, final String name,
- final String relationship, final String fromRole, final String toRole) {
- if (name != null) {
- assertEquals(name, navigationProperty.getName());
- }
- FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
- assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
- assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
- assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
- }
-
- private void validateNavProperty(final NavigationProperty navigationProperty,
- final String relationship, final String fromRole, final String toRole) {
- validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
- }
-
- private boolean containsProperty(final List<Property> properties, final String propertyName) {
- return getProperty(properties, propertyName) != null;
- }
-
- private Property getProperty(final List<Property> properties, final String name) {
- for (Property property : properties) {
- if (name.equals(property.getName())) {
- return property;
- }
- }
- return null;
- }
-
- private PropertyRef getPropertyRef(final List<PropertyRef> properties, final String name) {
- for (PropertyRef property : properties) {
- if (name.equals(property.getName())) {
- return property;
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
deleted file mode 100644
index 9f9dc00..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ /dev/null
@@ -1,99 +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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Buildings")
-public class Building {
- @EdmKey
- @EdmProperty(type = EdmType.INT32)
- private String id;
- @EdmProperty
- private String name;
- @EdmProperty(name = "Image", type = EdmType.BINARY)
- private byte[] image;
- @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
- association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
- private List<Room> rooms = new ArrayList<Room>();
-
- public Building() {}
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setImage(final byte[] byteArray) {
- image = byteArray;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- } else {
- return image.clone();
- }
- }
-
- public List<Room> getRooms() {
- return rooms;
- }
-
- @Override
- public int hashCode() {
- return id == null ? 0 : id.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
deleted file mode 100644
index a4b48fd..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
+++ /dev/null
@@ -1,61 +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.odata2.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmComplexType(name = "c_City", namespace = ModelSharedConstants.NAMESPACE_1)
-public class City {
-
- @EdmProperty
- private String postalCode;
- @EdmProperty
- private String cityName;
-
- public City(final String postalCode, final String name) {
- this.postalCode = postalCode;
- cityName = name;
- }
-
- public void setPostalCode(final String postalCode) {
- this.postalCode = postalCode;
- }
-
- public String getPostalCode() {
- return postalCode;
- }
-
- public void setCityName(final String cityName) {
- this.cityName = cityName;
- }
-
- public String getCityName() {
- return cityName;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", cityName, postalCode);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
deleted file mode 100644
index 63b8a76..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ /dev/null
@@ -1,187 +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.odata2.core.annotation.model;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Employees")
-public class Employee {
- @EdmKey
- @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
- private String employeeId;
- @EdmProperty(name = "EmployeeName")
- private String employeeName;
- @EdmProperty
- private int age;
- @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
- private Manager manager;
- @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
- private Team team;
- @EdmNavigationProperty(name = "ne_Room")
- private Room room;
- @EdmMediaResourceMimeType
- private String imageType;
- @EdmMediaResourceContent
- private byte[] image;
- @EdmProperty(name = "ImageUrl")
- private String imageUrl;
- @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
- private Calendar entryDate;
- @EdmProperty(name = "Location")
- private Location location;
-
- public Employee(final String employeeId, final String name) {
- this.employeeId = employeeId;
- setEmployeeName(name);
- }
-
- public String getId() {
- return employeeId;
- }
-
- public void setEmployeeName(final String employeeName) {
- this.employeeName = employeeName;
- }
-
- public String getEmployeeName() {
- return employeeName;
- }
-
- public void setAge(final int age) {
- this.age = age;
- }
-
- public int getAge() {
- return age;
- }
-
- public void setManager(final Manager manager) {
- this.manager = manager;
- }
-
- public Manager getManager() {
- return manager;
- }
-
- public void setTeam(final Team team) {
- this.team = team;
- }
-
- public Team getTeam() {
- return team;
- }
-
- public void setRoom(final Room room) {
- this.room = room;
- }
-
- public Room getRoom() {
- return room;
- }
-
- public void setImageUri(final String imageUri) {
- imageUrl = imageUri;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setLocation(final Location location) {
- this.location = location;
- }
-
- public Location getLocation() {
- return location;
- }
-
- public void setEntryDate(final Calendar date) {
- entryDate = date;
- }
-
- public Calendar getEntryDate() {
- return entryDate;
- }
-
- public void setImageType(final String imageType) {
- this.imageType = imageType;
- }
-
- public String getImageType() {
- return imageType;
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- }
- return image.clone();
- }
-
- @Override
- public int hashCode() {
- if (employeeId == null) {
- return 0;
- }
- return employeeId.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
- }
-
- @Override
- public String toString() {
- return "{\"EmployeeId\":\"" + employeeId + "\","
- + "\"EmployeeName\":\"" + employeeName + "\","
- + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
- + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
- + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
- + "\"Location\":"
- + (location == null ? "null" :
- "{\"City\":" + (location.getCity() == null ? "null" :
- "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
- + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
- + "\"Country\":\"" + location.getCountry() + "\"}") + ","
- + "\"Age\":" + age + ","
- + "\"EntryDate\":"
- + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
- + "\"ImageUrl\":\"" + imageUrl + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
deleted file mode 100644
index 288de70..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
+++ /dev/null
@@ -1,60 +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.odata2.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
-public class Location {
- @EdmProperty
- private String country;
- @EdmProperty
- private City city;
-
- public Location(final String country, final String postalCode, final String cityName) {
- this.country = country;
- city = new City(postalCode, cityName);
- }
-
- public void setCountry(final String country) {
- this.country = country;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCity(final City city) {
- this.city = city;
- }
-
- public City getCity() {
- return city;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", country, city.toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
deleted file mode 100644
index e3edbd0..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ /dev/null
@@ -1,47 +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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-
-/**
- *
- */
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Managers")
-public class Manager extends Employee {
-
- @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Manager(final String id, final String name) {
- super(id, name);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
deleted file mode 100644
index 1d44498..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
+++ /dev/null
@@ -1,25 +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.odata2.core.annotation.model;
-
-public interface ModelSharedConstants {
-
- String NAMESPACE_1 = "RefScenario";
- String CONTAINER_1 = "DefaultContainer";
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
deleted file mode 100644
index 8c920e4..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ /dev/null
@@ -1,128 +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.odata2.core.annotation.model;
-
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Photos")
-public class Photo {
- @EdmProperty
- @EdmKey
- private String name;
- @EdmProperty(name = "ImageFormat")
- @EdmKey
- private String type;
- @EdmProperty
- @EdmMediaResourceMimeType
- private String mimeType;
- @EdmProperty
- @EdmMediaResourceSource
- private String imageUrl = "http://localhost/someResource.png";
- @EdmProperty(type = EdmType.BINARY)
- @EdmMediaResourceContent
- private byte[] image = ResourceHelper.generateImage();
-
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(final String type) {
- this.type = type;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setImageUri(final String uri) {
- imageUrl = uri;
- }
-
- public byte[] getImage() {
- return image.clone();
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public String getImageType() {
- return mimeType;
- }
-
- public void setImageType(final String imageType) {
- mimeType = imageType;
- }
-
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 83 * hash + (name != null ? name.hashCode() : 0);
- hash = 83 * hash + (type != null ? type.hashCode() : 0);
- return hash;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Photo other = (Photo) obj;
- if ((name == null) ? (other.name != null) : !name.equals(other.name)) {
- return false;
- }
- if ((type == null) ? (other.type != null) : !type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "{\"Name\":\"" + name + "\","
- + "\"Type\":\"" + type + "\","
- + "\"ImageUrl\":\"" + imageUrl + "\","
- + "\"Image\":\"" + Arrays.toString(image) + "\","
- + "\"MimeType\":\"" + mimeType + "\"";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
deleted file mode 100644
index 8d39492..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Base", namespace = ModelSharedConstants.NAMESPACE_1)
-public abstract class RefBase {
- @EdmProperty(name = "Name")
- protected String name;
- @EdmProperty(name = "Id", type = EdmType.STRING)
- @EdmKey
- protected int id;
-
- public RefBase(final int id, final String name) {
- this.name = name;
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public String getId() {
- return Integer.toString(id);
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public void setId(final int id) {
- this.id = id;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
deleted file mode 100644
index 7edfcfc..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
+++ /dev/null
@@ -1,66 +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.odata2.core.annotation.model;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.WritableRaster;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import javax.imageio.ImageIO;
-
-/**
- *
- */
-public class ResourceHelper {
-
- public enum Format {
- BMP, JPEG, PNG, GIF
- };
-
- public static byte[] generateImage() {
- return generateImage(Format.PNG);
- }
-
- public static byte[] generateImage(final Format format) {
- try {
- int width = 320;
- int height = 320;
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
- WritableRaster raster = image.getRaster();
-
- int mod = format.ordinal() + 2;
- for (int h = 0; h < height; h++) {
- for (int w = 0; w < width; w++) {
- if (((h / 32) + (w / 32)) % mod == 0) {
- raster.setSample(w, h, 0, 0);
- } else {
- raster.setSample(w, h, 0, 1);
- }
- }
- }
-
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- ImageIO.write(image, format.name(), out);
- return out.toByteArray();
- } catch (IOException ex) {
- return new byte[0];
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
deleted file mode 100644
index 6ab8d74..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Rooms")
-public class Room extends RefBase {
-
- @EdmProperty
- private Integer seats;
- @EdmProperty
- private Integer version;
- @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
- private Building building;
- @EdmNavigationProperty(name = "nr_Employees")
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Room() {
- this(0, null);
- }
-
- public Room(final int id, final String name) {
- super(id, name);
- }
-
- public void setSeats(final int seats) {
- this.seats = seats;
- }
-
- public int getSeats() {
- return seats;
- }
-
- public void setVersion(final int version) {
- this.version = version;
- }
-
- public int getVersion() {
- return version;
- }
-
- public void setBuilding(final Building building) {
- this.building = building;
- }
-
- public Building getBuilding() {
- return building;
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
deleted file mode 100644
index 3f72319..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ /dev/null
@@ -1,81 +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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
-*
-*/
-@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Teams")
-public class Team extends RefBase {
- @EdmProperty(type = EdmType.BOOLEAN)
- private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Team() {
- super(-1, null);
- }
-
- public Team(final int id, final String name) {
- super(id, name);
- }
-
- public Boolean isScrumTeam() {
- return isScrumTeam;
- }
-
- public void setScrumTeam(final Boolean isScrumTeam) {
- this.isScrumTeam = isScrumTeam;
- }
-
- public void addEmployee(final Employee e) {
- employees.add(e);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
- }
-}
[33/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java
new file mode 100644
index 0000000..97e438e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelService.java
@@ -0,0 +1,247 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEdmMappingModel;
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEmbeddableTypeMapType;
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEntityTypeMapType;
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAPersistenceUnitMapType;
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAAttributeMapType.JPAAttribute;
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPARelationshipMapType.JPARelationship;
+
+public class JPAEdmMappingModelService implements JPAEdmMappingModelAccess {
+
+ boolean mappingModelExists = true;
+ private JPAEdmMappingModel mappingModel;
+ private String mappingModelName;
+
+ public JPAEdmMappingModelService(final ODataJPAContext ctx) {
+ mappingModelName = ctx.getJPAEdmMappingModel();
+ if (mappingModelName == null) {
+ mappingModelExists = false;
+ }
+ }
+
+ @Override
+ public void loadMappingModel() {
+
+ if (mappingModelExists) {
+ JAXBContext context;
+ try {
+ context = JAXBContext.newInstance(JPAEdmMappingModel.class);
+
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ InputStream is = loadMappingModelInputStream();
+ if (is == null) {
+ mappingModelExists = false;
+ return;
+ }
+
+ mappingModel = (JPAEdmMappingModel) unmarshaller.unmarshal(is);
+
+ if (mappingModel != null) {
+ mappingModelExists = true;
+ }
+
+ } catch (JAXBException e) {
+ mappingModelExists = false;
+ ODataJPAModelException.throwException(ODataJPAModelException.GENERAL, e);
+ }
+ }
+ }
+
+ @Override
+ public boolean isMappingModelExists() {
+ return mappingModelExists;
+ }
+
+ @Override
+ public JPAEdmMappingModel getJPAEdmMappingModel() {
+ return mappingModel;
+ }
+
+ @Override
+ public String mapJPAPersistenceUnit(final String persistenceUnitName) {
+
+ JPAPersistenceUnitMapType persistenceUnit = mappingModel.getPersistenceUnit();
+ if (persistenceUnit.getName().equals(persistenceUnitName)) {
+ return persistenceUnit.getEDMSchemaNamespace();
+ }
+
+ return null;
+ }
+
+ @Override
+ public String mapJPAEntityType(final String jpaEntityTypeName) {
+
+ JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
+ if (jpaEntityTypeMap != null) {
+ return jpaEntityTypeMap.getEDMEntityType();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String mapJPAEntitySet(final String jpaEntityTypeName) {
+ JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
+ if (jpaEntityTypeMap != null) {
+ return jpaEntityTypeMap.getEDMEntitySet();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String mapJPAAttribute(final String jpaEntityTypeName, final String jpaAttributeName) {
+ JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
+ if (jpaEntityTypeMap != null && jpaEntityTypeMap.getJPAAttributes() != null) {
+ // fixing attributes
+ // removal issue
+ // from mapping
+ for (JPAAttribute jpaAttribute : jpaEntityTypeMap.getJPAAttributes().getJPAAttribute()) {
+ if (jpaAttribute.getName().equals(jpaAttributeName)) {
+ return jpaAttribute.getValue();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String mapJPARelationship(final String jpaEntityTypeName, final String jpaRelationshipName) {
+ JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
+ if (jpaEntityTypeMap != null && jpaEntityTypeMap.getJPARelationships() != null) {
+ for (JPARelationship jpaRealtionship : jpaEntityTypeMap.getJPARelationships().getJPARelationship()) {
+ if (jpaRealtionship.getName().equals(jpaRelationshipName)) {
+ return jpaRealtionship.getValue();
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String mapJPAEmbeddableType(final String jpaEmbeddableTypeName) {
+ JPAEmbeddableTypeMapType jpaEmbeddableType = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
+ if (jpaEmbeddableType != null) {
+ return jpaEmbeddableType.getEDMComplexType();
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String mapJPAEmbeddableTypeAttribute(final String jpaEmbeddableTypeName, final String jpaAttributeName) {
+ JPAEmbeddableTypeMapType jpaEmbeddableType = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
+ if (jpaEmbeddableType != null && jpaEmbeddableType.getJPAAttributes() != null) {
+ for (JPAAttribute jpaAttribute : jpaEmbeddableType.getJPAAttributes().getJPAAttribute()) {
+ if (jpaAttribute.getName().equals(jpaAttributeName)) {
+ return jpaAttribute.getValue();
+ }
+ }
+ }
+ return null;
+ }
+
+ private JPAEntityTypeMapType searchJPAEntityTypeMapType(final String jpaEntityTypeName) {
+ for (JPAEntityTypeMapType jpaEntityType : mappingModel.getPersistenceUnit().getJPAEntityTypes()
+ .getJPAEntityType()) {
+ if (jpaEntityType.getName().equals(jpaEntityTypeName)) {
+ return jpaEntityType;
+ }
+ }
+
+ return null;
+ }
+
+ private JPAEmbeddableTypeMapType searchJPAEmbeddableTypeMapType(final String jpaEmbeddableTypeName) {
+ for (JPAEmbeddableTypeMapType jpaEmbeddableType : mappingModel.getPersistenceUnit().getJPAEmbeddableTypes()
+ .getJPAEmbeddableType()) {
+ if (jpaEmbeddableType.getName().equals(jpaEmbeddableTypeName)) {
+ return jpaEmbeddableType;
+ }
+ }
+
+ return null;
+ }
+
+ protected InputStream loadMappingModelInputStream() {
+ InputStream is = JPAEdmMappingModelService.class.getClassLoader().getResourceAsStream("../../" + mappingModelName);
+
+ return is;
+
+ }
+
+ @Override
+ public boolean checkExclusionOfJPAEntityType(final String jpaEntityTypeName) {
+ JPAEntityTypeMapType type = searchJPAEntityTypeMapType(jpaEntityTypeName);
+ if (type != null) {
+ return type.isExclude();
+ }
+ return false;
+ }
+
+ @Override
+ public boolean checkExclusionOfJPAAttributeType(final String jpaEntityTypeName, final String jpaAttributeName) {
+ JPAEntityTypeMapType type = searchJPAEntityTypeMapType(jpaEntityTypeName);
+ if (type != null && type.getJPAAttributes() != null) {
+ for (JPAAttribute jpaAttribute : type.getJPAAttributes().getJPAAttribute()) {
+ if (jpaAttribute.getName().equals(jpaAttributeName)) {
+ return jpaAttribute.isExclude();
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean checkExclusionOfJPAEmbeddableType(final String jpaEmbeddableTypeName) {
+ JPAEmbeddableTypeMapType type = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
+ if (type != null) {
+ return type.isExclude();
+ }
+ return false;
+ }
+
+ @Override
+ public boolean checkExclusionOfJPAEmbeddableAttributeType(final String jpaEmbeddableTypeName,
+ final String jpaAttributeName) {
+ JPAEmbeddableTypeMapType type = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
+ if (type != null && type.getJPAAttributes() != null) {
+ for (JPAAttribute jpaAttribute : type.getJPAAttributes().getJPAAttribute()) {
+ if (jpaAttribute.getName().equals(jpaAttributeName)) {
+ return jpaAttribute.isExclude();
+ }
+ }
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
new file mode 100644
index 0000000..5c8c999
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilder.java
@@ -0,0 +1,499 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+
+import javax.persistence.Column;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.PluralAttribute;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmBaseView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmComplexType;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+
+public class JPAEdmNameBuilder {
+ private static final String ENTITY_CONTAINER_SUFFIX = "Container";
+ private static final String ENTITY_SET_SUFFIX = "s";
+ private static final String ASSOCIATIONSET_SUFFIX = "Set";
+ private static final String NAVIGATION_NAME = "Details";
+ private static final String UNDERSCORE = "_";
+
+ public static FullQualifiedName build(final JPAEdmBaseView view, final String name) {
+ FullQualifiedName fqName = new FullQualifiedName(buildNamespace(view), name);
+ return fqName;
+ }
+
+ /*
+ * ************************************************************************
+ * EDM EntityType Name - RULES
+ * ************************************************************************
+ * EDM Entity Type Name = JPA Entity Name EDM Entity Type Internal Name =
+ * JPA Entity Name
+ * ************************************************************************
+ * EDM Entity Type Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmEntityTypeView view) {
+
+ EntityType edmEntityType = view.getEdmEntityType();
+ String jpaEntityName = view.getJPAEntityType().getName();
+ JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
+ String edmEntityTypeName = null;
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ edmEntityTypeName = mappingModelAccess.mapJPAEntityType(jpaEntityName);
+ }
+
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(view.getJPAEntityType().getJavaType());
+
+ if (edmEntityTypeName == null) {
+ edmEntityTypeName = jpaEntityName;
+ }
+ // Setting the mapping object
+ edmEntityType.setMapping(((Mapping) mapping).setInternalName(jpaEntityName));
+
+ edmEntityType.setName(edmEntityTypeName);
+
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Schema Name - RULES
+ * ************************************************************************
+ * Java Persistence Unit name is set as Schema's Namespace
+ * ************************************************************************
+ * EDM Schema Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmSchemaView view) throws ODataJPAModelException {
+ view.getEdmSchema().setNamespace(buildNamespace(view));
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Property Name - RULES
+ * ************************************************************************
+ * OData Property Names are represented in Camel Case. The first character
+ * of JPA Attribute Name is converted to an UpperCase Character and set as
+ * OData Property Name. JPA Attribute Name is set as Internal Name for OData
+ * Property. The Column name (annotated as @Column(name="x")) is set as
+ * column name in the mapping object.
+ * ************************************************************************
+ * EDM Property Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmPropertyView view, final boolean isComplexMode,
+ final boolean skipDefaultNaming) {
+ Attribute<?, ?> jpaAttribute = view.getJPAAttribute();
+ String jpaAttributeName = jpaAttribute.getName();
+ String propertyName = null;
+
+ JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ if (isComplexMode) {
+ propertyName =
+ mappingModelAccess.mapJPAEmbeddableTypeAttribute(view.getJPAEdmComplexTypeView().getJPAEmbeddableType()
+ .getJavaType().getSimpleName(), jpaAttributeName);
+ } else {
+ propertyName =
+ mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
+ jpaAttributeName);
+ }
+ }
+ if (skipDefaultNaming == false && propertyName == null) {
+ propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
+ } else if (propertyName == null) {
+ propertyName = jpaAttributeName;
+ }
+
+ view.getEdmSimpleProperty().setName(propertyName);
+
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ ((Mapping) mapping).setInternalName(jpaAttributeName);
+ mapping.setJPAType(jpaAttribute.getJavaType());
+
+ AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember();
+ if (annotatedElement != null) {
+ Column column = annotatedElement.getAnnotation(Column.class);
+ if (column != null) {
+ mapping.setJPAColumnName(column.name());
+ }
+ } else {
+ ManagedType<?> managedType = jpaAttribute.getDeclaringType();
+ if (managedType != null) {
+ Class<?> clazz = managedType.getJavaType();
+ try {
+ Field field = clazz.getField(jpaAttributeName);
+ Column column = field.getAnnotation(Column.class);
+ if (column != null) {
+ mapping.setJPAColumnName(column.name());
+ }
+ } catch (SecurityException e) {
+
+ } catch (NoSuchFieldException e) {
+
+ }
+ }
+
+ }
+ view.getEdmSimpleProperty().setMapping((Mapping) mapping);
+ }
+
+ /*
+ * ************************************************************************
+ * EDM EntityContainer Name - RULES
+ * ************************************************************************
+ * Entity Container Name = EDM Namespace + Literal "Container"
+ * ************************************************************************
+ * EDM EntityContainer Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmEntityContainerView view) {
+ view.getEdmEntityContainer().setName(buildNamespace(view) + ENTITY_CONTAINER_SUFFIX);
+ }
+
+ /*
+ * ************************************************************************
+ * EDM EntitySet Name - RULES
+ * ************************************************************************
+ * Entity Set Name = JPA Entity Type Name + Literal "s"
+ * ************************************************************************
+ * EDM EntitySet Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmEntitySetView view, final JPAEdmEntityTypeView entityTypeView) {
+ FullQualifiedName fQname = view.getEdmEntitySet().getEntityType();
+ JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
+ String entitySetName = null;
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ Mapping mapping = entityTypeView.getEdmEntityType().getMapping();
+ if (mapping != null) {
+ entitySetName = mappingModelAccess.mapJPAEntitySet(mapping.getInternalName());
+ }
+ }
+
+ if (entitySetName == null) {
+ entitySetName = fQname.getName() + ENTITY_SET_SUFFIX;
+ }
+
+ view.getEdmEntitySet().setName(entitySetName);
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Complex Type Name - RULES
+ * ************************************************************************
+ * Complex Type Name = JPA Embeddable Type Simple Name.
+ * ************************************************************************
+ * EDM Complex Type Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmComplexType view) {
+
+ JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
+ String jpaEmbeddableTypeName = view.getJPAEmbeddableType().getJavaType().getSimpleName();
+ String edmComplexTypeName = null;
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ edmComplexTypeName = mappingModelAccess.mapJPAEmbeddableType(jpaEmbeddableTypeName);
+ }
+
+ if (edmComplexTypeName == null) {
+ edmComplexTypeName = jpaEmbeddableTypeName;
+ }
+
+ view.getEdmComplexType().setName(edmComplexTypeName);
+ ComplexType complexType = view.getEdmComplexType();
+ complexType.setName(edmComplexTypeName);
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(view.getJPAEmbeddableType().getJavaType());
+ complexType.setMapping((Mapping) mapping);
+
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Complex Property Name - RULES
+ * ************************************************************************
+ * The first character of JPA complex attribute name is converted to
+ * uppercase. The modified JPA complex attribute name is assigned as EDM
+ * complex property name. The unmodified JPA complex attribute name is
+ * assigned as internal name.
+ * ************************************************************************
+ * EDM Complex Property Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmComplexPropertyView complexView,
+ final JPAEdmPropertyView propertyView, final boolean skipDefaultNaming) {
+
+ ComplexProperty complexProperty = complexView.getEdmComplexProperty();
+
+ String jpaAttributeName = propertyView.getJPAAttribute().getName();
+ String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView().getJPAEntityType().getName();
+
+ JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
+ String propertyName = null;
+
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ propertyName = mappingModelAccess.mapJPAAttribute(jpaEntityTypeName, jpaAttributeName);
+ }
+
+ if (skipDefaultNaming == false && propertyName == null) {
+ propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
+ } else if (propertyName == null) {
+ propertyName = jpaAttributeName;
+ }
+
+ // change for navigation property issue
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ ((Mapping) mapping).setInternalName(jpaAttributeName);
+ mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
+ complexProperty.setMapping((Mapping) mapping);
+
+ complexProperty.setName(propertyName);
+
+ }
+
+ public static void build(final JPAEdmComplexPropertyView complexView,
+ final String parentComplexTypeName, final boolean skipDefaultNaming) {
+ ComplexProperty complexProperty = complexView.getEdmComplexProperty();
+
+ JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
+ JPAEdmPropertyView propertyView = ((JPAEdmPropertyView) complexView);
+ String jpaAttributeName = propertyView.getJPAAttribute().getName();
+ String propertyName = null;
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ propertyName = mappingModelAccess.mapJPAEmbeddableTypeAttribute(parentComplexTypeName, jpaAttributeName);
+ }
+ if (skipDefaultNaming == false && propertyName == null) {
+ propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
+ } else if (propertyName == null) {
+ propertyName = jpaAttributeName;
+ }
+
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ ((Mapping) mapping).setInternalName(jpaAttributeName);
+ mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
+ complexProperty.setMapping((Mapping) mapping);
+ complexProperty.setName(propertyName);
+
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Association End Name - RULES
+ * ************************************************************************
+ * Association End name = Namespace + Entity Type Name
+ * ************************************************************************
+ * EDM Association End Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmAssociationEndView assocaitionEndView,
+ final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) {
+
+ String namespace = buildNamespace(assocaitionEndView);
+
+ String name = entityTypeView.getEdmEntityType().getName();
+ FullQualifiedName fQName = new FullQualifiedName(namespace, name);
+ assocaitionEndView.getEdmAssociationEnd1().setType(fQName);
+
+ name = null;
+ String jpaEntityTypeName = null;
+ Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
+ if (jpaAttribute.isCollection()) {
+ jpaEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType()
+ .getSimpleName();
+ } else {
+ jpaEntityTypeName = propertyView.getJPAAttribute().getJavaType()
+ .getSimpleName();
+ }
+
+ JPAEdmMappingModelAccess mappingModelAccess = assocaitionEndView.getJPAEdmMappingModelAccess();
+
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ name = mappingModelAccess.mapJPAEntityType(jpaEntityTypeName);
+ }
+
+ if (name == null) {
+ name = jpaEntityTypeName;
+ }
+
+ fQName = new FullQualifiedName(namespace, name);
+ assocaitionEndView.getEdmAssociationEnd2().setType(fQName);
+
+ }
+
+ private static String buildNamespace(final JPAEdmBaseView view) {
+ JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
+ String namespace = null;
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ namespace = mappingModelAccess.mapJPAPersistenceUnit(view.getpUnitName());
+ }
+ if (namespace == null) {
+ namespace = view.getpUnitName();
+ }
+
+ return namespace;
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Association Name - RULES
+ * ************************************************************************
+ * Association name = Association + End1 Name + End2 Name
+ * ************************************************************************
+ * EDM Association Name - RULES
+ * ************************************************************************
+ */
+
+ public static void build(final JPAEdmAssociationView view, final int count) {
+ Association association = view.getEdmAssociation();
+ String associationName = null;
+ String end1Name = association.getEnd1().getType().getName();
+ String end2Name = association.getEnd2().getType().getName();
+
+ if (end1Name.compareToIgnoreCase(end2Name) > 0) {
+ associationName = end2Name + UNDERSCORE + end1Name;
+ } else {
+ associationName = end1Name + UNDERSCORE + end2Name;
+ }
+ if (count > 1) {
+ associationName = associationName + Integer.toString(count - 1);
+ }
+ association.setName(associationName);
+
+ }
+
+ /*
+ * ************************************************************************
+ * EDM Association Set Name - RULES
+ * ************************************************************************
+ * Association Set name = Association Name + "Set"
+ * ************************************************************************
+ * EDM Association Set Name - RULES
+ * ************************************************************************
+ */
+ public static void build(final JPAEdmAssociationSetView view) {
+ AssociationSet associationSet = view.getEdmAssociationSet();
+
+ String name = view.getEdmAssociation().getName();
+ associationSet.setName(name + ASSOCIATIONSET_SUFFIX);
+
+ }
+
+ public static void build(final JPAEdmAssociationView associationView,
+ final JPAEdmPropertyView propertyView,
+ final JPAEdmNavigationPropertyView navPropertyView, final boolean skipDefaultNaming, final int count) {
+
+ String toName = null;
+ String fromName = null;
+ String navPropName = null;
+ NavigationProperty navProp = navPropertyView.getEdmNavigationProperty();
+ String namespace = buildNamespace(associationView);
+
+ Association association = associationView.getEdmAssociation();
+ navProp.setRelationship(new FullQualifiedName(namespace, association
+ .getName()));
+
+ FullQualifiedName associationEndTypeOne = association.getEnd1()
+ .getType();
+ FullQualifiedName associationEndTypeTwo = association.getEnd2()
+ .getType();
+
+ Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ ((Mapping) mapping).setInternalName(jpaAttribute.getName());
+ mapping.setJPAType(jpaAttribute.getJavaType());
+ navProp.setMapping((Mapping) mapping);
+
+ String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView()
+ .getJPAEntityType().getName();
+ JPAEdmMappingModelAccess mappingModelAccess = navPropertyView
+ .getJPAEdmMappingModelAccess();
+
+ String targetEntityTypeName = null;
+ if (jpaAttribute.isCollection()) {
+ targetEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType().getSimpleName();
+ } else {
+ targetEntityTypeName = jpaAttribute.getJavaType().getSimpleName();
+ }
+
+ if (mappingModelAccess != null
+ && mappingModelAccess.isMappingModelExists()) {
+ navPropName = mappingModelAccess.mapJPARelationship(
+ jpaEntityTypeName, jpaAttribute.getName());
+ toName = mappingModelAccess.mapJPAEntityType(targetEntityTypeName);
+ fromName = mappingModelAccess
+ .mapJPAEntityType(jpaEntityTypeName);
+ }
+ if (toName == null) {
+ toName = targetEntityTypeName;
+ }
+
+ if (fromName == null) {
+ fromName = jpaEntityTypeName;
+ }
+
+ if (skipDefaultNaming == false) {
+ if (navPropName == null) {
+ navPropName = toName.concat(NAVIGATION_NAME);
+ }
+ if (count > 1) {
+ navPropName = navPropName + Integer.toString(count - 1);
+ }
+ } else if (navPropName == null) {
+ navPropName = jpaAttribute.getName();
+ }
+
+ navProp.setName(navPropName);
+
+ if (toName.equals(associationEndTypeOne.getName())) {
+ navProp.setFromRole(association.getEnd2().getRole());
+ navProp.setToRole(association.getEnd1().getRole());
+ } else if (toName.equals(associationEndTypeTwo.getName())) {
+
+ navProp.setToRole(association.getEnd2().getRole());
+ navProp.setFromRole(association.getEnd1().getRole());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
new file mode 100644
index 0000000..e35e4cf
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertor.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+
+/**
+ * This class holds utility methods for Type conversions between JPA and OData Types.
+ *
+ *
+ *
+ */
+public class JPATypeConvertor {
+
+ /**
+ * This utility method converts a given jpa Type to equivalent
+ * EdmSimpleTypeKind for maintaining compatibility between Java and OData
+ * Types.
+ *
+ * @param jpaType
+ * The JPA Type input.
+ * @return The corresponding EdmSimpleTypeKind.
+ * @throws ODataJPAModelException
+ * @throws org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException
+ *
+ * @see EdmSimpleTypeKind
+ */
+
+ private static final String OBJECT_TYPE = "java.lang.Object";
+
+ public static EdmSimpleTypeKind
+ convertToEdmSimpleType(final Class<?> jpaType, final Attribute<?, ?> currentAttribute)
+ throws ODataJPAModelException {
+ if (jpaType.equals(String.class) || jpaType.equals(Character.class) || jpaType.equals(char.class)
+ || jpaType.equals(char[].class) ||
+ jpaType.equals(Character[].class)) {
+ return EdmSimpleTypeKind.String;
+ } else if (jpaType.equals(Long.class) || jpaType.equals(long.class)) {
+ return EdmSimpleTypeKind.Int64;
+ } else if (jpaType.equals(Short.class) || jpaType.equals(short.class)) {
+ return EdmSimpleTypeKind.Int16;
+ } else if (jpaType.equals(Integer.class) || jpaType.equals(int.class)) {
+ return EdmSimpleTypeKind.Int32;
+ } else if (jpaType.equals(Double.class) || jpaType.equals(double.class)) {
+ return EdmSimpleTypeKind.Double;
+ } else if (jpaType.equals(Float.class) || jpaType.equals(float.class)) {
+ return EdmSimpleTypeKind.Single;
+ } else if (jpaType.equals(BigDecimal.class)) {
+ return EdmSimpleTypeKind.Decimal;
+ } else if (jpaType.equals(byte[].class)) {
+ return EdmSimpleTypeKind.Binary;
+ } else if (jpaType.equals(Byte.class) || jpaType.equals(byte.class)) {
+ return EdmSimpleTypeKind.Byte;
+ } else if (jpaType.equals(Byte[].class)) {
+ return EdmSimpleTypeKind.Binary;
+ } else if (jpaType.equals(Boolean.class) || jpaType.equals(boolean.class)) {
+ return EdmSimpleTypeKind.Boolean;
+ } else if ((jpaType.equals(Date.class)) || (jpaType.equals(Calendar.class))) {
+ try {
+ if ((currentAttribute != null)
+ && (determineTemporalType(currentAttribute.getDeclaringType().getJavaType(), currentAttribute.getName())
+ == TemporalType.TIME)) {
+ return EdmSimpleTypeKind.Time;
+ } else {
+ return EdmSimpleTypeKind.DateTime;
+ }
+ } catch (SecurityException e) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
+ }
+ } else if (jpaType.equals(UUID.class)) {
+ return EdmSimpleTypeKind.Guid;
+ }
+ throw ODataJPAModelException.throwException(ODataJPAModelException.TYPE_NOT_SUPPORTED
+ .addContent(jpaType.toString()), null);
+ }
+
+ private static TemporalType determineTemporalType(final Class<?> type, final String fieldName)
+ throws ODataJPAModelException {
+ if (type != null && !type.getName().equals(OBJECT_TYPE)) {
+ try {
+ Field field = type.getField(fieldName);
+ return field.getAnnotation(Temporal.class).value();
+ } catch (NoSuchFieldException e) {
+ determineTemporalType(type.getSuperclass(), fieldName);
+ } catch (SecurityException e) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
+ }
+ }
+ return null;
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
new file mode 100644
index 0000000..101db9b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProvider.java
@@ -0,0 +1,295 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.edm;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+
+public class ODataJPAEdmProvider extends EdmProvider {
+
+ private ODataJPAContext oDataJPAContext;
+ private JPAEdmModelView jpaEdmModel;
+
+ private List<Schema> schemas;
+ private HashMap<String, EntityType> entityTypes;
+ private HashMap<String, EntityContainerInfo> entityContainerInfos;
+ private HashMap<String, ComplexType> complexTypes;
+ private HashMap<String, Association> associations;
+ private HashMap<String, FunctionImport> functionImports;
+
+ public ODataJPAEdmProvider() {
+ entityTypes = new HashMap<String, EntityType>();
+ entityContainerInfos = new HashMap<String, EntityContainerInfo>();
+ complexTypes = new HashMap<String, ComplexType>();
+ associations = new HashMap<String, Association>();
+ functionImports = new HashMap<String, FunctionImport>();
+ }
+
+ public ODataJPAEdmProvider(final ODataJPAContext oDataJPAContext) {
+ if (oDataJPAContext == null) {
+ throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
+ }
+ entityTypes = new HashMap<String, EntityType>();
+ entityContainerInfos = new HashMap<String, EntityContainerInfo>();
+ complexTypes = new HashMap<String, ComplexType>();
+ associations = new HashMap<String, Association>();
+ functionImports = new HashMap<String, FunctionImport>();
+ jpaEdmModel = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmModelView(oDataJPAContext);
+ }
+
+ public ODataJPAContext getODataJPAContext() {
+ return oDataJPAContext;
+ }
+
+ public void setODataJPAContext(final ODataJPAContext jpaContext) {
+ oDataJPAContext = jpaContext;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
+
+ if (entityContainerInfos.containsKey(name)) {
+ return entityContainerInfos.get(name);
+ } else {
+
+ if (schemas == null) {
+ getSchemas();
+ }
+ List<EntityContainer> containerList = schemas.get(0).getEntityContainers();
+ if (containerList == null) {
+ return null;
+ }
+ for (EntityContainer container : containerList) {
+ if (name == null && container.isDefaultEntityContainer()) {
+ entityContainerInfos.put(name, container);
+ return container;
+ } else if (name != null && name.equals(container.getName())) {
+ return container;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
+
+ String strEdmFQName = edmFQName.toString();
+
+ if (edmFQName != null) {
+ if (entityTypes.containsKey(strEdmFQName)) {
+ return entityTypes.get(strEdmFQName);
+ } else if (schemas == null) {
+ getSchemas();
+ }
+
+ String entityTypeNamespace = edmFQName.getNamespace();
+ String entityTypeName = edmFQName.getName();
+
+ for (Schema schema : schemas) {
+ String schemaNamespace = schema.getNamespace();
+ if (schemaNamespace.equals(entityTypeNamespace)) {
+ if (schema.getEntityTypes() == null) {
+ return null;
+ }
+ for (EntityType et : schema.getEntityTypes()) {
+ if (et.getName().equals(entityTypeName)) {
+ entityTypes.put(strEdmFQName, et);
+ return et;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
+
+ if (edmFQName != null) {
+ if (complexTypes.containsKey(edmFQName.toString())) {
+ return complexTypes.get(edmFQName.toString());
+ } else if (schemas == null) {
+ getSchemas();
+ }
+
+ for (Schema schema : schemas) {
+ if (schema.getNamespace().equals(edmFQName.getNamespace())) {
+ if (schema.getComplexTypes() == null) {
+ return null;
+ }
+ for (ComplexType ct : schema.getComplexTypes()) {
+ if (ct.getName().equals(edmFQName.getName())) {
+ complexTypes.put(edmFQName.toString(), ct);
+ return ct;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
+ if (edmFQName != null) {
+ if (associations.containsKey(edmFQName.toString())) {
+ return associations.get(edmFQName.toString());
+ } else if (schemas == null) {
+ getSchemas();
+ }
+
+ for (Schema schema : schemas) {
+ if (schema.getNamespace().equals(edmFQName.getNamespace())) {
+ if (schema.getAssociations() == null) {
+ return null;
+ }
+ for (Association association : schema.getAssociations()) {
+ if (association.getName().equals(edmFQName.getName())) {
+ associations.put(edmFQName.toString(), association);
+ return association;
+ }
+ }
+ }
+ }
+
+ }
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
+
+ EntitySet returnedSet = null;
+ EntityContainer container = null;
+ if (!entityContainerInfos.containsKey(entityContainer)) {
+ container = (EntityContainer) getEntityContainerInfo(entityContainer);
+ } else {
+ container = (EntityContainer) entityContainerInfos.get(entityContainer);
+ }
+
+ if (container != null && name != null) {
+ for (EntitySet es : container.getEntitySets()) {
+ if (name.equals(es.getName())) {
+ returnedSet = es;
+ break;
+ }
+ }
+ }
+
+ return returnedSet;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
+ final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
+
+ EntityContainer container = null;
+ if (!entityContainerInfos.containsKey(entityContainer)) {
+ container = (EntityContainer) getEntityContainerInfo(entityContainer);
+ } else {
+ container = (EntityContainer) entityContainerInfos.get(entityContainer);
+ }
+
+ if (container != null && association != null && container.getAssociationSets() != null) {
+ for (AssociationSet as : container.getAssociationSets()) {
+ if (association.equals(as.getAssociation())) {
+ AssociationSetEnd end = as.getEnd1();
+ if (sourceEntitySetName.equals(end.getEntitySet()) && sourceEntitySetRole.equals(end.getRole())) {
+ return as;
+ } else {
+ end = as.getEnd2();
+ if (sourceEntitySetName.equals(end.getEntitySet()) && sourceEntitySetRole.equals(end.getRole())) {
+ return as;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
+
+ if (functionImports.containsKey(name)) {
+ return functionImports.get(name);
+ }
+
+ EntityContainer container = null;
+ if (!entityContainerInfos.containsKey(entityContainer)) {
+ container = (EntityContainer) getEntityContainerInfo(entityContainer);
+ } else {
+ container = (EntityContainer) entityContainerInfos.get(entityContainer);
+ }
+
+ if (container != null && name != null) {
+ if (container.getFunctionImports() == null) {
+ return null;
+ }
+ for (FunctionImport fi : container.getFunctionImports()) {
+ if (name.equals(fi.getName())) {
+ functionImports.put(name, fi);
+ return fi;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ if (schemas == null && jpaEdmModel != null) {
+ jpaEdmModel.getBuilder().build();
+ schemas = new ArrayList<Schema>();
+ schemas.add(jpaEdmModel.getEdmSchemaView().getEdmSchema());
+ }
+ if (jpaEdmModel == null) {
+
+ throw ODataJPAModelException.throwException(ODataJPAModelException.BUILDER_NULL, null);
+ }
+
+ return schemas;
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/exception/ODataJPAMessageServiceDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/exception/ODataJPAMessageServiceDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/exception/ODataJPAMessageServiceDefault.java
new file mode 100644
index 0000000..cd96b40
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/exception/ODataJPAMessageServiceDefault.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.exception;
+
+import java.util.Arrays;
+import java.util.Formatter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingFormatArgumentException;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+
+public class ODataJPAMessageServiceDefault implements ODataJPAMessageService {
+
+ private static final String BUNDLE_NAME = "jpaprocessor_msg"; //$NON-NLS-1$
+ private static final Map<Locale, ODataJPAMessageService> LOCALE_2_MESSAGE_SERVICE =
+ new HashMap<Locale, ODataJPAMessageService>();
+ private static final ResourceBundle defaultResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
+ private final ResourceBundle resourceBundle;
+ private final Locale lanLocale;
+
+ @Override
+ public String getLocalizedMessage(final MessageReference context, final Throwable exception) {
+
+ Object[] contentAsArray = context.getContent().toArray(new Object[0]);
+
+ if (contentAsArray.length == 0 && exception != null) {
+ contentAsArray = new Object[2];
+ contentAsArray[0] = exception.getStackTrace()[1].getClassName();
+ contentAsArray[1] = exception.getMessage();
+ }
+ String value = null;
+ String key = context.getKey();
+
+ try {
+ value = getMessage(key);
+ StringBuilder builder = new StringBuilder();
+ Formatter f = null;
+ if (lanLocale == null) {
+ f = new Formatter();
+ } else {
+ f = new Formatter(builder, lanLocale);
+ }
+ f.format(value, contentAsArray);
+ f.close();
+ return builder.toString();
+
+ } catch (MissingResourceException e) {
+ return "Missing message for key '" + key + "'!";
+ } catch (MissingFormatArgumentException e) {
+ return "Missing replacement for place holder in value '" + value + "' for following arguments '"
+ + Arrays.toString(contentAsArray) + "'!";
+ }
+ }
+
+ private ODataJPAMessageServiceDefault(final ResourceBundle resourceBundle, final Locale locale) {
+ this.resourceBundle = resourceBundle;
+ lanLocale = locale;
+ }
+
+ public static ODataJPAMessageService getInstance(final Locale locale) {
+
+ Locale acceptedLocale = Locale.ENGLISH;
+ if ((ODataJPAContextImpl.getContextInThreadLocal() != null)
+ && (ODataJPAContextImpl.getContextInThreadLocal().getAcceptableLanguages() != null)) {
+
+ List<Locale> acceptedLanguages = ODataJPAContextImpl.getContextInThreadLocal().getAcceptableLanguages();
+
+ Iterator<Locale> itr = acceptedLanguages.iterator();
+
+ while (itr.hasNext()) {
+
+ Locale tempLocale = itr.next();
+ if (ResourceBundle.getBundle(BUNDLE_NAME, tempLocale).getLocale().equals(tempLocale)) {
+ acceptedLocale = tempLocale;
+ break;
+ }
+ }
+ }
+
+ ODataJPAMessageService messagesInstance = LOCALE_2_MESSAGE_SERVICE.get(acceptedLocale);
+ if (messagesInstance == null) {
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, acceptedLocale);
+
+ if (resourceBundle != null) {
+ messagesInstance = new ODataJPAMessageServiceDefault(resourceBundle, acceptedLocale);
+ LOCALE_2_MESSAGE_SERVICE.put(acceptedLocale, messagesInstance);
+ } else if (defaultResourceBundle != null) {
+ messagesInstance = new ODataJPAMessageServiceDefault(defaultResourceBundle, null);
+ }
+
+ }
+ return messagesInstance;
+ }
+
+ private String getMessage(final String key) {
+ return resourceBundle.getString(key);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
new file mode 100644
index 0000000..d27713f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.factory;
+
+import java.util.Locale;
+
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext.JPAMethodContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService;
+import org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory;
+import org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAProcessorDefault;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAFunctionContext;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmMappingModelService;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.exception.ODataJPAMessageServiceDefault;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectSingleContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectSingleStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmModel;
+
+public class ODataJPAFactoryImpl extends ODataJPAFactory {
+
+ @Override
+ public JPQLBuilderFactory getJPQLBuilderFactory() {
+ return JPQLBuilderFactoryImpl.create();
+ };
+
+ @Override
+ public JPAAccessFactory getJPAAccessFactory() {
+ return JPAAccessFactoryImpl.create();
+ };
+
+ @Override
+ public ODataJPAAccessFactory getODataJPAAccessFactory() {
+ return ODataJPAAccessFactoryImpl.create();
+ };
+
+ private static class JPQLBuilderFactoryImpl implements JPQLBuilderFactory {
+
+ private static JPQLBuilderFactoryImpl factory = null;
+
+ private JPQLBuilderFactoryImpl() {}
+
+ @Override
+ public JPQLStatementBuilder getStatementBuilder(final JPQLContextView context) {
+ JPQLStatementBuilder builder = null;
+ switch (context.getType()) {
+ case SELECT:
+ case SELECT_COUNT: // for $count, Same as select
+ builder = new JPQLSelectStatementBuilder(context);
+ break;
+ case SELECT_SINGLE:
+ builder = new JPQLSelectSingleStatementBuilder(context);
+ break;
+ case JOIN:
+ case JOIN_COUNT: // for $count, Same as join
+ builder = new JPQLJoinStatementBuilder(context);
+ break;
+ case JOIN_SINGLE:
+ builder = new JPQLJoinSelectSingleStatementBuilder(context);
+ default:
+ break;
+ }
+
+ return builder;
+ }
+
+ @Override
+ public JPQLContextBuilder getContextBuilder(final JPQLContextType contextType) {
+ JPQLContextBuilder contextBuilder = null;
+
+ switch (contextType) {
+ case SELECT:
+ JPQLSelectContext selectContext = new JPQLSelectContext(false);
+ contextBuilder = selectContext.new JPQLSelectContextBuilder();
+ break;
+ case SELECT_SINGLE:
+ JPQLSelectSingleContext singleSelectContext = new JPQLSelectSingleContext();
+ contextBuilder = singleSelectContext.new JPQLSelectSingleContextBuilder();
+ break;
+ case JOIN:
+ JPQLJoinSelectContext joinContext = new JPQLJoinSelectContext(false);
+ contextBuilder = joinContext.new JPQLJoinContextBuilder();
+ break;
+ case JOIN_SINGLE:
+ JPQLJoinSelectSingleContext joinSingleContext = new JPQLJoinSelectSingleContext();
+ contextBuilder = joinSingleContext.new JPQLJoinSelectSingleContextBuilder();
+ break;
+ case SELECT_COUNT:
+ JPQLSelectContext selectCountContext = new JPQLSelectContext(true);
+ contextBuilder = selectCountContext.new JPQLSelectContextBuilder();
+ break;
+ case JOIN_COUNT:
+ JPQLJoinSelectContext joinCountContext = new JPQLJoinSelectContext(true);
+ contextBuilder = joinCountContext.new JPQLJoinContextBuilder();
+ default:
+ break;
+ }
+
+ return contextBuilder;
+ }
+
+ private static JPQLBuilderFactory create() {
+ if (factory == null) {
+ return new JPQLBuilderFactoryImpl();
+ } else {
+ return factory;
+ }
+ }
+
+ @Override
+ public JPAMethodContextBuilder getJPAMethodContextBuilder(final JPQLContextType contextType) {
+
+ JPAMethodContextBuilder contextBuilder = null;
+ switch (contextType) {
+ case FUNCTION:
+ JPAFunctionContext methodConext = new JPAFunctionContext();
+ contextBuilder = methodConext.new JPAFunctionContextBuilder();
+
+ break;
+ default:
+ break;
+ }
+ return contextBuilder;
+ }
+
+ }
+
+ private static class ODataJPAAccessFactoryImpl implements ODataJPAAccessFactory {
+
+ private static ODataJPAAccessFactoryImpl factory = null;
+
+ private ODataJPAAccessFactoryImpl() {}
+
+ @Override
+ public ODataSingleProcessor createODataProcessor(final ODataJPAContext oDataJPAContext) {
+ return new ODataJPAProcessorDefault(oDataJPAContext);
+ }
+
+ @Override
+ public EdmProvider createJPAEdmProvider(final ODataJPAContext oDataJPAContext) {
+ return new ODataJPAEdmProvider(oDataJPAContext);
+ }
+
+ @Override
+ public ODataJPAContext createODataJPAContext() {
+ return new ODataJPAContextImpl();
+ }
+
+ private static ODataJPAAccessFactoryImpl create() {
+ if (factory == null) {
+ return new ODataJPAAccessFactoryImpl();
+ } else {
+ return factory;
+ }
+ }
+
+ @Override
+ public ODataJPAMessageService getODataJPAMessageService(final Locale locale) {
+ return ODataJPAMessageServiceDefault.getInstance(locale);
+ }
+
+ }
+
+ private static class JPAAccessFactoryImpl implements JPAAccessFactory {
+
+ private static JPAAccessFactoryImpl factory = null;
+
+ private JPAAccessFactoryImpl() {}
+
+ @Override
+ public JPAEdmModelView getJPAEdmModelView(final ODataJPAContext oDataJPAContext) {
+ JPAEdmModelView view = null;
+
+ view = new JPAEdmModel(oDataJPAContext);
+ return view;
+ }
+
+ @Override
+ public JPAProcessor getJPAProcessor(final ODataJPAContext oDataJPAContext) {
+ JPAProcessor jpaProcessor = new JPAProcessorImpl(oDataJPAContext);
+
+ return jpaProcessor;
+ }
+
+ private static JPAAccessFactoryImpl create() {
+ if (factory == null) {
+ return new JPAAccessFactoryImpl();
+ } else {
+ return factory;
+ }
+ }
+
+ @Override
+ public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(final ODataJPAContext oDataJPAContext) {
+ JPAEdmMappingModelAccess mappingModelAccess = new JPAEdmMappingModelService(oDataJPAContext);
+
+ return mappingModelAccess;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectContext.java
new file mode 100644
index 0000000..e69a2d6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectContext.java
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLJoinContextView;
+import org.apache.olingo.odata2.jpa.processor.core.ODataExpressionParser;
+
+public class JPQLJoinSelectContext extends JPQLSelectContext implements JPQLJoinContextView {
+
+ private List<JPAJoinClause> jpaJoinClauses = null;
+
+ protected void setJPAOuterJoinClause(final List<JPAJoinClause> jpaOuterJoinClauses) {
+ jpaJoinClauses = jpaOuterJoinClauses;
+ }
+
+ public JPQLJoinSelectContext(final boolean isCountOnly) {
+ super(isCountOnly);
+ }
+
+ public class JPQLJoinContextBuilder extends JPQLSelectContextBuilder {
+
+ protected int relationShipAliasCounter = 0;
+
+ @Override
+ public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
+ try {
+
+ if (JPQLJoinSelectContext.this.isCountOnly) {
+ setType(JPQLContextType.JOIN_COUNT);
+ } else {
+ setType(JPQLContextType.JOIN);
+ }
+
+ setJPAOuterJoinClause(generateJoinClauses());
+
+ if (!jpaJoinClauses.isEmpty()) {
+ JPAJoinClause joinClause = jpaJoinClauses.get(jpaJoinClauses.size() - 1);
+ setJPAEntityName(joinClause.getEntityName());
+ setJPAEntityAlias(joinClause.getEntityRelationShipAlias());
+ }
+
+ setOrderByCollection(generateOrderByFileds());
+
+ setSelectExpression(generateSelectExpression());
+
+ setWhereExpression(generateWhereExpression());
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return JPQLJoinSelectContext.this;
+ }
+
+ protected List<JPAJoinClause> generateJoinClauses() throws ODataJPARuntimeException, EdmException {
+
+ List<JPAJoinClause> jpaOuterJoinClauses = new ArrayList<JPAJoinClause>();
+ JPAJoinClause jpaOuterJoinClause = null;
+ String joinCondition = null;
+ String entityAlias = generateJPAEntityAlias();
+ joinCondition = ODataExpressionParser.parseKeyPredicates(entitySetView.getKeyPredicates(), entityAlias);
+
+ EdmEntityType entityType = entitySetView.getStartEntitySet().getEntityType();
+ Mapping mapping = (Mapping) entityType.getMapping();
+ String entityTypeName = null;
+ if (mapping != null) {
+ entityTypeName = mapping.getInternalName();
+ } else {
+ entityTypeName = entityType.getName();
+ }
+
+ jpaOuterJoinClause =
+ new JPAJoinClause(entityTypeName, entityAlias, null, null, joinCondition, JPAJoinClause.JOIN.INNER);
+
+ jpaOuterJoinClauses.add(jpaOuterJoinClause);
+
+ for (NavigationSegment navigationSegment : entitySetView.getNavigationSegments()) {
+
+ EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty();
+
+ String relationShipAlias = generateRelationShipAlias();
+
+ joinCondition =
+ ODataExpressionParser.parseKeyPredicates(navigationSegment.getKeyPredicates(), relationShipAlias);
+
+ jpaOuterJoinClause =
+ new JPAJoinClause(getFromEntityName(navigationProperty), entityAlias,
+ getRelationShipName(navigationProperty), relationShipAlias, joinCondition, JPAJoinClause.JOIN.INNER);
+
+ jpaOuterJoinClauses.add(jpaOuterJoinClause);
+
+ }
+
+ return jpaOuterJoinClauses;
+ }
+
+ private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException {
+
+ String fromRole = navigationProperty.getFromRole();
+
+ EdmEntityType toEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType();
+
+ EdmMapping mapping = toEntityType.getMapping();
+
+ String entityName = null;
+ if (mapping != null) {
+ entityName = mapping.getInternalName();
+ } else {
+ entityName = toEntityType.getName();
+ }
+
+ return entityName;
+
+ }
+
+ private String getRelationShipName(final EdmNavigationProperty navigationProperty) throws EdmException {
+
+ EdmMapping mapping = navigationProperty.getMapping();
+
+ String relationShipName = null;
+ if (mapping != null) {
+ relationShipName = mapping.getInternalName();
+ } else {
+ relationShipName = navigationProperty.getName();
+ }
+
+ return relationShipName;
+ }
+
+ private String generateRelationShipAlias() {
+ return new String("R" + ++relationShipAliasCounter);
+ }
+ }
+
+ @Override
+ public List<JPAJoinClause> getJPAJoinClauses() {
+ return jpaJoinClauses;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContext.java
new file mode 100644
index 0000000..199f05a
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContext.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLJoinSelectSingleContextView;
+import org.apache.olingo.odata2.jpa.processor.core.ODataExpressionParser;
+
+public class JPQLJoinSelectSingleContext extends JPQLSelectSingleContext implements JPQLJoinSelectSingleContextView {
+
+ private List<JPAJoinClause> jpaJoinClauses = null;
+
+ protected void setJPAJoinClause(final List<JPAJoinClause> jpaJoinClauses) {
+ this.jpaJoinClauses = jpaJoinClauses;
+ }
+
+ public class JPQLJoinSelectSingleContextBuilder extends JPQLSelectSingleContextBuilder {
+
+ protected int relationShipAliasCounter = 0;
+
+ @Override
+ public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
+ try {
+ setType(JPQLContextType.JOIN_SINGLE);
+ setJPAJoinClause(generateJoinClauses());
+
+ if (!jpaJoinClauses.isEmpty()) {
+ JPAJoinClause joinClause = jpaJoinClauses.get(jpaJoinClauses.size() - 1);
+ setJPAEntityName(joinClause.getEntityName());
+ setJPAEntityAlias(joinClause.getEntityRelationShipAlias());
+ }
+
+ setKeyPredicates(entityView.getKeyPredicates());
+
+ setSelectExpression(generateSelectExpression());
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL, e);
+ }
+
+ return JPQLJoinSelectSingleContext.this;
+ }
+
+ protected List<JPAJoinClause> generateJoinClauses() throws ODataJPARuntimeException, EdmException {
+
+ List<JPAJoinClause> jpaOuterJoinClauses = new ArrayList<JPAJoinClause>();
+ JPAJoinClause jpaOuterJoinClause = null;
+ String joinCondition = null;
+ String entityAlias = generateJPAEntityAlias();
+ joinCondition = ODataExpressionParser.parseKeyPredicates(entityView.getKeyPredicates(), entityAlias);
+
+ EdmEntityType entityType = entityView.getStartEntitySet().getEntityType();
+ Mapping mapping = (Mapping) entityType.getMapping();
+ String entityTypeName = null;
+ if (mapping != null) {
+ entityTypeName = mapping.getInternalName();
+ } else {
+ entityTypeName = entityType.getName();
+ }
+
+ jpaOuterJoinClause =
+ new JPAJoinClause(entityTypeName, entityAlias, null, null, joinCondition, JPAJoinClause.JOIN.INNER);
+
+ jpaOuterJoinClauses.add(jpaOuterJoinClause);
+
+ for (NavigationSegment navigationSegment : entityView.getNavigationSegments()) {
+
+ EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty();
+
+ String relationShipAlias = generateRelationShipAlias();
+
+ joinCondition =
+ ODataExpressionParser.parseKeyPredicates(navigationSegment.getKeyPredicates(), relationShipAlias);
+
+ jpaOuterJoinClause =
+ new JPAJoinClause(getFromEntityName(navigationProperty), entityAlias,
+ getRelationShipName(navigationProperty), relationShipAlias, joinCondition, JPAJoinClause.JOIN.INNER);
+
+ jpaOuterJoinClauses.add(jpaOuterJoinClause);
+
+ }
+
+ return jpaOuterJoinClauses;
+ }
+
+ private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException {
+
+ String fromRole = navigationProperty.getFromRole();
+
+ EdmEntityType fromEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType();
+
+ EdmMapping mapping = fromEntityType.getMapping();
+
+ String entityName = null;
+ if (mapping != null) {
+ entityName = mapping.getInternalName();
+ } else {
+ entityName = fromEntityType.getName();
+ }
+
+ return entityName;
+
+ }
+
+ private String getRelationShipName(final EdmNavigationProperty navigationProperty) throws EdmException {
+
+ EdmMapping mapping = navigationProperty.getMapping();
+
+ String relationShipName = null;
+ if (mapping != null) {
+ relationShipName = mapping.getInternalName();
+ } else {
+ relationShipName = navigationProperty.getName();
+ }
+
+ return relationShipName;
+ }
+
+ private String generateRelationShipAlias() {
+ return new String("R" + ++relationShipAliasCounter);
+ }
+ }
+
+ @Override
+ public List<JPAJoinClause> getJPAJoinClauses() {
+ return jpaJoinClauses;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilder.java
new file mode 100644
index 0000000..0a9a5b9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilder.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLJoinSelectSingleContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+
+public class JPQLJoinSelectSingleStatementBuilder extends JPQLStatementBuilder {
+
+ JPQLStatement jpqlStatement;
+ private JPQLJoinSelectSingleContextView context;
+
+ public JPQLJoinSelectSingleStatementBuilder(final JPQLContextView context) {
+ this.context = (JPQLJoinSelectSingleContextView) context;
+ }
+
+ @Override
+ public JPQLStatement build() throws ODataJPARuntimeException {
+ jpqlStatement = createStatement(createJPQLQuery());
+ return jpqlStatement;
+
+ }
+
+ private String createJPQLQuery() throws ODataJPARuntimeException {
+
+ StringBuilder jpqlQuery = new StringBuilder();
+ StringBuilder joinWhereCondition = null;
+
+ jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
+
+ if (context.getJPAJoinClauses() != null && context.getJPAJoinClauses().size() > 0) {
+ List<JPAJoinClause> joinClauseList = context.getJPAJoinClauses();
+ JPAJoinClause joinClause = joinClauseList.get(0);
+ String joinCondition = joinClause.getJoinCondition();
+ joinWhereCondition = new StringBuilder();
+ if (joinCondition != null) {
+ joinWhereCondition.append(joinCondition);
+ }
+ String relationShipAlias = null;
+ joinClause = joinClauseList.get(1);
+ jpqlQuery.append(joinClause.getEntityName()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(joinClause.getEntityAlias());
+
+ int i = 1;
+ int limit = joinClauseList.size();
+ relationShipAlias = joinClause.getEntityAlias();
+ while (i < limit) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.JOIN).append(JPQLStatement.DELIMITER.SPACE);
+
+ joinClause = joinClauseList.get(i);
+ jpqlQuery.append(relationShipAlias).append(JPQLStatement.DELIMITER.PERIOD);
+ jpqlQuery.append(joinClause.getEntityRelationShip()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(joinClause.getEntityRelationShipAlias());
+
+ relationShipAlias = joinClause.getEntityRelationShipAlias();
+ i++;
+
+ joinCondition = joinClause.getJoinCondition();
+ if (joinCondition != null) {
+ joinWhereCondition.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND
+ + JPQLStatement.DELIMITER.SPACE);
+
+ joinWhereCondition.append(joinCondition);
+ }
+
+ }
+ } else {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED, null);
+ }
+
+ if (joinWhereCondition.length() > 0) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(joinWhereCondition.toString());
+ }
+
+ return jpqlQuery.toString();
+
+ }
+
+}
[06/47] git commit: [OLINGO-87] Create base test classes and service
document test
Posted by tb...@apache.org.
[OLINGO-87] Create base test classes and service document test
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/78da059d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/78da059d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/78da059d
Branch: refs/heads/ODataServlet
Commit: 78da059d588a2d7fdae9b280ed5a6a7f1f324b0a
Parents: d9a7f2d
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Dec 23 11:01:58 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Dec 23 13:28:15 2013 +0100
----------------------------------------------------------------------
.../annotation-processor-webref/pom.xml | 6 +
.../processor/ref/AbstractRefTest.java | 195 +++++++++++++++++++
.../processor/ref/AbstractRefXmlTest.java | 89 +++++++++
.../processor/ref/ServiceJsonTest.java | 71 +++++++
.../processor/ref/ServiceXmlTest.java | 123 ++++++++++++
5 files changed, 484 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/pom.xml b/odata2-annotation-processor/annotation-processor-webref/pom.xml
index 9f31106..a6cc569 100644
--- a/odata2-annotation-processor/annotation-processor-webref/pom.xml
+++ b/odata2-annotation-processor/annotation-processor-webref/pom.xml
@@ -98,6 +98,12 @@ the License. -->
<artifactId>slf4j-log4j12</artifactId>
<version>${version.slf4j}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-testutil-incubating</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java
new file mode 100644
index 0000000..6ddbff4
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPatch;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.StringEntity;
+import org.apache.olingo.odata2.annotation.processor.api.AnnotationServiceFactory;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.testutil.fit.AbstractFitTest;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
+
+/**
+ * Abstract base class for tests employing the reference scenario.
+ *
+ */
+public class AbstractRefTest extends AbstractFitTest {
+
+ protected static final String IMAGE_JPEG = "image/jpeg";
+ protected static final String IMAGE_GIF = "image/gif";
+
+ final static String MODEL_PACKAGE = "org.apache.olingo.odata2.annotation.processor.ref.model";
+
+ @Override
+ protected ODataService createService() throws ODataException {
+ return AnnotationServiceFactory.createAnnotationService(MODEL_PACKAGE);
+ }
+
+ protected HttpResponse callUri(
+ final ODataHttpMethod httpMethod, final String uri,
+ final String additionalHeader, final String additionalHeaderValue,
+ final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+
+ HttpRequestBase request =
+ httpMethod == ODataHttpMethod.GET ? new HttpGet() :
+ httpMethod == ODataHttpMethod.DELETE ? new HttpDelete() :
+ httpMethod == ODataHttpMethod.POST ? new HttpPost() :
+ httpMethod == ODataHttpMethod.PUT ? new HttpPut() : new HttpPatch();
+ request.setURI(URI.create(getEndpoint() + uri));
+ if (additionalHeader != null) {
+ request.addHeader(additionalHeader, additionalHeaderValue);
+ }
+ if (requestBody != null) {
+ ((HttpEntityEnclosingRequest) request).setEntity(new StringEntity(requestBody));
+ request.setHeader(HttpHeaders.CONTENT_TYPE, requestContentType);
+ }
+
+ final HttpResponse response = getHttpClient().execute(request);
+
+ assertNotNull(response);
+ assertEquals(expectedStatusCode.getStatusCode(), response.getStatusLine().getStatusCode());
+
+ if (expectedStatusCode == HttpStatusCodes.OK) {
+ assertNotNull(response.getEntity());
+ assertNotNull(response.getEntity().getContent());
+ } else if (expectedStatusCode == HttpStatusCodes.CREATED) {
+ assertNotNull(response.getEntity());
+ assertNotNull(response.getEntity().getContent());
+ assertNotNull(response.getFirstHeader(HttpHeaders.LOCATION));
+ } else if (expectedStatusCode == HttpStatusCodes.NO_CONTENT) {
+ assertTrue(response.getEntity() == null || response.getEntity().getContent() == null);
+ }
+
+ return response;
+ }
+
+ protected HttpResponse callUri(final String uri, final String additionalHeader, final String additionalHeaderValue,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ return callUri(ODataHttpMethod.GET, uri, additionalHeader, additionalHeaderValue, null, null, expectedStatusCode);
+ }
+
+ protected HttpResponse callUri(final String uri, final String additionalHeader, final String additionalHeaderValue)
+ throws Exception {
+ return callUri(ODataHttpMethod.GET, uri, additionalHeader, additionalHeaderValue, null, null, HttpStatusCodes.OK);
+ }
+
+ protected HttpResponse callUri(final String uri, final HttpStatusCodes expectedStatusCode) throws Exception {
+ return callUri(uri, null, null, expectedStatusCode);
+ }
+
+ protected HttpResponse callUri(final String uri) throws Exception {
+ return callUri(uri, HttpStatusCodes.OK);
+ }
+
+ protected void checkUri(final String uri) throws Exception {
+ assertNotNull(getBody(callUri(uri)));
+ }
+
+ protected void badRequest(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.BAD_REQUEST);
+ assertNotNull(getBody(response));
+ }
+
+ protected void notFound(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.NOT_FOUND);
+ assertNotNull(getBody(response));
+ }
+
+ protected void deleteUri(final String uri, final HttpStatusCodes expectedStatusCode)
+ throws Exception, AssertionError {
+ final HttpResponse response = callUri(ODataHttpMethod.DELETE, uri, null, null, null, null, expectedStatusCode);
+ if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
+ response.getEntity().getContent().close();
+ }
+ }
+
+ protected void deleteUriOk(final String uri) throws Exception {
+ deleteUri(uri, HttpStatusCodes.NO_CONTENT);
+ }
+
+ protected HttpResponse postUri(final String uri, final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ return callUri(ODataHttpMethod.POST, uri, null, null, requestBody, requestContentType, expectedStatusCode);
+ }
+
+ protected HttpResponse postUri(final String uri, final String requestBody, final String requestContentType,
+ final String additionalHeader, final String additionalHeaderValue, final HttpStatusCodes expectedStatusCode)
+ throws Exception {
+ return callUri(ODataHttpMethod.POST, uri, additionalHeader, additionalHeaderValue, requestBody, requestContentType,
+ expectedStatusCode);
+ }
+
+ protected void putUri(final String uri,
+ final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ final HttpResponse response =
+ callUri(ODataHttpMethod.PUT, uri, null, null, requestBody, requestContentType, expectedStatusCode);
+ if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
+ response.getEntity().getContent().close();
+ }
+ }
+
+ protected void putUri(final String uri, final String acceptHeader,
+ final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ final HttpResponse response =
+ callUri(ODataHttpMethod.PUT, uri,
+ org.apache.olingo.odata2.api.commons.HttpHeaders.ACCEPT, acceptHeader, requestBody, requestContentType,
+ expectedStatusCode);
+ if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
+ response.getEntity().getContent().close();
+ }
+ }
+
+ protected String getBody(final HttpResponse response) throws Exception {
+ assertNotNull(response);
+ assertNotNull(response.getEntity());
+ assertNotNull(response.getEntity().getContent());
+ return StringHelper.inputStreamToString(response.getEntity().getContent());
+ }
+
+ protected void checkMediaType(final HttpResponse response, final String expectedMediaType) {
+ assertEquals(expectedMediaType, response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+ }
+
+ protected void checkEtag(final HttpResponse response, final String expectedEtag) {
+ assertNotNull(response.getFirstHeader(HttpHeaders.ETAG));
+ final String entityTag = response.getFirstHeader(HttpHeaders.ETAG).getValue();
+ assertNotNull(entityTag);
+ assertEquals(expectedEtag, entityTag);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java
new file mode 100644
index 0000000..aefd16b
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.HttpResponse;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.custommonkey.xmlunit.exceptions.XpathException;
+import org.junit.Before;
+import org.xml.sax.SAXException;
+
+/**
+ * Abstract base class for tests employing the reference scenario reading or writing XML.
+ *
+ */
+public class AbstractRefXmlTest extends AbstractRefTest {
+ @Before
+ public void setXmlNamespacePrefixes() {
+ Map<String, String> prefixMap = new HashMap<String, String>();
+ prefixMap.put(Edm.PREFIX_ATOM, Edm.NAMESPACE_ATOM_2005);
+ prefixMap.put(Edm.PREFIX_APP, Edm.NAMESPACE_APP_2007);
+ prefixMap.put(Edm.PREFIX_D, Edm.NAMESPACE_D_2007_08);
+ prefixMap.put(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
+ prefixMap.put(Edm.PREFIX_EDM, Edm.NAMESPACE_EDM_2008_09);
+ prefixMap.put(Edm.PREFIX_EDMX, Edm.NAMESPACE_EDMX_2007_06);
+ prefixMap.put(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998);
+ XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
+ }
+
+ @Override
+ protected void badRequest(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.BAD_REQUEST);
+ validateXmlError(getBody(response));
+ }
+
+ @Override
+ protected void notFound(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.NOT_FOUND);
+ validateXmlError(getBody(response));
+ }
+
+ protected void validateXmlError(final String xml) throws XpathException, IOException, SAXException {
+ assertXpathExists("/m:error", xml);
+ assertXpathExists("/m:error/m:code", xml);
+ assertXpathExists("/m:error/m:message[@xml:lang=\"en\"]", xml);
+ }
+
+ protected String readFile(final String filename) throws IOException {
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
+ if (in == null) {
+ throw new IOException("Requested file '" + filename + "' was not found.");
+ }
+
+ byte[] tmp = new byte[8192];
+ int count = in.read(tmp);
+ StringBuffer b = new StringBuffer();
+ while (count >= 0) {
+ b.append(new String(tmp, 0, count));
+ count = in.read(tmp);
+ }
+
+ return b.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
new file mode 100644
index 0000000..9c0a049
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.HttpResponse;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+/**
+ * Tests employing the reference scenario reading the service document in JSON format.
+ *
+ */
+public class ServiceJsonTest extends AbstractRefTest {
+ @Test
+ public void serviceDocumentDollarFormatJson() throws Exception {
+ final HttpResponse response = callUri("?$format=json");
+ // checkMediaType(response, HttpContentType.APPLICATION_JSON);
+ assertEquals("{\"d\":{\"EntitySets\":["
+ + "\"Buildings\",\"Employees\",\"Managers\",\"Photos\",\"Rooms\",\"Teams\"]}}",
+ getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderJson() throws Exception {
+ final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
+ assertEquals("{\"d\":{\"EntitySets\":["
+ + "\"Buildings\",\"Employees\",\"Managers\",\"Photos\",\"Rooms\",\"Teams\"]}}",
+ getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderInvalidCharset() throws Exception {
+ final HttpResponse response =
+ callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML + "; charset=iso-latin-1",
+ HttpStatusCodes.NOT_ACCEPTABLE);
+ final String body = getBody(response);
+ Map<String, String> prefixMap = new HashMap<String, String>();
+ prefixMap.put("a", Edm.NAMESPACE_M_2007_08);
+ XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
+ assertXpathExists("/a:error", body);
+ assertXpathExists("/a:error/a:code", body);
+ assertXpathExists("/a:error/a:message", body);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java
new file mode 100644
index 0000000..4d49883
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.custommonkey.xmlunit.exceptions.XpathException;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Tests employing the reference scenario reading the service document in XML format
+ */
+public class ServiceXmlTest extends AbstractRefXmlTest {
+
+ @Test
+ public void serviceDocument() throws Exception {
+ final HttpResponse response = callUri("/");
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_SVC_UTF8);
+ final String body = getBody(response);
+
+ assertXpathEvaluatesTo("Employees", "/app:service/app:workspace/app:collection[@href=\"Employees\"]", body);
+ assertXpathEvaluatesTo("Teams", "/app:service/app:workspace/app:collection[@href=\"Teams\"]", body);
+ assertXpathEvaluatesTo("Rooms", "/app:service/app:workspace/app:collection[@href=\"Rooms\"]", body);
+ assertXpathEvaluatesTo("Managers", "/app:service/app:workspace/app:collection[@href=\"Managers\"]", body);
+ assertXpathEvaluatesTo("Buildings", "/app:service/app:workspace/app:collection[@href=\"Buildings\"]", body);
+ assertXpathEvaluatesTo("Photos", "/app:service/app:workspace/app:collection[@href=\"Photos\"]", body);
+
+ notFound("invalid.svc");
+ }
+
+ @Test
+ public void serviceDocumentDefault() throws Exception {
+ final HttpResponse response = callUri("");
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_SVC_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentDollarFormatAtom() throws Exception {
+ HttpResponse response = callUri("?$format=atom");
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_SVC_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentDollarFormatXml() throws Exception {
+ HttpResponse response = callUri("?$format=xml");
+ checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderAtom() throws Exception {
+ final HttpResponse response =
+ callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_ATOM_XML, HttpStatusCodes.NOT_ACCEPTABLE);
+ checkMediaType(response, HttpContentType.APPLICATION_XML);
+ validateXmlError(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderUtf8Atom() throws Exception {
+ final HttpResponse response =
+ callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_ATOM_XML_UTF8, HttpStatusCodes.NOT_ACCEPTABLE);
+ checkMediaType(response, HttpContentType.APPLICATION_XML);
+ validateXmlError(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderXml() throws Exception {
+ HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
+ checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderUtf8Xml() throws Exception {
+ HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML_UTF8);
+ checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ private void validateXmlServiceDocument(final String payload) throws IOException, SAXException, XpathException {
+ assertXpathExists("/app:service", payload);
+ assertXpathExists("/app:service/app:workspace", payload);
+ assertXpathExists("/app:service/app:workspace/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Employees\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Employees\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Teams\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Teams\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Rooms\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Rooms\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Managers\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Managers\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Buildings\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Buildings\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Photos\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Photos\"]/atom:title", payload);
+ }
+}
[09/47] git commit: [OLINGO-87] Fixed problem with json service
document test
Posted by tb...@apache.org.
[OLINGO-87] Fixed problem with json service document test
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/eeee989a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/eeee989a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/eeee989a
Branch: refs/heads/ODataServlet
Commit: eeee989acf746d7c7cde8039e05b1abb457edfb2
Parents: 9a05b37
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Dec 23 13:51:08 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Dec 23 13:51:20 2013 +0100
----------------------------------------------------------------------
.../processor/ref/ServiceJsonTest.java | 30 +++++++++++++++-----
1 file changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/eeee989a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
index 9c0a049..4813690 100644
--- a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
@@ -19,11 +19,12 @@
package org.apache.olingo.odata2.annotation.processor.ref;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
+import junit.framework.Assert;
+
import org.apache.http.HttpResponse;
import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpHeaders;
@@ -42,17 +43,32 @@ public class ServiceJsonTest extends AbstractRefTest {
public void serviceDocumentDollarFormatJson() throws Exception {
final HttpResponse response = callUri("?$format=json");
// checkMediaType(response, HttpContentType.APPLICATION_JSON);
- assertEquals("{\"d\":{\"EntitySets\":["
- + "\"Buildings\",\"Employees\",\"Managers\",\"Photos\",\"Rooms\",\"Teams\"]}}",
- getBody(response));
+ String body = getBody(response);
+
+ Assert.assertTrue(jsonDataResponseContains(body, "Buildings"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Employees"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Managers"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Photos"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Rooms"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Teams"));
}
+ private boolean jsonDataResponseContains(String content, String containingValue) {
+ return content.matches("\\{\"d\":\\{\"EntitySets\":\\[.*"
+ + containingValue + ".*\"\\]\\}\\}");
+ }
+
@Test
public void serviceDocumentAcceptHeaderJson() throws Exception {
final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
- assertEquals("{\"d\":{\"EntitySets\":["
- + "\"Buildings\",\"Employees\",\"Managers\",\"Photos\",\"Rooms\",\"Teams\"]}}",
- getBody(response));
+ String body = getBody(response);
+
+ Assert.assertTrue(jsonDataResponseContains(body, "Buildings"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Employees"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Managers"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Photos"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Rooms"));
+ Assert.assertTrue(jsonDataResponseContains(body, "Teams"));
}
@Test
[05/47] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2
Posted by tb...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/9a698438
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/9a698438
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/9a698438
Branch: refs/heads/ODataServlet
Commit: 9a698438af26891bb292ad9371979552f952bf2e
Parents: ecdc476 d9a7f2d
Author: Chandan V A <ch...@sap.com>
Authored: Mon Dec 23 17:56:52 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Mon Dec 23 17:56:52 2013 +0530
----------------------------------------------------------------------
.../processor/core/ListsProcessorTest.java | 40 +++
.../datasource/AnnotationValueAccessTest.java | 237 +++++++++++++++++
.../core/datasource/BeanPropertyAccessTest.java | 261 +++++++++++++++++++
3 files changed, 538 insertions(+)
----------------------------------------------------------------------
[40/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAException.java
new file mode 100644
index 0000000..5258edd
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAException.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.exception;
+
+import java.util.Locale;
+
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+/**
+ * The exception class is the base of OData JPA exceptions. The class also
+ * provides non localized error texts that can be used for raising OData JPA
+ * exceptions with non localized error texts.
+ *
+ *
+ *
+ */
+public abstract class ODataJPAException extends ODataException {
+
+ protected MessageReference messageReference;
+
+ public static final String ODATA_JPACTX_NULL = "OData JPA Context cannot be null";
+
+ private static final long serialVersionUID = -6884673558124441214L;
+ protected static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
+
+ protected ODataJPAException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
+ super(localizedMessage, e);
+ messageReference = msgRef;
+ }
+
+ /**
+ * The method creates a Reference to Message Object {@link org.apache.olingo.odata2.api.exception.MessageReference} .
+ * The message
+ * text key is derived out of parameters clazz.messageReferenceKey.
+ *
+ * @param clazz
+ * is name of the class extending {@link org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException}
+ * @param messageReferenceKey
+ * is the key of the message
+ * @return an instance of type {@link org.apache.olingo.odata2.api.exception.MessageReference}
+ */
+ protected static MessageReference createMessageReference(final Class<? extends ODataJPAException> clazz,
+ final String messageReferenceKey) {
+ return MessageReference.create(clazz, messageReferenceKey);
+ }
+
+ public MessageReference getMessageReference() {
+ return messageReference;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAMessageService.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAMessageService.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAMessageService.java
new file mode 100644
index 0000000..6a7b166
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAMessageService.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.exception;
+
+import org.apache.olingo.odata2.api.exception.MessageReference;
+
+/**
+ * The interface is used to access language dependent message texts. Default
+ * language is "English - EN". <br>
+ * The default implementation of the interface shipped with the library loads
+ * message texts from language dependent property files. If the message text is
+ * not found for the given language then the default language -EN is used for
+ * the message texts.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException
+ * @see org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException
+ * @see org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException
+ * @see org.apache.olingo.odata2.api.exception.MessageReference
+ */
+public interface ODataJPAMessageService {
+ /**
+ * The method returns a language dependent message texts for the given
+ * {@link org.apache.olingo.odata2.api.exception.MessageReference}.
+ *
+ * @param context
+ * is a Message Reference
+ * exception
+ * is a Throwable Exception
+ * @return a language dependent message text
+ */
+ public String getLocalizedMessage(MessageReference context, Throwable exception);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
new file mode 100644
index 0000000..9f18f37
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAModelException.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.exception;
+
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+
+/**
+ * The exception is thrown for any unexpected errors raising while
+ * accessing/transforming Java Persistence Models.
+ *
+ *
+ *
+ */
+public class ODataJPAModelException extends ODataJPAException {
+
+ public static final MessageReference INVALID_ENTITY_TYPE = createMessageReference(ODataJPAModelException.class,
+ "INVALID_ENTITY_TYPE");
+ public static final MessageReference INVALID_COMPLEX_TYPE = createMessageReference(ODataJPAModelException.class,
+ "INVLAID_COMPLEX_TYPE");
+ public static final MessageReference INVALID_ASSOCIATION = createMessageReference(ODataJPAModelException.class,
+ "INVALID_ASSOCIATION");
+ public static final MessageReference INVALID_ENTITYSET = createMessageReference(ODataJPAModelException.class,
+ "INVALID_ENTITYSET");
+ public static final MessageReference INVALID_ENTITYCONTAINER = createMessageReference(ODataJPAModelException.class,
+ "INVALID_ENTITYCONTAINER");
+ public static final MessageReference INVALID_ASSOCIATION_SET = createMessageReference(ODataJPAModelException.class,
+ "INVALID_ASSOCIATION_SET");
+ public static final MessageReference INVALID_FUNC_IMPORT = createMessageReference(ODataJPAModelException.class,
+ "INVALID_FUNC_IMPORT");
+
+ public static final MessageReference BUILDER_NULL = createMessageReference(ODataJPAModelException.class,
+ "BUILDER_NULL");
+ public static final MessageReference TYPE_NOT_SUPPORTED = createMessageReference(ODataJPAModelException.class,
+ "TYPE_NOT_SUPPORTED");
+ public static final MessageReference FUNC_ENTITYSET_EXP = createMessageReference(ODataJPAModelException.class,
+ "FUNC_ENTITYSET_EXP");
+ public static final MessageReference FUNC_RETURN_TYPE_EXP = createMessageReference(ODataJPAModelException.class,
+ "FUNC_RETURN_TYPE_EXP");
+ public static final MessageReference FUNC_RETURN_TYPE_ENTITY_NOT_FOUND = createMessageReference(
+ ODataJPAModelException.class, "FUNC_RETURN_TYPE_ENTITY_NOT_FOUND");
+ public static final MessageReference GENERAL = createMessageReference(ODataJPAModelException.class, "GENERAL");
+ public static final MessageReference INNER_EXCEPTION = createMessageReference(ODataJPAModelException.class,
+ "INNER_EXCEPTION");
+ public static final MessageReference FUNC_PARAM_NAME_EXP = createMessageReference(ODataJPAModelException.class,
+ "FUNC_PARAM_NAME_EXP");
+
+ private ODataJPAModelException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
+ super(localizedMessage, e, msgRef);
+ }
+
+ /**
+ * The method creates an exception object of type ODataJPAModelException
+ * with localized error texts.
+ *
+ * @param messageReference
+ * is a <b>mandatory</b> parameter referring to a literal that
+ * could be translated to localized error texts.
+ * @param e
+ * is an optional parameter representing the previous exception
+ * in the call stack
+ * @return an instance of ODataJPAModelException which can be then raised.
+ * @throws ODataJPARuntimeException
+ */
+ public static ODataJPAModelException throwException(final MessageReference messageReference, final Throwable e) {
+
+ ODataJPAMessageService messageService;
+ messageService =
+ ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAMessageService(DEFAULT_LOCALE);
+ String message = messageService.getLocalizedMessage(messageReference, e);
+ return new ODataJPAModelException(message, e, messageReference);
+ }
+
+ private static final long serialVersionUID = 7940106375606950703L;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPARuntimeException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPARuntimeException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPARuntimeException.java
new file mode 100644
index 0000000..46737bc
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPARuntimeException.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.exception;
+
+import org.apache.olingo.odata2.api.exception.MessageReference;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+
+/**
+ * The exception is thrown for any unexpected errors raising while accessing
+ * data from Java Persistence Models.
+ *
+ * The exception object is created with localized error texts provided error
+ * texts are maintained in localized languages.
+ *
+ *
+ *
+ */
+public class ODataJPARuntimeException extends ODataJPAException {
+
+ public static final MessageReference ENTITY_MANAGER_NOT_INITIALIZED = createMessageReference(
+ ODataJPARuntimeException.class, "ENTITY_MANAGER_NOT_INITIALIZED");
+ public static final MessageReference RESOURCE_NOT_FOUND = createMessageReference(ODataJPARuntimeException.class,
+ "RESOURCE_NOT_FOUND");
+ public static final MessageReference GENERAL = createMessageReference(ODataJPARuntimeException.class, "GENERAL");
+ public static final MessageReference INNER_EXCEPTION = createMessageReference(ODataJPARuntimeException.class,
+ "INNER_EXCEPTION");
+ public static final MessageReference JOIN_CLAUSE_EXPECTED = createMessageReference(ODataJPARuntimeException.class,
+ "JOIN_CLAUSE_EXPECTED");
+ public static final MessageReference ERROR_JPQLCTXBLDR_CREATE = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_JPQLCTXBLDR_CREATE");
+ public static final MessageReference ERROR_ODATA_FILTER_CONDITION = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_ODATA_FILTER_CONDITION");
+ public static final MessageReference ERROR_JPQL_QUERY_CREATE = createMessageReference(ODataJPARuntimeException.class,
+ "ERROR_JPQL_QUERY_CREATE");
+ public static final MessageReference ERROR_JPQL_CREATE_REQUEST = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_JPQL_CREATE_REQUEST");
+ public static final MessageReference ERROR_JPQL_UPDATE_REQUEST = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_JPQL_UPDATE_REQUEST");
+ public static final MessageReference ERROR_JPQL_DELETE_REQUEST = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_JPQL_DELETE_REQUEST");
+ public static final MessageReference ERROR_JPQL_KEY_VALUE = createMessageReference(ODataJPARuntimeException.class,
+ "ERROR_JPQL_KEY_VALUE");
+ public static final MessageReference ERROR_JPQL_PARAM_VALUE = createMessageReference(ODataJPARuntimeException.class,
+ "ERROR_JPQL_PARAM_VALUE");
+ public static final MessageReference ERROR_JPQL_UNIQUE_CONSTRAINT = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_JPQL_UNIQUE_CONSTRAINT");
+ public static final MessageReference ERROR_JPQL_INTEGRITY_CONSTRAINT = createMessageReference(
+ ODataJPARuntimeException.class, "ERROR_JPQL_INTEGRITY_CONSTRAINT");
+ public static final MessageReference RELATIONSHIP_INVALID = createMessageReference(ODataJPARuntimeException.class,
+ "RELATIONSHIP_INVALID");
+ public static final MessageReference RESOURCE_X_NOT_FOUND = createMessageReference(ODataJPARuntimeException.class,
+ "RESOURCE_X_NOT_FOUND");
+
+ private ODataJPARuntimeException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
+ super(localizedMessage, e, msgRef);
+ }
+
+ /**
+ * The method creates an exception object of type ODataJPARuntimeException
+ * with localized error texts.
+ *
+ * @param messageReference
+ * is a <b>mandatory</b> parameter referring to a literal that
+ * could be translated to localized error texts.
+ * @param e
+ * is an optional parameter representing the previous exception
+ * in the call stack
+ * @return an instance of ODataJPARuntimeException which can be then raised.
+ * @throws ODataJPARuntimeException
+ */
+ public static ODataJPARuntimeException throwException(final MessageReference messageReference, final Throwable e) {
+ ODataJPAMessageService messageService;
+ messageService =
+ ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAMessageService(DEFAULT_LOCALE);
+ String message = messageService.getLocalizedMessage(messageReference, e);
+ return new ODataJPARuntimeException(message, e, messageReference);
+ }
+
+ private static final long serialVersionUID = -5230976355642443012L;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/package-info.java
new file mode 100644
index 0000000..dad4d22
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/package-info.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library - Exceptions</h3>
+ * There are two main types of exceptions thrown from the library
+ * <ol><li>Model Exception</li>
+ * <li>Runtime Exception</li></ol>
+ * <br>
+ * The Model Exception is thrown while processing JPA metamodels and
+ * runtime exception is thrown while processing persistence data.
+ *
+ *
+ */
+package org.apache.olingo.odata2.jpa.processor.api.exception;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
new file mode 100644
index 0000000..20f965e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPAAccessFactory.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.factory;
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+
+/**
+ * Factory interface for creating
+ * <ol>
+ * <li>JPA EDM Model view</li>
+ * <li>JPA Processor</li>
+ * </ol>
+ *
+ *
+ *
+ */
+public interface JPAAccessFactory {
+ /**
+ * The method returns an instance of JPA EDM model view based on OData JPA
+ * Context. The JPA EDM model view thus returned can be used for building
+ * EDM models from Java persistence models.
+ *
+ * @param oDataJPAContext
+ * a non null instance of {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView}
+ */
+ public JPAEdmModelView getJPAEdmModelView(ODataJPAContext oDataJPAContext);
+
+ /**
+ * The method returns an instance of JPA processor based on OData JPA
+ * Context. The JPA Processor thus returned can be used for building and
+ * processing JPQL statements.
+ *
+ * @param oDataJPAContext
+ * a non null instance of {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor}
+ */
+ public JPAProcessor getJPAProcessor(ODataJPAContext oDataJPAContext);
+
+ /**
+ * The method returns an instance of JPA EDM mapping model access based on
+ * OData JPA context. The instance thus returned can be used for accessing
+ * the mapping details maintained for an OData service
+ *
+ * @param oDataJPAContext
+ * a non null instance of {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess}
+ */
+ public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(ODataJPAContext oDataJPAContext);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPQLBuilderFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPQLBuilderFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPQLBuilderFactory.java
new file mode 100644
index 0000000..4880257
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/JPQLBuilderFactory.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.factory;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext.JPAMethodContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+
+/**
+ * Factory interface for creating following instances
+ *
+ * <p>
+ * <ul>
+ * <li>JPQL statement builders of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder} </li>
+ * <li>JPQL context builder of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder} </li>
+ * </ul>
+ * </p>
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory
+ */
+public interface JPQLBuilderFactory {
+ /**
+ * The method returns JPQL statement builder for building JPQL statements.
+ *
+ * @param context
+ * is {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext} that determines the type of JPQL statement
+ * builder. The
+ * parameter cannot be null.
+ * @return an instance of JPQLStatementBuilder
+ */
+ public JPQLStatementBuilder getStatementBuilder(JPQLContextView context);
+
+ /**
+ * The method returns a JPQL context builder for building JPQL Context
+ * object.
+ *
+ * @param contextType
+ * is {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType} that determines the type of JPQL context
+ * builder. The
+ * parameter cannot be null.
+ * @return an instance of JPQLContextBuilder
+ */
+ public JPQLContextBuilder getContextBuilder(JPQLContextType contextType);
+
+ /**
+ * The method returns a JPA method context builder for building JPA Method
+ * context object.
+ *
+ * @param contextType
+ * is {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType} that determines the type of JPQL context
+ * builder. The
+ * parameter cannot be null.
+ * @return an instance of JPAMethodContextBuilder
+ */
+ public JPAMethodContextBuilder getJPAMethodContextBuilder(JPQLContextType contextType);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
new file mode 100644
index 0000000..50f84f6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.factory;
+
+import java.util.Locale;
+
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService;
+
+/**
+ * Factory interface for creating following instances
+ *
+ * <p>
+ * <ul>
+ * <li>OData JPA Processor of type {@link org.apache.olingo.odata2.api.processor.ODataSingleProcessor}</li>
+ * <li>JPA EDM Provider of type {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider}</li>
+ * <li>OData JPA Context {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}</li>
+ * </ul>
+ * </p>
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory
+ */
+public interface ODataJPAAccessFactory {
+ /**
+ * The method creates an OData JPA Processor. The processor handles runtime
+ * behavior of an OData service.
+ *
+ * @param oDataJPAContext
+ * an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}.
+ * The context should be initialized properly and cannot be null.
+ * @return An implementation of OData JPA Processor.
+ */
+ public ODataSingleProcessor createODataProcessor(ODataJPAContext oDataJPAContext);
+
+ /**
+ *
+ * @param oDataJPAContext
+ * an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}.
+ * The context should be initialized properly and cannot be null.
+ * @return An implementation of JPA EdmProvider. EdmProvider handles
+ * meta-data.
+ */
+ public EdmProvider createJPAEdmProvider(ODataJPAContext oDataJPAContext);
+
+ /**
+ * The method creates an instance of OData JPA Context. An empty instance is
+ * returned.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}
+ */
+ public ODataJPAContext createODataJPAContext();
+
+ /**
+ * The method creates an instance of message service for loading language
+ * dependent message text.
+ *
+ * @param locale
+ * is the language in which the message service should load
+ * message texts.
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService}
+ */
+ public ODataJPAMessageService getODataJPAMessageService(Locale locale);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAFactory.java
new file mode 100644
index 0000000..77da8c5
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAFactory.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.factory;
+
+/**
+ * The class is an abstract factory for creating default ODataJPAFactory. The
+ * class's actual implementation is responsible for creating other factory
+ * implementations.The class creates factories implementing interfaces
+ * <ul>
+ * <li>{@link org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory}</li>
+ * <li>{@link org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory}</li>
+ * <li>{@link org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory}</li>
+ * </ul>
+ *
+ * <b>Note: </b>Extend this class only if you don't require library's default
+ * factory implementation.
+ * <p>
+ *
+ *
+ *
+ *
+ *
+ */
+public abstract class ODataJPAFactory {
+
+ private static final String IMPLEMENTATION =
+ "org.apache.olingo.odata2.jpa.processor.core.factory.ODataJPAFactoryImpl";
+ private static ODataJPAFactory factoryImpl;
+
+ /**
+ * Method creates a factory instance. The instance returned is singleton.
+ * The instance of this factory can be used for creating other factory
+ * implementations.
+ *
+ * @return instance of type {@link org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory} .
+ */
+ public static ODataJPAFactory createFactory() {
+
+ if (factoryImpl != null) {
+ return factoryImpl;
+ } else {
+ try {
+ Class<?> clazz = Class.forName(ODataJPAFactory.IMPLEMENTATION);
+
+ Object object = clazz.newInstance();
+ factoryImpl = (ODataJPAFactory) object;
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return factoryImpl;
+ }
+ }
+
+ /**
+ * The method returns a null reference to JPQL Builder Factory. Override
+ * this method to return an implementation of JPQLBuilderFactory if default
+ * implementation from library is not required.
+ *
+ * @return instance of type {@link org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory}
+ */
+ public JPQLBuilderFactory getJPQLBuilderFactory() {
+ return null;
+ };
+
+ /**
+ * The method returns a null reference to JPA Access Factory. Override this
+ * method to return an implementation of JPAAccessFactory if default
+ * implementation from library is not required.
+ *
+ * @return instance of type {@link org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory}
+ */
+ public JPAAccessFactory getJPAAccessFactory() {
+ return null;
+ };
+
+ /**
+ * The method returns a null reference to OData JPA Access Factory. Override
+ * this method to return an implementation of ODataJPAAccessFactory if
+ * default implementation from library is not required.
+ *
+ * @return instance of type {@link org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory}
+ */
+ public ODataJPAAccessFactory getODataJPAAccessFactory() {
+ return null;
+ };
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/package-info.java
new file mode 100644
index 0000000..d8d3122
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/package-info.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library - Factory</h3>
+ * The library provides different types of factories for creating instances for
+ * <ul>
+ * <li>Accessing Java Persistence Model/Data</li>
+ * <li>Building different types of JPQL statements</li>
+ * <li>Accessing OData EDM provider and processor</li>
+ * </ul>
+ *
+ * The instances of these factories can be obtained from an abstract ODataJPAFactory.
+ *
+ *
+ */
+package org.apache.olingo.odata2.jpa.processor.api.factory;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContext.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContext.java
new file mode 100644
index 0000000..0226300
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContext.java
@@ -0,0 +1,204 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+
+/**
+ * The abstract class is a compilation of objects required for building
+ * {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement}. Extend this
+ * class to implement specific implementations of JPQL context types (Select,
+ * Join). A JPQL Context is constructed from an OData
+ * request. Depending on OData CRUD operation performed on an Entity, a
+ * corresponding JPQL context object is built. The JPQL context object thus
+ * built can be used for constructing JPQL statements. <br>
+ * A default implementation is provided by the library.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory
+ *
+ */
+public abstract class JPQLContext implements JPQLContextView {
+
+ /**
+ * An alias for Java Persistence Entity
+ */
+ protected String jpaEntityAlias;
+ /**
+ * Java Persistence Entity name
+ */
+ protected String jpaEntityName;
+ /**
+ * The type of JPQL context. Based on the type JPQL statements can be built.
+ */
+ protected JPQLContextType type;
+
+ /**
+ * sets JPA Entity Name into the context
+ *
+ * @param jpaEntityName
+ * is the name of JPA Entity
+ */
+ protected final void setJPAEntityName(final String jpaEntityName) {
+ this.jpaEntityName = jpaEntityName;
+ }
+
+ /**
+ * sets JPA Entity alias name into the context
+ *
+ * @param jpaEntityAlias
+ * is the JPA entity alias name
+ */
+ protected final void setJPAEntityAlias(final String jpaEntityAlias) {
+ this.jpaEntityAlias = jpaEntityAlias;
+ }
+
+ /**
+ * gets the JPA entity alias name set into the context
+ */
+ @Override
+ public final String getJPAEntityAlias() {
+ return jpaEntityAlias;
+ }
+
+ /**
+ * sets the JPQL context type into the context
+ *
+ * @param type
+ * is JPQLContextType
+ */
+ protected final void setType(final JPQLContextType type) {
+ this.type = type;
+ }
+
+ /**
+ * gets the JPA entity name set into the context
+ */
+ @Override
+ public final String getJPAEntityName() {
+ return jpaEntityName;
+ }
+
+ /**
+ * gets the JPQL context type set into the context
+ */
+ @Override
+ public final JPQLContextType getType() {
+ return type;
+ }
+
+ /**
+ * the method returns an instance of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder} based on the
+ * JPQLContextType. The context builder can be used for
+ * building different JPQL contexts.
+ *
+ * @param contextType
+ * is the JPQLContextType
+ * @param resultsView
+ * is the OData request view
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder}
+ * @throws ODataJPARuntimeException
+ */
+ public final static JPQLContextBuilder createBuilder(final JPQLContextType contextType, final Object resultsView)
+ throws ODataJPARuntimeException {
+ return JPQLContextBuilder.create(contextType, resultsView);
+ }
+
+ /**
+ * The abstract class is extended by specific JPQLContext builder for
+ * building JPQLContexts.
+ *
+ *
+ *
+ */
+ public static abstract class JPQLContextBuilder {
+ /**
+ * alias counter is an integer counter that is incremented by "1" for
+ * every new alias name generation. The value of counter is used in the
+ * generation of JPA entity alias names.
+ */
+ protected int aliasCounter = 0;
+
+ protected JPQLContextBuilder() {}
+
+ /**
+ * the method instantiates an instance of type JPQLContextBuilder.
+ *
+ * @param contextType
+ * indicates the type of JPQLContextBuilder to instantiate.
+ * @param resultsView
+ * is the OData request view
+ * @return an instance of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder}
+ * @throws ODataJPARuntimeException
+ */
+ private static JPQLContextBuilder create(final JPQLContextType contextType, final Object resultsView)
+ throws ODataJPARuntimeException {
+ JPQLContextBuilder contextBuilder =
+ ODataJPAFactory.createFactory().getJPQLBuilderFactory().getContextBuilder(contextType);
+ if (contextBuilder == null) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE, null);
+ }
+ contextBuilder.setResultsView(resultsView);
+ return contextBuilder;
+ }
+
+ /**
+ * The abstract method is implemented by specific JPQL context builders
+ * to build JPQL Contexts. The build method makes use of information set
+ * into the context to built JPQL Context Types.
+ *
+ * @return an instance of {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext}
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public abstract JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * The abstract method is implemented by specific JPQL context builder.
+ * The method sets the OData request view into the JPQL context.
+ *
+ * @param resultsView
+ * is an instance representing OData request.
+ */
+ protected abstract void setResultsView(Object resultsView);
+
+ /**
+ * The method resets the alias counter value to "0".
+ */
+ protected void resetAliasCounter() {
+ aliasCounter = 0;
+ }
+
+ /**
+ * The method returns a system generated alias name starting with prefix
+ * "E" and ending with suffix "aliasCounter".
+ *
+ * @return a String representing JPA entity alias name
+ */
+ protected String generateJPAEntityAlias() {
+ return new String("E" + ++aliasCounter);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextType.java
new file mode 100644
index 0000000..39d00ac
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextType.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+/**
+ * Enumerated list of JPQL context Types.
+ *
+ *
+ *
+ */
+public enum JPQLContextType {
+ /**
+ * indicates that the JPQL context can be used for building JPQL select
+ * statements
+ */
+ SELECT,
+ /**
+ * indicates that the JPQL context can be used for building JPQL modify
+ * statements
+ */
+ MODIFY,
+ /**
+ * indicates that the JPQL context can be used for building JPQL delete
+ * statements
+ */
+ DELETE,
+ /**
+ * indicates that the JPQL context can be used for building JPQL select
+ * statement that fetches single record
+ */
+ SELECT_SINGLE,
+ /**
+ * indicates that the JPQL context can be used for building JPQL join
+ * statement
+ */
+ JOIN,
+ /**
+ * indicates that the JPQL context can be used for building JPQL join
+ * statement that fetches single record
+ */
+ JOIN_SINGLE,
+ /**
+ * indicates that the JPQL context can be used for building JPQL select
+ * statement that fetches record counts
+ */
+ SELECT_COUNT,
+ /**
+ * indicates that the JPQL context can be used for building JPQL join
+ * statement that fetches single record
+ */
+ JOIN_COUNT,
+ /**
+ * indicates that the JPQL context can be used for building JPA Method
+ * context that can be used for invoking custom functions
+ */
+ FUNCTION
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextView.java
new file mode 100644
index 0000000..bee9c39
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLContextView.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+/**
+ * The interface provides a view on JPQL Context. The view can be used to access
+ * different JPQL context type implementations.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType
+ */
+public interface JPQLContextView {
+ /**
+ * The method returns a JPA entity name for which the JPQL context is
+ * relevant.
+ *
+ * @return JPA entity name
+ */
+ public String getJPAEntityName();
+
+ /**
+ * The method returns a JPA entity alias name for which the JPQL context is
+ * relevant.
+ *
+ * @return JPA entity alias name
+ */
+
+ public String getJPAEntityAlias();
+
+ /**
+ * The method returns a JPQL context type
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType}
+ */
+ public JPQLContextType getType();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinContextView.java
new file mode 100644
index 0000000..ec3fe8b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinContextView.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+
+/**
+ * The interface provide a view on JPQL Join context.The interface provides
+ * methods for accessing the Join Clause which can be part of JPQL Select
+ * statement. The interface extends the JPQL Select Context to add JQPL Join
+ * clauses to the Select statement. The JPQL Join context view is built from
+ * OData read entity set with navigation request.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLSelectContextView
+ *
+ */
+public interface JPQLJoinContextView extends JPQLSelectContextView {
+ /**
+ * The method returns a list of JPA Join Clauses. The returned list of
+ * values can be used for building JPQL Statements with Join clauses.
+ *
+ * @return a list of {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause}
+ */
+ public List<JPAJoinClause> getJPAJoinClauses();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinSelectSingleContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinSelectSingleContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinSelectSingleContextView.java
new file mode 100644
index 0000000..2fa8c3c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLJoinSelectSingleContextView.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.odata2.jpa.processor.api.jpql;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+
+/**
+ * The interface provide a view on JPQL Join Clauses.The interface is an
+ * extension to JPQL select single context and provides methods for accessing
+ * JPQL Join clauses. The view can be used for building JPQL statements without
+ * any WHERE,ORDERBY clauses. The clauses are built from OData read entity
+ * request views.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLSelectSingleContextView
+ *
+ */
+public interface JPQLJoinSelectSingleContextView extends JPQLSelectSingleContextView {
+
+ /**
+ * The method returns a list of JPA Join Clauses. The returned list of
+ * values can be used for building JPQL Statements with Join clauses.
+ *
+ * @return a list of {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause}
+ */
+ public abstract List<JPAJoinClause> getJPAJoinClauses();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectContextView.java
new file mode 100644
index 0000000..88878b6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectContextView.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+import java.util.HashMap;
+
+/**
+ * The interface provide a view on JPQL select context.The interface provides
+ * methods for accessing the clauses of a JPQL SELECT statement like "SELECT",
+ * "ORDERBY", "WHERE". The clauses are built from OData read entity set request
+ * views. The clauses thus built can be used for building JPQL Statements.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement
+ *
+ */
+public interface JPQLSelectContextView extends JPQLContextView {
+ /**
+ * The method returns a JPQL SELECT clause. The SELECT clause is built from
+ * $select OData system Query option.
+ *
+ * @return a String representing a SELECT clause in JPQL
+ */
+ public String getSelectExpression();
+
+ /**
+ * The method returns a Hash Map of JPQL ORDERBY clause. The ORDERBY clause
+ * is built from $orderby OData system query option. The hash map contains
+ * <ol>
+ * <li>Key - JPA Entity Property name to be ordered</li>
+ * <li>Value - Sort Order in JPQL (desc,asc)</li>
+ * </ol>
+ *
+ * @return a hash map of (JPA Property Name,Sort Order)
+ */
+ public HashMap<String, String> getOrderByCollection();
+
+ /**
+ * The method returns a JPQL WHERE condition as string. The WHERE condition
+ * can be built from $filter OData System Query Option and/or Key predicates
+ * of an OData Request.
+ *
+ * @return a String representing a WHERE condition in JPQL
+ */
+ public String getWhereExpression();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectSingleContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectSingleContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectSingleContextView.java
new file mode 100644
index 0000000..2a4ca0c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLSelectSingleContextView.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+
+/**
+ * The interface provide a view on JPQL select single context.The interface
+ * provides methods for accessing the clause of a JPQL SELECT statement like
+ * "SELECT". The view can be used for building JPQL statements without any
+ * WHERE,JOIN,ORDERBY clauses. The clauses are built from OData read entity
+ * request views.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement
+ *
+ */
+public interface JPQLSelectSingleContextView extends JPQLContextView {
+ /**
+ * The method returns a JPQL SELECT clause. The SELECT clause is built from
+ * $select OData system Query option.
+ *
+ * @return a String representing a SELECT clause in JPQL
+ */
+ public String getSelectExpression();
+
+ /**
+ * The method returns the list of key predicates that can be used for
+ * constructing the WHERE clause in JPQL statements. The OData entity key
+ * predicates are thus converted into JPA entity keys.
+ *
+ * @return a list of key predicates
+ */
+ public List<KeyPredicate> getKeyPredicates();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
new file mode 100644
index 0000000..56ea231
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/JPQLStatement.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.jpql;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+
+/**
+ * The class represents a Java Persistence Query Language (JPQL) Statement.
+ * The JPQL statement is built using a builder namely
+ * {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder} . Based upon the JPQL
+ * Context types ( {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType} different
+ * kinds of JPQL statements are built.
+ * The JPQL statements thus generated can be executed using JPA Query APIs to fetch JPA entities.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView
+ */
+public class JPQLStatement {
+
+ protected String statement;
+
+ /**
+ * The method is used for creating an instance of JPQL Statement Builder for
+ * building JPQL statements. The JPQL Statement builder is created based
+ * upon the JPQL Context.
+ *
+ * @param context
+ * a non null value of {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView} . The context is
+ * expected to be set to be built with no
+ * errors.
+ * @return an instance of JPQL statement builder
+ * @throws ODataJPARuntimeException
+ */
+ public static JPQLStatementBuilder createBuilder(final JPQLContextView context) throws ODataJPARuntimeException {
+ return JPQLStatementBuilder.create(context);
+ }
+
+ private JPQLStatement(final String statement) {
+ this.statement = statement;
+ }
+
+ /**
+ * The method provides a String representation of JPQLStatement.
+ */
+ @Override
+ public String toString() {
+ return statement;
+ }
+
+ /**
+ * The abstract class is extended by specific JPQL statement builders for
+ * building JPQL statements like
+ * <ol>
+ * <li>Select statements</li>
+ * <li>Select single statements</li>
+ * <li>Select statements with Join</li>
+ * <li>Insert/Modify/Delete statements</li>
+ * </ol>
+ *
+ * A default statement builder for building each kind of JPQL statements is
+ * provided by the library.
+ *
+ *
+ *
+ */
+ public static abstract class JPQLStatementBuilder {
+
+ protected JPQLStatementBuilder() {}
+
+ private static final JPQLStatementBuilder create(final JPQLContextView context) throws ODataJPARuntimeException {
+ return ODataJPAFactory.createFactory().getJPQLBuilderFactory().getStatementBuilder(context);
+ }
+
+ protected final JPQLStatement createStatement(final String statement) {
+ return new JPQLStatement(statement);
+ }
+
+ /**
+ * The abstract method is implemented by specific statement builder for
+ * building JPQL Statement.
+ *
+ * @return an instance of {@link org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement}
+ * @throws ODataJPARuntimeException
+ * in case there are errors building the statements
+ */
+ public abstract JPQLStatement build() throws ODataJPARuntimeException;
+
+ }
+
+ public static final class Operator {
+ public static final String EQ = "=";
+ public static final String NE = "<>";
+ public static final String LT = "<";
+ public static final String LE = "<=";
+ public static final String GT = ">";
+ public static final String GE = ">=";
+ public static final String AND = "AND";
+ public static final String NOT = "NOT";
+ public static final String OR = "OR";
+
+ }
+
+ public static final class KEYWORD {
+ public static final String SELECT = "SELECT";
+ public static final String FROM = "FROM";
+ public static final String WHERE = "WHERE";
+ public static final String LEFT_OUTER_JOIN = "LEFT OUTER JOIN";
+ public static final String OUTER = "OUTER";
+ public static final String JOIN = "JOIN";
+ public static final String ORDERBY = "ORDER BY";
+ public static final String COUNT = "COUNT";
+ public static final String OFFSET = ".000";
+ public static final String TIMESTAMP = "ts";
+
+ }
+
+ public static final class DELIMITER {
+ public static final char SPACE = ' ';
+ public static final char COMMA = ',';
+ public static final char PERIOD = '.';
+ public static final char PARENTHESIS_LEFT = '(';
+ public static final char PARENTHESIS_RIGHT = ')';
+ public static final char COLON = ':';
+ public static final char HYPHEN = '-';
+ public static final char LEFT_BRACE = '{';
+ public static final char RIGHT_BRACE = '}';
+ public static final char LONG = 'L';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/package-info.java
new file mode 100644
index 0000000..c059f7e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/jpql/package-info.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library - Java Persistence Query Language</h3>
+ * The library provides set of APIs for building JPQL contexts from OData Requests.
+ * The JPQL contexts thus built can be used for building JPQL Statements.
+ *
+ *
+ */
+package org.apache.olingo.odata2.jpa.processor.api.jpql;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationEndView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationEndView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationEndView.java
new file mode 100644
index 0000000..2d1262e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationEndView.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+
+/**
+ * <p>
+ * A view on Java Persistence Entity Relationship and Entity Data Model
+ * Association End.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM Association Ends
+ * created from Java Persistence Entity Relationships. The implementation acts
+ * as a container for Association Ends.
+ * </p>
+ *
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView
+ *
+ */
+public interface JPAEdmAssociationEndView extends JPAEdmBaseView {
+
+ /**
+ * The method gets the one of the association ends present in the container.
+ *
+ * @return one of the {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} for an
+ * {@link org.apache.olingo.odata2.api.edm.provider.Association}
+ */
+ AssociationEnd getEdmAssociationEnd2();
+
+ /**
+ * The method gets the other association end present in the container.
+ *
+ * @return one of the {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} for an
+ * {@link org.apache.olingo.odata2.api.edm.provider.Association}
+ */
+ AssociationEnd getEdmAssociationEnd1();
+
+ /**
+ * The method compares two ends {<b>end1, end2</b>} of an
+ * {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} against its
+ * two ends.
+ *
+ * The Method compares the following properties in each end for equality <i>
+ * <ul>
+ * <li>{@link org.apache.olingo.odata2.api.edm.FullQualifiedName} of End Type</li>
+ * <li>{@link org.apache.olingo.odata2.api.edm.EdmMultiplicity} of End</li>
+ * </ul>
+ * </i>
+ *
+ * @param end1
+ * one end of type {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} of
+ * an {@link org.apache.olingo.odata2.api.edm.provider.Association}
+ * @param end2
+ * other end of type {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} of
+ * an {@link org.apache.olingo.odata2.api.edm.provider.Association} <p>
+ * @return <ul>
+ * <li><i>true</i> - Only if the properties of <b>end1</b> matches
+ * with all the properties of any one end and only if the properties
+ * of <b>end2</b> matches with all the properties of the remaining
+ * end</li> <li><i>false</i> - Otherwise</li>
+ * </ul>
+ */
+ boolean compare(AssociationEnd end1, AssociationEnd end2);
+
+ String getJoinColumnName();
+
+ String getJoinColumnReferenceColumnName();
+
+ String getMappedByName();
+
+ String getOwningPropertyName();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationSetView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationSetView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationSetView.java
new file mode 100644
index 0000000..e0ed0db
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationSetView.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+
+/**
+ * <p>
+ * A view on Java Persistence Entity Relationship and Entity Data Model
+ * Association Set.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM Association Set created
+ * from Java Persistence Entity Relationship. The implementation act as a
+ * container for list of association sets that are consistent.
+ * </p>
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView
+ */
+public interface JPAEdmAssociationSetView extends JPAEdmBaseView {
+
+ /**
+ * The method returns a consistent list of association sets. An association
+ * set is set to be consistent only if all its mandatory properties can be
+ * completely built from a Java Persistence Relationship.
+ *
+ * @return a consistent list of {@link org.apache.olingo.odata2.api.edm.provider.AssociationSet}
+ *
+ */
+ List<AssociationSet> getConsistentEdmAssociationSetList();
+
+ /**
+ * The method returns an association set that is currently being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.AssociationSet}
+ */
+ AssociationSet getEdmAssociationSet();
+
+ /**
+ * The method returns an association from which the association set is
+ * currently being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.Association}
+ */
+ Association getEdmAssociation();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationView.java
new file mode 100644
index 0000000..ad29cc0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmAssociationView.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.Association;
+
+/**
+ * <p>
+ * A View on Java Persistence Entity Relationship and Entity Data Model
+ * Association.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM Association created
+ * from Java Persistence Entity Relationships. The implementation acts as a
+ * container for list of association that are consistent.
+ *
+ * An Association is said to be consistent only
+ * <ol>
+ * <li>If both the Ends of Association are consistent</li>
+ * <li>If referential constraint exists for the Association then it should be
+ * consistent</li>
+ * </ol>
+ * </p>
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView
+ *
+ */
+public interface JPAEdmAssociationView extends JPAEdmBaseView {
+
+ /**
+ * The method returns an association which is currently being processed.
+ *
+ * @return an {@link org.apache.olingo.odata2.api.edm.provider.Association}
+ */
+ public Association getEdmAssociation();
+
+ /**
+ * The method returns a consistent list of associations. An association is
+ * set to be consistent only if all its mandatory properties can be
+ * completely built from a Java Persistence Relationship.
+ *
+ * @return a consistent list of {@link org.apache.olingo.odata2.api.edm.provider.Association}
+ *
+ */
+ public List<Association> getConsistentEdmAssociationList();
+
+ /**
+ * The method adds {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView} to its container
+ *
+ * @param associationView
+ * of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}
+ */
+ public void addJPAEdmAssociationView(JPAEdmAssociationView associationView,
+ JPAEdmAssociationEndView associationEndView);
+
+ /**
+ * The method searches for an Association in its container against the
+ * search parameter <b>view</b> of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}
+ * .
+ *
+ * The Association in the container <b>view</b> is searched against the
+ * consistent list of Association stored in this container.
+ *
+ * @param view
+ * of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}
+ * @return {@link org.apache.olingo.odata2.api.edm.provider.Association} if found
+ * in the container
+ */
+ public Association searchAssociation(JPAEdmAssociationEndView view);
+
+ /**
+ * The method adds the referential constraint view to its container.
+ * <p>
+ * <b>Note: </b>The referential constraint view is added only if it exists.
+ * </p>
+ *
+ * @param refView
+ * of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView}
+ */
+ public void addJPAEdmRefConstraintView(JPAEdmReferentialConstraintView refView);
+
+ /**
+ * The method returns the referential constraint view that is currently
+ * being processed.
+ *
+ * @return an instance of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView}
+ */
+ public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView();
+
+ /**
+ * The method searches for the number of associations with similar endpoints in its container against the
+ * search parameter <b>view</b> of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}
+ * .
+ *
+ * The Association in the container <b>view</b> is searched against the
+ * consistent list of Association stored in this container.
+ *
+ * @param view
+ * of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}
+ * @return {@link org.apache.olingo.odata2.api.edm.provider.Association} if found
+ * in the container
+ */
+ int getNumberOfAssociationsWithSimilarEndPoints(JPAEdmAssociationEndView view);
+
+}
[37/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAMessageService.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAMessageService.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAMessageService.java
deleted file mode 100644
index 97dc1bf..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAMessageService.java
+++ /dev/null
@@ -1,49 +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.odata2.processor.api.jpa.exception;
-
-import org.apache.olingo.odata2.api.exception.MessageReference;
-
-/**
- * The interface is used to access language dependent message texts. Default
- * language is "English - EN". <br>
- * The default implementation of the interface shipped with the library loads
- * message texts from language dependent property files. If the message text is
- * not found for the given language then the default language -EN is used for
- * the message texts.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException
- * @see org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException
- * @see org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException
- * @see org.apache.olingo.odata2.api.exception.MessageReference
- */
-public interface ODataJPAMessageService {
- /**
- * The method returns a language dependent message texts for the given
- * {@link org.apache.olingo.odata2.api.exception.MessageReference}.
- *
- * @param context
- * is a Message Reference
- * exception
- * is a Throwable Exception
- * @return a language dependent message text
- */
- public String getLocalizedMessage(MessageReference context, Throwable exception);
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAModelException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAModelException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAModelException.java
deleted file mode 100644
index 7800b9e..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAModelException.java
+++ /dev/null
@@ -1,92 +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.odata2.processor.api.jpa.exception;
-
-import org.apache.olingo.odata2.api.exception.MessageReference;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-
-/**
- * The exception is thrown for any unexpected errors raising while
- * accessing/transforming Java Persistence Models.
- *
- *
- *
- */
-public class ODataJPAModelException extends ODataJPAException {
-
- public static final MessageReference INVALID_ENTITY_TYPE = createMessageReference(ODataJPAModelException.class,
- "INVALID_ENTITY_TYPE");
- public static final MessageReference INVALID_COMPLEX_TYPE = createMessageReference(ODataJPAModelException.class,
- "INVLAID_COMPLEX_TYPE");
- public static final MessageReference INVALID_ASSOCIATION = createMessageReference(ODataJPAModelException.class,
- "INVALID_ASSOCIATION");
- public static final MessageReference INVALID_ENTITYSET = createMessageReference(ODataJPAModelException.class,
- "INVALID_ENTITYSET");
- public static final MessageReference INVALID_ENTITYCONTAINER = createMessageReference(ODataJPAModelException.class,
- "INVALID_ENTITYCONTAINER");
- public static final MessageReference INVALID_ASSOCIATION_SET = createMessageReference(ODataJPAModelException.class,
- "INVALID_ASSOCIATION_SET");
- public static final MessageReference INVALID_FUNC_IMPORT = createMessageReference(ODataJPAModelException.class,
- "INVALID_FUNC_IMPORT");
-
- public static final MessageReference BUILDER_NULL = createMessageReference(ODataJPAModelException.class,
- "BUILDER_NULL");
- public static final MessageReference TYPE_NOT_SUPPORTED = createMessageReference(ODataJPAModelException.class,
- "TYPE_NOT_SUPPORTED");
- public static final MessageReference FUNC_ENTITYSET_EXP = createMessageReference(ODataJPAModelException.class,
- "FUNC_ENTITYSET_EXP");
- public static final MessageReference FUNC_RETURN_TYPE_EXP = createMessageReference(ODataJPAModelException.class,
- "FUNC_RETURN_TYPE_EXP");
- public static final MessageReference FUNC_RETURN_TYPE_ENTITY_NOT_FOUND = createMessageReference(
- ODataJPAModelException.class, "FUNC_RETURN_TYPE_ENTITY_NOT_FOUND");
- public static final MessageReference GENERAL = createMessageReference(ODataJPAModelException.class, "GENERAL");
- public static final MessageReference INNER_EXCEPTION = createMessageReference(ODataJPAModelException.class,
- "INNER_EXCEPTION");
- public static final MessageReference FUNC_PARAM_NAME_EXP = createMessageReference(ODataJPAModelException.class,
- "FUNC_PARAM_NAME_EXP");
-
- private ODataJPAModelException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
- super(localizedMessage, e, msgRef);
- }
-
- /**
- * The method creates an exception object of type ODataJPAModelException
- * with localized error texts.
- *
- * @param messageReference
- * is a <b>mandatory</b> parameter referring to a literal that
- * could be translated to localized error texts.
- * @param e
- * is an optional parameter representing the previous exception
- * in the call stack
- * @return an instance of ODataJPAModelException which can be then raised.
- * @throws ODataJPARuntimeException
- */
- public static ODataJPAModelException throwException(final MessageReference messageReference, final Throwable e) {
-
- ODataJPAMessageService messageService;
- messageService =
- ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAMessageService(DEFAULT_LOCALE);
- String message = messageService.getLocalizedMessage(messageReference, e);
- return new ODataJPAModelException(message, e, messageReference);
- }
-
- private static final long serialVersionUID = 7940106375606950703L;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPARuntimeException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPARuntimeException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPARuntimeException.java
deleted file mode 100644
index b3195c3..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPARuntimeException.java
+++ /dev/null
@@ -1,97 +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.odata2.processor.api.jpa.exception;
-
-import org.apache.olingo.odata2.api.exception.MessageReference;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-
-/**
- * The exception is thrown for any unexpected errors raising while accessing
- * data from Java Persistence Models.
- *
- * The exception object is created with localized error texts provided error
- * texts are maintained in localized languages.
- *
- *
- *
- */
-public class ODataJPARuntimeException extends ODataJPAException {
-
- public static final MessageReference ENTITY_MANAGER_NOT_INITIALIZED = createMessageReference(
- ODataJPARuntimeException.class, "ENTITY_MANAGER_NOT_INITIALIZED");
- public static final MessageReference RESOURCE_NOT_FOUND = createMessageReference(ODataJPARuntimeException.class,
- "RESOURCE_NOT_FOUND");
- public static final MessageReference GENERAL = createMessageReference(ODataJPARuntimeException.class, "GENERAL");
- public static final MessageReference INNER_EXCEPTION = createMessageReference(ODataJPARuntimeException.class,
- "INNER_EXCEPTION");
- public static final MessageReference JOIN_CLAUSE_EXPECTED = createMessageReference(ODataJPARuntimeException.class,
- "JOIN_CLAUSE_EXPECTED");
- public static final MessageReference ERROR_JPQLCTXBLDR_CREATE = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_JPQLCTXBLDR_CREATE");
- public static final MessageReference ERROR_ODATA_FILTER_CONDITION = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_ODATA_FILTER_CONDITION");
- public static final MessageReference ERROR_JPQL_QUERY_CREATE = createMessageReference(ODataJPARuntimeException.class,
- "ERROR_JPQL_QUERY_CREATE");
- public static final MessageReference ERROR_JPQL_CREATE_REQUEST = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_JPQL_CREATE_REQUEST");
- public static final MessageReference ERROR_JPQL_UPDATE_REQUEST = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_JPQL_UPDATE_REQUEST");
- public static final MessageReference ERROR_JPQL_DELETE_REQUEST = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_JPQL_DELETE_REQUEST");
- public static final MessageReference ERROR_JPQL_KEY_VALUE = createMessageReference(ODataJPARuntimeException.class,
- "ERROR_JPQL_KEY_VALUE");
- public static final MessageReference ERROR_JPQL_PARAM_VALUE = createMessageReference(ODataJPARuntimeException.class,
- "ERROR_JPQL_PARAM_VALUE");
- public static final MessageReference ERROR_JPQL_UNIQUE_CONSTRAINT = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_JPQL_UNIQUE_CONSTRAINT");
- public static final MessageReference ERROR_JPQL_INTEGRITY_CONSTRAINT = createMessageReference(
- ODataJPARuntimeException.class, "ERROR_JPQL_INTEGRITY_CONSTRAINT");
- public static final MessageReference RELATIONSHIP_INVALID = createMessageReference(ODataJPARuntimeException.class,
- "RELATIONSHIP_INVALID");
- public static final MessageReference RESOURCE_X_NOT_FOUND = createMessageReference(ODataJPARuntimeException.class,
- "RESOURCE_X_NOT_FOUND");
-
- private ODataJPARuntimeException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
- super(localizedMessage, e, msgRef);
- }
-
- /**
- * The method creates an exception object of type ODataJPARuntimeException
- * with localized error texts.
- *
- * @param messageReference
- * is a <b>mandatory</b> parameter referring to a literal that
- * could be translated to localized error texts.
- * @param e
- * is an optional parameter representing the previous exception
- * in the call stack
- * @return an instance of ODataJPARuntimeException which can be then raised.
- * @throws ODataJPARuntimeException
- */
- public static ODataJPARuntimeException throwException(final MessageReference messageReference, final Throwable e) {
- ODataJPAMessageService messageService;
- messageService =
- ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAMessageService(DEFAULT_LOCALE);
- String message = messageService.getLocalizedMessage(messageReference, e);
- return new ODataJPARuntimeException(message, e, messageReference);
- }
-
- private static final long serialVersionUID = -5230976355642443012L;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/package-info.java
deleted file mode 100644
index 5059bb4..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/package-info.java
+++ /dev/null
@@ -1,31 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library - Exceptions</h3>
- * There are two main types of exceptions thrown from the library
- * <ol><li>Model Exception</li>
- * <li>Runtime Exception</li></ol>
- * <br>
- * The Model Exception is thrown while processing JPA metamodels and
- * runtime exception is thrown while processing persistence data.
- *
- *
- */
-package org.apache.olingo.odata2.processor.api.jpa.exception;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPAAccessFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPAAccessFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPAAccessFactory.java
deleted file mode 100644
index 02268de..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPAAccessFactory.java
+++ /dev/null
@@ -1,69 +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.odata2.processor.api.jpa.factory;
-
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
-
-/**
- * Factory interface for creating
- * <ol>
- * <li>JPA EDM Model view</li>
- * <li>JPA Processor</li>
- * </ol>
- *
- *
- *
- */
-public interface JPAAccessFactory {
- /**
- * The method returns an instance of JPA EDM model view based on OData JPA
- * Context. The JPA EDM model view thus returned can be used for building
- * EDM models from Java persistence models.
- *
- * @param oDataJPAContext
- * a non null instance of {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView}
- */
- public JPAEdmModelView getJPAEdmModelView(ODataJPAContext oDataJPAContext);
-
- /**
- * The method returns an instance of JPA processor based on OData JPA
- * Context. The JPA Processor thus returned can be used for building and
- * processing JPQL statements.
- *
- * @param oDataJPAContext
- * a non null instance of {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor}
- */
- public JPAProcessor getJPAProcessor(ODataJPAContext oDataJPAContext);
-
- /**
- * The method returns an instance of JPA EDM mapping model access based on
- * OData JPA context. The instance thus returned can be used for accessing
- * the mapping details maintained for an OData service
- *
- * @param oDataJPAContext
- * a non null instance of {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess}
- */
- public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(ODataJPAContext oDataJPAContext);
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPQLBuilderFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPQLBuilderFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPQLBuilderFactory.java
deleted file mode 100644
index 52d45ab..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/JPQLBuilderFactory.java
+++ /dev/null
@@ -1,77 +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.odata2.processor.api.jpa.factory;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext.JPAMethodContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-
-/**
- * Factory interface for creating following instances
- *
- * <p>
- * <ul>
- * <li>JPQL statement builders of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder} </li>
- * <li>JPQL context builder of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder} </li>
- * </ul>
- * </p>
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory
- */
-public interface JPQLBuilderFactory {
- /**
- * The method returns JPQL statement builder for building JPQL statements.
- *
- * @param context
- * is {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext} that determines the type of JPQL statement
- * builder. The
- * parameter cannot be null.
- * @return an instance of JPQLStatementBuilder
- */
- public JPQLStatementBuilder getStatementBuilder(JPQLContextView context);
-
- /**
- * The method returns a JPQL context builder for building JPQL Context
- * object.
- *
- * @param contextType
- * is {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType} that determines the type of JPQL context
- * builder. The
- * parameter cannot be null.
- * @return an instance of JPQLContextBuilder
- */
- public JPQLContextBuilder getContextBuilder(JPQLContextType contextType);
-
- /**
- * The method returns a JPA method context builder for building JPA Method
- * context object.
- *
- * @param contextType
- * is {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType} that determines the type of JPQL context
- * builder. The
- * parameter cannot be null.
- * @return an instance of JPAMethodContextBuilder
- */
- public JPAMethodContextBuilder getJPAMethodContextBuilder(JPQLContextType contextType);
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAAccessFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAAccessFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAAccessFactory.java
deleted file mode 100644
index 3d8073e..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAAccessFactory.java
+++ /dev/null
@@ -1,82 +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.odata2.processor.api.jpa.factory;
-
-import java.util.Locale;
-
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAMessageService;
-
-/**
- * Factory interface for creating following instances
- *
- * <p>
- * <ul>
- * <li>OData JPA Processor of type {@link org.apache.olingo.odata2.api.processor.ODataSingleProcessor}</li>
- * <li>JPA EDM Provider of type {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider}</li>
- * <li>OData JPA Context {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}</li>
- * </ul>
- * </p>
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory
- */
-public interface ODataJPAAccessFactory {
- /**
- * The method creates an OData JPA Processor. The processor handles runtime
- * behavior of an OData service.
- *
- * @param oDataJPAContext
- * an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}.
- * The context should be initialized properly and cannot be null.
- * @return An implementation of OData JPA Processor.
- */
- public ODataSingleProcessor createODataProcessor(ODataJPAContext oDataJPAContext);
-
- /**
- *
- * @param oDataJPAContext
- * an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}.
- * The context should be initialized properly and cannot be null.
- * @return An implementation of JPA EdmProvider. EdmProvider handles
- * meta-data.
- */
- public EdmProvider createJPAEdmProvider(ODataJPAContext oDataJPAContext);
-
- /**
- * The method creates an instance of OData JPA Context. An empty instance is
- * returned.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}
- */
- public ODataJPAContext createODataJPAContext();
-
- /**
- * The method creates an instance of message service for loading language
- * dependent message text.
- *
- * @param locale
- * is the language in which the message service should load
- * message texts.
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAMessageService}
- */
- public ODataJPAMessageService getODataJPAMessageService(Locale locale);
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAFactory.java
deleted file mode 100644
index b421ce4..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/ODataJPAFactory.java
+++ /dev/null
@@ -1,105 +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.odata2.processor.api.jpa.factory;
-
-/**
- * The class is an abstract factory for creating default ODataJPAFactory. The
- * class's actual implementation is responsible for creating other factory
- * implementations.The class creates factories implementing interfaces
- * <ul>
- * <li>{@link org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory}</li>
- * <li>{@link org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory}</li>
- * <li>{@link org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory}</li>
- * </ul>
- *
- * <b>Note: </b>Extend this class only if you don't require library's default
- * factory implementation.
- * <p>
- *
- *
- *
- *
- *
- */
-public abstract class ODataJPAFactory {
-
- private static final String IMPLEMENTATION =
- "org.apache.olingo.odata2.processor.core.jpa.factory.ODataJPAFactoryImpl";
- private static ODataJPAFactory factoryImpl;
-
- /**
- * Method creates a factory instance. The instance returned is singleton.
- * The instance of this factory can be used for creating other factory
- * implementations.
- *
- * @return instance of type {@link org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory} .
- */
- public static ODataJPAFactory createFactory() {
-
- if (factoryImpl != null) {
- return factoryImpl;
- } else {
- try {
- Class<?> clazz = Class.forName(ODataJPAFactory.IMPLEMENTATION);
-
- Object object = clazz.newInstance();
- factoryImpl = (ODataJPAFactory) object;
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- return factoryImpl;
- }
- }
-
- /**
- * The method returns a null reference to JPQL Builder Factory. Override
- * this method to return an implementation of JPQLBuilderFactory if default
- * implementation from library is not required.
- *
- * @return instance of type {@link org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory}
- */
- public JPQLBuilderFactory getJPQLBuilderFactory() {
- return null;
- };
-
- /**
- * The method returns a null reference to JPA Access Factory. Override this
- * method to return an implementation of JPAAccessFactory if default
- * implementation from library is not required.
- *
- * @return instance of type {@link org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory}
- */
- public JPAAccessFactory getJPAAccessFactory() {
- return null;
- };
-
- /**
- * The method returns a null reference to OData JPA Access Factory. Override
- * this method to return an implementation of ODataJPAAccessFactory if
- * default implementation from library is not required.
- *
- * @return instance of type {@link org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAAccessFactory}
- */
- public ODataJPAAccessFactory getODataJPAAccessFactory() {
- return null;
- };
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/package-info.java
deleted file mode 100644
index de2b699..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/factory/package-info.java
+++ /dev/null
@@ -1,33 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library - Factory</h3>
- * The library provides different types of factories for creating instances for
- * <ul>
- * <li>Accessing Java Persistence Model/Data</li>
- * <li>Building different types of JPQL statements</li>
- * <li>Accessing OData EDM provider and processor</li>
- * </ul>
- *
- * The instances of these factories can be obtained from an abstract ODataJPAFactory.
- *
- *
- */
-package org.apache.olingo.odata2.processor.api.jpa.factory;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContext.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContext.java
deleted file mode 100644
index ab24e67..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContext.java
+++ /dev/null
@@ -1,204 +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.odata2.processor.api.jpa.jpql;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-
-/**
- * The abstract class is a compilation of objects required for building
- * {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement}. Extend this
- * class to implement specific implementations of JPQL context types (Select,
- * Join). A JPQL Context is constructed from an OData
- * request. Depending on OData CRUD operation performed on an Entity, a
- * corresponding JPQL context object is built. The JPQL context object thus
- * built can be used for constructing JPQL statements. <br>
- * A default implementation is provided by the library.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory
- *
- */
-public abstract class JPQLContext implements JPQLContextView {
-
- /**
- * An alias for Java Persistence Entity
- */
- protected String jpaEntityAlias;
- /**
- * Java Persistence Entity name
- */
- protected String jpaEntityName;
- /**
- * The type of JPQL context. Based on the type JPQL statements can be built.
- */
- protected JPQLContextType type;
-
- /**
- * sets JPA Entity Name into the context
- *
- * @param jpaEntityName
- * is the name of JPA Entity
- */
- protected final void setJPAEntityName(final String jpaEntityName) {
- this.jpaEntityName = jpaEntityName;
- }
-
- /**
- * sets JPA Entity alias name into the context
- *
- * @param jpaEntityAlias
- * is the JPA entity alias name
- */
- protected final void setJPAEntityAlias(final String jpaEntityAlias) {
- this.jpaEntityAlias = jpaEntityAlias;
- }
-
- /**
- * gets the JPA entity alias name set into the context
- */
- @Override
- public final String getJPAEntityAlias() {
- return jpaEntityAlias;
- }
-
- /**
- * sets the JPQL context type into the context
- *
- * @param type
- * is JPQLContextType
- */
- protected final void setType(final JPQLContextType type) {
- this.type = type;
- }
-
- /**
- * gets the JPA entity name set into the context
- */
- @Override
- public final String getJPAEntityName() {
- return jpaEntityName;
- }
-
- /**
- * gets the JPQL context type set into the context
- */
- @Override
- public final JPQLContextType getType() {
- return type;
- }
-
- /**
- * the method returns an instance of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder} based on the
- * JPQLContextType. The context builder can be used for
- * building different JPQL contexts.
- *
- * @param contextType
- * is the JPQLContextType
- * @param resultsView
- * is the OData request view
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder}
- * @throws ODataJPARuntimeException
- */
- public final static JPQLContextBuilder createBuilder(final JPQLContextType contextType, final Object resultsView)
- throws ODataJPARuntimeException {
- return JPQLContextBuilder.create(contextType, resultsView);
- }
-
- /**
- * The abstract class is extended by specific JPQLContext builder for
- * building JPQLContexts.
- *
- *
- *
- */
- public static abstract class JPQLContextBuilder {
- /**
- * alias counter is an integer counter that is incremented by "1" for
- * every new alias name generation. The value of counter is used in the
- * generation of JPA entity alias names.
- */
- protected int aliasCounter = 0;
-
- protected JPQLContextBuilder() {}
-
- /**
- * the method instantiates an instance of type JPQLContextBuilder.
- *
- * @param contextType
- * indicates the type of JPQLContextBuilder to instantiate.
- * @param resultsView
- * is the OData request view
- * @return an instance of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder}
- * @throws ODataJPARuntimeException
- */
- private static JPQLContextBuilder create(final JPQLContextType contextType, final Object resultsView)
- throws ODataJPARuntimeException {
- JPQLContextBuilder contextBuilder =
- ODataJPAFactory.createFactory().getJPQLBuilderFactory().getContextBuilder(contextType);
- if (contextBuilder == null) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE, null);
- }
- contextBuilder.setResultsView(resultsView);
- return contextBuilder;
- }
-
- /**
- * The abstract method is implemented by specific JPQL context builders
- * to build JPQL Contexts. The build method makes use of information set
- * into the context to built JPQL Context Types.
- *
- * @return an instance of {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext}
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public abstract JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * The abstract method is implemented by specific JPQL context builder.
- * The method sets the OData request view into the JPQL context.
- *
- * @param resultsView
- * is an instance representing OData request.
- */
- protected abstract void setResultsView(Object resultsView);
-
- /**
- * The method resets the alias counter value to "0".
- */
- protected void resetAliasCounter() {
- aliasCounter = 0;
- }
-
- /**
- * The method returns a system generated alias name starting with prefix
- * "E" and ending with suffix "aliasCounter".
- *
- * @return a String representing JPA entity alias name
- */
- protected String generateJPAEntityAlias() {
- return new String("E" + ++aliasCounter);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextType.java
deleted file mode 100644
index 17df83a..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextType.java
+++ /dev/null
@@ -1,73 +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.odata2.processor.api.jpa.jpql;
-
-/**
- * Enumerated list of JPQL context Types.
- *
- *
- *
- */
-public enum JPQLContextType {
- /**
- * indicates that the JPQL context can be used for building JPQL select
- * statements
- */
- SELECT,
- /**
- * indicates that the JPQL context can be used for building JPQL modify
- * statements
- */
- MODIFY,
- /**
- * indicates that the JPQL context can be used for building JPQL delete
- * statements
- */
- DELETE,
- /**
- * indicates that the JPQL context can be used for building JPQL select
- * statement that fetches single record
- */
- SELECT_SINGLE,
- /**
- * indicates that the JPQL context can be used for building JPQL join
- * statement
- */
- JOIN,
- /**
- * indicates that the JPQL context can be used for building JPQL join
- * statement that fetches single record
- */
- JOIN_SINGLE,
- /**
- * indicates that the JPQL context can be used for building JPQL select
- * statement that fetches record counts
- */
- SELECT_COUNT,
- /**
- * indicates that the JPQL context can be used for building JPQL join
- * statement that fetches single record
- */
- JOIN_COUNT,
- /**
- * indicates that the JPQL context can be used for building JPA Method
- * context that can be used for invoking custom functions
- */
- FUNCTION
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextView.java
deleted file mode 100644
index d1ac24f..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLContextView.java
+++ /dev/null
@@ -1,53 +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.odata2.processor.api.jpa.jpql;
-
-/**
- * The interface provides a view on JPQL Context. The view can be used to access
- * different JPQL context type implementations.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType
- */
-public interface JPQLContextView {
- /**
- * The method returns a JPA entity name for which the JPQL context is
- * relevant.
- *
- * @return JPA entity name
- */
- public String getJPAEntityName();
-
- /**
- * The method returns a JPA entity alias name for which the JPQL context is
- * relevant.
- *
- * @return JPA entity alias name
- */
-
- public String getJPAEntityAlias();
-
- /**
- * The method returns a JPQL context type
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType}
- */
- public JPQLContextType getType();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinContextView.java
deleted file mode 100644
index 4392015..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinContextView.java
+++ /dev/null
@@ -1,44 +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.odata2.processor.api.jpa.jpql;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-
-/**
- * The interface provide a view on JPQL Join context.The interface provides
- * methods for accessing the Join Clause which can be part of JPQL Select
- * statement. The interface extends the JPQL Select Context to add JQPL Join
- * clauses to the Select statement. The JPQL Join context view is built from
- * OData read entity set with navigation request.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLSelectContextView
- *
- */
-public interface JPQLJoinContextView extends JPQLSelectContextView {
- /**
- * The method returns a list of JPA Join Clauses. The returned list of
- * values can be used for building JPQL Statements with Join clauses.
- *
- * @return a list of {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause}
- */
- public List<JPAJoinClause> getJPAJoinClauses();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinSelectSingleContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinSelectSingleContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinSelectSingleContextView.java
deleted file mode 100644
index 7d71dc3..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLJoinSelectSingleContextView.java
+++ /dev/null
@@ -1,45 +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.odata2.processor.api.jpa.jpql;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-
-/**
- * The interface provide a view on JPQL Join Clauses.The interface is an
- * extension to JPQL select single context and provides methods for accessing
- * JPQL Join clauses. The view can be used for building JPQL statements without
- * any WHERE,ORDERBY clauses. The clauses are built from OData read entity
- * request views.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLSelectSingleContextView
- *
- */
-public interface JPQLJoinSelectSingleContextView extends JPQLSelectSingleContextView {
-
- /**
- * The method returns a list of JPA Join Clauses. The returned list of
- * values can be used for building JPQL Statements with Join clauses.
- *
- * @return a list of {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause}
- */
- public abstract List<JPAJoinClause> getJPAJoinClauses();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectContextView.java
deleted file mode 100644
index 58f595e..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectContextView.java
+++ /dev/null
@@ -1,62 +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.odata2.processor.api.jpa.jpql;
-
-import java.util.HashMap;
-
-/**
- * The interface provide a view on JPQL select context.The interface provides
- * methods for accessing the clauses of a JPQL SELECT statement like "SELECT",
- * "ORDERBY", "WHERE". The clauses are built from OData read entity set request
- * views. The clauses thus built can be used for building JPQL Statements.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement
- *
- */
-public interface JPQLSelectContextView extends JPQLContextView {
- /**
- * The method returns a JPQL SELECT clause. The SELECT clause is built from
- * $select OData system Query option.
- *
- * @return a String representing a SELECT clause in JPQL
- */
- public String getSelectExpression();
-
- /**
- * The method returns a Hash Map of JPQL ORDERBY clause. The ORDERBY clause
- * is built from $orderby OData system query option. The hash map contains
- * <ol>
- * <li>Key - JPA Entity Property name to be ordered</li>
- * <li>Value - Sort Order in JPQL (desc,asc)</li>
- * </ol>
- *
- * @return a hash map of (JPA Property Name,Sort Order)
- */
- public HashMap<String, String> getOrderByCollection();
-
- /**
- * The method returns a JPQL WHERE condition as string. The WHERE condition
- * can be built from $filter OData System Query Option and/or Key predicates
- * of an OData Request.
- *
- * @return a String representing a WHERE condition in JPQL
- */
- public String getWhereExpression();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectSingleContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectSingleContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectSingleContextView.java
deleted file mode 100644
index 5e492be..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLSelectSingleContextView.java
+++ /dev/null
@@ -1,53 +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.odata2.processor.api.jpa.jpql;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-
-/**
- * The interface provide a view on JPQL select single context.The interface
- * provides methods for accessing the clause of a JPQL SELECT statement like
- * "SELECT". The view can be used for building JPQL statements without any
- * WHERE,JOIN,ORDERBY clauses. The clauses are built from OData read entity
- * request views.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement
- *
- */
-public interface JPQLSelectSingleContextView extends JPQLContextView {
- /**
- * The method returns a JPQL SELECT clause. The SELECT clause is built from
- * $select OData system Query option.
- *
- * @return a String representing a SELECT clause in JPQL
- */
- public String getSelectExpression();
-
- /**
- * The method returns the list of key predicates that can be used for
- * constructing the WHERE clause in JPQL statements. The OData entity key
- * predicates are thus converted into JPA entity keys.
- *
- * @return a list of key predicates
- */
- public List<KeyPredicate> getKeyPredicates();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLStatement.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLStatement.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLStatement.java
deleted file mode 100644
index e68b4d4..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/JPQLStatement.java
+++ /dev/null
@@ -1,148 +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.odata2.processor.api.jpa.jpql;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-
-/**
- * The class represents a Java Persistence Query Language (JPQL) Statement.
- * The JPQL statement is built using a builder namely
- * {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder} . Based upon the JPQL
- * Context types ( {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType} different
- * kinds of JPQL statements are built.
- * The JPQL statements thus generated can be executed using JPA Query APIs to fetch JPA entities.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView
- */
-public class JPQLStatement {
-
- protected String statement;
-
- /**
- * The method is used for creating an instance of JPQL Statement Builder for
- * building JPQL statements. The JPQL Statement builder is created based
- * upon the JPQL Context.
- *
- * @param context
- * a non null value of {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView} . The context is
- * expected to be set to be built with no
- * errors.
- * @return an instance of JPQL statement builder
- * @throws ODataJPARuntimeException
- */
- public static JPQLStatementBuilder createBuilder(final JPQLContextView context) throws ODataJPARuntimeException {
- return JPQLStatementBuilder.create(context);
- }
-
- private JPQLStatement(final String statement) {
- this.statement = statement;
- }
-
- /**
- * The method provides a String representation of JPQLStatement.
- */
- @Override
- public String toString() {
- return statement;
- }
-
- /**
- * The abstract class is extended by specific JPQL statement builders for
- * building JPQL statements like
- * <ol>
- * <li>Select statements</li>
- * <li>Select single statements</li>
- * <li>Select statements with Join</li>
- * <li>Insert/Modify/Delete statements</li>
- * </ol>
- *
- * A default statement builder for building each kind of JPQL statements is
- * provided by the library.
- *
- *
- *
- */
- public static abstract class JPQLStatementBuilder {
-
- protected JPQLStatementBuilder() {}
-
- private static final JPQLStatementBuilder create(final JPQLContextView context) throws ODataJPARuntimeException {
- return ODataJPAFactory.createFactory().getJPQLBuilderFactory().getStatementBuilder(context);
- }
-
- protected final JPQLStatement createStatement(final String statement) {
- return new JPQLStatement(statement);
- }
-
- /**
- * The abstract method is implemented by specific statement builder for
- * building JPQL Statement.
- *
- * @return an instance of {@link org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement}
- * @throws ODataJPARuntimeException
- * in case there are errors building the statements
- */
- public abstract JPQLStatement build() throws ODataJPARuntimeException;
-
- }
-
- public static final class Operator {
- public static final String EQ = "=";
- public static final String NE = "<>";
- public static final String LT = "<";
- public static final String LE = "<=";
- public static final String GT = ">";
- public static final String GE = ">=";
- public static final String AND = "AND";
- public static final String NOT = "NOT";
- public static final String OR = "OR";
-
- }
-
- public static final class KEYWORD {
- public static final String SELECT = "SELECT";
- public static final String FROM = "FROM";
- public static final String WHERE = "WHERE";
- public static final String LEFT_OUTER_JOIN = "LEFT OUTER JOIN";
- public static final String OUTER = "OUTER";
- public static final String JOIN = "JOIN";
- public static final String ORDERBY = "ORDER BY";
- public static final String COUNT = "COUNT";
- public static final String OFFSET = ".000";
- public static final String TIMESTAMP = "ts";
-
- }
-
- public static final class DELIMITER {
- public static final char SPACE = ' ';
- public static final char COMMA = ',';
- public static final char PERIOD = '.';
- public static final char PARENTHESIS_LEFT = '(';
- public static final char PARENTHESIS_RIGHT = ')';
- public static final char COLON = ':';
- public static final char HYPHEN = '-';
- public static final char LEFT_BRACE = '{';
- public static final char RIGHT_BRACE = '}';
- public static final char LONG = 'L';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/package-info.java
deleted file mode 100644
index dc02b90..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/jpql/package-info.java
+++ /dev/null
@@ -1,27 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library - Java Persistence Query Language</h3>
- * The library provides set of APIs for building JPQL contexts from OData Requests.
- * The JPQL contexts thus built can be used for building JPQL Statements.
- *
- *
- */
-package org.apache.olingo.odata2.processor.api.jpa.jpql;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationEndView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationEndView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationEndView.java
deleted file mode 100644
index 9d3238d..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationEndView.java
+++ /dev/null
@@ -1,91 +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.odata2.processor.api.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-
-/**
- * <p>
- * A view on Java Persistence Entity Relationship and Entity Data Model
- * Association End.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM Association Ends
- * created from Java Persistence Entity Relationships. The implementation acts
- * as a container for Association Ends.
- * </p>
- *
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView
- *
- */
-public interface JPAEdmAssociationEndView extends JPAEdmBaseView {
-
- /**
- * The method gets the one of the association ends present in the container.
- *
- * @return one of the {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} for an
- * {@link org.apache.olingo.odata2.api.edm.provider.Association}
- */
- AssociationEnd getEdmAssociationEnd2();
-
- /**
- * The method gets the other association end present in the container.
- *
- * @return one of the {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} for an
- * {@link org.apache.olingo.odata2.api.edm.provider.Association}
- */
- AssociationEnd getEdmAssociationEnd1();
-
- /**
- * The method compares two ends {<b>end1, end2</b>} of an
- * {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} against its
- * two ends.
- *
- * The Method compares the following properties in each end for equality <i>
- * <ul>
- * <li>{@link org.apache.olingo.odata2.api.edm.FullQualifiedName} of End Type</li>
- * <li>{@link org.apache.olingo.odata2.api.edm.EdmMultiplicity} of End</li>
- * </ul>
- * </i>
- *
- * @param end1
- * one end of type {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} of
- * an {@link org.apache.olingo.odata2.api.edm.provider.Association}
- * @param end2
- * other end of type {@link org.apache.olingo.odata2.api.edm.provider.AssociationEnd} of
- * an {@link org.apache.olingo.odata2.api.edm.provider.Association} <p>
- * @return <ul>
- * <li><i>true</i> - Only if the properties of <b>end1</b> matches
- * with all the properties of any one end and only if the properties
- * of <b>end2</b> matches with all the properties of the remaining
- * end</li> <li><i>false</i> - Otherwise</li>
- * </ul>
- */
- boolean compare(AssociationEnd end1, AssociationEnd end2);
-
- String getJoinColumnName();
-
- String getJoinColumnReferenceColumnName();
-
- String getMappedByName();
-
- String getOwningPropertyName();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationSetView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationSetView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationSetView.java
deleted file mode 100644
index 911569d..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationSetView.java
+++ /dev/null
@@ -1,69 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-
-/**
- * <p>
- * A view on Java Persistence Entity Relationship and Entity Data Model
- * Association Set.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM Association Set created
- * from Java Persistence Entity Relationship. The implementation act as a
- * container for list of association sets that are consistent.
- * </p>
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView
- */
-public interface JPAEdmAssociationSetView extends JPAEdmBaseView {
-
- /**
- * The method returns a consistent list of association sets. An association
- * set is set to be consistent only if all its mandatory properties can be
- * completely built from a Java Persistence Relationship.
- *
- * @return a consistent list of {@link org.apache.olingo.odata2.api.edm.provider.AssociationSet}
- *
- */
- List<AssociationSet> getConsistentEdmAssociationSetList();
-
- /**
- * The method returns an association set that is currently being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.AssociationSet}
- */
- AssociationSet getEdmAssociationSet();
-
- /**
- * The method returns an association from which the association set is
- * currently being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.Association}
- */
- Association getEdmAssociation();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationView.java
deleted file mode 100644
index 7cc7cda..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmAssociationView.java
+++ /dev/null
@@ -1,128 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.Association;
-
-/**
- * <p>
- * A View on Java Persistence Entity Relationship and Entity Data Model
- * Association.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM Association created
- * from Java Persistence Entity Relationships. The implementation acts as a
- * container for list of association that are consistent.
- *
- * An Association is said to be consistent only
- * <ol>
- * <li>If both the Ends of Association are consistent</li>
- * <li>If referential constraint exists for the Association then it should be
- * consistent</li>
- * </ol>
- * </p>
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView
- *
- */
-public interface JPAEdmAssociationView extends JPAEdmBaseView {
-
- /**
- * The method returns an association which is currently being processed.
- *
- * @return an {@link org.apache.olingo.odata2.api.edm.provider.Association}
- */
- public Association getEdmAssociation();
-
- /**
- * The method returns a consistent list of associations. An association is
- * set to be consistent only if all its mandatory properties can be
- * completely built from a Java Persistence Relationship.
- *
- * @return a consistent list of {@link org.apache.olingo.odata2.api.edm.provider.Association}
- *
- */
- public List<Association> getConsistentEdmAssociationList();
-
- /**
- * The method adds {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView} to its container
- *
- * @param associationView
- * of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}
- */
- public void addJPAEdmAssociationView(JPAEdmAssociationView associationView,
- JPAEdmAssociationEndView associationEndView);
-
- /**
- * The method searches for an Association in its container against the
- * search parameter <b>view</b> of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}
- * .
- *
- * The Association in the container <b>view</b> is searched against the
- * consistent list of Association stored in this container.
- *
- * @param view
- * of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}
- * @return {@link org.apache.olingo.odata2.api.edm.provider.Association} if found
- * in the container
- */
- public Association searchAssociation(JPAEdmAssociationEndView view);
-
- /**
- * The method adds the referential constraint view to its container.
- * <p>
- * <b>Note: </b>The referential constraint view is added only if it exists.
- * </p>
- *
- * @param refView
- * of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView}
- */
- public void addJPAEdmRefConstraintView(JPAEdmReferentialConstraintView refView);
-
- /**
- * The method returns the referential constraint view that is currently
- * being processed.
- *
- * @return an instance of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView}
- */
- public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView();
-
- /**
- * The method searches for the number of associations with similar endpoints in its container against the
- * search parameter <b>view</b> of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}
- * .
- *
- * The Association in the container <b>view</b> is searched against the
- * consistent list of Association stored in this container.
- *
- * @param view
- * of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}
- * @return {@link org.apache.olingo.odata2.api.edm.provider.Association} if found
- * in the container
- */
- int getNumberOfAssociationsWithSimilarEndPoints(JPAEdmAssociationEndView view);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmBaseView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmBaseView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmBaseView.java
deleted file mode 100644
index 765da7f..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmBaseView.java
+++ /dev/null
@@ -1,101 +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.odata2.processor.api.jpa.model;
-
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-
-/**
- * <p>
- * A base view on Java Persistence Model and Entity Data Model.
- * </p>
- * <p>
- * The implementation of the view acts as a base container for containers of
- * Java Persistence Model and Entity Data Model elements.
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- *
- */
-public interface JPAEdmBaseView {
- /**
- *
- * @return Java Persistence Unit Name
- */
- public String getpUnitName();
-
- /**
- * The method returns the Java Persistence MetaModel
- *
- * @return a meta model of type {@link javax.persistence.metamodel.Metamodel}
- */
- public Metamodel getJPAMetaModel();
-
- /**
- * The method returns a builder for building Entity Data Model elements from
- * Java Persistence Model Elements
- *
- * @return a builder of type {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder}
- */
- public JPAEdmBuilder getBuilder();
-
- /**
- * The method returns the if the container is consistent without any errors
- *
- * @return <ul>
- * <li>true - if the container is consistent without errors</li>
- * <li>false - if the container is inconsistent with errors</li>
- * </ul>
- *
- */
- public boolean isConsistent();
-
- /**
- * The method cleans the container.
- */
- public void clean();
-
- /**
- * The method returns a reference to JPA EDM mapping model access.
- *
- * @return an instance to JPA EDM mapping model access
- */
- public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess();
-
- /**
- * The method returns a reference to JPA EDM extension if available else
- * null.
- *
- * @return an instance of JPA Edm Extension
- */
- public JPAEdmExtension getJPAEdmExtension();
-
- /**
- * The method returns whether the default naming logic is skipped for the
- * current view.
- *
- * @return <ul><li>true - skip default naming logic</li>
- * <li>false - do not skip default naming logic</li>
- * </ul>
- */
- public boolean isDefaultNamingSkipped();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexPropertyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexPropertyView.java
deleted file mode 100644
index 172e5f4..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexPropertyView.java
+++ /dev/null
@@ -1,45 +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.odata2.processor.api.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-
-/**
- * <p>
- * A view on properties of Java Persistence embeddable type and EDM complex
- * type. Properties of JPA embeddable types are converted into EDM properties of
- * EDM complex type.
- * </p>
- * <p>
- * The implementation of the view provides access to properties of EDM complex
- * type created for a given JPA EDM complex type. The implementation acts as a
- * container for the properties of EDM complex type.
- * </p>
- *
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView
- */
-public interface JPAEdmComplexPropertyView extends JPAEdmBaseView {
- /**
- * The method returns a complex property for a complex type.
- *
- * @return an instance of {@link org.apache.olingo.odata2.api.edm.provider.ComplexProperty}
- */
- ComplexProperty getEdmComplexProperty();
-}
[11/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModelTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModelTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModelTest.java
deleted file mode 100644
index 4192c2b..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModelTest.java
+++ /dev/null
@@ -1,145 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEmbeddableMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPASingularAttributeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmModelTest extends JPAEdmTestModelView {
-
- private JPAEdmModel objJPAEdmModel;
-
- @Before
- public void setUp() {
- objJPAEdmModel = new JPAEdmModel(getJPAMetaModel(), "salesorderprocessing");
- try {
- objJPAEdmModel.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetEdmSchemaView() {
- assertNotNull(objJPAEdmModel.getEdmSchemaView());
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmModel.getBuilder());
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAEdmMetaModel();
- }
-
- private class JPAEdmMetaModel extends JPAMetaModelMock {
- Set<EmbeddableType<?>> embeddableSet;
-
- public JPAEdmMetaModel() {
- embeddableSet = new HashSet<EmbeddableType<?>>();
- }
-
- @Override
- public Set<EmbeddableType<?>> getEmbeddables() {
- embeddableSet.add(new JPAEdmEmbeddable<String>());
- return embeddableSet;
- }
-
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEmbeddable<String> extends JPAEmbeddableMock<String> {
-
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) java.lang.String.class;
- }
-
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return PersistentAttributeType.BASIC;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return false;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationPropertyTest.java
deleted file mode 100644
index 8912bf8..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationPropertyTest.java
+++ /dev/null
@@ -1,218 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Type;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAPluralAttributeMock;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmNavigationPropertyTest extends JPAEdmTestModelView {
-
- private static JPAEdmNavigationProperty objNavigationProperty;
- private static JPAEdmNavigationPropertyTest navPropView;
-
- @BeforeClass
- public static void setup() {
- JPAEdmNavigationPropertyTest localView = new JPAEdmNavigationPropertyTest();
- navPropView = new JPAEdmNavigationPropertyTest();
- objNavigationProperty = new JPAEdmNavigationProperty(localView,
- localView, 1);
- try {
- objNavigationProperty.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public EntityType<?> getJPAEntityType() {
- return new JPAEdmEntityType();
- }
-
- private Attribute<?, ?> getJPAAttributeLocal() {
- AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
- return attr;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return getJPAAttributeLocal();
- }
-
- @Override
- public Association getEdmAssociation() {
-
- Association association = new Association();
- association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
- association.setEnd1(new AssociationEnd().setType(
- new FullQualifiedName("salesorderprocessing", "String"))
- .setRole("SalesOrderHeader"));
- association.setEnd2(new AssociationEnd()
- .setType(
- new FullQualifiedName("salesorderprocessing",
- "SalesOrderItem")).setRole("SalesOrderItem"));
- return association;
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objNavigationProperty.getBuilder());
-
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objNavigationProperty.getBuilder();
- JPAEdmBuilder builder2 = objNavigationProperty.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetEdmNavigationProperty() {
- if (objNavigationProperty == null || objNavigationProperty.getEdmNavigationProperty() == null) {
- JPAEdmNavigationPropertyTest localView = new JPAEdmNavigationPropertyTest();
- navPropView = new JPAEdmNavigationPropertyTest();
- objNavigationProperty = new JPAEdmNavigationProperty(localView,
- localView, 1);
- try {
- objNavigationProperty.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
- assertEquals(
- objNavigationProperty.getEdmNavigationProperty().getName(),
- "StringDetails");
- }
-
- @Test
- public void testGetConsistentEdmNavigationProperties() {
- assertTrue(objNavigationProperty.getConsistentEdmNavigationProperties()
- .size() > 0);
- }
-
- @Test
- public void testAddJPAEdmNavigationPropertyView() {
- JPAEdmNavigationPropertyTest localView = new JPAEdmNavigationPropertyTest();
- navPropView = new JPAEdmNavigationPropertyTest();
- objNavigationProperty = new JPAEdmNavigationProperty(localView,
- localView, 1);
- try {
- objNavigationProperty.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- objNavigationProperty.addJPAEdmNavigationPropertyView(navPropView);
- assertTrue(objNavigationProperty.getConsistentEdmNavigationProperties()
- .size() > 1);
- }
-
- @Override
- public boolean isConsistent() {
- return true;
- }
-
- @Test
- public void testBuildNavigationProperty() {
-
- try {
- objNavigationProperty.getBuilder().build();
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals(objNavigationProperty.getEdmNavigationProperty()
- .getFromRole(), "SalesOrderItem");
- assertEquals(objNavigationProperty.getEdmNavigationProperty()
- .getToRole(), "SalesOrderHeader");
-
- }
-
- @SuppressWarnings("hiding")
- private class AttributeMock<Object, String> extends
- JPAPluralAttributeMock {
-
- @Override
- public boolean isCollection() {
- return true;
- }
-
- @Override
- public Type<java.lang.String> getElementType() {
- return new ElementType();
- }
- }
-
- private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
- @Override
- public String getName() {
- return "SalesOrderHeader";
- }
- }
-
- private class ElementType implements Type<String> {
-
- @Override
- public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
- return PersistenceType.BASIC;
- }
-
- @Override
- public Class<String> getJavaType() {
- return String.class;
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
deleted file mode 100644
index a0bcbce..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
+++ /dev/null
@@ -1,438 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.Attribute.PersistentAttributeType;
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Metamodel;
-import javax.persistence.metamodel.Type;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.ComplexType;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.SimpleType;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEmbeddableTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAPluralAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPASingularAttributeMock;
-import org.junit.Test;
-
-public class JPAEdmPropertyTest extends JPAEdmTestModelView {
-
- private JPAEdmPropertyTest objJPAEdmPropertyTest;
- private JPAEdmProperty objJPAEdmProperty;
-
- private static PersistentAttributeType ATTRIBUTE_TYPE = PersistentAttributeType.BASIC;
-
- public void setUp() {
- ATTRIBUTE_TYPE = PersistentAttributeType.BASIC;
- objJPAEdmPropertyTest = new JPAEdmPropertyTest();
- objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest);
- try {
- objJPAEdmProperty.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testGetBuilder() {
- setUp();
- assertNotNull(objJPAEdmProperty.getBuilder());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- setUp();
- JPAEdmBuilder builder1 = objJPAEdmProperty.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmProperty.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetPropertyList() {
- setUp();
- assertNotNull(objJPAEdmProperty.getEdmPropertyList());
- assertTrue(objJPAEdmProperty.getEdmPropertyList().size() > 0);
- }
-
- @Test
- public void testGetJPAEdmKeyView() {
- setUp();
- assertNotNull(objJPAEdmProperty.getJPAEdmKeyView());
- }
-
- @Test
- public void testGetSimpleProperty() {
- setUp();
- assertNotNull(objJPAEdmProperty.getEdmSimpleProperty());
- }
-
- @Test
- public void testGetJPAAttribute() {
- setUp();
- assertNotNull(objJPAEdmProperty.getJPAAttribute());
- }
-
- @Test
- public void testGetEdmComplexProperty() {
-
- // builder for complex type
- ATTRIBUTE_TYPE = PersistentAttributeType.EMBEDDED;
- objJPAEdmPropertyTest = new JPAEdmPropertyTest();
- objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest, objJPAEdmPropertyTest);
- try {
- objJPAEdmProperty.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertNotNull(objJPAEdmProperty.getEdmComplexProperty());
- }
-
- @Test
- public void testGetJPAEdmNavigationPropertyView() {
- setUp();
- assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView());
- }
-
- @Test
- public void testIsConsistent() {
- setUp();
- assertNotNull(objJPAEdmProperty.isConsistent());
- }
-
- @Test
- public void testClean() {
- setUp();
- objJPAEdmProperty.clean();
- assertFalse(objJPAEdmProperty.isConsistent());
- }
-
- @Test
- public void testBuildManyToOne() {
- ATTRIBUTE_TYPE = PersistentAttributeType.MANY_TO_ONE;
- objJPAEdmPropertyTest = new JPAEdmPropertyTest();
- objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest);
- try {
- objJPAEdmProperty.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView().getEdmNavigationProperty());
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAEdmMetaModel();
- }
-
- @Override
- public boolean isReferencedInKey(final String complexType) {
- return false;
- }
-
- @Override
- public Schema getEdmSchema() {
- Schema schema = new Schema();
- schema.setNamespace(getpUnitName());
- return schema;
- }
-
- @Override
- public org.apache.olingo.odata2.api.edm.provider.ComplexType searchEdmComplexType(final String arg0) {
- org.apache.olingo.odata2.api.edm.provider.ComplexType complexType =
- new org.apache.olingo.odata2.api.edm.provider.ComplexType();
- complexType.setName("ComplexTypeA");
- return complexType;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public EntityType<?> getJPAEntityType() {
- return new JPAEdmEntityType<String>();
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public org.apache.olingo.odata2.api.edm.provider.EntityType getEdmEntityType() {
- org.apache.olingo.odata2.api.edm.provider.EntityType entityType =
- new org.apache.olingo.odata2.api.edm.provider.EntityType();
- entityType.setName("SalesOrderHeader");
-
- return entityType;
- }
-
- @Override
- public Association getEdmAssociation() {
- Association association = new Association();
- association
- .setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader")));
- association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")));
-
- return association;
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @Override
- public JPAEdmAssociationView getJPAEdmAssociationView() {
- return this;
- }
-
- @Override
- public EmbeddableType<?> getJPAEmbeddableType() {
- return new JPAEdmEmbeddable<java.lang.String>();
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return this;
- }
-
- private class JPAEdmMetaModel extends JPAMetaModelMock {
- Set<EntityType<?>> entities;
- Set<EmbeddableType<?>> embeddableSet;
-
- public JPAEdmMetaModel() {
- entities = new HashSet<EntityType<?>>();
- embeddableSet = new HashSet<EmbeddableType<?>>();
- }
-
- @Override
- public Set<EntityType<?>> getEntities() {
- entities.add(new JPAEdmEntityType());
- return entities;
- }
-
- @Override
- public Set<EmbeddableType<?>> getEmbeddables() {
- embeddableSet.add(new JPAEdmEmbeddable<String>());
- return embeddableSet;
- }
-
- private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
- @Override
- public String getName() {
- return "SalesOrderHeader";
- }
- }
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- if (JPAEdmPropertyTest.ATTRIBUTE_TYPE.equals(PersistentAttributeType.BASIC)) {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- } else if (JPAEdmPropertyTest.ATTRIBUTE_TYPE.equals(PersistentAttributeType.EMBEDDED)) {
- attributeSet.add(new JPAEdmAttribute(JPAEdmEmbeddable.class, ComplexType.ComplexTypeA.clazz.getName()));
- } else if (JPAEdmPropertyTest.ATTRIBUTE_TYPE.equals(PersistentAttributeType.MANY_TO_ONE)) {
- attributeSet.add(new JPAEdmPluralAttribute());
- }
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- private class JPAEdmPluralAttribute extends JPAPluralAttributeMock {
- @Override
- public java.lang.String getName() {
- return "salesorderheaderdetails";
- }
-
- @Override
- public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
- return ATTRIBUTE_TYPE;
- }
-
- @Override
- public boolean isCollection() {
- return true;
- }
-
- @Override
- public Type<java.lang.String> getElementType() {
- return new Type<java.lang.String>() {
-
- @Override
- public Class<java.lang.String> getJavaType() {
- return java.lang.String.class;
- }
-
- @Override
- public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
- return null;
- }
-
- };
- }
- }
-
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return ATTRIBUTE_TYPE;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return true;
- }
- }
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEmbeddable<String> extends JPAEmbeddableTypeMock<String> {
-
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- Class<?> clazz = null;
- if (ATTRIBUTE_TYPE.equals(PersistentAttributeType.BASIC)) {
- clazz = (Class<java.lang.String>) SimpleType.SimpleTypeA.clazz;
- } else {
- clazz = (Class<?>) ComplexType.ComplexTypeA.clazz;
- }
- return (Class<String>) clazz;
- }
-
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return ATTRIBUTE_TYPE;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return true;
- }
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRoleTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRoleTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRoleTest.java
deleted file mode 100644
index 6c8c5eb..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRoleTest.java
+++ /dev/null
@@ -1,233 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.JoinColumn;
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.ManagedType;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView.RoleType;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAJavaMemberMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAManagedTypeMock;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmReferentialConstraintRoleTest extends JPAEdmTestModelView {
-
- private static JPAEdmReferentialConstraintRole objJPAEdmReferentialConstraintRole = null;
- private static JPAEdmReferentialConstraintRoleTest objJPAEdmReferentialConstraintRoleTest = null;
-
- @Before
- public void setUp() {
- objJPAEdmReferentialConstraintRoleTest = new JPAEdmReferentialConstraintRoleTest();
-
- objJPAEdmReferentialConstraintRole =
- new JPAEdmReferentialConstraintRole(RoleType.PRINCIPAL, objJPAEdmReferentialConstraintRoleTest,
- objJPAEdmReferentialConstraintRoleTest, objJPAEdmReferentialConstraintRoleTest);
-
- try {
- objJPAEdmReferentialConstraintRole.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testIsExists() {
- assertTrue(objJPAEdmReferentialConstraintRole.isExists());// Default
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmReferentialConstraintRole.getBuilder());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmReferentialConstraintRole.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmReferentialConstraintRole.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetRoleTypePrincipal() {
- assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.PRINCIPAL);
- }
-
- @Test
- public void testGetRoleTypeDependent() {
- objJPAEdmReferentialConstraintRoleTest = new JPAEdmReferentialConstraintRoleTest();
- objJPAEdmReferentialConstraintRole =
- new JPAEdmReferentialConstraintRole(RoleType.DEPENDENT, objJPAEdmReferentialConstraintRoleTest,
- objJPAEdmReferentialConstraintRoleTest, objJPAEdmReferentialConstraintRoleTest);
-
- try {
- objJPAEdmReferentialConstraintRole.getBuilder().build();
- objJPAEdmReferentialConstraintRole.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.DEPENDENT);
- }
-
- @Test
- public void testGetEdmReferentialConstraintRole() {
- try {
- objJPAEdmReferentialConstraintRole.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(objJPAEdmReferentialConstraintRole.getEdmReferentialConstraintRole());
- }
-
- @Test
- public void testGetJPAColumnName() {
- assertNull(objJPAEdmReferentialConstraintRole.getJPAColumnName());
- }
-
- @Test
- public void testGetEdmEntityTypeName() {
- assertNull(objJPAEdmReferentialConstraintRole.getEdmEntityTypeName());
- }
-
- @Test
- public void testGetEdmAssociationName() {
- assertNull(objJPAEdmReferentialConstraintRole.getEdmAssociationName());
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return getJPAAttributeLocal();
- }
-
- @Override
- public Association getEdmAssociation() {
- Association association = new Association();
- association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
- association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
- "SalesOrderHeader"));
- association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
- .setRole("SalesOrderItem"));
- return association;
- }
-
- @Override
- public EntityType searchEdmEntityType(final String arg0) {
-
- EntityType entityType = new EntityType();
-
- JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
- mapping.setJPAColumnName("SOID");
-
- List<Property> propList = new ArrayList<Property>();
-
- Property property = new Property() {};
- property.setMapping((Mapping) mapping);
- property.setName("SOID");
- propList.add(property);
-
- entityType.setProperties(propList);
-
- return entityType;
- }
-
- private Attribute<?, ?> getJPAAttributeLocal() {
- AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
- return attr;
- }
-
- @SuppressWarnings("hiding")
- private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
-
- @Override
- public Member getJavaMember() {
- return new JavaMemberMock();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) java.lang.String.class;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public ManagedType<Object> getDeclaringType() {
- return (ManagedType<Object>) getManagedTypeLocal();
- }
-
- private ManagedType<?> getManagedTypeLocal() {
- ManagedTypeMock<String> managedTypeMock = new ManagedTypeMock<String>();
- return managedTypeMock;
- }
- }
-
- @SuppressWarnings("hiding")
- private class ManagedTypeMock<String> extends JPAManagedTypeMock<String> {
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) java.lang.String.class;
- }
- }
-
- private class JavaMemberMock extends JPAJavaMemberMock {
- @SuppressWarnings("unchecked")
- @Override
- public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
- JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
- EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID");
- EasyMock.expect(joinColumn.name()).andReturn("SOID");
-
- EasyMock.replay(joinColumn);
- return (T) joinColumn;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintTest.java
deleted file mode 100644
index 84b7ad4..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintTest.java
+++ /dev/null
@@ -1,177 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Member;
-
-import javax.persistence.JoinColumn;
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.ManagedType;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAJavaMemberMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAManagedTypeMock;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmReferentialConstraintTest extends JPAEdmTestModelView {
-
- private static JPAEdmReferentialConstraint objJPAEdmReferentialConstraint = null;
- private static JPAEdmReferentialConstraintTest objJPAEdmReferentialConstraintTest = null;
-
- @Before
- public void setUp() {
- objJPAEdmReferentialConstraintTest = new JPAEdmReferentialConstraintTest();
- objJPAEdmReferentialConstraint =
- new JPAEdmReferentialConstraint(objJPAEdmReferentialConstraintTest, objJPAEdmReferentialConstraintTest,
- objJPAEdmReferentialConstraintTest);
- try {
- objJPAEdmReferentialConstraint.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmReferentialConstraint.getBuilder());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmReferentialConstraint.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmReferentialConstraint.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetEdmReferentialConstraint() {
- assertNotNull(objJPAEdmReferentialConstraint.getEdmReferentialConstraint());
- }
-
- @Test
- public void testIsExistsTrue() {
- objJPAEdmReferentialConstraintTest = new JPAEdmReferentialConstraintTest();
- objJPAEdmReferentialConstraint =
- new JPAEdmReferentialConstraint(objJPAEdmReferentialConstraintTest, objJPAEdmReferentialConstraintTest,
- objJPAEdmReferentialConstraintTest);
- try {
- objJPAEdmReferentialConstraint.getBuilder().build();
- objJPAEdmReferentialConstraint.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertTrue(objJPAEdmReferentialConstraint.isExists());
- }
-
- @Test
- public void testGetRelationShipName() {
- assertEquals("Assoc_SalesOrderHeader_SalesOrderItem", objJPAEdmReferentialConstraint.getEdmRelationShipName());
- }
-
- @Override
- public Association getEdmAssociation() {
- Association association = new Association();
- association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
- association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
- "SalesOrderHeader"));
- association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
- .setRole("SalesOrderItem"));
- return association;
- }
-
- private Attribute<?, ?> getJPAAttributeLocal() {
- AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
- return attr;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return getJPAAttributeLocal();
- }
-
- @SuppressWarnings("hiding")
- private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
-
- @Override
- public Member getJavaMember() {
- return new JavaMemberMock();
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) java.lang.String.class;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public ManagedType<Object> getDeclaringType() {
- return (ManagedType<Object>) getManagedTypeLocal();
- }
-
- private ManagedType<?> getManagedTypeLocal() {
- ManagedTypeMock<String> managedTypeMock = new ManagedTypeMock<String>();
- return managedTypeMock;
- }
- }
-
- @SuppressWarnings("hiding")
- private class ManagedTypeMock<String> extends JPAManagedTypeMock<String> {
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) java.lang.String.class;
- }
- }
-
- private class JavaMemberMock extends JPAJavaMemberMock {
- @SuppressWarnings("unchecked")
- @Override
- public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
- JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
- EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID");
- EasyMock.expect(joinColumn.name()).andReturn("SOID");
-
- EasyMock.replay(joinColumn);
- return (T) joinColumn;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchemaTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchemaTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchemaTest.java
deleted file mode 100644
index 9d6848a..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchemaTest.java
+++ /dev/null
@@ -1,103 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmSchemaTest extends JPAEdmTestModelView {
- private JPAEdmSchemaTest objJPAEdmSchemaTest;
- private JPAEdmSchema objJPAEdmSchema;
-
- @Before
- public void setUp() {
- objJPAEdmSchemaTest = new JPAEdmSchemaTest();
- objJPAEdmSchema = new JPAEdmSchema(objJPAEdmSchemaTest);
- // building schema is not required as downstream structure already tested
-
- }
-
- @Test
- public void testClean() {
- assertTrue(objJPAEdmSchema.isConsistent());
- objJPAEdmSchema.clean();
- assertFalse(objJPAEdmSchema.isConsistent());
- }
-
- @Test
- public void testGetEdmSchema() {
- assertNull(objJPAEdmSchema.getEdmSchema());
- }
-
- @Test
- public void testGetJPAEdmEntityContainerView() {
- assertNull(objJPAEdmSchema.getJPAEdmEntityContainerView());
- }
-
- @Test
- public void testGetJPAEdmComplexTypeView() {
- assertNull(objJPAEdmSchema.getJPAEdmComplexTypeView());
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmSchema.getBuilder());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmSchema.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmSchema.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetJPAEdmAssociationView() {
- assertNull(objJPAEdmSchema.getJPAEdmAssociationView());
- }
-
- @Test
- public void testIsConsistent() {
- assertTrue(objJPAEdmSchema.isConsistent());
- objJPAEdmSchema.clean();
- assertFalse(objJPAEdmSchema.isConsistent());
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAMetaModelMock();
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
deleted file mode 100644
index 1b15b75..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
+++ /dev/null
@@ -1,400 +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.odata2.processor.core.jpa.model;
-
-import java.util.HashMap;
-import java.util.List;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationEndView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmBaseView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-
-public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAssociationSetView, JPAEdmAssociationView,
- JPAEdmBaseView, JPAEdmComplexPropertyView, JPAEdmComplexTypeView, JPAEdmEntityContainerView, JPAEdmEntitySetView,
- JPAEdmEntityTypeView, JPAEdmKeyView, JPAEdmModelView, JPAEdmNavigationPropertyView, JPAEdmPropertyView,
- JPAEdmReferentialConstraintView, JPAEdmSchemaView {
-
- protected JPAEdmMappingModelAccess mappingModelAccess;
-
- @Override
- public Schema getEdmSchema() {
- return null;
- }
-
- @Override
- public JPAEdmAssociationView getJPAEdmAssociationView() {
- return null;
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return null;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return null;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return null;
- }
-
- @Override
- public JPAEdmKeyView getJPAEdmKeyView() {
- return null;
- }
-
- @Override
- public List<Property> getEdmPropertyList() {
- return null;
- }
-
- @Override
- public SimpleProperty getEdmSimpleProperty() {
- return null;
- }
-
- @Override
- public JPAEdmSchemaView getEdmSchemaView() {
- return null;
- }
-
- @Override
- public Key getEdmKey() {
- return null;
- }
-
- @Override
- public List<EntityType> getConsistentEdmEntityTypes() {
- return null;
- }
-
- @Override
- public EntityType getEdmEntityType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.EntityType<?> getJPAEntityType() {
- return null;
- }
-
- @Override
- public List<EntitySet> getConsistentEdmEntitySetList() {
- return null;
- }
-
- @Override
- public EntitySet getEdmEntitySet() {
- return null;
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return null;
- }
-
- @Override
- public List<EntityContainer> getConsistentEdmEntityContainerList() {
- return null;
- }
-
- @Override
- public JPAEdmAssociationSetView getEdmAssociationSetView() {
- return null;
- }
-
- @Override
- public EntityContainer getEdmEntityContainer() {
- return null;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return null;
- }
-
- @Override
- public void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView arg0) {
-
- }
-
- @Override
- public List<ComplexType> getConsistentEdmComplexTypes() {
- return null;
- }
-
- @Override
- public ComplexType getEdmComplexType() {
- return null;
- }
-
- @Override
- public EmbeddableType<?> getJPAEmbeddableType() {
- return null;
- }
-
- @Override
- public ComplexType searchEdmComplexType(final String arg0) {
- return null;
- }
-
- @Override
- public ComplexType searchEdmComplexType(final FullQualifiedName arg0) {
- return null;
- }
-
- @Override
- public ComplexProperty getEdmComplexProperty() {
- return null;
- }
-
- @Override
- public void clean() {
-
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- return null;
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return null;
- }
-
- @Override
- public String getpUnitName() {
- return null;
- }
-
- @Override
- public boolean isConsistent() {
- return false;
- }
-
- @Override
- public void addJPAEdmRefConstraintView(final JPAEdmReferentialConstraintView arg0) {
-
- }
-
- @Override
- public ReferentialConstraint getEdmReferentialConstraint() {
- return null;
- }
-
- @Override
- public String getEdmRelationShipName() {
- return null;
- }
-
- @Override
- public boolean isExists() {
- return false;
- }
-
- @Override
- public EntityType searchEdmEntityType(final String arg0) {
- return null;
- }
-
- @Override
- public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
- return null;
- }
-
- @Override
- public List<Association> getConsistentEdmAssociationList() {
- return null;
- }
-
- @Override
- public Association searchAssociation(final JPAEdmAssociationEndView arg0) {
- return null;
- }
-
- @Override
- public List<AssociationSet> getConsistentEdmAssociationSetList() {
- return null;
- }
-
- @Override
- public Association getEdmAssociation() {
- return null;
- }
-
- @Override
- public AssociationSet getEdmAssociationSet() {
- return null;
- }
-
- @Override
- public boolean compare(final AssociationEnd arg0, final AssociationEnd arg1) {
- return false;
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd1() {
- return null;
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd2() {
- return null;
- }
-
- @Override
- public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() {
- return null;
- }
-
- @Override
- public void addJPAEdmNavigationPropertyView(final JPAEdmNavigationPropertyView view) {
-
- }
-
- @Override
- public List<NavigationProperty> getConsistentEdmNavigationProperties() {
- return null;
- }
-
- @Override
- public NavigationProperty getEdmNavigationProperty() {
- return null;
- }
-
- @Override
- public void expandEdmComplexType(final ComplexType complexType, final List<Property> expandedPropertyList,
- final String embeddablePropertyName) {
-
- }
-
- @Override
- public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
- return null;
- }
-
- @Override
- public void registerOperations(final Class<?> customClass, final String[] methodNames) {
- // Do nothing
- }
-
- @Override
- public HashMap<Class<?>, String[]> getRegisteredOperations() {
- return null;
- }
-
- @Override
- public JPAEdmExtension getJPAEdmExtension() {
- return null;
- }
-
- @Override
- public void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
- final JPAEdmAssociationEndView associationEndView) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public String getJoinColumnName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getJoinColumnReferenceColumnName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getMappedByName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getOwningPropertyName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean isDefaultNamingSkipped() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isReferencedInKey(String complexTypeName) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public void setReferencedInKey(String complexTypeName) {
- // TODO Auto-generated method stub
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportTest.java
deleted file mode 100644
index d596e77..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportTest.java
+++ /dev/null
@@ -1,570 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.ReturnType;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model._JPACustomProcessorMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model._JPACustomProcessorNegativeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-@Deprecated
-public class _JPAEdmFunctionImportTest extends JPAEdmTestModelView {
- private static final int METHOD_COUNT = 6;
- private static int VARIANT = 0;
- private JPAEdmFunctionImport jpaEdmfunctionImport;
-
- @Before
- public void setup() {
- jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
- }
-
- /**
- * Test Case - Function Import Basic test - Positive Case
- */
- @Test
- public void testFunctionImportBasic() {
- VARIANT = 0;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
- for (FunctionImport functionImport : functionImportList) {
- assertEquals(functionImport.getName(), "Method1");
- assertNotNull(functionImport.getMapping());
- Mapping mapping = new Mapping();
- mapping.setInternalName("method1");
-
- assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
-
- List<FunctionImportParameter> funcImpList = functionImport.getParameters();
- assertEquals(2, funcImpList.size());
- assertEquals("Param1", funcImpList.get(0).getName());
- assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType());
- assertEquals(Mode.IN.toString(), funcImpList.get(0).getMode());
-
- assertEquals("Param3", funcImpList.get(1).getName());
- assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType());
- assertEquals(Mode.IN.toString(), funcImpList.get(1).getMode());
-
- }
-
- }
-
- /**
- * Test Case - Enable a method that does not exists
- */
- @Test
- public void testFunctionImportNoSuchMethod() {
- VARIANT = 1;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- /**
- * Test Case - Enable all annotated methods in a class as function imports
- */
- @Test
- public void testFunctionImportAllMethods() {
- VARIANT = 2;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(METHOD_COUNT, functionImportList.size());
-
- }
-
- /**
- * Test Case - Function Import with no names. Default name is Java method
- * name.
- */
- @Test
- public void testFunctionImportNoName() {
- VARIANT = 3;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method3");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString());
- }
-
- /**
- * Test Case - Function Import with No return type defined - Negative case
- */
- @Test
- public void testNoReturnType() {
- VARIANT = 4;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- /**
- * Test Case - Function Import with return type as Entity and Multiplicity
- * as Many but no Entity set defined. --> Negative Case
- */
- @Test
- public void testNoEntitySet() {
- VARIANT = 5;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
- }
-
- /**
- * Test Case - Function Import with return type as Entity Type but method
- * has returns void. --> Negative Case
- */
- @Test
- public void testNoReturnTypeButAnnotated() {
- VARIANT = 6;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
- }
-
- /**
- * Test Case - Function Import that returns an Entity Type with Multiplicity
- * as ONE. -->Positive Case
- */
- @Test
- public void testFunctionImportEntityTypeSingleReturn() {
- VARIANT = 7;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method7");
- assertNotNull(functionImport.getMapping());
- JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping();
- assertEquals(_JPACustomProcessorMock.class, mapping.getJPAType());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + _JPACustomProcessorMock.edmName);
- }
-
- /**
- * Test Case - Function Import that returns an Entity Type that is not found
- * in JPA Model
- */
- @Test
- public void testFunctionImportEntityTypeInvalid() {
- VARIANT = 8;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that returns a complex Type
- */
- @Test
- public void testFunctionImportComplexType() {
- VARIANT = 9;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method9");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + _JPACustomProcessorMock.edmName);
-
- }
-
- /**
- * Test Case - Function Import that returns a complex Type with multiplicity
- * Many
- */
- @Test
- public void testFunctionImportComplexTypeMany() {
- VARIANT = 10;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method10");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + _JPACustomProcessorMock.edmName);
-
- }
-
- /**
- * Test Case - Function Import that returns an Complex Type that is not
- * found in JPA Model
- */
- @Test
- public void testFunctionImportComplexTypeInvalid() {
- VARIANT = 11;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that returns an scalar Type that is not valid
- */
- @Test
- public void testFunctionImportScalarTypeInvalid() {
- VARIANT = 12;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that takes a parameter with no name
- */
- @Test
- public void testFunctionImportParamNoName() {
- VARIANT = 13;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import test for facets
- */
- @Test
- public void testFunctionImportParamFacets() {
- VARIANT = 14;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
- EdmFacets facets = funcImpParamList.get(0).getFacets();
- assertNotNull(facets);
- assertEquals(2, facets.getMaxLength().intValue());
- assertEquals(true, facets.isNullable());
-
- facets = funcImpParamList.get(1).getFacets();
- assertNotNull(facets);
- assertEquals(false, facets.isNullable());
- assertEquals(10, facets.getPrecision().intValue());
- assertEquals(2, facets.getScale().intValue());
-
- }
-
- /**
- * Test Case - Function Import test for default facets
- */
- @Test
- public void testFunctionImportParamFacetsDefault() {
- VARIANT = 15;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
- EdmFacets facets = funcImpParamList.get(0).getFacets();
- assertNotNull(facets);
- assertNull(facets.getMaxLength());
- assertEquals(false, facets.isNullable());
- assertNull(facets.getPrecision());
- assertNull(facets.getScale());
-
- }
-
- /**
- * Test Case - Function Import test for ReturnType.SCALAR but method returns
- * void
- */
- @Test
- public void testWrongReturnTypeScalar() {
- VARIANT = 16;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import test for ReturnType.COMPLEX but method returns
- * void
- */
- @Test
- public void testWrongReturnTypeComplex() {
- VARIANT = 17;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- @Test
- public void testNoFunctionImport() {
- VARIANT = 99;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
-
- JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder();
- JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public HashMap<Class<?>, String[]> getRegisteredOperations() {
-
- HashMap<Class<?>, String[]> customOperations = new HashMap<Class<?>, String[]>();
-
- if (VARIANT == 0) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
- } else if (VARIANT == 1) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "XYX" });
- } else if (VARIANT == 2) {
- customOperations.put(_JPACustomProcessorMock.class, null);
- } else if (VARIANT == 3) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
- } else if (VARIANT == 4) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method4" });
- } else if (VARIANT == 5) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
- } else if (VARIANT == 6) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
- } else if (VARIANT == 7) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method7" });
- } else if (VARIANT == 8) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
- } else if (VARIANT == 9) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method9" });
- } else if (VARIANT == 10) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method10" });
- } else if (VARIANT == 11) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
- } else if (VARIANT == 12) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
- } else if (VARIANT == 13) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
- } else if (VARIANT == 14) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
- } else if (VARIANT == 15) {
- customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
- } else if (VARIANT == 16) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
- } else if (VARIANT == 17) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
- } else {
- return null;
- }
-
- return customOperations;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return this;
- }
-
- @Override
- public EntityType searchEdmEntityType(final String arg0) {
- if (arg0.equals(_JPACustomProcessorMock.class.getSimpleName())) {
- return new EntityType().setName(_JPACustomProcessorMock.edmName);
- } else {
- return null;
- }
- }
-
- @Override
- public ComplexType searchEdmComplexType(final String arg0) {
- if (arg0.equals(_JPACustomProcessorMock.class.getName())) {
- return new ComplexType().setName(_JPACustomProcessorMock.edmName);
- } else {
- return null;
- }
- }
-
- @Override
- public String getpUnitName() {
- return ODataJPAContextMock.PERSISTENCE_UNIT_NAME;
- }
-
- private void build() {
- try {
- jpaEdmfunctionImport.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/resources/SalesOrderProcessingMappingModels.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/resources/SalesOrderProcessingMappingModels.xml b/odata2-jpa-processor/jpa-core/src/test/resources/SalesOrderProcessingMappingModels.xml
index d81cae9..eeb4c38 100644
--- a/odata2-jpa-processor/jpa-core/src/test/resources/SalesOrderProcessingMappingModels.xml
+++ b/odata2-jpa-processor/jpa-core/src/test/resources/SalesOrderProcessingMappingModels.xml
@@ -18,7 +18,7 @@
under the License.
-->
<JPAEDMMappingModel
- xmlns="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping">
+ xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
<PersistenceUnit name="salesorderprocessing">
<EDMSchemaNamespace>SalesOrderProcessing</EDMSchemaNamespace>
<JPAEntityTypes>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
index 3dacd7e..94aad4f 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
@@ -26,8 +26,8 @@ import org.apache.olingo.odata2.api.edm.provider.ComplexType;
import org.apache.olingo.odata2.api.edm.provider.Property;
import org.apache.olingo.odata2.api.edm.provider.Schema;
import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
public class SalesOrderProcessingExtension implements JPAEdmExtension {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
index fe4e618..63d9c4a 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
@@ -20,12 +20,12 @@ package org.apache.olingo.odata2.jpa.processor.ref.web;
import java.util.ResourceBundle;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
import org.apache.olingo.odata2.jpa.processor.ref.extension.SalesOrderProcessingExtension;
import org.apache.olingo.odata2.jpa.processor.ref.factory.JPAEntityManagerFactory;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
public class JPAReferenceServiceFactory extends ODataJPAServiceFactory {
private static final String PUNIT_NAME = "salesorderprocessing";
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-web/src/main/webapp/SalesOrderProcessingMappingModel.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/webapp/SalesOrderProcessingMappingModel.xml b/odata2-jpa-processor/jpa-web/src/main/webapp/SalesOrderProcessingMappingModel.xml
index 6a0f911..cba7813 100644
--- a/odata2-jpa-processor/jpa-web/src/main/webapp/SalesOrderProcessingMappingModel.xml
+++ b/odata2-jpa-processor/jpa-web/src/main/webapp/SalesOrderProcessingMappingModel.xml
@@ -10,7 +10,7 @@
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<JPAEDMMappingModel
- xmlns="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping">
+ xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
<PersistenceUnit name="salesorderprocessing">
<EDMSchemaNamespace>SalesOrderProcessing</EDMSchemaNamespace>
<JPAEntityTypes>
[16/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTestForStaticMethods.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTestForStaticMethods.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTestForStaticMethods.java
deleted file mode 100644
index 86514b4..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTestForStaticMethods.java
+++ /dev/null
@@ -1,251 +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.odata2.processor.core.jpa.access.data;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Method;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.junit.Test;
-
-public class JPAEntityParserTestForStaticMethods {
-
- @Test
- public void testToStringDefault() {
-
- Character[] input = new Character[] { 'A', 'B' };
- assertEquals("AB", JPAEntityParser.toString(input));
-
- }
-
- @Test
- public void testToStringNull() {
- Character[] input = null;
- assertNull(JPAEntityParser.toString(input));
- }
-
- @Test
- public void testToStringPartialNull() {
- Character[] input = new Character[] { 'A', null };
- assertEquals("A", JPAEntityParser.toString(input));
- }
-
- @Test
- public void testToCharacterArrayDefault() {
- String input = new String("AB");
- Character[] ch = JPAEntityParser.toCharacterArray(input);
-
- assertEquals(2, ch.length);
- assertTrue(ch[0].equals('A'));
- assertTrue(ch[1].equals('B'));
- }
-
- @Test
- public void testToCharacterArrayNull() {
- String input = null;
- Character[] ch = JPAEntityParser.toCharacterArray(input);
-
- assertNull(ch);
- }
-
- @Test
- public void testGetPropertyCharacter() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacter", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertEquals("A", output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharacterNull() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertNull(output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharacterArray() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterArray", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertEquals("AB", output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharacterArrayNull() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterArrayNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertNull(output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyChar() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getChar", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertEquals("A", output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharNull() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertNull(output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharArray() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArray", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertEquals("AB", output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharArrayNull() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArrayNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertNull(output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetPropertyCharArrayValueNull() {
- try {
- Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArrayValueNull", (Class<?>[]) null);
- String output = (String) JPAEntityParser.getProperty(method, this);
- assertEquals("A\u0000", output);
-
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- public Character getCharacter() {
- return new Character('A');
- }
-
- public Character getCharacterNull() {
- return null;
- }
-
- public Character[] getCharacterArray() {
- return new Character[] { 'A', 'B' };
- }
-
- public Character[] getCharacterArrayNull() {
- return null;
- }
-
- public char getChar() {
- return 'A';
- }
-
- public char getCharNull() {
- return '\u0000';
- }
-
- public char[] getCharArray() {
- return new char[] { 'A', 'B' };
- }
-
- public char[] getCharArrayNull() {
- return null;
- }
-
- public char[] getCharArrayValueNull() {
- return new char[] { 'A', '\u0000' };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityTest.java
deleted file mode 100644
index 8fbbed9..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityTest.java
+++ /dev/null
@@ -1,187 +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.odata2.processor.core.jpa.access.data;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.EdmMockUtilV2;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPARelatedTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPATypeEmbeddableMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPATypeEmbeddableMock2;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.ODataEntryMockUtil;
-import org.junit.Test;
-
-public class JPAEntityTest {
-
- private JPAEntity jpaEntity = null;
-
- @Test
- public void testCreateODataEntryWithComplexType() {
- try {
- EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, true);
- EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-
- jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
- jpaEntity.create(ODataEntryMockUtil.mockODataEntryWithComplexType(JPATypeMock.ENTITY_NAME));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
- assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
- assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
- assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
- JPATypeEmbeddableMock jpaEmbeddableMock = jpaTypeMock.getComplexType();
- assertNotNull(jpaEmbeddableMock);
-
- assertEquals(jpaEmbeddableMock.getMShort(), ODataEntryMockUtil.VALUE_SHORT);
- JPATypeEmbeddableMock2 jpaEmbeddableMock2 = jpaEmbeddableMock.getMEmbeddable();
- assertNotNull(jpaEmbeddableMock2);
- assertEquals(jpaEmbeddableMock2.getMFloat(), ODataEntryMockUtil.VALUE_MFLOAT, 1);
- assertEquals(jpaEmbeddableMock2.getMUUID(), ODataEntryMockUtil.VALUE_UUID);
- }
-
- @Test
- public void testCreateODataEntry() {
- try {
- EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
- EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-
- jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
- jpaEntity.create(ODataEntryMockUtil.mockODataEntry(JPATypeMock.ENTITY_NAME));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
- assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
- assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
- assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
- }
-
- @Test
- public void testCreateODataEntryWithInline() {
- try {
- EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
- EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-
- jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
- jpaEntity.create(ODataEntryMockUtil.mockODataEntryWithInline(JPATypeMock.ENTITY_NAME));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
- assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
- assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
- assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
-
- JPARelatedTypeMock relatedType = jpaTypeMock.getMRelatedEntity();
- assertNotNull(jpaTypeMock.getMRelatedEntity());
- assertEquals(relatedType.getMByte(), ODataEntryMockUtil.VALUE_MBYTE);
- assertEquals(relatedType.getMByteArray(), ODataEntryMockUtil.VALUE_MBYTEARRAY);
- assertEquals(relatedType.getMDouble(), ODataEntryMockUtil.VALUE_MDOUBLE, 0.0);
- assertEquals(relatedType.getMLong(), ODataEntryMockUtil.VALUE_MLONG);
- }
-
- @Test
- public void testCreateODataEntryProperty() {
- try {
- EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
- EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-
- jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
- jpaEntity.create(ODataEntryMockUtil.mockODataEntryProperties(JPATypeMock.ENTITY_NAME));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
- assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
- assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
- assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
- }
-
- @Test
- public void testUpdateODataEntry() {
- try {
- EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
- EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-
- jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
- JPATypeMock jpaTypeMock = new JPATypeMock();
- jpaEntity.setJPAEntity(jpaTypeMock);
- jpaEntity.update(ODataEntryMockUtil.mockODataEntry(JPATypeMock.ENTITY_NAME));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
- assertEquals(jpaTypeMock.getMInt(), 0);// Key should not be changed
- assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
- assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
- }
-
- @Test
- public void testUpdateODataEntryProperty() {
- try {
- EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
- EdmEntityType edmEntityType = edmEntitySet.getEntityType();
-
- jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
- JPATypeMock jpaTypeMock = new JPATypeMock();
- jpaEntity.setJPAEntity(jpaTypeMock);
- jpaEntity.update(ODataEntryMockUtil.mockODataEntryProperties(JPATypeMock.ENTITY_NAME));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
- assertEquals(jpaTypeMock.getMInt(), 0);// Key should not be changed
- assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
- assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java
deleted file mode 100644
index 021c353..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBackTest.java
+++ /dev/null
@@ -1,160 +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.odata2.processor.core.jpa.access.data;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.EdmMockUtil;
-import org.junit.Test;
-
-public class JPAExpandCallBackTest {
-
- @Test
- public void testRetrieveEntryResult() {
- JPAExpandCallBack callBack = getJPAExpandCallBackObject();
- WriteEntryCallbackContext writeFeedContext = EdmMockUtil.getWriteEntryCallBackContext();
- try {
- Field field = callBack.getClass().getDeclaredField("nextEntitySet");
- field.setAccessible(true);
- field.set(callBack, EdmMockUtil.mockTargetEntitySet());
- WriteEntryCallbackResult result = callBack.retrieveEntryResult(writeFeedContext);
- assertEquals(1, result.getEntryData().size());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testRetrieveFeedResult() {
- JPAExpandCallBack callBack = getJPAExpandCallBackObject();
- WriteFeedCallbackContext writeFeedContext = EdmMockUtil.getWriteFeedCallBackContext();
- try {
- Field field = callBack.getClass().getDeclaredField("nextEntitySet");
- field.setAccessible(true);
- field.set(callBack, EdmMockUtil.mockTargetEntitySet());
- WriteFeedCallbackResult result = callBack.retrieveFeedResult(writeFeedContext);
- assertEquals(2, result.getFeedData().size());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetCallbacks() {
- Map<String, ODataCallback> callBacks = null;
- try {
- URI baseUri =
- new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/");
- ExpandSelectTreeNode expandSelectTreeNode = EdmMockUtil.mockExpandSelectTreeNode();
- List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList();
- callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList);
- } catch (URISyntaxException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals(1, callBacks.size());
-
- }
-
- @Test
- public void testGetNextNavigationProperty() {
- JPAExpandCallBack callBack = getJPAExpandCallBackObject();
- List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList();
- ArrayList<NavigationPropertySegment> expands = expandList.get(0);
- expands.add(EdmMockUtil.mockThirdNavigationPropertySegment());
- EdmNavigationProperty result = null;
- try {
- Field field = callBack.getClass().getDeclaredField("expandList");
- field.setAccessible(true);
- field.set(callBack, expandList);
- Class<?>[] formalParams = { EdmEntityType.class, EdmNavigationProperty.class };
- Object[] actualParams = { EdmMockUtil.mockSourceEdmEntityType(), EdmMockUtil.mockNavigationProperty() };
- Method method = callBack.getClass().getDeclaredMethod("getNextNavigationProperty", formalParams);
- method.setAccessible(true);
- result = (EdmNavigationProperty) method.invoke(callBack, actualParams);
- assertEquals("MaterialDetails", result.getName());
-
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- private JPAExpandCallBack getJPAExpandCallBackObject() {
- Map<String, ODataCallback> callBacks = null;
- try {
- URI baseUri =
- new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/");
- ExpandSelectTreeNode expandSelectTreeNode = EdmMockUtil.mockExpandSelectTreeNode();
- List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList();
- callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList);
- } catch (URISyntaxException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return (JPAExpandCallBack) callBacks.get("SalesOrderLineItemDetails");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java
deleted file mode 100644
index 1b2d7b6..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContextTest.java
+++ /dev/null
@@ -1,143 +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.odata2.processor.core.jpa.access.data;
-
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-
-import junit.framework.Assert;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmLiteral;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmMappingImpl;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPAFunctionContextTest {
-
- private int VARIANT = 0;
-
- public JPAFunctionContext build() {
- JPAFunctionContext functionContext = null;
- try {
- if (VARIANT == 0) {
- functionContext =
- (JPAFunctionContext) JPAMethodContext.createBuilder(JPQLContextType.FUNCTION, getView()).build();
- }
-
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- return functionContext;
- }
-
- @Test
- public void testGetEnclosingObject() {
-
- VARIANT = 0;
-
- Assert.assertNotNull(build());
-
- }
-
- private GetFunctionImportUriInfo getView() {
- GetFunctionImportUriInfo functiontView = EasyMock.createMock(GetFunctionImportUriInfo.class);
- EasyMock.expect(functiontView.getFunctionImport()).andStubReturn(getEdmFunctionImport());
- EasyMock.expect(functiontView.getFunctionImportParameters()).andStubReturn(getFunctionImportParameters());
-
- EasyMock.replay(functiontView);
- return functiontView;
- }
-
- private Map<String, EdmLiteral> getFunctionImportParameters() {
- return null;
- }
-
- private EdmFunctionImport getEdmFunctionImport() {
- EdmFunctionImport edmFunctionImport = EasyMock.createMock(EdmFunctionImport.class);
- try {
- EasyMock.expect(edmFunctionImport.getMapping()).andStubReturn(getMapping());
- EasyMock.expect(edmFunctionImport.getParameterNames()).andStubReturn(getParameterNames());
- EasyMock.expect(edmFunctionImport.getParameter("Gentleman")).andStubReturn(getParameter("Gentleman"));
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- EasyMock.replay(edmFunctionImport);
- return edmFunctionImport;
- }
-
- private EdmParameter getParameter(final String string) {
- EdmParameter edmParameter = EasyMock.createMock(EdmParameter.class);
- try {
- EasyMock.expect(edmParameter.getMapping()).andStubReturn(getEdmMapping());
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(edmParameter);
- return edmParameter;
- }
-
- private EdmMapping getEdmMapping() {
- JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(String.class);
- ((Mapping) mapping).setInternalName("Gentleman");
- return mapping;
- }
-
- private JPAEdmMappingImpl getMapping() {
- JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(FunctionImportTestClass.class);
- ((Mapping) mapping).setInternalName("testMethod");
- return mapping;
- }
-
- private Collection<String> getParameterNames() {
- Collection<String> parametersList = new ArrayList<String>();
- parametersList.add("Gentleman");
- return parametersList;
- }
-
- public static class FunctionImportTestClass {
-
- public FunctionImportTestClass() {
-
- }
-
- public String testMethod(final String message) {
- return "Hello " + message + "!!";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java
deleted file mode 100644
index 45f0528..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImplTest.java
+++ /dev/null
@@ -1,447 +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.odata2.processor.core.jpa.access.data;
-
-import static org.junit.Assert.fail;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Query;
-import javax.persistence.metamodel.Metamodel;
-
-import junit.framework.Assert;
-
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAProcessorImplTest {
-
- // -------------------------------- Common Start ------------------------------------common in
- // ODataJPAProcessorDefaultTest as well
- private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
- private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
- private static final String SO_ID = "SoId";
- private static final String SALES_ORDER = "SalesOrder";
- private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
- // -------------------------------- Common End ------------------------------------
-
- JPAProcessorImpl objJPAProcessorImpl;
-
- @Before
- public void setUp() throws Exception {
- objJPAProcessorImpl = new JPAProcessorImpl(getLocalmockODataJPAContext());
- }
-
- @Test
- public void testProcessGetEntitySetCountUriInfo() {
- try {
- Assert.assertEquals(11, objJPAProcessorImpl.process(getEntitySetCountUriInfo()));
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testProcessGetEntityCountUriInfo() {
- try {
- Assert.assertEquals(11, objJPAProcessorImpl.process(getEntityCountUriInfo()));
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testProcessGetEntitySetUriInfo() {
- try {
- Assert.assertNotNull(objJPAProcessorImpl.process(getEntitySetUriInfo()));
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testProcessDeleteUriInfo() {
- try {
- Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
- Assert.assertEquals(new Address(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testProcessDeleteUriInfoNegative() {
- try {
- Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
- Assert.assertNotSame(new Object(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- // ---------------------------- Common Code Start ---------------- TODO - common in ODataJPAProcessorDefaultTest as
- // well
-
- private DeleteUriInfo getDeletetUriInfo() {
- UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
- EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
- EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
- EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
- EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
- EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
- EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
- EasyMock.replay(objUriInfo);
- return objUriInfo;
- }
-
- private List<KeyPredicate> getKeyPredicates() {
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- return keyPredicates;
- }
-
- private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
- return getLocalUriInfo();
- }
-
- private GetEntityCountUriInfo getEntityCountUriInfo() {
- return getLocalUriInfo();
- }
-
- private GetEntitySetUriInfo getEntitySetUriInfo() {
-
- UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
- EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
- EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
- EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
- EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
- EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
- // EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(getFunctionImport());
- EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
- EasyMock.replay(objUriInfo);
- return objUriInfo;
- }
-
- /**
- * @return
- */
- private UriInfo getLocalUriInfo() {
- UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
- EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
- EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
- EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
- EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
- EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
- EasyMock.replay(objUriInfo);
- return objUriInfo;
- }
-
- /**
- * @return
- * @throws EdmException
- */
- private EdmEntitySet getLocalEdmEntitySet() {
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
- EasyMock.replay(edmEntitySet);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return edmEntitySet;
- }
-
- /**
- * @return
- * @throws EdmException
- */
- private EdmEntityType getLocalEdmEntityType() {
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- try {
- EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
- EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
- EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
- EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
- EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
- EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));// ID vs Salesorder
- // ID
- EasyMock.replay(edmEntityType);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return edmEntityType;
- }
-
- private InlineCount getInlineCount() {
- return InlineCount.NONE;
- }
-
- private FilterExpression getFilter() {
- return null;
- }
-
- private Integer getSkip() {
- return null;
- }
-
- private Integer getTop() {
- return null;
- }
-
- private OrderByExpression getOrderByExpression() {
- return null;
- }
-
- private ODataJPAContext getLocalmockODataJPAContext() {
- ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
- EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
- EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
- EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
- EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
- EasyMock.replay(odataJPAContext);
- return odataJPAContext;
- }
-
- private EntityManagerFactory mockEntityManagerFactory() {
- EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
- EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
- EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
- EasyMock.replay(emf);
- return emf;
- }
-
- public EntityManager getLocalEntityManager() {
- EntityManager em = EasyMock.createMock(EntityManager.class);
- EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
- EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(
- getQueryForSelectCount());
- EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); // For Delete
- em.flush();
- em.flush();
- Address obj = new Address();
- em.remove(obj);// testing void method
- em.remove(obj);// testing void method
- EasyMock.replay(em);
- return em;
- }
-
- private EntityTransaction getLocalTransaction() {
- EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
- entityTransaction.begin(); // testing void method
- entityTransaction.begin(); // testing void method
- entityTransaction.commit();// testing void method
- entityTransaction.commit();// testing void method
- EasyMock.replay(entityTransaction);
- return entityTransaction;
- }
-
- private Query getQuery() {
- Query query = EasyMock.createMock(Query.class);
- EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
- EasyMock.replay(query);
- return query;
- }
-
- private Query getQueryForSelectCount() {
- Query query = EasyMock.createMock(Query.class);
- EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
- EasyMock.replay(query);
- return query;
- }
-
- private List<?> getResultList() {
- List<Object> list = new ArrayList<Object>();
- list.add(new Address());
- return list;
- }
-
- private List<?> getResultListForSelectCount() {
- List<Object> list = new ArrayList<Object>();
- list.add(new Long(11));
- return list;
- }
-
- private class Address {
- private String soId = "12";
-
- public String getSoId() {
- return soId;
- }
-
- @Override
- public boolean equals(final Object obj) {
- boolean isEqual = false;
- if (obj instanceof Address) {
- isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
- }
- return isEqual;
- }
- }
-
- private Metamodel mockMetaModel() {
- Metamodel metaModel = EasyMock.createMock(Metamodel.class);
- EasyMock.replay(metaModel);
- return metaModel;
- }
-
- private EdmEntityContainer getLocalEdmEntityContainer() {
- EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
- EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
- try {
- EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- EasyMock.replay(edmEntityContainer);
- return edmEntityContainer;
- }
-
- private EdmTyped getEdmTypedMockedObj(final String propertyName) {
- EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
- try {
- EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmType);
- EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
- EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
-
- EasyMock.replay(mockedEdmProperty);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return mockedEdmProperty;
- }
-
- private EdmFacets getEdmFacetsMockedObj() {
- EdmFacets facets = EasyMock.createMock(EdmFacets.class);
- EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
-
- EasyMock.replay(facets);
- return facets;
- }
-
- private EdmMapping getEdmMappingMockedObj(final String propertyName) {
- EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
- if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
- EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
- } else {
- EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
- }
- EasyMock.replay(mockedEdmMapping);
- return mockedEdmMapping;
- }
-
- private List<String> getLocalPropertyNames() {
- List<String> list = new ArrayList<String>();
- list.add(SO_ID);
- return list;
- }
-
- private ODataContext getLocalODataContext() {
- ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
- try {
- EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(objODataContext);
- return objODataContext;
- }
-
- private PathInfo getLocalPathInfo() {
- PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
- EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
- EasyMock.replay(pathInfo);
- return pathInfo;
- }
-
- private URI getLocalURI() {
- URI uri = null;
- try {
- uri = new URI(STR_LOCAL_URI);
- } catch (URISyntaxException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return uri;
- }
-
- // -------------------------------- Common End ------------------------------------
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java
deleted file mode 100644
index 76ea726..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelServiceTest.java
+++ /dev/null
@@ -1,213 +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.odata2.processor.core.jpa.access.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.InputStream;
-
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmMappingModelServiceTest extends JPAEdmMappingModelService {
-
- private static JPAEdmMappingModelServiceTest objJPAEdmMappingModelServiceTest;
-
- private static final String MAPPING_FILE_CORRECT = "SalesOrderProcessingMappingModels.xml";
- private static final String MAPPING_FILE_INCORRECT = "TEST.xml";
-
- private static int VARIANT_MAPPING_FILE; // 0 FOR INCORRECT, 1 FOR CORRECT
-
- private static String PERSISTENCE_UNIT_NAME_JPA = "salesorderprocessing";
- private static String PERSISTENCE_UNIT_NAME_EDM = "SalesOrderProcessing";
-
- private static String ENTITY_TYPE_NAME_JPA = "SalesOrderHeader";
- private static String ENTITY_TYPE_NAME_EDM = "SalesOrder";
- private static String ENTITY_SET_NAME_EDM = "SalesOrders";
- private static String RELATIONSHIP_NAME_JPA = "salesOrderItems";
- private static String RELATIONSHIP_NAME_EDM = "SalesOrderItemDetails";
- private static String ATTRIBUTE_NAME_JPA = "netAmount";
- private static String ATTRIBUTE_NAME_EDM = "NetAmount";
- private static String EMBEDDABLE_TYPE_NAME_JPA = "SalesOrderItemKey";
- private static String EMBEDDABLE_ATTRIBUTE_NAME_JPA = "liId";
- private static String EMBEDDABLE_ATTRIBUTE_NAME_EDM = "ID";
- private static String EMBEDDABLE_TYPE_2_NAME_JPA = "SalesOrderItemKey";
-
- private static String ENTITY_TYPE_NAME_JPA_WRONG = "SalesOrderHeaders";
- private static String RELATIONSHIP_NAME_JPA_WRONG = "value";
- private static String EMBEDDABLE_TYPE_NAME_JPA_WRONG = "SalesOrderItemKeys";
-
- public JPAEdmMappingModelServiceTest() {
- super(ODataJPAContextMock.mockODataJPAContext());
- }
-
- @BeforeClass
- public static void setup() {
- objJPAEdmMappingModelServiceTest = new JPAEdmMappingModelServiceTest();
- VARIANT_MAPPING_FILE = 1;
- objJPAEdmMappingModelServiceTest.loadMappingModel();
- }
-
- @Test
- public void testLoadMappingModel() {
- VARIANT_MAPPING_FILE = 1;
- loadMappingModel();
- assertTrue(isMappingModelExists());
- }
-
- @Test
- public void testLoadMappingModelNegative() {
- VARIANT_MAPPING_FILE = 0;
- loadMappingModel();
- assertFalse(isMappingModelExists());
- // reset it for other JUnits
- VARIANT_MAPPING_FILE = 1;
- loadMappingModel();
- }
-
- @Test
- public void testIsMappingModelExists() {
- assertTrue(objJPAEdmMappingModelServiceTest.isMappingModelExists());
- }
-
- @Test
- public void testGetJPAEdmMappingModel() {
- assertNotNull(objJPAEdmMappingModelServiceTest.getJPAEdmMappingModel());
- }
-
- @Test
- public void testMapJPAPersistenceUnit() {
- assertEquals(PERSISTENCE_UNIT_NAME_EDM, objJPAEdmMappingModelServiceTest
- .mapJPAPersistenceUnit(PERSISTENCE_UNIT_NAME_JPA));
- }
-
- @Test
- public void testMapJPAPersistenceUnitNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAPersistenceUnit(PERSISTENCE_UNIT_NAME_EDM));// Wrong value to
- // bring null
- }
-
- @Test
- public void testMapJPAEntityType() {
- assertEquals(ENTITY_TYPE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEntityType(ENTITY_TYPE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAEntityTypeNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEntityType(ENTITY_TYPE_NAME_JPA_WRONG));// Wrong value to bring
- // null
- }
-
- @Test
- public void testMapJPAEntitySet() {
- assertEquals(ENTITY_SET_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEntitySet(ENTITY_TYPE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAEntitySetNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEntitySet(ENTITY_TYPE_NAME_JPA_WRONG));// Wrong value to bring
- // null
- }
-
- @Test
- public void testMapJPAAttribute() {
- assertEquals(ATTRIBUTE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAAttribute(ENTITY_TYPE_NAME_JPA,
- ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAAttributeNegative() {
- // Wrong value to bring null
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAAttribute(ENTITY_TYPE_NAME_JPA, ATTRIBUTE_NAME_JPA + "AA"));
- }
-
- @Test
- public void testMapJPARelationship() {
- assertEquals(RELATIONSHIP_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPARelationship(ENTITY_TYPE_NAME_JPA,
- RELATIONSHIP_NAME_JPA));
- }
-
- @Test
- public void testMapJPARelationshipNegative() {
- // Wrong value to bring null
- assertNull(objJPAEdmMappingModelServiceTest.mapJPARelationship(ENTITY_TYPE_NAME_JPA, RELATIONSHIP_NAME_JPA_WRONG));
- }
-
- @Test
- public void testMapJPAEmbeddableType() {
- assertEquals("SalesOrderLineItemKey", objJPAEdmMappingModelServiceTest.mapJPAEmbeddableType("SalesOrderItemKey"));
- }
-
- @Test
- public void testMapJPAEmbeddableTypeNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEmbeddableType(EMBEDDABLE_TYPE_NAME_JPA_WRONG));// Wrong value to
- // bring null
- }
-
- @Test
- public void testMapJPAEmbeddableTypeAttribute() {
- assertEquals(EMBEDDABLE_ATTRIBUTE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEmbeddableTypeAttribute(
- EMBEDDABLE_TYPE_NAME_JPA, EMBEDDABLE_ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testMapJPAEmbeddableTypeAttributeNegative() {
- assertNull(objJPAEdmMappingModelServiceTest.mapJPAEmbeddableTypeAttribute(EMBEDDABLE_TYPE_NAME_JPA_WRONG,
- EMBEDDABLE_ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAEntityType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEntityType(ENTITY_TYPE_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAAttributeType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAAttributeType(ENTITY_TYPE_NAME_JPA,
- ATTRIBUTE_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAEmbeddableType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEmbeddableType(EMBEDDABLE_TYPE_2_NAME_JPA));
- }
-
- @Test
- public void testCheckExclusionOfJPAEmbeddableAttributeType() {
- assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEmbeddableAttributeType(EMBEDDABLE_TYPE_NAME_JPA,
- EMBEDDABLE_ATTRIBUTE_NAME_JPA));
- }
-
- /**
- * This method is for loading the xml file for testing.
- */
- @Override
- protected InputStream loadMappingModelInputStream() {
- if (VARIANT_MAPPING_FILE == 1) {
- return ClassLoader.getSystemResourceAsStream(MAPPING_FILE_CORRECT);
- } else {
- return ClassLoader.getSystemResourceAsStream(MAPPING_FILE_INCORRECT);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java
deleted file mode 100644
index 3808909..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilderTest.java
+++ /dev/null
@@ -1,151 +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.odata2.processor.core.jpa.access.model;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAContextImpl;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPAEdmNameBuilderTest {
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Test
- public void testBuildJPAEdmPropertyView() {
-
- SimpleProperty simpleProperty = new SimpleProperty();
-
- // Mocking EDMProperty
- JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
- JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
-
- EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
- EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
- EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
- EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
- EasyMock.replay(propertyView);
-
- JPAEdmNameBuilder.build(propertyView, false, false);
- assertEquals("Id", simpleProperty.getName());
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Test
- public void testBuildJPAEdmPropertyViewWithNoDefaultNaming() {
-
- SimpleProperty simpleProperty = new SimpleProperty();
-
- // Mocking EDMProperty
- JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
- JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
-
- EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
- EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
- EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
- EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
- EasyMock.replay(propertyView);
-
- JPAEdmNameBuilder.build(propertyView, false, true);
- assertEquals("id", simpleProperty.getName());
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Test
- public void testBuildJPAEdmComplexPropertyView() {
- JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
- ComplexProperty complexProperty = new ComplexProperty();
- EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
- ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
- JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
- EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);
-
- // Mocking EDMProperty
- JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
- JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
- EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JPAEntityType());
- EasyMock.replay(entityTypeView);
- EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
- EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
- EasyMock.replay(complexPropertyView);
- EasyMock.replay(propertyView);
-
- JPAEdmNameBuilder.build(complexPropertyView, propertyView, false);
- assertEquals("Id", complexPropertyView.getEdmComplexProperty().getName());
-
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Test
- public void testBuildJPAEdmComplexPropertyViewWithNoDefaultNaming() {
- JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
- ComplexProperty complexProperty = new ComplexProperty();
- EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
- ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
- JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
- EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);
-
- // Mocking EDMProperty
- JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
- JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
- EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JPAEntityType());
- EasyMock.replay(entityTypeView);
- EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
- EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
- EasyMock.replay(complexPropertyView);
- EasyMock.replay(propertyView);
-
- JPAEdmNameBuilder.build(complexPropertyView, propertyView, true);
- assertEquals("id", complexPropertyView.getEdmComplexProperty().getName());
-
- }
-
- @SuppressWarnings("hiding")
- class JPAAttribute<Object, String> extends JPAAttributeMock<Object, java.lang.String> {
-
- @Override
- public java.lang.String getName() {
- return "id";
- }
-
- @Override
- public Class<java.lang.String> getJavaType() {
- return java.lang.String.class;
- }
-
- }
-
- @SuppressWarnings("hiding")
- class JPAEntityType<Object> extends JPAEntityTypeMock<Object> {
-
- @Override
- public java.lang.String getName() {
- return "SalesOrderHeader";
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java
deleted file mode 100644
index 3a4057f..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertorTest.java
+++ /dev/null
@@ -1,94 +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.odata2.processor.core.jpa.access.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.math.BigDecimal;
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.junit.Test;
-
-public class JPATypeConvertorTest {
-
- private EdmSimpleTypeKind edmSimpleKindTypeString;
- private EdmSimpleTypeKind edmSimpleKindTypeByteArr;
- private EdmSimpleTypeKind edmSimpleKindTypeLong;
- private EdmSimpleTypeKind edmSimpleKindTypeShort;
- private EdmSimpleTypeKind edmSimpleKindTypeInteger;
- private EdmSimpleTypeKind edmSimpleKindTypeDouble;
- private EdmSimpleTypeKind edmSimpleKindTypeFloat;
- private EdmSimpleTypeKind edmSimpleKindTypeBigDecimal;
- private EdmSimpleTypeKind edmSimpleKindTypeByte;
- private EdmSimpleTypeKind edmSimpleKindTypeBoolean;
- private EdmSimpleTypeKind edmSimpleKindTypeUUID;
-
- @Test
- public void testConvertToEdmSimpleType() {
- String str = "entity";
- byte[] byteArr = new byte[3];
- Long longObj = new Long(0);
- Short shortObj = new Short((short) 0);
- Integer integerObj = new Integer(0);
- Double doubleObj = new Double(0);
- Float floatObj = new Float(0);
- BigDecimal bigDecimalObj = new BigDecimal(0);
- Byte byteObj = new Byte((byte) 0);
- Boolean booleanObj = Boolean.TRUE;
- UUID uUID = new UUID(0, 0);
-
- try {
- edmSimpleKindTypeString = JPATypeConvertor.convertToEdmSimpleType(str.getClass(), null);
- edmSimpleKindTypeByteArr = JPATypeConvertor.convertToEdmSimpleType(byteArr.getClass(), null);
- edmSimpleKindTypeLong = JPATypeConvertor.convertToEdmSimpleType(longObj.getClass(), null);
- edmSimpleKindTypeShort = JPATypeConvertor.convertToEdmSimpleType(shortObj.getClass(), null);
- edmSimpleKindTypeInteger = JPATypeConvertor.convertToEdmSimpleType(integerObj.getClass(), null);
- edmSimpleKindTypeDouble = JPATypeConvertor.convertToEdmSimpleType(doubleObj.getClass(), null);
- edmSimpleKindTypeFloat = JPATypeConvertor.convertToEdmSimpleType(floatObj.getClass(), null);
- edmSimpleKindTypeBigDecimal = JPATypeConvertor.convertToEdmSimpleType(bigDecimalObj.getClass(), null);
- edmSimpleKindTypeByte = JPATypeConvertor.convertToEdmSimpleType(byteObj.getClass(), null);
- edmSimpleKindTypeBoolean = JPATypeConvertor.convertToEdmSimpleType(booleanObj.getClass(), null);
- /*
- * edmSimpleKindTypeDate = JPATypeConvertor
- * .convertToEdmSimpleType(dateObj.getClass(),null);
- */
- edmSimpleKindTypeUUID = JPATypeConvertor.convertToEdmSimpleType(uUID.getClass(), null);
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals(EdmSimpleTypeKind.String, edmSimpleKindTypeString);
- assertEquals(EdmSimpleTypeKind.Binary, edmSimpleKindTypeByteArr);
- assertEquals(EdmSimpleTypeKind.Int64, edmSimpleKindTypeLong);
- assertEquals(EdmSimpleTypeKind.Int16, edmSimpleKindTypeShort);
- assertEquals(EdmSimpleTypeKind.Int32, edmSimpleKindTypeInteger);
- assertEquals(EdmSimpleTypeKind.Double, edmSimpleKindTypeDouble);
- assertEquals(EdmSimpleTypeKind.Single, edmSimpleKindTypeFloat);
- assertEquals(EdmSimpleTypeKind.Decimal, edmSimpleKindTypeBigDecimal);
- assertEquals(EdmSimpleTypeKind.Byte, edmSimpleKindTypeByte);
- assertEquals(EdmSimpleTypeKind.Boolean, edmSimpleKindTypeBoolean);
- // assertEquals(EdmSimpleTypeKind.DateTime, edmSimpleKindTypeDate);
- assertEquals(EdmSimpleTypeKind.Guid, edmSimpleKindTypeUUID);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java
deleted file mode 100644
index cd6caee..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/common/ODataJPATestConstants.java
+++ /dev/null
@@ -1,27 +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.odata2.processor.core.jpa.common;
-
-public final class ODataJPATestConstants {
-
- public static final String EXCEPTION_MSG_PART_1 = "Exception [ ";
- public static final String EXCEPTION_MSG_PART_2 = " ] not expected";
- public static final String EMPTY_STRING = "gwt1";
- public static final String EXCEPTION_EXPECTED = "Exception expected";
-}
[34/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
new file mode 100644
index 0000000..6d8651b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntity.java
@@ -0,0 +1,355 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
+import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+
+public class JPAEntity {
+
+ private Object jpaEntity = null;
+ private EdmEntityType oDataEntityType = null;
+ private EdmEntitySet oDataEntitySet = null;
+ private Class<?> jpaType = null;
+ private HashMap<String, Method> accessModifiersWrite = null;
+ private JPAEntityParser jpaEntityParser = null;
+ public HashMap<EdmNavigationProperty, EdmEntitySet> inlinedEntities = null;
+
+ public JPAEntity(final EdmEntityType oDataEntityType, final EdmEntitySet oDataEntitySet) {
+ this.oDataEntityType = oDataEntityType;
+ this.oDataEntitySet = oDataEntitySet;
+ try {
+ JPAEdmMapping mapping = (JPAEdmMapping) oDataEntityType.getMapping();
+ jpaType = mapping.getJPAType();
+ } catch (EdmException e) {
+ return;
+ }
+ jpaEntityParser = new JPAEntityParser();
+ }
+
+ public void setAccessModifersWrite(final HashMap<String, Method> accessModifiersWrite) {
+ this.accessModifiersWrite = accessModifiersWrite;
+ }
+
+ public Object getJPAEntity() {
+ return jpaEntity;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void write(final Map<String, Object> oDataEntryProperties, final boolean isCreate)
+ throws ODataJPARuntimeException {
+ try {
+
+ EdmStructuralType structuralType = null;
+ final List<String> keyNames = oDataEntityType.getKeyPropertyNames();
+
+ if (isCreate) {
+ jpaEntity = instantiateJPAEntity();
+ } else if (jpaEntity == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.RESOURCE_NOT_FOUND, null);
+ }
+
+ if (accessModifiersWrite == null) {
+ accessModifiersWrite =
+ jpaEntityParser.getAccessModifiers(jpaEntity, oDataEntityType, JPAEntityParser.ACCESS_MODIFIER_SET);
+ }
+
+ if (oDataEntityType == null || oDataEntryProperties == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL, null);
+ }
+
+ final HashMap<String, String> embeddableKeys =
+ jpaEntityParser.getJPAEmbeddableKeyMap(jpaEntity.getClass().getName());
+ Set<String> propertyNames = null;
+ if (embeddableKeys != null) {
+ setEmbeddableKeyProperty(embeddableKeys, oDataEntityType.getKeyProperties(), oDataEntryProperties, jpaEntity);
+ propertyNames = new HashSet<String>();
+ propertyNames.addAll(oDataEntryProperties.keySet());
+ for (String propertyName : oDataEntityType.getKeyPropertyNames()) {
+ propertyNames.remove(propertyName);
+ }
+ } else {
+ propertyNames = oDataEntryProperties.keySet();
+ }
+
+ for (String propertyName : propertyNames) {
+ EdmTyped edmTyped = (EdmTyped) oDataEntityType.getProperty(propertyName);
+
+ Method accessModifier = null;
+
+ switch (edmTyped.getType().getKind()) {
+ case SIMPLE:
+ if (isCreate == false) {
+ if (keyNames.contains(edmTyped.getName())) {
+ continue;
+ }
+ }
+ accessModifier = accessModifiersWrite.get(propertyName);
+ setProperty(accessModifier, jpaEntity, oDataEntryProperties.get(propertyName));
+ break;
+ case COMPLEX:
+ structuralType = (EdmStructuralType) edmTyped.getType();
+ accessModifier = accessModifiersWrite.get(propertyName);
+ setComplexProperty(accessModifier, jpaEntity,
+ structuralType,
+ (HashMap<String, Object>) oDataEntryProperties.get(propertyName));
+ break;
+ case NAVIGATION:
+ case ENTITY:
+ structuralType = (EdmStructuralType) edmTyped.getType();
+ EdmNavigationProperty navProperty = (EdmNavigationProperty) edmTyped;
+ accessModifier =
+ jpaEntityParser.getAccessModifier(jpaEntity, navProperty,
+ JPAEntityParser.ACCESS_MODIFIER_SET);
+ EdmEntitySet edmRelatedEntitySet = oDataEntitySet.getRelatedEntitySet(navProperty);
+ List<ODataEntry> relatedEntries = (List<ODataEntry>) oDataEntryProperties.get(propertyName);
+ Collection<Object> relatedJPAEntites = instantiateRelatedJPAEntities(jpaEntity, navProperty);
+ JPAEntity relatedEntity = new JPAEntity((EdmEntityType) structuralType, edmRelatedEntitySet);
+ for (ODataEntry oDataEntry : relatedEntries) {
+ relatedEntity.create(oDataEntry);
+ relatedJPAEntites.add(relatedEntity.getJPAEntity());
+ }
+
+ switch (navProperty.getMultiplicity()) {
+ case MANY:
+ accessModifier.invoke(jpaEntity, relatedJPAEntites);
+ break;
+ case ONE:
+ case ZERO_TO_ONE:
+ accessModifier.invoke(jpaEntity, relatedJPAEntites.iterator().next());
+ break;
+ }
+
+ if (inlinedEntities == null) {
+ inlinedEntities = new HashMap<EdmNavigationProperty, EdmEntitySet>();
+ }
+
+ inlinedEntities.put((EdmNavigationProperty) edmTyped, edmRelatedEntitySet);
+ default:
+ continue;
+ }
+ }
+ } catch (Exception e) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL
+ .addContent(e.getMessage()), e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Collection<Object> instantiateRelatedJPAEntities(final Object jpaEntity,
+ final EdmNavigationProperty navProperty)
+ throws InstantiationException,
+ IllegalAccessException, EdmException, ODataJPARuntimeException, IllegalArgumentException,
+ InvocationTargetException {
+ Method accessModifier =
+ jpaEntityParser.getAccessModifier(jpaEntity, navProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
+ Collection<Object> relatedJPAEntities = (Collection<Object>) accessModifier.invoke(jpaEntity);
+ if (relatedJPAEntities == null) {
+ relatedJPAEntities = new ArrayList<Object>();
+ }
+ return relatedJPAEntities;
+ }
+
+ public void create(final ODataEntry oDataEntry) throws ODataJPARuntimeException {
+ if (oDataEntry == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL, null);
+ }
+ Map<String, Object> oDataEntryProperties = oDataEntry.getProperties();
+ if (oDataEntry.containsInlineEntry()) {
+ normalizeInlineEntries(oDataEntryProperties);
+ }
+ write(oDataEntryProperties, true);
+ }
+
+ public void create(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
+ normalizeInlineEntries(oDataEntryProperties);
+ write(oDataEntryProperties, true);
+ }
+
+ public void update(final ODataEntry oDataEntry) throws ODataJPARuntimeException {
+ if (oDataEntry == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL, null);
+ }
+ Map<String, Object> oDataEntryProperties = oDataEntry.getProperties();
+ write(oDataEntryProperties, false);
+ }
+
+ public void update(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
+ write(oDataEntryProperties, false);
+ }
+
+ public HashMap<EdmNavigationProperty, EdmEntitySet> getInlineJPAEntities() {
+ return inlinedEntities;
+ }
+
+ public void setJPAEntity(final Object jpaEntity) {
+ this.jpaEntity = jpaEntity;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void setComplexProperty(Method accessModifier, final Object jpaEntity,
+ final EdmStructuralType edmComplexType, final HashMap<String, Object> propertyValue)
+ throws EdmException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
+ InstantiationException, ODataJPARuntimeException {
+
+ JPAEdmMapping mapping = (JPAEdmMapping) edmComplexType.getMapping();
+ Object embeddableObject = mapping.getJPAType().newInstance();
+ accessModifier.invoke(jpaEntity, embeddableObject);
+
+ HashMap<String, Method> accessModifiers =
+ jpaEntityParser.getAccessModifiers(embeddableObject, edmComplexType, JPAEntityParser.ACCESS_MODIFIER_SET);
+
+ for (String edmPropertyName : edmComplexType.getPropertyNames()) {
+ EdmTyped edmTyped = (EdmTyped) edmComplexType.getProperty(edmPropertyName);
+ accessModifier = accessModifiers.get(edmPropertyName);
+ if (edmTyped.getType().getKind().toString().equals(EdmTypeKind.COMPLEX.toString())) {
+ EdmStructuralType structualType = (EdmStructuralType) edmTyped.getType();
+ setComplexProperty(accessModifier, embeddableObject, structualType, (HashMap<String, Object>) propertyValue
+ .get(edmPropertyName));
+ } else {
+ setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName));
+ }
+ }
+ }
+
+ protected void setProperty(final Method method, final Object entity, final Object entityPropertyValue) throws
+ IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ if (entityPropertyValue != null) {
+ Class<?> parameterType = method.getParameterTypes()[0];
+ if (parameterType.equals(char[].class)) {
+ char[] characters = ((String) entityPropertyValue).toCharArray();
+ method.invoke(entity, characters);
+ } else if (parameterType.equals(char.class)) {
+ char c = ((String) entityPropertyValue).charAt(0);
+ method.invoke(entity, c);
+ } else if (parameterType.equals(Character[].class)) {
+ Character[] characters = JPAEntityParser.toCharacterArray((String) entityPropertyValue);
+ method.invoke(entity, (Object) characters);
+ } else if (parameterType.equals(Character.class)) {
+ Character c = Character.valueOf(((String) entityPropertyValue).charAt(0));
+ method.invoke(entity, c);
+ } else {
+ method.invoke(entity, entityPropertyValue);
+ }
+ }
+ }
+
+ protected void setEmbeddableKeyProperty(final HashMap<String, String> embeddableKeys,
+ final List<EdmProperty> oDataEntryKeyProperties,
+ final Map<String, Object> oDataEntryProperties, final Object entity)
+ throws ODataJPARuntimeException, EdmException, IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException, InstantiationException {
+
+ HashMap<String, Object> embeddableObjMap = new HashMap<String, Object>();
+ List<EdmProperty> leftODataEntryKeyProperties = new ArrayList<EdmProperty>();
+ HashMap<String, String> leftEmbeddableKeys = new HashMap<String, String>();
+
+ for (EdmProperty edmProperty : oDataEntryKeyProperties) {
+ if (oDataEntryProperties.containsKey(edmProperty.getName()) == false) {
+ continue;
+ }
+
+ String edmPropertyName = edmProperty.getName();
+ String embeddableKeyNameComposite = embeddableKeys.get(edmPropertyName);
+ String embeddableKeyNameSplit[] = embeddableKeyNameComposite.split("\\.");
+ String methodPartName = null;
+ Method method = null;
+ Object embeddableObj = null;
+
+ if (embeddableObjMap.containsKey(embeddableKeyNameSplit[0]) == false) {
+ methodPartName = embeddableKeyNameSplit[0];
+ method = jpaEntityParser.getAccessModifierSet(entity, methodPartName);
+ embeddableObj = method.getParameterTypes()[0].newInstance();
+ method.invoke(entity, embeddableObj);
+ embeddableObjMap.put(embeddableKeyNameSplit[0], embeddableObj);
+ } else {
+ embeddableObj = embeddableObjMap.get(embeddableKeyNameSplit[0]);
+ }
+
+ if (embeddableKeyNameSplit.length == 2) {
+ methodPartName = embeddableKeyNameSplit[1];
+ method = jpaEntityParser.getAccessModifierSet(embeddableObj, methodPartName);
+ Object simpleObj = oDataEntryProperties.get(edmProperty.getName());
+ method.invoke(embeddableObj, simpleObj);
+ } else if (embeddableKeyNameSplit.length > 2) { // Deeply nested
+ leftODataEntryKeyProperties.add(edmProperty);
+ leftEmbeddableKeys
+ .put(edmPropertyName, embeddableKeyNameComposite.split(embeddableKeyNameSplit[0] + ".", 2)[1]);
+ setEmbeddableKeyProperty(leftEmbeddableKeys, leftODataEntryKeyProperties, oDataEntryProperties, embeddableObj);
+ }
+
+ }
+ }
+
+ protected Object instantiateJPAEntity() throws InstantiationException, IllegalAccessException {
+ if (jpaType == null) {
+ throw new InstantiationException();
+ }
+
+ return jpaType.newInstance();
+ }
+
+ private void normalizeInlineEntries(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
+ List<ODataEntry> entries = null;
+ try {
+ for (String navigationPropertyName : oDataEntityType.getNavigationPropertyNames()) {
+ Object inline = oDataEntryProperties.get(navigationPropertyName);
+ if (inline instanceof ODataFeed) {
+ entries = ((ODataFeed) inline).getEntries();
+ } else if (inline instanceof ODataEntry) {
+ entries = new ArrayList<ODataEntry>();
+ entries.add((ODataEntry) inline);
+ }
+ if (entries != null) {
+ oDataEntryProperties.put(navigationPropertyName, entries);
+ entries = null;
+ }
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL
+ .addContent(e.getMessage()), e);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
new file mode 100644
index 0000000..2850577
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParser.java
@@ -0,0 +1,453 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+
+public final class JPAEntityParser {
+
+ /*
+ * List of buffers used by the Parser
+ */
+ private static short MAX_SIZE = 10;
+ public static final String ACCESS_MODIFIER_GET = "get";
+ public static final String ACCESS_MODIFIER_SET = "set";
+
+ private HashMap<String, HashMap<String, Method>> jpaEntityAccessMap = null;
+ private HashMap<String, HashMap<String, String>> jpaEmbeddableKeyMap = null;
+
+ public JPAEntityParser() {
+ jpaEntityAccessMap = new HashMap<String, HashMap<String, Method>>(
+ MAX_SIZE);
+ jpaEmbeddableKeyMap = new HashMap<String, HashMap<String, String>>();
+ };
+
+ public HashMap<String, Method> getJPAEntityAccessMap(final String jpaEntityName) {
+ return jpaEntityAccessMap.get(jpaEntityName);
+ }
+
+ public HashMap<String, String> getJPAEmbeddableKeyMap(final String jpaEntityName) {
+ return jpaEmbeddableKeyMap.get(jpaEntityName);
+ }
+
+ /**
+ * The method returns a Hash Map of Properties and values for selected
+ * properties of an EdmEntity Type
+ *
+ * @param jpaEntity
+ * @param selectedItems
+ * @return a Hash Map of Properties and values for given selected properties
+ * of an EdmEntity Type
+ * @throws ODataJPARuntimeException
+ */
+
+ public final HashMap<String, Object> parse2EdmPropertyValueMap(
+ final Object jpaEntity, final List<EdmProperty> selectPropertyList)
+ throws ODataJPARuntimeException {
+ HashMap<String, Object> edmEntity = new HashMap<String, Object>();
+ String methodName = null;
+ Method method = null;
+ for (int i = 0; i < selectPropertyList.size(); i++) {
+ String key = null;
+ Object propertyValue = null;
+ EdmProperty property = null;
+ property = selectPropertyList.get(i);
+
+ try {
+ methodName = getAccessModifierName(property.getName(),
+ property.getMapping(), ACCESS_MODIFIER_GET);
+ String[] nameParts = methodName.split("\\.");
+ if (nameParts.length > 1) {
+ Object propertyVal = new Object();
+ propertyVal = jpaEntity;
+ for (String namePart : nameParts) {
+ method = propertyVal.getClass().getMethod(
+ namePart, (Class<?>[]) null);
+ method.setAccessible(true);
+ propertyVal = getProperty(method, propertyVal);
+ }
+ edmEntity.put(property.getName(), propertyVal);
+ } else {
+ method = jpaEntity.getClass().getMethod(methodName,
+ (Class<?>[]) null);
+ method.setAccessible(true);
+ propertyValue = getProperty(method, jpaEntity);
+ key = property.getName();
+ if (property.getType().getKind()
+ .equals(EdmTypeKind.COMPLEX)) {
+ try {
+ propertyValue = parse2EdmPropertyValueMap(
+ propertyValue,
+ (EdmStructuralType) property.getType());
+ } catch (ODataJPARuntimeException e) {
+ throw e;
+ }
+ }
+ edmEntity.put(key, propertyValue);
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ }
+
+ return edmEntity;
+ }
+
+ /**
+ * The method returns a Hash Map of Properties and values for an EdmEntity
+ * Type The method uses reflection on object jpaEntity to get the list of
+ * accessModifier method. Then uses the accessModifier method to extract the value from
+ * JPAEntity.
+ *
+ * @param jpaEntity
+ * @param structuralType
+ * @return a Hash Map of Properties and values for given EdmEntity Type
+ * @throws ODataJPARuntimeException
+ */
+ public final HashMap<String, Object> parse2EdmPropertyValueMap(
+ final Object jpaEntity, final EdmStructuralType structuralType)
+ throws ODataJPARuntimeException {
+
+ if (jpaEntity == null || structuralType == null) {
+ return null;
+ }
+
+ String jpaEntityAccessKey = jpaEntity.getClass().getName();
+
+ if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) {
+ jpaEntityAccessMap.put(jpaEntityAccessKey,
+ getAccessModifiers(jpaEntity, structuralType, ACCESS_MODIFIER_GET));
+ }
+
+ HashMap<String, Object> edmEntity = new HashMap<String, Object>();
+ HashMap<String, Method> getters = jpaEntityAccessMap
+ .get(jpaEntityAccessKey);
+ HashMap<String, String> embeddableKeys = jpaEmbeddableKeyMap
+ .get(jpaEntityAccessKey);
+
+ try {
+ for (String key : getters.keySet()) {
+
+ EdmProperty property = (EdmProperty) structuralType
+ .getProperty(key);
+
+ Method method = getters.get(key);
+ Object propertyValue = null;
+
+ if (method != null) {
+ getters.get(key).setAccessible(true);
+ propertyValue = getProperty(method, jpaEntity);
+ }
+ if (property.getType().getKind().equals(EdmTypeKind.COMPLEX)) {
+ propertyValue = parse2EdmPropertyValueMap(propertyValue,
+ (EdmStructuralType) property.getType());
+ }
+
+ edmEntity.put(key, propertyValue);
+
+ }
+
+ if (embeddableKeys != null) {
+ for (String key : embeddableKeys.keySet()) {
+ String name = embeddableKeys.get(key);
+ String[] nameParts = name.split("\\.");
+ Object propertyValue = jpaEntity;
+ Method method = null;
+ for (String namePart : nameParts) {
+ method = propertyValue.getClass().getMethod(
+ namePart, (Class<?>[]) null);
+ method.setAccessible(true);
+ propertyValue = getProperty(method, propertyValue);
+ }
+ edmEntity.put(key, propertyValue);
+ }
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ return edmEntity;
+ }
+
+ // This method appends the associated entities as a java list to an expanded
+ // map of a source entity
+ public final HashMap<String, Object> parse2EdmNavigationValueMap(
+ final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList)
+ throws ODataJPARuntimeException {
+ Object result = null;
+ String methodName = null;
+ HashMap<String, Object> navigationMap = new HashMap<String, Object>();
+ if (navigationPropertyList != null
+ && navigationPropertyList.size() != 0) {
+
+ try {
+ for (EdmNavigationProperty navigationProperty : navigationPropertyList) {
+ methodName = getAccessModifierName(navigationProperty.getName(),
+ navigationProperty.getMapping(), ACCESS_MODIFIER_GET);
+ Method getterMethod = jpaEntity.getClass()
+ .getDeclaredMethod(methodName, (Class<?>[]) null);
+ getterMethod.setAccessible(true);
+ result = getProperty(getterMethod, jpaEntity);
+ navigationMap.put(navigationProperty.getName(), result);
+ }
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ }
+ return navigationMap;
+ }
+
+ public Method getAccessModifierSet(final Object jpaEntity, final String methodName) throws ODataJPARuntimeException {
+ Class<?> jpaType = jpaEntity.getClass();
+ String methodNameGet = ACCESS_MODIFIER_GET + methodName.substring(3);
+ Method method = null;
+
+ try {
+ method = jpaType.getMethod(methodNameGet, (Class<?>[]) null);
+ Class<?> parameterType = method.getReturnType();
+ method = jpaType.getMethod(methodName, new Class<?>[] { parameterType });
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return method;
+ }
+
+ public HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
+ final EdmStructuralType structuralType, final String accessModifier) throws ODataJPARuntimeException {
+
+ HashMap<String, Method> accessModifierMap = new HashMap<String, Method>();
+ HashMap<String, String> embeddableKey = new HashMap<String, String>();
+ try {
+ for (String propertyName : structuralType.getPropertyNames()) {
+
+ EdmProperty property = (EdmProperty) structuralType
+ .getProperty(propertyName);
+
+ String name = getAccessModifierName(property.getName(),
+ property.getMapping(), accessModifier);
+ String[] nameParts = name.split("\\.");
+ if (nameParts.length > 1) {
+ embeddableKey.put(propertyName, name);
+ } else {
+ if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
+ JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
+ accessModifierMap.put(
+ propertyName,
+ jpaEntity.getClass().getMethod(name, new Class<?>[] { jpaEdmMapping.getJPAType() }));
+ } else {
+ accessModifierMap.put(
+ propertyName,
+ jpaEntity.getClass().getMethod(name,
+ (Class<?>[]) null));
+ }
+ }
+ }
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ if (!embeddableKey.isEmpty()) {
+ jpaEmbeddableKeyMap.put(jpaEntity.getClass().getName(),
+ embeddableKey);
+ }
+ return accessModifierMap;
+ }
+
+ public static Object getProperty(final Method method, final Object entity) throws ODataJPARuntimeException {
+ Object propertyValue = null;
+ try {
+ Class<?> returnType = method.getReturnType();
+
+ if (returnType.equals(char[].class)) {
+ char[] ch = (char[]) method.invoke(entity);
+ if (ch != null) {
+ propertyValue = (String) String.valueOf((char[]) method.invoke(entity));
+ }
+ } else if (returnType.equals(Character[].class)) {
+ propertyValue = (String) toString((Character[]) method.invoke(entity));
+ } else if (returnType.equals(char.class)) {
+ char c = (Character) method.invoke(entity);
+ if (c != '\u0000') {
+ propertyValue = (String) String.valueOf(c);
+ }
+ } else if (returnType.equals(Character.class)) {
+ Character c = (Character) method.invoke(entity);
+ if (c != null) {
+ propertyValue = toString(new Character[] { c });
+ }
+ } else {
+ propertyValue = method.invoke(entity);
+ }
+ } catch (IllegalAccessException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (InvocationTargetException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ return propertyValue;
+ }
+
+ public static String toString(final Character[] input) {
+ if (input == null) {
+ return null;
+ }
+
+ StringBuilder builder = new StringBuilder();
+ for (Character element : input) {
+ if (element == null) {
+ continue;
+ }
+ builder.append(element.charValue());
+ }
+ return builder.toString();
+
+ }
+
+ public static Character[] toCharacterArray(final String input) {
+ if (input == null) {
+ return null;
+ }
+
+ Character[] characters = new Character[input.length()];
+ char[] chars = ((String) input).toCharArray();
+ for (int i = 0; i < input.length(); i++) {
+ characters[i] = new Character(chars[i]);
+ }
+
+ return characters;
+ }
+
+ public static String getAccessModifierName(final String propertyName, final EdmMapping mapping,
+ final String accessModifier)
+ throws ODataJPARuntimeException {
+ String name = null;
+ StringBuilder builder = new StringBuilder();
+ String[] nameParts = {};
+ if (mapping == null || mapping.getInternalName() == null) {
+ name = propertyName;
+ } else {
+ name = mapping.getInternalName();
+ }
+ if (name != null) {
+ nameParts = name.split("\\.");
+ }
+ if (nameParts.length == 1) {
+ if (name != null) {
+ char c = Character.toUpperCase(name.charAt(0));
+
+ builder.append(accessModifier).append(c).append(name.substring(1))
+ .toString();
+ }
+ } else if (nameParts.length > 1) {
+
+ for (int i = 0; i < nameParts.length; i++) {
+ name = nameParts[i];
+ char c = Character.toUpperCase(name.charAt(0));
+ if (i == 0) {
+ builder.append(accessModifier).append(c).append(name.substring(1));
+ } else {
+ builder.append(".").append(accessModifier).append(c)
+ .append(name.substring(1));
+ }
+ }
+ } else {
+ return null;
+ }
+
+ if (builder.length() > 0) {
+ return builder.toString();
+ } else {
+ return null;
+ }
+
+ }
+
+ public Method getAccessModifier(final Object jpaEntity, final EdmNavigationProperty navigationProperty,
+ final String accessModifier)
+ throws ODataJPARuntimeException {
+
+ try {
+
+ JPAEdmMapping navPropMapping = (JPAEdmMapping) navigationProperty.getMapping();
+ String name = getAccessModifierName(navigationProperty.getName(), (EdmMapping) navPropMapping, accessModifier);
+
+ Class<?>[] params = null;
+ if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
+ EdmAssociationEnd end = navigationProperty.getRelationship().getEnd(navigationProperty.getToRole());
+ switch (end.getMultiplicity()) {
+ case MANY:
+ params = new Class<?>[] { navPropMapping.getJPAType() };
+ break;
+ case ONE:
+ params = new Class<?>[] { ((JPAEdmMapping) end.getEntityType().getMapping()).getJPAType() };
+ default:
+ break;
+ }
+ }
+ return jpaEntity.getClass().getMethod(name,
+ params);
+
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
new file mode 100644
index 0000000..1cf74b3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBack.java
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
+import org.apache.olingo.odata2.api.ep.callback.OnWriteFeedContent;
+import org.apache.olingo.odata2.api.ep.callback.WriteCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+
+public class JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryContent, ODataCallback {
+
+ private URI baseUri;
+ private List<ArrayList<NavigationPropertySegment>> expandList;
+ private EdmEntitySet nextEntitySet = null;
+
+ private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList) {
+ super();
+ this.baseUri = baseUri;
+ this.expandList = expandList;
+ }
+
+ @Override
+ public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) {
+ WriteEntryCallbackResult result = new WriteEntryCallbackResult();
+ Map<String, Object> entry = context.getEntryData();
+ Map<String, Object> edmPropertyValueMap = null;
+ List<EdmNavigationProperty> currentNavPropertyList = null;
+ Map<String, ExpandSelectTreeNode> navigationLinks = null;
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty();
+ try {
+ Object inlinedEntry = entry.get(currentNavigationProperty.getName());
+ if (nextEntitySet == null) {
+ nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty);
+ }
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(inlinedEntry, nextEntitySet.getEntityType());
+ result.setEntryData(edmPropertyValueMap);
+ navigationLinks = context.getCurrentExpandSelectTreeNode().getLinks();
+ if (navigationLinks.size() > 0) {
+ currentNavPropertyList = new ArrayList<EdmNavigationProperty>();
+ EdmNavigationProperty nextNavProperty =
+ getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty());
+ if (nextNavProperty != null) {
+ currentNavPropertyList.add(nextNavProperty);
+ }
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(inlinedEntry, currentNavPropertyList);
+ edmPropertyValueMap.putAll(navigationMap);
+ result.setEntryData(edmPropertyValueMap);
+ }
+ result.setInlineProperties(getInlineEntityProviderProperties(context));
+ } catch (EdmException e) {
+
+ } catch (ODataJPARuntimeException e) {
+
+ }
+
+ return result;
+ }
+
+ @Override
+ public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context) {
+ WriteFeedCallbackResult result = new WriteFeedCallbackResult();
+ HashMap<String, Object> inlinedEntry = (HashMap<String, Object>) context.getEntryData();
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmPropertyValueMap = null;
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ List<EdmNavigationProperty> currentNavPropertyList = null;
+ EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty();
+ try {
+ @SuppressWarnings({ "unchecked" })
+ Collection<Object> listOfItems = (Collection<Object>) inlinedEntry.get(context.getNavigationProperty().getName());
+ if (nextEntitySet == null) {
+ nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty);
+ }
+ for (Object object : listOfItems) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(object, nextEntitySet.getEntityType());
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ result.setFeedData(edmEntityList);
+ if (context.getCurrentExpandSelectTreeNode().getLinks().size() > 0) {
+ currentNavPropertyList = new ArrayList<EdmNavigationProperty>();
+ EdmNavigationProperty nextNavProperty =
+ getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty());
+ if (nextNavProperty != null) {
+ currentNavPropertyList.add(nextNavProperty);
+ }
+ int count = 0;
+ for (Object object : listOfItems) {
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(object, currentNavPropertyList);
+ edmEntityList.get(count).putAll(navigationMap);
+ count++;
+ }
+ result.setFeedData(edmEntityList);
+ }
+ result.setInlineProperties(getInlineEntityProviderProperties(context));
+ } catch (EdmException e) {
+
+ } catch (ODataJPARuntimeException e) {
+
+ }
+ return result;
+ }
+
+ private EdmNavigationProperty getNextNavigationProperty(final EdmEntityType sourceEntityType,
+ final EdmNavigationProperty navigationProperty) throws EdmException {
+ for (ArrayList<NavigationPropertySegment> navPropSegments : expandList) {
+ int size = navPropSegments.size();
+ for (int i = 0; i < size; i++) {
+ EdmNavigationProperty navProperty = navPropSegments.get(i).getNavigationProperty();
+ if (navProperty.getFromRole().equalsIgnoreCase(sourceEntityType.getName())
+ && navProperty.getName().equals(navigationProperty.getName())) {
+ if (i < size - 1) {
+ return navPropSegments.get(i + 1).getNavigationProperty();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static <T> Map<String, ODataCallback> getCallbacks(final URI baseUri,
+ final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList)
+ throws EdmException {
+ Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
+
+ for (String navigationPropertyName : expandSelectTreeNode.getLinks().keySet()) {
+ callbacks.put(navigationPropertyName, new JPAExpandCallBack(baseUri, expandList));
+ }
+
+ return callbacks;
+
+ }
+
+ private EntityProviderWriteProperties getInlineEntityProviderProperties(final WriteCallbackContext context)
+ throws EdmException {
+ ODataEntityProviderPropertiesBuilder propertiesBuilder = EntityProviderWriteProperties.serviceRoot(baseUri);
+ propertiesBuilder.callbacks(getCallbacks(baseUri, context.getCurrentExpandSelectTreeNode(), expandList));
+ propertiesBuilder.expandSelectTree(context.getCurrentExpandSelectTreeNode());
+ return propertiesBuilder.build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContext.java
new file mode 100644
index 0000000..d96c476
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContext.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteral;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmParameter;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAFunction;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+
+public class JPAFunctionContext extends JPAMethodContext {
+
+ public class JPAFunctionContextBuilder extends JPAMethodContextBuilder {
+
+ protected GetFunctionImportUriInfo functiontView;
+ private EdmFunctionImport functionImport;
+ private EdmMapping mapping;
+
+ @Override
+ public JPAMethodContext build() throws ODataJPAModelException, ODataJPARuntimeException {
+ if (functiontView != null) {
+
+ functionImport = functiontView.getFunctionImport();
+ try {
+ mapping = functionImport.getMapping();
+
+ List<JPAFunction> jpaFunctionList = new ArrayList<JPAFunction>();
+ jpaFunctionList.add(generateJPAFunction());
+ setJpaFunction(jpaFunctionList);
+ setEnclosingObject(generateEnclosingObject());
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (InstantiationException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (IllegalAccessException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (InvocationTargetException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (NoSuchMethodException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (SecurityException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ }
+
+ return JPAFunctionContext.this;
+ }
+
+ private JPAFunction generateJPAFunction() throws EdmException, NoSuchMethodException, SecurityException,
+ ODataJPAModelException, ODataJPARuntimeException {
+
+ Class<?>[] parameterTypes = getParameterTypes();
+ Method method = getMethod(parameterTypes);
+ Type returnType = getReturnType();
+ Object[] args = getAruguments();
+
+ JPAFunction jpafunction = new JPAFunction(method, parameterTypes, returnType, args);
+
+ return jpafunction;
+ }
+
+ private Object[] getAruguments() throws EdmException {
+ Map<String, EdmLiteral> edmArguements = functiontView.getFunctionImportParameters();
+
+ if (edmArguements == null) {
+ return null;
+ } else {
+ Object[] args = new Object[edmArguements.size()];
+ int i = 0;
+ for (String paramName : functionImport.getParameterNames()) {
+ EdmLiteral literal = edmArguements.get(paramName);
+ EdmParameter parameter = functionImport.getParameter(paramName);
+ JPAEdmMapping mapping = (JPAEdmMapping) parameter.getMapping();
+ args[i] = convertArguement(literal, parameter.getFacets(), mapping.getJPAType());
+ i++;
+ }
+ return args;
+ }
+
+ }
+
+ private Object convertArguement(final EdmLiteral edmLiteral, final EdmFacets facets, final Class<?> targetType)
+ throws EdmSimpleTypeException {
+ EdmSimpleType edmType = edmLiteral.getType();
+ Object value = edmType.valueOfString(edmLiteral.getLiteral(), EdmLiteralKind.DEFAULT, facets, targetType);
+
+ return value;
+ }
+
+ private Class<?>[] getParameterTypes() throws EdmException {
+
+ Class<?>[] parameterTypes = new Class<?>[functionImport.getParameterNames().size()];
+ int i = 0;
+ for (String parameterName : functionImport.getParameterNames()) {
+ EdmParameter parameter = functionImport.getParameter(parameterName);
+ parameterTypes[i] = ((JPAEdmMapping) parameter.getMapping()).getJPAType();
+ i++;
+ }
+
+ return parameterTypes;
+ }
+
+ private Method getMethod(final Class<?>[] parameterTypes) throws NoSuchMethodException, SecurityException {
+
+ Class<?> type = ((JPAEdmMapping) mapping).getJPAType();
+ Method method;
+ method = type.getMethod(mapping.getInternalName(), parameterTypes);
+
+ return method;
+ }
+
+ private Type getReturnType() throws ODataJPAModelException, ODataJPARuntimeException, EdmException {
+ return null;
+ }
+
+ private Object generateEnclosingObject() throws InstantiationException, IllegalAccessException,
+ IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
+
+ Class<?> type = ((JPAEdmMapping) mapping).getJPAType();
+ Object[] params = null;
+
+ return type.getConstructor((Class<?>[]) params).newInstance(params);
+
+ }
+
+ @Override
+ protected void setResultsView(final Object resultsView) {
+ if (resultsView instanceof GetFunctionImportUriInfo) {
+ functiontView = (GetFunctionImportUriInfo) resultsView;
+ }
+
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
new file mode 100644
index 0000000..40e0792
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPALink.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+import org.apache.olingo.odata2.jpa.processor.core.ODataEntityParser;
+
+public class JPALink {
+
+ private ODataJPAContext context;
+ private JPAProcessor jpaProcessor;
+ private ODataEntityParser parser;
+ private Object targetJPAEntity;
+ private Object sourceJPAEntity;
+
+ public JPALink(final ODataJPAContext context) {
+ this.context = context;
+ jpaProcessor = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAProcessor(this.context);
+ parser = new ODataEntityParser(this.context);
+ }
+
+ public void setSourceJPAEntity(final Object jpaEntity) {
+ sourceJPAEntity = jpaEntity;
+ }
+
+ public void create(final PostUriInfo uriInfo, final InputStream content, final String requestContentType,
+ final String contentType) throws ODataJPARuntimeException, ODataJPAModelException {
+
+ EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+ String targerEntitySetName;
+ EdmNavigationProperty navigationProperty = null;
+ try {
+ targerEntitySetName = targetEntitySet.getName();
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ List<UriInfo> uriInfoList = new ArrayList<UriInfo>();
+
+ if (((UriInfo) uriInfo).isLinks()) {
+ UriInfo getUriInfo = parser.parseLink(targetEntitySet, content, requestContentType);
+ uriInfoList = new ArrayList<UriInfo>();
+ uriInfoList.add(getUriInfo);
+ navigationProperty = uriInfo.getNavigationSegments().get(0).getNavigationProperty();
+ } else {
+ uriInfoList = parser.parseLinks(targetEntitySet, content, contentType);
+ }
+
+ if (uriInfoList == null) {
+ return;
+ }
+ try {
+ for (UriInfo getUriInfo : uriInfoList) {
+
+ if (!getUriInfo.getTargetEntitySet().getName().equals(targerEntitySetName)) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RELATIONSHIP_INVALID, null);
+ }
+ if (!((UriInfo) uriInfo).isLinks()) {
+ navigationProperty = getUriInfo.getNavigationSegments().get(0).getNavigationProperty();
+ }
+
+ targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
+ if (targetJPAEntity != null && ((UriInfo) uriInfo).isLinks()) {
+ getUriInfo = parser.parseLinkURI();
+ sourceJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
+ if (sourceJPAEntity == null) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND
+ .addContent(getUriInfo.getTargetEntitySet().getName()), null);
+ }
+ }
+
+ JPAEntityParser entityParser = new JPAEntityParser();
+ Method setMethod =
+ entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
+
+ Method getMethod =
+ entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
+
+ if (getMethod.getReturnType().getTypeParameters() != null) {
+ @SuppressWarnings("unchecked")
+ List<Object> relatedEntities = (List<Object>) getMethod.invoke(sourceJPAEntity);
+ relatedEntities.add(targetJPAEntity);
+ setMethod.invoke(sourceJPAEntity, relatedEntities);
+ } else {
+ setMethod.invoke(sourceJPAEntity, targetJPAEntity);
+ }
+ }
+ } catch (IllegalAccessException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (InvocationTargetException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ }
+
+ public void delete() {}
+
+ public void save() {
+ EntityManager em = context.getEntityManager();
+ EntityTransaction tx = em.getTransaction();
+
+ if (!tx.isActive()) {
+ em.getTransaction().begin();
+ em.persist(sourceJPAEntity);
+ em.getTransaction().commit();
+ }
+
+ }
+
+ public void update(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType,
+ final String contentType) throws ODataJPARuntimeException, ODataJPAModelException {
+ UriInfo uriInfo = (UriInfo) putUriInfo;
+
+ EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+ String targerEntitySetName;
+ EdmNavigationProperty navigationProperty = null;
+ try {
+ targerEntitySetName = targetEntitySet.getName();
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ List<UriInfo> uriInfoList = new ArrayList<UriInfo>();
+
+ if (((UriInfo) uriInfo).isLinks()) {
+ UriInfo getUriInfo = parser.parseLink(targetEntitySet, content, requestContentType);
+ uriInfoList = new ArrayList<UriInfo>();
+ uriInfoList.add(getUriInfo);
+ navigationProperty = uriInfo.getNavigationSegments().get(0).getNavigationProperty();
+ } else {
+ uriInfoList = parser.parseLinks(targetEntitySet, content, contentType);
+ }
+
+ if (uriInfoList == null) {
+ return;
+ }
+ try {
+ for (UriInfo getUriInfo : uriInfoList) {
+
+ if (!getUriInfo.getTargetEntitySet().getName().equals(targerEntitySetName)) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RELATIONSHIP_INVALID, null);
+ }
+ if (!((UriInfo) uriInfo).isLinks()) {
+ navigationProperty = getUriInfo.getNavigationSegments().get(0).getNavigationProperty();
+ }
+
+ targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
+ if (targetJPAEntity != null && ((UriInfo) uriInfo).isLinks()) {
+ getUriInfo = parser.parseLinkURI();
+ sourceJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
+ if (sourceJPAEntity == null) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND
+ .addContent(getUriInfo.getTargetEntitySet().getName()), null);
+ }
+ }
+
+ JPAEntityParser entityParser = new JPAEntityParser();
+ Method setMethod =
+ entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
+
+ Method getMethod =
+ entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
+
+ if (getMethod.getReturnType().getTypeParameters() != null
+ && getMethod.getReturnType().getTypeParameters().length != 0) {
+ @SuppressWarnings("unchecked")
+ List<Object> relatedEntities = (List<Object>) getMethod.invoke(sourceJPAEntity);
+ relatedEntities.add(targetJPAEntity);
+ setMethod.invoke(sourceJPAEntity, relatedEntities);
+ } else {
+ setMethod.invoke(sourceJPAEntity, targetJPAEntity);
+ }
+ }
+ } catch (IllegalAccessException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (InvocationTargetException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
new file mode 100644
index 0000000..6ca98e6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImpl.java
@@ -0,0 +1,491 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAFunction;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.core.ODataEntityParser;
+
+public class JPAProcessorImpl implements JPAProcessor {
+
+ ODataJPAContext oDataJPAContext;
+ EntityManager em;
+
+ public JPAProcessorImpl(final ODataJPAContext oDataJPAContext) {
+ this.oDataJPAContext = oDataJPAContext;
+ em = oDataJPAContext.getEntityManager();
+ }
+
+ /* Process Function Import Request */
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<Object> process(final GetFunctionImportUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
+ JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder(
+ JPQLContextType.FUNCTION, uriParserResultView).build();
+
+ List<Object> resultObj = null;
+
+ try {
+
+ JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList()
+ .get(0);
+ Method method = jpaFunction.getFunction();
+ Object[] args = jpaFunction.getArguments();
+
+ if (uriParserResultView.getFunctionImport().getReturnType()
+ .getMultiplicity().equals(EdmMultiplicity.MANY)) {
+
+ resultObj = (List<Object>) method.invoke(
+ jpaMethodContext.getEnclosingObject(), args);
+ } else {
+ resultObj = new ArrayList<Object>();
+ Object result = method.invoke(
+ jpaMethodContext.getEnclosingObject(), args);
+ resultObj.add(result);
+ }
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL
+ .addContent(e.getMessage()), e);
+ } catch (IllegalAccessException e) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL
+ .addContent(e.getMessage()), e);
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL
+ .addContent(e.getMessage()), e);
+ } catch (InvocationTargetException e) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.GENERAL
+ .addContent(e.getTargetException().getMessage()), e.getTargetException());
+ }
+
+ return resultObj;
+ }
+
+ /* Process Get Entity Set Request (Query) */
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> List<T> process(final GetEntitySetUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
+ if (uriParserResultView.getFunctionImport() != null) {
+ return (List<T>) process((GetFunctionImportUriInfo) uriParserResultView);
+ }
+ JPQLContextType contextType = null;
+ try {
+ if (!uriParserResultView.getStartEntitySet().getName()
+ .equals(uriParserResultView.getTargetEntitySet().getName())) {
+ contextType = JPQLContextType.JOIN;
+ } else {
+ contextType = JPQLContextType.SELECT;
+ }
+
+ } catch (EdmException e) {
+ ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.GENERAL, e);
+ }
+
+ JPQLContext jpqlContext = JPQLContext.createBuilder(contextType,
+ uriParserResultView).build();
+
+ JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext)
+ .build();
+ Query query = null;
+ try {
+ query = em.createQuery(jpqlStatement.toString());
+ // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call
+ if (uriParserResultView.getSkip() != null && uriParserResultView.getInlineCount() == null) {
+ query.setFirstResult(uriParserResultView.getSkip());
+ }
+
+ if (uriParserResultView.getTop() != null && uriParserResultView.getInlineCount() == null) {
+ if (uriParserResultView.getTop() == 0) {
+ List<T> resultList = new ArrayList<T>();
+ return resultList;
+ } else {
+ query.setMaxResults(uriParserResultView.getTop());
+ }
+ }
+ return query.getResultList();
+ } catch (Exception e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
+
+ }
+ }
+
+ /* Process Get Entity Request (Read) */
+ @Override
+ public <T> Object process(GetEntityUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
+ JPQLContextType contextType = null;
+ try {
+ if (uriParserResultView instanceof GetEntityUriInfo) {
+ uriParserResultView = ((GetEntityUriInfo) uriParserResultView);
+ if (!((GetEntityUriInfo) uriParserResultView).getStartEntitySet().getName()
+ .equals(((GetEntityUriInfo) uriParserResultView).getTargetEntitySet().getName())) {
+ contextType = JPQLContextType.JOIN_SINGLE;
+ } else {
+ contextType = JPQLContextType.SELECT_SINGLE;
+ }
+ }
+ } catch (EdmException e) {
+ ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.GENERAL, e);
+ }
+
+ return readEntity(uriParserResultView, contextType);
+ }
+
+ /* Process $count for Get Entity Set Request */
+ @Override
+ public long process(final GetEntitySetCountUriInfo resultsView)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
+ JPQLContextType contextType = null;
+ try {
+ if (!resultsView.getStartEntitySet().getName()
+ .equals(resultsView.getTargetEntitySet().getName())) {
+ contextType = JPQLContextType.JOIN_COUNT;
+ } else {
+ contextType = JPQLContextType.SELECT_COUNT;
+ }
+ } catch (EdmException e) {
+ ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.GENERAL, e);
+ }
+
+ JPQLContext jpqlContext = JPQLContext.createBuilder(contextType,
+ resultsView).build();
+
+ JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext)
+ .build();
+ Query query = null;
+ try {
+
+ query = em.createQuery(jpqlStatement.toString());
+ List<?> resultList = query.getResultList();
+ if (resultList != null && resultList.size() == 1) {
+ return Long.valueOf(resultList.get(0).toString());
+ }
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
+ }
+ return 0;
+ }
+
+ /* Process $count for Get Entity Request */
+ @Override
+ public long process(final GetEntityCountUriInfo resultsView) throws ODataJPAModelException, ODataJPARuntimeException {
+
+ JPQLContextType contextType = null;
+ try {
+ if (!resultsView.getStartEntitySet().getName()
+ .equals(resultsView.getTargetEntitySet().getName())) {
+ contextType = JPQLContextType.JOIN_COUNT;
+ } else {
+ contextType = JPQLContextType.SELECT_COUNT;
+ }
+ } catch (EdmException e) {
+ ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.GENERAL, e);
+ }
+
+ JPQLContext jpqlContext = JPQLContext.createBuilder(contextType,
+ resultsView).build();
+
+ JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext)
+ .build();
+ Query query = null;
+ try {
+
+ query = em.createQuery(jpqlStatement.toString());
+ List<?> resultList = query.getResultList();
+ if (resultList != null && resultList.size() == 1) {
+ return Long.valueOf(resultList.get(0).toString());
+ }
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
+ }
+
+ return 0;
+ }
+
+ /* Process Create Entity Request */
+ @Override
+ public <T> List<T> process(final PostUriInfo createView, final InputStream content,
+ final String requestedContentType) throws ODataJPAModelException,
+ ODataJPARuntimeException {
+ return processCreate(createView, content, null, requestedContentType);
+ }
+
+ @Override
+ public <T> List<T> process(final PostUriInfo createView, final Map<String, Object> content)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+ return processCreate(createView, null, content, null);
+ }
+
+ /* Process Update Entity Request */
+ @Override
+ public <T> Object process(final PutMergePatchUriInfo updateView,
+ final InputStream content, final String requestContentType)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+ return processUpdate(updateView, content, null, requestContentType);
+ }
+
+ @Override
+ public <T> Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+ return processUpdate(updateView, null, content, null);
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> List<T> processCreate(final PostUriInfo createView, final InputStream content,
+ final Map<String, Object> properties,
+ final String requestedContentType) throws ODataJPAModelException,
+ ODataJPARuntimeException {
+ try {
+
+ final EdmEntitySet oDataEntitySet = createView.getTargetEntitySet();
+ final EdmEntityType oDataEntityType = oDataEntitySet.getEntityType();
+ final JPAEntity virtualJPAEntity = new JPAEntity(oDataEntityType, oDataEntitySet);
+ final List<Object> createList = new ArrayList<Object>();
+ Object jpaEntity = null;
+
+ if (content != null) {
+ final ODataEntityParser oDataEntityParser = new ODataEntityParser(oDataJPAContext);
+ final ODataEntry oDataEntry =
+ oDataEntityParser.parseEntry(oDataEntitySet, content, requestedContentType, false);
+ virtualJPAEntity.create(oDataEntry);
+ JPALink link = new JPALink(oDataJPAContext);
+ link.setSourceJPAEntity(jpaEntity);
+ link.create(createView, content, requestedContentType, requestedContentType);
+ } else if (properties != null) {
+ virtualJPAEntity.create(properties);
+ } else {
+ return null;
+ }
+
+ em.getTransaction().begin();
+ jpaEntity = virtualJPAEntity.getJPAEntity();
+
+ em.persist(jpaEntity);
+ if (em.contains(jpaEntity)) {
+ em.getTransaction().commit();
+
+ createList.add(virtualJPAEntity.getJPAEntity());
+ createList.add(virtualJPAEntity.getInlineJPAEntities());
+
+ return (List<T>) createList;
+ }
+ } catch (Exception e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST, e);
+ }
+ return null;
+ }
+
+ public <T> Object processUpdate(PutMergePatchUriInfo updateView,
+ final InputStream content, final Map<String, Object> properties, final String requestContentType)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+ JPQLContextType contextType = null;
+ Object jpaEntity = null;
+ try {
+ em.getTransaction().begin();
+ if (updateView instanceof PutMergePatchUriInfo) {
+ updateView = ((PutMergePatchUriInfo) updateView);
+ if (!((PutMergePatchUriInfo) updateView).getStartEntitySet().getName()
+ .equals(((PutMergePatchUriInfo) updateView).getTargetEntitySet().getName())) {
+ contextType = JPQLContextType.JOIN_SINGLE;
+ } else {
+ contextType = JPQLContextType.SELECT_SINGLE;
+ }
+ }
+
+ jpaEntity = readEntity(updateView, contextType);
+
+ if (jpaEntity == null) {
+ throw ODataJPARuntimeException
+ .throwException(ODataJPARuntimeException.RESOURCE_NOT_FOUND, null);
+ }
+
+ final EdmEntitySet oDataEntitySet = updateView.getTargetEntitySet();
+ final EdmEntityType oDataEntityType = oDataEntitySet.getEntityType();
+ final JPAEntity virtualJPAEntity = new JPAEntity(oDataEntityType, oDataEntitySet);
+ virtualJPAEntity.setJPAEntity(jpaEntity);
+
+ if (content != null) {
+ final ODataEntityParser oDataEntityParser = new ODataEntityParser(oDataJPAContext);
+ final ODataEntry oDataEntry = oDataEntityParser.parseEntry(oDataEntitySet, content, requestContentType, false);
+ virtualJPAEntity.update(oDataEntry);
+ } else if (properties != null) {
+ virtualJPAEntity.update(properties);
+ } else {
+ return null;
+ }
+ em.flush();
+ em.getTransaction().commit();
+ } catch (Exception e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST, e);
+ }
+
+ return jpaEntity;
+ }
+
+ /* Process Delete Entity Request */
+ @Override
+ public Object process(DeleteUriInfo uriParserResultView, final String contentType)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+ JPQLContextType contextType = null;
+ try {
+ if (uriParserResultView instanceof DeleteUriInfo) {
+ uriParserResultView = ((DeleteUriInfo) uriParserResultView);
+ if (!((DeleteUriInfo) uriParserResultView).getStartEntitySet().getName()
+ .equals(((DeleteUriInfo) uriParserResultView).getTargetEntitySet().getName())) {
+ contextType = JPQLContextType.JOIN_SINGLE;
+ } else {
+ contextType = JPQLContextType.SELECT_SINGLE;
+ }
+ }
+ } catch (EdmException e) {
+ ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.GENERAL, e);
+ }
+
+ // First read the entity with read operation.
+ Object selectedObject = readEntity(uriParserResultView, contextType);
+ // Read operation done. This object would be passed on to entity manager for delete
+ if (selectedObject != null) {
+ try {
+ em.getTransaction().begin();
+ em.remove(selectedObject);
+ em.flush();
+ em.getTransaction().commit();
+ } catch (Exception e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST, e);
+ }
+ }
+ return selectedObject;
+ }
+
+ /* Process Get Entity Link Request */
+ @Override
+ public Object process(final GetEntityLinkUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
+ return this.process((GetEntityUriInfo) uriParserResultView);
+ }
+
+ /* Process Get Entity Set Link Request */
+ @Override
+ public <T> List<T> process(final GetEntitySetLinksUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+ return this.process((GetEntitySetUriInfo) uriParserResultView);
+ }
+
+ @Override
+ public void process(final PostUriInfo uriInfo,
+ final InputStream content, final String requestContentType, final String contentType)
+ throws ODataJPARuntimeException, ODataJPAModelException {
+ JPALink link = new JPALink(oDataJPAContext);
+ link.create(uriInfo, content, requestContentType, contentType);
+ link.save();
+ }
+
+ /* Common method for Read and Delete */
+ private Object readEntity(final Object uriParserResultView, final JPQLContextType contextType)
+ throws ODataJPAModelException, ODataJPARuntimeException {
+
+ Object selectedObject = null;
+
+ if (uriParserResultView instanceof DeleteUriInfo || uriParserResultView instanceof GetEntityUriInfo
+ || uriParserResultView instanceof PutMergePatchUriInfo) {
+
+ JPQLContext selectJPQLContext = JPQLContext.createBuilder(
+ contextType, uriParserResultView).build();
+
+ JPQLStatement selectJPQLStatement = JPQLStatement.createBuilder(
+ selectJPQLContext).build();
+ Query query = null;
+ try {
+ query = em.createQuery(selectJPQLStatement.toString());
+ if (!query.getResultList().isEmpty()) {
+ selectedObject = query.getResultList().get(0);
+ }
+ } catch (IllegalArgumentException e) {
+ throw ODataJPARuntimeException.throwException(
+ ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
+ }
+ }
+ return selectedObject;
+ }
+
+ @Override
+ public void process(final PutMergePatchUriInfo putUriInfo,
+ final InputStream content, final String requestContentType, final String contentType)
+ throws ODataJPARuntimeException, ODataJPAModelException {
+
+ JPALink link = new JPALink(oDataJPAContext);
+ link.update(putUriInfo, content, requestContentType, contentType);
+ link.save();
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/EdmTypeConvertor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/EdmTypeConvertor.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/EdmTypeConvertor.java
new file mode 100644
index 0000000..771aae6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/access/model/EdmTypeConvertor.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import java.math.BigDecimal;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.UUID;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+
+public class EdmTypeConvertor {
+
+ public static Class<?> convertToJavaType(final EdmType edmType) throws ODataJPAModelException,
+ ODataJPARuntimeException {
+ if (edmType instanceof EdmSimpleType) {
+ EdmSimpleType edmSimpleType = (EdmSimpleType) edmType;
+ if (edmSimpleType == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()) {
+ return String.class;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Int64.getEdmSimpleTypeInstance()) {
+ return Long.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance()) {
+ return Short.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance()) {
+ return Integer.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()) {
+ return Double.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Float.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()) {
+ return BigDecimal.class;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) {
+ return byte[].class;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Byte.getEdmSimpleTypeInstance()) {
+ return Byte.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance()) {
+ return Boolean.TYPE;
+ } else if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()) {
+ return Date.class;
+ } else if (edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
+ return Calendar.class;
+ } else if (edmSimpleType == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()) {
+ return UUID.class;
+ }
+ }
+ throw ODataJPAModelException.throwException(ODataJPAModelException.TYPE_NOT_SUPPORTED
+ .addContent(edmType.toString()), null);
+ }
+}
[35/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAPersistenceUnitMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAPersistenceUnitMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAPersistenceUnitMapType.java
deleted file mode 100644
index a9d34b2..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAPersistenceUnitMapType.java
+++ /dev/null
@@ -1,157 +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.odata2.processor.api.jpa.model.mapping;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- *
- * By default Java Persistence Unit name is taken as EDM schema name. This can
- * be overriden using JPAPersistenceUnitMapType.
- *
- *
- * <p>
- * Java class for JPAPersistenceUnitMapType complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within
- * this class.
- *
- * <pre>
- * <complexType name="JPAPersistenceUnitMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="EDMSchemaNamespace" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- * <element name="JPAEntityTypes"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAEntityTypesMapType"/>
- * <element name="JPAEmbeddableTypes"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAEmbeddableTypesMapType"/>
- * </sequence>
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPAPersistenceUnitMapType",
- propOrder = { "edmSchemaNamespace", "jpaEntityTypes", "jpaEmbeddableTypes" })
-public class JPAPersistenceUnitMapType {
-
- @XmlElement(name = "EDMSchemaNamespace")
- protected String edmSchemaNamespace;
- @XmlElement(name = "JPAEntityTypes", required = true)
- protected JPAEntityTypesMapType jpaEntityTypes;
- @XmlElement(name = "JPAEmbeddableTypes", required = true)
- protected JPAEmbeddableTypesMapType jpaEmbeddableTypes;
- @XmlAttribute(name = "name", required = true)
- protected String name;
-
- /**
- * Gets the value of the edmSchemaNamespace property.
- *
- * @return possible object is {@link String }
- *
- */
- public String getEDMSchemaNamespace() {
- return edmSchemaNamespace;
- }
-
- /**
- * Sets the value of the edmSchemaNamespace property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setEDMSchemaNamespace(final String value) {
- edmSchemaNamespace = value;
- }
-
- /**
- * Gets the value of the jpaEntityTypes property.
- *
- * @return possible object is {@link JPAEntityTypesMapType }
- *
- */
- public JPAEntityTypesMapType getJPAEntityTypes() {
- return jpaEntityTypes;
- }
-
- /**
- * Sets the value of the jpaEntityTypes property.
- *
- * @param value
- * allowed object is {@link JPAEntityTypesMapType }
- *
- */
- public void setJPAEntityTypes(final JPAEntityTypesMapType value) {
- jpaEntityTypes = value;
- }
-
- /**
- * Gets the value of the jpaEmbeddableTypes property.
- *
- * @return possible object is {@link JPAEmbeddableTypesMapType }
- *
- */
- public JPAEmbeddableTypesMapType getJPAEmbeddableTypes() {
- return jpaEmbeddableTypes;
- }
-
- /**
- * Sets the value of the jpaEmbeddableTypes property.
- *
- * @param value
- * allowed object is {@link JPAEmbeddableTypesMapType }
- *
- */
- public void setJPAEmbeddableTypes(final JPAEmbeddableTypesMapType value) {
- jpaEmbeddableTypes = value;
- }
-
- /**
- * Gets the value of the name property.
- *
- * @return possible object is {@link String }
- *
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the value of the name property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setName(final String value) {
- name = value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPARelationshipMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPARelationshipMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPARelationshipMapType.java
deleted file mode 100644
index 986c187..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPARelationshipMapType.java
+++ /dev/null
@@ -1,175 +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.odata2.processor.api.jpa.model.mapping;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.XmlValue;
-
-/**
- *
- * The default name for EDM navigation property is derived from JPA relationship
- * name. This can be overriden using JPARelationshipMapType.
- *
- *
- * <p>
- * Java class for JPARelationshipMapType complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within
- * this class.
- *
- * <pre>
- * <complexType name="JPARelationshipMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="JPARelationship" maxOccurs="unbounded" minOccurs="0">
- * <complexType>
- * <simpleContent>
- * <extension base="<http://www.w3.org/2001/XMLSchema>string">
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * </extension>
- * </simpleContent>
- * </complexType>
- * </element>
- * </sequence>
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPARelationshipMapType", propOrder = { "jpaRelationship" })
-public class JPARelationshipMapType {
-
- @XmlElement(name = "JPARelationship")
- protected List<JPARelationshipMapType.JPARelationship> jpaRelationship;
-
- /**
- * Gets the value of the jpaRelationship property.
- *
- * <p>
- * This accessor method returns a reference to the live list, not a
- * snapshot. Therefore any modification you make to the returned list will
- * be present inside the JAXB object. This is why there is not a
- * <CODE>set</CODE> method for the jpaRelationship property.
- *
- * <p>
- * For example, to add a new item, do as follows:
- *
- * <pre>
- * getJPARelationship().add(newItem);
- * </pre>
- *
- *
- * <p>
- * Objects of the following type(s) are allowed in the list {@link JPARelationshipMapType.JPARelationship }
- *
- *
- */
- public List<JPARelationshipMapType.JPARelationship> getJPARelationship() {
- if (jpaRelationship == null) {
- jpaRelationship = new ArrayList<JPARelationshipMapType.JPARelationship>();
- }
- return jpaRelationship;
- }
-
- /**
- * <p>
- * Java class for anonymous complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained
- * within this class.
- *
- * <pre>
- * <complexType>
- * <simpleContent>
- * <extension base="<http://www.w3.org/2001/XMLSchema>string">
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * </extension>
- * </simpleContent>
- * </complexType>
- * </pre>
- *
- *
- */
- @XmlAccessorType(XmlAccessType.FIELD)
- @XmlType(name = "", propOrder = { "value" })
- public static class JPARelationship {
-
- @XmlValue
- protected String value;
- @XmlAttribute(name = "name", required = true)
- protected String name;
-
- /**
- * Gets the value of the value property.
- *
- * @return possible object is {@link String }
- *
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Sets the value of the value property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setValue(final String value) {
- this.value = value;
- }
-
- /**
- * Gets the value of the name property.
- *
- * @return possible object is {@link String }
- *
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the value of the name property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setName(final String value) {
- name = value;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/package-info.java
deleted file mode 100644
index 4593031..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/package-info.java
+++ /dev/null
@@ -1,28 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library - Mapping Model</h3>
- * The JPA EDM Mapping model (XML document) is represented as JAXB annotated Java Classes.
- *
- *
- */
-@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping",
- elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
-package org.apache.olingo.odata2.processor.api.jpa.model.mapping;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/package-info.java
deleted file mode 100644
index b2cf90a..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/package-info.java
+++ /dev/null
@@ -1,27 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library - JPA EDM Model</h3>
- * The library provides a set of views over the JPA/EDM element containers.
- * The views can used to access the elements that form EDM.
- *
- *
- */
-package org.apache.olingo.odata2.processor.api.jpa.model;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/package-info.java
deleted file mode 100644
index 89f4974..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/package-info.java
+++ /dev/null
@@ -1,33 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library</h3>
- * The library provides a way for the developers to create an OData Service from a Java Persistence Model.
- * The library supports Java Persistence 2.0 and is dependent on OData library.
- *
- * To create an OData service from JPA models
- * <ol><li>extend the service factory class {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory}
- * and implement the methods</li>
- * <li>define a JAX-RS servlet in web.xml and configure the service factory as servlet init parameter.
- * <p><b>See Also:</b>{@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory}</li></ol>
- *
- *
- */
-package org.apache.olingo.odata2.processor.api.jpa;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/resources/JPAEDMMappingModel.xsd
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/resources/JPAEDMMappingModel.xsd b/odata2-jpa-processor/jpa-api/src/main/resources/JPAEDMMappingModel.xsd
index 07abdbf..9d8acd2 100644
--- a/odata2-jpa-processor/jpa-api/src/main/resources/JPAEDMMappingModel.xsd
+++ b/odata2-jpa-processor/jpa-api/src/main/resources/JPAEDMMappingModel.xsd
@@ -19,8 +19,8 @@
-->
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping"
- xmlns:tns="http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping">
+ targetNamespace="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping"
+ xmlns:tns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
<xs:element name="JPAEDMMappingModel">
<xs:annotation>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/pom.xml b/odata2-jpa-processor/jpa-core/pom.xml
index 7cc8b0a..941d6e4 100644
--- a/odata2-jpa-processor/jpa-core/pom.xml
+++ b/odata2-jpa-processor/jpa-core/pom.xml
@@ -58,7 +58,7 @@
<configuration>
<instructions>
<Import-Package>*</Import-Package>
- <Export-Package>org.apache.olingo.odata2.processor.core.jpa.factory;version=${project.version}</Export-Package>
+ <Export-Package>org.apache.olingo.odata2.jpa.processor.core.factory;version=${project.version}</Export-Package>
<Bundle-DocURL>${project.url}</Bundle-DocURL>
<Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataEntityParser.java
new file mode 100644
index 0000000..3823e2c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataEntityParser.java
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
+import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
+import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.uri.PathSegment;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.UriParser;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+
+public final class ODataEntityParser {
+
+ private ODataJPAContext context;
+
+ public ODataEntityParser(final ODataJPAContext context) {
+ this.context = context;
+ }
+
+ public final ODataEntry parseEntry(final EdmEntitySet entitySet,
+ final InputStream content, final String requestContentType, final boolean merge)
+ throws ODataBadRequestException {
+ ODataEntry entryValues;
+ try {
+ EntityProviderReadProperties entityProviderProperties =
+ EntityProviderReadProperties.init().mergeSemantic(merge).build();
+ entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, entityProviderProperties);
+ } catch (EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+ return entryValues;
+
+ }
+
+ public final UriInfo parseLinkURI() throws ODataJPARuntimeException {
+ UriInfo uriInfo = null;
+
+ Edm edm;
+ try {
+ edm = context.getODataContext().getService().getEntityDataModel();
+
+ List<PathSegment> pathSegments = context.getODataContext().getPathInfo().getODataSegments();
+ List<PathSegment> subPathSegments = pathSegments.subList(0, pathSegments.size() - 2);
+
+ uriInfo = UriParser.parse(edm, subPathSegments, Collections.<String, String> emptyMap());
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return uriInfo;
+ }
+
+ public final UriInfo parseLink(final EdmEntitySet entitySet, final InputStream content, final String contentType)
+ throws ODataJPARuntimeException {
+
+ String uriString = null;
+ UriInfo uri = null;
+
+ try {
+ uriString = EntityProvider.readLink(contentType, entitySet, content);
+ ODataContext odataContext = context.getODataContext();
+ final String serviceRoot = odataContext.getPathInfo().getServiceRoot().toString();
+
+ final String path =
+ uriString.startsWith(serviceRoot.toString()) ? uriString.substring(serviceRoot.length()) : uriString;
+
+ final PathSegment pathSegment = new PathSegment() {
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ @Override
+ public Map<String, List<String>> getMatrixParameters() {
+ return null;
+ }
+ };
+
+ final Edm edm = odataContext.getService().getEntityDataModel();
+
+ uri = UriParser.parse(edm, Arrays.asList(pathSegment), Collections.<String, String> emptyMap());
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return uri;
+
+ }
+
+ public List<UriInfo> parseLinks(final EdmEntitySet entitySet, final InputStream content, final String contentType)
+ throws ODataJPARuntimeException {
+
+ List<String> uriList = new ArrayList<String>();
+ List<UriInfo> uriInfoList = new ArrayList<UriInfo>();
+
+ try {
+
+ uriList = EntityProvider.readLinks(contentType, entitySet, content);
+ ODataContext odataContext = context.getODataContext();
+ final String serviceRoot = odataContext.getPathInfo().getServiceRoot().toString();
+ final int length = serviceRoot.length();
+ final Edm edm = odataContext.getService().getEntityDataModel();
+
+ for (String uriString : uriList) {
+ final String path = uriString.startsWith(serviceRoot) ? uriString.substring(length) : uriString;
+
+ final PathSegment pathSegment = new PathSegment() {
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ @Override
+ public Map<String, List<String>> getMatrixParameters() {
+ return null;
+ }
+ };
+
+ UriInfo uriInfo = UriParser.parse(edm, Arrays.asList(pathSegment), Collections.<String, String> emptyMap());
+ uriInfoList.add(uriInfo);
+ }
+ } catch (EntityProviderException e) {
+ return null;
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return uriInfoList;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
new file mode 100644
index 0000000..7da1e90
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParser.java
@@ -0,0 +1,381 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
+import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodOperator;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+import org.apache.olingo.odata2.api.uri.expression.SortOrder;
+import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+
+/**
+ * This class contains utility methods for parsing the filter expressions built by core library from user OData Query.
+ *
+ *
+ *
+ */
+public class ODataExpressionParser {
+
+ public static final String EMPTY = ""; //$NON-NLS-1$
+ public static Integer methodFlag = 0;
+
+ /**
+ * This method returns the parsed where condition corresponding to the filter input in the user query.
+ *
+ * @param whereExpression
+ *
+ * @return Parsed where condition String
+ * @throws ODataException
+ */
+
+ public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias)
+ throws ODataException {
+ switch (whereExpression.getKind()) {
+ case UNARY:
+ final UnaryExpression unaryExpression = (UnaryExpression) whereExpression;
+ final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias);
+
+ switch (unaryExpression.getOperator()) {
+ case NOT:
+ return JPQLStatement.Operator.NOT + "(" + operand + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ case MINUS:
+ if (operand.startsWith("-")) {
+ return operand.substring(1);
+ } else {
+ return "-" + operand; //$NON-NLS-1$
+ }
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ case FILTER:
+ return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias);
+ case BINARY:
+ final BinaryExpression binaryExpression = (BinaryExpression) whereExpression;
+ if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD)
+ && ((binaryExpression.getOperator() == BinaryOperator.EQ) ||
+ (binaryExpression.getOperator() == BinaryOperator.NE))
+ && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) {
+ methodFlag = 1;
+ }
+ final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias);
+ final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias);
+
+ switch (binaryExpression.getOperator()) {
+ case AND:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE
+ + right;
+ case OR:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right;
+ case EQ:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right;
+ case NE:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right;
+ case LT:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right;
+ case LE:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right;
+ case GT:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right;
+ case GE:
+ return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right;
+ case PROPERTY_ACCESS:
+ throw new ODataNotImplementedException();
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ case PROPERTY:
+ String returnStr =
+ tableAlias + JPQLStatement.DELIMITER.PERIOD
+ + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName();
+ return returnStr;
+
+ case MEMBER:
+ String memberExpStr = EMPTY;
+ int i = 0;
+ MemberExpression member = null;
+ CommonExpression tempExp = whereExpression;
+ while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) {
+ member = (MemberExpression) tempExp;
+ if (i > 0) {
+ memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr;
+ }
+ i++;
+ memberExpStr =
+ ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName()
+ + memberExpStr;
+ tempExp = member.getPath();
+ }
+ memberExpStr =
+ ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName()
+ + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
+ return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
+
+ case LITERAL:
+ final LiteralExpression literal = (LiteralExpression) whereExpression;
+ final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
+ String value =
+ literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
+ literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null);
+ return evaluateComparingExpression(value, literalType);
+
+ case METHOD:
+ final MethodExpression methodExpression = (MethodExpression) whereExpression;
+ String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias);
+ final String second =
+ methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1),
+ tableAlias) : null;
+ String third =
+ methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2),
+ tableAlias) : null;
+
+ switch (methodExpression.getMethod()) {
+ case SUBSTRING:
+ third = third != null ? ", " + third : "";
+ return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third);
+ case SUBSTRINGOF:
+ first = first.substring(1, first.length() - 1);
+ if (methodFlag == 1) {
+ methodFlag = 0;
+ return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first);
+ } else {
+ return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first);
+ }
+ case TOLOWER:
+ return String.format("LOWER(%s)", first);
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ default:
+ throw new ODataNotImplementedException();
+ }
+ }
+
+ /**
+ * This method parses the select clause
+ *
+ * @param tableAlias
+ * @param selectedFields
+ * @return a select expression
+ */
+ public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) {
+
+ if ((selectedFields == null) || (selectedFields.size() == 0)) {
+ return tableAlias;
+ }
+
+ String selectClause = EMPTY;
+ Iterator<String> itr = selectedFields.iterator();
+ int count = 0;
+
+ while (itr.hasNext()) {
+ selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next();
+ count++;
+
+ if (count < selectedFields.size()) {
+ selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE;
+ }
+ }
+ return selectClause;
+ }
+
+ /**
+ * This method parses the order by condition in the query.
+ *
+ * @param orderByExpression
+ * @return a map of JPA attributes and their sort order
+ * @throws ODataJPARuntimeException
+ */
+ public static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression,
+ final String tableAlias) throws ODataJPARuntimeException {
+ HashMap<String, String> orderByMap = new HashMap<String, String>();
+ if (orderByExpression != null && orderByExpression.getOrders() != null) {
+ List<OrderExpression> orderBys = orderByExpression.getOrders();
+ String orderByField = null;
+ String orderByDirection = null;
+ for (OrderExpression orderBy : orderBys) {
+
+ try {
+ orderByField =
+ ((EdmProperty) ((PropertyExpression) orderBy.getExpression()).getEdmProperty()).getMapping()
+ .getInternalName();
+ orderByDirection = (orderBy.getSortOrder() == SortOrder.asc) ? EMPTY : "DESC"; //$NON-NLS-1$
+ orderByMap.put(tableAlias + JPQLStatement.DELIMITER.PERIOD + orderByField, orderByDirection);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ }
+ }
+ return orderByMap;
+ }
+
+ /**
+ * This method evaluated the where expression for read of an entity based on the keys specified in the query.
+ *
+ * @param keyPredicates
+ * @return the evaluated where expression
+ */
+
+ public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias)
+ throws ODataJPARuntimeException {
+ String literal = null;
+ String propertyName = null;
+ EdmSimpleType edmSimpleType = null;
+ StringBuilder keyFilters = new StringBuilder();
+ int i = 0;
+ for (KeyPredicate keyPredicate : keyPredicates) {
+ if (i > 0) {
+ keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE);
+ }
+ i++;
+ literal = keyPredicate.getLiteral();
+ try {
+ propertyName = keyPredicate.getProperty().getMapping().getInternalName();
+ edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType();
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ literal = evaluateComparingExpression(literal, edmSimpleType);
+
+ if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
+ literal = literal.substring(literal.indexOf('\''), literal.indexOf('}'));
+ }
+
+ keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE
+ + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal);
+ }
+ if (keyFilters.length() > 0) {
+ return keyFilters.toString();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * This method evaluates the expression based on the type instance. Used for adding escape characters where necessary.
+ *
+ * @param value
+ * @param edmSimpleType
+ * @return the evaluated expression
+ * @throws ODataJPARuntimeException
+ */
+ private static String evaluateComparingExpression(String value, final EdmSimpleType edmSimpleType)
+ throws ODataJPARuntimeException {
+
+ if (edmSimpleType == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || edmSimpleType == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()) {
+ value = "\'" + value + "\'"; //$NON-NLS-1$ //$NON-NLS-2$
+ } else if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
+ try {
+ Calendar datetime =
+ (Calendar) edmSimpleType.valueOfString(value, EdmLiteralKind.DEFAULT, null, edmSimpleType.getDefaultType());
+
+ String year = String.format("%04d", datetime.get(Calendar.YEAR));
+ String month = String.format("%02d", datetime.get(Calendar.MONTH) + 1);
+ String day = String.format("%02d", datetime.get(Calendar.DAY_OF_MONTH));
+ String hour = String.format("%02d", datetime.get(Calendar.HOUR_OF_DAY));
+ String min = String.format("%02d", datetime.get(Calendar.MINUTE));
+ String sec = String.format("%02d", datetime.get(Calendar.SECOND));
+
+ value =
+ JPQLStatement.DELIMITER.LEFT_BRACE + JPQLStatement.KEYWORD.TIMESTAMP + JPQLStatement.DELIMITER.SPACE + "\'"
+ + year + JPQLStatement.DELIMITER.HYPHEN + month + JPQLStatement.DELIMITER.HYPHEN + day
+ + JPQLStatement.DELIMITER.SPACE + hour + JPQLStatement.DELIMITER.COLON + min
+ + JPQLStatement.DELIMITER.COLON + sec + JPQLStatement.KEYWORD.OFFSET + "\'"
+ + JPQLStatement.DELIMITER.RIGHT_BRACE;
+
+ } catch (EdmSimpleTypeException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ } else if (edmSimpleType == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ try {
+ Calendar time =
+ (Calendar) edmSimpleType.valueOfString(value, EdmLiteralKind.DEFAULT, null, edmSimpleType.getDefaultType());
+
+ String hourValue = String.format("%02d", time.get(Calendar.HOUR_OF_DAY));
+ String minValue = String.format("%02d", time.get(Calendar.MINUTE));
+ String secValue = String.format("%02d", time.get(Calendar.SECOND));
+
+ value =
+ "\'" + hourValue + JPQLStatement.DELIMITER.COLON + minValue + JPQLStatement.DELIMITER.COLON + secValue
+ + "\'";
+ } catch (EdmSimpleTypeException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ } else if (edmSimpleType == EdmSimpleTypeKind.Int64.getEdmSimpleTypeInstance()) {
+ value = value + JPQLStatement.DELIMITER.LONG; //$NON-NLS-1$
+ }
+ return value;
+ }
+
+ public static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(
+ final List<EdmProperty> edmPropertylist, final String tableAlias) throws ODataJPARuntimeException {
+ HashMap<String, String> orderByMap = new HashMap<String, String>();
+ String propertyName = null;
+ for (EdmProperty edmProperty : edmPropertylist) {
+ try {
+ EdmMapping mapping = edmProperty.getMapping();
+ if (mapping != null && mapping.getInternalName() != null) {
+ propertyName = mapping.getInternalName();// For embedded/complex keys
+ } else {
+ propertyName = edmProperty.getName();
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ orderByMap.put(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName, EMPTY);
+ }
+ return orderByMap;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
new file mode 100644
index 0000000..fe8c45f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImpl.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+
+public class ODataJPAContextImpl implements ODataJPAContext {
+
+ private String pUnitName;
+ private EntityManagerFactory emf;
+ private EntityManager em;
+ private ODataContext odataContext;
+ private ODataProcessor processor;
+ private EdmProvider edmProvider;
+ private String jpaEdmMappingModelName;
+ private JPAEdmExtension jpaEdmExtension;
+ private static final ThreadLocal<ODataContext> oDataContextThreadLocal = new ThreadLocal<ODataContext>();
+ private boolean defaultNaming = true;
+
+ @Override
+ public String getPersistenceUnitName() {
+ return pUnitName;
+ }
+
+ @Override
+ public void setPersistenceUnitName(final String pUnitName) {
+ this.pUnitName = pUnitName;
+ }
+
+ @Override
+ public EntityManagerFactory getEntityManagerFactory() {
+ return emf;
+ }
+
+ @Override
+ public void setEntityManagerFactory(final EntityManagerFactory emf) {
+ this.emf = emf;
+ }
+
+ @Override
+ public void setODataContext(final ODataContext ctx) {
+ odataContext = ctx;
+ setContextInThreadLocal(odataContext);
+ }
+
+ @Override
+ public ODataContext getODataContext() {
+ return odataContext;
+ }
+
+ @Override
+ public void setODataProcessor(final ODataProcessor processor) {
+ this.processor = processor;
+ }
+
+ @Override
+ public ODataProcessor getODataProcessor() {
+ return processor;
+ }
+
+ @Override
+ public void setEdmProvider(final EdmProvider edmProvider) {
+ this.edmProvider = edmProvider;
+ }
+
+ @Override
+ public EdmProvider getEdmProvider() {
+ return edmProvider;
+ }
+
+ @Override
+ public void setJPAEdmMappingModel(final String name) {
+ jpaEdmMappingModelName = name;
+
+ }
+
+ @Override
+ public String getJPAEdmMappingModel() {
+ return jpaEdmMappingModelName;
+ }
+
+ public static void setContextInThreadLocal(final ODataContext ctx) {
+ oDataContextThreadLocal.set(ctx);
+ }
+
+ public static void unsetContextInThreadLocal() {
+ oDataContextThreadLocal.remove();
+ }
+
+ public static ODataContext getContextInThreadLocal() {
+ return (ODataContext) oDataContextThreadLocal.get();
+ }
+
+ @Override
+ public EntityManager getEntityManager() {
+ if (em == null) {
+ em = emf.createEntityManager();
+ }
+
+ return em;
+ }
+
+ @Override
+ public void setJPAEdmExtension(final JPAEdmExtension jpaEdmExtension) {
+ this.jpaEdmExtension = jpaEdmExtension;
+
+ }
+
+ @Override
+ public JPAEdmExtension getJPAEdmExtension() {
+ return jpaEdmExtension;
+ }
+
+ @Override
+ public void setDefaultNaming(final boolean defaultNaming) {
+ this.defaultNaming = defaultNaming;
+ }
+
+ @Override
+ public boolean getDefaultNaming() {
+ return defaultNaming;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
new file mode 100644
index 0000000..320fce7
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
@@ -0,0 +1,194 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException;
+
+public class ODataJPAProcessorDefault extends ODataJPAProcessor {
+
+ public ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext) {
+ super(oDataJPAContext);
+ if (oDataJPAContext == null) {
+ throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
+ }
+ }
+
+ @Override
+ public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
+ throws ODataException {
+
+ List<?> jpaEntities = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(jpaEntities, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
+ throws ODataException {
+
+ Object jpaEntity = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
+ throws ODataException {
+
+ long jpaEntityCount = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntityCount, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+
+ long jpaEntityCount = jpaProcessor.process(uriInfo);
+
+ ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntityCount, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+
+ List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
+ final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+
+ Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
+
+ ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType)
+ throws ODataException {
+
+ Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
+
+ ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView);
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriParserResultView,
+ final String contentType) throws ODataException {
+
+ List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(resultEntity, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriParserResultView,
+ final String contentType) throws ODataException {
+
+ List<Object> result = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(result, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriParserResultView, final String contentType)
+ throws ODataException {
+
+ Object jpaEntity = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriParserResultView, final String contentType)
+ throws ODataException {
+
+ List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
+
+ ODataResponse oDataResponse =
+ ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
+
+ return oDataResponse;
+ }
+
+ @Override
+ public ODataResponse createEntityLink(final PostUriInfo uriParserResultView, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+
+ jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+
+ jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java
new file mode 100644
index 0000000..f63e9d3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java
@@ -0,0 +1,629 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.UriParser;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAExpandCallBack;
+
+public final class ODataJPAResponseBuilder {
+
+ /* Response for Read Entity Set */
+ public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView,
+ final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException {
+
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+ List<ArrayList<NavigationPropertySegment>> expandList = null;
+
+ try {
+ edmEntityType = resultsView.getTargetEntitySet().getEntityType();
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmPropertyValueMap = null;
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ final List<SelectItem> selectedItems = resultsView.getSelect();
+ if (selectedItems != null && selectedItems.size() > 0) {
+ for (Object jpaEntity : jpaEntities) {
+ edmPropertyValueMap =
+ jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, edmEntityType));
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ } else {
+ for (Object jpaEntity : jpaEntities) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ }
+ expandList = resultsView.getExpand();
+ if (expandList != null && expandList.size() != 0) {
+ int count = 0;
+ List<EdmNavigationProperty> edmNavPropertyList = constructListofNavProperty(expandList);
+ for (Object jpaEntity : jpaEntities) {
+ Map<String, Object> relationShipMap = edmEntityList.get(count);
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, edmNavPropertyList);
+ relationShipMap.putAll(navigationMap);
+ count++;
+ }
+ }
+
+ EntityProviderWriteProperties feedProperties = null;
+
+ feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList);
+ odataResponse =
+ EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties);
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
+
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Read Entity */
+ public static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView,
+ final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
+ ODataNotFoundException {
+
+ List<ArrayList<NavigationPropertySegment>> expandList = null;
+ if (jpaEntity == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ edmEntityType = resultsView.getTargetEntitySet().getEntityType();
+ Map<String, Object> edmPropertyValueMap = null;
+
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ final List<SelectItem> selectedItems = resultsView.getSelect();
+ if (selectedItems != null && selectedItems.size() > 0) {
+ edmPropertyValueMap =
+ jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, resultsView
+ .getTargetEntitySet().getEntityType()));
+ } else {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
+ }
+
+ expandList = resultsView.getExpand();
+ if (expandList != null && expandList.size() != 0) {
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, constructListofNavProperty(expandList));
+ edmPropertyValueMap.putAll(navigationMap);
+ }
+ EntityProviderWriteProperties feedProperties = null;
+ feedProperties = getEntityProviderProperties(oDataJPAContext, resultsView);
+ odataResponse =
+ EntityProvider.writeEntry(contentType, resultsView.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
+
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
+
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for $count */
+ public static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext)
+ throws ODataJPARuntimeException {
+
+ ODataResponse odataResponse = null;
+ try {
+ odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount));
+ odataResponse = ODataResponse.fromResponse(odataResponse).build();
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ return odataResponse;
+ }
+
+ /* Response for Create Entity */
+ @SuppressWarnings("unchecked")
+ public static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo,
+ final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
+ ODataNotFoundException {
+
+ if (createdObjectList == null || createdObjectList.size() == 0 || createdObjectList.get(0) == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ edmEntityType = uriInfo.getTargetEntitySet().getEntityType();
+ Map<String, Object> edmPropertyValueMap = null;
+
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(createdObjectList.get(0), edmEntityType);
+
+ List<ArrayList<NavigationPropertySegment>> expandList = null;
+ if (createdObjectList.get(1) != null
+ && ((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1)).size() > 0) {
+ expandList = getExpandList((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1));
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(createdObjectList.get(0),
+ constructListofNavProperty(expandList));
+ edmPropertyValueMap.putAll(navigationMap);
+ }
+ EntityProviderWriteProperties feedProperties = null;
+ try {
+ feedProperties = getEntityProviderPropertiesforPost(oDataJPAContext, uriInfo, expandList);
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ odataResponse =
+ EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
+
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.CREATED).build();
+
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Update Entity */
+ public static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo)
+ throws ODataJPARuntimeException, ODataNotFoundException {
+ if (updatedObject == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
+ }
+
+ /* Response for Delete Entity */
+ public static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo)
+ throws ODataJPARuntimeException, ODataNotFoundException {
+
+ if (deletedObject == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
+ }
+
+ /* Response for Function Import Single Result */
+ public static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView)
+ throws ODataJPARuntimeException {
+
+ try {
+ final EdmFunctionImport functionImport = resultsView.getFunctionImport();
+ final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
+
+ if (result != null) {
+ ODataResponse response = null;
+
+ final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null);
+ response = EntityProvider.writeText(value);
+
+ return ODataResponse.fromResponse(response).build();
+ } else {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ }
+
+ /* Response for Function Import Multiple Result */
+ public static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView,
+ final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
+ ODataNotFoundException {
+
+ ODataResponse odataResponse = null;
+
+ if (resultList != null && !resultList.isEmpty()) {
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ EdmType edmType = null;
+ EdmFunctionImport functionImport = null;
+ Map<String, Object> edmPropertyValueMap = null;
+ List<Map<String, Object>> edmEntityList = null;
+ Object result = null;
+ try {
+ EntityProviderWriteProperties feedProperties = null;
+
+ feedProperties =
+ EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
+ .build();
+
+ functionImport = resultsView.getFunctionImport();
+ edmType = functionImport.getReturnType().getType();
+
+ if (edmType.getKind().equals(EdmTypeKind.ENTITY) || edmType.getKind().equals(EdmTypeKind.COMPLEX)) {
+ if (functionImport.getReturnType().getMultiplicity().equals(EdmMultiplicity.MANY)) {
+ edmEntityList = new ArrayList<Map<String, Object>>();
+ for (Object jpaEntity : resultList) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, (EdmStructuralType) edmType);
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ result = edmEntityList;
+ } else {
+
+ Object resultObject = resultList.get(0);
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(resultObject, (EdmStructuralType) edmType);
+
+ result = edmPropertyValueMap;
+ }
+
+ } else if (edmType.getKind().equals(EdmTypeKind.SIMPLE)) {
+ result = resultList.get(0);
+ }
+
+ odataResponse =
+ EntityProvider.writeFunctionImport(contentType, resultsView.getFunctionImport(), result, feedProperties);
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ } else {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Read Entity Link */
+ public static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView,
+ final String contentType, final ODataJPAContext oDataJPAContext) throws ODataNotFoundException,
+ ODataJPARuntimeException {
+
+ if (jpaEntity == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ EdmEntitySet entitySet = resultsView.getTargetEntitySet();
+ edmEntityType = entitySet.getEntityType();
+ Map<String, Object> edmPropertyValueMap = null;
+
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType.getKeyProperties());
+
+ EntityProviderWriteProperties entryProperties =
+ EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
+ .build();
+
+ ODataResponse response = EntityProvider.writeLink(contentType, entitySet, edmPropertyValueMap, entryProperties);
+
+ odataResponse = ODataResponse.fromResponse(response).build();
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Read Entity Links */
+ public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView,
+ final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException {
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ EdmEntitySet entitySet = resultsView.getTargetEntitySet();
+ edmEntityType = entitySet.getEntityType();
+ List<EdmProperty> keyProperties = edmEntityType.getKeyProperties();
+
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmPropertyValueMap = null;
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+
+ for (Object jpaEntity : jpaEntities) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, keyProperties);
+ edmEntityList.add(edmPropertyValueMap);
+ }
+
+ Integer count = null;
+ if (resultsView.getInlineCount() != null) {
+ if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
+ // when $skip and/or $top is present with $inlinecount
+ count = getInlineCountForNonFilterQueryLinks(edmEntityList, resultsView);
+ } else {
+ // In all other cases
+ count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
+ }
+ }
+
+ ODataContext context = oDataJPAContext.getODataContext();
+ EntityProviderWriteProperties entryProperties =
+ EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).inlineCountType(
+ resultsView.getInlineCount()).inlineCount(count).build();
+
+ odataResponse = EntityProvider.writeLinks(contentType, entitySet, edmEntityList, entryProperties);
+
+ odataResponse = ODataResponse.fromResponse(odataResponse).build();
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+
+ }
+
+ /*
+ * This method handles $inlinecount request. It also modifies the list of results in case of
+ * $inlinecount and $top/$skip combinations. Specific to LinksUriInfo.
+ *
+ * @param edmEntityList
+ *
+ * @param resultsView
+ *
+ * @return
+ */
+ private static Integer getInlineCountForNonFilterQueryLinks(final List<Map<String, Object>> edmEntityList,
+ final GetEntitySetLinksUriInfo resultsView) {
+ // when $skip and/or $top is present with $inlinecount, first get the total count
+ Integer count = null;
+ if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
+ if (resultsView.getSkip() != null || resultsView.getTop() != null) {
+ count = edmEntityList.size();
+ // Now update the list
+ if (resultsView.getSkip() != null) {
+ // Index checks to avoid IndexOutOfBoundsException
+ if (resultsView.getSkip() > edmEntityList.size()) {
+ edmEntityList.clear();
+ return count;
+ }
+ edmEntityList.subList(0, resultsView.getSkip()).clear();
+ }
+ if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
+ edmEntityList.subList(0, resultsView.getTop());
+ }
+ }
+ }// Inlinecount of None is handled by default - null
+ return count;
+ }
+
+ /*
+ * Method to build the entity provider Property.Callbacks for $expand would
+ * be registered here
+ */
+ private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
+ final GetEntitySetUriInfo resultsView, final List<Map<String, Object>> edmEntityList)
+ throws ODataJPARuntimeException {
+ ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
+
+ Integer count = null;
+ if (resultsView.getInlineCount() != null) {
+ if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
+ // when $skip and/or $top is present with $inlinecount
+ count = getInlineCountForNonFilterQueryEntitySet(edmEntityList, resultsView);
+ } else {
+ // In all other cases
+ count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
+ }
+ }
+
+ try {
+ entityFeedPropertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
+ entityFeedPropertiesBuilder.inlineCount(count);
+ entityFeedPropertiesBuilder.inlineCountType(resultsView.getInlineCount());
+ ExpandSelectTreeNode expandSelectTree =
+ UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
+ entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
+ .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
+ entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return entityFeedPropertiesBuilder.build();
+ }
+
+ /*
+ * This method handles $inlinecount request. It also modifies the list of results in case of
+ * $inlinecount and $top/$skip combinations. Specific to Entity Set.
+ */
+ private static Integer getInlineCountForNonFilterQueryEntitySet(final List<Map<String, Object>> edmEntityList,
+ final GetEntitySetUriInfo resultsView) {
+ // when $skip and/or $top is present with $inlinecount, first get the total count
+ Integer count = null;
+ if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
+ if (resultsView.getSkip() != null || resultsView.getTop() != null) {
+ count = edmEntityList.size();
+ // Now update the list
+ if (resultsView.getSkip() != null) {
+ // Index checks to avoid IndexOutOfBoundsException
+ if (resultsView.getSkip() > edmEntityList.size()) {
+ edmEntityList.clear();
+ return count;
+ }
+ edmEntityList.subList(0, resultsView.getSkip()).clear();
+ }
+ if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
+ edmEntityList.retainAll(edmEntityList.subList(0, resultsView.getTop()));
+ }
+ }
+ }// Inlinecount of None is handled by default - null
+ return count;
+ }
+
+ private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
+ final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
+ ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
+ ExpandSelectTreeNode expandSelectTree = null;
+ try {
+ entityFeedPropertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
+ expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
+ entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
+ entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
+ .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return entityFeedPropertiesBuilder.build();
+ }
+
+ private static EntityProviderWriteProperties getEntityProviderPropertiesforPost(
+ final ODataJPAContext odataJPAContext, final PostUriInfo resultsView,
+ final List<ArrayList<NavigationPropertySegment>> expandList) throws ODataJPARuntimeException {
+ ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
+ ExpandSelectTreeNode expandSelectTree = null;
+ try {
+ entityFeedPropertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
+ expandSelectTree = UriParser.createExpandSelectTree(null, expandList);
+ entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
+ entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
+ .getPathInfo().getServiceRoot(), expandSelectTree, expandList));
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return entityFeedPropertiesBuilder.build();
+ }
+
+ private static List<ArrayList<NavigationPropertySegment>> getExpandList(
+ final Map<EdmNavigationProperty, EdmEntitySet> navPropEntitySetMap) {
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navigationPropertySegmentList = new ArrayList<NavigationPropertySegment>();
+ for (Map.Entry<EdmNavigationProperty, EdmEntitySet> entry : navPropEntitySetMap.entrySet()) {
+ final EdmNavigationProperty edmNavigationProperty = entry.getKey();
+ final EdmEntitySet edmEntitySet = entry.getValue();
+ NavigationPropertySegment navigationPropertySegment = new NavigationPropertySegment() {
+
+ @Override
+ public EdmEntitySet getTargetEntitySet() {
+ return edmEntitySet;
+ }
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty() {
+ return edmNavigationProperty;
+ }
+ };
+ navigationPropertySegmentList.add(navigationPropertySegment);
+ }
+ expandList.add(navigationPropertySegmentList);
+ return expandList;
+ }
+
+ private static List<EdmProperty> buildSelectItemList(final List<SelectItem> selectItems, final EdmEntityType entity)
+ throws ODataJPARuntimeException {
+ boolean flag = false;
+ List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
+ try {
+ for (SelectItem selectItem : selectItems) {
+ selectPropertyList.add(selectItem.getProperty());
+ }
+ for (EdmProperty keyProperty : entity.getKeyProperties()) {
+ flag = true;
+ for (SelectItem selectedItem : selectItems) {
+ if (selectedItem.getProperty().equals(keyProperty)) {
+ flag = false;
+ break;
+ }
+ }
+ if (flag == true) {
+ selectPropertyList.add(keyProperty);
+ }
+ }
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ return selectPropertyList;
+ }
+
+ private static List<EdmNavigationProperty> constructListofNavProperty(
+ final List<ArrayList<NavigationPropertySegment>> expandList) {
+ List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
+ for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) {
+ navigationPropertyList.add(navpropSegment.get(0).getNavigationProperty());
+ }
+ return navigationPropertyList;
+ }
+
+}
[45/47] git commit: [OLINGO-83] Renamed test packages
Posted by tb...@apache.org.
[OLINGO-83] Renamed test packages
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/80dc018d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/80dc018d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/80dc018d
Branch: refs/heads/ODataServlet
Commit: 80dc018d1e447dafc0e1918fab71d8d29e3aac93
Parents: 80379ec
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Dec 20 16:10:24 2013 +0100
Committer: Tamara Boehm <ta...@sap.com>
Committed: Thu Jan 2 13:36:47 2014 +0100
----------------------------------------------------------------------
.../core/AnnotationServiceFactoryImpl.java | 12 +-
.../core/AnnotationServiceFactoryImplTest.java | 74 +++
.../datasource/AnnotationsInMemoryDsTest.java | 628 +++++++++++++++++++
.../core/edm/AnnotationEdmProviderTest.java | 463 ++++++++++++++
.../processor/core/model/Building.java | 99 +++
.../annotation/processor/core/model/City.java | 61 ++
.../processor/core/model/Employee.java | 187 ++++++
.../processor/core/model/Location.java | 60 ++
.../processor/core/model/Manager.java | 47 ++
.../core/model/ModelSharedConstants.java | 25 +
.../annotation/processor/core/model/Photo.java | 128 ++++
.../processor/core/model/RefBase.java | 55 ++
.../processor/core/model/ResourceHelper.java | 66 ++
.../annotation/processor/core/model/Room.java | 93 +++
.../annotation/processor/core/model/Team.java | 81 +++
.../data/AnnotationsInMemoryDsTest.java | 628 -------------------
.../edm/AnnotationEdmProviderTest.java | 462 --------------
.../odata2/core/annotation/model/Building.java | 99 ---
.../odata2/core/annotation/model/City.java | 61 --
.../odata2/core/annotation/model/Employee.java | 187 ------
.../odata2/core/annotation/model/Location.java | 60 --
.../odata2/core/annotation/model/Manager.java | 47 --
.../annotation/model/ModelSharedConstants.java | 25 -
.../odata2/core/annotation/model/Photo.java | 128 ----
.../odata2/core/annotation/model/RefBase.java | 55 --
.../core/annotation/model/ResourceHelper.java | 66 --
.../odata2/core/annotation/model/Room.java | 93 ---
.../odata2/core/annotation/model/Team.java | 81 ---
28 files changed, 2068 insertions(+), 2003 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
index 9c673a3..7947d6b 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
@@ -29,20 +29,10 @@ import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.rt.RuntimeDelegate;
/**
- * ODataServiceFactory implementation based on ListProcessor
+ * AnnotationServiceFactoryInstance (ODataServiceFactory) implementation based on ListProcessor
* in combination with Annotation-Support-Classes for EdmProvider, DataSource and ValueAccess.
*/
public class AnnotationServiceFactoryImpl implements AnnotationServiceFactoryInstance {
-
- /**
- * Create an instance which further can create an {@link ODataService}.
- *
- * @return instance which further can create an {@link ODataService}.
- */
- public AnnotationServiceFactoryInstance createInstance() {
- return new AnnotationServiceFactoryImpl();
- }
-
/**
* {@inheritDoc}
*/
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java
new file mode 100644
index 0000000..4feaac7
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.annotation.processor.core.model.Employee;
+import org.apache.olingo.odata2.annotation.processor.core.model.Manager;
+import org.apache.olingo.odata2.annotation.processor.core.model.Photo;
+import org.apache.olingo.odata2.annotation.processor.core.model.RefBase;
+import org.apache.olingo.odata2.annotation.processor.core.model.Room;
+import org.apache.olingo.odata2.annotation.processor.core.model.Team;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AnnotationServiceFactoryImplTest {
+
+ @Test
+ public void createFromPackage() throws ODataException {
+ AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
+ ODataService service = factory.createAnnotationService(Building.class.getPackage().getName());
+
+ Assert.assertNotNull(service);
+ }
+
+ @Test
+ public void createFromAnnotatedClasses() throws ODataException {
+ AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
+ final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+ annotatedClasses.add(RefBase.class);
+ annotatedClasses.add(Building.class);
+ annotatedClasses.add(Employee.class);
+ annotatedClasses.add(Manager.class);
+ annotatedClasses.add(Photo.class);
+ annotatedClasses.add(Room.class);
+ annotatedClasses.add(Team.class);
+ ODataService service = factory.createAnnotationService(annotatedClasses);
+
+ Assert.assertNotNull(service);
+ }
+
+ @Test(expected=ODataException.class)
+ public void createFromClasses() throws ODataException {
+ AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
+
+ final Collection<Class<?>> notAnnotatedClasses = new ArrayList<Class<?>>();
+ notAnnotatedClasses.add(String.class);
+ notAnnotatedClasses.add(Long.class);
+ ODataService service = factory.createAnnotationService(notAnnotatedClasses);
+
+ Assert.assertNotNull(service);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
new file mode 100644
index 0000000..b9ebcb3
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
@@ -0,0 +1,628 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.datasource;
+
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataStore;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource.BinaryData;
+import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.annotation.processor.core.model.ModelSharedConstants;
+import org.apache.olingo.odata2.annotation.processor.core.model.Photo;
+import org.apache.olingo.odata2.annotation.processor.core.model.Room;
+import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class AnnotationsInMemoryDsTest {
+
+ private final AnnotationInMemoryDs datasource;
+ private final AnnotationEdmProvider edmProvider;
+ private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
+
+ public AnnotationsInMemoryDsTest() throws ODataException {
+ datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
+ edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
+ }
+
+ @Test
+ @Ignore
+ public void multiThreadedSyncOnBuildingsTest() throws Exception {
+ final EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ CountDownLatch latch;
+
+ List<Thread> threads = new ArrayList<Thread>();
+ int max = 500;
+
+ latch = new CountDownLatch(max);
+ for (int i = 0; i < max; i++) {
+ threads.add(createBuildingThread(latch, datasource, edmEntitySet, String.valueOf("10")));
+ }
+
+ for (Thread thread : threads) {
+ thread.start();
+ }
+
+ latch.await(60, TimeUnit.SECONDS);
+
+ DataStore<Building> ds = datasource.getDataStore(Building.class);
+ Collection<Building> buildings = ds.read();
+ Assert.assertEquals(max, buildings.size());
+ }
+
+ @org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet
+ @org.apache.olingo.odata2.api.annotation.edm.EdmEntityType
+ private static class SimpleEntity {
+ @EdmKey
+ @EdmProperty
+ public Integer id;
+ @EdmProperty
+ public String name;
+ }
+
+ @Test
+ @Ignore
+ public void multiThreadedSyncCreateReadTest() throws Exception {
+ Collection<Class<?>> ac = new ArrayList<Class<?>>();
+ ac.add(SimpleEntity.class);
+ final AnnotationInMemoryDs localDs = new AnnotationInMemoryDs(SimpleEntity.class.getPackage().getName(), true);
+ final AnnotationEdmProvider localProvider = new AnnotationEdmProvider(ac);
+ final EdmEntitySet edmEntitySet = createMockedEdmEntitySet(localProvider, "SimpleEntitySet");
+ final CountDownLatch latch;
+
+ List<Thread> threads = new ArrayList<Thread>();
+ int max = 500;
+ latch = new CountDownLatch(max);
+ for (int i = 0; i < max; i++) {
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ SimpleEntity se = new SimpleEntity();
+ se.id = Integer.valueOf(String.valueOf(System.currentTimeMillis()).substring(8));
+ se.name = "Name: " + System.currentTimeMillis();
+ try {
+ localDs.createData(edmEntitySet, se);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }finally{
+ latch.countDown();
+ }
+ }
+ };
+
+ threads.add(new Thread(run));
+ }
+
+ for (Thread thread : threads) {
+ thread.start();
+ }
+
+ latch.await(60, TimeUnit.SECONDS);
+
+ DataStore<SimpleEntity> ds = localDs.getDataStore(SimpleEntity.class);
+ Collection<SimpleEntity> buildings = ds.read();
+ Assert.assertEquals(max, buildings.size());
+ }
+
+ private Thread createBuildingThread(final CountDownLatch latch, final DataSource datasource,
+ final EdmEntitySet edmEntitySet, final String id) {
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ Building building = new Building();
+ building.setName("Common Building - " + System.currentTimeMillis());
+ building.setId(id);
+ try {
+ datasource.createData(edmEntitySet, building);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ } finally {
+ latch.countDown();
+ }
+ }
+ };
+
+ return new Thread(run);
+ }
+
+ @Test
+ public void readBinaryData() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
+ Photo photo = new Photo();
+ photo.setName("SomePic");
+ photo.setType("PNG");
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ photo.setImage(image);
+ photo.setImageType("image/png");
+ photoDataStore.create(photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Name", "SomePic");
+ keys.put("ImageFormat", "PNG");
+ Photo toReadPhoto = (Photo) datasource.readData(entitySet, keys);
+
+ // execute
+ BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
+
+ // validate
+ Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
+ Assert.assertArrayEquals(image, readBinaryData.getData());
+ Assert.assertEquals("image/png", readBinaryData.getMimeType());
+ }
+
+ @Test
+ public void readBinaryDataDirect() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
+ Photo photo = new Photo();
+ photo.setName("SomePic");
+ photo.setType("PNG");
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ photo.setImage(image);
+ photo.setImageType("image/png");
+ photoDataStore.create(photo);
+
+ Photo toReadPhoto = new Photo();
+ toReadPhoto.setName("SomePic");
+ toReadPhoto.setType("PNG");
+ toReadPhoto.setImage(null);
+ toReadPhoto.setImageType(null);
+
+ BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
+
+ Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
+ Assert.assertArrayEquals(image, readBinaryData.getData());
+ Assert.assertEquals("image/png", readBinaryData.getMimeType());
+ }
+
+
+ @Test
+ public void writeBinaryData() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
+
+ Photo toWritePhoto = new Photo();
+ toWritePhoto.setName("SomePic");
+ toWritePhoto.setType("PNG");
+ photoDataStore.create(toWritePhoto);
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ String mimeType = "image/png";
+ BinaryData writeBinaryData = new BinaryData(image, mimeType);
+ // execute
+ datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
+
+ // validate
+ Photo photoKey = new Photo();
+ photoKey.setName("SomePic");
+ photoKey.setType("PNG");
+ Photo storedPhoto = photoDataStore.read(photoKey);
+ Assert.assertEquals("binary", new String(storedPhoto.getImage(), Charset.defaultCharset()));
+ Assert.assertArrayEquals(image, storedPhoto.getImage());
+ Assert.assertEquals("image/png", storedPhoto.getImageType());
+ }
+
+ @Test(expected=ODataNotFoundException.class)
+ public void writeBinaryDataNotFound() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ Photo toWritePhoto = new Photo();
+ toWritePhoto.setName("SomePic");
+ toWritePhoto.setType("PNG");
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ String mimeType = "image/png";
+ BinaryData writeBinaryData = new BinaryData(image, mimeType);
+ // execute
+ datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
+ }
+
+
+ @Test
+ public void newDataObject() throws Exception {
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+ Room room = (Room) datasource.newDataObject(roomsEntitySet);
+
+ Assert.assertNotNull(room);
+ }
+
+ @Test
+ public void readEntity() throws Exception {
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 3;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ building.getRooms().addAll(rooms);
+ datasource.createData(buildingsEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ // execute
+ Object relatedData = datasource.readData(buildingsEntitySet, keys);
+
+ // validate
+ Building readBuilding = (Building) relatedData;
+ Assert.assertEquals("Common Building", readBuilding.getName());
+ Assert.assertEquals("1", readBuilding.getId());
+
+ Collection<Room> relatedRooms = readBuilding.getRooms();
+ Assert.assertEquals(roomsCount, relatedRooms.size());
+ for (Room room : relatedRooms) {
+ Assert.assertNotNull(room.getId());
+ Assert.assertTrue(room.getName().matches("Room \\d*"));
+ Assert.assertEquals("Common Building", room.getBuilding().getName());
+ }
+ }
+
+ @Test
+ public void readEntities() throws Exception {
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 11;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ // execute
+ Object relatedData = datasource.readData(roomsEntitySet);
+
+ // validate
+ @SuppressWarnings("unchecked")
+ Collection<Room> relatedRooms = (Collection<Room>) relatedData;
+ Assert.assertEquals(roomsCount, relatedRooms.size());
+ for (Room room : relatedRooms) {
+ Assert.assertNotNull(room.getId());
+ Assert.assertTrue(room.getName().matches("Room \\d*"));
+ Assert.assertEquals("Common Building", room.getBuilding().getName());
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void readRelatedEntities() throws Exception {
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 10;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ building.getRooms().addAll(rooms);
+ datasource.createData(buildingsEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(buildingsEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+
+ // execute
+ Object relatedData = datasource.readRelatedData(
+ buildingsEntitySet, building, roomsEntitySet, Collections.EMPTY_MAP);
+
+ // validate
+ Assert.assertTrue("Result is no collection.", relatedData instanceof Collection);
+ Collection<Room> relatedRooms = (Collection<Room>) relatedData;
+ Assert.assertEquals(roomsCount, relatedRooms.size());
+ for (Room room : relatedRooms) {
+ Assert.assertNotNull(room.getId());
+ Assert.assertTrue(room.getName().matches("Room \\d*"));
+ Assert.assertEquals("Common Building", room.getBuilding().getName());
+ }
+ }
+
+ @Test
+ public void readRelatedTargetEntity() throws Exception {
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 10;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ building.getRooms().addAll(rooms);
+ datasource.createData(buildingsEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(buildingsEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+
+ // execute
+ Map<String, Object> targetKeys = new HashMap<String, Object>();
+ targetKeys.put("Id", 3);
+ Object relatedData = datasource.readRelatedData(
+ buildingsEntitySet, building, roomsEntitySet, targetKeys);
+
+ // validate
+ Assert.assertTrue("Result is no Room.", relatedData instanceof Room);
+ Room relatedRoom = (Room) relatedData;
+ Assert.assertEquals("3", relatedRoom.getId());
+ Assert.assertEquals("Room 3", relatedRoom.getName());
+ Assert.assertEquals("Common Building", relatedRoom.getBuilding().getName());
+ }
+
+ @Test
+ public void createSimpleEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+ }
+
+ @Test
+ public void createSimpleEntityWithOwnKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ AnnotationHelper ah = new AnnotationHelper();
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "42");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("42", read.getId());
+ }
+
+ @Test
+ public void createSimpleEntityWithDuplicateKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ AnnotationHelper ah = new AnnotationHelper();
+
+ Building building = new Building();
+ building.setName("Common Building");
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+ //
+ Building buildingDuplicate = new Building();
+ buildingDuplicate.setName("Duplicate Building");
+ ah.setValueForProperty(buildingDuplicate, "Id", "42");
+ datasource.createData(edmEntitySet, buildingDuplicate);
+
+ Map<String, Object> keys42 = new HashMap<String, Object>();
+ keys42.put("Id", "42");
+ Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
+ Assert.assertEquals("Common Building", read42.getName());
+ Assert.assertEquals("42", read42.getId());
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Duplicate Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+ }
+
+ @Test
+ public void createEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
+ Photo photo = new Photo();
+ photo.setName("BigPicture");
+ photo.setType("PNG");
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("ImageFormat", "PNG");
+ keys.put("Name", "BigPicture");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+ }
+
+ @Test
+ public void createAndUpdateEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
+ Photo photo = new Photo();
+ final String nameKeyValue = "BigPicture";
+ final String typeKeyValue = "PNG";
+ photo.setName(nameKeyValue);
+ photo.setType(typeKeyValue);
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Name", "BigPicture");
+ keys.put("ImageFormat", "PNG");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+
+ // update
+ Photo updatedPhoto = new Photo();
+ updatedPhoto.setName(nameKeyValue);
+ updatedPhoto.setType(typeKeyValue);
+ updatedPhoto.setImageUri("https://localhost/image.jpg");
+ updatedPhoto.setImageType("image/jpg");
+ datasource.updateData(edmEntitySet, updatedPhoto);
+
+ Map<String, Object> updatedKeys = new HashMap<String, Object>();
+ updatedKeys.put("Name", nameKeyValue);
+ updatedKeys.put("ImageFormat", typeKeyValue);
+
+ Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
+ Assert.assertEquals("BigPicture", readUpdated.getName());
+ Assert.assertEquals("PNG", readUpdated.getType());
+ Assert.assertEquals("image/jpg", readUpdated.getImageType());
+ Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
+ }
+
+
+ @Test
+ public void deleteSimpleEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ DataStore<Building> datastore = datasource.getDataStore(Building.class);
+
+ Building building = new Building();
+ building.setName("Common Building");
+ datastore.create(building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+
+ //
+ datasource.deleteData(edmEntitySet, keys);
+
+ // validate
+ try {
+ Building readAfterDelete = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.fail("Expected " + ODataNotFoundException.class + "was not thrown for '" + readAfterDelete + "'.");
+ } catch (ODataNotFoundException e) { }
+ }
+
+ @Test(expected=ODataRuntimeException.class)
+ public void unknownEntitySetForEntity() throws Exception {
+ String entitySetName = "Unknown";
+ FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+ //
+ datasource.readData(edmEntitySet, keys);
+ }
+
+ @Test(expected=ODataRuntimeException.class)
+ public void unknownEntitySetForEntities() throws Exception {
+ String entitySetName = "Unknown";
+ FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ //
+ datasource.readData(edmEntitySet);
+ }
+
+
+ private EdmEntitySet createMockedEdmEntitySet(final String entitySetName) throws ODataException {
+ return createMockedEdmEntitySet(edmProvider, entitySetName);
+ }
+
+ private EdmEntitySet createMockedEdmEntitySet(AnnotationEdmProvider edmProvider, final String entitySetName)
+ throws ODataException {
+ EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
+ FullQualifiedName entityType = entitySet.getEntityType();
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ return edmEntitySet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
new file mode 100644
index 0000000..7c35fca
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
@@ -0,0 +1,463 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.edm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.annotation.processor.core.model.City;
+import org.apache.olingo.odata2.annotation.processor.core.model.Employee;
+import org.apache.olingo.odata2.annotation.processor.core.model.Location;
+import org.apache.olingo.odata2.annotation.processor.core.model.Manager;
+import org.apache.olingo.odata2.annotation.processor.core.model.ModelSharedConstants;
+import org.apache.olingo.odata2.annotation.processor.core.model.Photo;
+import org.apache.olingo.odata2.annotation.processor.core.model.RefBase;
+import org.apache.olingo.odata2.annotation.processor.core.model.Room;
+import org.apache.olingo.odata2.annotation.processor.core.model.Team;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AnnotationEdmProviderTest {
+
+ private static final String TEST_MODEL_PACKAGE = "org.apache.olingo.odata2.annotation.processor.core.model";
+
+ @EdmEntityType
+ @EdmEntitySet
+ private static final class GeneratedNamesTestClass {}
+
+ @EdmComplexType
+ private static final class GeneratedNamesComplexTestClass {}
+
+ @EdmEntityType(namespace = "MyTestNamespace")
+ @EdmEntitySet(container = "MyTestContainer")
+ private static final class DefinedNamesTestClass {}
+
+ private final AnnotationEdmProvider aep;
+ private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+
+ public AnnotationEdmProviderTest() {
+ annotatedClasses.add(RefBase.class);
+ annotatedClasses.add(Building.class);
+ annotatedClasses.add(City.class);
+ annotatedClasses.add(Employee.class);
+ annotatedClasses.add(Location.class);
+ annotatedClasses.add(Manager.class);
+ annotatedClasses.add(Photo.class);
+ annotatedClasses.add(Room.class);
+ annotatedClasses.add(Team.class);
+
+ aep = new AnnotationEdmProvider(annotatedClasses);
+ }
+
+ @Test
+ public void defaultNamespaceGeneration() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testType = localAep.getEntityType(new FullQualifiedName(
+ GeneratedNamesTestClass.class.getPackage().getName(),
+ GeneratedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultNamespaceGenerationComplexType() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ ComplexType testType = localAep.getComplexType(new FullQualifiedName(
+ GeneratedNamesComplexTestClass.class.getPackage().getName(),
+ GeneratedNamesComplexTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesComplexTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameGeneration() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep =
+ new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("DefaultContainer", containerInfo.getName());
+ }
+
+ @Test
+ public void defaultNamespaceDefined() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(DefinedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
+ DefinedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testClass);
+ assertEquals("DefinedNamesTestClass", testClass.getName());
+ assertNull("This should not have a base type", testClass.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameDefined() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("MyTestContainer", containerInfo.getName());
+ }
+
+ @Test
+ public void loadAnnotatedClassesFromPackage() throws Exception {
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(TEST_MODEL_PACKAGE);
+
+ // validate employee
+ EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(6, employee.getProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ List<Schema> schemas = localAep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+ }
+
+ @Test
+ public void annotationProviderBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+
+ FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
+ assertNull(funImp);
+
+ final FullQualifiedName associationFqn = new FullQualifiedName(
+ ModelSharedConstants.NAMESPACE_1, "NoAssociation");
+ Association noAssociation = aep.getAssociation(associationFqn);
+ assertNull(noAssociation);
+
+ AssociationSet noAssociationSet = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
+ assertNull(noAssociationSet);
+
+ AssociationSet asBuildingRooms = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
+ assertNotNull(asBuildingRooms);
+ assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
+ assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
+ assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
+ assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
+ }
+
+ @Test
+ public void annotationProviderGetDefaultContainer() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(null);
+ assertTrue(info.isDefaultEntityContainer());
+ assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
+ }
+
+ @Test
+ public void schemaBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+
+ Schema schema = schemas.get(0);
+ List<EntityContainer> containers = schema.getEntityContainers();
+ assertEquals(1, containers.size());
+ EntityContainer container = containers.get(0);
+ assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
+ final List<EntitySet> entitySets = container.getEntitySets();
+ assertEquals(6, entitySets.size());
+
+ List<Association> associations = schema.getAssociations();
+ assertEquals(4, associations.size());
+ for (Association association : associations) {
+ assertNotNull(association.getName());
+ validateAssociation(association);
+ }
+ }
+
+ private FullQualifiedName defaultFqn(final String name) {
+ return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
+ }
+
+ private void validateAssociation(final Association association) {
+ String name = association.getName();
+ if (name.equals("r_Employee-r_Room")) {
+ validateAssociation(association,
+ "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if (name.equals("BuildingRooms")) {
+ validateAssociation(association,
+ "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
+ "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
+ } else if (name.equals("ManagerEmployees")) {
+ validateAssociation(association,
+ "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if (name.equals("TeamEmployees")) {
+ validateAssociation(association,
+ "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else {
+ fail("Got unknown association to validate with name '" + name + "'.");
+ }
+ }
+
+ private void validateAssociation(final Association association,
+ final String fromRole, final EdmMultiplicity fromMulti, final FullQualifiedName fromType,
+ final String toRole, final EdmMultiplicity toMulti, final FullQualifiedName toType) {
+
+ AssociationEnd[] ends = new AssociationEnd[] { association.getEnd1(), association.getEnd2() };
+ for (AssociationEnd associationEnd : ends) {
+ if (associationEnd.getRole().equals(fromRole)) {
+ validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
+ } else if (associationEnd.getRole().equals(toRole)) {
+ validateAssociationEnd(associationEnd, toRole, toMulti, toType);
+ } else {
+ fail("Unexpected navigation end '" + associationEnd.getRole()
+ + "' for association with name '" + association.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateAssociationEnd(final AssociationEnd associationEnd,
+ final String role, final EdmMultiplicity multiplicity, final FullQualifiedName type) {
+ assertEquals(role, associationEnd.getRole());
+ assertEquals(multiplicity, associationEnd.getMultiplicity());
+ assertEquals(type, associationEnd.getType());
+ }
+
+ @Test
+ public void entitySetTeams() throws Exception {
+ // validate teams
+ EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
+ assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
+ assertEquals("Team", teams.getEntityType().getName());
+ }
+
+ @Test
+ public void entityTypeEmployee() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(6, employee.getProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
+ if (navigationProperty.getName().equals("ne_Manager")) {
+ validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
+ } else if (navigationProperty.getName().equals("ne_Team")) {
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
+ } else if (navigationProperty.getName().equals("ne_Room")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+ }
+
+ @Test
+ public void entityTypeTeam() throws Exception {
+ // validate team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+
+ assertEquals(1, team.getProperties().size());
+ assertEquals(1, team.getNavigationProperties().size());
+ NavigationProperty navigationProperty = team.getNavigationProperties().get(0);
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
+ }
+
+ @Test
+ public void entityTypePhotoWithTwoKeyProperties() throws Exception {
+ // validate team
+ EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
+ assertEquals("Photo", photo.getName());
+ final List<Property> properties = photo.getProperties();
+ assertEquals(5, properties.size());
+ assertTrue(containsProperty(properties, "Name"));
+ assertTrue(containsProperty(properties, "ImageFormat"));
+ assertTrue(containsProperty(properties, "MimeType"));
+ assertTrue(containsProperty(properties, "ImageUrl"));
+ assertTrue(containsProperty(properties, "Image"));
+ assertFalse(photo.isAbstract());
+ assertTrue(photo.isHasStream());
+
+ Key photoKey = photo.getKey();
+ List<PropertyRef> keyReferences = photoKey.getKeys();
+ assertEquals(2, keyReferences.size());
+ PropertyRef name = getPropertyRef(keyReferences, "Name");
+ assertEquals("Name", name.getName());
+ PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
+ assertEquals("ImageFormat", imageFormat.getName());
+
+// assertEquals(0, photo.getNavigationProperties().size());
+ assertNull(photo.getNavigationProperties());
+ }
+
+ @Test
+ public void entityTypeAbstractBaseType() throws Exception {
+ // validate employee
+ EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
+ assertEquals("Base", baseType.getName());
+ final List<PropertyRef> keys = baseType.getKey().getKeys();
+ assertEquals(1, keys.size());
+ assertEquals("Id", keys.get(0).getName());
+ assertEquals(2, baseType.getProperties().size());
+ assertTrue(baseType.isAbstract());
+
+ // validate base for team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+ }
+
+ @Test
+ public void complexTypeLocation() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ final List<Property> properties = employee.getProperties();
+ Property location = null;
+ for (Property property : properties) {
+ if (property.getName().equals("Location")) {
+ location = property;
+ }
+ }
+ assertNotNull(location);
+ assertEquals("Location", location.getName());
+
+ // validate location complex type
+ ComplexType locationType = aep.getComplexType(
+ new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
+ assertEquals("c_Location", locationType.getName());
+ assertEquals(2, locationType.getProperties().size());
+ }
+
+ @Test
+ public void entityTypeRoomWithNavigation() throws Exception {
+ // validate employee
+ EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
+ assertEquals("Room", room.getName());
+ assertEquals("Base", room.getBaseType().getName());
+ assertEquals(2, room.getProperties().size());
+ final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
+ assertEquals(2, navigationProperties.size());
+
+ for (NavigationProperty navigationProperty : navigationProperties) {
+ if (navigationProperty.getName().equals("nr_Employees")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
+ } else if (navigationProperty.getName().equals("nr_Building")) {
+ validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateNavProperty(final NavigationProperty navigationProperty, final String name,
+ final String relationship, final String fromRole, final String toRole) {
+ if (name != null) {
+ assertEquals(name, navigationProperty.getName());
+ }
+ FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
+ assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
+ assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
+ assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
+ }
+
+ private void validateNavProperty(final NavigationProperty navigationProperty,
+ final String relationship, final String fromRole, final String toRole) {
+ validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
+ }
+
+ private boolean containsProperty(final List<Property> properties, final String propertyName) {
+ return getProperty(properties, propertyName) != null;
+ }
+
+ private Property getProperty(final List<Property> properties, final String name) {
+ for (Property property : properties) {
+ if (name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ private PropertyRef getPropertyRef(final List<PropertyRef> properties, final String name) {
+ for (PropertyRef property : properties) {
+ if (name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java
new file mode 100644
index 0000000..bc9f54b
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Buildings")
+public class Building {
+ @EdmKey
+ @EdmProperty(type = EdmType.INT32)
+ private String id;
+ @EdmProperty
+ private String name;
+ @EdmProperty(name = "Image", type = EdmType.BINARY)
+ private byte[] image;
+ @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
+ association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
+ private List<Room> rooms = new ArrayList<Room>();
+
+ public Building() {}
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setImage(final byte[] byteArray) {
+ image = byteArray;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ } else {
+ return image.clone();
+ }
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ @Override
+ public int hashCode() {
+ return id == null ? 0 : id.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java
new file mode 100644
index 0000000..2e630ba
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexType(name = "c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+public class City {
+
+ @EdmProperty
+ private String postalCode;
+ @EdmProperty
+ private String cityName;
+
+ public City(final String postalCode, final String name) {
+ this.postalCode = postalCode;
+ cityName = name;
+ }
+
+ public void setPostalCode(final String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setCityName(final String cityName) {
+ this.cityName = cityName;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", cityName, postalCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java
new file mode 100644
index 0000000..136a2e1
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Employees")
+public class Employee {
+ @EdmKey
+ @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
+ private String employeeId;
+ @EdmProperty(name = "EmployeeName")
+ private String employeeName;
+ @EdmProperty
+ private int age;
+ @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
+ private Manager manager;
+ @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
+ private Team team;
+ @EdmNavigationProperty(name = "ne_Room")
+ private Room room;
+ @EdmMediaResourceMimeType
+ private String imageType;
+ @EdmMediaResourceContent
+ private byte[] image;
+ @EdmProperty(name = "ImageUrl")
+ private String imageUrl;
+ @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
+ private Calendar entryDate;
+ @EdmProperty(name = "Location")
+ private Location location;
+
+ public Employee(final String employeeId, final String name) {
+ this.employeeId = employeeId;
+ setEmployeeName(name);
+ }
+
+ public String getId() {
+ return employeeId;
+ }
+
+ public void setEmployeeName(final String employeeName) {
+ this.employeeName = employeeName;
+ }
+
+ public String getEmployeeName() {
+ return employeeName;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setManager(final Manager manager) {
+ this.manager = manager;
+ }
+
+ public Manager getManager() {
+ return manager;
+ }
+
+ public void setTeam(final Team team) {
+ this.team = team;
+ }
+
+ public Team getTeam() {
+ return team;
+ }
+
+ public void setRoom(final Room room) {
+ this.room = room;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public void setImageUri(final String imageUri) {
+ imageUrl = imageUri;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setLocation(final Location location) {
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setEntryDate(final Calendar date) {
+ entryDate = date;
+ }
+
+ public Calendar getEntryDate() {
+ return entryDate;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ }
+ return image.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ if (employeeId == null) {
+ return 0;
+ }
+ return employeeId.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"EmployeeId\":\"" + employeeId + "\","
+ + "\"EmployeeName\":\"" + employeeName + "\","
+ + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
+ + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
+ + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
+ + "\"Location\":"
+ + (location == null ? "null" :
+ "{\"City\":" + (location.getCity() == null ? "null" :
+ "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
+ + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
+ + "\"Country\":\"" + location.getCountry() + "\"}") + ","
+ + "\"Age\":" + age + ","
+ + "\"EntryDate\":"
+ + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
+ + "\"ImageUrl\":\"" + imageUrl + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java
new file mode 100644
index 0000000..99f56c9
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+public class Location {
+ @EdmProperty
+ private String country;
+ @EdmProperty
+ private City city;
+
+ public Location(final String country, final String postalCode, final String cityName) {
+ this.country = country;
+ city = new City(postalCode, cityName);
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCity(final City city) {
+ this.city = city;
+ }
+
+ public City getCity() {
+ return city;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", country, city.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java
new file mode 100644
index 0000000..cd894f0
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers")
+public class Manager extends Employee {
+
+ @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
+ toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Manager(final String id, final String name) {
+ super(id, name);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java
new file mode 100644
index 0000000..bd4d3d4
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+public interface ModelSharedConstants {
+
+ String NAMESPACE_1 = "RefScenario";
+ String CONTAINER_1 = "DefaultContainer";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java
new file mode 100644
index 0000000..83be665
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
+public class Photo {
+ @EdmProperty
+ @EdmKey
+ private String name;
+ @EdmProperty(name = "ImageFormat")
+ @EdmKey
+ private String type;
+ @EdmProperty
+ @EdmMediaResourceMimeType
+ private String mimeType;
+ @EdmProperty
+ @EdmMediaResourceSource
+ private String imageUrl = "http://localhost/someResource.png";
+ @EdmProperty(type = EdmType.BINARY)
+ @EdmMediaResourceContent
+ private byte[] image = ResourceHelper.generateImage();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setImageUri(final String uri) {
+ imageUrl = uri;
+ }
+
+ public byte[] getImage() {
+ return image.clone();
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public String getImageType() {
+ return mimeType;
+ }
+
+ public void setImageType(final String imageType) {
+ mimeType = imageType;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 83 * hash + (name != null ? name.hashCode() : 0);
+ hash = 83 * hash + (type != null ? type.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Photo other = (Photo) obj;
+ if ((name == null) ? (other.name != null) : !name.equals(other.name)) {
+ return false;
+ }
+ if ((type == null) ? (other.type != null) : !type.equals(other.type)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Name\":\"" + name + "\","
+ + "\"Type\":\"" + type + "\","
+ + "\"ImageUrl\":\"" + imageUrl + "\","
+ + "\"Image\":\"" + Arrays.toString(image) + "\","
+ + "\"MimeType\":\"" + mimeType + "\"";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java
new file mode 100644
index 0000000..e998efc
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Base", namespace = ModelSharedConstants.NAMESPACE_1)
+public abstract class RefBase {
+ @EdmProperty(name = "Name")
+ protected String name;
+ @EdmProperty(name = "Id", type = EdmType.STRING)
+ @EdmKey
+ protected int id;
+
+ public RefBase(final int id, final String name) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public void setId(final int id) {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java
new file mode 100644
index 0000000..f9e9d88
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+/**
+ *
+ */
+public class ResourceHelper {
+
+ public enum Format {
+ BMP, JPEG, PNG, GIF
+ };
+
+ public static byte[] generateImage() {
+ return generateImage(Format.PNG);
+ }
+
+ public static byte[] generateImage(final Format format) {
+ try {
+ int width = 320;
+ int height = 320;
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+ WritableRaster raster = image.getRaster();
+
+ int mod = format.ordinal() + 2;
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
+ raster.setSample(w, h, 0, 0);
+ } else {
+ raster.setSample(w, h, 0, 1);
+ }
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+ ImageIO.write(image, format.name(), out);
+ return out.toByteArray();
+ } catch (IOException ex) {
+ return new byte[0];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java
new file mode 100644
index 0000000..57e42db
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms")
+public class Room extends RefBase {
+
+ @EdmProperty
+ private Integer seats;
+ @EdmProperty
+ private Integer version;
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
+ private Building building;
+ @EdmNavigationProperty(name = "nr_Employees")
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Room() {
+ this(0, null);
+ }
+
+ public Room(final int id, final String name) {
+ super(id, name);
+ }
+
+ public void setSeats(final int seats) {
+ this.seats = seats;
+ }
+
+ public int getSeats() {
+ return seats;
+ }
+
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setBuilding(final Building building) {
+ this.building = building;
+ }
+
+ public Building getBuilding() {
+ return building;
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
+ }
+}
[32/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilder.java
new file mode 100644
index 0000000..40ceeba
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilder.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLJoinContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+
+public class JPQLJoinStatementBuilder extends JPQLStatementBuilder {
+
+ JPQLStatement jpqlStatement;
+ private JPQLJoinContextView context;
+
+ public JPQLJoinStatementBuilder(final JPQLContextView context) {
+ this.context = (JPQLJoinContextView) context;
+ }
+
+ @Override
+ public JPQLStatement build() throws ODataJPARuntimeException {
+ jpqlStatement = createStatement(createJPQLQuery());
+ return jpqlStatement;
+
+ }
+
+ private String createJPQLQuery() throws ODataJPARuntimeException {
+
+ StringBuilder jpqlQuery = new StringBuilder();
+ StringBuilder joinWhereCondition = null;
+
+ jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
+ if (context.getType().equals(JPQLContextType.JOIN_COUNT)) {// $COUNT
+ jpqlQuery.append(JPQLStatement.KEYWORD.COUNT).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_LEFT).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_RIGHT).append(JPQLStatement.DELIMITER.SPACE);
+ } else { // Normal
+ jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
+ }
+
+ jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
+
+ if (context.getJPAJoinClauses() != null && context.getJPAJoinClauses().size() > 0) {
+ List<JPAJoinClause> joinClauseList = context.getJPAJoinClauses();
+ JPAJoinClause joinClause = joinClauseList.get(0);
+ String joinCondition = joinClause.getJoinCondition();
+ joinWhereCondition = new StringBuilder();
+ if (joinCondition != null) {
+ joinWhereCondition.append(joinCondition);
+ }
+ String relationShipAlias = null;
+ joinClause = joinClauseList.get(1);
+ jpqlQuery.append(joinClause.getEntityName()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(joinClause.getEntityAlias());
+
+ int i = 1;
+ int limit = joinClauseList.size();
+ relationShipAlias = joinClause.getEntityAlias();
+ while (i < limit) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.JOIN).append(JPQLStatement.DELIMITER.SPACE);
+
+ joinClause = joinClauseList.get(i);
+ jpqlQuery.append(relationShipAlias).append(JPQLStatement.DELIMITER.PERIOD);
+ jpqlQuery.append(joinClause.getEntityRelationShip()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(joinClause.getEntityRelationShipAlias());
+
+ relationShipAlias = joinClause.getEntityRelationShipAlias();
+ i++;
+
+ joinCondition = joinClause.getJoinCondition();
+ if (joinCondition != null) {
+ joinWhereCondition.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND
+ + JPQLStatement.DELIMITER.SPACE);
+
+ joinWhereCondition.append(joinCondition);
+ }
+ }
+ } else {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED, null);
+ }
+ String whereExpression = context.getWhereExpression();
+ if (whereExpression != null || joinWhereCondition.length() > 0) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.KEYWORD.WHERE).append(
+ JPQLStatement.DELIMITER.SPACE);
+ if (whereExpression != null) {
+ jpqlQuery.append(whereExpression);
+ if (joinWhereCondition != null) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE);
+ }
+ }
+ if (joinWhereCondition != null) {
+ jpqlQuery.append(joinWhereCondition.toString());
+ }
+
+ }
+
+ if (context.getOrderByCollection() != null && context.getOrderByCollection().size() > 0) {
+
+ StringBuilder orderByBuilder = new StringBuilder();
+ Iterator<Entry<String, String>> orderItr = context.getOrderByCollection().entrySet().iterator();
+
+ int i = 0;
+
+ while (orderItr.hasNext()) {
+ if (i != 0) {
+ orderByBuilder.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.DELIMITER.COMMA).append(
+ JPQLStatement.DELIMITER.SPACE);
+ }
+ Entry<String, String> entry = orderItr.next();
+ orderByBuilder.append(entry.getKey()).append(JPQLStatement.DELIMITER.SPACE);
+ orderByBuilder.append(entry.getValue());
+ i++;
+ }
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.KEYWORD.ORDERBY).append(
+ JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(orderByBuilder);
+ }
+
+ return jpqlQuery.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContext.java
new file mode 100644
index 0000000..61d2801
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContext.java
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.HashMap;
+
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLSelectContextView;
+import org.apache.olingo.odata2.jpa.processor.core.ODataExpressionParser;
+
+public class JPQLSelectContext extends JPQLContext implements JPQLSelectContextView {
+
+ protected String selectExpression;
+ protected HashMap<String, String> orderByCollection;
+ protected String whereCondition;
+
+ protected boolean isCountOnly = false;// Support for $count
+
+ public JPQLSelectContext(final boolean isCountOnly) {
+ this.isCountOnly = isCountOnly;
+ }
+
+ protected final void setOrderByCollection(final HashMap<String, String> orderByCollection) {
+ this.orderByCollection = orderByCollection;
+ }
+
+ protected final void setWhereExpression(final String filterExpression) {
+ whereCondition = filterExpression;
+ }
+
+ protected final void setSelectExpression(final String selectExpression) {
+ this.selectExpression = selectExpression;
+ }
+
+ @Override
+ public String getSelectExpression() {
+ return selectExpression;
+ }
+
+ @Override
+ public HashMap<String, String> getOrderByCollection() {
+ return orderByCollection;
+ }
+
+ @Override
+ public String getWhereExpression() {
+ return whereCondition;
+ }
+
+ public class JPQLSelectContextBuilder extends
+ org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder {
+
+ protected GetEntitySetUriInfo entitySetView;
+
+ @Override
+ public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
+ if (entitySetView != null) {
+
+ try {
+
+ if (isCountOnly) {
+ setType(JPQLContextType.SELECT_COUNT);
+ } else {
+ setType(JPQLContextType.SELECT);
+ }
+ EdmEntityType entityType = entitySetView.getTargetEntitySet().getEntityType();
+ EdmMapping mapping = entityType.getMapping();
+ if (mapping != null) {
+ setJPAEntityName(mapping.getInternalName());
+ } else {
+ setJPAEntityName(entityType.getName());
+ }
+
+ setJPAEntityAlias(generateJPAEntityAlias());
+
+ setOrderByCollection(generateOrderByFileds());
+
+ setSelectExpression(generateSelectExpression());
+
+ setWhereExpression(generateWhereExpression());
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ }
+
+ return JPQLSelectContext.this;
+
+ }
+
+ @Override
+ protected void setResultsView(final Object resultsView) {
+ if (resultsView instanceof GetEntitySetUriInfo) {
+ entitySetView = (GetEntitySetUriInfo) resultsView;
+ }
+
+ }
+
+ /*
+ * Generate Select Clause
+ */
+ protected String generateSelectExpression() throws EdmException {
+ return getJPAEntityAlias();
+ }
+
+ /*
+ * Generate Order By Clause Fields
+ */
+ protected HashMap<String, String> generateOrderByFileds() throws ODataJPARuntimeException, EdmException {
+
+ if (entitySetView.getOrderBy() != null) {
+
+ return ODataExpressionParser.parseToJPAOrderByExpression(entitySetView.getOrderBy(), getJPAEntityAlias());
+
+ } else if (entitySetView.getTop() != null || entitySetView.getSkip() != null) {
+
+ return ODataExpressionParser.parseKeyPropertiesToJPAOrderByExpression(entitySetView.getTargetEntitySet()
+ .getEntityType().getKeyProperties(), getJPAEntityAlias());
+ } else {
+ return null;
+ }
+
+ }
+
+ /*
+ * Generate Where Clause Expression
+ */
+ protected String generateWhereExpression() throws ODataException {
+ if (entitySetView.getFilter() != null) {
+ return ODataExpressionParser.parseToJPAWhereExpression(entitySetView.getFilter(), getJPAEntityAlias());
+ }
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContext.java
new file mode 100644
index 0000000..ac54d2c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContext.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLSelectSingleContextView;
+
+public class JPQLSelectSingleContext extends JPQLContext implements JPQLSelectSingleContextView {
+
+ private String selectExpression;
+ private List<KeyPredicate> keyPredicates;
+
+ protected void setKeyPredicates(final List<KeyPredicate> keyPredicates) {
+ this.keyPredicates = keyPredicates;
+ }
+
+ @Override
+ public List<KeyPredicate> getKeyPredicates() {
+ return keyPredicates;
+ }
+
+ protected final void setSelectExpression(final String selectExpression) {
+ this.selectExpression = selectExpression;
+ }
+
+ @Override
+ public String getSelectExpression() {
+ return selectExpression;
+ }
+
+ public class JPQLSelectSingleContextBuilder extends
+ org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder {
+
+ protected GetEntityUriInfo entityView;
+
+ @Override
+ public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
+ if (entityView != null) {
+
+ try {
+
+ setType(JPQLContextType.SELECT_SINGLE);
+
+ EdmEntityType entityType = entityView.getTargetEntitySet().getEntityType();
+ EdmMapping mapping = entityType.getMapping();
+ if (mapping != null) {
+ setJPAEntityName(mapping.getInternalName());
+ } else {
+ setJPAEntityName(entityType.getName());
+ }
+
+ setJPAEntityAlias(generateJPAEntityAlias());
+
+ setKeyPredicates(entityView.getKeyPredicates());
+
+ setSelectExpression(generateSelectExpression());
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ }
+
+ return JPQLSelectSingleContext.this;
+
+ }
+
+ @Override
+ protected void setResultsView(final Object resultsView) {
+ if (resultsView instanceof GetEntityUriInfo) {
+ entityView = (GetEntityUriInfo) resultsView;
+ }
+
+ }
+
+ /*
+ * Generate Select Clause
+ */
+ protected String generateSelectExpression() throws EdmException {
+ return getJPAEntityAlias();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilder.java
new file mode 100644
index 0000000..4e06b9e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilder.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLSelectSingleContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.ODataExpressionParser;
+
+public class JPQLSelectSingleStatementBuilder extends JPQLStatementBuilder {
+
+ JPQLStatement jpqlStatement;
+ private JPQLSelectSingleContextView context;
+
+ public JPQLSelectSingleStatementBuilder(final JPQLContextView context) {
+ this.context = (JPQLSelectSingleContextView) context;
+ }
+
+ @Override
+ public JPQLStatement build() throws ODataJPARuntimeException {
+ jpqlStatement = createStatement(createJPQLQuery());
+ return jpqlStatement;
+
+ }
+
+ private String createJPQLQuery() throws ODataJPARuntimeException {
+
+ StringBuilder jpqlQuery = new StringBuilder();
+ String tableAlias = context.getJPAEntityAlias();
+ String fromClause = context.getJPAEntityName() + JPQLStatement.DELIMITER.SPACE + tableAlias;
+
+ jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(fromClause);
+
+ if (context.getKeyPredicates() != null && context.getKeyPredicates().size() > 0) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(ODataExpressionParser
+ .parseKeyPredicates(context.getKeyPredicates(), context.getJPAEntityAlias()));
+ }
+
+ return jpqlQuery.toString();
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilder.java
new file mode 100644
index 0000000..22dcc9a
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilder.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLSelectContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+
+public class JPQLSelectStatementBuilder extends JPQLStatementBuilder {
+
+ JPQLStatement jpqlStatement;
+ private JPQLSelectContextView context;
+
+ public JPQLSelectStatementBuilder(final JPQLContextView context) {
+ this.context = (JPQLSelectContextView) context;
+ }
+
+ @Override
+ public JPQLStatement build() throws ODataJPARuntimeException {
+ jpqlStatement = createStatement(createJPQLQuery());
+ return jpqlStatement;
+
+ }
+
+ private String createJPQLQuery() throws ODataJPARuntimeException {
+
+ StringBuilder jpqlQuery = new StringBuilder();
+ String tableAlias = context.getJPAEntityAlias();
+ String fromClause = context.getJPAEntityName() + JPQLStatement.DELIMITER.SPACE + tableAlias;
+
+ jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
+ if (context.getType().equals(JPQLContextType.SELECT_COUNT)) { // $COUNT
+ jpqlQuery.append(JPQLStatement.KEYWORD.COUNT).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_LEFT).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_RIGHT).append(JPQLStatement.DELIMITER.SPACE);
+ } else {// Normal
+ jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
+ }
+
+ jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(fromClause);
+
+ if (context.getWhereExpression() != null) {
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(context.getWhereExpression());
+ }
+
+ if (context.getOrderByCollection() != null && context.getOrderByCollection().size() > 0) {
+
+ StringBuilder orderByBuilder = new StringBuilder();
+ Iterator<Entry<String, String>> orderItr = context.getOrderByCollection().entrySet().iterator();
+
+ int i = 0;
+
+ while (orderItr.hasNext()) {
+ if (i != 0) {
+ orderByBuilder.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.DELIMITER.COMMA).append(
+ JPQLStatement.DELIMITER.SPACE);
+ }
+ Entry<String, String> entry = orderItr.next();
+ orderByBuilder.append(entry.getKey()).append(JPQLStatement.DELIMITER.SPACE);
+ orderByBuilder.append(entry.getValue());
+ i++;
+ }
+ jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(JPQLStatement.KEYWORD.ORDERBY).append(JPQLStatement.DELIMITER.SPACE);
+ jpqlQuery.append(orderByBuilder);
+ }
+
+ return jpqlQuery.toString();
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
new file mode 100644
index 0000000..537a4f8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociation.java
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView {
+
+ private JPAEdmAssociationEndView associationEndView;
+
+ private Association currentAssociation;
+ private List<Association> consistentAssociatonList;
+ private HashMap<String, Association> associationMap;
+ private HashMap<String, JPAEdmAssociationEndView> associationEndMap;
+ private List<JPAEdmReferentialConstraintView> inconsistentRefConstraintViewList;
+ private int numberOfSimilarEndPoints;
+
+ public JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
+ final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value) {
+ super(associationEndview);
+ associationEndView = associationEndview;
+ numberOfSimilarEndPoints = value;
+ init();
+ }
+
+ public JPAEdmAssociation(final JPAEdmSchemaView view) {
+ super(view);
+ init();
+ }
+
+ private void init() {
+ isConsistent = false;
+ consistentAssociatonList = new ArrayList<Association>();
+ inconsistentRefConstraintViewList = new LinkedList<JPAEdmReferentialConstraintView>();
+ associationMap = new HashMap<String, Association>();
+ associationEndMap = new HashMap<String, JPAEdmAssociationEndView>();
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmAssociationBuilder();
+ }
+ return builder;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ return currentAssociation;
+ }
+
+ @Override
+ public List<Association> getConsistentEdmAssociationList() {
+ return consistentAssociatonList;
+ }
+
+ @Override
+ public Association searchAssociation(final JPAEdmAssociationEndView view) {
+ if (view != null) {
+ for (String key : associationMap.keySet()) {
+ Association association = associationMap.get(key);
+ if (association != null) {
+ if (view.compare(association.getEnd1(), association.getEnd2())) {
+ JPAEdmAssociationEndView associationEnd = associationEndMap.get(association.getName());
+ if (associationEnd.getJoinColumnName() != null && associationEnd.getJoinColumnReferenceColumnName() != null
+ && view.getJoinColumnName() != null && view.getJoinColumnReferenceColumnName() != null) {
+ if (view.getJoinColumnName().equals(associationEnd.getJoinColumnName())
+ && view.getJoinColumnReferenceColumnName()
+ .equals(associationEnd.getJoinColumnReferenceColumnName())) {
+ currentAssociation = association;
+ return association;
+ }
+
+ }
+ if (associationEnd.getMappedByName() != null) {
+ if (associationEnd.getMappedByName().equals(view.getOwningPropertyName())) {
+ currentAssociation = association;
+ return association;
+ }
+ }
+ if (associationEnd.getOwningPropertyName() != null) {
+ if (associationEnd.getOwningPropertyName().equals(view.getMappedByName())) {
+ currentAssociation = association;
+ return association;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
+ final JPAEdmAssociationEndView associationEndView) {
+ if (associationView != null) {
+ currentAssociation = associationView.getEdmAssociation();
+ associationMap.put(currentAssociation.getName(), currentAssociation);
+ associationEndMap.put(currentAssociation.getName(), associationEndView);
+ addJPAEdmRefConstraintView(associationView.getJPAEdmReferentialConstraintView());
+ }
+ }
+
+ @Override
+ public void addJPAEdmRefConstraintView(final JPAEdmReferentialConstraintView refView) {
+ if (refView != null && refView.isExists()) {
+ inconsistentRefConstraintViewList.add(refView);
+ }
+ }
+
+ @Override
+ public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
+ if (inconsistentRefConstraintViewList.isEmpty()) {
+ return null;
+ }
+ return inconsistentRefConstraintViewList.get(0);
+ }
+
+ private class JPAEdmAssociationBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ if (associationEndView != null && searchAssociation(associationEndView) == null) {
+ currentAssociation = new Association();
+ currentAssociation.setEnd1(associationEndView.getEdmAssociationEnd1());
+ currentAssociation.setEnd2(associationEndView.getEdmAssociationEnd2());
+
+ JPAEdmNameBuilder.build(JPAEdmAssociation.this, numberOfSimilarEndPoints);
+
+ associationMap.put(currentAssociation.getName(), currentAssociation);
+
+ } else if (!inconsistentRefConstraintViewList.isEmpty()) {
+ int inconsistentRefConstraintViewSize = inconsistentRefConstraintViewList.size();
+ int index = 0;
+ for (int i = 0; i < inconsistentRefConstraintViewSize; i++) {
+ JPAEdmReferentialConstraintView view = inconsistentRefConstraintViewList.get(index);
+
+ if (view.isExists() && !view.isConsistent()) {
+ view.getBuilder().build();
+ }
+ if (view.isConsistent()) {
+ Association newAssociation = new Association();
+ copyAssociation(newAssociation, associationMap.get(view.getEdmRelationShipName()));
+ newAssociation.setReferentialConstraint(view.getEdmReferentialConstraint());
+ consistentAssociatonList.add(newAssociation);
+ associationMap.put(view.getEdmRelationShipName(), newAssociation);
+ inconsistentRefConstraintViewList.remove(index);
+ } else {
+ associationMap.remove(view.getEdmRelationShipName());
+ index++;
+ }
+ }
+ }
+
+ if (associationMap.size() == consistentAssociatonList.size()) {
+ isConsistent = true;
+ } else {
+ for (String key : associationMap.keySet()) {
+ Association association = associationMap.get(key);
+ if (!consistentAssociatonList.contains(association)) {
+ consistentAssociatonList.add(association);
+ }
+ }
+ isConsistent = true;
+ }
+
+ }
+
+ private void copyAssociation(final Association copyToAssociation, final Association copyFromAssociation) {
+ copyToAssociation.setEnd1(copyFromAssociation.getEnd1());
+ copyToAssociation.setEnd2(copyFromAssociation.getEnd2());
+ copyToAssociation.setName(copyFromAssociation.getName());
+ copyToAssociation.setAnnotationAttributes(copyFromAssociation.getAnnotationAttributes());
+ copyToAssociation.setAnnotationElements(copyFromAssociation.getAnnotationElements());
+ copyToAssociation.setDocumentation(copyFromAssociation.getDocumentation());
+
+ }
+ }
+
+ @Override
+ public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
+ int count = 0;
+ AssociationEnd currentAssociationEnd1 = view.getEdmAssociationEnd1();
+ AssociationEnd currentAssociationEnd2 = view.getEdmAssociationEnd2();
+ AssociationEnd end1 = null;
+ AssociationEnd end2 = null;
+ for (String key : associationMap.keySet()) {
+ Association association = associationMap.get(key);
+ if (association != null) {
+ end1 = association.getEnd1();
+ end2 = association.getEnd2();
+ if ((end1.getType().equals(currentAssociationEnd1.getType()) && end2.getType().equals(
+ currentAssociationEnd2.getType()))
+ || (end1.getType().equals(currentAssociationEnd2.getType()) && end2.getType().equals(
+ currentAssociationEnd1.getType()))) {
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
new file mode 100644
index 0000000..0fdaee0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEnd.java
@@ -0,0 +1,183 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToMany;
+import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
+import javax.persistence.metamodel.Attribute.PersistentAttributeType;
+
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmAssociationEnd extends JPAEdmBaseViewImpl implements JPAEdmAssociationEndView {
+
+ private JPAEdmEntityTypeView entityTypeView = null;
+ private JPAEdmPropertyView propertyView = null;
+ private AssociationEnd currentAssociationEnd1 = null;
+ private AssociationEnd currentAssociationEnd2 = null;
+ private String columnName;
+ private String referencedColumnName;
+ private String mappedBy;
+ private String ownerPropertyName;
+
+ public JPAEdmAssociationEnd(final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) {
+ super(entityTypeView);
+ this.entityTypeView = entityTypeView;
+ this.propertyView = propertyView;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmAssociationEndBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd1() {
+ return currentAssociationEnd1;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd2() {
+ return currentAssociationEnd2;
+ }
+
+ private class JPAEdmAssociationEndBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException {
+
+ JoinColumn joinColumn = null;
+
+ currentAssociationEnd1 = new AssociationEnd();
+ currentAssociationEnd2 = new AssociationEnd();
+
+ JPAEdmNameBuilder.build(JPAEdmAssociationEnd.this, entityTypeView, propertyView);
+
+ currentAssociationEnd1.setRole(currentAssociationEnd1.getType().getName());
+ currentAssociationEnd2.setRole(currentAssociationEnd2.getType().getName());
+
+ setEdmMultiplicity(propertyView.getJPAAttribute().getPersistentAttributeType());
+
+ AnnotatedElement annotatedElement = (AnnotatedElement) propertyView.getJPAAttribute().getJavaMember();
+ if (annotatedElement != null) {
+ joinColumn = annotatedElement.getAnnotation(JoinColumn.class);
+ if (joinColumn != null) {
+ columnName = joinColumn.name();
+ referencedColumnName = joinColumn.referencedColumnName();
+ }
+
+ }
+ ownerPropertyName = propertyView.getJPAAttribute().getName();
+
+ }
+
+ private void setEdmMultiplicity(final PersistentAttributeType type) {
+ AnnotatedElement annotatedElement = (AnnotatedElement) propertyView.getJPAAttribute().getJavaMember();
+ switch (type) {
+ case ONE_TO_MANY:
+ currentAssociationEnd1.setMultiplicity(EdmMultiplicity.ONE);
+ currentAssociationEnd2.setMultiplicity(EdmMultiplicity.MANY);
+ if (annotatedElement != null) {
+ OneToMany reln = annotatedElement.getAnnotation(OneToMany.class);
+ if (reln != null) {
+ mappedBy = reln.mappedBy();
+ }
+ }
+ break;
+ case MANY_TO_MANY:
+ currentAssociationEnd1.setMultiplicity(EdmMultiplicity.MANY);
+ currentAssociationEnd2.setMultiplicity(EdmMultiplicity.MANY);
+ if (annotatedElement != null) {
+ ManyToMany reln = annotatedElement.getAnnotation(ManyToMany.class);
+ if (reln != null) {
+ mappedBy = reln.mappedBy();
+ }
+ }
+ break;
+ case MANY_TO_ONE:
+ currentAssociationEnd1.setMultiplicity(EdmMultiplicity.MANY);
+ currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ONE);
+ break;
+ case ONE_TO_ONE:
+ currentAssociationEnd1.setMultiplicity(EdmMultiplicity.ONE);
+ currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ONE);
+ if (annotatedElement != null) {
+ OneToOne reln = annotatedElement.getAnnotation(OneToOne.class);
+ if (reln != null) {
+ mappedBy = reln.mappedBy();
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ @Override
+ public boolean compare(final AssociationEnd end1, final AssociationEnd end2) {
+ if ((end1.getType().equals(currentAssociationEnd1.getType())
+ && end2.getType().equals(currentAssociationEnd2.getType())
+ && end1.getMultiplicity().equals(currentAssociationEnd1.getMultiplicity()) && end2.getMultiplicity().equals(
+ currentAssociationEnd2.getMultiplicity()))
+ || (end1.getType().equals(currentAssociationEnd2.getType())
+ && end2.getType().equals(currentAssociationEnd1.getType())
+ && end1.getMultiplicity().equals(currentAssociationEnd2.getMultiplicity()) && end2.getMultiplicity()
+ .equals(currentAssociationEnd1.getMultiplicity()))) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public String getJoinColumnName() {
+ return columnName;
+ }
+
+ @Override
+ public String getJoinColumnReferenceColumnName() {
+ return referencedColumnName;
+ }
+
+ @Override
+ public String getMappedByName() {
+ return mappedBy;
+ }
+
+ @Override
+ public String getOwningPropertyName() {
+ return ownerPropertyName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSet.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSet.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSet.java
new file mode 100644
index 0000000..f5a0ecd
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSet.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmAssociationSet extends JPAEdmBaseViewImpl implements JPAEdmAssociationSetView {
+
+ private JPAEdmSchemaView schemaView;
+ private AssociationSet currentAssociationSet;
+ private List<AssociationSet> associationSetList;
+ private Association currentAssociation;
+
+ public JPAEdmAssociationSet(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmAssociationSetBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public List<AssociationSet> getConsistentEdmAssociationSetList() {
+ return associationSetList;
+ }
+
+ @Override
+ public AssociationSet getEdmAssociationSet() {
+ return currentAssociationSet;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ return currentAssociation;
+ }
+
+ private class JPAEdmAssociationSetBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException {
+
+ if (associationSetList == null) {
+ associationSetList = new ArrayList<AssociationSet>();
+ }
+
+ JPAEdmAssociationView associationView = schemaView.getJPAEdmAssociationView();
+ JPAEdmEntitySetView entitySetView = schemaView.getJPAEdmEntityContainerView().getJPAEdmEntitySetView();
+
+ List<EntitySet> entitySetList = entitySetView.getConsistentEdmEntitySetList();
+ if (associationView.isConsistent()) {
+ for (Association association : associationView.getConsistentEdmAssociationList()) {
+
+ currentAssociation = association;
+
+ FullQualifiedName fQname =
+ new FullQualifiedName(schemaView.getEdmSchema().getNamespace(), association.getName());
+ currentAssociationSet = new AssociationSet();
+ currentAssociationSet.setAssociation(fQname);
+
+ int endCount = 0;
+ short endFlag = 0;
+ for (EntitySet entitySet : entitySetList) {
+ fQname = entitySet.getEntityType();
+ endFlag = 0;
+ if (fQname.equals(association.getEnd1().getType()) || ++endFlag > 1
+ || fQname.equals(association.getEnd2().getType())) {
+
+ AssociationSetEnd end = new AssociationSetEnd();
+ end.setEntitySet(entitySet.getName());
+ if (endFlag == 0) {
+ currentAssociationSet.setEnd1(end);
+ end.setRole(association.getEnd1().getRole());
+ endCount++;
+ } else {
+ endCount++;
+ currentAssociationSet.setEnd2(end);
+ end.setRole(association.getEnd2().getRole());
+ }
+
+ if (endCount == 2) {
+ break;
+ }
+ }
+ }
+ if (endCount == 2) {
+ JPAEdmNameBuilder.build(JPAEdmAssociationSet.this);
+ associationSetList.add(currentAssociationSet);
+ }
+
+ }
+
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImpl.java
new file mode 100644
index 0000000..ee6f083
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImpl.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmBaseView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+
+public abstract class JPAEdmBaseViewImpl implements JPAEdmBaseView {
+
+ protected boolean skipDefaultNaming = false;
+ protected String pUnitName = null;
+ protected Metamodel metaModel = null;
+ protected boolean isConsistent = true;
+ protected JPAEdmBuilder builder = null;
+ protected JPAEdmExtension jpaEdmExtension = null;
+ private JPAEdmMappingModelAccess jpaEdmMappingModelAccess = null;
+
+ public JPAEdmBaseViewImpl(final JPAEdmBaseView view) {
+ pUnitName = view.getpUnitName();
+ metaModel = view.getJPAMetaModel();
+ jpaEdmMappingModelAccess = view.getJPAEdmMappingModelAccess();
+ jpaEdmExtension = view.getJPAEdmExtension();
+ skipDefaultNaming = view.isDefaultNamingSkipped();
+ }
+
+ public JPAEdmBaseViewImpl(final ODataJPAContext context) {
+ pUnitName = context.getPersistenceUnitName();
+ metaModel = context.getEntityManagerFactory().getMetamodel();
+ jpaEdmMappingModelAccess =
+ ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmMappingModelAccess(context);
+ jpaEdmExtension = context.getJPAEdmExtension();
+ jpaEdmMappingModelAccess.loadMappingModel();
+ skipDefaultNaming = !context.getDefaultNaming();
+ }
+
+ public JPAEdmBaseViewImpl(final Metamodel metaModel, final String pUnitName) {
+ this.metaModel = metaModel;
+ this.pUnitName = pUnitName;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return pUnitName;
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return metaModel;
+ }
+
+ @Override
+ public boolean isConsistent() {
+ return isConsistent;
+ }
+
+ @Override
+ public void clean() {
+ pUnitName = null;
+ metaModel = null;
+ isConsistent = false;
+ }
+
+ @Override
+ public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
+ return jpaEdmMappingModelAccess;
+
+ }
+
+ @Override
+ public JPAEdmExtension getJPAEdmExtension() {
+ return jpaEdmExtension;
+ }
+
+ @Override
+ public boolean isDefaultNamingSkipped() {
+ return skipDefaultNaming;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexType.java
new file mode 100644
index 0000000..c033494
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexType.java
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EmbeddableType;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmComplexTypeView {
+
+ private JPAEdmSchemaView schemaView;
+ private ComplexType currentComplexType = null;
+ private EmbeddableType<?> currentEmbeddableType = null;
+ private HashMap<String, ComplexType> searchMap = null;
+ private List<ComplexType> consistentComplextTypes = null;
+ private boolean directBuild;
+ private EmbeddableType<?> nestedComplexType = null;
+ private List<String> nonKeyComplexList = null;
+
+ public JPAEdmComplexType(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ directBuild = true;
+ if (nonKeyComplexList == null) {
+ nonKeyComplexList = new ArrayList<String>();
+ }
+ }
+
+ public JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute) {
+ super(view);
+ schemaView = view;
+ for (EmbeddableType<?> jpaEmbeddable : schemaView.getJPAMetaModel().getEmbeddables()) {
+ if (jpaEmbeddable.getJavaType().getName().equals(complexAttribute.getJavaType().getName())) {
+ nestedComplexType = jpaEmbeddable;
+ break;
+ }
+ }
+ directBuild = false;
+ if (nonKeyComplexList == null) {
+ nonKeyComplexList = new ArrayList<String>();
+ }
+ }
+
+ @Override
+ public boolean isReferencedInKey(final String complexTypeName) {
+ return nonKeyComplexList.contains(complexTypeName);
+ }
+
+ @Override
+ public void setReferencedInKey(final String complexTypeName) {
+ nonKeyComplexList.add(complexTypeName);
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmComplexTypeBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public ComplexType getEdmComplexType() {
+ return currentComplexType;
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String embeddableTypeName) {
+ return searchMap.get(embeddableTypeName);
+ }
+
+ @Override
+ public EmbeddableType<?> getJPAEmbeddableType() {
+ return currentEmbeddableType;
+ }
+
+ @Override
+ public List<ComplexType> getConsistentEdmComplexTypes() {
+ return consistentComplextTypes;
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final FullQualifiedName type) {
+ String name = type.getName();
+ return searchComplexTypeByName(name);
+
+ }
+
+ private ComplexType searchComplexTypeByName(final String name) {
+ for (ComplexType complexType : consistentComplextTypes) {
+ if (null != complexType && null != complexType.getName() && complexType.getName().equals(name)) {
+ return complexType;
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view) {
+ String searchKey = view.getJPAEmbeddableType().getJavaType().getName();
+
+ if (!searchMap.containsKey(searchKey)) {
+ consistentComplextTypes.add(view.getEdmComplexType());
+ searchMap.put(searchKey, view.getEdmComplexType());
+ }
+ }
+
+ @Override
+ public void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList,
+ final String embeddablePropertyName) {
+
+ if (expandedList == null) {
+ expandedList = new ArrayList<Property>();
+ }
+ for (Property property : complexType.getProperties()) {
+ try {
+ SimpleProperty newSimpleProperty = new SimpleProperty();
+ SimpleProperty oldSimpleProperty = (SimpleProperty) property;
+ newSimpleProperty.setAnnotationAttributes(oldSimpleProperty.getAnnotationAttributes());
+ newSimpleProperty.setAnnotationElements(oldSimpleProperty.getAnnotationElements());
+ newSimpleProperty.setCustomizableFeedMappings(oldSimpleProperty.getCustomizableFeedMappings());
+ newSimpleProperty.setDocumentation(oldSimpleProperty.getDocumentation());
+ newSimpleProperty.setFacets(oldSimpleProperty.getFacets());
+ newSimpleProperty.setMimeType(oldSimpleProperty.getMimeType());
+ newSimpleProperty.setName(oldSimpleProperty.getName());
+ newSimpleProperty.setType(oldSimpleProperty.getType());
+ JPAEdmMappingImpl newMapping = new JPAEdmMappingImpl();
+ Mapping mapping = oldSimpleProperty.getMapping();
+ JPAEdmMapping oldMapping = (JPAEdmMapping) mapping;
+ newMapping.setJPAColumnName(oldMapping.getJPAColumnName());
+ newMapping.setInternalName(embeddablePropertyName + "." + mapping.getInternalName());
+ newMapping.setObject(mapping.getObject());
+ newMapping.setJPAType(oldMapping.getJPAType());
+ newSimpleProperty.setMapping(newMapping);
+ expandedList.add(newSimpleProperty);
+ } catch (ClassCastException e) {
+ ComplexProperty complexProperty = (ComplexProperty) property;
+ String name = embeddablePropertyName + "." + complexProperty.getMapping().getInternalName();
+ expandEdmComplexType(searchComplexTypeByName(complexProperty.getName()), expandedList, name);
+ }
+ }
+
+ }
+
+ private class JPAEdmComplexTypeBuilder implements JPAEdmBuilder {
+ /*
+ *
+ * Each call to build method creates a new Complex Type.
+ * The Complex Type is created only if it is not created
+ * earlier. A local buffer is maintained to track the list
+ * of complex types created.
+ *
+ * ************************************************************
+ * Build EDM Complex Type - STEPS
+ * ************************************************************
+ * 1) Fetch list of embeddable types from JPA Model
+ * 2) Search local buffer if there exists already a Complex
+ * type for the embeddable type.
+ * 3) If the complex type was already been built continue with
+ * the next embeddable type, else create new EDM Complex Type.
+ * 4) Create a Property view with Complex Type
+ * 5) Get Property Builder and build the Property with Complex
+ * type.
+ * 6) Set EDM complex type with list of properties built by
+ * the property view
+ * 7) Provide name for EDM complex type.
+ *
+ * ************************************************************
+ * Build EDM Complex Type - STEPS
+ * ************************************************************
+ */
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+ Set<EmbeddableType<?>> embeddables = new HashSet<EmbeddableType<?>>();
+
+ if (consistentComplextTypes == null) {
+ consistentComplextTypes = new ArrayList<ComplexType>();
+ }
+
+ if (searchMap == null) {
+ searchMap = new HashMap<String, ComplexType>();
+ }
+
+ if (directBuild) {
+ embeddables = schemaView.getJPAMetaModel().getEmbeddables();
+ } else {
+ embeddables.add(nestedComplexType);
+ }
+
+ for (EmbeddableType<?> embeddableType : embeddables) {
+
+ currentEmbeddableType = embeddableType;
+ String searchKey = embeddableType.getJavaType().getName();
+
+ if (searchMap.containsKey(searchKey)) {
+ continue;
+ }
+
+ // Check for need to Exclude
+ if (isExcluded(JPAEdmComplexType.this)) {
+ continue;
+ }
+
+ JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView, JPAEdmComplexType.this);
+ propertyView.getBuilder().build();
+
+ currentComplexType = new ComplexType();
+ currentComplexType.setProperties(propertyView.getEdmPropertyList());
+ JPAEdmNameBuilder.build(JPAEdmComplexType.this);
+
+ searchMap.put(searchKey, currentComplexType);
+ consistentComplextTypes.add(currentComplexType);
+
+ }
+
+ }
+
+ private boolean isExcluded(final JPAEdmComplexType jpaEdmComplexType) {
+
+ JPAEdmMappingModelAccess mappingModelAccess = jpaEdmComplexType.getJPAEdmMappingModelAccess();
+ if (mappingModelAccess != null
+ && mappingModelAccess.isMappingModelExists()
+ && mappingModelAccess.checkExclusionOfJPAEmbeddableType(jpaEdmComplexType.getJPAEmbeddableType()
+ .getJavaType().getSimpleName())) {
+ return true;
+ }
+ return false;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainer.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainer.java
new file mode 100644
index 0000000..81d6c4f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainer.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmEntityContainer extends JPAEdmBaseViewImpl implements JPAEdmEntityContainerView {
+
+ private JPAEdmEntitySetView entitySetView;
+ private JPAEdmSchemaView schemaView;
+ private JPAEdmAssociationSetView associationSetView;
+
+ private EntityContainer currentEntityContainer;
+ private List<EntityContainer> consistentEntityContainerList;
+
+ public JPAEdmEntityContainer(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmEntityContainerBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public EntityContainer getEdmEntityContainer() {
+ return currentEntityContainer;
+ }
+
+ @Override
+ public List<EntityContainer> getConsistentEdmEntityContainerList() {
+ return consistentEntityContainerList;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return entitySetView;
+ }
+
+ @Override
+ public JPAEdmAssociationSetView getEdmAssociationSetView() {
+ return associationSetView;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+ entitySetView = null;
+ associationSetView = null;
+ currentEntityContainer = null;
+ consistentEntityContainerList = null;
+ }
+
+ private class JPAEdmEntityContainerBuilder implements JPAEdmBuilder {
+ /*
+ *
+ * Each call to build method creates a new Entity Container and builds
+ * the entity container with Association Sets and Entity Sets. The newly
+ * created and built entity container is added to the exiting Entity
+ * Container List.
+ *
+ * ************************************************************ Build
+ * EDM Entity Container - STEPS
+ * ************************************************************ 1)
+ * Instantiate New EDM Entity Container 2) Build Name for EDM Entity
+ * Container 2) Create Entity Container List (if does not exists) 3)
+ * Build EDM Entity Set 4) Add EDM Entity Set to EDM Entity Container 6)
+ * Build EDM Association Set 7) Add EDM Association Set to EDM Entity
+ * Container 8) Add EDM Entity Container to the Container List
+ * ************************************************************ Build
+ * EDM Entity Container - STEPS
+ * ************************************************************
+ */
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ currentEntityContainer = new EntityContainer();
+
+ if (consistentEntityContainerList == null) {
+ currentEntityContainer.setDefaultEntityContainer(true);
+ consistentEntityContainerList = new ArrayList<EntityContainer>();
+ }
+
+ entitySetView = new JPAEdmEntitySet(schemaView);
+ entitySetView.getBuilder().build();
+ if (entitySetView.isConsistent()) {
+ currentEntityContainer.setEntitySets(entitySetView.getConsistentEdmEntitySetList());
+ } else {
+ isConsistent = false;
+ return;
+ }
+
+ if (!schemaView.getJPAEdmAssociationView().isConsistent()) {
+ schemaView.getJPAEdmAssociationView().getBuilder().build();
+ }
+
+ associationSetView = new JPAEdmAssociationSet(schemaView);
+ associationSetView.getBuilder().build();
+ if (associationSetView.isConsistent()) {
+ currentEntityContainer.setAssociationSets(associationSetView.getConsistentEdmAssociationSetList());
+ } else {
+ isConsistent = false;
+ return;
+ }
+
+ JPAEdmNameBuilder.build(JPAEdmEntityContainer.this);
+ consistentEntityContainerList.add(currentEntityContainer);
+ isConsistent = true;
+
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySet.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySet.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySet.java
new file mode 100644
index 0000000..5558165
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySet.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmEntitySet extends JPAEdmBaseViewImpl implements JPAEdmEntitySetView {
+
+ private EntitySet currentEntitySet = null;
+ private List<EntitySet> consistentEntitySetList = null;
+ private JPAEdmEntityTypeView entityTypeView = null;
+ private JPAEdmSchemaView schemaView;
+
+ public JPAEdmEntitySet(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmEntitySetBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public EntitySet getEdmEntitySet() {
+ return currentEntitySet;
+ }
+
+ @Override
+ public List<EntitySet> getConsistentEdmEntitySetList() {
+ return consistentEntitySetList;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return entityTypeView;
+ }
+
+ @Override
+ public void clean() {
+ currentEntitySet = null;
+ consistentEntitySetList = null;
+ entityTypeView = null;
+ isConsistent = false;
+ }
+
+ private class JPAEdmEntitySetBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ if (consistentEntitySetList == null) {
+ consistentEntitySetList = new ArrayList<EntitySet>();
+ }
+
+ entityTypeView = new JPAEdmEntityType(schemaView);
+ entityTypeView.getBuilder().build();
+
+ if (entityTypeView.isConsistent() && entityTypeView.getConsistentEdmEntityTypes() != null) {
+
+ String nameSpace = schemaView.getEdmSchema().getNamespace();
+ for (EntityType entityType : entityTypeView.getConsistentEdmEntityTypes()) {
+
+ currentEntitySet = new EntitySet();
+ currentEntitySet.setEntityType(new FullQualifiedName(nameSpace, entityType.getName()));
+ JPAEdmNameBuilder.build(JPAEdmEntitySet.this, entityTypeView);
+ consistentEntitySetList.add(currentEntitySet);
+
+ }
+ isConsistent = true;
+ } else {
+ isConsistent = false;
+ return;
+ }
+
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
new file mode 100644
index 0000000..a127c1e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityType.java
@@ -0,0 +1,230 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView {
+
+ private JPAEdmSchemaView schemaView = null;
+ private EntityType currentEdmEntityType = null;
+ private javax.persistence.metamodel.EntityType<?> currentJPAEntityType = null;
+ private EntityTypeList<EntityType> consistentEntityTypes = null;
+
+ private HashMap<String, EntityType> consistentEntityTypeMap;
+
+ public JPAEdmEntityType(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ consistentEntityTypeMap = new HashMap<String, EntityType>();
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmEntityTypeBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public EntityType getEdmEntityType() {
+ return currentEdmEntityType;
+ }
+
+ @Override
+ public javax.persistence.metamodel.EntityType<?> getJPAEntityType() {
+ return currentJPAEntityType;
+ }
+
+ @Override
+ public List<EntityType> getConsistentEdmEntityTypes() {
+ return consistentEntityTypes;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String jpaEntityTypeName) {
+ return consistentEntityTypeMap.get(jpaEntityTypeName);
+ }
+
+ private class JPAEdmEntityTypeBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ Set<javax.persistence.metamodel.EntityType<?>> jpaEntityTypes = metaModel.getEntities();
+
+ if (jpaEntityTypes == null || jpaEntityTypes.isEmpty() == true) {
+ return;
+ } else if (consistentEntityTypes == null) {
+ consistentEntityTypes = new EntityTypeList<EntityType>();
+
+ }
+
+ for (javax.persistence.metamodel.EntityType<?> jpaEntityType : jpaEntityTypes) {
+ currentEdmEntityType = new EntityType();
+ currentJPAEntityType = jpaEntityType;
+
+ // Check for need to Exclude
+ if (isExcluded(JPAEdmEntityType.this)) {
+ continue;
+ }
+
+ JPAEdmNameBuilder.build(JPAEdmEntityType.this);
+
+ JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView);
+ propertyView.getBuilder().build();
+
+ currentEdmEntityType.setProperties(propertyView.getEdmPropertyList());
+ if (propertyView.getJPAEdmNavigationPropertyView() != null) {
+ JPAEdmNavigationPropertyView navPropView = propertyView.getJPAEdmNavigationPropertyView();
+ if (navPropView.getConsistentEdmNavigationProperties() != null
+ && !navPropView.getConsistentEdmNavigationProperties().isEmpty()) {
+ currentEdmEntityType.setNavigationProperties(navPropView.getConsistentEdmNavigationProperties());
+ }
+ }
+ JPAEdmKeyView keyView = propertyView.getJPAEdmKeyView();
+ currentEdmEntityType.setKey(keyView.getEdmKey());
+
+ consistentEntityTypes.add(currentEdmEntityType);
+ consistentEntityTypeMap.put(currentJPAEntityType.getName(), currentEdmEntityType);
+ }
+
+ }
+
+ private boolean isExcluded(final JPAEdmEntityType jpaEdmEntityType) {
+ JPAEdmMappingModelAccess mappingModelAccess = jpaEdmEntityType.getJPAEdmMappingModelAccess();
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()
+ && mappingModelAccess.checkExclusionOfJPAEntityType(jpaEdmEntityType.getJPAEntityType().getName())) {
+ return true;
+ }
+ return false;
+ }
+
+ }
+
+ private class EntityTypeList<X> extends ArrayList<EntityType> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 719079109608251592L;
+
+ @Override
+ public Iterator<EntityType> iterator() {
+ return new EntityTypeListIterator<X>(size());
+ }
+
+ }
+
+ private class EntityTypeListIterator<E> implements ListIterator<EntityType> {
+
+ private int size = 0;
+ private int pos = 0;
+
+ public EntityTypeListIterator(final int listSize) {
+ this.size = listSize;
+ }
+
+ @Override
+ public void add(final EntityType e) {
+ consistentEntityTypes.add(e);
+ size++;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (pos < size) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ if (pos > 0) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public EntityType next() {
+ if (pos < size) {
+ currentEdmEntityType = consistentEntityTypes.get(pos++);
+ return currentEdmEntityType;
+ }
+
+ return null;
+ }
+
+ @Override
+ public int nextIndex() {
+ return pos;
+ }
+
+ @Override
+ public EntityType previous() {
+ if (pos > 0 && pos < size) {
+ currentEdmEntityType = consistentEntityTypes.get(--pos);
+ return currentEdmEntityType;
+ }
+ return null;
+ }
+
+ @Override
+ public int previousIndex() {
+ if (pos > 0) {
+ return pos - 1;
+ }
+
+ return 0;
+ }
+
+ @Override
+ public void remove() {
+ consistentEntityTypes.remove(pos);
+ }
+
+ @Override
+ public void set(final EntityType e) {
+ consistentEntityTypes.set(pos, e);
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFacets.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFacets.java
new file mode 100644
index 0000000..916b49c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFacets.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.lang.reflect.AnnotatedElement;
+
+import javax.persistence.Column;
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+
+public class JPAEdmFacets {
+ public static void setFacets(final Attribute<?, ?> jpaAttribute, final SimpleProperty edmProperty) {
+ EdmSimpleTypeKind edmTypeKind = edmProperty.getType();
+ Facets facets = new Facets();
+ edmProperty.setFacets(facets);
+
+ Column column = null;
+ if (jpaAttribute.getJavaMember() instanceof AnnotatedElement) {
+ column = ((AnnotatedElement) jpaAttribute
+ .getJavaMember()).getAnnotation(Column.class);
+ }
+
+ if (column == null) {
+ return;
+ }
+
+ setNullable(column, edmProperty);
+
+ switch (edmTypeKind) {
+ case Binary:
+ setMaxLength(column, edmProperty);
+ break;
+ case DateTime:
+ setPrecision(column, edmProperty);
+ break;
+ case DateTimeOffset:
+ setPrecision(column, edmProperty);
+ break;
+ case Time:
+ setPrecision(column, edmProperty);
+ break;
+ case Decimal:
+ setPrecision(column, edmProperty);
+ setScale(column, edmProperty);
+ break;
+ case String:
+ setMaxLength(column, edmProperty);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private static void setNullable(final Column column, final SimpleProperty edmProperty) {
+ ((Facets) edmProperty.getFacets()).setNullable(column.nullable());
+ }
+
+ private static void setMaxLength(final Column column, final SimpleProperty edmProperty) {
+ if (column.length() > 0) {
+ ((Facets) edmProperty.getFacets()).setMaxLength(column.length());
+ }
+ }
+
+ private static void setPrecision(final Column column, final SimpleProperty edmProperty) {
+ if (column.precision() > 0) {
+ ((Facets) edmProperty.getFacets()).setPrecision(column.precision());
+ }
+ }
+
+ private static void setScale(final Column column, final SimpleProperty edmProperty) {
+ if (column.scale() > 0) {
+ ((Facets) edmProperty.getFacets()).setScale(column.scale());
+ }
+ }
+}
[27/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContext.java
deleted file mode 100644
index 9d2884d..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContext.java
+++ /dev/null
@@ -1,109 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLSelectSingleContextView;
-
-public class JPQLSelectSingleContext extends JPQLContext implements JPQLSelectSingleContextView {
-
- private String selectExpression;
- private List<KeyPredicate> keyPredicates;
-
- protected void setKeyPredicates(final List<KeyPredicate> keyPredicates) {
- this.keyPredicates = keyPredicates;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- protected final void setSelectExpression(final String selectExpression) {
- this.selectExpression = selectExpression;
- }
-
- @Override
- public String getSelectExpression() {
- return selectExpression;
- }
-
- public class JPQLSelectSingleContextBuilder extends
- org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder {
-
- protected GetEntityUriInfo entityView;
-
- @Override
- public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
- if (entityView != null) {
-
- try {
-
- setType(JPQLContextType.SELECT_SINGLE);
-
- EdmEntityType entityType = entityView.getTargetEntitySet().getEntityType();
- EdmMapping mapping = entityType.getMapping();
- if (mapping != null) {
- setJPAEntityName(mapping.getInternalName());
- } else {
- setJPAEntityName(entityType.getName());
- }
-
- setJPAEntityAlias(generateJPAEntityAlias());
-
- setKeyPredicates(entityView.getKeyPredicates());
-
- setSelectExpression(generateSelectExpression());
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- }
-
- return JPQLSelectSingleContext.this;
-
- }
-
- @Override
- protected void setResultsView(final Object resultsView) {
- if (resultsView instanceof GetEntityUriInfo) {
- entityView = (GetEntityUriInfo) resultsView;
- }
-
- }
-
- /*
- * Generate Select Clause
- */
- protected String generateSelectExpression() throws EdmException {
- return getJPAEntityAlias();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilder.java
deleted file mode 100644
index 06e2444..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilder.java
+++ /dev/null
@@ -1,66 +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.odata2.processor.core.jpa.jpql;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLSelectSingleContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.ODataExpressionParser;
-
-public class JPQLSelectSingleStatementBuilder extends JPQLStatementBuilder {
-
- JPQLStatement jpqlStatement;
- private JPQLSelectSingleContextView context;
-
- public JPQLSelectSingleStatementBuilder(final JPQLContextView context) {
- this.context = (JPQLSelectSingleContextView) context;
- }
-
- @Override
- public JPQLStatement build() throws ODataJPARuntimeException {
- jpqlStatement = createStatement(createJPQLQuery());
- return jpqlStatement;
-
- }
-
- private String createJPQLQuery() throws ODataJPARuntimeException {
-
- StringBuilder jpqlQuery = new StringBuilder();
- String tableAlias = context.getJPAEntityAlias();
- String fromClause = context.getJPAEntityName() + JPQLStatement.DELIMITER.SPACE + tableAlias;
-
- jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(fromClause);
-
- if (context.getKeyPredicates() != null && context.getKeyPredicates().size() > 0) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(ODataExpressionParser
- .parseKeyPredicates(context.getKeyPredicates(), context.getJPAEntityAlias()));
- }
-
- return jpqlQuery.toString();
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilder.java
deleted file mode 100644
index 22059f1..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilder.java
+++ /dev/null
@@ -1,98 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.Iterator;
-import java.util.Map.Entry;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLSelectContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-
-public class JPQLSelectStatementBuilder extends JPQLStatementBuilder {
-
- JPQLStatement jpqlStatement;
- private JPQLSelectContextView context;
-
- public JPQLSelectStatementBuilder(final JPQLContextView context) {
- this.context = (JPQLSelectContextView) context;
- }
-
- @Override
- public JPQLStatement build() throws ODataJPARuntimeException {
- jpqlStatement = createStatement(createJPQLQuery());
- return jpqlStatement;
-
- }
-
- private String createJPQLQuery() throws ODataJPARuntimeException {
-
- StringBuilder jpqlQuery = new StringBuilder();
- String tableAlias = context.getJPAEntityAlias();
- String fromClause = context.getJPAEntityName() + JPQLStatement.DELIMITER.SPACE + tableAlias;
-
- jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
- if (context.getType().equals(JPQLContextType.SELECT_COUNT)) { // $COUNT
- jpqlQuery.append(JPQLStatement.KEYWORD.COUNT).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_LEFT).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_RIGHT).append(JPQLStatement.DELIMITER.SPACE);
- } else {// Normal
- jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
- }
-
- jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(fromClause);
-
- if (context.getWhereExpression() != null) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(context.getWhereExpression());
- }
-
- if (context.getOrderByCollection() != null && context.getOrderByCollection().size() > 0) {
-
- StringBuilder orderByBuilder = new StringBuilder();
- Iterator<Entry<String, String>> orderItr = context.getOrderByCollection().entrySet().iterator();
-
- int i = 0;
-
- while (orderItr.hasNext()) {
- if (i != 0) {
- orderByBuilder.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.DELIMITER.COMMA).append(
- JPQLStatement.DELIMITER.SPACE);
- }
- Entry<String, String> entry = orderItr.next();
- orderByBuilder.append(entry.getKey()).append(JPQLStatement.DELIMITER.SPACE);
- orderByBuilder.append(entry.getValue());
- i++;
- }
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.ORDERBY).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(orderByBuilder);
- }
-
- return jpqlQuery.toString();
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociation.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociation.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociation.java
deleted file mode 100644
index aa10ef8..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociation.java
+++ /dev/null
@@ -1,237 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationEndView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmAssociation extends JPAEdmBaseViewImpl implements JPAEdmAssociationView {
-
- private JPAEdmAssociationEndView associationEndView;
-
- private Association currentAssociation;
- private List<Association> consistentAssociatonList;
- private HashMap<String, Association> associationMap;
- private HashMap<String, JPAEdmAssociationEndView> associationEndMap;
- private List<JPAEdmReferentialConstraintView> inconsistentRefConstraintViewList;
- private int numberOfSimilarEndPoints;
-
- public JPAEdmAssociation(final JPAEdmAssociationEndView associationEndview,
- final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView, final int value) {
- super(associationEndview);
- associationEndView = associationEndview;
- numberOfSimilarEndPoints = value;
- init();
- }
-
- public JPAEdmAssociation(final JPAEdmSchemaView view) {
- super(view);
- init();
- }
-
- private void init() {
- isConsistent = false;
- consistentAssociatonList = new ArrayList<Association>();
- inconsistentRefConstraintViewList = new LinkedList<JPAEdmReferentialConstraintView>();
- associationMap = new HashMap<String, Association>();
- associationEndMap = new HashMap<String, JPAEdmAssociationEndView>();
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmAssociationBuilder();
- }
- return builder;
- }
-
- @Override
- public Association getEdmAssociation() {
- return currentAssociation;
- }
-
- @Override
- public List<Association> getConsistentEdmAssociationList() {
- return consistentAssociatonList;
- }
-
- @Override
- public Association searchAssociation(final JPAEdmAssociationEndView view) {
- if (view != null) {
- for (String key : associationMap.keySet()) {
- Association association = associationMap.get(key);
- if (association != null) {
- if (view.compare(association.getEnd1(), association.getEnd2())) {
- JPAEdmAssociationEndView associationEnd = associationEndMap.get(association.getName());
- if (associationEnd.getJoinColumnName() != null && associationEnd.getJoinColumnReferenceColumnName() != null
- && view.getJoinColumnName() != null && view.getJoinColumnReferenceColumnName() != null) {
- if (view.getJoinColumnName().equals(associationEnd.getJoinColumnName())
- && view.getJoinColumnReferenceColumnName()
- .equals(associationEnd.getJoinColumnReferenceColumnName())) {
- currentAssociation = association;
- return association;
- }
-
- }
- if (associationEnd.getMappedByName() != null) {
- if (associationEnd.getMappedByName().equals(view.getOwningPropertyName())) {
- currentAssociation = association;
- return association;
- }
- }
- if (associationEnd.getOwningPropertyName() != null) {
- if (associationEnd.getOwningPropertyName().equals(view.getMappedByName())) {
- currentAssociation = association;
- return association;
- }
- }
- }
- }
- }
- }
- return null;
- }
-
- @Override
- public void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
- final JPAEdmAssociationEndView associationEndView) {
- if (associationView != null) {
- currentAssociation = associationView.getEdmAssociation();
- associationMap.put(currentAssociation.getName(), currentAssociation);
- associationEndMap.put(currentAssociation.getName(), associationEndView);
- addJPAEdmRefConstraintView(associationView.getJPAEdmReferentialConstraintView());
- }
- }
-
- @Override
- public void addJPAEdmRefConstraintView(final JPAEdmReferentialConstraintView refView) {
- if (refView != null && refView.isExists()) {
- inconsistentRefConstraintViewList.add(refView);
- }
- }
-
- @Override
- public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
- if (inconsistentRefConstraintViewList.isEmpty()) {
- return null;
- }
- return inconsistentRefConstraintViewList.get(0);
- }
-
- private class JPAEdmAssociationBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- if (associationEndView != null && searchAssociation(associationEndView) == null) {
- currentAssociation = new Association();
- currentAssociation.setEnd1(associationEndView.getEdmAssociationEnd1());
- currentAssociation.setEnd2(associationEndView.getEdmAssociationEnd2());
-
- JPAEdmNameBuilder.build(JPAEdmAssociation.this, numberOfSimilarEndPoints);
-
- associationMap.put(currentAssociation.getName(), currentAssociation);
-
- } else if (!inconsistentRefConstraintViewList.isEmpty()) {
- int inconsistentRefConstraintViewSize = inconsistentRefConstraintViewList.size();
- int index = 0;
- for (int i = 0; i < inconsistentRefConstraintViewSize; i++) {
- JPAEdmReferentialConstraintView view = inconsistentRefConstraintViewList.get(index);
-
- if (view.isExists() && !view.isConsistent()) {
- view.getBuilder().build();
- }
- if (view.isConsistent()) {
- Association newAssociation = new Association();
- copyAssociation(newAssociation, associationMap.get(view.getEdmRelationShipName()));
- newAssociation.setReferentialConstraint(view.getEdmReferentialConstraint());
- consistentAssociatonList.add(newAssociation);
- associationMap.put(view.getEdmRelationShipName(), newAssociation);
- inconsistentRefConstraintViewList.remove(index);
- } else {
- associationMap.remove(view.getEdmRelationShipName());
- index++;
- }
- }
- }
-
- if (associationMap.size() == consistentAssociatonList.size()) {
- isConsistent = true;
- } else {
- for (String key : associationMap.keySet()) {
- Association association = associationMap.get(key);
- if (!consistentAssociatonList.contains(association)) {
- consistentAssociatonList.add(association);
- }
- }
- isConsistent = true;
- }
-
- }
-
- private void copyAssociation(final Association copyToAssociation, final Association copyFromAssociation) {
- copyToAssociation.setEnd1(copyFromAssociation.getEnd1());
- copyToAssociation.setEnd2(copyFromAssociation.getEnd2());
- copyToAssociation.setName(copyFromAssociation.getName());
- copyToAssociation.setAnnotationAttributes(copyFromAssociation.getAnnotationAttributes());
- copyToAssociation.setAnnotationElements(copyFromAssociation.getAnnotationElements());
- copyToAssociation.setDocumentation(copyFromAssociation.getDocumentation());
-
- }
- }
-
- @Override
- public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
- int count = 0;
- AssociationEnd currentAssociationEnd1 = view.getEdmAssociationEnd1();
- AssociationEnd currentAssociationEnd2 = view.getEdmAssociationEnd2();
- AssociationEnd end1 = null;
- AssociationEnd end2 = null;
- for (String key : associationMap.keySet()) {
- Association association = associationMap.get(key);
- if (association != null) {
- end1 = association.getEnd1();
- end2 = association.getEnd2();
- if ((end1.getType().equals(currentAssociationEnd1.getType()) && end2.getType().equals(
- currentAssociationEnd2.getType()))
- || (end1.getType().equals(currentAssociationEnd2.getType()) && end2.getType().equals(
- currentAssociationEnd1.getType()))) {
- count++;
- }
- }
- }
- return count;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEnd.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEnd.java
deleted file mode 100644
index 1b648ae..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEnd.java
+++ /dev/null
@@ -1,183 +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.odata2.processor.core.jpa.model;
-
-import java.lang.reflect.AnnotatedElement;
-
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToMany;
-import javax.persistence.OneToMany;
-import javax.persistence.OneToOne;
-import javax.persistence.metamodel.Attribute.PersistentAttributeType;
-
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationEndView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmAssociationEnd extends JPAEdmBaseViewImpl implements JPAEdmAssociationEndView {
-
- private JPAEdmEntityTypeView entityTypeView = null;
- private JPAEdmPropertyView propertyView = null;
- private AssociationEnd currentAssociationEnd1 = null;
- private AssociationEnd currentAssociationEnd2 = null;
- private String columnName;
- private String referencedColumnName;
- private String mappedBy;
- private String ownerPropertyName;
-
- public JPAEdmAssociationEnd(final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) {
- super(entityTypeView);
- this.entityTypeView = entityTypeView;
- this.propertyView = propertyView;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmAssociationEndBuilder();
- }
-
- return builder;
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd1() {
- return currentAssociationEnd1;
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd2() {
- return currentAssociationEnd2;
- }
-
- private class JPAEdmAssociationEndBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException {
-
- JoinColumn joinColumn = null;
-
- currentAssociationEnd1 = new AssociationEnd();
- currentAssociationEnd2 = new AssociationEnd();
-
- JPAEdmNameBuilder.build(JPAEdmAssociationEnd.this, entityTypeView, propertyView);
-
- currentAssociationEnd1.setRole(currentAssociationEnd1.getType().getName());
- currentAssociationEnd2.setRole(currentAssociationEnd2.getType().getName());
-
- setEdmMultiplicity(propertyView.getJPAAttribute().getPersistentAttributeType());
-
- AnnotatedElement annotatedElement = (AnnotatedElement) propertyView.getJPAAttribute().getJavaMember();
- if (annotatedElement != null) {
- joinColumn = annotatedElement.getAnnotation(JoinColumn.class);
- if (joinColumn != null) {
- columnName = joinColumn.name();
- referencedColumnName = joinColumn.referencedColumnName();
- }
-
- }
- ownerPropertyName = propertyView.getJPAAttribute().getName();
-
- }
-
- private void setEdmMultiplicity(final PersistentAttributeType type) {
- AnnotatedElement annotatedElement = (AnnotatedElement) propertyView.getJPAAttribute().getJavaMember();
- switch (type) {
- case ONE_TO_MANY:
- currentAssociationEnd1.setMultiplicity(EdmMultiplicity.ONE);
- currentAssociationEnd2.setMultiplicity(EdmMultiplicity.MANY);
- if (annotatedElement != null) {
- OneToMany reln = annotatedElement.getAnnotation(OneToMany.class);
- if (reln != null) {
- mappedBy = reln.mappedBy();
- }
- }
- break;
- case MANY_TO_MANY:
- currentAssociationEnd1.setMultiplicity(EdmMultiplicity.MANY);
- currentAssociationEnd2.setMultiplicity(EdmMultiplicity.MANY);
- if (annotatedElement != null) {
- ManyToMany reln = annotatedElement.getAnnotation(ManyToMany.class);
- if (reln != null) {
- mappedBy = reln.mappedBy();
- }
- }
- break;
- case MANY_TO_ONE:
- currentAssociationEnd1.setMultiplicity(EdmMultiplicity.MANY);
- currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ONE);
- break;
- case ONE_TO_ONE:
- currentAssociationEnd1.setMultiplicity(EdmMultiplicity.ONE);
- currentAssociationEnd2.setMultiplicity(EdmMultiplicity.ONE);
- if (annotatedElement != null) {
- OneToOne reln = annotatedElement.getAnnotation(OneToOne.class);
- if (reln != null) {
- mappedBy = reln.mappedBy();
- }
- }
- break;
- default:
- break;
- }
- }
- }
-
- @Override
- public boolean compare(final AssociationEnd end1, final AssociationEnd end2) {
- if ((end1.getType().equals(currentAssociationEnd1.getType())
- && end2.getType().equals(currentAssociationEnd2.getType())
- && end1.getMultiplicity().equals(currentAssociationEnd1.getMultiplicity()) && end2.getMultiplicity().equals(
- currentAssociationEnd2.getMultiplicity()))
- || (end1.getType().equals(currentAssociationEnd2.getType())
- && end2.getType().equals(currentAssociationEnd1.getType())
- && end1.getMultiplicity().equals(currentAssociationEnd2.getMultiplicity()) && end2.getMultiplicity()
- .equals(currentAssociationEnd1.getMultiplicity()))) {
- return true;
- }
-
- return false;
- }
-
- @Override
- public String getJoinColumnName() {
- return columnName;
- }
-
- @Override
- public String getJoinColumnReferenceColumnName() {
- return referencedColumnName;
- }
-
- @Override
- public String getMappedByName() {
- return mappedBy;
- }
-
- @Override
- public String getOwningPropertyName() {
- return ownerPropertyName;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSet.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSet.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSet.java
deleted file mode 100644
index 925a497..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSet.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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmAssociationSet extends JPAEdmBaseViewImpl implements JPAEdmAssociationSetView {
-
- private JPAEdmSchemaView schemaView;
- private AssociationSet currentAssociationSet;
- private List<AssociationSet> associationSetList;
- private Association currentAssociation;
-
- public JPAEdmAssociationSet(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmAssociationSetBuilder();
- }
-
- return builder;
- }
-
- @Override
- public List<AssociationSet> getConsistentEdmAssociationSetList() {
- return associationSetList;
- }
-
- @Override
- public AssociationSet getEdmAssociationSet() {
- return currentAssociationSet;
- }
-
- @Override
- public Association getEdmAssociation() {
- return currentAssociation;
- }
-
- private class JPAEdmAssociationSetBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException {
-
- if (associationSetList == null) {
- associationSetList = new ArrayList<AssociationSet>();
- }
-
- JPAEdmAssociationView associationView = schemaView.getJPAEdmAssociationView();
- JPAEdmEntitySetView entitySetView = schemaView.getJPAEdmEntityContainerView().getJPAEdmEntitySetView();
-
- List<EntitySet> entitySetList = entitySetView.getConsistentEdmEntitySetList();
- if (associationView.isConsistent()) {
- for (Association association : associationView.getConsistentEdmAssociationList()) {
-
- currentAssociation = association;
-
- FullQualifiedName fQname =
- new FullQualifiedName(schemaView.getEdmSchema().getNamespace(), association.getName());
- currentAssociationSet = new AssociationSet();
- currentAssociationSet.setAssociation(fQname);
-
- int endCount = 0;
- short endFlag = 0;
- for (EntitySet entitySet : entitySetList) {
- fQname = entitySet.getEntityType();
- endFlag = 0;
- if (fQname.equals(association.getEnd1().getType()) || ++endFlag > 1
- || fQname.equals(association.getEnd2().getType())) {
-
- AssociationSetEnd end = new AssociationSetEnd();
- end.setEntitySet(entitySet.getName());
- if (endFlag == 0) {
- currentAssociationSet.setEnd1(end);
- end.setRole(association.getEnd1().getRole());
- endCount++;
- } else {
- endCount++;
- currentAssociationSet.setEnd2(end);
- end.setRole(association.getEnd2().getRole());
- }
-
- if (endCount == 2) {
- break;
- }
- }
- }
- if (endCount == 2) {
- JPAEdmNameBuilder.build(JPAEdmAssociationSet.this);
- associationSetList.add(currentAssociationSet);
- }
-
- }
-
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImpl.java
deleted file mode 100644
index 0798487..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImpl.java
+++ /dev/null
@@ -1,101 +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.odata2.processor.core.jpa.model;
-
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmBaseView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
-
-public abstract class JPAEdmBaseViewImpl implements JPAEdmBaseView {
-
- protected boolean skipDefaultNaming = false;
- protected String pUnitName = null;
- protected Metamodel metaModel = null;
- protected boolean isConsistent = true;
- protected JPAEdmBuilder builder = null;
- protected JPAEdmExtension jpaEdmExtension = null;
- private JPAEdmMappingModelAccess jpaEdmMappingModelAccess = null;
-
- public JPAEdmBaseViewImpl(final JPAEdmBaseView view) {
- pUnitName = view.getpUnitName();
- metaModel = view.getJPAMetaModel();
- jpaEdmMappingModelAccess = view.getJPAEdmMappingModelAccess();
- jpaEdmExtension = view.getJPAEdmExtension();
- skipDefaultNaming = view.isDefaultNamingSkipped();
- }
-
- public JPAEdmBaseViewImpl(final ODataJPAContext context) {
- pUnitName = context.getPersistenceUnitName();
- metaModel = context.getEntityManagerFactory().getMetamodel();
- jpaEdmMappingModelAccess =
- ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmMappingModelAccess(context);
- jpaEdmExtension = context.getJPAEdmExtension();
- jpaEdmMappingModelAccess.loadMappingModel();
- skipDefaultNaming = !context.getDefaultNaming();
- }
-
- public JPAEdmBaseViewImpl(final Metamodel metaModel, final String pUnitName) {
- this.metaModel = metaModel;
- this.pUnitName = pUnitName;
- }
-
- @Override
- public String getpUnitName() {
- return pUnitName;
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return metaModel;
- }
-
- @Override
- public boolean isConsistent() {
- return isConsistent;
- }
-
- @Override
- public void clean() {
- pUnitName = null;
- metaModel = null;
- isConsistent = false;
- }
-
- @Override
- public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
- return jpaEdmMappingModelAccess;
-
- }
-
- @Override
- public JPAEdmExtension getJPAEdmExtension() {
- return jpaEdmExtension;
- }
-
- @Override
- public boolean isDefaultNamingSkipped() {
- return skipDefaultNaming;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
deleted file mode 100644
index 31831dd..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
+++ /dev/null
@@ -1,270 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EmbeddableType;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmComplexTypeView {
-
- private JPAEdmSchemaView schemaView;
- private ComplexType currentComplexType = null;
- private EmbeddableType<?> currentEmbeddableType = null;
- private HashMap<String, ComplexType> searchMap = null;
- private List<ComplexType> consistentComplextTypes = null;
- private boolean directBuild;
- private EmbeddableType<?> nestedComplexType = null;
- private List<String> nonKeyComplexList = null;
-
- public JPAEdmComplexType(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- directBuild = true;
- if (nonKeyComplexList == null) {
- nonKeyComplexList = new ArrayList<String>();
- }
- }
-
- public JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute) {
- super(view);
- schemaView = view;
- for (EmbeddableType<?> jpaEmbeddable : schemaView.getJPAMetaModel().getEmbeddables()) {
- if (jpaEmbeddable.getJavaType().getName().equals(complexAttribute.getJavaType().getName())) {
- nestedComplexType = jpaEmbeddable;
- break;
- }
- }
- directBuild = false;
- if (nonKeyComplexList == null) {
- nonKeyComplexList = new ArrayList<String>();
- }
- }
-
- @Override
- public boolean isReferencedInKey(final String complexTypeName) {
- return nonKeyComplexList.contains(complexTypeName);
- }
-
- @Override
- public void setReferencedInKey(final String complexTypeName) {
- nonKeyComplexList.add(complexTypeName);
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmComplexTypeBuilder();
- }
-
- return builder;
- }
-
- @Override
- public ComplexType getEdmComplexType() {
- return currentComplexType;
- }
-
- @Override
- public ComplexType searchEdmComplexType(final String embeddableTypeName) {
- return searchMap.get(embeddableTypeName);
- }
-
- @Override
- public EmbeddableType<?> getJPAEmbeddableType() {
- return currentEmbeddableType;
- }
-
- @Override
- public List<ComplexType> getConsistentEdmComplexTypes() {
- return consistentComplextTypes;
- }
-
- @Override
- public ComplexType searchEdmComplexType(final FullQualifiedName type) {
- String name = type.getName();
- return searchComplexTypeByName(name);
-
- }
-
- private ComplexType searchComplexTypeByName(final String name) {
- for (ComplexType complexType : consistentComplextTypes) {
- if (null != complexType && null != complexType.getName() && complexType.getName().equals(name)) {
- return complexType;
- }
- }
-
- return null;
- }
-
- @Override
- public void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView view) {
- String searchKey = view.getJPAEmbeddableType().getJavaType().getName();
-
- if (!searchMap.containsKey(searchKey)) {
- consistentComplextTypes.add(view.getEdmComplexType());
- searchMap.put(searchKey, view.getEdmComplexType());
- }
- }
-
- @Override
- public void expandEdmComplexType(final ComplexType complexType, List<Property> expandedList,
- final String embeddablePropertyName) {
-
- if (expandedList == null) {
- expandedList = new ArrayList<Property>();
- }
- for (Property property : complexType.getProperties()) {
- try {
- SimpleProperty newSimpleProperty = new SimpleProperty();
- SimpleProperty oldSimpleProperty = (SimpleProperty) property;
- newSimpleProperty.setAnnotationAttributes(oldSimpleProperty.getAnnotationAttributes());
- newSimpleProperty.setAnnotationElements(oldSimpleProperty.getAnnotationElements());
- newSimpleProperty.setCustomizableFeedMappings(oldSimpleProperty.getCustomizableFeedMappings());
- newSimpleProperty.setDocumentation(oldSimpleProperty.getDocumentation());
- newSimpleProperty.setFacets(oldSimpleProperty.getFacets());
- newSimpleProperty.setMimeType(oldSimpleProperty.getMimeType());
- newSimpleProperty.setName(oldSimpleProperty.getName());
- newSimpleProperty.setType(oldSimpleProperty.getType());
- JPAEdmMappingImpl newMapping = new JPAEdmMappingImpl();
- Mapping mapping = oldSimpleProperty.getMapping();
- JPAEdmMapping oldMapping = (JPAEdmMapping) mapping;
- newMapping.setJPAColumnName(oldMapping.getJPAColumnName());
- newMapping.setInternalName(embeddablePropertyName + "." + mapping.getInternalName());
- newMapping.setObject(mapping.getObject());
- newMapping.setJPAType(oldMapping.getJPAType());
- newSimpleProperty.setMapping(newMapping);
- expandedList.add(newSimpleProperty);
- } catch (ClassCastException e) {
- ComplexProperty complexProperty = (ComplexProperty) property;
- String name = embeddablePropertyName + "." + complexProperty.getMapping().getInternalName();
- expandEdmComplexType(searchComplexTypeByName(complexProperty.getName()), expandedList, name);
- }
- }
-
- }
-
- private class JPAEdmComplexTypeBuilder implements JPAEdmBuilder {
- /*
- *
- * Each call to build method creates a new Complex Type.
- * The Complex Type is created only if it is not created
- * earlier. A local buffer is maintained to track the list
- * of complex types created.
- *
- * ************************************************************
- * Build EDM Complex Type - STEPS
- * ************************************************************
- * 1) Fetch list of embeddable types from JPA Model
- * 2) Search local buffer if there exists already a Complex
- * type for the embeddable type.
- * 3) If the complex type was already been built continue with
- * the next embeddable type, else create new EDM Complex Type.
- * 4) Create a Property view with Complex Type
- * 5) Get Property Builder and build the Property with Complex
- * type.
- * 6) Set EDM complex type with list of properties built by
- * the property view
- * 7) Provide name for EDM complex type.
- *
- * ************************************************************
- * Build EDM Complex Type - STEPS
- * ************************************************************
- */
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
- Set<EmbeddableType<?>> embeddables = new HashSet<EmbeddableType<?>>();
-
- if (consistentComplextTypes == null) {
- consistentComplextTypes = new ArrayList<ComplexType>();
- }
-
- if (searchMap == null) {
- searchMap = new HashMap<String, ComplexType>();
- }
-
- if (directBuild) {
- embeddables = schemaView.getJPAMetaModel().getEmbeddables();
- } else {
- embeddables.add(nestedComplexType);
- }
-
- for (EmbeddableType<?> embeddableType : embeddables) {
-
- currentEmbeddableType = embeddableType;
- String searchKey = embeddableType.getJavaType().getName();
-
- if (searchMap.containsKey(searchKey)) {
- continue;
- }
-
- // Check for need to Exclude
- if (isExcluded(JPAEdmComplexType.this)) {
- continue;
- }
-
- JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView, JPAEdmComplexType.this);
- propertyView.getBuilder().build();
-
- currentComplexType = new ComplexType();
- currentComplexType.setProperties(propertyView.getEdmPropertyList());
- JPAEdmNameBuilder.build(JPAEdmComplexType.this);
-
- searchMap.put(searchKey, currentComplexType);
- consistentComplextTypes.add(currentComplexType);
-
- }
-
- }
-
- private boolean isExcluded(final JPAEdmComplexType jpaEdmComplexType) {
-
- JPAEdmMappingModelAccess mappingModelAccess = jpaEdmComplexType.getJPAEdmMappingModelAccess();
- if (mappingModelAccess != null
- && mappingModelAccess.isMappingModelExists()
- && mappingModelAccess.checkExclusionOfJPAEmbeddableType(jpaEdmComplexType.getJPAEmbeddableType()
- .getJavaType().getSimpleName())) {
- return true;
- }
- return false;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
deleted file mode 100644
index 1bb60be..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
+++ /dev/null
@@ -1,145 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmEntityContainer extends JPAEdmBaseViewImpl implements JPAEdmEntityContainerView {
-
- private JPAEdmEntitySetView entitySetView;
- private JPAEdmSchemaView schemaView;
- private JPAEdmAssociationSetView associationSetView;
-
- private EntityContainer currentEntityContainer;
- private List<EntityContainer> consistentEntityContainerList;
-
- public JPAEdmEntityContainer(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmEntityContainerBuilder();
- }
-
- return builder;
- }
-
- @Override
- public EntityContainer getEdmEntityContainer() {
- return currentEntityContainer;
- }
-
- @Override
- public List<EntityContainer> getConsistentEdmEntityContainerList() {
- return consistentEntityContainerList;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return entitySetView;
- }
-
- @Override
- public JPAEdmAssociationSetView getEdmAssociationSetView() {
- return associationSetView;
- }
-
- @Override
- public void clean() {
- super.clean();
- entitySetView = null;
- associationSetView = null;
- currentEntityContainer = null;
- consistentEntityContainerList = null;
- }
-
- private class JPAEdmEntityContainerBuilder implements JPAEdmBuilder {
- /*
- *
- * Each call to build method creates a new Entity Container and builds
- * the entity container with Association Sets and Entity Sets. The newly
- * created and built entity container is added to the exiting Entity
- * Container List.
- *
- * ************************************************************ Build
- * EDM Entity Container - STEPS
- * ************************************************************ 1)
- * Instantiate New EDM Entity Container 2) Build Name for EDM Entity
- * Container 2) Create Entity Container List (if does not exists) 3)
- * Build EDM Entity Set 4) Add EDM Entity Set to EDM Entity Container 6)
- * Build EDM Association Set 7) Add EDM Association Set to EDM Entity
- * Container 8) Add EDM Entity Container to the Container List
- * ************************************************************ Build
- * EDM Entity Container - STEPS
- * ************************************************************
- */
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- currentEntityContainer = new EntityContainer();
-
- if (consistentEntityContainerList == null) {
- currentEntityContainer.setDefaultEntityContainer(true);
- consistentEntityContainerList = new ArrayList<EntityContainer>();
- }
-
- entitySetView = new JPAEdmEntitySet(schemaView);
- entitySetView.getBuilder().build();
- if (entitySetView.isConsistent()) {
- currentEntityContainer.setEntitySets(entitySetView.getConsistentEdmEntitySetList());
- } else {
- isConsistent = false;
- return;
- }
-
- if (!schemaView.getJPAEdmAssociationView().isConsistent()) {
- schemaView.getJPAEdmAssociationView().getBuilder().build();
- }
-
- associationSetView = new JPAEdmAssociationSet(schemaView);
- associationSetView.getBuilder().build();
- if (associationSetView.isConsistent()) {
- currentEntityContainer.setAssociationSets(associationSetView.getConsistentEdmAssociationSetList());
- } else {
- isConsistent = false;
- return;
- }
-
- JPAEdmNameBuilder.build(JPAEdmEntityContainer.this);
- consistentEntityContainerList.add(currentEntityContainer);
- isConsistent = true;
-
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySet.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySet.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySet.java
deleted file mode 100644
index 9e5248f..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySet.java
+++ /dev/null
@@ -1,112 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmEntitySet extends JPAEdmBaseViewImpl implements JPAEdmEntitySetView {
-
- private EntitySet currentEntitySet = null;
- private List<EntitySet> consistentEntitySetList = null;
- private JPAEdmEntityTypeView entityTypeView = null;
- private JPAEdmSchemaView schemaView;
-
- public JPAEdmEntitySet(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmEntitySetBuilder();
- }
-
- return builder;
- }
-
- @Override
- public EntitySet getEdmEntitySet() {
- return currentEntitySet;
- }
-
- @Override
- public List<EntitySet> getConsistentEdmEntitySetList() {
- return consistentEntitySetList;
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return entityTypeView;
- }
-
- @Override
- public void clean() {
- currentEntitySet = null;
- consistentEntitySetList = null;
- entityTypeView = null;
- isConsistent = false;
- }
-
- private class JPAEdmEntitySetBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- if (consistentEntitySetList == null) {
- consistentEntitySetList = new ArrayList<EntitySet>();
- }
-
- entityTypeView = new JPAEdmEntityType(schemaView);
- entityTypeView.getBuilder().build();
-
- if (entityTypeView.isConsistent() && entityTypeView.getConsistentEdmEntityTypes() != null) {
-
- String nameSpace = schemaView.getEdmSchema().getNamespace();
- for (EntityType entityType : entityTypeView.getConsistentEdmEntityTypes()) {
-
- currentEntitySet = new EntitySet();
- currentEntitySet.setEntityType(new FullQualifiedName(nameSpace, entityType.getName()));
- JPAEdmNameBuilder.build(JPAEdmEntitySet.this, entityTypeView);
- consistentEntitySetList.add(currentEntitySet);
-
- }
- isConsistent = true;
- } else {
- isConsistent = false;
- return;
- }
-
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityType.java
deleted file mode 100644
index 5864a1c..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityType.java
+++ /dev/null
@@ -1,230 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmEntityType extends JPAEdmBaseViewImpl implements JPAEdmEntityTypeView {
-
- private JPAEdmSchemaView schemaView = null;
- private EntityType currentEdmEntityType = null;
- private javax.persistence.metamodel.EntityType<?> currentJPAEntityType = null;
- private EntityTypeList<EntityType> consistentEntityTypes = null;
-
- private HashMap<String, EntityType> consistentEntityTypeMap;
-
- public JPAEdmEntityType(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- consistentEntityTypeMap = new HashMap<String, EntityType>();
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmEntityTypeBuilder();
- }
-
- return builder;
- }
-
- @Override
- public EntityType getEdmEntityType() {
- return currentEdmEntityType;
- }
-
- @Override
- public javax.persistence.metamodel.EntityType<?> getJPAEntityType() {
- return currentJPAEntityType;
- }
-
- @Override
- public List<EntityType> getConsistentEdmEntityTypes() {
- return consistentEntityTypes;
- }
-
- @Override
- public EntityType searchEdmEntityType(final String jpaEntityTypeName) {
- return consistentEntityTypeMap.get(jpaEntityTypeName);
- }
-
- private class JPAEdmEntityTypeBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- Set<javax.persistence.metamodel.EntityType<?>> jpaEntityTypes = metaModel.getEntities();
-
- if (jpaEntityTypes == null || jpaEntityTypes.isEmpty() == true) {
- return;
- } else if (consistentEntityTypes == null) {
- consistentEntityTypes = new EntityTypeList<EntityType>();
-
- }
-
- for (javax.persistence.metamodel.EntityType<?> jpaEntityType : jpaEntityTypes) {
- currentEdmEntityType = new EntityType();
- currentJPAEntityType = jpaEntityType;
-
- // Check for need to Exclude
- if (isExcluded(JPAEdmEntityType.this)) {
- continue;
- }
-
- JPAEdmNameBuilder.build(JPAEdmEntityType.this);
-
- JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView);
- propertyView.getBuilder().build();
-
- currentEdmEntityType.setProperties(propertyView.getEdmPropertyList());
- if (propertyView.getJPAEdmNavigationPropertyView() != null) {
- JPAEdmNavigationPropertyView navPropView = propertyView.getJPAEdmNavigationPropertyView();
- if (navPropView.getConsistentEdmNavigationProperties() != null
- && !navPropView.getConsistentEdmNavigationProperties().isEmpty()) {
- currentEdmEntityType.setNavigationProperties(navPropView.getConsistentEdmNavigationProperties());
- }
- }
- JPAEdmKeyView keyView = propertyView.getJPAEdmKeyView();
- currentEdmEntityType.setKey(keyView.getEdmKey());
-
- consistentEntityTypes.add(currentEdmEntityType);
- consistentEntityTypeMap.put(currentJPAEntityType.getName(), currentEdmEntityType);
- }
-
- }
-
- private boolean isExcluded(final JPAEdmEntityType jpaEdmEntityType) {
- JPAEdmMappingModelAccess mappingModelAccess = jpaEdmEntityType.getJPAEdmMappingModelAccess();
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()
- && mappingModelAccess.checkExclusionOfJPAEntityType(jpaEdmEntityType.getJPAEntityType().getName())) {
- return true;
- }
- return false;
- }
-
- }
-
- private class EntityTypeList<X> extends ArrayList<EntityType> {
-
- /**
- *
- */
- private static final long serialVersionUID = 719079109608251592L;
-
- @Override
- public Iterator<EntityType> iterator() {
- return new EntityTypeListIterator<X>(size());
- }
-
- }
-
- private class EntityTypeListIterator<E> implements ListIterator<EntityType> {
-
- private int size = 0;
- private int pos = 0;
-
- public EntityTypeListIterator(final int listSize) {
- this.size = listSize;
- }
-
- @Override
- public void add(final EntityType e) {
- consistentEntityTypes.add(e);
- size++;
- }
-
- @Override
- public boolean hasNext() {
- if (pos < size) {
- return true;
- }
-
- return false;
- }
-
- @Override
- public boolean hasPrevious() {
- if (pos > 0) {
- return true;
- }
- return false;
- }
-
- @Override
- public EntityType next() {
- if (pos < size) {
- currentEdmEntityType = consistentEntityTypes.get(pos++);
- return currentEdmEntityType;
- }
-
- return null;
- }
-
- @Override
- public int nextIndex() {
- return pos;
- }
-
- @Override
- public EntityType previous() {
- if (pos > 0 && pos < size) {
- currentEdmEntityType = consistentEntityTypes.get(--pos);
- return currentEdmEntityType;
- }
- return null;
- }
-
- @Override
- public int previousIndex() {
- if (pos > 0) {
- return pos - 1;
- }
-
- return 0;
- }
-
- @Override
- public void remove() {
- consistentEntityTypes.remove(pos);
- }
-
- @Override
- public void set(final EntityType e) {
- consistentEntityTypes.set(pos, e);
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFacets.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFacets.java
deleted file mode 100644
index 61f984f..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFacets.java
+++ /dev/null
@@ -1,94 +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.odata2.processor.core.jpa.model;
-
-import java.lang.reflect.AnnotatedElement;
-
-import javax.persistence.Column;
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-
-public class JPAEdmFacets {
- public static void setFacets(final Attribute<?, ?> jpaAttribute, final SimpleProperty edmProperty) {
- EdmSimpleTypeKind edmTypeKind = edmProperty.getType();
- Facets facets = new Facets();
- edmProperty.setFacets(facets);
-
- Column column = null;
- if (jpaAttribute.getJavaMember() instanceof AnnotatedElement) {
- column = ((AnnotatedElement) jpaAttribute
- .getJavaMember()).getAnnotation(Column.class);
- }
-
- if (column == null) {
- return;
- }
-
- setNullable(column, edmProperty);
-
- switch (edmTypeKind) {
- case Binary:
- setMaxLength(column, edmProperty);
- break;
- case DateTime:
- setPrecision(column, edmProperty);
- break;
- case DateTimeOffset:
- setPrecision(column, edmProperty);
- break;
- case Time:
- setPrecision(column, edmProperty);
- break;
- case Decimal:
- setPrecision(column, edmProperty);
- setScale(column, edmProperty);
- break;
- case String:
- setMaxLength(column, edmProperty);
- break;
- default:
- break;
- }
- }
-
- private static void setNullable(final Column column, final SimpleProperty edmProperty) {
- ((Facets) edmProperty.getFacets()).setNullable(column.nullable());
- }
-
- private static void setMaxLength(final Column column, final SimpleProperty edmProperty) {
- if (column.length() > 0) {
- ((Facets) edmProperty.getFacets()).setMaxLength(column.length());
- }
- }
-
- private static void setPrecision(final Column column, final SimpleProperty edmProperty) {
- if (column.precision() > 0) {
- ((Facets) edmProperty.getFacets()).setPrecision(column.precision());
- }
- }
-
- private static void setScale(final Column column, final SimpleProperty edmProperty) {
- if (column.scale() > 0) {
- ((Facets) edmProperty.getFacets()).setScale(column.scale());
- }
- }
-}
[03/47] git commit: [OLINGO-86] Test for value access
Posted by tb...@apache.org.
[OLINGO-86] Test for value access
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/d9a7f2db
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d9a7f2db
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d9a7f2db
Branch: refs/heads/ODataServlet
Commit: d9a7f2db447410b0d1b842d8f4b3697890cbed80
Parents: 636eed2
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Dec 23 08:18:43 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Dec 23 08:18:43 2013 +0100
----------------------------------------------------------------------
.../processor/core/ListsProcessorTest.java | 40 +++
.../datasource/AnnotationValueAccessTest.java | 237 +++++++++++++++++
.../core/datasource/BeanPropertyAccessTest.java | 261 +++++++++++++++++++
3 files changed, 538 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d9a7f2db/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
new file mode 100644
index 0000000..b7642fb
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/ListsProcessorTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core;
+
+import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationValueAccess;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.ValueAccess;
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class ListsProcessorTest {
+
+ @Test
+ public void init() throws ODataException {
+ DataSource dataSource = new AnnotationInMemoryDs(Building.class.getPackage().getName());
+ ValueAccess valueAccess = new AnnotationValueAccess();
+ ListsProcessor lp = new ListsProcessor(dataSource, valueAccess);
+
+ Assert.assertNotNull(lp);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d9a7f2db/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
new file mode 100644
index 0000000..5e9147f
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationValueAccessTest.java
@@ -0,0 +1,237 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.datasource;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class AnnotationValueAccessTest {
+
+ @Test
+ public void getPropertyType() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Class<?> type = ava.getPropertyType(data, property);
+
+ Assert.assertEquals(String.class, type);
+ }
+
+ @Test(expected=ODataNotImplementedException.class)
+ public void getPropertyTypeNotAnnotated() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ NotAnnotatedBean data = new NotAnnotatedBean();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Class<?> type = ava.getPropertyType(data, property);
+
+ Assert.assertEquals(String.class, type);
+ }
+
+ @Test
+ public void getPropertyValue() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertEquals(String.class, value.getClass());
+ Assert.assertEquals("A Name", value);
+ }
+
+ @Test
+ public void getPropertyValueNull() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void getPropertyValueNullData() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = null;
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertNull(value);
+ }
+
+ @Test(expected=ODataNotImplementedException.class)
+ public void getPropertyValueNotAnnotated() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ NotAnnotatedBean data = new NotAnnotatedBean();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+ Assert.assertEquals("A Name", value);
+ }
+
+ @Test
+ public void setPropertyValue() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Object value = "Another Name";
+ ava.setPropertyValue(data, property, value);
+
+ Assert.assertEquals("Another Name", data.name);
+ }
+
+ @Test(expected=ODataNotImplementedException.class)
+ public void setPropertyValueNotAnnotated() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ NotAnnotatedBean data = new NotAnnotatedBean();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Object value = "Another Name";
+ ava.setPropertyValue(data, property, value);
+ }
+
+ @Test
+ public void setPropertyValueNull() throws ODataException {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ ava.setPropertyValue(data, property, null);
+
+ Assert.assertNull(null, data.name);
+ }
+
+ @Test
+ public void getMappingValue() throws Exception {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = mockMapping("MyMappedProperty");
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertEquals(String.class, value.getClass());
+ Assert.assertEquals("mapped property value", value);
+ }
+
+ @Test
+ public void getMappingValueNullMapping() throws Exception {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "property";
+ EdmMapping mapping = null;
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void getMappingValueNullValue() throws Exception {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = null;
+ EdmMapping mapping = mockMapping("MyMappedProperty");
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void setMappingValue() throws Exception {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = mockMapping("MyMappedProperty");
+
+ Object value = "Changed mapped property value";
+ ava.setMappingValue(data, mapping, value);
+
+ Assert.assertEquals("Changed mapped property value", data.myMappedProperty);
+ }
+
+ @Test
+ public void setMappingValueNullValue() throws Exception {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = mockMapping("MyMappedProperty");
+
+ Object value = null;
+ ava.setMappingValue(data, mapping, value);
+
+ Assert.assertNull(data.myMappedProperty);
+ }
+
+ @Test
+ public void setMappingValueNullMapping() throws Exception {
+ AnnotationValueAccess ava = new AnnotationValueAccess();
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = null;
+
+ Object value = null;
+ ava.setMappingValue(data, mapping, value);
+
+ Assert.assertEquals("mapped property value", data.myMappedProperty);
+ }
+
+ private EdmProperty mockProperty(String name) throws EdmException {
+ EdmProperty property = Mockito.mock(EdmProperty.class);
+ Mockito.when(property.getName()).thenReturn(name);
+ return property;
+ }
+
+ private EdmMapping mockMapping(String mimeTypeKey) throws EdmException {
+ EdmMapping mapping = Mockito.mock(EdmMapping.class);
+ Mockito.when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mimeTypeKey);
+ return mapping;
+ }
+
+ @EdmEntityType
+ private class SimpleEntity {
+ @org.apache.olingo.odata2.api.annotation.edm.EdmProperty String name;
+ @org.apache.olingo.odata2.api.annotation.edm.EdmProperty String myMappedProperty;
+ }
+
+ private class NotAnnotatedBean {
+ private String name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d9a7f2db/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/BeanPropertyAccessTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/BeanPropertyAccessTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/BeanPropertyAccessTest.java
new file mode 100644
index 0000000..322116a
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/BeanPropertyAccessTest.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.datasource;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class BeanPropertyAccessTest {
+
+ private final BeanPropertyAccess ava;
+
+ public BeanPropertyAccessTest() {
+ ava = new BeanPropertyAccess();
+ }
+
+ @Test
+ public void getPropertyType() throws ODataException {
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Class<?> type = ava.getPropertyType(data, property);
+
+ Assert.assertEquals(String.class, type);
+ }
+
+ @Test(expected=ODataNotFoundException.class)
+ public void getPropertyTypeInvalidPropertyName() throws ODataException {
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("invalid.Name");
+
+ Object value = ava.getPropertyValue(data, property);
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void getPropertyValue() throws ODataException {
+
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertEquals(String.class, value.getClass());
+ Assert.assertEquals("A Name", value);
+ }
+
+ @Test
+ public void getPropertyValueBoolean() throws ODataException {
+
+ SimpleEntity data = new SimpleEntity();
+ EdmProperty property = mockProperty("BooleanProperty", true);
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertEquals(Boolean.class, value.getClass());
+ Assert.assertEquals(true, value);
+ }
+
+ @Test
+ public void getPropertyValueNull() throws ODataException {
+
+ SimpleEntity data = new SimpleEntity();
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void getPropertyValueNullData() throws ODataException {
+
+ SimpleEntity data = null;
+ EdmProperty property = mockProperty("Name");
+
+ Object value = ava.getPropertyValue(data, property);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void setPropertyValue() throws ODataException {
+
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ Object value = "Another Name";
+ ava.setPropertyValue(data, property, value);
+
+ Assert.assertEquals("Another Name", data.name);
+ }
+
+ @Test
+ public void setPropertyValueNull() throws ODataException {
+
+ SimpleEntity data = new SimpleEntity();
+ data.name = "A Name";
+ EdmProperty property = mockProperty("Name");
+
+ ava.setPropertyValue(data, property, null);
+
+ Assert.assertNull(null, data.name);
+ }
+
+ @Test
+ public void getMappingValue() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = mockMapping("getMyMappedProperty");
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertEquals(String.class, value.getClass());
+ Assert.assertEquals("mapped property value", value);
+ }
+
+
+ @Test
+ public void getMappingValueNullMapping() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "property";
+ EdmMapping mapping = null;
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void getMappingValueNullValue() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = null;
+ EdmMapping mapping = mockMapping("getMyMappedProperty");
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertNull(value);
+ }
+
+ @Test
+ public void setMappingValue() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = mockMapping("getMyMappedProperty");
+
+ Object value = "Changed mapped property value";
+ ava.setMappingValue(data, mapping, value);
+
+ Assert.assertEquals("Changed mapped property value", data.myMappedProperty);
+ }
+
+ @Test
+ public void setMappingValueNullValue() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = mockMapping("getMyMappedProperty");
+
+ Object value = null;
+ ava.setMappingValue(data, mapping, value);
+
+ Assert.assertNull(data.myMappedProperty);
+ }
+
+ @Test
+ public void setMappingValueNullMapping() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = "mapped property value";
+ EdmMapping mapping = null;
+
+ Object value = null;
+ ava.setMappingValue(data, mapping, value);
+
+ Assert.assertEquals("mapped property value", data.myMappedProperty);
+ }
+
+ @Test(expected=ODataNotFoundException.class)
+ public void invalidMethodName() throws Exception {
+
+ SimpleEntity data = new SimpleEntity();
+ data.myMappedProperty = null;
+ EdmMapping mapping = mockMapping("MyMappedProperty");
+
+ Object value = ava.getMappingValue(data, mapping);
+
+ Assert.assertNull(value);
+ }
+
+ private EdmProperty mockProperty(String name) throws EdmException {
+ return mockProperty(name, false);
+ }
+
+ private EdmProperty mockProperty(String name, boolean isBoolean) throws EdmException {
+ EdmProperty property = Mockito.mock(EdmProperty.class);
+ Mockito.when(property.getName()).thenReturn(name);
+ Mockito.when(property.isSimple()).thenReturn(Boolean.TRUE);
+ if(isBoolean) {
+ Mockito.when(property.getType()).thenReturn(EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance());
+ }
+ return property;
+ }
+
+ private EdmMapping mockMapping(String mimeTypeKey) throws EdmException {
+ EdmMapping mapping = Mockito.mock(EdmMapping.class);
+ Mockito.when(mapping.getMimeType()).thenReturn(mimeTypeKey);
+ return mapping;
+ }
+
+ private class SimpleEntity {
+ private String name;
+ private String myMappedProperty;
+ public final String getName() {
+ return name;
+ }
+ public final void setName(String name) {
+ this.name = name;
+ }
+ public final String getMyMappedProperty() {
+ return myMappedProperty;
+ }
+ public final void setMyMappedProperty(String myMappedProperty) {
+ this.myMappedProperty = myMappedProperty;
+ }
+ public final boolean isBooleanProperty() {
+ return true;
+ }
+ }
+}
[23/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java
new file mode 100644
index 0000000..359ddfa
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAFunctionContextTest.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteral;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAFunctionContext;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class JPAFunctionContextTest {
+
+ private int VARIANT = 0;
+
+ public JPAFunctionContext build() {
+ JPAFunctionContext functionContext = null;
+ try {
+ if (VARIANT == 0) {
+ functionContext =
+ (JPAFunctionContext) JPAMethodContext.createBuilder(JPQLContextType.FUNCTION, getView()).build();
+ }
+
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ return functionContext;
+ }
+
+ @Test
+ public void testGetEnclosingObject() {
+
+ VARIANT = 0;
+
+ Assert.assertNotNull(build());
+
+ }
+
+ private GetFunctionImportUriInfo getView() {
+ GetFunctionImportUriInfo functiontView = EasyMock.createMock(GetFunctionImportUriInfo.class);
+ EasyMock.expect(functiontView.getFunctionImport()).andStubReturn(getEdmFunctionImport());
+ EasyMock.expect(functiontView.getFunctionImportParameters()).andStubReturn(getFunctionImportParameters());
+
+ EasyMock.replay(functiontView);
+ return functiontView;
+ }
+
+ private Map<String, EdmLiteral> getFunctionImportParameters() {
+ return null;
+ }
+
+ private EdmFunctionImport getEdmFunctionImport() {
+ EdmFunctionImport edmFunctionImport = EasyMock.createMock(EdmFunctionImport.class);
+ try {
+ EasyMock.expect(edmFunctionImport.getMapping()).andStubReturn(getMapping());
+ EasyMock.expect(edmFunctionImport.getParameterNames()).andStubReturn(getParameterNames());
+ EasyMock.expect(edmFunctionImport.getParameter("Gentleman")).andStubReturn(getParameter("Gentleman"));
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmFunctionImport);
+ return edmFunctionImport;
+ }
+
+ private EdmParameter getParameter(final String string) {
+ EdmParameter edmParameter = EasyMock.createMock(EdmParameter.class);
+ try {
+ EasyMock.expect(edmParameter.getMapping()).andStubReturn(getEdmMapping());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmParameter);
+ return edmParameter;
+ }
+
+ private EdmMapping getEdmMapping() {
+ JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(String.class);
+ ((Mapping) mapping).setInternalName("Gentleman");
+ return mapping;
+ }
+
+ private JPAEdmMappingImpl getMapping() {
+ JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(FunctionImportTestClass.class);
+ ((Mapping) mapping).setInternalName("testMethod");
+ return mapping;
+ }
+
+ private Collection<String> getParameterNames() {
+ Collection<String> parametersList = new ArrayList<String>();
+ parametersList.add("Gentleman");
+ return parametersList;
+ }
+
+ public static class FunctionImportTestClass {
+
+ public FunctionImportTestClass() {
+
+ }
+
+ public String testMethod(final String message) {
+ return "Hello " + message + "!!";
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
new file mode 100644
index 0000000..915a7d3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAProcessorImplTest.java
@@ -0,0 +1,448 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import static org.junit.Assert.fail;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+import javax.persistence.metamodel.Metamodel;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAProcessorImplTest {
+
+ // -------------------------------- Common Start ------------------------------------common in
+ // ODataJPAProcessorDefaultTest as well
+ private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
+ private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
+ private static final String SO_ID = "SoId";
+ private static final String SALES_ORDER = "SalesOrder";
+ private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
+ // -------------------------------- Common End ------------------------------------
+
+ JPAProcessorImpl objJPAProcessorImpl;
+
+ @Before
+ public void setUp() throws Exception {
+ objJPAProcessorImpl = new JPAProcessorImpl(getLocalmockODataJPAContext());
+ }
+
+ @Test
+ public void testProcessGetEntitySetCountUriInfo() {
+ try {
+ Assert.assertEquals(11, objJPAProcessorImpl.process(getEntitySetCountUriInfo()));
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testProcessGetEntityCountUriInfo() {
+ try {
+ Assert.assertEquals(11, objJPAProcessorImpl.process(getEntityCountUriInfo()));
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testProcessGetEntitySetUriInfo() {
+ try {
+ Assert.assertNotNull(objJPAProcessorImpl.process(getEntitySetUriInfo()));
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testProcessDeleteUriInfo() {
+ try {
+ Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ Assert.assertEquals(new Address(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testProcessDeleteUriInfoNegative() {
+ try {
+ Assert.assertNotNull(objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ Assert.assertNotSame(new Object(), objJPAProcessorImpl.process(getDeletetUriInfo(), "application/xml"));
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ // ---------------------------- Common Code Start ---------------- TODO - common in ODataJPAProcessorDefaultTest as
+ // well
+
+ private DeleteUriInfo getDeletetUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ private List<KeyPredicate> getKeyPredicates() {
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ return keyPredicates;
+ }
+
+ private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private GetEntityCountUriInfo getEntityCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private GetEntitySetUriInfo getEntitySetUriInfo() {
+
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ // EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(getFunctionImport());
+ EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ /**
+ * @return
+ */
+ private UriInfo getLocalUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ /**
+ * @return
+ * @throws EdmException
+ */
+ private EdmEntitySet getLocalEdmEntitySet() {
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
+ EasyMock.replay(edmEntitySet);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return edmEntitySet;
+ }
+
+ /**
+ * @return
+ * @throws EdmException
+ */
+ private EdmEntityType getLocalEdmEntityType() {
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ try {
+ EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+ EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
+ EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
+ EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
+ EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));// ID vs Salesorder
+ // ID
+ EasyMock.replay(edmEntityType);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return edmEntityType;
+ }
+
+ private InlineCount getInlineCount() {
+ return InlineCount.NONE;
+ }
+
+ private FilterExpression getFilter() {
+ return null;
+ }
+
+ private Integer getSkip() {
+ return null;
+ }
+
+ private Integer getTop() {
+ return null;
+ }
+
+ private OrderByExpression getOrderByExpression() {
+ return null;
+ }
+
+ private ODataJPAContext getLocalmockODataJPAContext() {
+ ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
+ EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
+ EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+ EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
+ EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(odataJPAContext);
+ return odataJPAContext;
+ }
+
+ private EntityManagerFactory mockEntityManagerFactory() {
+ EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+ EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
+ EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(emf);
+ return emf;
+ }
+
+ public EntityManager getLocalEntityManager() {
+ EntityManager em = EasyMock.createMock(EntityManager.class);
+ EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
+ EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(
+ getQueryForSelectCount());
+ EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); // For Delete
+ em.flush();
+ em.flush();
+ Address obj = new Address();
+ em.remove(obj);// testing void method
+ em.remove(obj);// testing void method
+ EasyMock.replay(em);
+ return em;
+ }
+
+ private EntityTransaction getLocalTransaction() {
+ EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
+ entityTransaction.begin(); // testing void method
+ entityTransaction.begin(); // testing void method
+ entityTransaction.commit();// testing void method
+ entityTransaction.commit();// testing void method
+ EasyMock.replay(entityTransaction);
+ return entityTransaction;
+ }
+
+ private Query getQuery() {
+ Query query = EasyMock.createMock(Query.class);
+ EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
+ EasyMock.replay(query);
+ return query;
+ }
+
+ private Query getQueryForSelectCount() {
+ Query query = EasyMock.createMock(Query.class);
+ EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
+ EasyMock.replay(query);
+ return query;
+ }
+
+ private List<?> getResultList() {
+ List<Object> list = new ArrayList<Object>();
+ list.add(new Address());
+ return list;
+ }
+
+ private List<?> getResultListForSelectCount() {
+ List<Object> list = new ArrayList<Object>();
+ list.add(new Long(11));
+ return list;
+ }
+
+ private class Address {
+ private String soId = "12";
+
+ public String getSoId() {
+ return soId;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ boolean isEqual = false;
+ if (obj instanceof Address) {
+ isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
+ }
+ return isEqual;
+ }
+ }
+
+ private Metamodel mockMetaModel() {
+ Metamodel metaModel = EasyMock.createMock(Metamodel.class);
+ EasyMock.replay(metaModel);
+ return metaModel;
+ }
+
+ private EdmEntityContainer getLocalEdmEntityContainer() {
+ EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
+ EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
+ try {
+ EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmEntityContainer);
+ return edmEntityContainer;
+ }
+
+ private EdmTyped getEdmTypedMockedObj(final String propertyName) {
+ EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
+ try {
+ EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType);
+ EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
+ EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
+
+ EasyMock.replay(mockedEdmProperty);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return mockedEdmProperty;
+ }
+
+ private EdmFacets getEdmFacetsMockedObj() {
+ EdmFacets facets = EasyMock.createMock(EdmFacets.class);
+ EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
+
+ EasyMock.replay(facets);
+ return facets;
+ }
+
+ private EdmMapping getEdmMappingMockedObj(final String propertyName) {
+ EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
+ if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
+ } else {
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
+ }
+ EasyMock.replay(mockedEdmMapping);
+ return mockedEdmMapping;
+ }
+
+ private List<String> getLocalPropertyNames() {
+ List<String> list = new ArrayList<String>();
+ list.add(SO_ID);
+ return list;
+ }
+
+ private ODataContext getLocalODataContext() {
+ ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
+ try {
+ EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objODataContext);
+ return objODataContext;
+ }
+
+ private PathInfo getLocalPathInfo() {
+ PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
+ EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
+ EasyMock.replay(pathInfo);
+ return pathInfo;
+ }
+
+ private URI getLocalURI() {
+ URI uri = null;
+ try {
+ uri = new URI(STR_LOCAL_URI);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return uri;
+ }
+
+ // -------------------------------- Common End ------------------------------------
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java
new file mode 100644
index 0000000..073cd1f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmMappingModelServiceTest.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.InputStream;
+
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmMappingModelService;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPAEdmMappingModelServiceTest extends JPAEdmMappingModelService {
+
+ private static JPAEdmMappingModelServiceTest objJPAEdmMappingModelServiceTest;
+
+ private static final String MAPPING_FILE_CORRECT = "SalesOrderProcessingMappingModels.xml";
+ private static final String MAPPING_FILE_INCORRECT = "TEST.xml";
+
+ private static int VARIANT_MAPPING_FILE; // 0 FOR INCORRECT, 1 FOR CORRECT
+
+ private static String PERSISTENCE_UNIT_NAME_JPA = "salesorderprocessing";
+ private static String PERSISTENCE_UNIT_NAME_EDM = "SalesOrderProcessing";
+
+ private static String ENTITY_TYPE_NAME_JPA = "SalesOrderHeader";
+ private static String ENTITY_TYPE_NAME_EDM = "SalesOrder";
+ private static String ENTITY_SET_NAME_EDM = "SalesOrders";
+ private static String RELATIONSHIP_NAME_JPA = "salesOrderItems";
+ private static String RELATIONSHIP_NAME_EDM = "SalesOrderItemDetails";
+ private static String ATTRIBUTE_NAME_JPA = "netAmount";
+ private static String ATTRIBUTE_NAME_EDM = "NetAmount";
+ private static String EMBEDDABLE_TYPE_NAME_JPA = "SalesOrderItemKey";
+ private static String EMBEDDABLE_ATTRIBUTE_NAME_JPA = "liId";
+ private static String EMBEDDABLE_ATTRIBUTE_NAME_EDM = "ID";
+ private static String EMBEDDABLE_TYPE_2_NAME_JPA = "SalesOrderItemKey";
+
+ private static String ENTITY_TYPE_NAME_JPA_WRONG = "SalesOrderHeaders";
+ private static String RELATIONSHIP_NAME_JPA_WRONG = "value";
+ private static String EMBEDDABLE_TYPE_NAME_JPA_WRONG = "SalesOrderItemKeys";
+
+ public JPAEdmMappingModelServiceTest() {
+ super(ODataJPAContextMock.mockODataJPAContext());
+ }
+
+ @BeforeClass
+ public static void setup() {
+ objJPAEdmMappingModelServiceTest = new JPAEdmMappingModelServiceTest();
+ VARIANT_MAPPING_FILE = 1;
+ objJPAEdmMappingModelServiceTest.loadMappingModel();
+ }
+
+ @Test
+ public void testLoadMappingModel() {
+ VARIANT_MAPPING_FILE = 1;
+ loadMappingModel();
+ assertTrue(isMappingModelExists());
+ }
+
+ @Test
+ public void testLoadMappingModelNegative() {
+ VARIANT_MAPPING_FILE = 0;
+ loadMappingModel();
+ assertFalse(isMappingModelExists());
+ // reset it for other JUnits
+ VARIANT_MAPPING_FILE = 1;
+ loadMappingModel();
+ }
+
+ @Test
+ public void testIsMappingModelExists() {
+ assertTrue(objJPAEdmMappingModelServiceTest.isMappingModelExists());
+ }
+
+ @Test
+ public void testGetJPAEdmMappingModel() {
+ assertNotNull(objJPAEdmMappingModelServiceTest.getJPAEdmMappingModel());
+ }
+
+ @Test
+ public void testMapJPAPersistenceUnit() {
+ assertEquals(PERSISTENCE_UNIT_NAME_EDM, objJPAEdmMappingModelServiceTest
+ .mapJPAPersistenceUnit(PERSISTENCE_UNIT_NAME_JPA));
+ }
+
+ @Test
+ public void testMapJPAPersistenceUnitNegative() {
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPAPersistenceUnit(PERSISTENCE_UNIT_NAME_EDM));// Wrong value to
+ // bring null
+ }
+
+ @Test
+ public void testMapJPAEntityType() {
+ assertEquals(ENTITY_TYPE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEntityType(ENTITY_TYPE_NAME_JPA));
+ }
+
+ @Test
+ public void testMapJPAEntityTypeNegative() {
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPAEntityType(ENTITY_TYPE_NAME_JPA_WRONG));// Wrong value to bring
+ // null
+ }
+
+ @Test
+ public void testMapJPAEntitySet() {
+ assertEquals(ENTITY_SET_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEntitySet(ENTITY_TYPE_NAME_JPA));
+ }
+
+ @Test
+ public void testMapJPAEntitySetNegative() {
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPAEntitySet(ENTITY_TYPE_NAME_JPA_WRONG));// Wrong value to bring
+ // null
+ }
+
+ @Test
+ public void testMapJPAAttribute() {
+ assertEquals(ATTRIBUTE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAAttribute(ENTITY_TYPE_NAME_JPA,
+ ATTRIBUTE_NAME_JPA));
+ }
+
+ @Test
+ public void testMapJPAAttributeNegative() {
+ // Wrong value to bring null
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPAAttribute(ENTITY_TYPE_NAME_JPA, ATTRIBUTE_NAME_JPA + "AA"));
+ }
+
+ @Test
+ public void testMapJPARelationship() {
+ assertEquals(RELATIONSHIP_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPARelationship(ENTITY_TYPE_NAME_JPA,
+ RELATIONSHIP_NAME_JPA));
+ }
+
+ @Test
+ public void testMapJPARelationshipNegative() {
+ // Wrong value to bring null
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPARelationship(ENTITY_TYPE_NAME_JPA, RELATIONSHIP_NAME_JPA_WRONG));
+ }
+
+ @Test
+ public void testMapJPAEmbeddableType() {
+ assertEquals("SalesOrderLineItemKey", objJPAEdmMappingModelServiceTest.mapJPAEmbeddableType("SalesOrderItemKey"));
+ }
+
+ @Test
+ public void testMapJPAEmbeddableTypeNegative() {
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPAEmbeddableType(EMBEDDABLE_TYPE_NAME_JPA_WRONG));// Wrong value to
+ // bring null
+ }
+
+ @Test
+ public void testMapJPAEmbeddableTypeAttribute() {
+ assertEquals(EMBEDDABLE_ATTRIBUTE_NAME_EDM, objJPAEdmMappingModelServiceTest.mapJPAEmbeddableTypeAttribute(
+ EMBEDDABLE_TYPE_NAME_JPA, EMBEDDABLE_ATTRIBUTE_NAME_JPA));
+ }
+
+ @Test
+ public void testMapJPAEmbeddableTypeAttributeNegative() {
+ assertNull(objJPAEdmMappingModelServiceTest.mapJPAEmbeddableTypeAttribute(EMBEDDABLE_TYPE_NAME_JPA_WRONG,
+ EMBEDDABLE_ATTRIBUTE_NAME_JPA));
+ }
+
+ @Test
+ public void testCheckExclusionOfJPAEntityType() {
+ assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEntityType(ENTITY_TYPE_NAME_JPA));
+ }
+
+ @Test
+ public void testCheckExclusionOfJPAAttributeType() {
+ assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAAttributeType(ENTITY_TYPE_NAME_JPA,
+ ATTRIBUTE_NAME_JPA));
+ }
+
+ @Test
+ public void testCheckExclusionOfJPAEmbeddableType() {
+ assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEmbeddableType(EMBEDDABLE_TYPE_2_NAME_JPA));
+ }
+
+ @Test
+ public void testCheckExclusionOfJPAEmbeddableAttributeType() {
+ assertTrue(!objJPAEdmMappingModelServiceTest.checkExclusionOfJPAEmbeddableAttributeType(EMBEDDABLE_TYPE_NAME_JPA,
+ EMBEDDABLE_ATTRIBUTE_NAME_JPA));
+ }
+
+ /**
+ * This method is for loading the xml file for testing.
+ */
+ @Override
+ protected InputStream loadMappingModelInputStream() {
+ if (VARIANT_MAPPING_FILE == 1) {
+ return ClassLoader.getSystemResourceAsStream(MAPPING_FILE_CORRECT);
+ } else {
+ return ClassLoader.getSystemResourceAsStream(MAPPING_FILE_INCORRECT);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
new file mode 100644
index 0000000..73af3e9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPAEdmNameBuilderTest.java
@@ -0,0 +1,153 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmMappingModelService;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class JPAEdmNameBuilderTest {
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testBuildJPAEdmPropertyView() {
+
+ SimpleProperty simpleProperty = new SimpleProperty();
+
+ // Mocking EDMProperty
+ JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
+ JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
+
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
+ EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(propertyView, false, false);
+ assertEquals("Id", simpleProperty.getName());
+ }
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Test
+ public void testBuildJPAEdmPropertyViewWithNoDefaultNaming() {
+
+ SimpleProperty simpleProperty = new SimpleProperty();
+
+ // Mocking EDMProperty
+ JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
+ JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
+
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.expect(propertyView.getJPAEdmMappingModelAccess()).andStubReturn(null);
+ EasyMock.expect(propertyView.getEdmSimpleProperty()).andStubReturn(simpleProperty);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(propertyView, false, true);
+ assertEquals("id", simpleProperty.getName());
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testBuildJPAEdmComplexPropertyView() {
+ JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
+ ComplexProperty complexProperty = new ComplexProperty();
+ EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
+ ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
+ JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
+ EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);
+
+ // Mocking EDMProperty
+ JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
+ JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
+ EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JPAEntityType());
+ EasyMock.replay(entityTypeView);
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.replay(complexPropertyView);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(complexPropertyView, propertyView, false);
+ assertEquals("Id", complexPropertyView.getEdmComplexProperty().getName());
+
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ @Test
+ public void testBuildJPAEdmComplexPropertyViewWithNoDefaultNaming() {
+ JPAEdmComplexPropertyView complexPropertyView = EasyMock.createMock(JPAEdmComplexPropertyView.class);
+ ComplexProperty complexProperty = new ComplexProperty();
+ EasyMock.expect(complexPropertyView.getEdmComplexProperty()).andStubReturn(complexProperty);
+ ODataJPAContextImpl oDataJPAContext = new ODataJPAContextImpl();
+ JPAEdmMappingModelService mappingModelService = new JPAEdmMappingModelService(oDataJPAContext);
+ EasyMock.expect(complexPropertyView.getJPAEdmMappingModelAccess()).andStubReturn(mappingModelService);
+
+ // Mocking EDMProperty
+ JPAEdmPropertyView propertyView = EasyMock.createMock(JPAEdmPropertyView.class);
+ JPAEdmEntityTypeView entityTypeView = EasyMock.createMock(JPAEdmEntityTypeView.class);
+ EasyMock.expect(entityTypeView.getJPAEntityType()).andStubReturn(new JPAEntityType());
+ EasyMock.replay(entityTypeView);
+ EasyMock.expect(propertyView.getJPAAttribute()).andStubReturn(new JPAAttribute());
+ EasyMock.expect(propertyView.getJPAEdmEntityTypeView()).andStubReturn(entityTypeView);
+ EasyMock.replay(complexPropertyView);
+ EasyMock.replay(propertyView);
+
+ JPAEdmNameBuilder.build(complexPropertyView, propertyView, true);
+ assertEquals("id", complexPropertyView.getEdmComplexProperty().getName());
+
+ }
+
+ @SuppressWarnings("hiding")
+ class JPAAttribute<Object, String> extends JPAAttributeMock<Object, java.lang.String> {
+
+ @Override
+ public java.lang.String getName() {
+ return "id";
+ }
+
+ @Override
+ public Class<java.lang.String> getJavaType() {
+ return java.lang.String.class;
+ }
+
+ }
+
+ @SuppressWarnings("hiding")
+ class JPAEntityType<Object> extends JPAEntityTypeMock<Object> {
+
+ @Override
+ public java.lang.String getName() {
+ return "SalesOrderHeader";
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
new file mode 100644
index 0000000..cdcf3b1
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/model/JPATypeConvertorTest.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+import java.util.UUID;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPATypeConvertor;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.junit.Test;
+
+public class JPATypeConvertorTest {
+
+ private EdmSimpleTypeKind edmSimpleKindTypeString;
+ private EdmSimpleTypeKind edmSimpleKindTypeByteArr;
+ private EdmSimpleTypeKind edmSimpleKindTypeLong;
+ private EdmSimpleTypeKind edmSimpleKindTypeShort;
+ private EdmSimpleTypeKind edmSimpleKindTypeInteger;
+ private EdmSimpleTypeKind edmSimpleKindTypeDouble;
+ private EdmSimpleTypeKind edmSimpleKindTypeFloat;
+ private EdmSimpleTypeKind edmSimpleKindTypeBigDecimal;
+ private EdmSimpleTypeKind edmSimpleKindTypeByte;
+ private EdmSimpleTypeKind edmSimpleKindTypeBoolean;
+ private EdmSimpleTypeKind edmSimpleKindTypeUUID;
+
+ @Test
+ public void testConvertToEdmSimpleType() {
+ String str = "entity";
+ byte[] byteArr = new byte[3];
+ Long longObj = new Long(0);
+ Short shortObj = new Short((short) 0);
+ Integer integerObj = new Integer(0);
+ Double doubleObj = new Double(0);
+ Float floatObj = new Float(0);
+ BigDecimal bigDecimalObj = new BigDecimal(0);
+ Byte byteObj = new Byte((byte) 0);
+ Boolean booleanObj = Boolean.TRUE;
+ UUID uUID = new UUID(0, 0);
+
+ try {
+ edmSimpleKindTypeString = JPATypeConvertor.convertToEdmSimpleType(str.getClass(), null);
+ edmSimpleKindTypeByteArr = JPATypeConvertor.convertToEdmSimpleType(byteArr.getClass(), null);
+ edmSimpleKindTypeLong = JPATypeConvertor.convertToEdmSimpleType(longObj.getClass(), null);
+ edmSimpleKindTypeShort = JPATypeConvertor.convertToEdmSimpleType(shortObj.getClass(), null);
+ edmSimpleKindTypeInteger = JPATypeConvertor.convertToEdmSimpleType(integerObj.getClass(), null);
+ edmSimpleKindTypeDouble = JPATypeConvertor.convertToEdmSimpleType(doubleObj.getClass(), null);
+ edmSimpleKindTypeFloat = JPATypeConvertor.convertToEdmSimpleType(floatObj.getClass(), null);
+ edmSimpleKindTypeBigDecimal = JPATypeConvertor.convertToEdmSimpleType(bigDecimalObj.getClass(), null);
+ edmSimpleKindTypeByte = JPATypeConvertor.convertToEdmSimpleType(byteObj.getClass(), null);
+ edmSimpleKindTypeBoolean = JPATypeConvertor.convertToEdmSimpleType(booleanObj.getClass(), null);
+ /*
+ * edmSimpleKindTypeDate = JPATypeConvertor
+ * .convertToEdmSimpleType(dateObj.getClass(),null);
+ */
+ edmSimpleKindTypeUUID = JPATypeConvertor.convertToEdmSimpleType(uUID.getClass(), null);
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertEquals(EdmSimpleTypeKind.String, edmSimpleKindTypeString);
+ assertEquals(EdmSimpleTypeKind.Binary, edmSimpleKindTypeByteArr);
+ assertEquals(EdmSimpleTypeKind.Int64, edmSimpleKindTypeLong);
+ assertEquals(EdmSimpleTypeKind.Int16, edmSimpleKindTypeShort);
+ assertEquals(EdmSimpleTypeKind.Int32, edmSimpleKindTypeInteger);
+ assertEquals(EdmSimpleTypeKind.Double, edmSimpleKindTypeDouble);
+ assertEquals(EdmSimpleTypeKind.Single, edmSimpleKindTypeFloat);
+ assertEquals(EdmSimpleTypeKind.Decimal, edmSimpleKindTypeBigDecimal);
+ assertEquals(EdmSimpleTypeKind.Byte, edmSimpleKindTypeByte);
+ assertEquals(EdmSimpleTypeKind.Boolean, edmSimpleKindTypeBoolean);
+ // assertEquals(EdmSimpleTypeKind.DateTime, edmSimpleKindTypeDate);
+ assertEquals(EdmSimpleTypeKind.Guid, edmSimpleKindTypeUUID);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java
new file mode 100644
index 0000000..c25af73
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/common/ODataJPATestConstants.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.common;
+
+public final class ODataJPATestConstants {
+
+ public static final String EXCEPTION_MSG_PART_1 = "Exception [ ";
+ public static final String EXCEPTION_MSG_PART_2 = " ] not expected";
+ public static final String EMPTY_STRING = "gwt1";
+ public static final String EXCEPTION_EXPECTED = "Exception expected";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java
new file mode 100644
index 0000000..3e680f2
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderNegativeTest.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.edm;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmModel;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ODataJPAEdmProviderNegativeTest {
+
+ private static ODataJPAEdmProvider edmProvider;
+
+ @BeforeClass
+ public static void setup() {
+
+ edmProvider = new ODataJPAEdmProvider();
+ try {
+ Class<? extends ODataJPAEdmProvider> clazz = edmProvider.getClass();
+ Field field = clazz.getDeclaredField("schemas");
+ field.setAccessible(true);
+ List<Schema> schemas = new ArrayList<Schema>();
+ schemas.add(new Schema().setNamespace("salesorderprocessing")); // Empty Schema
+ field.set(edmProvider, schemas);
+ field = clazz.getDeclaredField("oDataJPAContext");
+ field.setAccessible(true);
+ field.set(edmProvider, ODataJPAContextMock.mockODataJPAContext());
+ field = clazz.getDeclaredField("jpaEdmModel");
+ field.setAccessible(true);
+ field.set(edmProvider, new JPAEdmModel(null, null));
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testNullGetEntityContainerInfo() {
+ EntityContainerInfo entityContainer = null;
+ try {
+ entityContainer = edmProvider.getEntityContainerInfo("salesorderprocessingContainer");
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNull(entityContainer);
+ }
+
+ @Test
+ public void testNullGetEntityType() {
+ FullQualifiedName entityTypeName = new FullQualifiedName("salesorderprocessing", "SalesOrderHeader");
+ try {
+ assertNull(edmProvider.getEntityType(entityTypeName));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testNullGetComplexType() {
+ FullQualifiedName complexTypeName = new FullQualifiedName("salesorderprocessing", "Address");
+ try {
+ assertNull(edmProvider.getComplexType(complexTypeName));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetAssociationFullQualifiedName() {
+ Association association = null;
+ try {
+ association =
+ edmProvider.getAssociation(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader_SalesOrderItem"));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNull(association);
+ }
+
+ @Test
+ public void testGetEntitySet() {
+ try {
+ assertNull(edmProvider.getEntitySet("salesorderprocessingContainer", "SalesOrderHeaders"));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetAssociationSet() {
+ try {
+ assertNull(edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName(
+ "salesorderprocessing", "SalesOrderHeader_SalesOrderItem"), "SalesOrderHeaders", "SalesOrderHeader"));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testNullGetFunctionImport() {
+
+ try {
+ assertNull(edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testNullGetFunctionImport2() {
+
+ try {
+ ODataJPAEdmProvider provider = new ODataJPAEdmProvider();
+ try {
+ Class<? extends ODataJPAEdmProvider> clazz = provider.getClass();
+ Field field = clazz.getDeclaredField("schemas");
+ field.setAccessible(true);
+ List<Schema> schemas = new ArrayList<Schema>();
+ Schema schema = new Schema().setNamespace("salesorderprocessing");
+ EntityContainer container = new EntityContainer().setName("salesorderprocessingContainer");
+ List<EntityContainer> containerList = new ArrayList<EntityContainer>();
+ containerList.add(container); // Empty Container
+ schema.setEntityContainers(containerList);
+ schemas.add(schema); // Empty Schema
+ field.set(provider, schemas);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertNull(provider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testGetSchemas() {
+ try {
+ assertNotNull(edmProvider.getSchemas());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java
new file mode 100644
index 0000000..44d0448
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/edm/ODataJPAEdmProviderTest.java
@@ -0,0 +1,386 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.edm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.EdmSchemaMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmModel;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ODataJPAEdmProviderTest {
+
+ private static ODataJPAEdmProvider edmProvider;
+
+ @BeforeClass
+ public static void setup() {
+
+ edmProvider = new ODataJPAEdmProvider();
+ try {
+ Class<? extends ODataJPAEdmProvider> clazz = edmProvider.getClass();
+ Field field = clazz.getDeclaredField("schemas");
+ field.setAccessible(true);
+ List<Schema> schemas = new ArrayList<Schema>();
+ schemas.add(EdmSchemaMock.createMockEdmSchema());
+ field.set(edmProvider, schemas);
+ field = clazz.getDeclaredField("oDataJPAContext");
+ field.setAccessible(true);
+ field.set(edmProvider, ODataJPAContextMock.mockODataJPAContext());
+ field = clazz.getDeclaredField("jpaEdmModel");
+ field.setAccessible(true);
+ field.set(edmProvider, new JPAEdmModel(null, null));
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testConstructor() {
+ try {
+ ODataJPAEdmProvider edmProv = new ODataJPAEdmProvider(ODataJPAContextMock.mockODataJPAContext());
+ edmProv.getClass();
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGetODataJPAContext() {
+ String pUnitName = edmProvider.getODataJPAContext().getPersistenceUnitName();
+ assertEquals("salesorderprocessing", pUnitName);
+ }
+
+ @Test
+ public void testGetEntityContainerInfo() {
+ String entityContainerName = null;
+ EntityContainerInfo entityContainer = null;
+ try {
+ entityContainer = edmProvider.getEntityContainerInfo("salesorderprocessingContainer");
+ entityContainerName = entityContainer.getName();
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertEquals("salesorderprocessingContainer", entityContainerName);
+ assertNotNull(entityContainer);
+ }
+
+ @Test
+ public void testDefaultGetEntityContainerInfo() {
+ String entityContainerName = null;
+ EntityContainerInfo entityContainer = null;
+ try {
+ entityContainer = edmProvider.getEntityContainerInfo(null);
+ entityContainerName = entityContainer.getName();
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertEquals("salesorderprocessingContainer", entityContainerName);
+ assertNotNull(entityContainer);
+ }
+
+ @Test
+ public void testGetEntityType() {
+ FullQualifiedName entityTypeName = new FullQualifiedName("salesorderprocessing", "SalesOrderHeader");
+ String entityName = null;
+ try {
+ entityName = edmProvider.getEntityType(entityTypeName).getName();
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals("SalesOrderHeader", entityName);
+ try {
+ edmProvider.getEntityType(new FullQualifiedName("salesorder", "abc"));
+ } catch (ODataException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testGetComplexType() {
+ FullQualifiedName complexTypeName = new FullQualifiedName("salesorderprocessing", "Address");
+ String nameStr = null;
+ try {
+ nameStr = edmProvider.getComplexType(complexTypeName).getName();
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals("Address", nameStr);
+ }
+
+ @Test
+ public void testGetAssociationFullQualifiedName() {
+ Association association = null;
+ try {
+ association =
+ edmProvider.getAssociation(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader_SalesOrderItem"));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(association);
+ assertEquals("SalesOrderHeader_SalesOrderItem", association.getName());
+ }
+
+ @Test
+ public void testGetEntitySet() {
+ String entitySetName = null;
+ try {
+ entitySetName = edmProvider.getEntitySet("salesorderprocessingContainer", "SalesOrderHeaders").getName();
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals("SalesOrderHeaders", entitySetName);
+ try {
+ assertNull(edmProvider.getEntitySet("salesorderprocessing", "SalesOrderHeaders"));
+ } catch (ODataException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGetAssociationSet() {
+ AssociationSet associationSet = null;
+
+ try {
+ associationSet =
+ edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName("salesorderprocessing",
+ "SalesOrderHeader_SalesOrderItem"), "SalesOrderHeaders", "SalesOrderHeader");
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(associationSet);
+ assertEquals("SalesOrderHeader_SalesOrderItemSet", associationSet.getName());
+ try {
+ associationSet =
+ edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName("salesorderprocessing",
+ "SalesOrderHeader_SalesOrderItem"), "SalesOrderItems", "SalesOrderItem");
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(associationSet);
+ try {
+ associationSet =
+ edmProvider.getAssociationSet("salesorderproceContainer", new FullQualifiedName("salesorderprocessing",
+ "SalesOrderHeader_SalesOrderItem"), "SalesOrderItems", "SalesOrderItem");
+ } catch (ODataException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testGetFunctionImport() {
+ String functionImportName = null;
+ try {
+ functionImportName =
+ edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1").getName();
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals("SalesOrder_FunctionImport1", functionImportName);
+ try {
+ functionImportName =
+ edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1").getName();
+ } catch (ODataException e) {
+ assertTrue(true);
+ }
+ try {
+ assertNotNull(edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
+ } catch (ODataException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testGetSchemas() {
+ try {
+ assertNotNull(edmProvider.getSchemas());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testgetComplexTypeWithBuffer() {
+ HashMap<String, ComplexType> compTypes = new HashMap<String, ComplexType>();
+ ComplexType comp = new ComplexType();
+ comp.setName("Address");
+ compTypes.put("salesorderprocessing" + "." + "Address", comp);
+ ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
+ Class<?> claz = jpaEdmProv.getClass();
+ Field f;
+ try {
+ f = claz.getDeclaredField("complexTypes");
+ f.setAccessible(true);
+ f.set(jpaEdmProv, compTypes);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ try {
+ assertEquals(comp, jpaEdmProv.getComplexType(new FullQualifiedName("salesorderprocessing", "Address")));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ try {
+ jpaEdmProv.getComplexType(new FullQualifiedName("salesorderessing", "abc"));
+ } catch (ODataJPAModelException e) {
+ assertTrue(true);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetEntityContainerInfoWithBuffer() {
+ HashMap<String, EntityContainerInfo> entityContainerInfos = new HashMap<String, EntityContainerInfo>();
+ EntityContainerInfo entityContainer = new EntityContainerInfo();
+ entityContainer.setName("salesorderprocessingContainer");
+ entityContainerInfos.put("salesorderprocessingContainer", entityContainer);
+ ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
+ Class<?> claz = jpaEdmProv.getClass();
+ try {
+ Field f = claz.getDeclaredField("entityContainerInfos");
+ f.setAccessible(true);
+ f.set(jpaEdmProv, entityContainerInfos);
+ assertEquals(entityContainer, jpaEdmProv.getEntityContainerInfo("salesorderprocessingContainer"));
+ jpaEdmProv.getEntityContainerInfo("abc");
+ } catch (ODataJPAModelException e) {
+ assertTrue(true);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetEntityTypeWithBuffer() {
+ HashMap<String, org.apache.olingo.odata2.api.edm.provider.EntityType> entityTypes =
+ new HashMap<String, org.apache.olingo.odata2.api.edm.provider.EntityType>();
+ org.apache.olingo.odata2.api.edm.provider.EntityType entity =
+ new org.apache.olingo.odata2.api.edm.provider.EntityType();
+ entity.setName("SalesOrderHeader");
+ entityTypes.put("salesorderprocessing" + "." + "SalesorderHeader", entity);
+ ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
+ Class<?> claz = jpaEdmProv.getClass();
+ Field f;
+ try {
+ f = claz.getDeclaredField("entityTypes");
+ f.setAccessible(true);
+ f.set(jpaEdmProv, entityTypes);
+ assertEquals(entity, jpaEdmProv.getEntityType(new FullQualifiedName("salesorderprocessing", "SalesorderHeader")));
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ try {
+ jpaEdmProv.getEntityType(new FullQualifiedName("salesoprocessing", "abc"));
+ } catch (ODataJPAModelException e) {
+ assertTrue(true);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetAssociationWithBuffer() {
+ HashMap<String, Association> associations = new HashMap<String, Association>();
+ Association association = new Association();
+ association.setName("SalesOrderHeader_SalesOrderItem");
+ associations.put("salesorderprocessing" + "." + "SalesOrderHeader_SalesOrderItem", association);
+ ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
+ Class<?> claz = jpaEdmProv.getClass();
+ Field f;
+ try {
+ f = claz.getDeclaredField("associations");
+ f.setAccessible(true);
+ f.set(jpaEdmProv, associations);
+ assertEquals(association, jpaEdmProv.getAssociation(new FullQualifiedName("salesorderprocessing",
+ "SalesOrderHeader_SalesOrderItem")));
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ try {
+ jpaEdmProv.getAssociation(new FullQualifiedName("salesorderprocessing", "abc"));
+ } catch (ODataJPAModelException e) {
+ assertTrue(true);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+}
[10/47] git commit: [OLINGO-28] Enhance the Reference Project to
include Function Imports and also enhance the sample data for Sales Order
Line Item
Posted by tb...@apache.org.
[OLINGO-28] Enhance the Reference Project to include Function Imports
and also enhance the sample data for Sales Order Line Item
Signed-off-by: Chandan V A <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/86953027
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/86953027
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/86953027
Branch: refs/heads/ODataServlet
Commit: 869530272adf54a0065b7b2a359893edb57aa99f
Parents: eeee989
Author: Chandan V A <ch...@sap.com>
Authored: Tue Dec 24 11:30:40 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Tue Dec 24 11:30:40 2013 +0530
----------------------------------------------------------------------
.../extension/SalesOrderHeaderProcessor.java | 21 +++++++++++--------
.../resources/SalesOrderItemSQLs.properties | 22 ++++++++++----------
.../jpa-web/src/main/webapp/index.jsp | 9 ++++++++
3 files changed, 32 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/86953027/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
index 72a8fbd..57549ee 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
@@ -113,20 +113,23 @@ public class SalesOrderHeaderProcessor {
}
@EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX))
- public OrderValue getOrderValue(
+ public OrderValue orderValue(
@EdmFunctionImportParameter(name = "SoId", facets = @EdmFacets(nullable = false)) final Long soID) {
Query q = em
.createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ soID + "l");
- @SuppressWarnings("unchecked")
- List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
- .getResultList();
- OrderValue orderValue = new OrderValue();
- if (!soList.isEmpty()) {
-
- orderValue.setAmount(soList.get(0).getNetAmount());
- orderValue.setCurrency(soList.get(0).getCurrencyCode());
+ if (q.getResultList().isEmpty()) {
+ return null;
}
+ SalesOrderHeader so = (SalesOrderHeader) q.getResultList().get(0);
+ double amount = 0;
+ for (SalesOrderItem soi : so.getSalesOrderItem()) {
+ amount = amount
+ + (soi.getAmount() * soi.getDiscount() * soi.getQuantity());
+ }
+ OrderValue orderValue = new OrderValue();
+ orderValue.setAmount(amount);
+ orderValue.setCurrency(so.getCurrencyCode());
return orderValue;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/86953027/odata2-jpa-processor/jpa-web/src/main/resources/SalesOrderItemSQLs.properties
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/resources/SalesOrderItemSQLs.properties b/odata2-jpa-processor/jpa-web/src/main/resources/SalesOrderItemSQLs.properties
index 46c8655..ed93834 100644
--- a/odata2-jpa-processor/jpa-web/src/main/resources/SalesOrderItemSQLs.properties
+++ b/odata2-jpa-processor/jpa-web/src/main/resources/SalesOrderItemSQLs.properties
@@ -17,14 +17,14 @@
# under the License.
#-------------------------------------------------------------------------------
-line_item_query1 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(111, 1, 1.1, 1.11, 3, 11);
-line_item_query2 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(112, 1, 1.1, 1.12, 2, 10);
-line_item_query3 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(113, 1, 1.1, 1.13, 3, 9);
-line_item_query4 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(114, 1, 1.1, 1.14, 4, 8);
-line_item_query5 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(115, 1, 1.1, 1.15, 5, 7);
-line_item_query6 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(116, 1, 1.1, 1.16, 6, 6);
-line_item_query7 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(117, 1, 1.1, 1.17, 7, 5);
-line_item_query8 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(118, 1, 1.1, 1.18, 8, 4);
-line_item_query9 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(119, 1, 1.1, 1.19, 9, 3);
-line_item_query10 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(120, 1, 1.1, 1.20, 10, 2);
-line_item_query11 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(121, 1, 1.1, 1.21, 3, 1);
+line_item_query1 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(111, 1, 10.1, 1.11, 3, 11);
+line_item_query2 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(112, 1, 111.1, 1.12, 2, 10);
+line_item_query3 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(113, 1, 211.1, 1.13, 3, 9);
+line_item_query4 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(114, 1, 221.1, 1.14, 4, 8);
+line_item_query5 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(115, 1, 651.1, 1.15, 5, 7);
+line_item_query6 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(116, 1, 653.21, 1.16, 6, 6);
+line_item_query7 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(117, 1, 57.11, 1.17, 7, 5);
+line_item_query8 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(118, 1, 52.98, 1.18, 8, 4);
+line_item_query9 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(119, 1, 78.99, 1.19, 9, 3);
+line_item_query10 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(120, 1,69.23, 1.20, 10, 2);
+line_item_query11 = insert into T_SALESORDERITEM (Material_Id , quantity , amount , discount , Sales_Order_Id , Sales_Order_Item_Id ) values(121, 1, 356.65, 1.21, 3, 1);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/86953027/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp b/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp
index cc5522e..f897cbb 100644
--- a/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp
+++ b/odata2-jpa-processor/jpa-web/src/main/webapp/index.jsp
@@ -285,6 +285,15 @@ th,td {
target="_blank">SalesOrders(2L)?$expand=SalesOrderLineItemDetails/MaterialDetails,SalesOrderLineItemDetails/MaterialDetails/StoreDetails,NotesDetails</a></li>
</ul>
+ <h3>Function Imports</h3>
+ <ul>
+ <li><a
+ href="SalesOrderProcessing.svc/FindAllSalesOrders?DeliveryStatusCode='01'"
+ target="_blank">SalesOrderProcessing.svc/FindAllSalesOrders?DeliveryStatusCode='01'</a></li>
+ <li><a
+ href="SalesOrderProcessing.svc/orderValue?SoId=2L"
+ target="_blank">SalesOrderProcessing.svc/orderValue?SoId=2L</a></li>
+ </ul>
</td>
<td valign="top"> </td>
<td valign="bottom">
[13/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/ODataEntryMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/ODataEntryMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/ODataEntryMockUtil.java
deleted file mode 100644
index 609017b..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/ODataEntryMockUtil.java
+++ /dev/null
@@ -1,127 +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.odata2.processor.core.jpa.mock.data;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPARelatedTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPATypeEmbeddableMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPATypeEmbeddableMock2;
-import org.easymock.EasyMock;
-
-public class ODataEntryMockUtil {
-
- public static final int VALUE_MINT = 20;
- public static Calendar VALUE_DATE_TIME = null;
- public static final String VALUE_MSTRING = "Mock";
- public static final long VALUE_MLONG = 1234567890L;
- public static final double VALUE_MDOUBLE = 20.12;
- public static final byte VALUE_MBYTE = 0XA;
- public static final byte[] VALUE_MBYTEARRAY = { 0XA, 0XB };
- public static final float VALUE_MFLOAT = 2.00F;
- public static final UUID VALUE_UUID = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d");
- public static final short VALUE_SHORT = 2;
-
- public static ODataEntry mockODataEntry(final String entityName) {
- ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
- EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryProperties(entityName)).anyTimes();
-
- EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(false);
- EasyMock.replay(oDataEntry);
- return oDataEntry;
- }
-
- public static ODataEntry mockODataEntryWithComplexType(final String entityName) {
- ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
- EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithComplexType(entityName))
- .anyTimes();
-
- EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(false);
- EasyMock.replay(oDataEntry);
- return oDataEntry;
- }
-
- public static Map<String, Object> mockODataEntryProperties(final String entityName) {
- Map<String, Object> propertyMap = new HashMap<String, Object>();
-
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- propertyMap.put(JPATypeMock.PROPERTY_NAME_MINT, VALUE_MINT);
-
- VALUE_DATE_TIME = Calendar.getInstance(TimeZone.getDefault());
- VALUE_DATE_TIME.set(2013, 1, 1, 1, 1, 1);
- propertyMap.put(JPATypeMock.PROPERTY_NAME_MDATETIME, VALUE_DATE_TIME);
-
- propertyMap.put(JPATypeMock.PROPERTY_NAME_MSTRING, VALUE_MSTRING);
- } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
- propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MLONG, VALUE_MLONG);
- propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE, VALUE_MDOUBLE);
- propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTE, VALUE_MBYTE);
- propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY, VALUE_MBYTEARRAY);
- } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
- propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT, VALUE_SHORT);
- propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE,
- mockODataEntryProperties(JPATypeEmbeddableMock2.ENTITY_NAME));
- } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
- propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT, VALUE_MFLOAT);
- propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID, VALUE_UUID);
- }
-
- return propertyMap;
- }
-
- public static Map<String, Object> mockODataEntryPropertiesWithComplexType(final String entityName) {
- Map<String, Object> propertyMap = mockODataEntryProperties(entityName);
- propertyMap
- .put(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE, mockODataEntryProperties(JPATypeEmbeddableMock.ENTITY_NAME));
- return propertyMap;
- }
-
- public static Map<String, Object> mockODataEntryPropertiesWithInline(final String entityName) {
- Map<String, Object> propertyMap = mockODataEntryProperties(entityName);
- List<ODataEntry> relatedEntries = new ArrayList<ODataEntry>();
- relatedEntries.add(mockODataEntry(JPARelatedTypeMock.ENTITY_NAME));
- ODataFeed feed = EasyMock.createMock(ODataFeed.class);
- EasyMock.expect(feed.getEntries()).andReturn(relatedEntries);
- EasyMock.replay(feed);
- propertyMap.put(JPATypeMock.NAVIGATION_PROPERTY_X, feed);
-
- return propertyMap;
-
- }
-
- public static ODataEntry mockODataEntryWithInline(final String entityName) {
- ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
- EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithInline(entityName)).anyTimes();
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(true);
- } else {
- EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(false);
- }
- EasyMock.replay(oDataEntry);
- return oDataEntry;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderHeader.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderHeader.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderHeader.java
deleted file mode 100644
index c54411e..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderHeader.java
+++ /dev/null
@@ -1,63 +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.odata2.processor.core.jpa.mock.data;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class SalesOrderHeader {
-
- private int id;
- private String description;
-
- public SalesOrderHeader() {}
-
- public SalesOrderHeader(final int id, final String description) {
- super();
- this.id = id;
- this.description = description;
- }
-
- private List<SalesOrderLineItem> salesOrderLineItems = new ArrayList<SalesOrderLineItem>();
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(final String description) {
- this.description = description;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(final int id) {
- this.id = id;
- }
-
- public List<SalesOrderLineItem> getSalesOrderLineItems() {
- return salesOrderLineItems;
- }
-
- public void setSalesOrderLineItems(final List<SalesOrderLineItem> salesOrderLineItems) {
- this.salesOrderLineItems = salesOrderLineItems;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItem.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItem.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItem.java
deleted file mode 100644
index ba9c09a..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItem.java
+++ /dev/null
@@ -1,38 +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.odata2.processor.core.jpa.mock.data;
-
-public class SalesOrderLineItem {
-
- private int price;
-
- public SalesOrderLineItem(final int price) {
- super();
- this.price = price;
- }
-
- public int getPrice() {
- return price;
- }
-
- public void setPrice(final int price) {
- this.price = price;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItemKey.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItemKey.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItemKey.java
deleted file mode 100644
index d8b7ee3..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/SalesOrderLineItemKey.java
+++ /dev/null
@@ -1,52 +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.odata2.processor.core.jpa.mock.data;
-
-public class SalesOrderLineItemKey {
-
- private int soId;
- private int liId;
-
- public SalesOrderLineItemKey() {
-
- }
-
- public SalesOrderLineItemKey(final int soId, final int liId) {
- super();
- this.soId = soId;
- this.liId = liId;
- }
-
- public int getSoId() {
- return soId;
- }
-
- public void setSoId(final int soId) {
- this.soId = soId;
- }
-
- public int getLiId() {
- return liId;
- }
-
- public void setLiId(final int liId) {
- this.liId = liId;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/EdmSchemaMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/EdmSchemaMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/EdmSchemaMock.java
deleted file mode 100644
index 879c2c2..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/EdmSchemaMock.java
+++ /dev/null
@@ -1,213 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmMappingImpl;
-
-public class EdmSchemaMock {
-
- private static final String ASSOCIATION_ROLE_NAME_ONE = "SalesOrderHeader";
- private static final String ASSOCIATION_NAME = "SalesOrderHeader_SalesOrderItem";
- private static final String ASSOCIATION_SET_NAME = "SalesOrderHeader_SalesOrderItemSet";
- private static final String ASSOCIATION_ROLE_NAME_TWO = "SalesOrderItem";
- private static final String NAMESPACE = "salesorderprocessing";
- private static final String ENTITY_CONTAINER_NAME = "salesorderprocessingContainer";
- private static final String ENTITY_NAME_ONE = "SalesOrderHeader";
- private static final String ENTITY_NAME_TWO = "SalesOrderItem";
- private static final String ENTITY_SET_NAME_ONE = "SalesOrderHeaders";
- private static final String FUNCTION_IMPORT_NAME_ONE = "SalesOrder_FunctionImport1";
- private static final String FUNCTION_IMPORT_NAME_TWO = "SalesOrder_FunctionImport2";
- private static final String ENTITY_SET_NAME_TWO = "SalesOrderItems";
- private static final String COMPLEX_TYPE_NAME_ONE = "Address";
- private static final String COMPLEX_TYPE_NAME_TWO = "SalesOrderItemKey";
-
- public static Schema createMockEdmSchema() {
- Schema schema = new Schema();
- schema.setNamespace(NAMESPACE);
- schema.setComplexTypes(createComplexTypes());
- schema.setEntityContainers(createEntityContainer());
- schema.setEntityTypes(createEntityTypes());
- schema.setAssociations(createAssociations());
- return schema;
- }
-
- private static List<EntityContainer> createEntityContainer() {
- List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
- EntityContainer entityContainer = new EntityContainer();
- entityContainer.setDefaultEntityContainer(true);
- entityContainer.setName(ENTITY_CONTAINER_NAME);
- entityContainer.setEntitySets(createEntitySets());
- entityContainer.setAssociationSets(createAssociationSets());
- entityContainer.setFunctionImports(createFunctionImports());
- entityContainers.add(entityContainer);
- return entityContainers;
- }
-
- private static List<AssociationSet> createAssociationSets() {
- List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- AssociationSet associationSet = new AssociationSet();
- associationSet.setName(ASSOCIATION_SET_NAME);
- associationSet.setAssociation(new FullQualifiedName(NAMESPACE, ASSOCIATION_NAME));
- associationSet
- .setEnd1(new AssociationSetEnd().setEntitySet(ENTITY_SET_NAME_ONE).setRole(ASSOCIATION_ROLE_NAME_ONE));
- associationSet
- .setEnd2(new AssociationSetEnd().setEntitySet(ENTITY_SET_NAME_TWO).setRole(ASSOCIATION_ROLE_NAME_TWO));
- associationSets.add(associationSet);
- return associationSets;
- }
-
- private static List<EntitySet> createEntitySets() {
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- EntitySet entitySet = new EntitySet();
- entitySet.setName(ENTITY_SET_NAME_ONE);
- entitySet.setEntityType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_ONE));
- entitySets.add(entitySet);
- entitySet = new EntitySet();
- entitySet.setName(ENTITY_SET_NAME_TWO);
- entitySet.setEntityType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_TWO));
- entitySets.add(entitySet);
- return entitySets;
- }
-
- private static List<FunctionImport> createFunctionImports() {
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- FunctionImport functionImport = new FunctionImport();
- functionImport.setName(FUNCTION_IMPORT_NAME_ONE);
- functionImports.add(functionImport);
- functionImport = new FunctionImport();
- functionImport.setName(FUNCTION_IMPORT_NAME_TWO);
- functionImports.add(functionImport);
- return functionImports;
- }
-
- private static List<Association> createAssociations() {
- List<Association> associations = new ArrayList<Association>();
- Association association = new Association();
- association.setName(ASSOCIATION_NAME);
- association.setEnd1(new AssociationEnd().setMultiplicity(EdmMultiplicity.ONE).setRole(ASSOCIATION_ROLE_NAME_ONE)
- .setType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_ONE)));
- association.setEnd2(new AssociationEnd().setMultiplicity(EdmMultiplicity.MANY).setRole(ASSOCIATION_ROLE_NAME_TWO)
- .setType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_TWO)));
- associations.add(association);
- return associations;
- }
-
- private static List<EntityType> createEntityTypes() {
- List<EntityType> entityTypes = new ArrayList<EntityType>();
- EntityType entityType = new EntityType();
- entityType.setName(ENTITY_NAME_ONE);
- String[] keyNamesOne = { "SoId" };
- entityType.setKey(createKey(keyNamesOne));
- entityTypes.add(entityType);
-
- entityType = new EntityType();
- entityType.setName(ENTITY_NAME_TWO);
- String[] keyNamesTwo = { "SoId", "LiId" };
- entityType.setKey(createKey(keyNamesTwo));
- entityTypes.add(entityType);
- return entityTypes;
-
- }
-
- private static Key createKey(final String[] keyNames) {
- Key key = new Key();
- List<PropertyRef> keys = new ArrayList<PropertyRef>();
- for (String keyName : keyNames) {
- keys.add(new PropertyRef().setName(keyName));
- }
- key.setKeys(keys);
- return null;
- }
-
- private static List<ComplexType> createComplexTypes() {
- List<ComplexType> complexTypes = new ArrayList<ComplexType>();
- ComplexType complexTypeOne = new ComplexType();
- complexTypeOne.setName(COMPLEX_TYPE_NAME_ONE);
- complexTypeOne.setProperties(createComplexTypePropertiesOne());
- complexTypes.add(complexTypeOne);
- ComplexType complexTypeTwo = new ComplexType();
- complexTypeTwo.setName(COMPLEX_TYPE_NAME_TWO);
- complexTypeTwo.setProperties(createComplexTypePropertiesTwo());
- complexTypes.add(complexTypeTwo);
- return complexTypes;
- }
-
- private static List<Property> createComplexTypePropertiesTwo() {
- List<Property> properties = new ArrayList<Property>();
- SimpleProperty property = new SimpleProperty();
- property.setName("SoId");
- property.setType(EdmSimpleTypeKind.Int64);
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- mapping.setJPAColumnName("Sales_Order_Id");
- ((Mapping) mapping).setInternalName("SalesOrderItemKey.SoId");
- property.setMapping((Mapping) mapping);
- properties.add(property);
- property = new SimpleProperty();
- property.setName("LiId");
- property.setType(EdmSimpleTypeKind.Int64);
- mapping = new JPAEdmMappingImpl();
- mapping.setJPAColumnName("Sales_Order_Item_Id");
- property.setMapping((Mapping) mapping);
- properties.add(property);
- return properties;
-
- }
-
- private static List<Property> createComplexTypePropertiesOne() {
- List<Property> properties = new ArrayList<Property>();
- SimpleProperty property = new SimpleProperty();
- property.setName("StreetName");
- property.setType(EdmSimpleTypeKind.String);
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- mapping.setJPAColumnName("STREET_NAME");
- property.setMapping((Mapping) mapping);
- properties.add(property);
- property = new SimpleProperty();
- property.setName("City");
- property.setType(EdmSimpleTypeKind.String);
- mapping = new JPAEdmMappingImpl();
- mapping.setJPAColumnName("CITY");
- property.setMapping((Mapping) mapping);
- properties.add(property);
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAAttributeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAAttributeMock.java
deleted file mode 100644
index 9d6bad1..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAAttributeMock.java
+++ /dev/null
@@ -1,63 +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.odata2.processor.core.jpa.mock.model;
-
-import java.lang.reflect.Member;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.ManagedType;
-
-public abstract class JPAAttributeMock<X, Y> implements Attribute<X, Y> {
-
- @Override
- public ManagedType<X> getDeclaringType() {
- return null;
- }
-
- @Override
- public Member getJavaMember() {
- return null;
- }
-
- @Override
- public Class<Y> getJavaType() {
- return null;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
- return null;
- }
-
- @Override
- public boolean isAssociation() {
- return false;
- }
-
- @Override
- public boolean isCollection() {
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPACustomProcessorMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPACustomProcessorMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPACustomProcessorMock.java
deleted file mode 100644
index 54a6871..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPACustomProcessorMock.java
+++ /dev/null
@@ -1,74 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter;
-
-public class JPACustomProcessorMock {
-
- public static final String className = "JPACustomProcessorMock";
- public static final String edmName = "JPACustomProcessor";
-
- @EdmFunctionImport(name = "Method1", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
- isCollection = true))
- public List<JPACustomProcessorMock> method1(@EdmFunctionImportParameter(name = "Param1", facets = @EdmFacets(
- nullable = true,
- maxLength = 2)) final String param1, final int param2, @EdmFunctionImportParameter(name = "Param3",
- facets = @EdmFacets(precision = 10, scale = 2)) final double param3) {
- return new ArrayList<JPACustomProcessorMock>();
- }
-
- @EdmFunctionImport(name = "Method2", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
- isCollection = true))
- public List<JPACustomProcessorMock> method2(
- @EdmFunctionImportParameter(facets = @EdmFacets(maxLength = 2), name = "Param2") final String param2) {
- return new ArrayList<JPACustomProcessorMock>();
- }
-
- @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
- public int method3(@EdmFunctionImportParameter(name = "Param3") final String param3) {
- return 0;
- }
-
- @EdmFunctionImport(returnType = @ReturnType(type = Type.ENTITY,
- isCollection = false), entitySet = "MockSet")
- public JPACustomProcessorMock method7() {
- return null;
- }
-
- @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX,
- isCollection = false))
- public JPACustomProcessorMock method9() {
- return null;
- }
-
- @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX,
- isCollection = true))
- public List<JPACustomProcessorMock> method10() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEdmMockData.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEdmMockData.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEdmMockData.java
deleted file mode 100644
index 9b25115..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEdmMockData.java
+++ /dev/null
@@ -1,72 +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.odata2.processor.core.jpa.mock.model;
-
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.EntityType.EntityTypeA;
-
-public interface JPAEdmMockData {
- /*
- * Edm Complex Type Mock Data
- */
- public interface ComplexType {
-
- public interface ComplexTypeA {
- public static final String name = "ComplexTypeA";
- public static final Class<ComplexTypeA> clazz = ComplexTypeA.class;
-
- public interface Property {
- public static final String PROPERTY_A = "A";
- public static final String PROPERTY_B = "B";
- public static final String PROPERTY_C = "C";
- }
-
- }
-
- public interface ComplexTypeB {
- public static final String name = "ComplexTypeB";
-
- public interface Property {
- public static final String PROPERTY_D = "D";
- public static final String PROPERTY_E = "E";
- }
-
- }
- }
-
- public interface EntityType {
- public interface EntityTypeA {
- public static final String name = "SalesOrderHeader";
- public static final Class<EntityTypeA> entityClazz = EntityTypeA.class;
-
- public interface Property {
- public static final String PROPERTY_A = SimpleType.SimpleTypeA.NAME;
-
- }
-
- }
- }
-
- public interface SimpleType {
- public interface SimpleTypeA {
- public static final String NAME = "SOID";
- public static final Class<String> clazz = String.class;
- public static final Class<EntityTypeA> declaringClazz = EntityType.EntityTypeA.class;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableMock.java
deleted file mode 100644
index 397f971..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableMock.java
+++ /dev/null
@@ -1,184 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.CollectionAttribute;
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.ListAttribute;
-import javax.persistence.metamodel.MapAttribute;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.SetAttribute;
-import javax.persistence.metamodel.SingularAttribute;
-
-public class JPAEmbeddableMock<X> implements EmbeddableType<X> {
-
- @Override
- public Attribute<? super X, ?> getAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<? super X, ?>> getAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<X, ?>> getDeclaredAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public ListAttribute<X, ?> getDeclaredList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
- return null;
- }
-
- @Override
- public ListAttribute<? super X, ?> getList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<? super X, ?> getSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
- return null;
- }
-
- @Override
- public Class<X> getJavaType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableTypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableTypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableTypeMock.java
deleted file mode 100644
index 7f6adc8..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEmbeddableTypeMock.java
+++ /dev/null
@@ -1,184 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.CollectionAttribute;
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.ListAttribute;
-import javax.persistence.metamodel.MapAttribute;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.SetAttribute;
-import javax.persistence.metamodel.SingularAttribute;
-
-public class JPAEmbeddableTypeMock<X> implements EmbeddableType<X> {
-
- @Override
- public Attribute<? super X, ?> getAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<? super X, ?>> getAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<X, ?>> getDeclaredAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public ListAttribute<X, ?> getDeclaredList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
- return null;
- }
-
- @Override
- public ListAttribute<? super X, ?> getList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<? super X, ?> getSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
- return null;
- }
-
- @Override
- public Class<X> getJavaType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEntityTypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEntityTypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEntityTypeMock.java
deleted file mode 100644
index 602d430..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAEntityTypeMock.java
+++ /dev/null
@@ -1,246 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.CollectionAttribute;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.IdentifiableType;
-import javax.persistence.metamodel.ListAttribute;
-import javax.persistence.metamodel.MapAttribute;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.SetAttribute;
-import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.Type;
-
-public abstract class JPAEntityTypeMock<X> implements EntityType<X> {
-
- @Override
- public <Y> SingularAttribute<X, Y> getDeclaredId(final Class<Y> arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<X, Y> getDeclaredVersion(final Class<Y> arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<? super X, Y> getId(final Class<Y> arg0) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() {
- return null;
- }
-
- @Override
- public Type<?> getIdType() {
- return null;
- }
-
- @Override
- public IdentifiableType<? super X> getSupertype() {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<? super X, Y> getVersion(final Class<Y> arg0) {
- return null;
- }
-
- @Override
- public boolean hasSingleIdAttribute() {
- return false;
- }
-
- @Override
- public boolean hasVersionAttribute() {
- return false;
- }
-
- @Override
- public Attribute<? super X, ?> getAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<? super X, ?>> getAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<X, ?>> getDeclaredAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public ListAttribute<X, ?> getDeclaredList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
- return null;
- }
-
- @Override
- public ListAttribute<? super X, ?> getList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<? super X, ?> getSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
- return null;
- }
-
- @Override
- public Class<X> getJavaType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
- return null;
- }
-
- @Override
- public Class<X> getBindableJavaType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Bindable.BindableType getBindableType() {
- return null;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAJavaMemberMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAJavaMemberMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAJavaMemberMock.java
deleted file mode 100644
index 740a2ec..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAJavaMemberMock.java
+++ /dev/null
@@ -1,74 +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.odata2.processor.core.jpa.mock.model;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Member;
-
-import javax.persistence.JoinColumns;
-
-public class JPAJavaMemberMock implements Member, AnnotatedElement, Annotation {
-
- @Override
- public Class<?> getDeclaringClass() {
- return null;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public int getModifiers() {
- return 0;
- }
-
- @Override
- public boolean isSynthetic() {
- return false;
- }
-
- @Override
- public boolean isAnnotationPresent(final Class<? extends Annotation> annotationClass) {
- return false;
- }
-
- @Override
- public Annotation[] getAnnotations() {
- return null;
- }
-
- @Override
- public Annotation[] getDeclaredAnnotations() {
- return null;
- }
-
- @Override
- public Class<? extends Annotation> annotationType() {
- return JoinColumns.class;
- }
-
- @Override
- public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAManagedTypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAManagedTypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAManagedTypeMock.java
deleted file mode 100644
index 915c562..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAManagedTypeMock.java
+++ /dev/null
@@ -1,184 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.CollectionAttribute;
-import javax.persistence.metamodel.ListAttribute;
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.MapAttribute;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.SetAttribute;
-import javax.persistence.metamodel.SingularAttribute;
-
-public class JPAManagedTypeMock<X> implements ManagedType<X> {
-
- @Override
- public Class<X> getJavaType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
- return null;
- }
-
- @Override
- public Attribute<? super X, ?> getAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<? super X, ?>> getAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public Set<Attribute<X, ?>> getDeclaredAttributes() {
- return null;
- }
-
- @Override
- public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
- return null;
- }
-
- @Override
- public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public ListAttribute<X, ?> getDeclaredList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
- return null;
- }
-
- @Override
- public ListAttribute<? super X, ?> getList(final String arg0) {
- return null;
- }
-
- @Override
- public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
- return null;
- }
-
- @Override
- public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
- return null;
- }
-
- @Override
- public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
- return null;
- }
-
- @Override
- public SetAttribute<? super X, ?> getSet(final String arg0) {
- return null;
- }
-
- @Override
- public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
- return null;
- }
-
- @Override
- public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
- return null;
- }
-
- @Override
- public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
- return null;
- }
-
- @Override
- public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAMetaModelMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAMetaModelMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAMetaModelMock.java
deleted file mode 100644
index 8e528b2..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAMetaModelMock.java
+++ /dev/null
@@ -1,60 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.Set;
-
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.Metamodel;
-
-public class JPAMetaModelMock implements Metamodel {
-
- @Override
- public <X> EmbeddableType<X> embeddable(final Class<X> arg0) {
- return null;
- }
-
- @Override
- public <X> EntityType<X> entity(final Class<X> arg0) {
- return null;
- }
-
- @Override
- public Set<EmbeddableType<?>> getEmbeddables() {
- return null;
- }
-
- @Override
- public Set<EntityType<?>> getEntities() {
- return null;
- }
-
- @Override
- public Set<ManagedType<?>> getManagedTypes() {
- return null;
- }
-
- @Override
- public <X> ManagedType<X> managedType(final Class<X> arg0) {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAPluralAttributeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAPluralAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAPluralAttributeMock.java
deleted file mode 100644
index a4aa2b5..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPAPluralAttributeMock.java
+++ /dev/null
@@ -1,95 +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.odata2.processor.core.jpa.mock.model;
-
-import java.lang.reflect.Member;
-import java.util.ArrayList;
-
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.Type;
-
-public class JPAPluralAttributeMock implements PluralAttribute<Object, ArrayList<String>, String> {
-
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ManagedType<Object> getDeclaringType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Class<ArrayList<String>> getJavaType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Member getJavaMember() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean isAssociation() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isCollection() {
- return false;
- }
-
- @Override
- public javax.persistence.metamodel.Bindable.BindableType getBindableType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Class<String> getBindableJavaType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.PluralAttribute.CollectionType getCollectionType() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Type<String> getElementType() {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPASingularAttributeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPASingularAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPASingularAttributeMock.java
deleted file mode 100644
index 41124fe..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/JPASingularAttributeMock.java
+++ /dev/null
@@ -1,94 +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.odata2.processor.core.jpa.mock.model;
-
-import java.lang.reflect.Member;
-
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.Type;
-
-public class JPASingularAttributeMock<X, T> implements SingularAttribute<X, T> {
-
- @Override
- public ManagedType<X> getDeclaringType() {
- return null;
- }
-
- @Override
- public Member getJavaMember() {
- return null;
- }
-
- @Override
- public Class<T> getJavaType() {
- return null;
- }
-
- @Override
- public String getName() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
- return null;
- }
-
- @Override
- public boolean isAssociation() {
- return false;
- }
-
- @Override
- public boolean isCollection() {
- return false;
- }
-
- @Override
- public Class<T> getBindableJavaType() {
- return null;
- }
-
- @Override
- public javax.persistence.metamodel.Bindable.BindableType getBindableType() {
- return null;
- }
-
- @Override
- public Type<T> getType() {
- return null;
- }
-
- @Override
- public boolean isId() {
- return false;
- }
-
- @Override
- public boolean isOptional() {
- return false;
- }
-
- @Override
- public boolean isVersion() {
- return false;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorMock.java
deleted file mode 100644
index dbc6d7a..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorMock.java
+++ /dev/null
@@ -1,77 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.Facets;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
-
-@Deprecated
-public class _JPACustomProcessorMock {
-
- public static final String className = "_JPACustomProcessorMock";
- public static final String edmName = "JPACustomProcessor";
-
- @FunctionImport(name = "Method1", entitySet = "MockSet", returnType = ReturnType.ENTITY_TYPE,
- multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorMock> method1(@Parameter(name = "Param1", facets = @Facets(nullable = true,
- maxLength = 2), mode = Mode.IN) final String param1, final int param2, @Parameter(name = "Param3",
- facets = @Facets(precision = 10, scale = 2), mode = Mode.IN) final double param3) {
- return new ArrayList<_JPACustomProcessorMock>();
- }
-
- @FunctionImport(name = "Method2", entitySet = "MockSet", returnType = ReturnType.ENTITY_TYPE,
- multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorMock> method2(
- @Parameter(facets = @Facets(maxLength = 2), name = "Param2") final String param2) {
- return new ArrayList<_JPACustomProcessorMock>();
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR)
- public int method3(@Parameter(name = "Param3") final String param3) {
- return 0;
- }
-
- @FunctionImport(returnType = ReturnType.NONE)
- public void method4() {
- return;
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.ONE)
- public _JPACustomProcessorMock method7() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
- public _JPACustomProcessorMock method9() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorMock> method10() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorNegativeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorNegativeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorNegativeMock.java
deleted file mode 100644
index 6799949..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/model/_JPACustomProcessorNegativeMock.java
+++ /dev/null
@@ -1,70 +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.odata2.processor.core.jpa.mock.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-
-@Deprecated
-public class _JPACustomProcessorNegativeMock {
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, multiplicity = Multiplicity.MANY)
- public List<_JPACustomProcessorNegativeMock> method5() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.MANY)
- public void method6() {
- return;
- }
-
- @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.MANY)
- public _JPACustomProcessorNegativeMock method8() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
- public _JPACustomProcessorNegativeMock method11() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
- public JPACustomProcessorMock method12() {
- return null;
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
- public int method13(@Parameter(name = "") final int y) {
- return 0;
- }
-
- @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
- public void method16(@Parameter(name = "") final int y) {
- return;
- }
-
- @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
- public void method17(@Parameter(name = "") final int y) {
- return;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEndTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEndTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEndTest.java
deleted file mode 100644
index 05db5ab..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationEndTest.java
+++ /dev/null
@@ -1,177 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.SimpleType;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.SimpleType.SimpleTypeA;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmAssociationEndTest extends JPAEdmTestModelView {
-
- private final static int VARIANT1 = 1;
- private final static int VARIANT2 = 2;
- private final static int VARIANT3 = 3;
-
- private static int variant;
-
- private static final String PUNIT_NAME = "salesorderprocessing";
- private static JPAEdmAssociationEnd objJPAEdmAssociationEnd = null;
- private static JPAEdmAssociationEndTest objJPAEdmAssociationEndTest = null;
-
- @BeforeClass
- public static void setup() {
- objJPAEdmAssociationEndTest = new JPAEdmAssociationEndTest();
- objJPAEdmAssociationEnd = new JPAEdmAssociationEnd(objJPAEdmAssociationEndTest, objJPAEdmAssociationEndTest);
- try {
- objJPAEdmAssociationEnd.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetBuilder() {
- JPAEdmBuilder builder = objJPAEdmAssociationEnd.getBuilder();
- assertNotNull(builder);
-
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmAssociationEnd.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmAssociationEnd.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetAssociationEnd1() {
- AssociationEnd associationEnd = objJPAEdmAssociationEnd.getEdmAssociationEnd1();
- assertEquals(associationEnd.getType().getName(), "SOID");
- }
-
- @Test
- public void testGetAssociationEnd2() {
- AssociationEnd associationEnd = objJPAEdmAssociationEnd.getEdmAssociationEnd2();
- assertEquals(associationEnd.getType().getName(), "String");
- }
-
- @Test
- public void testCompare() {
- assertTrue(objJPAEdmAssociationEnd.compare(getAssociationEnd("SOID", 1), getAssociationEnd("String", 1)));
- assertFalse(objJPAEdmAssociationEnd.compare(getAssociationEnd("String", 2), getAssociationEnd("SOID", 1)));
- }
-
- @Test
- public void testBuildAssociationEnd() {
- assertEquals("SOID", objJPAEdmAssociationEnd.getEdmAssociationEnd1().getType().getName());
- assertEquals(new FullQualifiedName("salesorderprocessing", "SOID"), objJPAEdmAssociationEnd.getEdmAssociationEnd1()
- .getType());
- assertTrue(objJPAEdmAssociationEnd.isConsistent());
-
- }
-
- private AssociationEnd getAssociationEnd(final String typeName, final int variant) {
- AssociationEnd associationEnd = new AssociationEnd();
- associationEnd.setType(getFullQualifiedName(typeName));
- if (variant == VARIANT1) {
- associationEnd.setMultiplicity(EdmMultiplicity.MANY);
- } else if (variant == VARIANT2) {
- associationEnd.setMultiplicity(EdmMultiplicity.ONE);
- } else if (variant == VARIANT3) {
- associationEnd.setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
- } else {
- associationEnd.setMultiplicity(EdmMultiplicity.MANY);//
- }
- return associationEnd;
- }
-
- private FullQualifiedName getFullQualifiedName(final String typeName) {
- FullQualifiedName fullQualifiedName = new FullQualifiedName(PUNIT_NAME, typeName);
- return fullQualifiedName;
- }
-
- private Attribute<?, ?> getJPAAttributeLocal() {
- AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
- return attr;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return getJPAAttributeLocal();
- }
-
- @Override
- public String getpUnitName() {
- return PUNIT_NAME;
- }
-
- @Override
- public EntityType getEdmEntityType() {
- EntityType entityType = new EntityType();
- entityType.setName(SimpleTypeA.NAME);
- return entityType;
- }
-
- // The inner class which gives us an replica of the jpa attribute
- @SuppressWarnings("hiding")
- public class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) SimpleType.SimpleTypeA.clazz;
- }
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- if (variant == VARIANT1) {
- return PersistentAttributeType.ONE_TO_MANY;
- } else if (variant == VARIANT2) {
- return PersistentAttributeType.ONE_TO_ONE;
- } else if (variant == VARIANT3) {
- return PersistentAttributeType.MANY_TO_ONE;
- } else {
- return PersistentAttributeType.MANY_TO_MANY;
- }
-
- }
- }
-
-}
[31/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
new file mode 100644
index 0000000..d35eae0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImport.java
@@ -0,0 +1,349 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmFunctionImportView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPATypeConvertor;
+
+public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView {
+
+ private List<FunctionImport> consistentFunctionImportList = new ArrayList<FunctionImport>();
+ private JPAEdmBuilder builder = null;
+ private JPAEdmSchemaView schemaView;
+
+ public JPAEdmFunctionImport(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmFunctionImportBuilder();
+ }
+ return builder;
+ }
+
+ @Override
+ public List<FunctionImport> getConsistentFunctionImportList() {
+ return consistentFunctionImportList;
+ }
+
+ protected class JPAEdmFunctionImportBuilder implements JPAEdmBuilder {
+
+ private JPAEdmEntityTypeView jpaEdmEntityTypeView = null;
+ private JPAEdmComplexTypeView jpaEdmComplexTypeView = null;
+ @SuppressWarnings("deprecation")
+ private _JPAEdmFunctionImportBuilder builderDeprecated = new _JPAEdmFunctionImportBuilder();
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ HashMap<Class<?>, String[]> customOperations = schemaView.getRegisteredOperations();
+
+ jpaEdmEntityTypeView =
+ schemaView.getJPAEdmEntityContainerView().getJPAEdmEntitySetView().getJPAEdmEntityTypeView();
+ jpaEdmComplexTypeView = schemaView.getJPAEdmComplexTypeView();
+
+ if (customOperations != null) {
+ // Initialize deprecated Builder
+ builderDeprecated.setJPAEdmComplexTypeView(jpaEdmComplexTypeView);
+ builderDeprecated.setJPAEdmEntityTypeView(jpaEdmEntityTypeView);
+ builderDeprecated.setSchemaView(schemaView);
+
+ for (Class<?> clazz : customOperations.keySet()) {
+
+ String[] operationNames = customOperations.get(clazz);
+ Method[] methods = clazz.getMethods();
+ Method method = null;
+
+ int length = 0;
+ if (operationNames != null) {
+ length = operationNames.length;
+ } else {
+ length = methods.length;
+ }
+
+ boolean found = false;
+ for (int i = 0; i < length; i++) {
+
+ try {
+ if (operationNames != null) {
+ for (Method method2 : methods) {
+ if (method2.getName().equals(operationNames[i])) {
+ found = true;
+ method = method2;
+ break;
+ }
+ }
+ if (found == true) {
+ found = false;
+ } else {
+ continue;
+ }
+ } else {
+ method = methods[i];
+ }
+
+ FunctionImport functionImport = buildFunctionImport(method);
+ if (functionImport != null) {
+ consistentFunctionImportList.add(functionImport);
+ }
+
+ } catch (SecurityException e) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL, e);
+ }
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private FunctionImport buildFunctionImport(final Method method) throws ODataJPAModelException {
+
+ EdmFunctionImport edmAnnotationFunctionImport = method.getAnnotation(EdmFunctionImport.class);
+ if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
+ return buildEdmFunctionImport(method, edmAnnotationFunctionImport);
+ }
+
+ org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation =
+ method.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.FunctionImport.class);
+
+ if (annotation != null) {
+ FunctionImport functionImport = builderDeprecated.buildFunctionImport(method, annotation);
+
+ return functionImport;
+ }
+ return null;
+ }
+
+ private FunctionImport buildEdmFunctionImport(final Method method,
+ final EdmFunctionImport edmAnnotationFunctionImport)
+ throws ODataJPAModelException {
+ if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
+ FunctionImport functionImport = new FunctionImport();
+
+ if (edmAnnotationFunctionImport.name().equals("")) {
+ functionImport.setName(method.getName());
+ } else {
+ functionImport.setName(edmAnnotationFunctionImport.name());
+ }
+
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ ((Mapping) mapping).setInternalName(method.getName());
+ mapping.setJPAType(method.getDeclaringClass());
+ functionImport.setMapping((Mapping) mapping);
+
+ functionImport.setHttpMethod(edmAnnotationFunctionImport.httpMethod().name().toString());
+
+ buildEdmReturnType(functionImport, method, edmAnnotationFunctionImport);
+ buildEdmParameter(functionImport, method);
+
+ return functionImport;
+ }
+ return null;
+ }
+
+ private void buildEdmParameter(final FunctionImport functionImport, final Method method)
+ throws ODataJPAModelException {
+ Annotation[][] annotations = method.getParameterAnnotations();
+ Class<?>[] parameterTypes = method.getParameterTypes();
+ List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
+ JPAEdmMapping mapping = null;
+ int j = 0;
+ for (Annotation[] annotationArr : annotations) {
+ Class<?> parameterType = parameterTypes[j++];
+
+ for (Annotation element : annotationArr) {
+ if (element instanceof EdmFunctionImportParameter) {
+ EdmFunctionImportParameter annotation = (EdmFunctionImportParameter) element;
+ FunctionImportParameter functionImportParameter = new FunctionImportParameter();
+ if (annotation.name().equals("")) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method
+ .getDeclaringClass().getName(), method.getName()), null);
+ } else {
+ functionImportParameter.setName(annotation.name());
+ }
+
+ functionImportParameter.setType(JPATypeConvertor.convertToEdmSimpleType(parameterType, null));
+
+ Facets facets = new Facets();
+ if (annotation.facets().maxLength() > 0) {
+ facets.setMaxLength(annotation.facets().maxLength());
+ }
+ if (annotation.facets().nullable() == false) {
+ facets.setNullable(false);
+ } else {
+ facets.setNullable(true);
+ }
+
+ if (annotation.facets().precision() > 0) {
+ facets.setPrecision(annotation.facets().precision());
+ }
+ if (annotation.facets().scale() >= 0) {
+ facets.setScale(annotation.facets().scale());
+ }
+
+ functionImportParameter.setFacets(facets);
+ mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(parameterType);
+ functionImportParameter.setMapping((Mapping) mapping);
+ funcImpList.add(functionImportParameter);
+ }
+ }
+ }
+ if (!funcImpList.isEmpty()) {
+ functionImport.setParameters(funcImpList);
+ }
+ }
+
+ private void buildEdmReturnType(final FunctionImport functionImport, final Method method,
+ final EdmFunctionImport edmAnnotationFunctionImport) throws ODataJPAModelException {
+ ReturnType returnType = edmAnnotationFunctionImport.returnType();
+
+ if (returnType != null) {
+ org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType =
+ new org.apache.olingo.odata2.api.edm.provider.ReturnType();
+
+ if (returnType.isCollection()) {
+ functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
+ } else {
+ functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
+ }
+
+ if (returnType.type() == ReturnType.Type.ENTITY) {
+ String entitySet = edmAnnotationFunctionImport.entitySet();
+ if (entitySet.equals("")) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
+ }
+ functionImport.setEntitySet(entitySet);
+ }
+
+ Class<?> methodReturnType = method.getReturnType();
+ if (methodReturnType == null || methodReturnType.getName().equals("void")) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method
+ .getDeclaringClass(), method.getName()), null);
+ }
+ switch (returnType.type()) {
+ case ENTITY:
+ EntityType edmEntityType = null;
+ if (returnType.isCollection() == false) {
+ edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName());
+ } else {
+ edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method));
+ }
+
+ if (edmEntityType == null) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
+ .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+ }
+ functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName()));
+ break;
+ case SIMPLE:
+ EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConvertor.convertToEdmSimpleType(methodReturnType, null);
+ functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName());
+
+ break;
+ case COMPLEX:
+ String embeddableTypeName = null;
+ ComplexType complexType = null;
+ boolean exists = false;
+
+ if (returnType.isCollection() == false) {
+ embeddableTypeName = methodReturnType.getName();
+ } else {
+ embeddableTypeName = getReturnTypeName(method);
+ }
+
+ complexType = jpaEdmComplexTypeView.searchEdmComplexType(embeddableTypeName);
+
+ if (complexType == null) {// This could occure of non JPA Embeddable Types : Extension Scenario
+ List<ComplexType> complexTypeList = schemaView.getEdmSchema().getComplexTypes();
+ String[] complexTypeNameParts = embeddableTypeName.split("\\.");
+ String complexTypeName = complexTypeNameParts[complexTypeNameParts.length - 1];
+ for (ComplexType complexType1 : complexTypeList) {
+ if (complexType1.getName().equals(complexTypeName)) {
+ complexType = complexType1;
+ exists = true;
+ break;
+ }
+ }
+ if (exists == false) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
+ .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+ }
+ }
+ functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
+ break;
+ default:
+ break;
+ }
+ functionImport.setReturnType(functionReturnType);
+ }
+ }
+
+ private String getReturnTypeName(final Method method) {
+ try {
+ ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
+ Type t = pt.getActualTypeArguments()[0];
+ return ((Class<?>) t).getName();
+ } catch (ClassCastException e) {
+ return method.getReturnType().getName();
+ }
+ }
+
+ private String getReturnTypeSimpleName(final Method method) {
+ try {
+ ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
+ Type t = pt.getActualTypeArguments()[0];
+ return ((Class<?>) t).getSimpleName();
+ } catch (ClassCastException e) {
+ return method.getReturnType().getSimpleName();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKey.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKey.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKey.java
new file mode 100644
index 0000000..69b6d07
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKey.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+
+public class JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView {
+
+ private JPAEdmPropertyView propertyView;
+ private JPAEdmComplexTypeView complexTypeView = null;
+ private boolean isBuildModeComplexType = false;
+ private Key key;
+
+ public JPAEdmKey(final JPAEdmProperty view) {
+ super(view);
+ propertyView = view;
+ }
+
+ public JPAEdmKey(final JPAEdmComplexTypeView complexTypeView, final JPAEdmPropertyView propertyView) {
+ super(complexTypeView);
+ this.propertyView = propertyView;
+ this.complexTypeView = complexTypeView;
+ isBuildModeComplexType = true;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmKeyBuider();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public Key getEdmKey() {
+ return key;
+ }
+
+ private class JPAEdmKeyBuider implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException {
+
+ List<PropertyRef> propertyRefList = null;
+ if (key == null) {
+ key = new Key();
+ }
+
+ if (key.getKeys() == null) {
+ propertyRefList = new ArrayList<PropertyRef>();
+ key.setKeys(propertyRefList);
+ } else {
+ propertyRefList = key.getKeys();
+ }
+
+ if (isBuildModeComplexType) {
+ ComplexType complexType =
+ complexTypeView.searchEdmComplexType(propertyView.getJPAAttribute().getJavaType().getName());
+ normalizeComplexKey(complexType, propertyRefList);
+ } else {
+ PropertyRef propertyRef = new PropertyRef();
+ propertyRef.setName(propertyView.getEdmSimpleProperty().getName());
+ Facets facets = (Facets) propertyView.getEdmSimpleProperty().getFacets();
+ if (facets == null) {
+ propertyView.getEdmSimpleProperty().setFacets(new Facets().setNullable(false));
+ } else {
+ facets.setNullable(false);
+ }
+ propertyRefList.add(propertyRef);
+ }
+
+ }
+
+ // TODO think how to stop the recursion if A includes B and B includes A!!!!!!
+ public void normalizeComplexKey(final ComplexType complexType, final List<PropertyRef> propertyRefList) {
+ for (Property property : complexType.getProperties()) {
+ try {
+
+ SimpleProperty simpleProperty = (SimpleProperty) property;
+ Facets facets = (Facets) simpleProperty.getFacets();
+ if (facets == null) {
+ simpleProperty.setFacets(new Facets().setNullable(false));
+ } else {
+ facets.setNullable(false);
+ }
+ PropertyRef propertyRef = new PropertyRef();
+ propertyRef.setName(simpleProperty.getName());
+ propertyRefList.add(propertyRef);
+
+ } catch (ClassCastException e) {
+ ComplexProperty complexProperty = (ComplexProperty) property;
+ normalizeComplexKey(complexTypeView.searchEdmComplexType(complexProperty.getType()), propertyRefList);
+ }
+
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
new file mode 100644
index 0000000..f930d20
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmMappingImpl.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+
+public class JPAEdmMappingImpl extends Mapping implements JPAEdmMapping {
+
+ private String columnName = null;
+ private Class<?> type = null;
+
+ @Override
+ public void setJPAColumnName(final String name) {
+ columnName = name;
+
+ }
+
+ @Override
+ public String getJPAColumnName() {
+ return columnName;
+ }
+
+ @Override
+ public void setJPAType(final Class<?> type) {
+ this.type = type;
+
+ }
+
+ @Override
+ public Class<?> getJPAType() {
+ return type;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModel.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModel.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModel.java
new file mode 100644
index 0000000..966bdd0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModel.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+
+public class JPAEdmModel extends JPAEdmBaseViewImpl implements JPAEdmModelView {
+
+ protected JPAEdmSchemaView schemaView;
+
+ public JPAEdmModel(final Metamodel metaModel, final String pUnitName) {
+ super(metaModel, pUnitName);
+ }
+
+ public JPAEdmModel(final ODataJPAContext ctx) {
+ super(ctx);
+ }
+
+ @Override
+ public JPAEdmSchemaView getEdmSchemaView() {
+ return schemaView;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmModelBuilder();
+ }
+
+ return builder;
+ }
+
+ private class JPAEdmModelBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+ schemaView = new JPAEdmSchema(JPAEdmModel.this);
+ schemaView.getBuilder().build();
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationProperty.java
new file mode 100644
index 0000000..b1b06f4
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationProperty.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmNavigationProperty extends JPAEdmBaseViewImpl implements JPAEdmNavigationPropertyView {
+
+ private JPAEdmAssociationView associationView = null;
+ private NavigationProperty currentNavigationProperty = null;
+ private JPAEdmPropertyView propertyView = null;
+ private List<NavigationProperty> consistentNavigationProperties = null;
+ private int count;
+
+ public JPAEdmNavigationProperty(final JPAEdmAssociationView associationView, final JPAEdmPropertyView propertyView,
+ final int countNumber) {
+ super(associationView);
+ this.associationView = associationView;
+ this.propertyView = propertyView;
+ count = countNumber;
+ if (consistentNavigationProperties == null) {
+ consistentNavigationProperties = new ArrayList<NavigationProperty>();
+ }
+ }
+
+ public JPAEdmNavigationProperty(final JPAEdmSchemaView schemaView) {
+ super(schemaView);
+ consistentNavigationProperties = new ArrayList<NavigationProperty>();
+
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmNavigationPropertyBuilder();
+ }
+
+ return builder;
+ }
+
+ private class JPAEdmNavigationPropertyBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException {
+
+ currentNavigationProperty = new NavigationProperty();
+ JPAEdmNameBuilder.build(associationView, propertyView, JPAEdmNavigationProperty.this, skipDefaultNaming, count);
+ consistentNavigationProperties.add(currentNavigationProperty);
+ }
+
+ }
+
+ @Override
+ public NavigationProperty getEdmNavigationProperty() {
+ return currentNavigationProperty;
+ }
+
+ @Override
+ public List<NavigationProperty> getConsistentEdmNavigationProperties() {
+ return consistentNavigationProperties;
+ }
+
+ @Override
+ public void addJPAEdmNavigationPropertyView(final JPAEdmNavigationPropertyView view) {
+ if (view != null && view.isConsistent()) {
+ currentNavigationProperty = view.getEdmNavigationProperty();
+ consistentNavigationProperties.add(currentNavigationProperty);
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
new file mode 100644
index 0000000..0923176
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmProperty.java
@@ -0,0 +1,377 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.Attribute.PersistentAttributeType;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPATypeConvertor;
+
+public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
+ JPAEdmPropertyView, JPAEdmComplexPropertyView {
+
+ private JPAEdmSchemaView schemaView;
+ private JPAEdmEntityTypeView entityTypeView;
+ private JPAEdmComplexTypeView complexTypeView;
+ private JPAEdmNavigationPropertyView navigationPropertyView = null;
+
+ private JPAEdmKeyView keyView;
+ private List<Property> properties;
+ private SimpleProperty currentSimpleProperty = null;
+ private ComplexProperty currentComplexProperty = null;
+ private Attribute<?, ?> currentAttribute;
+ private boolean isBuildModeComplexType;
+ private Map<String, Integer> associationCount;
+
+ public JPAEdmProperty(final JPAEdmSchemaView view) {
+ super(view);
+ schemaView = view;
+ entityTypeView = schemaView.getJPAEdmEntityContainerView()
+ .getJPAEdmEntitySetView().getJPAEdmEntityTypeView();
+ complexTypeView = schemaView.getJPAEdmComplexTypeView();
+ navigationPropertyView = new JPAEdmNavigationProperty(schemaView);
+ isBuildModeComplexType = false;
+ associationCount = new HashMap<String, Integer>();
+ }
+
+ public JPAEdmProperty(final JPAEdmSchemaView schemaView,
+ final JPAEdmComplexTypeView view) {
+ super(view);
+ this.schemaView = schemaView;
+ complexTypeView = view;
+ isBuildModeComplexType = true;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmPropertyBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public List<Property> getEdmPropertyList() {
+ return properties;
+ }
+
+ @Override
+ public JPAEdmKeyView getJPAEdmKeyView() {
+ return keyView;
+ }
+
+ @Override
+ public SimpleProperty getEdmSimpleProperty() {
+ return currentSimpleProperty;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return currentAttribute;
+ }
+
+ @Override
+ public ComplexProperty getEdmComplexProperty() {
+ return currentComplexProperty;
+ }
+
+ @Override
+ public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() {
+ return navigationPropertyView;
+ }
+
+ private class JPAEdmPropertyBuilder implements JPAEdmBuilder {
+ /*
+ *
+ * Each call to build method creates a new EDM Property List.
+ * The Property List can be created either by an Entity type or
+ * ComplexType. The flag isBuildModeComplexType tells if the
+ * Properties are built for complex type or for Entity Type.
+ *
+ * While Building Properties Associations are built. However
+ * the associations thus built does not contain Referential
+ * constraint. Associations thus built only contains
+ * information about Referential constraints. Adding of
+ * referential constraints to Associations is the taken care
+ * by Schema.
+ *
+ * Building Properties is divided into four parts
+ * A) Building Simple Properties
+ * B) Building Complex Properties
+ * C) Building Associations
+ * D) Building Navigation Properties
+ *
+ * ************************************************************
+ * Build EDM Schema - STEPS
+ * ************************************************************
+ * A) Building Simple Properties:
+ *
+ * 1) Fetch JPA Attribute List from
+ * A) Complex Type
+ * B) Entity Type
+ * depending on isBuildModeComplexType.
+ * B) Building Complex Properties
+ * C) Building Associations
+ * D) Building Navigation Properties
+ *
+ * ************************************************************
+ * Build EDM Schema - STEPS
+ * ************************************************************
+ */
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ JPAEdmBuilder keyViewBuilder = null;
+
+ properties = new ArrayList<Property>();
+
+ List<Attribute<?, ?>> jpaAttributes = null;
+ String currentEntityName = null;
+ String targetEntityName = null;
+ String entityTypeName = null;
+ if (isBuildModeComplexType) {
+ jpaAttributes = sortInAscendingOrder(complexTypeView.getJPAEmbeddableType()
+ .getAttributes());
+ entityTypeName = complexTypeView.getJPAEmbeddableType().getJavaType()
+ .getSimpleName();
+ } else {
+ jpaAttributes = sortInAscendingOrder(entityTypeView.getJPAEntityType()
+ .getAttributes());
+ entityTypeName = entityTypeView.getJPAEntityType().getName();
+ }
+
+ for (Object jpaAttribute : jpaAttributes) {
+ currentAttribute = (Attribute<?, ?>) jpaAttribute;
+
+ // Check for need to Exclude
+ if (isExcluded((JPAEdmPropertyView) JPAEdmProperty.this, entityTypeName, currentAttribute.getName())) {
+ continue;
+ }
+
+ PersistentAttributeType attributeType = currentAttribute
+ .getPersistentAttributeType();
+
+ switch (attributeType) {
+ case BASIC:
+
+ currentSimpleProperty = new SimpleProperty();
+ JPAEdmNameBuilder
+ .build((JPAEdmPropertyView) JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming);
+
+ EdmSimpleTypeKind simpleTypeKind = JPATypeConvertor
+ .convertToEdmSimpleType(currentAttribute
+ .getJavaType(), currentAttribute);
+
+ currentSimpleProperty.setType(simpleTypeKind);
+ JPAEdmFacets.setFacets(currentAttribute, currentSimpleProperty);
+
+ properties.add(currentSimpleProperty);
+
+ if (((SingularAttribute<?, ?>) currentAttribute).isId()) {
+ if (keyView == null) {
+ keyView = new JPAEdmKey(JPAEdmProperty.this);
+ keyViewBuilder = keyView.getBuilder();
+ }
+
+ keyViewBuilder.build();
+ }
+
+ break;
+ case EMBEDDED:
+ ComplexType complexType = complexTypeView
+ .searchEdmComplexType(currentAttribute.getJavaType().getName());
+
+ if (complexType == null) {
+ JPAEdmComplexTypeView complexTypeViewLocal = new JPAEdmComplexType(
+ schemaView, currentAttribute);
+ complexTypeViewLocal.getBuilder().build();
+ complexType = complexTypeViewLocal.getEdmComplexType();
+ complexTypeView.addJPAEdmCompleTypeView(complexTypeViewLocal);
+
+ }
+
+ if (isBuildModeComplexType == false
+ && entityTypeView.getJPAEntityType().getIdType()
+ .getJavaType()
+ .equals(currentAttribute.getJavaType())) {
+
+ if (keyView == null) {
+ keyView = new JPAEdmKey(complexTypeView,
+ JPAEdmProperty.this);
+ }
+ keyView.getBuilder().build();
+ complexTypeView.expandEdmComplexType(complexType, properties, currentAttribute.getName());
+ } else {
+ currentComplexProperty = new ComplexProperty();
+ if (isBuildModeComplexType) {
+ JPAEdmNameBuilder
+ .build((JPAEdmComplexPropertyView) JPAEdmProperty.this,
+ complexTypeView.getJPAEmbeddableType().getJavaType().getSimpleName());
+ } else {
+ JPAEdmNameBuilder
+ .build((JPAEdmComplexPropertyView) JPAEdmProperty.this,
+ JPAEdmProperty.this, skipDefaultNaming);
+ }
+ currentComplexProperty.setType(new FullQualifiedName(
+ schemaView.getEdmSchema().getNamespace(),
+ complexType.getName()));
+
+ properties.add(currentComplexProperty);
+ if (!complexTypeView.isReferencedInKey(currentComplexProperty.getType().getName()))
+ {
+ complexTypeView.setReferencedInKey(currentComplexProperty.getType().getName());
+ }
+ }
+
+ break;
+ case MANY_TO_MANY:
+ case ONE_TO_MANY:
+ case ONE_TO_ONE:
+ case MANY_TO_ONE:
+
+ JPAEdmAssociationEndView associationEndView = new JPAEdmAssociationEnd(entityTypeView, JPAEdmProperty.this);
+ associationEndView.getBuilder().build();
+ JPAEdmAssociationView associationView = schemaView.getJPAEdmAssociationView();
+ if (associationView.searchAssociation(associationEndView) == null) {
+ int count = associationView.getNumberOfAssociationsWithSimilarEndPoints(associationEndView);
+ JPAEdmAssociationView associationViewLocal =
+ new JPAEdmAssociation(associationEndView, entityTypeView, JPAEdmProperty.this, count);
+ associationViewLocal.getBuilder().build();
+ associationView.addJPAEdmAssociationView(associationViewLocal, associationEndView);
+ }
+
+ JPAEdmReferentialConstraintView refConstraintView = new JPAEdmReferentialConstraint(
+ associationView, entityTypeView, JPAEdmProperty.this);
+ refConstraintView.getBuilder().build();
+
+ if (refConstraintView.isExists()) {
+ associationView.addJPAEdmRefConstraintView(refConstraintView);
+ }
+
+ if (navigationPropertyView == null) {
+ navigationPropertyView = new JPAEdmNavigationProperty(schemaView);
+ }
+ currentEntityName = entityTypeView.getJPAEntityType().getName();
+
+ if (currentAttribute.isCollection()) {
+ targetEntityName = ((PluralAttribute<?, ?, ?>) currentAttribute).getElementType().getJavaType()
+ .getSimpleName();
+ } else {
+ targetEntityName = currentAttribute.getJavaType().getSimpleName();
+ }
+ Integer sequenceNumber = associationCount.get(currentEntityName + targetEntityName);
+ if (sequenceNumber == null) {
+ sequenceNumber = new Integer(1);
+ } else {
+ sequenceNumber = new Integer(sequenceNumber.intValue() + 1);
+ }
+ associationCount.put(currentEntityName + targetEntityName, sequenceNumber);
+ JPAEdmNavigationPropertyView localNavigationPropertyView =
+ new JPAEdmNavigationProperty(associationView, JPAEdmProperty.this, sequenceNumber.intValue());
+ localNavigationPropertyView.getBuilder().build();
+ navigationPropertyView.addJPAEdmNavigationPropertyView(localNavigationPropertyView);
+ break;
+ default:
+ break;
+ }
+ }
+
+ }
+
+ @SuppressWarnings("rawtypes")
+ private List<Attribute<?, ?>> sortInAscendingOrder(final Set<?> jpaAttributes) {
+ List<Attribute<?, ?>> jpaAttributeList = new ArrayList<Attribute<?, ?>>();
+ Iterator itr = null;
+ Attribute<?, ?> smallestJpaAttribute;
+ Attribute<?, ?> currentJpaAttribute;
+ while (!jpaAttributes.isEmpty()) {
+ itr = jpaAttributes.iterator();
+ smallestJpaAttribute = (Attribute<?, ?>) itr.next();
+ while (itr.hasNext()) {
+ currentJpaAttribute = (Attribute<?, ?>) itr.next();
+ if (smallestJpaAttribute.getName().compareTo(currentJpaAttribute.getName()) > 0) {
+ smallestJpaAttribute = currentJpaAttribute;
+ }
+ }
+ jpaAttributeList.add(smallestJpaAttribute);
+ jpaAttributes.remove(smallestJpaAttribute);
+ }
+ return jpaAttributeList;
+ }
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return entityTypeView;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return complexTypeView;
+ }
+
+ private boolean isExcluded(final JPAEdmPropertyView jpaEdmPropertyView, final String jpaEntityTypeName,
+ final String jpaAttributeName) {
+ JPAEdmMappingModelAccess mappingModelAccess = jpaEdmPropertyView
+ .getJPAEdmMappingModelAccess();
+ boolean isExcluded = false;
+ if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
+ // Exclusion of a simple property in a complex type
+ if (isBuildModeComplexType
+ && mappingModelAccess.checkExclusionOfJPAEmbeddableAttributeType(jpaEntityTypeName, jpaAttributeName)
+ // Exclusion of a simple property of an Entity Type
+ || (!isBuildModeComplexType && mappingModelAccess.checkExclusionOfJPAAttributeType(jpaEntityTypeName,
+ jpaAttributeName))) {
+ isExcluded = true;
+ }
+ }
+ return isExcluded;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraint.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraint.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraint.java
new file mode 100644
index 0000000..cd80e70
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraint.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView.RoleType;
+
+public class JPAEdmReferentialConstraint extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintView {
+
+ private JPAEdmRefConstraintBuilder builder = null;
+
+ private boolean exists = false;
+ private boolean firstBuild = true;
+
+ private JPAEdmAssociationView associationView;
+ private JPAEdmPropertyView propertyView;
+ private JPAEdmEntityTypeView entityTypeView;
+
+ private ReferentialConstraint referentialConstraint;
+
+ private JPAEdmReferentialConstraintRoleView principalRoleView;
+ private JPAEdmReferentialConstraintRoleView dependentRoleView;
+
+ private String relationShipName;
+
+ public JPAEdmReferentialConstraint(final JPAEdmAssociationView associationView,
+ final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) {
+ super(associationView);
+ this.associationView = associationView;
+ this.propertyView = propertyView;
+ this.entityTypeView = entityTypeView;
+
+ relationShipName = associationView.getEdmAssociation().getName();
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmRefConstraintBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public ReferentialConstraint getEdmReferentialConstraint() {
+ return referentialConstraint;
+ }
+
+ @Override
+ public boolean isExists() {
+ return exists;
+ }
+
+ @Override
+ public String getEdmRelationShipName() {
+ return relationShipName;
+ }
+
+ private class JPAEdmRefConstraintBuilder implements JPAEdmBuilder {
+ /*
+ * Check if Ref Constraint was already Built. If Ref constraint was
+ * already built consistently then do not build referential constraint.
+ *
+ * For Ref Constraint to be consistently built Principal and Dependent
+ * roles must be consistently built. If Principal or Dependent roles are
+ * not consistently built then try building them again.
+ *
+ * The Principal and Dependent roles could be have been built
+ * inconsistently if the required EDM Entity Types or EDM properties are
+ * yet to be built. In such cases rebuilding these roles would make them
+ * consistent.
+ */
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ if (firstBuild) {
+ firstBuild();
+ } else {
+ if (exists && !firstBuild && principalRoleView.isConsistent() == false) {
+ principalRoleView.getBuilder().build();
+ }
+
+ if (exists && !firstBuild && dependentRoleView.isConsistent() == false) {
+ dependentRoleView.getBuilder().build();
+ }
+ }
+
+ if (principalRoleView.isConsistent()) {
+ referentialConstraint.setPrincipal(principalRoleView.getEdmReferentialConstraintRole());
+ }
+
+ if (dependentRoleView.isConsistent()) {
+ referentialConstraint.setDependent(dependentRoleView.getEdmReferentialConstraintRole());
+ }
+
+ exists = principalRoleView.isExists() & dependentRoleView.isExists();
+
+ isConsistent = principalRoleView.isConsistent() & dependentRoleView.isConsistent();
+
+ }
+
+ private void firstBuild() throws ODataJPAModelException, ODataJPARuntimeException {
+ firstBuild = false;
+ if (principalRoleView == null && dependentRoleView == null) {
+
+ principalRoleView =
+ new JPAEdmReferentialConstraintRole(RoleType.PRINCIPAL, entityTypeView, propertyView, associationView);
+ principalRoleView.getBuilder().build();
+
+ dependentRoleView =
+ new JPAEdmReferentialConstraintRole(RoleType.DEPENDENT, entityTypeView, propertyView, associationView);
+ dependentRoleView.getBuilder().build();
+
+ if (referentialConstraint == null) {
+ referentialConstraint = new ReferentialConstraint();
+ }
+ }
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
new file mode 100644
index 0000000..6358774
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRole.java
@@ -0,0 +1,258 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinColumns;
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView;
+
+public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView {
+ /*
+ * Static Buffer
+ */
+ private static Attribute<?, ?> bufferedJPAAttribute = null;
+ private static ArrayList<JoinColumn> bufferedJoinColumns = new ArrayList<JoinColumn>();
+ /*
+ * Static Buffer
+ */
+
+ private boolean firstBuild = true;
+
+ private JPAEdmEntityTypeView entityTypeView;
+ private JPAEdmReferentialConstraintRoleView.RoleType roleType;
+
+ private Attribute<?, ?> jpaAttribute;
+ private ArrayList<String> jpaColumnNames;
+ private Association association;
+
+ private boolean roleExists = false;
+
+ private JPAEdmRefConstraintRoleBuilder builder;
+ private ReferentialConstraintRole currentRole;
+
+ public JPAEdmReferentialConstraintRole(final JPAEdmReferentialConstraintRoleView.RoleType roleType,
+ final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView,
+ final JPAEdmAssociationView associationView) {
+
+ super(entityTypeView);
+ this.entityTypeView = entityTypeView;
+ this.roleType = roleType;
+
+ jpaAttribute = propertyView.getJPAAttribute();
+ association = associationView.getEdmAssociation();
+
+ }
+
+ @Override
+ public boolean isExists() {
+ return roleExists;
+
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmRefConstraintRoleBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public RoleType getRoleType() {
+ return roleType;
+ }
+
+ @Override
+ public ReferentialConstraintRole getEdmReferentialConstraintRole() {
+ return currentRole;
+ }
+
+ @Override
+ public String getJPAColumnName() {
+ return null;
+ }
+
+ @Override
+ public String getEdmEntityTypeName() {
+ return null;
+ }
+
+ @Override
+ public String getEdmAssociationName() {
+ return null;
+ }
+
+ private class JPAEdmRefConstraintRoleBuilder implements JPAEdmBuilder {
+
+ @Override
+ public void build() throws ODataJPAModelException {
+ if (firstBuild) {
+ firstBuild();
+ } else if (roleExists) {
+ try {
+ buildRole();
+ } catch (SecurityException e) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
+ } catch (NoSuchFieldException e) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
+ }
+ }
+
+ }
+
+ private void firstBuild() {
+ firstBuild = false;
+ isConsistent = false;
+
+ extractJoinColumns();
+
+ if (!roleExists) {
+ return;
+ }
+
+ jpaColumnNames = new ArrayList<String>();
+
+ for (JoinColumn joinColumn : bufferedJoinColumns) {
+ if (roleType == RoleType.PRINCIPAL) {
+ jpaColumnNames.add(joinColumn.referencedColumnName());
+ } else if (roleType == RoleType.DEPENDENT) {
+ jpaColumnNames.add(joinColumn.name());
+ }
+ }
+
+ }
+
+ private void buildRole() throws SecurityException, NoSuchFieldException {
+
+ if (currentRole == null) {
+ currentRole = new ReferentialConstraintRole();
+ String jpaAttributeType = null;
+ EntityType edmEntityType = null;
+
+ if (roleType == RoleType.PRINCIPAL) {
+ jpaAttributeType = jpaAttribute.getJavaType().getSimpleName();
+ if (jpaAttributeType.equals("List")) {
+ Type type =
+ ((ParameterizedType) jpaAttribute.getJavaMember().getDeclaringClass().getDeclaredField(
+ jpaAttribute.getName()).getGenericType()).getActualTypeArguments()[0];
+ int lastIndexOfDot = type.toString().lastIndexOf(".");
+ jpaAttributeType = type.toString().substring(lastIndexOfDot + 1);
+ }
+ edmEntityType = entityTypeView.searchEdmEntityType(jpaAttributeType);
+ } else if (roleType == RoleType.DEPENDENT) {
+ edmEntityType =
+ entityTypeView.searchEdmEntityType(jpaAttribute.getDeclaringType().getJavaType().getSimpleName());
+ }
+
+ List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
+ if (edmEntityType != null) {
+ for (String columnName : jpaColumnNames) {
+ for (Property property : edmEntityType.getProperties()) {
+ if (columnName.equals(((JPAEdmMapping) property.getMapping()).getJPAColumnName())) {
+ PropertyRef propertyRef = new PropertyRef();
+ propertyRef.setName(property.getName());
+ propertyRefs.add(propertyRef);
+ break;
+ }
+ }
+ }
+ currentRole.setPropertyRefs(propertyRefs);
+ if (propertyRefs.isEmpty()) {
+ isConsistent = false;
+ return;
+ }
+ AssociationEnd end = association.getEnd1();
+ if (end.getType().getName().equals(edmEntityType.getName())) {
+ currentRole.setRole(end.getRole());
+ isConsistent = true;
+ } else {
+ end = association.getEnd2();
+ if (end.getType().getName().equals(edmEntityType.getName())) {
+ currentRole.setRole(end.getRole());
+ isConsistent = true;
+ }
+ }
+ }
+
+ }
+ }
+
+ private void extractJoinColumns() {
+ /*
+ * Check against Static Buffer whether the join column was already
+ * extracted.
+ */
+ if (!jpaAttribute.equals(bufferedJPAAttribute)) {
+ bufferedJPAAttribute = jpaAttribute;
+ bufferedJoinColumns.clear();
+ } else if (bufferedJoinColumns.isEmpty()) {
+ roleExists = false;
+ return;
+ } else {
+ roleExists = true;
+ return;
+ }
+
+ AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember();
+
+ if (annotatedElement == null) {
+ return;
+ }
+
+ JoinColumn joinColumn = annotatedElement.getAnnotation(JoinColumn.class);
+ if (joinColumn == null) {
+ JoinColumns joinColumns = annotatedElement.getAnnotation(JoinColumns.class);
+
+ if (joinColumns != null) {
+ JoinColumn[] joinColumnArray = joinColumns.value();
+
+ for (JoinColumn element : joinColumnArray) {
+ bufferedJoinColumns.add(element);
+ }
+ } else {
+ return;
+ }
+ } else {
+ bufferedJoinColumns.add(joinColumn);
+ }
+ roleExists = true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchema.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchema.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchema.java
new file mode 100644
index 0000000..f27accd
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchema.java
@@ -0,0 +1,214 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmFunctionImportView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+
+public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView {
+
+ private Schema schema;
+ private JPAEdmComplexTypeView complexTypeView;
+ private JPAEdmEntityContainerView entityContainerView;
+ private JPAEdmAssociationView associationView = null;
+ private HashMap<Class<?>, String[]> customOperations = null;
+
+ public JPAEdmSchema(final JPAEdmModelView modelView) {
+ super(modelView);
+ }
+
+ @Override
+ public Schema getEdmSchema() {
+ return schema;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return entityContainerView;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return complexTypeView;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ if (builder == null) {
+ builder = new JPAEdmSchemaBuilder();
+ }
+
+ return builder;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+ schema = null;
+ }
+
+ private class JPAEdmSchemaBuilder implements JPAEdmBuilder {
+ /*
+ *
+ * Each call to build method creates a new EDM Schema. The newly created
+ * schema is built with Entity Containers, associations, Complex Types
+ * and Entity Types.
+ *
+ * ************************************************************ Build
+ * EDM Schema - STEPS
+ * ************************************************************ 1) Build
+ * Name for EDM Schema 2) Build EDM Complex Types from JPA Embeddable
+ * Types 3) Add EDM Complex Types to EDM Schema 4) Build EDM Entity
+ * Container 5) Add EDM Entity Container to EDM Schema 6) Fetch Built
+ * EDM Entity Types from EDM Entity Container 7) Add EDM Entity Types to
+ * EDM Schema 8) Fetch Built EDM Association Sets from EDM Entity
+ * Container 9) Fetch Built EDM Associations from EDM Association Set
+ * 10) Add EDM Association to EDM Schema
+ * ************************************************************ Build
+ * EDM Schema - STEPS
+ * ************************************************************
+ */
+ @Override
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException {
+
+ schema = new Schema();
+ JPAEdmNameBuilder.build(JPAEdmSchema.this);
+
+ associationView = new JPAEdmAssociation(JPAEdmSchema.this);
+
+ complexTypeView = new JPAEdmComplexType(JPAEdmSchema.this);
+ complexTypeView.getBuilder().build();
+
+ entityContainerView = new JPAEdmEntityContainer(JPAEdmSchema.this);
+ entityContainerView.getBuilder().build();
+ schema.setEntityContainers(entityContainerView.getConsistentEdmEntityContainerList());
+
+ JPAEdmEntitySetView entitySetView = entityContainerView.getJPAEdmEntitySetView();
+ if (entitySetView.isConsistent() && entitySetView.getJPAEdmEntityTypeView() != null) {
+ JPAEdmEntityTypeView entityTypeView = entitySetView.getJPAEdmEntityTypeView();
+ if (entityTypeView.isConsistent() && !entityTypeView.getConsistentEdmEntityTypes().isEmpty()) {
+ schema.setEntityTypes(entityTypeView.getConsistentEdmEntityTypes());
+ }
+ }
+ if (complexTypeView.isConsistent()) {
+ List<ComplexType> complexTypes = complexTypeView.getConsistentEdmComplexTypes();
+ List<ComplexType> existingComplexTypes = new ArrayList<ComplexType>();
+ for (ComplexType complexType : complexTypes) {
+ if (complexType != null && complexTypeView.isReferencedInKey(complexType.getName())) {// null check for
+ // exclude
+ existingComplexTypes.add(complexType);
+ }
+ }
+ if (!existingComplexTypes.isEmpty()) {
+ schema.setComplexTypes(existingComplexTypes);
+ }
+ }
+
+ List<String> existingAssociationList = new ArrayList<String>();
+ if (associationView.isConsistent() && !associationView.getConsistentEdmAssociationList().isEmpty()) {
+
+ List<Association> consistentAssociationList = associationView.getConsistentEdmAssociationList();
+ schema.setAssociations(consistentAssociationList);
+ for (Association association : consistentAssociationList) {
+ existingAssociationList.add(association.getName());
+ }
+
+ }
+ List<EntityType> entityTypes =
+ entityContainerView.getJPAEdmEntitySetView().getJPAEdmEntityTypeView().getConsistentEdmEntityTypes();
+ List<NavigationProperty> navigationProperties;
+ if (entityTypes != null && !entityTypes.isEmpty()) {
+ for (EntityType entityType : entityTypes) {
+
+ List<NavigationProperty> consistentNavigationProperties = null;
+ navigationProperties = entityType.getNavigationProperties();
+ if (navigationProperties != null) {
+ consistentNavigationProperties = new ArrayList<NavigationProperty>();
+ for (NavigationProperty navigationProperty : navigationProperties) {
+ if (existingAssociationList.contains(navigationProperty.getRelationship().getName())) {
+ consistentNavigationProperties.add(navigationProperty);
+ }
+ }
+ if (consistentNavigationProperties.isEmpty()) {
+ entityType.setNavigationProperties(null);
+ } else {
+ entityType.setNavigationProperties(consistentNavigationProperties);
+ }
+ }
+
+ }
+ }
+
+ JPAEdmExtension edmExtension = getJPAEdmExtension();
+ if (edmExtension != null) {
+ edmExtension.extendJPAEdmSchema(JPAEdmSchema.this);
+ edmExtension.extendWithOperation(JPAEdmSchema.this);
+
+ JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(JPAEdmSchema.this);
+ functionImportView.getBuilder().build();
+ if (functionImportView.getConsistentFunctionImportList() != null) {
+ entityContainerView.getEdmEntityContainer().setFunctionImports(
+ functionImportView.getConsistentFunctionImportList());
+ }
+
+ }
+ }
+
+ }
+
+ @Override
+ public final JPAEdmAssociationView getJPAEdmAssociationView() {
+ return associationView;
+ }
+
+ @Override
+ public void registerOperations(final Class<?> customClass, final String[] methodNames) {
+ if (customOperations == null) {
+ customOperations = new HashMap<Class<?>, String[]>();
+ }
+
+ customOperations.put(customClass, methodNames);
+
+ }
+
+ @Override
+ public HashMap<Class<?>, String[]> getRegisteredOperations() {
+ return customOperations;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java
new file mode 100644
index 0000000..94e7374
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportBuilder.java
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.Parameter;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmNameBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.access.model.JPATypeConvertor;
+
+@Deprecated
+public final class _JPAEdmFunctionImportBuilder {
+
+ private JPAEdmEntityTypeView jpaEdmEntityTypeView = null;
+ private JPAEdmComplexTypeView jpaEdmComplexTypeView = null;
+ private JPAEdmSchemaView schemaView;
+
+ public void setJPAEdmEntityTypeView(final JPAEdmEntityTypeView jpaEdmEntityTypeView) {
+ this.jpaEdmEntityTypeView = jpaEdmEntityTypeView;
+ }
+
+ public void setSchemaView(final JPAEdmSchemaView schemaView) {
+ this.schemaView = schemaView;
+ }
+
+ public void setJPAEdmComplexTypeView(final JPAEdmComplexTypeView jpaEdmComplexTypeView) {
+ this.jpaEdmComplexTypeView = jpaEdmComplexTypeView;
+ }
+
+ public FunctionImport buildFunctionImport(final Method method,
+ final org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation) throws ODataJPAModelException {
+
+ if (method != null && annotation != null && annotation.returnType() != ReturnType.NONE) {
+ FunctionImport functionImport = new FunctionImport();
+
+ if (annotation.name().equals("")) {
+ functionImport.setName(method.getName());
+ } else {
+ functionImport.setName(annotation.name());
+ }
+
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ ((Mapping) mapping).setInternalName(method.getName());
+ mapping.setJPAType(method.getDeclaringClass());
+ functionImport.setMapping((Mapping) mapping);
+
+ functionImport.setHttpMethod(annotation.httpMethod().name().toString());
+
+ buildReturnType(functionImport, method, annotation);
+ buildParameter(functionImport, method);
+ return functionImport;
+ }
+ return null;
+
+ }
+
+ private void buildParameter(final FunctionImport functionImport, final Method method)
+ throws ODataJPAModelException {
+
+ Annotation[][] annotations = method.getParameterAnnotations();
+ Class<?>[] parameterTypes = method.getParameterTypes();
+ List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
+ JPAEdmMapping mapping = null;
+ int j = 0;
+ for (Annotation[] annotationArr : annotations) {
+ Class<?> parameterType = parameterTypes[j++];
+
+ for (Annotation element : annotationArr) {
+ if (element instanceof Parameter) {
+ Parameter annotation = (Parameter) element;
+ FunctionImportParameter functionImportParameter = new FunctionImportParameter();
+ if (annotation.name().equals("")) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method
+ .getDeclaringClass().getName(), method.getName()), null);
+ } else {
+ functionImportParameter.setName(annotation.name());
+ }
+
+ functionImportParameter.setType(JPATypeConvertor.convertToEdmSimpleType(parameterType, null));
+ functionImportParameter.setMode(annotation.mode().toString());
+
+ Facets facets = new Facets();
+ if (annotation.facets().maxLength() > 0) {
+ facets.setMaxLength(annotation.facets().maxLength());
+ }
+ if (annotation.facets().nullable() == false) {
+ facets.setNullable(false);
+ } else {
+ facets.setNullable(true);
+ }
+
+ if (annotation.facets().precision() > 0) {
+ facets.setPrecision(annotation.facets().precision());
+ }
+ if (annotation.facets().scale() >= 0) {
+ facets.setScale(annotation.facets().scale());
+ }
+
+ functionImportParameter.setFacets(facets);
+ mapping = new JPAEdmMappingImpl();
+ mapping.setJPAType(parameterType);
+ functionImportParameter.setMapping((Mapping) mapping);
+ funcImpList.add(functionImportParameter);
+ }
+ }
+ }
+ if (!funcImpList.isEmpty()) {
+ functionImport.setParameters(funcImpList);
+ }
+ }
+
+ private void buildReturnType(final FunctionImport functionImport, final Method method,
+ final org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation) throws ODataJPAModelException {
+ org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType returnType = annotation.returnType();
+ Multiplicity multiplicity = null;
+
+ if (returnType != ReturnType.NONE) {
+ org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType =
+ new org.apache.olingo.odata2.api.edm.provider.ReturnType();
+ multiplicity = annotation.multiplicity();
+
+ if (multiplicity == Multiplicity.MANY) {
+ functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
+ } else {
+ functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
+ }
+
+ if (returnType == ReturnType.ENTITY_TYPE) {
+ String entitySet = annotation.entitySet();
+ if (entitySet.equals("")) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
+ }
+ functionImport.setEntitySet(entitySet);
+ }
+
+ Class<?> methodReturnType = method.getReturnType();
+ if (methodReturnType == null || methodReturnType.getName().equals("void")) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method
+ .getDeclaringClass(), method.getName()), null);
+ }
+ switch (returnType) {
+ case ENTITY_TYPE:
+ EntityType edmEntityType = null;
+ if (multiplicity == Multiplicity.ONE) {
+ edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName());
+ } else if (multiplicity == Multiplicity.MANY) {
+ edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method));
+ }
+
+ if (edmEntityType == null) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
+ .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+ }
+ functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName()));
+ break;
+ case SCALAR:
+
+ EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConvertor.convertToEdmSimpleType(methodReturnType, null);
+ functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName());
+
+ break;
+ case COMPLEX_TYPE:
+ ComplexType complexType = null;
+ if (multiplicity == Multiplicity.ONE) {
+ complexType = jpaEdmComplexTypeView.searchEdmComplexType(methodReturnType.getName());
+ } else if (multiplicity == Multiplicity.MANY) {
+ complexType = jpaEdmComplexTypeView.searchEdmComplexType(getReturnTypeName(method));
+ }
+ if (complexType == null) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
+ .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+ }
+ functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
+ break;
+ default:
+ break;
+ }
+ functionImport.setReturnType(functionReturnType);
+ }
+ }
+
+ private String getReturnTypeName(final Method method) {
+ try {
+ ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
+ Type t = pt.getActualTypeArguments()[0];
+ return ((Class<?>) t).getName();
+ } catch (ClassCastException e) {
+ return method.getReturnType().getName();
+ }
+ }
+
+ private String getReturnTypeSimpleName(final Method method) {
+ try {
+ ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
+ Type t = pt.getActualTypeArguments()[0];
+ return ((Class<?>) t).getSimpleName();
+ } catch (ClassCastException e) {
+ return method.getReturnType().getSimpleName();
+ }
+ }
+}
[42/47] [OLINGO-103] Expose ODataJPAResponseBuilder for External Usage
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
index f4cc3f0..479dc6a 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
@@ -58,15 +58,23 @@ import org.apache.olingo.odata2.api.uri.SelectItem;
import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.jpa.processor.core.ODataJPAResponseBuilder;
import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmTestModelView;
import org.easymock.EasyMock;
+import org.junit.Before;
import org.junit.Test;
public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
+ private ODataJPAResponseBuilder responseBuilder;
+
+ @Before
+ public void init() {
+ responseBuilder = new ODataJPAResponseBuilderDefault(getODataJPAContext());
+ }
+
/*
* This Unit is supposed to test the building of Entity Provider Properties for query with $expand
*/
@@ -80,12 +88,11 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
edmEntity.put("ID", 1);
edmEntityList.add(edmEntity);
// Invoking the private static method using reflection
- Class<?> clazz = ODataJPAResponseBuilder.class;
+ Class<?> clazz = ODataJPAResponseBuilderDefault.class;
Object[] actualParameters = { oDataJPAContext, getEntitySetUriInfo, edmEntityList };
Class<?>[] formalParameters = { ODataJPAContext.class, GetEntitySetUriInfo.class, List.class };
EntityProviderWriteProperties providerProperties = null;
try {
- ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
Method method = clazz.getDeclaredMethod("getEntityProviderProperties", formalParameters);
method.setAccessible(true);
providerProperties = (EntityProviderWriteProperties) method.invoke(responseBuilder, actualParameters);
@@ -100,8 +107,6 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
} catch (InvocationTargetException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InstantiationException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
}
@@ -114,12 +119,11 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
// Getting the EntityUriInfo
GetEntityUriInfo getEntityUriInfo = mockEntityUriInfoForExpand();
ODataJPAContext oDataJPAContext = getODataJPAContext();
- Class<?> clazz = ODataJPAResponseBuilder.class;
+ Class<?> clazz = ODataJPAResponseBuilderDefault.class;
Object[] actualParameters = { oDataJPAContext, getEntityUriInfo };
Class<?>[] formalParameters = { ODataJPAContext.class, GetEntityUriInfo.class };
EntityProviderWriteProperties providerProperties = null;
try {
- ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
Method method = clazz.getDeclaredMethod("getEntityProviderProperties", formalParameters);
method.setAccessible(true);
providerProperties = (EntityProviderWriteProperties) method.invoke(responseBuilder, actualParameters);
@@ -134,8 +138,6 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
} catch (InvocationTargetException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InstantiationException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
}
@@ -152,12 +154,11 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties21"));
navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties22"));
expand.add(navPropList2);
- Class<?> clazz = ODataJPAResponseBuilder.class;
+ Class<?> clazz = ODataJPAResponseBuilderDefault.class;
Object[] actualParameters = { expand };
Class<?>[] formalParameters = { List.class };
List<EdmNavigationProperty> navigationProperties = null;
try {
- ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
Method method = clazz.getDeclaredMethod("constructListofNavProperty", formalParameters);
method.setAccessible(true);
navigationProperties = (List<EdmNavigationProperty>) method.invoke(responseBuilder, actualParameters);
@@ -173,8 +174,6 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
} catch (InvocationTargetException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InstantiationException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
} catch (EdmException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
@@ -184,8 +183,7 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
@Test
public void testBuildListOfTGetEntitySetUriInfoStringODataJPAContext() {
try {
- assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "application/xml",
- getODataJPAContext()));
+ assertNotNull(responseBuilder.build(getResultsView(), getJPAEntities(), "application/xml"));
} catch (ODataJPARuntimeException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
@@ -198,7 +196,7 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
EntityType entity = new EntityType();
entity.setName("SalesOrderHeader");
try {
- assertNotNull(ODataJPAResponseBuilder.build(getEntity(), getLocalGetURIInfo(), "xml", getODataJPAContext()));
+ assertNotNull(responseBuilder.build(getLocalGetURIInfo(), getEntity(), "xml"));
} catch (ODataNotFoundException e) {
assertTrue(true);
}
@@ -206,7 +204,7 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
assertTrue(true);// Nothing to do, Expected.
}
try {// Bad content type
- assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "xml", getODataJPAContext()));
+ assertNotNull(responseBuilder.build(getResultsView(), getJPAEntities(), "xml"));
} catch (ODataJPARuntimeException e) {
assertTrue(true);// Nothing to do, Expected.
}
@@ -216,8 +214,8 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
@Test
public void testBuildObjectGetEntityUriInfoStringODataJPAContext() throws ODataNotFoundException {
try {
- assertNotNull(ODataJPAResponseBuilder.build(new SalesOrderHeader(2, 10), getLocalGetURIInfo(), "application/xml",
- getODataJPAContext()));
+ assertNotNull(responseBuilder.build(getLocalGetURIInfo(), (Object) new SalesOrderHeader(2, 10),
+ "application/xml"));
} catch (ODataJPARuntimeException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
@@ -226,7 +224,7 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
@Test
public void testBuildNullSelects() {// Bad content type
try {
- ODataJPAResponseBuilder.build(getJPAEntities(), getResultsViewWithNullSelects(), "xml", getODataJPAContext());
+ responseBuilder.build(getResultsViewWithNullSelects(), getJPAEntities(), "xml");
} catch (ODataJPARuntimeException e) {
assertTrue(true);// Nothing to do, Expected.
} catch (Exception e) {
@@ -238,7 +236,7 @@ public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
public void testBuildGetCount() {
ODataResponse objODataResponse = null;
try {
- objODataResponse = ODataJPAResponseBuilder.build(1, getODataJPAContext());
+ objODataResponse = responseBuilder.build(1);
} catch (ODataJPARuntimeException e) {
fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
}
[36/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
deleted file mode 100644
index 9ec27c4..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
+++ /dev/null
@@ -1,137 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-
-/**
- * A view on Java Persistence embeddable types and EDM complex types. Java
- * persistence embeddable types are converted into EDM entity types. Only those
- * embeddable types that are
- * <ol>
- * <li>used in a java persistence Entity type</li>
- * <li>used as non embeddable id of a java persistence entity type</li>
- * </ol>
- * are converted into EDM complex types.
- * <p>
- * The implementation of the view provides access to EDM complex types for the
- * given JPA EDM model. The view acts as a container for consistent list of EDM
- * complex types. An EDM complex type is said to be consistent only if it used
- * in at least one of the EDM entity type.
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView
- *
- */
-public interface JPAEdmComplexTypeView extends JPAEdmBaseView {
-
- /**
- * The method returns an EDM complex type that is currently being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.ComplexType}
- */
- public ComplexType getEdmComplexType();
-
- /**
- * The method returns an JPA embeddable type that is currently being
- * processed.
- *
- * @return an instance of type {@link javax.persistence.metamodel.EmbeddableType}
- */
- public javax.persistence.metamodel.EmbeddableType<?> getJPAEmbeddableType();
-
- /**
- * The method returns a consistent list of EDM complex types.
- *
- * @return a list of {@link org.apache.olingo.odata2.api.edm.provider.ComplexType}
- */
- public List<ComplexType> getConsistentEdmComplexTypes();
-
- /**
- * The method searches for the EDM complex type with in the container for
- * the given JPA embeddable type name.
- *
- * @param embeddableTypeName
- * is the name of JPA embeddable type
- * @return a reference to EDM complex type if found else null
- */
- public ComplexType searchEdmComplexType(String embeddableTypeName);
-
- /**
- * The method add a JPA EDM complex type view to the container.
- *
- * @param view
- * @param isReferencedInKey
- * is the complex type referenced in an Entity as a key property
- * is an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}
- */
- public void addJPAEdmCompleTypeView(JPAEdmComplexTypeView view);
-
- /**
- * The method searches for the EDM complex type with in the container for
- * the given EDM complex type's fully qualified name.
- *
- * @param type
- * is the fully qualified name of EDM complex type
- * @return a reference to EDM complex type if found else null
- */
- public ComplexType searchEdmComplexType(FullQualifiedName type);
-
- /**
- * The method expands the given EDM complex type into a list of EDM simple
- * properties.
- *
- * @param complexType
- * is the EDM complex type to expand
- * @param expandedPropertyList
- * is the list to be populated with expanded EDM simple
- * properties
- * @param embeddablePropertyName
- * is the name of the complex property. The name is used as the
- * qualifier for the expanded simple property names.
- */
- public void expandEdmComplexType(ComplexType complexType, List<Property> expandedPropertyList,
- String embeddablePropertyName);
-
- /**
- * The method checks if the given EDM complex type is referenced as a Key property in any Entity
- * @param complexTypeName
- * EDM complex type name
- * @return
- * <ul><li><b>true</b> : if the complex type is referenced as an entity's key property</li>
- * <li><b>false</b> : if the complex type is not referenced as an entity's key property</li>
- * </ul>
- *
- */
- public boolean isReferencedInKey(String complexTypeName);
-
- /**
- * The method sets the given EDM complex type as referenced in an Entity as a key property
- * @param complexTypeName
- * EDM complex Type name
- */
- public void setReferencedInKey(String complexTypeName);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityContainerView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityContainerView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityContainerView.java
deleted file mode 100644
index 82ccaf9..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityContainerView.java
+++ /dev/null
@@ -1,72 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-
-/**
- * A view on JPA EDM entity container. JPA EDM entity container is built from
- * consistent JPA EDM entity set and consistent JPA EDM association set views.
- *
- * <p>
- * The implementation of the view provides access to EDM entity containers. The
- * view acts as container for JPA EDM entity containers. A JPA EDM entity
- * container is said to be consistent only if the JPA EDM association set and
- * JPA EDM Entity Set view are consistent.
- *
- *
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView
- *
- */
-public interface JPAEdmEntityContainerView extends JPAEdmBaseView {
- /**
- * The method returns the EDM entity container that is currently being
- * processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.EntityContainer}
- */
- public EntityContainer getEdmEntityContainer();
-
- /**
- * The method returns a list of consistent EDM entity containers
- *
- * @return a list of consistent EDM entity containers
- */
- public List<EntityContainer> getConsistentEdmEntityContainerList();
-
- /**
- * The method returns the JPA EDM entity set view that is currently being
- * processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView}
- */
- public JPAEdmEntitySetView getJPAEdmEntitySetView();
-
- /**
- * The method returns the JPA EDM association set view that is currently
- * being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView}
- */
- public JPAEdmAssociationSetView getEdmAssociationSetView();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntitySetView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntitySetView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntitySetView.java
deleted file mode 100644
index 87019f6..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntitySetView.java
+++ /dev/null
@@ -1,64 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-
-/**
- * A view on Java Persistence entity type and EDM entity sets. Java persistence
- * entity types are converted into EDM entity types and EDM entity sets.
- * <p>
- * The implementation of the view provides access to EDM entity sets for the
- * given JPA EDM entity type. The view acts as a container for consistent list
- * of EDM entity sets. An EDM entity set is said to be consistent only if it has
- * consistent EDM entity types.
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView
- *
- */
-public interface JPAEdmEntitySetView extends JPAEdmBaseView {
- /**
- * The method returns an EDM entity set that is currently being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.EntitySet}
- */
- public EntitySet getEdmEntitySet();
-
- /**
- * The method returns a list of consistent EDM entity sets.
- *
- * @return a list of EDM entity sets
- */
- public List<EntitySet> getConsistentEdmEntitySetList();
-
- /**
- * The method returns a JPA EDM entity type view that is currently being
- * processed. JPA EDM entity set view is built from JPA EDM entity type
- * view.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView}
- */
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityTypeView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityTypeView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityTypeView.java
deleted file mode 100644
index 54965d8..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmEntityTypeView.java
+++ /dev/null
@@ -1,76 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-
-/**
- * A view on Java Persistence entity types and EDM entity types. Java
- * persistence entity types are converted into EDM entity types.
- * <p>
- * The implementation of the view provides access to EDM entity types for the
- * given JPA EDM model. The view acts as a container for consistent list of EDM
- * entity types. An EDM entity type is said to be consistent only if it has at
- * least one consistent EDM property and at least one consistent EDM key.
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView
- *
- */
-public interface JPAEdmEntityTypeView extends JPAEdmBaseView {
- /**
- * The method returns an EDM entity currently being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.EntityType}
- */
- public EntityType getEdmEntityType();
-
- /**
- * The method returns java persistence Entity type currently being
- * processed.
- *
- * @return an instance of type {@link javax.persistence.metamodel.EntityType}
- */
- public javax.persistence.metamodel.EntityType<?> getJPAEntityType();
-
- /**
- * The method returns a consistent list of EDM entity types for a given java
- * persistence meta model.
- *
- * @return a list of {@link org.apache.olingo.odata2.api.edm.provider.EntityType}
- */
- public List<EntityType> getConsistentEdmEntityTypes();
-
- /**
- * The method searches in the consistent list of EDM entity types for the
- * given EDM entity type's name.
- *
- * @param jpaEntityTypeName
- * is the name of EDM entity type
- * @return a reference to EDM entity type if found else null
- */
- public EntityType searchEdmEntityType(String jpaEntityTypeName);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmExtension.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmExtension.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmExtension.java
deleted file mode 100644
index 1345106..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmExtension.java
+++ /dev/null
@@ -1,50 +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.odata2.processor.api.jpa.model;
-
-/**
- * The interface provides methods to extend JPA EDM containers.
- *
- *
- *
- */
-public interface JPAEdmExtension {
-
- /**
- * The method is used to extend the JPA EDM schema view with custom operations. Use this method to
- * register custom operations.
- *
- * @param view
- * is the schema view
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView#registerOperations(Class, String[])
- *
- */
- public void extendWithOperation(JPAEdmSchemaView view);
-
- /**
- * The method is used to extend the JPA EDM schema view with Entities, Entity Sets, Navigation Property and
- * Association.
- *
- * @param view
- * is the schema view
- *
- */
- public void extendJPAEdmSchema(JPAEdmSchemaView view);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmFunctionImportView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmFunctionImportView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmFunctionImportView.java
deleted file mode 100644
index be19742..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmFunctionImportView.java
+++ /dev/null
@@ -1,51 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-
-/**
- * <p>
- * A view on EDM Function Imports. EDM function imports are derived from Java
- * class methods annotated with EDM Annotations.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM Function Import created
- * from Java class methods. The implementation act as a container for list of
- * function imports that are consistent.
- * </p>
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- *
- */
-public interface JPAEdmFunctionImportView extends JPAEdmBaseView {
-
- /**
- * The method returns a list of consistent Function Imports. A function
- * import is said to be consistent only if it adheres to the rules defined
- * in CSDL.
- *
- * @return a list of type {@link org.apache.olingo.odata2.api.edm.provider.FunctionImport}
- */
- List<FunctionImport> getConsistentFunctionImportList();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmKeyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmKeyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmKeyView.java
deleted file mode 100644
index a684126..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmKeyView.java
+++ /dev/null
@@ -1,51 +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.odata2.processor.api.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.Key;
-
-/**
- * A view on Java Persistence Entity Key Attributes and EDM Key properties. Java
- * Persistence Key Attributes of type
- * <ol>
- * <li>embedded ID</li>
- * <li>ID</li>
- * </ol>
- * are converted into EDM keys. Embedded IDs are expanded into simple EDM
- * properties.
- * <p>
- * The implementation of the view provides access to EDM key properties for a
- * given JPA EDM entity type. The view acts as a container for consistent EDM
- * key property of an EDM entity type.
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView
- *
- */
-public interface JPAEdmKeyView extends JPAEdmBaseView {
- /**
- * The method returns an instance of EDM key for the given JPA EDM Entity
- * type.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.Key}
- */
- public Key getEdmKey();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmMapping.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmMapping.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmMapping.java
deleted file mode 100644
index 4c44083..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmMapping.java
+++ /dev/null
@@ -1,63 +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.odata2.processor.api.jpa.model;
-
-/**
- * The interface acts a container for storing Java persistence column name. The
- * JPA EDM mapping instance can be associated with any EDM simple, EDM complex
- * property to denote the properties Java persistence column name.
- *
- *
- *
- */
-public interface JPAEdmMapping {
- /**
- * The method sets the Java persistence column name into the mapping
- * container.
- *
- * @param name
- * is the Java persistence column name
- */
- public void setJPAColumnName(String name);
-
- /**
- * The method gets the Java persistence column name from the mapping
- * container.
- *
- * @return a String representing the Java persistence column name set into
- * the container
- */
- public String getJPAColumnName();
-
- /**
- * The method sets the Java persistence entity/property type.
- *
- * @param type
- * is an instance of type Class<?>
- */
- public void setJPAType(Class<?> type);
-
- /**
- * The method returns the Java persistence entity/property type.
- *
- * @return type
- */
- public Class<?> getJPAType();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmModelView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmModelView.java
deleted file mode 100644
index 4c9a777..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmModelView.java
+++ /dev/null
@@ -1,43 +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.odata2.processor.api.jpa.model;
-
-/**
- * A view on JPA meta model and EDM meta model. The view acts as the base for
- * the construction of EDM meta model from a JPA meta model.
- * <p>
- * The implementation of the view acts as the container for JPA meta model and
- * EDM meta model. The instance of JPA EDM meta model can be created using
- * {@link org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory}. The
- * instance thus obtained can be used for constructing other elements of the
- * meta model using {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder}.
- *
- *
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory
- */
-public interface JPAEdmModelView extends JPAEdmBaseView {
- /**
- * The method returns a consistent JPA EDM schema view created from the JPA
- * meta model.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView}
- */
- public JPAEdmSchemaView getEdmSchemaView();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmNavigationPropertyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmNavigationPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmNavigationPropertyView.java
deleted file mode 100644
index e1b0d3d..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmNavigationPropertyView.java
+++ /dev/null
@@ -1,72 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-
-/**
- * A view on Java persistence entity relationship and EDM navigation property.
- * Java persistence entity relationships annotated as
- * <ol>
- * <li>Many To Many</li>
- * <li>One To Many</li>
- * <li>One To One</li>
- * <li>Many To One</li>
- * </ol>
- * are transformed into navigation properties.
- * <p>
- * The implementation of the view provides access to EDM navigation properties
- * for a given JPA EDM entity type. The view acts as a container for consistent
- * list of EDM navigation properties of an EDM entity type. EDM navigation
- * property is consistent only if there exists a consistent EDM association.
- *
- *
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView
- *
- */
-public interface JPAEdmNavigationPropertyView extends JPAEdmBaseView {
- /**
- * The method adds a navigation property view to its container.
- *
- * @param view
- * is an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView}
- */
- void addJPAEdmNavigationPropertyView(JPAEdmNavigationPropertyView view);
-
- /**
- * The method returns a consistent list of EDM navigation property. A
- * navigation property is consistent only if all its mandatory properties
- * can be built with no errors from Java persistence entity relationship.
- *
- * @return a list of consistent EDM navigation property for the Entity
- */
- List<NavigationProperty> getConsistentEdmNavigationProperties();
-
- /**
- * The method returns the navigation property that is currently being
- * processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.NavigationProperty}
- */
- NavigationProperty getEdmNavigationProperty();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmPropertyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmPropertyView.java
deleted file mode 100644
index 742d5c8..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmPropertyView.java
+++ /dev/null
@@ -1,104 +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.odata2.processor.api.jpa.model;
-
-import java.util.List;
-
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-
-/**
- * A view on Java Persistence Entity Attributes and EDM properties. Java
- * Persistence Attributes of type
- * <ol>
- * <li>embedded ID - are converted into EDM keys</li>
- * <li>ID - are converted into EDM keys</li>
- * <li>attributes - are converted into EDM properties</li>
- * <li>embeddable type - are converted into EDM complex properties</li>
- * <li>relationships - are converted into Associations/Navigation properties</li>
- * </ol>
- * <p>
- * The implementation of the view provides access to EDM properties for a given
- * JPA EDM entity type. The view acts as a container for consistent list of EDM
- * properties of an EDM entity type. EDM property is consistent only if there
- * exists at least one property in the entity type and there is at least one key
- * property.
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView
- *
- */
-public interface JPAEdmPropertyView extends JPAEdmBaseView {
- /**
- * The method returns a simple EDM property.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.SimpleProperty}
- */
- SimpleProperty getEdmSimpleProperty();
-
- /**
- * The method returns a JPA EDM key view.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView}
- */
- JPAEdmKeyView getJPAEdmKeyView();
-
- /**
- * The method returns a list of Properties for the given Entity Type.
- *
- * @return a list of {@link org.apache.olingo.odata2.api.edm.provider.Property}
- */
- List<Property> getEdmPropertyList();
-
- /**
- * The method returns a JPA Attribute for the given JPA entity type.
- *
- * @return an instance of type {@link javax.persistence.metamodel.Attribute
- * <?, ?>}
- */
- Attribute<?, ?> getJPAAttribute();
-
- /**
- * The method returns a JPA EDM navigation property view.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView}
- */
- JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView();
-
- /**
- * The method returns a JPA EDM Entity Type view that holds the property
- * view.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView}
- */
- JPAEdmEntityTypeView getJPAEdmEntityTypeView();
-
- /**
- * The method returns a JPA EDM Complex Type view that holds the property
- * view.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}
- */
- JPAEdmComplexTypeView getJPAEdmComplexTypeView();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintRoleView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintRoleView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintRoleView.java
deleted file mode 100644
index ebf945c..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintRoleView.java
+++ /dev/null
@@ -1,101 +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.odata2.processor.api.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole;
-
-/**
- * <p>
- * A view on Java Persistence Entity Join Column's "name" and
- * "referenced column name" attributes and Entity Data Model Referential
- * Constraint's dependent and principal roles respectively. Each java
- * persistence entity with properties annotated with Join Columns are
- * transformed into Referential constraints and Referential constraint roles.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM referential constraint
- * roles created from Java Persistence Entity Join Columns. The implementation
- * acts as a container for EDM referential constraint roles. A referential
- * constraint role is consistent only if the principal role and dependent roles
- * can be created from JPA Entity relationships.
- * </p>
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView
- *
- */
-public interface JPAEdmReferentialConstraintRoleView extends JPAEdmBaseView {
- /**
- * Two types of EDM roles of a referential constraint.
- */
- public enum RoleType {
- PRINCIPAL, DEPENDENT
- }
-
- /**
- * The method returns the role type (PRINCIPAL or DEPENDENT)
- *
- * @return a {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView.RoleType}
- */
- RoleType getRoleType();
-
- /**
- * The method returns the Referential constraint role that is currently
- * being processed.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole}
- */
- ReferentialConstraintRole getEdmReferentialConstraintRole();
-
- /**
- * The method returns the name of JPA attribute's column name (annotated
- * with @Column). The returned Column Name acts as the PRINCIPAL entity
- * type.
- *
- * @return name of JPA Column name
- */
- String getJPAColumnName();
-
- /**
- * The method returns the EDM entity type name that holds the
- * relationship/referential constraint. The entity type that acts as a
- * DEPENDENT entity type.
- *
- * @return name of EDM entity type
- */
- String getEdmEntityTypeName();
-
- /**
- * The method returns the EDM association name.
- *
- * @return name of EDM association
- */
- String getEdmAssociationName();
-
- /**
- * The method tells if there exists a valid referential constraint for a
- * given association.
- *
- * @return true - if valid referential constraint exits else false
- */
- boolean isExists();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintView.java
deleted file mode 100644
index 4b90edb..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmReferentialConstraintView.java
+++ /dev/null
@@ -1,69 +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.odata2.processor.api.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
-
-/**
- * <p>
- * A view on Java Persistence Entity Join Columns and Entity Data Model
- * Referential Constraint. Each java persistence entity with properties
- * annotated with Join Columns are transformed into Referential constraints.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM referential constraint
- * created from Java Persistence Entity Join Columns. The implementation acts as
- * a container for EDM referential constraint. A referential constraint is said
- * to be consistent only if referential constraint role is consistent.
- * </p>
- *
- * <br>
- * @org.apache.olingo.odata2.DoNotImplement
- * <br>
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView
- *
- */
-public interface JPAEdmReferentialConstraintView extends JPAEdmBaseView {
-
- /**
- * The method returns EDM referential constraint created from Java
- * persistence Entity Join Columns.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint}
- */
- public ReferentialConstraint getEdmReferentialConstraint();
-
- /**
- * The method returns if a valid referential constraint exists for a given
- * EDM association. If there exists a JPA entity relationship with join
- * column having a valid "Name" and "ReferenceColumnName", that can be
- * mapped to EDM properties in dependent and source EDM entities
- * respectively then a valid EDM referential constraint exists.
- *
- * @return true if there exists a valid referential constraint else false.
- */
- public boolean isExists();
-
- /**
- * The method returns the name of EDM Association.
- *
- * @return name of an EDM association
- */
- public String getEdmRelationShipName();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
deleted file mode 100644
index 0400271..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
+++ /dev/null
@@ -1,111 +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.odata2.processor.api.jpa.model;
-
-import java.util.HashMap;
-
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-
-/**
- * <p>
- * A view on Java Persistence Model and Entity Data Model Schema. Each java
- * persistence unit corresponds to a one EDM schema.
- * </p>
- * <p>
- * The implementation of the view provides access to EDM schema created from
- * Java Persistence unit. The implementation acts as a container for schema. The
- * schema is consistent only if following elements are consistent
- * <ol>
- * <li>{@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView}</li>
- * <li>{@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}</li>
- * </ol>
- * </p>
- *
- *
- * <p>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView
- * @see org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView
- *
- */
-public interface JPAEdmSchemaView extends JPAEdmBaseView {
- /**
- * The method returns the EDM schema present in the container.
- *
- * @return an instance EDM schema of type {@link org.apache.olingo.odata2.api.edm.provider.Schema}
- */
- public Schema getEdmSchema();
-
- /**
- * The method returns JPA EDM container view. The JPA EDM container view can
- * be used to access EDM Entity Container elements.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView}
- */
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView();
-
- /**
- * The method returns JPA EDM complex view. The JPA EDM complex view can be
- * used to access EDM complex types and JPA Embeddable Types.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}
- */
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView();
-
- /**
- * The method returns JPA EDM association view. The JPA EDM association view
- * can be used to access EDM associations and JPA Relationships.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}
- */
- public JPAEdmAssociationView getJPAEdmAssociationView();
-
- /**
- * The method registers custom operations that shall be represented as Edm
- * Function Imports. Custom operations are created using Edm Annotation
- * {@link org.apache.olingo.odata2.api.annotation.edm.FunctionImport}.
- * <p>
- * Custom Operations can be part of JPA Entity or can be created in a class
- * other than JPA Entity. Such custom operations can be registered using
- * this method.
- * <p>
- * The method is a callback.
- *
- * @param customClass
- * is the class that contains custom operations
- * @param methodNames
- * is the name of the method that needs to be transformed into
- * Function Imports. It is an optional parameter. If null is
- * passed then all annotated methods are transformed into
- * Function Imports.
- *
- */
- public void registerOperations(Class<?> customClass, String methodNames[]);
-
- /**
- * The method returns an Hash Map containing the registered custom
- * operations.
- *
- * @return a HashMap of Class and the methods in the class
- */
- public HashMap<Class<?>, String[]> getRegisteredOperations();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAAttributeMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAAttributeMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAAttributeMapType.java
deleted file mode 100644
index 7c9278f..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAAttributeMapType.java
+++ /dev/null
@@ -1,202 +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.odata2.processor.api.jpa.model.mapping;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.XmlValue;
-
-/**
- *
- * The default name for EDM
- * property is derived from JPA attribute name. This can be overriden
- * using
- * JPAAttributeMapType.
- *
- *
- * <p>Java class for JPAAttributeMapType complex type.
- *
- * <p>The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * <complexType name="JPAAttributeMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="JPAAttribute" maxOccurs="unbounded" minOccurs="0">
- * <complexType>
- * <simpleContent>
- * <extension base="<http://www.w3.org/2001/XMLSchema>string">
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
- * </extension>
- * </simpleContent>
- * </complexType>
- * </element>
- * </sequence>
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPAAttributeMapType", propOrder = { "jpaAttribute" })
-public class JPAAttributeMapType {
-
- @XmlElement(name = "JPAAttribute")
- protected List<JPAAttributeMapType.JPAAttribute> jpaAttribute;
-
- /**
- * Gets the value of the jpaAttribute property.
- *
- * <p>
- * This accessor method returns a reference to the live list,
- * not a snapshot. Therefore any modification you make to the
- * returned list will be present inside the JAXB object.
- * This is why there is not a <CODE>set</CODE> method for the jpaAttribute property.
- *
- * <p>
- * For example, to add a new item, do as follows:
- * <pre>
- * getJPAAttribute().add(newItem);
- * </pre>
- *
- *
- * <p>
- * Objects of the following type(s) are allowed in the list {@link JPAAttributeMapType.JPAAttribute }
- *
- *
- */
- public List<JPAAttributeMapType.JPAAttribute> getJPAAttribute() {
- if (jpaAttribute == null) {
- jpaAttribute = new ArrayList<JPAAttributeMapType.JPAAttribute>();
- }
- return jpaAttribute;
- }
-
- /**
- * <p>Java class for anonymous complex type.
- *
- * <p>The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * <complexType>
- * <simpleContent>
- * <extension base="<http://www.w3.org/2001/XMLSchema>string">
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
- * </extension>
- * </simpleContent>
- * </complexType>
- * </pre>
- *
- *
- */
- @XmlAccessorType(XmlAccessType.FIELD)
- @XmlType(name = "", propOrder = { "value" })
- public static class JPAAttribute {
-
- @XmlValue
- protected String value;
- @XmlAttribute(name = "name", required = true)
- protected String name;
- @XmlAttribute(name = "exclude")
- protected Boolean exclude;
-
- /**
- * Gets the value of the value property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Sets the value of the value property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setValue(final String value) {
- this.value = value;
- }
-
- /**
- * Gets the value of the name property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the value of the name property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setName(final String value) {
- name = value;
- }
-
- /**
- * Gets the value of the exclude property.
- *
- * @return
- * possible object is {@link Boolean }
- *
- */
- public boolean isExclude() {
- if (exclude == null) {
- return false;
- } else {
- return exclude;
- }
- }
-
- /**
- * Sets the value of the exclude property.
- *
- * @param value
- * allowed object is {@link Boolean }
- *
- */
- public void setExclude(final Boolean value) {
- exclude = value;
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModel.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModel.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModel.java
deleted file mode 100644
index a91f12a..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModel.java
+++ /dev/null
@@ -1,79 +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.odata2.processor.api.jpa.model.mapping;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- * <p>
- * Java class for anonymous complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within
- * this class.
- *
- * <pre>
- * <complexType>
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="PersistenceUnit"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAPersistenceUnitMapType"/>
- * </sequence>
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "", propOrder = { "persistenceUnit" })
-@XmlRootElement(name = "JPAEDMMappingModel")
-public class JPAEdmMappingModel {
-
- @XmlElement(name = "PersistenceUnit", required = true)
- protected JPAPersistenceUnitMapType persistenceUnit;
-
- /**
- * Gets the value of the persistenceUnit property.
- *
- * @return possible object is {@link JPAPersistenceUnitMapType }
- *
- */
- public JPAPersistenceUnitMapType getPersistenceUnit() {
- return persistenceUnit;
- }
-
- /**
- * Sets the value of the persistenceUnit property.
- *
- * @param value
- * allowed object is {@link JPAPersistenceUnitMapType }
- *
- */
- public void setPersistenceUnit(final JPAPersistenceUnitMapType value) {
- persistenceUnit = value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModelFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModelFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModelFactory.java
deleted file mode 100644
index f0e9787..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEdmMappingModelFactory.java
+++ /dev/null
@@ -1,85 +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.odata2.processor.api.jpa.model.mapping;
-
-import javax.xml.bind.annotation.XmlRegistry;
-
-/**
- * This object contains factory methods for each Java content interface and Java
- * element interface generated in the
- * org.apache.olingo.odata2.processor.api.jpa.model.mapping package.
- * <p>
- * An ObjectFactory allows you to programatically construct new instances of the
- * Java representation for XML content. The Java representation of XML content
- * can consist of schema derived interfaces and classes representing the binding
- * of schema type definitions, element declarations and model groups. Factory
- * methods for each of these are provided in this class.
- *
- */
-@XmlRegistry
-public class JPAEdmMappingModelFactory {
-
- /**
- * Create a new ObjectFactory that can be used to create new instances of
- * schema derived classes for package:
- * org.apache.olingo.odata2.processor.api.jpa.model.mapping
- *
- */
- public JPAEdmMappingModelFactory() {}
-
- /**
- * Create an instance of {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPARelationshipMapType }
- *
- */
- public JPARelationshipMapType createJPARelationshipMapType() {
- return new JPARelationshipMapType();
- }
-
- /**
- * Create an instance of {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAAttributeMapType }
- *
- */
- public JPAAttributeMapType createJPAAttributeMapType() {
- return new JPAAttributeMapType();
- }
-
- /**
- * Create an instance of {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEdmMappingModel }
- *
- */
- public JPAEdmMappingModel createJPAEDMMappingModel() {
- return new JPAEdmMappingModel();
- }
-
- /**
- * Create an instance of {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAPersistenceUnitMapType }
- *
- */
- public JPAPersistenceUnitMapType createJPAPersistenceUnitMapType() {
- return new JPAPersistenceUnitMapType();
- }
-
- /**
- * Create an instance of {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEmbeddableTypeMapType }
- *
- */
- public JPAEmbeddableTypeMapType createJPAEmbeddableTypeMapType() {
- return new JPAEmbeddableTypeMapType();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypeMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypeMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypeMapType.java
deleted file mode 100644
index f462a96..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypeMapType.java
+++ /dev/null
@@ -1,161 +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.odata2.processor.api.jpa.model.mapping;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- *
- * The default name for EDM
- * complex type is derived from JPA Embeddable type name. This can be
- * overriden using JPAEmbeddableTypeMapType.
- *
- *
- * <p>Java class for JPAEmbeddableTypeMapType complex type.
- *
- * <p>The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * <complexType name="JPAEmbeddableTypeMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="EDMComplexType" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- * <element name="JPAAttributes"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAAttributeMapType"/>
- * </sequence>
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPAEmbeddableTypeMapType", propOrder = { "edmComplexType", "jpaAttributes" })
-public class JPAEmbeddableTypeMapType {
-
- @XmlElement(name = "EDMComplexType")
- protected String edmComplexType;
- @XmlElement(name = "JPAAttributes", required = true)
- protected JPAAttributeMapType jpaAttributes;
- @XmlAttribute(name = "name", required = true)
- protected String name;
- @XmlAttribute(name = "exclude")
- protected Boolean exclude;
-
- /**
- * Gets the value of the edmComplexType property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getEDMComplexType() {
- return edmComplexType;
- }
-
- /**
- * Sets the value of the edmComplexType property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setEDMComplexType(final String value) {
- edmComplexType = value;
- }
-
- /**
- * Gets the value of the jpaAttributes property.
- *
- * @return
- * possible object is {@link JPAAttributeMapType }
- *
- */
- public JPAAttributeMapType getJPAAttributes() {
- return jpaAttributes;
- }
-
- /**
- * Sets the value of the jpaAttributes property.
- *
- * @param value
- * allowed object is {@link JPAAttributeMapType }
- *
- */
- public void setJPAAttributes(final JPAAttributeMapType value) {
- jpaAttributes = value;
- }
-
- /**
- * Gets the value of the name property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the value of the name property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setName(final String value) {
- name = value;
- }
-
- /**
- * Gets the value of the exclude property.
- *
- * @return
- * possible object is {@link Boolean }
- *
- */
- public boolean isExclude() {
- if (exclude == null) {
- return false;
- } else {
- return exclude;
- }
- }
-
- /**
- * Sets the value of the exclude property.
- *
- * @param value
- * allowed object is {@link Boolean }
- *
- */
- public void setExclude(final Boolean value) {
- exclude = value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypesMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypesMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypesMapType.java
deleted file mode 100644
index 131e738..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEmbeddableTypesMapType.java
+++ /dev/null
@@ -1,89 +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.odata2.processor.api.jpa.model.mapping;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- * <p>
- * Java class for JPAEmbeddableTypesMapType complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within
- * this class.
- *
- * <pre>
- * <complexType name="JPAEmbeddableTypesMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="JPAEmbeddableType"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAEmbeddableTypeMapType"
- * maxOccurs="unbounded" minOccurs="0"/>
- * </sequence>
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPAEmbeddableTypesMapType", propOrder = { "jpaEmbeddableType" })
-public class JPAEmbeddableTypesMapType {
-
- @XmlElement(name = "JPAEmbeddableType")
- protected List<JPAEmbeddableTypeMapType> jpaEmbeddableType;
-
- /**
- * Gets the value of the jpaEmbeddableType property.
- *
- * <p>
- * This accessor method returns a reference to the live list, not a
- * snapshot. Therefore any modification you make to the returned list will
- * be present inside the JAXB object. This is why there is not a
- * <CODE>set</CODE> method for the jpaEmbeddableType property.
- *
- * <p>
- * For example, to add a new item, do as follows:
- *
- * <pre>
- * getJPAEmbeddableType().add(newItem);
- * </pre>
- *
- *
- * <p>
- * Objects of the following type(s) are allowed in the list {@link JPAEmbeddableTypeMapType }
- *
- *
- */
- public List<JPAEmbeddableTypeMapType> getJPAEmbeddableType() {
- if (jpaEmbeddableType == null) {
- jpaEmbeddableType = new ArrayList<JPAEmbeddableTypeMapType>();
- }
- return jpaEmbeddableType;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypeMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypeMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypeMapType.java
deleted file mode 100644
index 2f4526c..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypeMapType.java
+++ /dev/null
@@ -1,213 +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.odata2.processor.api.jpa.model.mapping;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- *
- * The default name for EDM
- * entity type is derived from JPA entity type name. This can be
- * overriden using JPAEntityTypeMapType.
- *
- *
- * <p>Java class for JPAEntityTypeMapType complex type.
- *
- * <p>The following schema fragment specifies the expected content contained within this class.
- *
- * <pre>
- * <complexType name="JPAEntityTypeMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="EDMEntityType" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- * <element name="EDMEntitySet" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- * <element name="JPAAttributes"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAAttributeMapType"/>
- * <element name="JPARelationships"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPARelationshipMapType"/>
- * </sequence>
- * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
- * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPAEntityTypeMapType", propOrder = { "edmEntityType", "edmEntitySet", "jpaAttributes",
- "jpaRelationships" })
-public class JPAEntityTypeMapType {
-
- @XmlElement(name = "EDMEntityType")
- protected String edmEntityType;
- @XmlElement(name = "EDMEntitySet")
- protected String edmEntitySet;
- @XmlElement(name = "JPAAttributes", required = true)
- protected JPAAttributeMapType jpaAttributes;
- @XmlElement(name = "JPARelationships", required = true)
- protected JPARelationshipMapType jpaRelationships;
- @XmlAttribute(name = "name", required = true)
- protected String name;
- @XmlAttribute(name = "exclude")
- protected Boolean exclude;
-
- /**
- * Gets the value of the edmEntityType property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getEDMEntityType() {
- return edmEntityType;
- }
-
- /**
- * Sets the value of the edmEntityType property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setEDMEntityType(final String value) {
- edmEntityType = value;
- }
-
- /**
- * Gets the value of the edmEntitySet property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getEDMEntitySet() {
- return edmEntitySet;
- }
-
- /**
- * Sets the value of the edmEntitySet property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setEDMEntitySet(final String value) {
- edmEntitySet = value;
- }
-
- /**
- * Gets the value of the jpaAttributes property.
- *
- * @return
- * possible object is {@link JPAAttributeMapType }
- *
- */
- public JPAAttributeMapType getJPAAttributes() {
- return jpaAttributes;
- }
-
- /**
- * Sets the value of the jpaAttributes property.
- *
- * @param value
- * allowed object is {@link JPAAttributeMapType }
- *
- */
- public void setJPAAttributes(final JPAAttributeMapType value) {
- jpaAttributes = value;
- }
-
- /**
- * Gets the value of the jpaRelationships property.
- *
- * @return
- * possible object is {@link JPARelationshipMapType }
- *
- */
- public JPARelationshipMapType getJPARelationships() {
- return jpaRelationships;
- }
-
- /**
- * Sets the value of the jpaRelationships property.
- *
- * @param value
- * allowed object is {@link JPARelationshipMapType }
- *
- */
- public void setJPARelationships(final JPARelationshipMapType value) {
- jpaRelationships = value;
- }
-
- /**
- * Gets the value of the name property.
- *
- * @return
- * possible object is {@link String }
- *
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the value of the name property.
- *
- * @param value
- * allowed object is {@link String }
- *
- */
- public void setName(final String value) {
- name = value;
- }
-
- /**
- * Gets the value of the exclude property.
- *
- * @return
- * possible object is {@link Boolean }
- *
- */
- public boolean isExclude() {
- if (exclude == null) {
- return false;
- } else {
- return exclude;
- }
- }
-
- /**
- * Sets the value of the exclude property.
- *
- * @param value
- * allowed object is {@link Boolean }
- *
- */
- public void setExclude(final Boolean value) {
- exclude = value;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypesMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypesMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypesMapType.java
deleted file mode 100644
index cd2a6de..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/mapping/JPAEntityTypesMapType.java
+++ /dev/null
@@ -1,89 +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.odata2.processor.api.jpa.model.mapping;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-
-/**
- * <p>
- * Java class for JPAEntityTypesMapType complex type.
- *
- * <p>
- * The following schema fragment specifies the expected content contained within
- * this class.
- *
- * <pre>
- * <complexType name="JPAEntityTypesMapType">
- * <complexContent>
- * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- * <sequence>
- * <element name="JPAEntityType"
- * type="{http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping}JPAEntityTypeMapType"
- * maxOccurs="unbounded" minOccurs="0"/>
- * </sequence>
- * </restriction>
- * </complexContent>
- * </complexType>
- * </pre>
- *
- *
- */
-@XmlAccessorType(XmlAccessType.FIELD)
-@XmlType(name = "JPAEntityTypesMapType", propOrder = { "jpaEntityType" })
-public class JPAEntityTypesMapType {
-
- @XmlElement(name = "JPAEntityType")
- protected List<JPAEntityTypeMapType> jpaEntityType;
-
- /**
- * Gets the value of the jpaEntityType property.
- *
- * <p>
- * This accessor method returns a reference to the live list, not a
- * snapshot. Therefore any modification you make to the returned list will
- * be present inside the JAXB object. This is why there is not a
- * <CODE>set</CODE> method for the jpaEntityType property.
- *
- * <p>
- * For example, to add a new item, do as follows:
- *
- * <pre>
- * getJPAEntityType().add(newItem);
- * </pre>
- *
- *
- * <p>
- * Objects of the following type(s) are allowed in the list {@link JPAEntityTypeMapType }
- *
- *
- */
- public List<JPAEntityTypeMapType> getJPAEntityType() {
- if (jpaEntityType == null) {
- jpaEntityType = new ArrayList<JPAEntityTypeMapType>();
- }
- return jpaEntityType;
- }
-
-}
[44/47] [OLINGO-83] Renamed test packages
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
new file mode 100644
index 0000000..8e5e794
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Team.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+*
+*/
+@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Teams")
+public class Team extends RefBase {
+ @EdmProperty(type = EdmType.BOOLEAN)
+ private Boolean isScrumTeam;
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Team() {
+ super(-1, null);
+ }
+
+ public Team(final int id, final String name) {
+ super(id, name);
+ }
+
+ public Boolean isScrumTeam() {
+ return isScrumTeam;
+ }
+
+ public void setScrumTeam(final Boolean isScrumTeam) {
+ this.isScrumTeam = isScrumTeam;
+ }
+
+ public void addEmployee(final Employee e) {
+ employees.add(e);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
deleted file mode 100644
index 5059327..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ /dev/null
@@ -1,628 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.data;
-
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationInMemoryDs;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataStore;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource.BinaryData;
-import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.core.annotation.model.Building;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.Photo;
-import org.apache.olingo.odata2.core.annotation.model.Room;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-/**
- *
- */
-public class AnnotationsInMemoryDsTest {
-
- private final AnnotationInMemoryDs datasource;
- private final AnnotationEdmProvider edmProvider;
- private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
-
- public AnnotationsInMemoryDsTest() throws ODataException {
- datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
- edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
- }
-
- @Test
- @Ignore
- public void multiThreadedSyncOnBuildingsTest() throws Exception {
- final EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- CountDownLatch latch;
-
- List<Thread> threads = new ArrayList<Thread>();
- int max = 500;
-
- latch = new CountDownLatch(max);
- for (int i = 0; i < max; i++) {
- threads.add(createBuildingThread(latch, datasource, edmEntitySet, String.valueOf("10")));
- }
-
- for (Thread thread : threads) {
- thread.start();
- }
-
- latch.await(60, TimeUnit.SECONDS);
-
- DataStore<Building> ds = datasource.getDataStore(Building.class);
- Collection<Building> buildings = ds.read();
- Assert.assertEquals(max, buildings.size());
- }
-
- @org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet
- @org.apache.olingo.odata2.api.annotation.edm.EdmEntityType
- private static class SimpleEntity {
- @EdmKey
- @EdmProperty
- public Integer id;
- @EdmProperty
- public String name;
- }
-
- @Test
- @Ignore
- public void multiThreadedSyncCreateReadTest() throws Exception {
- Collection<Class<?>> ac = new ArrayList<Class<?>>();
- ac.add(SimpleEntity.class);
- final AnnotationInMemoryDs localDs = new AnnotationInMemoryDs(SimpleEntity.class.getPackage().getName(), true);
- final AnnotationEdmProvider localProvider = new AnnotationEdmProvider(ac);
- final EdmEntitySet edmEntitySet = createMockedEdmEntitySet(localProvider, "SimpleEntitySet");
- final CountDownLatch latch;
-
- List<Thread> threads = new ArrayList<Thread>();
- int max = 500;
- latch = new CountDownLatch(max);
- for (int i = 0; i < max; i++) {
- Runnable run = new Runnable() {
- @Override
- public void run() {
- SimpleEntity se = new SimpleEntity();
- se.id = Integer.valueOf(String.valueOf(System.currentTimeMillis()).substring(8));
- se.name = "Name: " + System.currentTimeMillis();
- try {
- localDs.createData(edmEntitySet, se);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }finally{
- latch.countDown();
- }
- }
- };
-
- threads.add(new Thread(run));
- }
-
- for (Thread thread : threads) {
- thread.start();
- }
-
- latch.await(60, TimeUnit.SECONDS);
-
- DataStore<SimpleEntity> ds = localDs.getDataStore(SimpleEntity.class);
- Collection<SimpleEntity> buildings = ds.read();
- Assert.assertEquals(max, buildings.size());
- }
-
- private Thread createBuildingThread(final CountDownLatch latch, final DataSource datasource,
- final EdmEntitySet edmEntitySet, final String id) {
- Runnable run = new Runnable() {
- @Override
- public void run() {
- Building building = new Building();
- building.setName("Common Building - " + System.currentTimeMillis());
- building.setId(id);
- try {
- datasource.createData(edmEntitySet, building);
- } catch (Exception ex) {
- ex.printStackTrace();
- throw new RuntimeException(ex);
- } finally {
- latch.countDown();
- }
- }
- };
-
- return new Thread(run);
- }
-
- @Test
- public void readBinaryData() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
- Photo photo = new Photo();
- photo.setName("SomePic");
- photo.setType("PNG");
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- photo.setImage(image);
- photo.setImageType("image/png");
- photoDataStore.create(photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Name", "SomePic");
- keys.put("ImageFormat", "PNG");
- Photo toReadPhoto = (Photo) datasource.readData(entitySet, keys);
-
- // execute
- BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
-
- // validate
- Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
- Assert.assertArrayEquals(image, readBinaryData.getData());
- Assert.assertEquals("image/png", readBinaryData.getMimeType());
- }
-
- @Test
- public void readBinaryDataDirect() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
- Photo photo = new Photo();
- photo.setName("SomePic");
- photo.setType("PNG");
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- photo.setImage(image);
- photo.setImageType("image/png");
- photoDataStore.create(photo);
-
- Photo toReadPhoto = new Photo();
- toReadPhoto.setName("SomePic");
- toReadPhoto.setType("PNG");
- toReadPhoto.setImage(null);
- toReadPhoto.setImageType(null);
-
- BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
-
- Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
- Assert.assertArrayEquals(image, readBinaryData.getData());
- Assert.assertEquals("image/png", readBinaryData.getMimeType());
- }
-
-
- @Test
- public void writeBinaryData() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
-
- Photo toWritePhoto = new Photo();
- toWritePhoto.setName("SomePic");
- toWritePhoto.setType("PNG");
- photoDataStore.create(toWritePhoto);
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- String mimeType = "image/png";
- BinaryData writeBinaryData = new BinaryData(image, mimeType);
- // execute
- datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
-
- // validate
- Photo photoKey = new Photo();
- photoKey.setName("SomePic");
- photoKey.setType("PNG");
- Photo storedPhoto = photoDataStore.read(photoKey);
- Assert.assertEquals("binary", new String(storedPhoto.getImage(), Charset.defaultCharset()));
- Assert.assertArrayEquals(image, storedPhoto.getImage());
- Assert.assertEquals("image/png", storedPhoto.getImageType());
- }
-
- @Test(expected=ODataNotFoundException.class)
- public void writeBinaryDataNotFound() throws Exception {
- EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
-
- Photo toWritePhoto = new Photo();
- toWritePhoto.setName("SomePic");
- toWritePhoto.setType("PNG");
- byte[] image = "binary".getBytes(Charset.defaultCharset());
- String mimeType = "image/png";
- BinaryData writeBinaryData = new BinaryData(image, mimeType);
- // execute
- datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
- }
-
-
- @Test
- public void newDataObject() throws Exception {
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
- Room room = (Room) datasource.newDataObject(roomsEntitySet);
-
- Assert.assertNotNull(room);
- }
-
- @Test
- public void readEntity() throws Exception {
- EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 3;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- building.getRooms().addAll(rooms);
- datasource.createData(buildingsEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- // execute
- Object relatedData = datasource.readData(buildingsEntitySet, keys);
-
- // validate
- Building readBuilding = (Building) relatedData;
- Assert.assertEquals("Common Building", readBuilding.getName());
- Assert.assertEquals("1", readBuilding.getId());
-
- Collection<Room> relatedRooms = readBuilding.getRooms();
- Assert.assertEquals(roomsCount, relatedRooms.size());
- for (Room room : relatedRooms) {
- Assert.assertNotNull(room.getId());
- Assert.assertTrue(room.getName().matches("Room \\d*"));
- Assert.assertEquals("Common Building", room.getBuilding().getName());
- }
- }
-
- @Test
- public void readEntities() throws Exception {
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 11;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- // execute
- Object relatedData = datasource.readData(roomsEntitySet);
-
- // validate
- @SuppressWarnings("unchecked")
- Collection<Room> relatedRooms = (Collection<Room>) relatedData;
- Assert.assertEquals(roomsCount, relatedRooms.size());
- for (Room room : relatedRooms) {
- Assert.assertNotNull(room.getId());
- Assert.assertTrue(room.getName().matches("Room \\d*"));
- Assert.assertEquals("Common Building", room.getBuilding().getName());
- }
- }
-
-
- @Test
- @SuppressWarnings("unchecked")
- public void readRelatedEntities() throws Exception {
- EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 10;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- building.getRooms().addAll(rooms);
- datasource.createData(buildingsEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(buildingsEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
-
- // execute
- Object relatedData = datasource.readRelatedData(
- buildingsEntitySet, building, roomsEntitySet, Collections.EMPTY_MAP);
-
- // validate
- Assert.assertTrue("Result is no collection.", relatedData instanceof Collection);
- Collection<Room> relatedRooms = (Collection<Room>) relatedData;
- Assert.assertEquals(roomsCount, relatedRooms.size());
- for (Room room : relatedRooms) {
- Assert.assertNotNull(room.getId());
- Assert.assertTrue(room.getName().matches("Room \\d*"));
- Assert.assertEquals("Common Building", room.getBuilding().getName());
- }
- }
-
- @Test
- public void readRelatedTargetEntity() throws Exception {
- EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
- EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
-
- Building building = new Building();
- building.setName("Common Building");
-
- final int roomsCount = 10;
- List<Room> rooms = new ArrayList<Room>();
- for (int i = 0; i < roomsCount; i++) {
- Room room = new Room(i, "Room " + i);
- room.setBuilding(building);
- datasource.createData(roomsEntitySet, room);
- rooms.add(room);
- }
-
- building.getRooms().addAll(rooms);
- datasource.createData(buildingsEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(buildingsEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
-
- // execute
- Map<String, Object> targetKeys = new HashMap<String, Object>();
- targetKeys.put("Id", 3);
- Object relatedData = datasource.readRelatedData(
- buildingsEntitySet, building, roomsEntitySet, targetKeys);
-
- // validate
- Assert.assertTrue("Result is no Room.", relatedData instanceof Room);
- Room relatedRoom = (Room) relatedData;
- Assert.assertEquals("3", relatedRoom.getId());
- Assert.assertEquals("Room 3", relatedRoom.getName());
- Assert.assertEquals("Common Building", relatedRoom.getBuilding().getName());
- }
-
- @Test
- public void createSimpleEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
-
- Building building = new Building();
- building.setName("Common Building");
- datasource.createData(edmEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
- }
-
- @Test
- public void createSimpleEntityWithOwnKey() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
-
- Building building = new Building();
- building.setName("Common Building");
- AnnotationHelper ah = new AnnotationHelper();
- ah.setValueForProperty(building, "Id", "42");
- datasource.createData(edmEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "42");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("42", read.getId());
- }
-
- @Test
- public void createSimpleEntityWithDuplicateKey() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- AnnotationHelper ah = new AnnotationHelper();
-
- Building building = new Building();
- building.setName("Common Building");
- ah.setValueForProperty(building, "Id", "42");
- datasource.createData(edmEntitySet, building);
- //
- Building buildingDuplicate = new Building();
- buildingDuplicate.setName("Duplicate Building");
- ah.setValueForProperty(buildingDuplicate, "Id", "42");
- datasource.createData(edmEntitySet, buildingDuplicate);
-
- Map<String, Object> keys42 = new HashMap<String, Object>();
- keys42.put("Id", "42");
- Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
- Assert.assertEquals("Common Building", read42.getName());
- Assert.assertEquals("42", read42.getId());
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Duplicate Building", read.getName());
- Assert.assertEquals("1", read.getId());
- }
-
- @Test
- public void createEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
-
- Photo photo = new Photo();
- photo.setName("BigPicture");
- photo.setType("PNG");
- photo.setImageUri("https://localhost/image.png");
- photo.setImageType("image/png");
- datasource.createData(edmEntitySet, photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("ImageFormat", "PNG");
- keys.put("Name", "BigPicture");
-
- Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("PNG", read.getType());
- Assert.assertEquals("image/png", read.getImageType());
- Assert.assertEquals("https://localhost/image.png", read.getImageUri());
- }
-
- @Test
- public void createAndUpdateEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
-
- Photo photo = new Photo();
- final String nameKeyValue = "BigPicture";
- final String typeKeyValue = "PNG";
- photo.setName(nameKeyValue);
- photo.setType(typeKeyValue);
- photo.setImageUri("https://localhost/image.png");
- photo.setImageType("image/png");
- datasource.createData(edmEntitySet, photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Name", "BigPicture");
- keys.put("ImageFormat", "PNG");
-
- Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("PNG", read.getType());
- Assert.assertEquals("image/png", read.getImageType());
- Assert.assertEquals("https://localhost/image.png", read.getImageUri());
-
- // update
- Photo updatedPhoto = new Photo();
- updatedPhoto.setName(nameKeyValue);
- updatedPhoto.setType(typeKeyValue);
- updatedPhoto.setImageUri("https://localhost/image.jpg");
- updatedPhoto.setImageType("image/jpg");
- datasource.updateData(edmEntitySet, updatedPhoto);
-
- Map<String, Object> updatedKeys = new HashMap<String, Object>();
- updatedKeys.put("Name", nameKeyValue);
- updatedKeys.put("ImageFormat", typeKeyValue);
-
- Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
- Assert.assertEquals("BigPicture", readUpdated.getName());
- Assert.assertEquals("PNG", readUpdated.getType());
- Assert.assertEquals("image/jpg", readUpdated.getImageType());
- Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
- }
-
-
- @Test
- public void deleteSimpleEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- DataStore<Building> datastore = datasource.getDataStore(Building.class);
-
- Building building = new Building();
- building.setName("Common Building");
- datastore.create(building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
-
- //
- datasource.deleteData(edmEntitySet, keys);
-
- // validate
- try {
- Building readAfterDelete = (Building) datasource.readData(edmEntitySet, keys);
- Assert.fail("Expected " + ODataNotFoundException.class + "was not thrown for '" + readAfterDelete + "'.");
- } catch (ODataNotFoundException e) { }
- }
-
- @Test(expected=ODataRuntimeException.class)
- public void unknownEntitySetForEntity() throws Exception {
- String entitySetName = "Unknown";
- FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
- //
- datasource.readData(edmEntitySet, keys);
- }
-
- @Test(expected=ODataRuntimeException.class)
- public void unknownEntitySetForEntities() throws Exception {
- String entitySetName = "Unknown";
- FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- //
- datasource.readData(edmEntitySet);
- }
-
-
- private EdmEntitySet createMockedEdmEntitySet(final String entitySetName) throws ODataException {
- return createMockedEdmEntitySet(edmProvider, entitySetName);
- }
-
- private EdmEntitySet createMockedEdmEntitySet(AnnotationEdmProvider edmProvider, final String entitySetName)
- throws ODataException {
- EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
- FullQualifiedName entityType = entitySet.getEntityType();
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- return edmEntitySet;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
deleted file mode 100644
index 2f9a1e7..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ /dev/null
@@ -1,462 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.annotation.model.Building;
-import org.apache.olingo.odata2.core.annotation.model.City;
-import org.apache.olingo.odata2.core.annotation.model.Employee;
-import org.apache.olingo.odata2.core.annotation.model.Location;
-import org.apache.olingo.odata2.core.annotation.model.Manager;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.Photo;
-import org.apache.olingo.odata2.core.annotation.model.RefBase;
-import org.apache.olingo.odata2.core.annotation.model.Room;
-import org.apache.olingo.odata2.core.annotation.model.Team;
-import org.junit.Test;
-
-/**
- *
- */
-public class AnnotationEdmProviderTest {
-
- @EdmEntityType
- @EdmEntitySet
- private static final class GeneratedNamesTestClass {}
-
- @EdmComplexType
- private static final class GeneratedNamesComplexTestClass {}
-
- @EdmEntityType(namespace = "MyTestNamespace")
- @EdmEntitySet(container = "MyTestContainer")
- private static final class DefinedNamesTestClass {}
-
- private final AnnotationEdmProvider aep;
- private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
-
- public AnnotationEdmProviderTest() {
- annotatedClasses.add(RefBase.class);
- annotatedClasses.add(Building.class);
- annotatedClasses.add(City.class);
- annotatedClasses.add(Employee.class);
- annotatedClasses.add(Location.class);
- annotatedClasses.add(Manager.class);
- annotatedClasses.add(Photo.class);
- annotatedClasses.add(Room.class);
- annotatedClasses.add(Team.class);
-
- aep = new AnnotationEdmProvider(annotatedClasses);
- }
-
- @Test
- public void defaultNamespaceGeneration() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(GeneratedNamesTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- EntityType testType = localAep.getEntityType(new FullQualifiedName(
- GeneratedNamesTestClass.class.getPackage().getName(),
- GeneratedNamesTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testType);
- assertEquals("GeneratedNamesTestClass", testType.getName());
- assertNull("This should not have a base type", testType.getBaseType());
- }
-
- @Test
- public void defaultNamespaceGenerationComplexType() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- ComplexType testType = localAep.getComplexType(new FullQualifiedName(
- GeneratedNamesComplexTestClass.class.getPackage().getName(),
- GeneratedNamesComplexTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testType);
- assertEquals("GeneratedNamesComplexTestClass", testType.getName());
- assertNull("This should not have a base type", testType.getBaseType());
- }
-
- @Test
- public void defaultContainerNameGeneration() throws ODataException {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- AnnotationEdmProvider localAep =
- new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
-
- EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
- assertNotNull(containerInfo);
- assertEquals("DefaultContainer", containerInfo.getName());
- }
-
- @Test
- public void defaultNamespaceDefined() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(DefinedNamesTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
- DefinedNamesTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testClass);
- assertEquals("DefinedNamesTestClass", testClass.getName());
- assertNull("This should not have a base type", testClass.getBaseType());
- }
-
- @Test
- public void defaultContainerNameDefined() throws ODataException {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
-
- EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
- assertNotNull(containerInfo);
- assertEquals("MyTestContainer", containerInfo.getName());
- }
-
- @Test
- public void loadAnnotatedClassesFromPackage() throws Exception {
- AnnotationEdmProvider localAep = new AnnotationEdmProvider("org.apache.olingo.odata2.core.annotation.model");
-
- // validate employee
- EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- assertEquals("Employee", employee.getName());
- final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
- assertEquals(1, employeeKeys.size());
- assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(6, employee.getProperties().size());
- assertEquals(3, employee.getNavigationProperties().size());
-
- List<Schema> schemas = localAep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
- assertTrue(info.isDefaultEntityContainer());
- }
-
- @Test
- public void annotationProviderBasic() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
- assertTrue(info.isDefaultEntityContainer());
-
- FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
- assertNull(funImp);
-
- final FullQualifiedName associationFqn = new FullQualifiedName(
- ModelSharedConstants.NAMESPACE_1, "NoAssociation");
- Association noAssociation = aep.getAssociation(associationFqn);
- assertNull(noAssociation);
-
- AssociationSet noAssociationSet = aep.getAssociationSet(
- ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
- assertNull(noAssociationSet);
-
- AssociationSet asBuildingRooms = aep.getAssociationSet(
- ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
- assertNotNull(asBuildingRooms);
- assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
- assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
- assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
- assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
- }
-
- @Test
- public void annotationProviderGetDefaultContainer() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = aep.getEntityContainerInfo(null);
- assertTrue(info.isDefaultEntityContainer());
- assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
- }
-
- @Test
- public void schemaBasic() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
-
- Schema schema = schemas.get(0);
- List<EntityContainer> containers = schema.getEntityContainers();
- assertEquals(1, containers.size());
- EntityContainer container = containers.get(0);
- assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
- final List<EntitySet> entitySets = container.getEntitySets();
- assertEquals(6, entitySets.size());
-
- List<Association> associations = schema.getAssociations();
- assertEquals(4, associations.size());
- for (Association association : associations) {
- assertNotNull(association.getName());
- validateAssociation(association);
- }
- }
-
- private FullQualifiedName defaultFqn(final String name) {
- return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
- }
-
- private void validateAssociation(final Association association) {
- String name = association.getName();
- if (name.equals("r_Employee-r_Room")) {
- validateAssociation(association,
- "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if (name.equals("BuildingRooms")) {
- validateAssociation(association,
- "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
- "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
- } else if (name.equals("ManagerEmployees")) {
- validateAssociation(association,
- "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if (name.equals("TeamEmployees")) {
- validateAssociation(association,
- "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else {
- fail("Got unknown association to validate with name '" + name + "'.");
- }
- }
-
- private void validateAssociation(final Association association,
- final String fromRole, final EdmMultiplicity fromMulti, final FullQualifiedName fromType,
- final String toRole, final EdmMultiplicity toMulti, final FullQualifiedName toType) {
-
- AssociationEnd[] ends = new AssociationEnd[] { association.getEnd1(), association.getEnd2() };
- for (AssociationEnd associationEnd : ends) {
- if (associationEnd.getRole().equals(fromRole)) {
- validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
- } else if (associationEnd.getRole().equals(toRole)) {
- validateAssociationEnd(associationEnd, toRole, toMulti, toType);
- } else {
- fail("Unexpected navigation end '" + associationEnd.getRole()
- + "' for association with name '" + association.getName() + "'.");
- }
- }
- }
-
- private void validateAssociationEnd(final AssociationEnd associationEnd,
- final String role, final EdmMultiplicity multiplicity, final FullQualifiedName type) {
- assertEquals(role, associationEnd.getRole());
- assertEquals(multiplicity, associationEnd.getMultiplicity());
- assertEquals(type, associationEnd.getType());
- }
-
- @Test
- public void entitySetTeams() throws Exception {
- // validate teams
- EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
- assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
- assertEquals("Team", teams.getEntityType().getName());
- }
-
- @Test
- public void entityTypeEmployee() throws Exception {
- // validate employee
- EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- assertEquals("Employee", employee.getName());
- final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
- assertEquals(1, employeeKeys.size());
- assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(6, employee.getProperties().size());
- assertEquals(3, employee.getNavigationProperties().size());
-
- for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
- if (navigationProperty.getName().equals("ne_Manager")) {
- validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
- } else if (navigationProperty.getName().equals("ne_Team")) {
- validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
- } else if (navigationProperty.getName().equals("ne_Room")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
- } else {
- fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
- }
- }
- }
-
- @Test
- public void entityTypeTeam() throws Exception {
- // validate team
- EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
- assertEquals("Team", team.getName());
- assertEquals("Base", team.getBaseType().getName());
- assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
-
- assertEquals(1, team.getProperties().size());
- assertEquals(1, team.getNavigationProperties().size());
- NavigationProperty navigationProperty = team.getNavigationProperties().get(0);
- validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
- }
-
- @Test
- public void entityTypePhotoWithTwoKeyProperties() throws Exception {
- // validate team
- EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
- assertEquals("Photo", photo.getName());
- final List<Property> properties = photo.getProperties();
- assertEquals(5, properties.size());
- assertTrue(containsProperty(properties, "Name"));
- assertTrue(containsProperty(properties, "ImageFormat"));
- assertTrue(containsProperty(properties, "MimeType"));
- assertTrue(containsProperty(properties, "ImageUrl"));
- assertTrue(containsProperty(properties, "Image"));
- assertFalse(photo.isAbstract());
- assertTrue(photo.isHasStream());
-
- Key photoKey = photo.getKey();
- List<PropertyRef> keyReferences = photoKey.getKeys();
- assertEquals(2, keyReferences.size());
- PropertyRef name = getPropertyRef(keyReferences, "Name");
- assertEquals("Name", name.getName());
- PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
- assertEquals("ImageFormat", imageFormat.getName());
-
-// assertEquals(0, photo.getNavigationProperties().size());
- assertNull(photo.getNavigationProperties());
- }
-
- @Test
- public void entityTypeAbstractBaseType() throws Exception {
- // validate employee
- EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
- assertEquals("Base", baseType.getName());
- final List<PropertyRef> keys = baseType.getKey().getKeys();
- assertEquals(1, keys.size());
- assertEquals("Id", keys.get(0).getName());
- assertEquals(2, baseType.getProperties().size());
- assertTrue(baseType.isAbstract());
-
- // validate base for team
- EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
- assertEquals("Team", team.getName());
- assertEquals("Base", team.getBaseType().getName());
- assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
- }
-
- @Test
- public void complexTypeLocation() throws Exception {
- // validate employee
- EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- final List<Property> properties = employee.getProperties();
- Property location = null;
- for (Property property : properties) {
- if (property.getName().equals("Location")) {
- location = property;
- }
- }
- assertNotNull(location);
- assertEquals("Location", location.getName());
-
- // validate location complex type
- ComplexType locationType = aep.getComplexType(
- new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
- assertEquals("c_Location", locationType.getName());
- assertEquals(2, locationType.getProperties().size());
- }
-
- @Test
- public void entityTypeRoomWithNavigation() throws Exception {
- // validate employee
- EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
- assertEquals("Room", room.getName());
- assertEquals("Base", room.getBaseType().getName());
- assertEquals(2, room.getProperties().size());
- final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
- assertEquals(2, navigationProperties.size());
-
- for (NavigationProperty navigationProperty : navigationProperties) {
- if (navigationProperty.getName().equals("nr_Employees")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
- } else if (navigationProperty.getName().equals("nr_Building")) {
- validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
- } else {
- fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
- }
- }
- }
-
- private void validateNavProperty(final NavigationProperty navigationProperty, final String name,
- final String relationship, final String fromRole, final String toRole) {
- if (name != null) {
- assertEquals(name, navigationProperty.getName());
- }
- FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
- assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
- assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
- assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
- }
-
- private void validateNavProperty(final NavigationProperty navigationProperty,
- final String relationship, final String fromRole, final String toRole) {
- validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
- }
-
- private boolean containsProperty(final List<Property> properties, final String propertyName) {
- return getProperty(properties, propertyName) != null;
- }
-
- private Property getProperty(final List<Property> properties, final String name) {
- for (Property property : properties) {
- if (name.equals(property.getName())) {
- return property;
- }
- }
- return null;
- }
-
- private PropertyRef getPropertyRef(final List<PropertyRef> properties, final String name) {
- for (PropertyRef property : properties) {
- if (name.equals(property.getName())) {
- return property;
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
deleted file mode 100644
index 9f9dc00..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ /dev/null
@@ -1,99 +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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Buildings")
-public class Building {
- @EdmKey
- @EdmProperty(type = EdmType.INT32)
- private String id;
- @EdmProperty
- private String name;
- @EdmProperty(name = "Image", type = EdmType.BINARY)
- private byte[] image;
- @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
- association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
- private List<Room> rooms = new ArrayList<Room>();
-
- public Building() {}
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setImage(final byte[] byteArray) {
- image = byteArray;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- } else {
- return image.clone();
- }
- }
-
- public List<Room> getRooms() {
- return rooms;
- }
-
- @Override
- public int hashCode() {
- return id == null ? 0 : id.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
deleted file mode 100644
index a4b48fd..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
+++ /dev/null
@@ -1,61 +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.odata2.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmComplexType(name = "c_City", namespace = ModelSharedConstants.NAMESPACE_1)
-public class City {
-
- @EdmProperty
- private String postalCode;
- @EdmProperty
- private String cityName;
-
- public City(final String postalCode, final String name) {
- this.postalCode = postalCode;
- cityName = name;
- }
-
- public void setPostalCode(final String postalCode) {
- this.postalCode = postalCode;
- }
-
- public String getPostalCode() {
- return postalCode;
- }
-
- public void setCityName(final String cityName) {
- this.cityName = cityName;
- }
-
- public String getCityName() {
- return cityName;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", cityName, postalCode);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
deleted file mode 100644
index 63b8a76..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ /dev/null
@@ -1,187 +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.odata2.core.annotation.model;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Employees")
-public class Employee {
- @EdmKey
- @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
- private String employeeId;
- @EdmProperty(name = "EmployeeName")
- private String employeeName;
- @EdmProperty
- private int age;
- @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
- private Manager manager;
- @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
- private Team team;
- @EdmNavigationProperty(name = "ne_Room")
- private Room room;
- @EdmMediaResourceMimeType
- private String imageType;
- @EdmMediaResourceContent
- private byte[] image;
- @EdmProperty(name = "ImageUrl")
- private String imageUrl;
- @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
- private Calendar entryDate;
- @EdmProperty(name = "Location")
- private Location location;
-
- public Employee(final String employeeId, final String name) {
- this.employeeId = employeeId;
- setEmployeeName(name);
- }
-
- public String getId() {
- return employeeId;
- }
-
- public void setEmployeeName(final String employeeName) {
- this.employeeName = employeeName;
- }
-
- public String getEmployeeName() {
- return employeeName;
- }
-
- public void setAge(final int age) {
- this.age = age;
- }
-
- public int getAge() {
- return age;
- }
-
- public void setManager(final Manager manager) {
- this.manager = manager;
- }
-
- public Manager getManager() {
- return manager;
- }
-
- public void setTeam(final Team team) {
- this.team = team;
- }
-
- public Team getTeam() {
- return team;
- }
-
- public void setRoom(final Room room) {
- this.room = room;
- }
-
- public Room getRoom() {
- return room;
- }
-
- public void setImageUri(final String imageUri) {
- imageUrl = imageUri;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setLocation(final Location location) {
- this.location = location;
- }
-
- public Location getLocation() {
- return location;
- }
-
- public void setEntryDate(final Calendar date) {
- entryDate = date;
- }
-
- public Calendar getEntryDate() {
- return entryDate;
- }
-
- public void setImageType(final String imageType) {
- this.imageType = imageType;
- }
-
- public String getImageType() {
- return imageType;
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- }
- return image.clone();
- }
-
- @Override
- public int hashCode() {
- if (employeeId == null) {
- return 0;
- }
- return employeeId.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
- }
-
- @Override
- public String toString() {
- return "{\"EmployeeId\":\"" + employeeId + "\","
- + "\"EmployeeName\":\"" + employeeName + "\","
- + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
- + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
- + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
- + "\"Location\":"
- + (location == null ? "null" :
- "{\"City\":" + (location.getCity() == null ? "null" :
- "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
- + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
- + "\"Country\":\"" + location.getCountry() + "\"}") + ","
- + "\"Age\":" + age + ","
- + "\"EntryDate\":"
- + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
- + "\"ImageUrl\":\"" + imageUrl + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
deleted file mode 100644
index 288de70..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
+++ /dev/null
@@ -1,60 +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.odata2.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
-public class Location {
- @EdmProperty
- private String country;
- @EdmProperty
- private City city;
-
- public Location(final String country, final String postalCode, final String cityName) {
- this.country = country;
- city = new City(postalCode, cityName);
- }
-
- public void setCountry(final String country) {
- this.country = country;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCity(final City city) {
- this.city = city;
- }
-
- public City getCity() {
- return city;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", country, city.toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
deleted file mode 100644
index e3edbd0..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ /dev/null
@@ -1,47 +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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-
-/**
- *
- */
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Managers")
-public class Manager extends Employee {
-
- @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Manager(final String id, final String name) {
- super(id, name);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
deleted file mode 100644
index 1d44498..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
+++ /dev/null
@@ -1,25 +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.odata2.core.annotation.model;
-
-public interface ModelSharedConstants {
-
- String NAMESPACE_1 = "RefScenario";
- String CONTAINER_1 = "DefaultContainer";
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
deleted file mode 100644
index 8c920e4..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ /dev/null
@@ -1,128 +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.odata2.core.annotation.model;
-
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Photos")
-public class Photo {
- @EdmProperty
- @EdmKey
- private String name;
- @EdmProperty(name = "ImageFormat")
- @EdmKey
- private String type;
- @EdmProperty
- @EdmMediaResourceMimeType
- private String mimeType;
- @EdmProperty
- @EdmMediaResourceSource
- private String imageUrl = "http://localhost/someResource.png";
- @EdmProperty(type = EdmType.BINARY)
- @EdmMediaResourceContent
- private byte[] image = ResourceHelper.generateImage();
-
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(final String type) {
- this.type = type;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setImageUri(final String uri) {
- imageUrl = uri;
- }
-
- public byte[] getImage() {
- return image.clone();
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public String getImageType() {
- return mimeType;
- }
-
- public void setImageType(final String imageType) {
- mimeType = imageType;
- }
-
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 83 * hash + (name != null ? name.hashCode() : 0);
- hash = 83 * hash + (type != null ? type.hashCode() : 0);
- return hash;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Photo other = (Photo) obj;
- if ((name == null) ? (other.name != null) : !name.equals(other.name)) {
- return false;
- }
- if ((type == null) ? (other.type != null) : !type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "{\"Name\":\"" + name + "\","
- + "\"Type\":\"" + type + "\","
- + "\"ImageUrl\":\"" + imageUrl + "\","
- + "\"Image\":\"" + Arrays.toString(image) + "\","
- + "\"MimeType\":\"" + mimeType + "\"";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
deleted file mode 100644
index 8d39492..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Base", namespace = ModelSharedConstants.NAMESPACE_1)
-public abstract class RefBase {
- @EdmProperty(name = "Name")
- protected String name;
- @EdmProperty(name = "Id", type = EdmType.STRING)
- @EdmKey
- protected int id;
-
- public RefBase(final int id, final String name) {
- this.name = name;
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public String getId() {
- return Integer.toString(id);
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public void setId(final int id) {
- this.id = id;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
deleted file mode 100644
index 7edfcfc..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
+++ /dev/null
@@ -1,66 +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.odata2.core.annotation.model;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.WritableRaster;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import javax.imageio.ImageIO;
-
-/**
- *
- */
-public class ResourceHelper {
-
- public enum Format {
- BMP, JPEG, PNG, GIF
- };
-
- public static byte[] generateImage() {
- return generateImage(Format.PNG);
- }
-
- public static byte[] generateImage(final Format format) {
- try {
- int width = 320;
- int height = 320;
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
- WritableRaster raster = image.getRaster();
-
- int mod = format.ordinal() + 2;
- for (int h = 0; h < height; h++) {
- for (int w = 0; w < width; w++) {
- if (((h / 32) + (w / 32)) % mod == 0) {
- raster.setSample(w, h, 0, 0);
- } else {
- raster.setSample(w, h, 0, 1);
- }
- }
- }
-
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- ImageIO.write(image, format.name(), out);
- return out.toByteArray();
- } catch (IOException ex) {
- return new byte[0];
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
deleted file mode 100644
index 6ab8d74..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed 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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Rooms")
-public class Room extends RefBase {
-
- @EdmProperty
- private Integer seats;
- @EdmProperty
- private Integer version;
- @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
- private Building building;
- @EdmNavigationProperty(name = "nr_Employees")
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Room() {
- this(0, null);
- }
-
- public Room(final int id, final String name) {
- super(id, name);
- }
-
- public void setSeats(final int seats) {
- this.seats = seats;
- }
-
- public int getSeats() {
- return seats;
- }
-
- public void setVersion(final int version) {
- this.version = version;
- }
-
- public int getVersion() {
- return version;
- }
-
- public void setBuilding(final Building building) {
- this.building = building;
- }
-
- public Building getBuilding() {
- return building;
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80dc018d/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
deleted file mode 100644
index 3f72319..0000000
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ /dev/null
@@ -1,81 +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.odata2.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
-*
-*/
-@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Teams")
-public class Team extends RefBase {
- @EdmProperty(type = EdmType.BOOLEAN)
- private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Team() {
- super(-1, null);
- }
-
- public Team(final int id, final String name) {
- super(id, name);
- }
-
- public Boolean isScrumTeam() {
- return isScrumTeam;
- }
-
- public void setScrumTeam(final Boolean isScrumTeam) {
- this.isScrumTeam = isScrumTeam;
- }
-
- public void addEmployee(final Employee e) {
- employees.add(e);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
- }
-}
[17/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefaultTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefaultTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefaultTest.java
deleted file mode 100644
index af20194..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefaultTest.java
+++ /dev/null
@@ -1,554 +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.odata2.processor.core.jpa;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.Query;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmTestModelView;
-import org.easymock.EasyMock;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ODataJPAProcessorDefaultTest extends JPAEdmTestModelView {
-
- ODataJPAProcessorDefault objODataJPAProcessorDefault;
- ODataJPAProcessorDefaultTest objODataJPAProcessorDefaultTest;
-
- private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
- private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
- private static final String SO_ID = "SoId";
- private static final String SALES_ORDER = "SalesOrder";
- private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
- private static final String STR_CONTENT_TYPE = "Content-Type";
-
- @Before
- public void setUp() {
- objODataJPAProcessorDefaultTest = new ODataJPAProcessorDefaultTest();
- objODataJPAProcessorDefault = new ODataJPAProcessorDefault(getLocalmockODataJPAContext());
- }
-
- @Test
- public void testReadEntitySetGetEntitySetUriInfoString() {
- try {
- GetEntityUriInfo getEntityView = getEntityUriInfo();
- Assert.assertNotNull(objODataJPAProcessorDefault.readEntity(getEntityView, HttpContentType.APPLICATION_XML));
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e1) {// Expected
- assertTrue(true);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testcountEntitySet() {
- try {
- ODataResponse countEntitySet =
- objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML);
- Assert.assertNotNull(countEntitySet);
- Object entity = countEntitySet.getEntity();
- Assert.assertNotNull(entity);
-
- byte[] b = new byte[2];
- ((ByteArrayInputStream) entity).read(b);
- Assert.assertEquals("11", new String(b, Charset.forName("utf-8")));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (Exception e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testExistsEntity() {
- try {
- Assert.assertNotNull(objODataJPAProcessorDefault.existsEntity(getEntityCountCountUriInfo(),
- HttpContentType.APPLICATION_XML));
- Assert.assertNull("ContentType MUST NOT set by entity provider", objODataJPAProcessorDefault.existsEntity(
- getEntityCountCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (Exception e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testDeleteEntity() {
- try {
- Assert.assertNotNull(objODataJPAProcessorDefault.deleteEntity(getDeletetUriInfo(),
- HttpContentType.APPLICATION_XML));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testCreateEntity() {
- try {
- Assert.assertNotNull(objODataJPAProcessorDefault.createEntity(getPostUriInfo(), getMockedInputStreamContent(),
- HttpContentType.APPLICATION_XML, HttpContentType.APPLICATION_XML));
- } catch (ODataException e) {
- Assert.assertTrue(true); // Expected TODO - need to revisit
- }
- }
-
- @Test
- public void testUpdateEntity() {
- try {
- Assert.assertNotNull(objODataJPAProcessorDefault.updateEntity(getPutUriInfo(), getMockedInputStreamContent(),
- HttpContentType.APPLICATION_XML, false, HttpContentType.APPLICATION_XML));
- } catch (ODataException e) {
- Assert.assertTrue(true); // Expected TODO - need to revisit
- }
- }
-
- private PutMergePatchUriInfo getPutUriInfo() {
- return (PutMergePatchUriInfo) getDeletetUriInfo();
- }
-
- private PostUriInfo getPostUriInfo() {
- return (PostUriInfo) getDeletetUriInfo();
- }
-
- private InputStream getMockedInputStreamContent() {
- return new ByteArrayInputStream(getEntityBody().getBytes());
- }
-
- private String getEntityBody() {
- return "<entry xmlns=\"http://www.w3.org/2005/Atom\" " +
- "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
- "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" " +
- "xml:base=\"http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/\">"
- + "<content type=\"application/xml\">"
- + "<m:properties>"
- + "<d:ID>2</d:ID>"
- + "<d:CreationDate>2013-01-02T00:00:00</d:CreationDate>"
- + "<d:CurrencyCode>Code_555</d:CurrencyCode>"
- + "<d:BuyerAddressInfo m:type=\"SalesOrderProcessing.AddressInfo\">"
- + "<d:Street>Test_Street_Name_055</d:Street>"
- + "<d:Number>2</d:Number>"
- + "<d:Country>Test_Country_2</d:Country>"
- + "<d:City>Test_City_2</d:City>"
- + "</d:BuyerAddressInfo>"
- + "<d:GrossAmount>0.0</d:GrossAmount>"
- + "<d:BuyerId>2</d:BuyerId>"
- + "<d:DeliveryStatus>true</d:DeliveryStatus>"
- + "<d:BuyerName>buyerName_2</d:BuyerName>"
- + "<d:NetAmount>0.0</d:NetAmount>" + "</m:properties>" + "</content>" + "</entry>";
- }
-
- private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
- return getLocalUriInfo();
- }
-
- private GetEntityCountUriInfo getEntityCountCountUriInfo() {
- return getLocalUriInfo();
- }
-
- private DeleteUriInfo getDeletetUriInfo() {
- UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
- EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
- EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
- EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
- EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
- EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
- EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
- EasyMock.replay(objUriInfo);
- return objUriInfo;
- }
-
- private List<KeyPredicate> getKeyPredicates() {
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- return keyPredicates;
- }
-
- /**
- * @return
- */
- private UriInfo getLocalUriInfo() {
- UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
- EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
- EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
- EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
- EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
- EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
- EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
- EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
- EasyMock.replay(objUriInfo);
- return objUriInfo;
- }
-
- /**
- * @return
- * @throws EdmException
- */
- private EdmEntitySet getLocalEdmEntitySet() {
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
- EasyMock.replay(edmEntitySet);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return edmEntitySet;
- }
-
- /**
- * @return
- * @throws EdmException
- */
- private EdmEntityType getLocalEdmEntityType() {
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- try {
- EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
- EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
- EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
- EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
- EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
- EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));// ID vs Salesorder
- // ID
- EasyMock.replay(edmEntityType);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return edmEntityType;
- }
-
- private InlineCount getInlineCount() {
- return InlineCount.NONE;
- }
-
- private FilterExpression getFilter() {
- return null;
- }
-
- private Integer getSkip() {
- return null;
- }
-
- private Integer getTop() {
- return null;
- }
-
- private OrderByExpression getOrderByExpression() {
- return null;
- }
-
- private ODataJPAContext getLocalmockODataJPAContext() {
- ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
- EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
- EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
- EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
- EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
- EasyMock.replay(odataJPAContext);
- return odataJPAContext;
- }
-
- private EntityManagerFactory mockEntityManagerFactory() {
- EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
- EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
- EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
- EasyMock.replay(emf);
- return emf;
- }
-
- private EntityManagerFactory mockEntityManagerFactory2() {// For create, to avoid stackoverflow
- EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
- EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
- EasyMock.replay(emf);
- return emf;
- }
-
- private EntityManager getLocalEntityManager() {
- EntityManager em = EasyMock.createMock(EntityManager.class);
- EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
- EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(
- getQueryForSelectCount());
- EasyMock.expect(em.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory2());// For create
- EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); // For Delete
- Address obj = new Address();
- em.remove(obj);// testing void method
- em.flush();
- EasyMock.replay(em);
- return em;
- }
-
- private EntityTransaction getLocalTransaction() {
- EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
- entityTransaction.begin(); // testing void method
- entityTransaction.commit();// testing void method
- entityTransaction.rollback();// testing void method
- EasyMock.replay(entityTransaction);
- return entityTransaction;
- }
-
- private Query getQuery() {
- Query query = EasyMock.createMock(Query.class);
- EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
- EasyMock.replay(query);
- return query;
- }
-
- private Query getQueryForSelectCount() {
- Query query = EasyMock.createMock(Query.class);
- EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
- EasyMock.replay(query);
- return query;
- }
-
- private List<?> getResultList() {
- List<Object> list = new ArrayList<Object>();
- list.add(new Address());
- return list;
- }
-
- private List<?> getResultListForSelectCount() {
- List<Object> list = new ArrayList<Object>();
- list.add(new Long(11));
- return list;
- }
-
- class Address {
- private String soId = "12";
-
- public String getSoId() {
- return soId;
- }
-
- @Override
- public boolean equals(final Object obj) {
- boolean isEqual = false;
- if (obj instanceof Address) {
- isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
- }
- return isEqual;
- }
- }
-
- private Metamodel mockMetaModel() {
- Metamodel metaModel = EasyMock.createMock(Metamodel.class);
- EasyMock.expect(metaModel.getEntities()).andStubReturn(getLocalEntities());
- EasyMock.replay(metaModel);
- return metaModel;
- }
-
- private Set<EntityType<?>> getLocalEntities() {
- Set<EntityType<?>> entityTypeSet = new HashSet<EntityType<?>>();
- entityTypeSet.add(getLocalJPAEntityType());
- return entityTypeSet;
- }
-
- @SuppressWarnings("rawtypes")
- private EntityType<EntityType> getLocalJPAEntityType() {
- @SuppressWarnings("unchecked")
- EntityType<EntityType> entityType = EasyMock.createMock(EntityType.class);
- EasyMock.expect(entityType.getJavaType()).andStubReturn(EntityType.class);
- EasyMock.replay(entityType);
- return entityType;
- }
-
- private GetEntityUriInfo getEntityUriInfo() {
- GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- try {
- EasyMock.expect(getEntityView.getExpand()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
-
- EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
- EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
- EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SO_ID));
-
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));
-
- EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
- EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
- EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
- EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
-
- EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
-
- EasyMock.replay(edmEntityType, edmEntitySet);
- EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- EasyMock.expect(getEntityView.getNavigationSegments()).andReturn(navigationSegments);
- EasyMock.expect(getEntityView.getStartEntitySet()).andReturn(edmEntitySet);
-
- EasyMock.replay(getEntityView);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return getEntityView;
- }
-
- private EdmEntityContainer getLocalEdmEntityContainer() {
- EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
- EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
- try {
- EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- EasyMock.replay(edmEntityContainer);
- return edmEntityContainer;
- }
-
- private EdmTyped getEdmTypedMockedObj(final String propertyName) {
- EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
- try {
- EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmType);
- EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
- EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
-
- EasyMock.replay(mockedEdmProperty);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return mockedEdmProperty;
- }
-
- private EdmFacets getEdmFacetsMockedObj() {
- EdmFacets facets = EasyMock.createMock(EdmFacets.class);
- EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
-
- EasyMock.replay(facets);
- return facets;
- }
-
- private EdmMapping getEdmMappingMockedObj(final String propertyName) {
- EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
- if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
- EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
- } else {
- EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
- }
- EasyMock.replay(mockedEdmMapping);
- return mockedEdmMapping;
- }
-
- private List<String> getLocalPropertyNames() {
- List<String> list = new ArrayList<String>();
- list.add(SO_ID);
- return list;
- }
-
- private ODataContext getLocalODataContext() {
- ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
- try {
- EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(objODataContext);
- return objODataContext;
- }
-
- private PathInfo getLocalPathInfo() {
- PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
- EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
- EasyMock.replay(pathInfo);
- return pathInfo;
- }
-
- private URI getLocalURI() {
- URI uri = null;
- try {
- uri = new URI(STR_LOCAL_URI);
- } catch (URISyntaxException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return uri;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java
deleted file mode 100644
index 426f236..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilderTest.java
+++ /dev/null
@@ -1,566 +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.odata2.processor.core.jpa;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmTestModelView;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
-
- /*
- * This Unit is supposed to test the building of Entity Provider Properties for query with $expand
- */
- @Test
- public void testGetEntityProviderPropertiesQuery() {
- GetEntitySetUriInfo getEntitySetUriInfo = mockEntitySetUriInfoForExpand();
- ODataJPAContext oDataJPAContext = getODataJPAContext();
- // Building the edm entity
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmEntity = new HashMap<String, Object>();
- edmEntity.put("ID", 1);
- edmEntityList.add(edmEntity);
- // Invoking the private static method using reflection
- Class<?> clazz = ODataJPAResponseBuilder.class;
- Object[] actualParameters = { oDataJPAContext, getEntitySetUriInfo, edmEntityList };
- Class<?>[] formalParameters = { ODataJPAContext.class, GetEntitySetUriInfo.class, List.class };
- EntityProviderWriteProperties providerProperties = null;
- try {
- ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
- Method method = clazz.getDeclaredMethod("getEntityProviderProperties", formalParameters);
- method.setAccessible(true);
- providerProperties = (EntityProviderWriteProperties) method.invoke(responseBuilder, actualParameters);
- assertEquals(1, providerProperties.getExpandSelectTree().getLinks().size());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InstantiationException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- /*
- * This Unit is supposed to test the building of Entity Provider Properties for read with $expand
- */
- @Test
- public void testGetEntityProviderPropertiesRead() {
-
- // Getting the EntityUriInfo
- GetEntityUriInfo getEntityUriInfo = mockEntityUriInfoForExpand();
- ODataJPAContext oDataJPAContext = getODataJPAContext();
- Class<?> clazz = ODataJPAResponseBuilder.class;
- Object[] actualParameters = { oDataJPAContext, getEntityUriInfo };
- Class<?>[] formalParameters = { ODataJPAContext.class, GetEntityUriInfo.class };
- EntityProviderWriteProperties providerProperties = null;
- try {
- ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
- Method method = clazz.getDeclaredMethod("getEntityProviderProperties", formalParameters);
- method.setAccessible(true);
- providerProperties = (EntityProviderWriteProperties) method.invoke(responseBuilder, actualParameters);
- assertEquals(1, providerProperties.getExpandSelectTree().getLinks().size());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InstantiationException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void testConstructListofNavProperty() {
- List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>();
- ArrayList<NavigationPropertySegment> navPropList1 = new ArrayList<NavigationPropertySegment>();
- navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties11"));
- navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties12"));
- expand.add(navPropList1);
- ArrayList<NavigationPropertySegment> navPropList2 = new ArrayList<NavigationPropertySegment>();
- navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties21"));
- navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties22"));
- expand.add(navPropList2);
- Class<?> clazz = ODataJPAResponseBuilder.class;
- Object[] actualParameters = { expand };
- Class<?>[] formalParameters = { List.class };
- List<EdmNavigationProperty> navigationProperties = null;
- try {
- ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
- Method method = clazz.getDeclaredMethod("constructListofNavProperty", formalParameters);
- method.setAccessible(true);
- navigationProperties = (List<EdmNavigationProperty>) method.invoke(responseBuilder, actualParameters);
- assertEquals("DemoNavigationProperties21", navigationProperties.get(1).getName());
- assertEquals("DemoNavigationProperties11", navigationProperties.get(0).getName());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InstantiationException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testBuildListOfTGetEntitySetUriInfoStringODataJPAContext() {
- try {
- assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "application/xml",
- getODataJPAContext()));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testBuildNegatives() {// Bad content type
- try {
- EntityType entity = new EntityType();
- entity.setName("SalesOrderHeader");
- try {
- assertNotNull(ODataJPAResponseBuilder.build(getEntity(), getLocalGetURIInfo(), "xml", getODataJPAContext()));
- } catch (ODataNotFoundException e) {
- assertTrue(true);
- }
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);// Nothing to do, Expected.
- }
- try {// Bad content type
- assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "xml", getODataJPAContext()));
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);// Nothing to do, Expected.
- }
-
- }
-
- @Test
- public void testBuildObjectGetEntityUriInfoStringODataJPAContext() throws ODataNotFoundException {
- try {
- assertNotNull(ODataJPAResponseBuilder.build(new SalesOrderHeader(2, 10), getLocalGetURIInfo(), "application/xml",
- getODataJPAContext()));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testBuildNullSelects() {// Bad content type
- try {
- ODataJPAResponseBuilder.build(getJPAEntities(), getResultsViewWithNullSelects(), "xml", getODataJPAContext());
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);// Nothing to do, Expected.
- } catch (Exception e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testBuildGetCount() {
- ODataResponse objODataResponse = null;
- try {
- objODataResponse = ODataJPAResponseBuilder.build(1, getODataJPAContext());
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(objODataResponse);
- }
-
- private ODataJPAContext getODataJPAContext() {
- ODataJPAContext objODataJPAContext = EasyMock.createMock(ODataJPAContext.class);
- EasyMock.expect(objODataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
- EasyMock.replay(objODataJPAContext);
- return objODataJPAContext;
- }
-
- private ODataContext getLocalODataContext() {
- ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
- try {
- EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(objODataContext);
- return objODataContext;
- }
-
- private PathInfo getLocalPathInfo() {
- PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
- EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
- EasyMock.replay(pathInfo);
- return pathInfo;
- }
-
- private URI getLocalURI() {
- URI uri = null;
- try {
- uri = new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/");
- } catch (URISyntaxException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return uri;
- }
-
- private GetEntitySetUriInfo getResultsView() {
- GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
- EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(getLocalInlineCount());
- EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
- EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(getSelectItemList());
- EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(getExpandList());
- EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
- EasyMock.replay(objGetEntitySetUriInfo);
- return objGetEntitySetUriInfo;
- }
-
- private List<ArrayList<NavigationPropertySegment>> getExpandList() {
- List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
- return expandList;
- }
-
- private GetEntitySetUriInfo getResultsViewWithNullSelects() {
- GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
- EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(getLocalInlineCount());
- EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
- EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(null);
- EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
-
- EasyMock.replay(objGetEntitySetUriInfo);
- return objGetEntitySetUriInfo;
- }
-
- private GetEntityUriInfo getLocalGetURIInfo() {
- GetEntityUriInfo objGetEntityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
- EasyMock.expect(objGetEntityUriInfo.getSelect()).andStubReturn(getSelectItemList());
- EasyMock.expect(objGetEntityUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
- EasyMock.expect(objGetEntityUriInfo.getExpand()).andStubReturn(getExpandList());
- EasyMock.replay(objGetEntityUriInfo);
- return objGetEntityUriInfo;
- }
-
- private List<SelectItem> getSelectItemList() {
- List<SelectItem> selectItems = new ArrayList<SelectItem>();
- selectItems.add(getSelectItem());
- return selectItems;
- }
-
- private SelectItem getSelectItem() {
- SelectItem selectItem = EasyMock.createMock(SelectItem.class);
- EasyMock.expect(selectItem.getProperty()).andStubReturn(getEdmPropertyForSelect());
- List<NavigationPropertySegment> navigationSegmentList = new ArrayList<NavigationPropertySegment>();
- EasyMock.expect(selectItem.getNavigationPropertySegments()).andStubReturn(navigationSegmentList);
- EasyMock.replay(selectItem);
- return selectItem;
- }
-
- private EdmProperty getEdmPropertyForSelect() {
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- Facets facets = new Facets().setNullable(false);
- try {
- EasyMock.expect(edmType.valueToString(new Integer(2), EdmLiteralKind.URI, facets)).andStubReturn("2");
- EasyMock.expect(edmType.valueToString(new Integer(2), EdmLiteralKind.DEFAULT, facets)).andStubReturn("2");
- } catch (EdmSimpleTypeException e1) {
- fail("There is an exception in mocking EdmType object " + e1.getMessage());
- }
- EasyMock.replay(edmType);
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
- EasyMock.expect(edmMapping.getMimeType()).andReturn(null);
- EasyMock.replay(edmMapping);
- try {
- EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmProperty.getFacets()).andStubReturn(facets);
- EasyMock.expect(edmProperty.getCustomizableFeedMappings()).andStubReturn(null);
- EasyMock.expect(edmProperty.getMimeType()).andStubReturn(null);
- EasyMock.replay(edmProperty);
-
- } catch (EdmException e) {
- fail("There is an exception in mocking some object " + e.getMessage());
- }
-
- return edmProperty;
-
- }
-
- private EdmEntitySet getLocalTargetEntitySet() {
- EdmEntitySet objEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(objEdmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
- EasyMock.expect(objEdmEntitySet.getName()).andStubReturn("SalesOderHeaders");
- EasyMock.expect(objEdmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- EasyMock.replay(objEdmEntitySet);
- return objEdmEntitySet;
- }
-
- private EdmEntityContainer getLocalEdmEntityContainer() {
- EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
- EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
- try {
- EasyMock.expect(edmEntityContainer.getName()).andStubReturn("salesorderprocessingContainer");
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- EasyMock.replay(edmEntityContainer);
- return edmEntityContainer;
- }
-
- private EdmEntityType getLocalEdmEntityType() {
- EdmEntityType objEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- try {
- EasyMock.expect(objEdmEntityType.getName()).andStubReturn("SalesOderHeaders");
- EasyMock.expect(objEdmEntityType.getNamespace()).andStubReturn("SalesOderHeaders");
- EasyMock.expect(objEdmEntityType.hasStream()).andStubReturn(false);
- EasyMock.expect(objEdmEntityType.hasStream()).andStubReturn(false);
- ArrayList<String> propertyNames = new ArrayList<String>();
- propertyNames.add("ID");
- EasyMock.expect(objEdmEntityType.getProperty("ID")).andStubReturn(getEdmPropertyForSelect());
- EasyMock.expect(objEdmEntityType.getPropertyNames()).andStubReturn(propertyNames);
- EasyMock.expect(objEdmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
- EasyMock.expect(objEdmEntityType.getKeyPropertyNames()).andStubReturn(propertyNames);
- EasyMock.expect(objEdmEntityType.getKeyProperties()).andStubReturn(getKeyProperties());
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(objEdmEntityType);
- return objEdmEntityType;
- }
-
- private List<EdmProperty> getKeyProperties() {
- List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmType);
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
- EasyMock.replay(edmMapping);
- try {
- EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.replay(edmProperty);
- } catch (EdmException e) {
- fail("There is an exception is mocking some object " + e.getMessage());
- }
-
- edmProperties.add(edmProperty);
- return edmProperties;
- }
-
- private InlineCount getLocalInlineCount() {
- return InlineCount.NONE;
- }
-
- class SalesOrderHeader {
- private int soId;
- private int Field1;
-
- public SalesOrderHeader(final int soId, final int field) {
- this.soId = soId;
- Field1 = field;
- }
-
- public int getField1() {
- return Field1;
- }
-
- public void setField1(final int field1) {
- Field1 = field1;
- }
-
- public int getSoId() {
- return soId;
- }
-
- public void setSoId(final int soId) {
- this.soId = soId;
- }
-
- }
-
- private List<Object> getJPAEntities() {
- List<Object> listJPAEntities = new ArrayList<Object>();
- SalesOrderHeader entity;
- entity = new SalesOrderHeader(2, 10);
- listJPAEntities.add(entity);
- return listJPAEntities;
- }
-
- private Object getEntity() {
- SalesOrderHeader sHeader = new SalesOrderHeader(10, 34);
- return sHeader;
- }
-
- private GetEntityUriInfo mockEntityUriInfoForExpand() {
-
- List<SelectItem> selectItemList = new ArrayList<SelectItem>();
- List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
- ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
- // Mocking the navigation property
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- try {
- EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderItemDetails");
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(navigationProperty);
- // Mocking the navigation property segments and adding to expand list
- NavigationPropertySegment navigationPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
- EasyMock.expect(navigationPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
- EasyMock.expect(navigationPropertySegment.getTargetEntitySet()).andStubReturn(getTargetEntitySetForExpand());
- EasyMock.replay(navigationPropertySegment);
- navigationPropertyList.add(navigationPropertySegment);
- expandList.add(navigationPropertyList);
- // Mocking EntityUriInfo
- GetEntityUriInfo entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
- EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(selectItemList);
- EasyMock.expect(entityUriInfo.getExpand()).andStubReturn(expandList);
- EasyMock.replay(entityUriInfo);
- return entityUriInfo;
- }
-
- private GetEntitySetUriInfo mockEntitySetUriInfoForExpand() {
-
- List<SelectItem> selectItemList = new ArrayList<SelectItem>();
- List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
- ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
- // Mocking the navigation property
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- try {
- EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderItemDetails");
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(navigationProperty);
- // Mocking the navigation property segments and adding to expand list
- NavigationPropertySegment navigationPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
- EasyMock.expect(navigationPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
- EasyMock.expect(navigationPropertySegment.getTargetEntitySet()).andStubReturn(getTargetEntitySetForExpand());
- EasyMock.replay(navigationPropertySegment);
- navigationPropertyList.add(navigationPropertySegment);
- expandList.add(navigationPropertyList);
- // Mocking EntityUriInfo
- GetEntitySetUriInfo entitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
- EasyMock.expect(entitySetUriInfo.getSelect()).andStubReturn(selectItemList);
- EasyMock.expect(entitySetUriInfo.getExpand()).andStubReturn(expandList);
- EasyMock.expect(entitySetUriInfo.getInlineCount()).andStubReturn(InlineCount.ALLPAGES);
- EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
- EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(new Integer(2));
- EasyMock.replay(entitySetUriInfo);
- return entitySetUriInfo;
- }
-
- private EdmEntitySet getTargetEntitySetForExpand() {
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(entitySet.getName()).andStubReturn("SalesOrderHeaders");
- EasyMock.expect(entitySet.getEntityType()).andStubReturn(null);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entitySet);
- return entitySet;
- }
-
- private NavigationPropertySegment getNavigationPropertySegment(final String navPropertyName) {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- try {
- EasyMock.expect(navigationProperty.getName()).andStubReturn(navPropertyName);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(navigationProperty);
- NavigationPropertySegment navPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
- EasyMock.expect(navPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
- EasyMock.replay(navPropertySegment);
- return navPropertySegment;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTest.java
deleted file mode 100644
index 55511ca..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParserTest.java
+++ /dev/null
@@ -1,599 +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.odata2.processor.core.jpa.access.data;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPAEntityParserTest {
- /*
- * TestCase - JPAResultParser is a singleton class Check if the same
- * instance is returned when create method is called
- */
- @Test
- public void testCreate() {
- JPAEntityParser resultParser1 = new JPAEntityParser();
- JPAEntityParser resultParser2 = new JPAEntityParser();
-
- if (resultParser1.equals(resultParser2)) {
- fail();
- }
- }
-
- @Test
- public void testparse2EdmPropertyValueMap() {
- JPAEntityParser resultParser = new JPAEntityParser();
- Object jpaEntity = new demoItem("abc", 10);
- EdmStructuralType structuralType = EasyMock.createMock(EdmStructuralType.class);
- EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class);
- EdmType edmType01 = EasyMock.createMock(EdmType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EdmMapping edmMapping01 = EasyMock.createMock(EdmMapping.class);
-
- try {
- EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmTyped.getName()).andStubReturn("identifier");
- EasyMock.replay(edmType);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id");
- EasyMock.replay(edmMapping);
- EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
- EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
- EasyMock.replay(edmTyped);
- EasyMock.expect(structuralType.getProperty("identifier")).andStubReturn(edmTyped);
-
- EasyMock.expect(edmType01.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmTyped01.getName()).andStubReturn("Value");
- EasyMock.replay(edmType01);
- EasyMock.expect(edmMapping01.getInternalName()).andStubReturn("value");
- EasyMock.replay(edmMapping01);
- EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
- EasyMock.expect(edmTyped01.getMapping()).andStubReturn(edmMapping01);
- EasyMock.replay(edmTyped01);
- EasyMock.expect(structuralType.getProperty("value")).andStubReturn(edmTyped01);
-
- List<String> propNames = new ArrayList<String>();
- propNames.add("identifier");
- propNames.add("value");
- EasyMock.expect(structuralType.getPropertyNames()).andReturn(propNames);
- EasyMock.replay(structuralType);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- try {
- Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, structuralType);
- assertEquals(2, result.size());
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testparse2EdmPropertyValueMapEdmExcep() {
- JPAEntityParser resultParser = new JPAEntityParser();
- Object jpaEntity = new demoItem("abc", 10);
- EdmStructuralType structuralType = EasyMock
- .createMock(EdmStructuralType.class);
- EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class);
- EdmType edmType01 = EasyMock.createMock(EdmType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EdmMapping edmMapping01 = EasyMock.createMock(EdmMapping.class);
-
- try {
- EasyMock.expect(edmType.getKind())
- .andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmType.getName()).andReturn("identifier");
- EasyMock.replay(edmType);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id");
- EasyMock.replay(edmMapping);
- EasyMock.expect(edmTyped.getType()).andStubThrow(
- new EdmException(null));
- EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmTyped.getName()).andReturn("identifier");
- EasyMock.replay(edmTyped);
- EasyMock.expect(structuralType.getProperty("identifier"))
- .andStubReturn(edmTyped);
-
- EasyMock.expect(edmType01.getKind()).andStubReturn(
- EdmTypeKind.SIMPLE);
- EasyMock.expect(edmType01.getName()).andStubReturn("value");
- EasyMock.replay(edmType01);
- EasyMock.expect(edmMapping01.getInternalName()).andStubReturn(
- "value");
- EasyMock.replay(edmMapping01);
- EasyMock.expect(edmTyped01.getName()).andReturn("value");
- EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
- EasyMock.expect(edmTyped01.getMapping())
- .andStubReturn(edmMapping01);
- EasyMock.replay(edmTyped01);
- EasyMock.expect(structuralType.getProperty("value")).andStubReturn(
- edmTyped01);
-
- List<String> propNames = new ArrayList<String>();
- propNames.add("identifier");
- propNames.add("value");
- EasyMock.expect(structuralType.getPropertyNames()).andReturn(
- propNames);
- EasyMock.replay(structuralType);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2); // assertTrue(false);
- }
-
- try {
- resultParser.parse2EdmPropertyValueMap(jpaEntity, structuralType);
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
-
- }
-
- @Test
- public void testparse2EdmPropertyListMap() {
- JPAEntityParser resultParser = new JPAEntityParser();
- Map<String, Object> edmEntity = new HashMap<String, Object>();
- edmEntity.put("SoId", 1);
- DemoRelatedEntity relatedEntity = new DemoRelatedEntity("NewOrder");
- demoItem jpaEntity = new demoItem("laptop", 1);
- jpaEntity.setRelatedEntity(relatedEntity);
- List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
- // Mocking a navigation property and its mapping object
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- try {
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("relatedEntity");
- EasyMock.replay(edmMapping);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("RelatedEntities");
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.replay(navigationProperty);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- navigationPropertyList.add(navigationProperty);
- try {
- HashMap<String, Object> result = resultParser.parse2EdmNavigationValueMap(jpaEntity, navigationPropertyList);
- assertEquals(relatedEntity, result.get("RelatedEntities"));
-
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testparse2EdmPropertyValueMapFromList() {
- JPAEntityParser resultParser = new JPAEntityParser();
- demoItem jpaEntity = new demoItem("laptop", 1);
- DemoRelatedEntity relatedEntity = new DemoRelatedEntity("DemoOrder");
- jpaEntity.setRelatedEntity(relatedEntity);
- List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
- // Mocking EdmProperties
- EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
- EdmProperty edmProperty2 = EasyMock.createMock(EdmProperty.class);
- EdmType edmType1 = EasyMock.createMock(EdmType.class);
- EdmType edmType2 = EasyMock.createMock(EdmType.class);
- EdmMapping mapping1 = EasyMock.createMock(EdmMapping.class);
- EdmMapping mapping2 = EasyMock.createMock(EdmMapping.class);
- try {
- EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmType1);
- EasyMock.expect(mapping1.getInternalName()).andStubReturn("id");
- EasyMock.replay(mapping1);
- EasyMock.expect(edmProperty1.getName()).andStubReturn("Id");
- EasyMock.expect(edmProperty1.getMapping()).andStubReturn(mapping1);
- EasyMock.expect(edmProperty1.getType()).andStubReturn(edmType1);
- EasyMock.replay(edmProperty1);
- EasyMock.expect(edmType2.getKind()).andStubReturn(EdmTypeKind.COMPLEX);
- EasyMock.replay(edmType2);
- EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity.order");
- EasyMock.replay(mapping2);
- EasyMock.expect(edmProperty2.getName()).andStubReturn("Order");
- EasyMock.expect(edmProperty2.getMapping()).andStubReturn(mapping2);
- EasyMock.expect(edmProperty2.getType()).andStubReturn(edmType2);
- EasyMock.replay(edmProperty2);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- selectPropertyList.add(edmProperty1);
- selectPropertyList.add(edmProperty2);
- try {
- Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, selectPropertyList);
- assertEquals("DemoOrder", result.get("Order"));
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- // This unit tests when there is a complex type in the select list
- @SuppressWarnings("unchecked")
- @Test
- public void testparse2EdmPropertyValueMapFromListComplex() {
- JPAEntityParser resultParser = new JPAEntityParser();
- demoItem jpaEntity = new demoItem("laptop", 1);
- DemoRelatedEntity relatedEntity = new DemoRelatedEntity("DemoOrder");
- jpaEntity.setRelatedEntity(relatedEntity);
- List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
- // Mocking EdmProperties
- EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
- EdmProperty edmProperty2 = EasyMock.createMock(EdmProperty.class);
- EdmProperty edmComplexProperty = EasyMock.createMock(EdmProperty.class);
- EdmType edmType1 = EasyMock.createMock(EdmType.class);
- EdmStructuralType edmType2 = EasyMock.createMock(EdmStructuralType.class);
- EdmType edmComplexType = EasyMock.createMock(EdmType.class);
- EdmMapping mapping1 = EasyMock.createMock(EdmMapping.class);
- EdmMapping mapping2 = EasyMock.createMock(EdmMapping.class);
- EdmMapping complexMapping = EasyMock.createMock(EdmMapping.class);
- try {
- EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmType1);
- EasyMock.expect(mapping1.getInternalName()).andStubReturn("id");
- EasyMock.replay(mapping1);
- EasyMock.expect(edmProperty1.getName()).andStubReturn("Id");
- EasyMock.expect(edmProperty1.getMapping()).andStubReturn(mapping1);
- EasyMock.expect(edmProperty1.getType()).andStubReturn(edmType1);
- EasyMock.replay(edmProperty1);
- // Mocking the complex properties
- EasyMock.expect(edmComplexType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(edmComplexType);
- EasyMock.expect(complexMapping.getInternalName()).andStubReturn("order");
- EasyMock.replay(complexMapping);
- EasyMock.expect(edmComplexProperty.getName()).andStubReturn("OrderName");
- EasyMock.expect(edmComplexProperty.getMapping()).andStubReturn(complexMapping);
- EasyMock.expect(edmComplexProperty.getType()).andStubReturn(edmComplexType);
- EasyMock.replay(edmComplexProperty);
- EasyMock.expect(edmType2.getKind()).andStubReturn(EdmTypeKind.COMPLEX);
- EasyMock.expect(edmType2.getProperty("OrderName")).andStubReturn(edmComplexProperty);
- List<String> propertyNames = new ArrayList<String>();
- propertyNames.add("OrderName");
- EasyMock.expect(edmType2.getPropertyNames()).andStubReturn(propertyNames);
- EasyMock.replay(edmType2);
- EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity");
- EasyMock.replay(mapping2);
- EasyMock.expect(edmProperty2.getName()).andStubReturn("Order");
- EasyMock.expect(edmProperty2.getMapping()).andStubReturn(mapping2);
- EasyMock.expect(edmProperty2.getType()).andStubReturn(edmType2);
- EasyMock.replay(edmProperty2);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- selectPropertyList.add(edmProperty1);
- selectPropertyList.add(edmProperty2);
- try {
- Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, selectPropertyList);
- assertEquals(1, ((HashMap<String, Object>) result.get("Order")).size());
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
- + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- /*
- * TestCase - getGetterName is a private method in JPAResultParser. The
- * method is uses reflection to derive the property access methods from
- * EdmProperty
- */
- @Test
- public void testGetGettersWithOutMapping() {
- JPAEntityParser resultParser = new JPAEntityParser();
- try {
-
- /*
- * Case 1 - Property having No mapping
- */
- Class<?>[] pars = { String.class, EdmMapping.class, String.class };
- Object[] params = { "Field1", null, "get" };
- Method getGetterName = resultParser.getClass().getDeclaredMethod("getAccessModifierName", pars);
- getGetterName.setAccessible(true);
- String name = (String) getGetterName.invoke(resultParser, params);
-
- assertEquals("getField1", name);
-
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-
- }
- }
-
- @Test
- public void testGetGettersWithNullPropname() {
- JPAEntityParser resultParser = new JPAEntityParser();
- try {
-
- /*
- * Case 1 - Property having No mapping and no name
- */
- Class<?>[] pars = { String.class, EdmMapping.class, String.class };
- Object[] params = { null, null, null };
- Method getGetterName = resultParser.getClass().getDeclaredMethod("getAccessModifierName", pars);
- getGetterName.setAccessible(true);
-
- String name = (String) getGetterName.invoke(resultParser, params);
- assertNull(name);
-
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-
- }
- }
-
- /*
- * TestCase - getGetterName is a private method in JPAResultParser. The
- * method is uses reflection to derive the property access methods from
- * EdmProperty
- *
- * EdmProperty name could have been modified. Then mapping object of
- * EdmProperty should be used for deriving the name
- */
- @Test
- public void testGetGettersWithMapping() {
- JPAEntityParser resultParser = new JPAEntityParser();
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("field1");
- EasyMock.replay(edmMapping);
- try {
-
- Class<?>[] pars = { String.class, EdmMapping.class, String.class };
- Object[] params = { "myField", edmMapping, "get" };
- Method getGetterName = resultParser.getClass().getDeclaredMethod("getAccessModifierName", pars);
- getGetterName.setAccessible(true);
-
- String name = (String) getGetterName.invoke(resultParser, params);
- assertEquals("getField1", name);
-
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchMethodException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-
- }
- }
-
- @Test
- public void testGetGettersNoSuchMethodException() {
- JPAEntityParser resultParser = new JPAEntityParser();
- try {
-
- Method getGetterName = resultParser.getClass().getDeclaredMethod("getGetterName1", EdmProperty.class);
- getGetterName.setAccessible(true);
-
- } catch (NoSuchMethodException e) {
- assertEquals(
- "org.apache.olingo.odata2.processor.core.jpa.access.data.JPAEntityParser.getGetterName1" +
- "(org.apache.olingo.odata2.api.edm.EdmProperty)",
- e.getMessage());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
-
- }
- }
-
- @Test
- public void testParse2EdmPropertyValueMap() {
- JPAEntityParser resultParser = new JPAEntityParser();
- Object jpaEntity = new DemoItem2("abc");
- try {
- resultParser.parse2EdmPropertyValueMap(jpaEntity, getEdmPropertyList());
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetGetterEdmException() {
- JPAEntityParser resultParser = new JPAEntityParser();
- Object jpaEntity = new demoItem("abc", 10);
- EdmStructuralType structuralType = EasyMock.createMock(EdmStructuralType.class);
- try {
- EasyMock.expect(structuralType.getPropertyNames()).andStubThrow(new EdmException(null));
- EasyMock.replay(structuralType);
- Method getGetters =
- resultParser.getClass().getDeclaredMethod("getGetters", Object.class, EdmStructuralType.class);
- getGetters.setAccessible(true);
- try {
- getGetters.invoke(resultParser, jpaEntity, structuralType);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (InvocationTargetException e) {
- assertTrue(true);
- }
- } catch (NoSuchMethodException e) {
- assertEquals(
- "org.apache.olingo.odata2.processor.core.jpa.access.data.JPAEntityParser.getGetters(java.lang.Object, " +
- "org.apache.olingo.odata2.api.edm.EdmStructuralType)",
- e.getMessage());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testForNullJPAEntity() {
- JPAEntityParser resultParser = new JPAEntityParser();
- EdmStructuralType structuralType = EasyMock.createMock(EdmStructuralType.class);
- Object map;
- try {
- map = resultParser.parse2EdmPropertyValueMap(null, structuralType);
- assertNull(map);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- class demoItem {
- private String id;
- private int value;
- private DemoRelatedEntity relatedEntity;
-
- public String getId() {
- return id;
- }
-
- public void setId(final String id) {
- this.id = id;
- }
-
- public DemoRelatedEntity getRelatedEntity() {
- return relatedEntity;
- }
-
- public void setRelatedEntity(final DemoRelatedEntity relatedEntity) {
- this.relatedEntity = relatedEntity;
- }
-
- public int getValue() {
- return value;
- }
-
- public void setValue(final int value) {
- this.value = value;
- }
-
- demoItem(final String id, final int value) {
- this.id = id;
- this.value = value;
- }
-
- }
-
- class DemoRelatedEntity {
- String order;
-
- public String getOrder() {
- return order;
- }
-
- public void setOrder(final String order) {
- this.order = order;
- }
-
- public DemoRelatedEntity(final String order) {
- super();
- this.order = order;
- }
-
- }
-
- private List<EdmProperty> getEdmPropertyList() {
- List<EdmProperty> properties = new ArrayList<EdmProperty>();
- properties.add(getEdmProperty());
- return properties;
- }
-
- class DemoItem2 {
- private String field1;
-
- public String getField1() {
- return field1;
- }
-
- public void setField1(final String field) {
- field1 = field;
- }
-
- public DemoItem2(final String field) {
- field1 = field;
- }
-
- }
-
- private EdmProperty getEdmProperty() {
- EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
-
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
- EasyMock.replay(edmMapping);
-
- EdmType edmType = EasyMock.createMock(EdmType.class);
-
- try {
- EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmType.getName()).andStubReturn("identifier");
- EasyMock.expect(edmTyped.getName()).andStubReturn("SalesOrderHeader");
- EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
-
- EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
- EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(edmType);
- EasyMock.replay(edmTyped);
- return edmTyped;
- }
-}
[46/47] git commit: [OLINGO-67] support for q parameters in Accept
header
Posted by tb...@apache.org.
[OLINGO-67] support for q parameters in Accept header
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/051af1c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/051af1c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/051af1c8
Branch: refs/heads/ODataServlet
Commit: 051af1c8b1625a9ad244799f64bf810979db440e
Parents: 80dc018
Author: Tamara Boehm <ta...@sap.com>
Authored: Thu Jan 2 13:36:33 2014 +0100
Committer: Tamara Boehm <ta...@sap.com>
Committed: Thu Jan 2 13:39:04 2014 +0100
----------------------------------------------------------------------
.../odata2/core/servlet/ODataServlet.java | 6 +-
.../olingo/odata2/core/servlet/RestUtil.java | 111 +++++++++++--------
2 files changed, 70 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/051af1c8/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
index 6115fb5..986ba7c 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/ODataServlet.java
@@ -63,10 +63,10 @@ public class ODataServlet extends HttpServlet {
}
}
- if (req.getPathInfo() == null) {
- handleRedirect(req, resp);
- } else {
+ if (req.getPathInfo() != null) {
handle(req, resp, xHttpMethod, xHttpMethodOverride);
+ } else {
+ handleRedirect(req, resp);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/051af1c8/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
index ab1499e..de7f599 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java
@@ -11,9 +11,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Scanner;
import java.util.TreeSet;
-import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,18 +29,24 @@ import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.commons.Decoder;
public class RestUtil {
- private static final String REG_EX_QUALITY_FACTOR = "q=((?:1\\.0{0,3})|(?:0\\.[0-9]{0,2}[1-9]))";
private static final String REG_EX_OPTIONAL_WHITESPACE = "\\s?";
- private static final Pattern REG_EX_ACCEPT = Pattern.compile("((?:[a-z\\*\\s]+/[a-zA-Z\\+\\*\\-=\\s]+"
- + "(?:;\\s*[a-pr-zA-PR-Z][a-zA-Z0-9\\-\\s]*=[a-zA-Z0-9\\-\\s]+)*))");
- // private static final Pattern REG_EX_ACCEPT_WITH_Q_FACTOR = Pattern.compile(REG_EX_ACCEPT + "(?:;"
- // + REG_EX_OPTIONAL_WHITESPACE + "q=([0-9]\\.?[0-9]{0,3}))?");
- private static final Pattern REG_EX_ACCEPT_WITH_Q_FACTOR = Pattern.compile(REG_EX_ACCEPT + "(?:;"
- + REG_EX_OPTIONAL_WHITESPACE + REG_EX_QUALITY_FACTOR + ")?");
- private static final Pattern REG_EX_ACCEPT_LANGUAGES = Pattern
- .compile("((?:[a-z]{1,8})|(?:\\*))\\-?([a-zA-Z]{1,8})?");
- private static final Pattern REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR = Pattern.compile(REG_EX_ACCEPT_LANGUAGES + "(?:;"
- + REG_EX_OPTIONAL_WHITESPACE + REG_EX_QUALITY_FACTOR + ")?");
+
+ //RFC 2616, 3.9: qvalue = ("0"["." 0*3DIGIT]) | ("1"["." 0*3("0")])
+ private static final String REG_EX_QVALUE = "q=((?:1(?:\\.0{0,3})?)|(?:0(?:\\.[0-9]{0,3})?))";
+
+ //RFC 2616, 14.1: the media-range parameters
+ private static final String REG_EX_PARAMETER = "(?:;\\s*(?:(?:[^qQ].*)|(?:[qQ]\\s*=\\s*(?:[^01].*))))*";
+ private static final Pattern REG_EX_ACCEPT =
+ Pattern.compile("([a-z\\*\\s]+/[a-zA-Z\\+\\*\\-=\\s]+" + REG_EX_PARAMETER + ")");
+ private static final Pattern REG_EX_ACCEPT_WITH_Q_FACTOR =
+ Pattern.compile(REG_EX_ACCEPT + "(?:" + REG_EX_OPTIONAL_WHITESPACE + REG_EX_QVALUE + ")?");
+
+ //RFC 2616, 14.4: language-range = ((1*8ALPHA *("-" 1*8ALPHA)) | "*")
+ private static final Pattern REG_EX_ACCEPT_LANGUAGES =
+ Pattern.compile("((?:\\*)|(?:[a-z]{1,8}(?:\\-[a-zA-Z]{1,8})?))");
+ private static final Pattern REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR =
+ Pattern.compile(REG_EX_ACCEPT_LANGUAGES + "(?:;" + REG_EX_OPTIONAL_WHITESPACE + REG_EX_QVALUE + ")?");
+
private static final Pattern REG_EX_MATRIX_PARAMETER = Pattern.compile("([^=]*)(?:=(.*))?");
public static ContentType extractRequestContentType(final String contentType)
@@ -62,61 +66,75 @@ public class RestUtil {
}
}
+ /*
+ * Parses query parameters.
+ */
public static Map<String, String> extractQueryParameters(final String queryString) {
Map<String, String> queryParametersMap = new HashMap<String, String>();
if (queryString != null) {
+ //At first the queryString will be decoded.
List<String> queryParameters = Arrays.asList(Decoder.decode(queryString).split("\\&"));
for (String param : queryParameters) {
- int indexOfEq = param.indexOf("=");
- if (indexOfEq < 0) {
+ int indexOfEqualSign = param.indexOf("=");
+ if (indexOfEqualSign < 0) {
queryParametersMap.put(param, "");
} else {
- queryParametersMap.put(param.substring(0, indexOfEq), param.substring(indexOfEq + 1));
+ queryParametersMap.put(param.substring(0, indexOfEqualSign), param.substring(indexOfEqualSign + 1));
}
}
}
return queryParametersMap;
}
+ /*
+ * Parses Accept-Language header. Returns a list sorted by quality parameter
+ */
public static List<Locale> extractAcceptableLanguage(final String acceptableLanguageHeader) {
List<Locale> acceptLanguages = new ArrayList<Locale>();
- if (acceptableLanguageHeader != null) {
- Scanner acceptLanguageScanner = new Scanner(acceptableLanguageHeader).useDelimiter(",\\s?");
- while (acceptLanguageScanner.hasNext()) {
- if (acceptLanguageScanner.hasNext(REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR)) {
- acceptLanguageScanner.next(REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR);
- MatchResult result = acceptLanguageScanner.match();
- String language = result.group(1);
- String country = result.group(2);
- // //double qualityFactor = result.group(2) != null ? Double.parseDouble(result.group(2)) : 1d;
- if (country == null) {
- acceptLanguages.add(new Locale(language));
- } else {
- acceptLanguages.add(new Locale(language, country));
- }
+ TreeSet<Accept> acceptTree = getAcceptTree();
+ if (acceptableLanguageHeader != null && !acceptableLanguageHeader.isEmpty()) {
+ List<String> list = Arrays.asList(acceptableLanguageHeader.split(",\\s?"));
+ for (String acceptLanguage : list) {
+ Matcher matcher = REG_EX_ACCEPT_LANGUAGES_WITH_Q_FACTOR.matcher(acceptLanguage);
+ if (matcher.find()) {
+ String language = matcher.group(1);
+ double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d;
+ acceptTree.add(new Accept(language, qualityFactor));
}
}
- acceptLanguageScanner.close();
+ }
+ for (Accept accept : acceptTree) {
+ String languageRange = accept.getValue();
+ //The languageRange has to be splitted in language tag and country tag
+ int indexOfMinus = languageRange.indexOf("-");
+ Locale locale;
+ if (indexOfMinus < 0) {
+ // no country tag
+ locale = new Locale(languageRange);
+ } else {
+ String language = languageRange.substring(0, indexOfMinus);
+ String country = languageRange.substring(indexOfMinus + 1);
+ locale = new Locale(language, country);
+ }
+ acceptLanguages.add(locale);
}
return acceptLanguages;
}
- public static List<String> extractAcceptHeaders(final String header) {
+ /*
+ * Parses Accept header. Returns a list of media ranges sorted by quality parameter
+ */
+ public static List<String> extractAcceptHeaders(final String acceptHeader) {
TreeSet<Accept> acceptTree = getAcceptTree();
List<String> acceptHeaders = new ArrayList<String>();
- if (header != null && !header.isEmpty()) {
- List<String> list = Arrays.asList(header.split(",\\s?"));
- for (String el : list) {
- Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(el);
+ if (acceptHeader != null && !acceptHeader.isEmpty()) {
+ List<String> list = Arrays.asList(acceptHeader.split(",\\s?"));
+ for (String accept : list) {
+ Matcher matcher = REG_EX_ACCEPT_WITH_Q_FACTOR.matcher(accept);
if (matcher.find()) {
String headerValue = matcher.group(1);
double qualityFactor = matcher.group(2) != null ? Double.parseDouble(matcher.group(2)) : 1d;
- //double qualityFactor = Double.parseDouble(matcher.group(2));
- //if(!matcher.group(2).matches(REG_EX_QUALITY_FACTOR)){
- // throw new ODataBadRequestException(ODataBadRequestException.INVALID_HEADER);
- //}
- Accept acceptHeader = new Accept(headerValue, qualityFactor);
- acceptTree.add(acceptHeader);
+ acceptTree.add(new Accept(headerValue, qualityFactor));
}
}
}
@@ -298,8 +316,8 @@ public class RestUtil {
private static TreeSet<Accept> getAcceptTree() {
TreeSet<Accept> treeSet = new TreeSet<Accept>(new Comparator<Accept>() {
@Override
- public int compare(final Accept o1, final Accept o2) {
- if (o1.getQuality() <= o2.getQuality()) {
+ public int compare(final Accept header1, final Accept header2) {
+ if (header1.getQuality() <= header2.getQuality()) {
return 1;
} else {
return -1;
@@ -309,6 +327,11 @@ public class RestUtil {
return treeSet;
}
+ /*
+ * The class is used in order to sort headers by "q" parameter.
+ * The object of this class contains a value of the Accept header or Accept-Language header and value of the
+ * quality parameter.
+ */
private static class Accept {
private double quality;
private String value;
[43/47] git commit: [OLINGO-103] Expose ODataJPAResponseBuilder for
External Usage
Posted by tb...@apache.org.
[OLINGO-103] Expose ODataJPAResponseBuilder for External Usage
Signed-off-by: Chandan V A <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/f8638bb7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f8638bb7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f8638bb7
Branch: refs/heads/ODataServlet
Commit: f8638bb7a910fd44f4bd88d0368df760aa189db5
Parents: 63b621a
Author: Chandan V A <ch...@sap.com>
Authored: Wed Jan 1 19:42:29 2014 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Wed Jan 1 19:42:29 2014 +0530
----------------------------------------------------------------------
.../jpa/processor/api/ODataJPAProcessor.java | 12 +-
.../processor/api/ODataJPAResponseBuilder.java | 158 +++++
.../api/factory/ODataJPAAccessFactory.java | 12 +
.../core/ODataJPAProcessorDefault.java | 24 +-
.../processor/core/ODataJPAResponseBuilder.java | 629 ------------------
.../core/ODataJPAResponseBuilderDefault.java | 646 +++++++++++++++++++
.../core/factory/ODataJPAFactoryImpl.java | 11 +-
.../core/ODataJPAResponseBuilderTest.java | 40 +-
8 files changed, 866 insertions(+), 666 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
index 4ce0f19..d08eee9 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
@@ -27,8 +27,8 @@ import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
* Extend this class and implement an OData JPA processor if the default
* behavior of OData JPA Processor library has to be overwritten.
*
- *
- *
+ * The class encapsulates a default processor for handling OData requests and
+ * a default builder to build an OData response.
*
*/
public abstract class ODataJPAProcessor extends ODataSingleProcessor {
@@ -44,6 +44,12 @@ public abstract class ODataJPAProcessor extends ODataSingleProcessor {
*/
protected JPAProcessor jpaProcessor;
+ /**
+ * An instance of {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder}. The instance
+ * is created using {@link org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory}.
+ */
+ protected ODataJPAResponseBuilder responseBuilder;
+
public ODataJPAContext getOdataJPAContext() {
return oDataJPAContext;
}
@@ -64,6 +70,8 @@ public abstract class ODataJPAProcessor extends ODataSingleProcessor {
}
this.oDataJPAContext = oDataJPAContext;
jpaProcessor = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAProcessor(this.oDataJPAContext);
+ responseBuilder =
+ ODataJPAFactory.createFactory().getODataJPAAccessFactory().getODataJPAResponseBuilder(this.oDataJPAContext);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAResponseBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAResponseBuilder.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAResponseBuilder.java
new file mode 100644
index 0000000..63d692b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAResponseBuilder.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+
+/**
+ * The interface provides methods for building an OData response from a JPA Entity.
+ * Implement this interface for building an OData response from a JPA Entity.
+ */
+public interface ODataJPAResponseBuilder {
+
+ /**
+ * The method builds an OData response for an OData Query Request from a queried list of JPA Entities.
+ * @param queryUriInfo is an information about the request URI
+ * @param jpaEntities is an empty or non empty list of queried instances of JPA Entities
+ * @param contentType of the response
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ */
+ public ODataResponse build(final GetEntitySetUriInfo queryUriInfo, final List<Object> jpaEntities,
+ final String contentType) throws ODataJPARuntimeException;
+
+ /**
+ * The method builds an OData response for an OData Read Request from a read JPA Entity
+ * @param readUriInfo is an information about the request URI
+ * @param jpaEntity is a null or non null instances of read JPA Entity
+ * @param contentType of the response
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ * @throws ODataNotFoundException
+ */
+ public ODataResponse build(final GetEntityUriInfo readUriInfo, final Object jpaEntity,
+ final String contentType) throws ODataJPARuntimeException,
+ ODataNotFoundException;
+
+ /**
+ * The method builds an OData response for an OData Create Request from a created List of JPA entities.
+ * @param postUriInfo is an information about the request URI
+ * @param createdObjectList is an empty or non empty list of created instances of JPA Entities
+ * @param contentType of the response
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ * @throws ODataNotFoundException
+ */
+ public ODataResponse build(final PostUriInfo postUriInfo, final List<Object> createdObjectList,
+ final String contentType) throws ODataJPARuntimeException,
+ ODataNotFoundException;
+
+ /**
+ * The method builds an OData response for an OData Update Request from an updated JPA Entity
+ * @param putUriInfo is an information about the request URI
+ * @param updatedObject is an updated instance of JPA Entity
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ * @throws ODataNotFoundException
+ */
+ public ODataResponse build(final PutMergePatchUriInfo putUriInfo, final Object updatedObject)
+ throws ODataJPARuntimeException, ODataNotFoundException;
+
+ /**
+ * The method builds an OData response for an OData Delete Request from a deleted JPA Entity
+ * @param deleteUriInfo is an information about the request URI
+ * @param deletedObject is an null or non null instance of deleted JPA Entity. Null implies Entity not found.
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ * @throws ODataNotFoundException
+ */
+ public ODataResponse build(final DeleteUriInfo deleteUriInfo, final Object deletedObject)
+ throws ODataJPARuntimeException, ODataNotFoundException;
+
+ /**
+ * The method builds an OData response for an OData function Import Request from a registered processor method's
+ * return parameter.
+ * @param functionImportUriInfo is an information about the request URI
+ * @param result is a method's return parameter
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ */
+ public ODataResponse build(final GetFunctionImportUriInfo functionImportUriInfo, final Object result)
+ throws ODataJPARuntimeException;
+
+ /**
+ * The method builds an OData response for an OData function Import Request from a registered processor method's
+ * return parameter. The return parameter is a collection of objects.
+ * @param functionImportUriInfo is an information about the request URI
+ * @param result is a method's return parameter is a collection of objects.
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ */
+ public ODataResponse build(final GetFunctionImportUriInfo functionImportUriInfo, final List<Object> resultList,
+ final String contentType)
+ throws ODataJPARuntimeException, ODataNotFoundException;
+
+ /**
+ * The method builds an OData response for an OData Read Link Request from a read JPA Entity and its related JPA
+ * Entities.
+ * @param readLinkUriInfo is an information about the request URI
+ * @param jpaEntity is a null or non null read JPA Entity and its related JPA Entities.
+ * @param contentType of the response
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataNotFoundException
+ * @throws ODataJPARuntimeException
+ */
+ public ODataResponse build(final GetEntityLinkUriInfo readLinkUriInfo, final Object jpaEntity,
+ final String contentType) throws ODataNotFoundException,
+ ODataJPARuntimeException;
+
+ /**
+ * The method builds an OData response for an OData Query Link Request from a queried JPA Entity and its related JPA
+ * Entities.
+ * @param queryLinkUriInfo is an information about the request URI
+ * @param jpaEntity is an empty or non empty list of queried JPA Entities
+ * @param contentType of the response
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ */
+ public ODataResponse build(final GetEntitySetLinksUriInfo queryLinkUriInfo, final List<Object> jpaEntity,
+ final String contentType) throws ODataJPARuntimeException;
+
+ /**
+ * The method builds an OData response from a count representing total number of JPA Entities
+ * @param jpaEntityCount is the count value
+ * @return an instance of type {@link org.apache.olingo.odata2.api.processor.ODataResponse}
+ * @throws ODataJPARuntimeException
+ */
+ public ODataResponse build(final long jpaEntityCount)
+ throws ODataJPARuntimeException;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
index 50f84f6..3d5010d 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/factory/ODataJPAAccessFactory.java
@@ -23,6 +23,7 @@ import java.util.Locale;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService;
/**
@@ -33,6 +34,7 @@ import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageServi
* <li>OData JPA Processor of type {@link org.apache.olingo.odata2.api.processor.ODataSingleProcessor}</li>
* <li>JPA EDM Provider of type {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider}</li>
* <li>OData JPA Context {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}</li>
+ * <li>OData JPA Response Builder {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder}</li>
* </ul>
* </p>
*
@@ -79,4 +81,14 @@ public interface ODataJPAAccessFactory {
* @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService}
*/
public ODataJPAMessageService getODataJPAMessageService(Locale locale);
+
+ /**
+ * @param oDataJPAContext
+ * an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}.
+ * The context should be initialized properly and cannot be null.
+ *
+ * The method creates an instance of OData Response Builder for building OData Responses from a JPA Entity.
+ * @return an instance of type{@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder}
+ */
+ public ODataJPAResponseBuilder getODataJPAResponseBuilder(ODataJPAContext oDataJPAContext);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
index 320fce7..96782b8 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefault.java
@@ -50,10 +50,10 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
throws ODataException {
- List<?> jpaEntities = jpaProcessor.process(uriParserResultView);
+ List<Object> jpaEntities = jpaProcessor.process(uriParserResultView);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntities, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, jpaEntities, contentType);
return oDataResponse;
}
@@ -65,7 +65,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
Object jpaEntity = jpaProcessor.process(uriParserResultView);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, jpaEntity, contentType);
return oDataResponse;
}
@@ -76,7 +76,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
long jpaEntityCount = jpaProcessor.process(uriParserResultView);
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntityCount, oDataJPAContext);
+ ODataResponse oDataResponse = responseBuilder.build(jpaEntityCount);
return oDataResponse;
}
@@ -87,7 +87,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
long jpaEntityCount = jpaProcessor.process(uriInfo);
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntityCount, oDataJPAContext);
+ ODataResponse oDataResponse = responseBuilder.build(jpaEntityCount);
return oDataResponse;
}
@@ -99,7 +99,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, createdJpaEntityList, contentType);
return oDataResponse;
}
@@ -110,7 +110,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView);
+ ODataResponse oDataResponse = responseBuilder.build(uriParserResultView, jpaEntity);
return oDataResponse;
}
@@ -121,7 +121,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView);
+ ODataResponse oDataResponse = responseBuilder.build(uriParserResultView, deletedObj);
return oDataResponse;
}
@@ -132,7 +132,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(resultEntity, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, resultEntity, contentType);
return oDataResponse;
}
@@ -144,7 +144,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
List<Object> result = jpaProcessor.process(uriParserResultView);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(result, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, result, contentType);
return oDataResponse;
}
@@ -156,7 +156,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
Object jpaEntity = jpaProcessor.process(uriParserResultView);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, jpaEntity, contentType);
return oDataResponse;
}
@@ -168,7 +168,7 @@ public class ODataJPAProcessorDefault extends ODataJPAProcessor {
List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
+ responseBuilder.build(uriParserResultView, jpaEntity, contentType);
return oDataResponse;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java
deleted file mode 100644
index f63e9d3..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilder.java
+++ /dev/null
@@ -1,629 +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.odata2.jpa.processor.core;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.UriParser;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
-import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser;
-import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAExpandCallBack;
-
-public final class ODataJPAResponseBuilder {
-
- /* Response for Read Entity Set */
- public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView,
- final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException {
-
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
- List<ArrayList<NavigationPropertySegment>> expandList = null;
-
- try {
- edmEntityType = resultsView.getTargetEntitySet().getEntityType();
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- final List<SelectItem> selectedItems = resultsView.getSelect();
- if (selectedItems != null && selectedItems.size() > 0) {
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap =
- jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, edmEntityType));
- edmEntityList.add(edmPropertyValueMap);
- }
- } else {
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
- edmEntityList.add(edmPropertyValueMap);
- }
- }
- expandList = resultsView.getExpand();
- if (expandList != null && expandList.size() != 0) {
- int count = 0;
- List<EdmNavigationProperty> edmNavPropertyList = constructListofNavProperty(expandList);
- for (Object jpaEntity : jpaEntities) {
- Map<String, Object> relationShipMap = edmEntityList.get(count);
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, edmNavPropertyList);
- relationShipMap.putAll(navigationMap);
- count++;
- }
- }
-
- EntityProviderWriteProperties feedProperties = null;
-
- feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList);
- odataResponse =
- EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties);
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
-
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
- }
-
- /* Response for Read Entity */
- public static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
- ODataNotFoundException {
-
- List<ArrayList<NavigationPropertySegment>> expandList = null;
- if (jpaEntity == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- edmEntityType = resultsView.getTargetEntitySet().getEntityType();
- Map<String, Object> edmPropertyValueMap = null;
-
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- final List<SelectItem> selectedItems = resultsView.getSelect();
- if (selectedItems != null && selectedItems.size() > 0) {
- edmPropertyValueMap =
- jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, resultsView
- .getTargetEntitySet().getEntityType()));
- } else {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
- }
-
- expandList = resultsView.getExpand();
- if (expandList != null && expandList.size() != 0) {
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, constructListofNavProperty(expandList));
- edmPropertyValueMap.putAll(navigationMap);
- }
- EntityProviderWriteProperties feedProperties = null;
- feedProperties = getEntityProviderProperties(oDataJPAContext, resultsView);
- odataResponse =
- EntityProvider.writeEntry(contentType, resultsView.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
-
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
-
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
- }
-
- /* Response for $count */
- public static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext)
- throws ODataJPARuntimeException {
-
- ODataResponse odataResponse = null;
- try {
- odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount));
- odataResponse = ODataResponse.fromResponse(odataResponse).build();
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- return odataResponse;
- }
-
- /* Response for Create Entity */
- @SuppressWarnings("unchecked")
- public static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
- ODataNotFoundException {
-
- if (createdObjectList == null || createdObjectList.size() == 0 || createdObjectList.get(0) == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- edmEntityType = uriInfo.getTargetEntitySet().getEntityType();
- Map<String, Object> edmPropertyValueMap = null;
-
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(createdObjectList.get(0), edmEntityType);
-
- List<ArrayList<NavigationPropertySegment>> expandList = null;
- if (createdObjectList.get(1) != null
- && ((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1)).size() > 0) {
- expandList = getExpandList((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1));
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(createdObjectList.get(0),
- constructListofNavProperty(expandList));
- edmPropertyValueMap.putAll(navigationMap);
- }
- EntityProviderWriteProperties feedProperties = null;
- try {
- feedProperties = getEntityProviderPropertiesforPost(oDataJPAContext, uriInfo, expandList);
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- odataResponse =
- EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
-
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.CREATED).build();
-
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
- }
-
- /* Response for Update Entity */
- public static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo)
- throws ODataJPARuntimeException, ODataNotFoundException {
- if (updatedObject == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- }
-
- /* Response for Delete Entity */
- public static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo)
- throws ODataJPARuntimeException, ODataNotFoundException {
-
- if (deletedObject == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- }
-
- /* Response for Function Import Single Result */
- public static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView)
- throws ODataJPARuntimeException {
-
- try {
- final EdmFunctionImport functionImport = resultsView.getFunctionImport();
- final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
-
- if (result != null) {
- ODataResponse response = null;
-
- final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null);
- response = EntityProvider.writeText(value);
-
- return ODataResponse.fromResponse(response).build();
- } else {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- }
-
- /* Response for Function Import Multiple Result */
- public static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
- ODataNotFoundException {
-
- ODataResponse odataResponse = null;
-
- if (resultList != null && !resultList.isEmpty()) {
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- EdmType edmType = null;
- EdmFunctionImport functionImport = null;
- Map<String, Object> edmPropertyValueMap = null;
- List<Map<String, Object>> edmEntityList = null;
- Object result = null;
- try {
- EntityProviderWriteProperties feedProperties = null;
-
- feedProperties =
- EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
- .build();
-
- functionImport = resultsView.getFunctionImport();
- edmType = functionImport.getReturnType().getType();
-
- if (edmType.getKind().equals(EdmTypeKind.ENTITY) || edmType.getKind().equals(EdmTypeKind.COMPLEX)) {
- if (functionImport.getReturnType().getMultiplicity().equals(EdmMultiplicity.MANY)) {
- edmEntityList = new ArrayList<Map<String, Object>>();
- for (Object jpaEntity : resultList) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, (EdmStructuralType) edmType);
- edmEntityList.add(edmPropertyValueMap);
- }
- result = edmEntityList;
- } else {
-
- Object resultObject = resultList.get(0);
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(resultObject, (EdmStructuralType) edmType);
-
- result = edmPropertyValueMap;
- }
-
- } else if (edmType.getKind().equals(EdmTypeKind.SIMPLE)) {
- result = resultList.get(0);
- }
-
- odataResponse =
- EntityProvider.writeFunctionImport(contentType, resultsView.getFunctionImport(), result, feedProperties);
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- } else {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- return odataResponse;
- }
-
- /* Response for Read Entity Link */
- public static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataNotFoundException,
- ODataJPARuntimeException {
-
- if (jpaEntity == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- EdmEntitySet entitySet = resultsView.getTargetEntitySet();
- edmEntityType = entitySet.getEntityType();
- Map<String, Object> edmPropertyValueMap = null;
-
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType.getKeyProperties());
-
- EntityProviderWriteProperties entryProperties =
- EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
- .build();
-
- ODataResponse response = EntityProvider.writeLink(contentType, entitySet, edmPropertyValueMap, entryProperties);
-
- odataResponse = ODataResponse.fromResponse(response).build();
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
-
- }
-
- return odataResponse;
- }
-
- /* Response for Read Entity Links */
- public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException {
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- EdmEntitySet entitySet = resultsView.getTargetEntitySet();
- edmEntityType = entitySet.getEntityType();
- List<EdmProperty> keyProperties = edmEntityType.getKeyProperties();
-
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
- JPAEntityParser jpaResultParser = new JPAEntityParser();
-
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, keyProperties);
- edmEntityList.add(edmPropertyValueMap);
- }
-
- Integer count = null;
- if (resultsView.getInlineCount() != null) {
- if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
- // when $skip and/or $top is present with $inlinecount
- count = getInlineCountForNonFilterQueryLinks(edmEntityList, resultsView);
- } else {
- // In all other cases
- count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
- }
- }
-
- ODataContext context = oDataJPAContext.getODataContext();
- EntityProviderWriteProperties entryProperties =
- EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).inlineCountType(
- resultsView.getInlineCount()).inlineCount(count).build();
-
- odataResponse = EntityProvider.writeLinks(contentType, entitySet, edmEntityList, entryProperties);
-
- odataResponse = ODataResponse.fromResponse(odataResponse).build();
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
-
- }
-
- /*
- * This method handles $inlinecount request. It also modifies the list of results in case of
- * $inlinecount and $top/$skip combinations. Specific to LinksUriInfo.
- *
- * @param edmEntityList
- *
- * @param resultsView
- *
- * @return
- */
- private static Integer getInlineCountForNonFilterQueryLinks(final List<Map<String, Object>> edmEntityList,
- final GetEntitySetLinksUriInfo resultsView) {
- // when $skip and/or $top is present with $inlinecount, first get the total count
- Integer count = null;
- if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
- if (resultsView.getSkip() != null || resultsView.getTop() != null) {
- count = edmEntityList.size();
- // Now update the list
- if (resultsView.getSkip() != null) {
- // Index checks to avoid IndexOutOfBoundsException
- if (resultsView.getSkip() > edmEntityList.size()) {
- edmEntityList.clear();
- return count;
- }
- edmEntityList.subList(0, resultsView.getSkip()).clear();
- }
- if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
- edmEntityList.subList(0, resultsView.getTop());
- }
- }
- }// Inlinecount of None is handled by default - null
- return count;
- }
-
- /*
- * Method to build the entity provider Property.Callbacks for $expand would
- * be registered here
- */
- private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
- final GetEntitySetUriInfo resultsView, final List<Map<String, Object>> edmEntityList)
- throws ODataJPARuntimeException {
- ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
-
- Integer count = null;
- if (resultsView.getInlineCount() != null) {
- if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
- // when $skip and/or $top is present with $inlinecount
- count = getInlineCountForNonFilterQueryEntitySet(edmEntityList, resultsView);
- } else {
- // In all other cases
- count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
- }
- }
-
- try {
- entityFeedPropertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
- entityFeedPropertiesBuilder.inlineCount(count);
- entityFeedPropertiesBuilder.inlineCountType(resultsView.getInlineCount());
- ExpandSelectTreeNode expandSelectTree =
- UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
- entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
- .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
- entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return entityFeedPropertiesBuilder.build();
- }
-
- /*
- * This method handles $inlinecount request. It also modifies the list of results in case of
- * $inlinecount and $top/$skip combinations. Specific to Entity Set.
- */
- private static Integer getInlineCountForNonFilterQueryEntitySet(final List<Map<String, Object>> edmEntityList,
- final GetEntitySetUriInfo resultsView) {
- // when $skip and/or $top is present with $inlinecount, first get the total count
- Integer count = null;
- if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
- if (resultsView.getSkip() != null || resultsView.getTop() != null) {
- count = edmEntityList.size();
- // Now update the list
- if (resultsView.getSkip() != null) {
- // Index checks to avoid IndexOutOfBoundsException
- if (resultsView.getSkip() > edmEntityList.size()) {
- edmEntityList.clear();
- return count;
- }
- edmEntityList.subList(0, resultsView.getSkip()).clear();
- }
- if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
- edmEntityList.retainAll(edmEntityList.subList(0, resultsView.getTop()));
- }
- }
- }// Inlinecount of None is handled by default - null
- return count;
- }
-
- private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
- final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
- ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
- ExpandSelectTreeNode expandSelectTree = null;
- try {
- entityFeedPropertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
- expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
- entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
- entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
- .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return entityFeedPropertiesBuilder.build();
- }
-
- private static EntityProviderWriteProperties getEntityProviderPropertiesforPost(
- final ODataJPAContext odataJPAContext, final PostUriInfo resultsView,
- final List<ArrayList<NavigationPropertySegment>> expandList) throws ODataJPARuntimeException {
- ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
- ExpandSelectTreeNode expandSelectTree = null;
- try {
- entityFeedPropertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
- expandSelectTree = UriParser.createExpandSelectTree(null, expandList);
- entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
- entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
- .getPathInfo().getServiceRoot(), expandSelectTree, expandList));
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return entityFeedPropertiesBuilder.build();
- }
-
- private static List<ArrayList<NavigationPropertySegment>> getExpandList(
- final Map<EdmNavigationProperty, EdmEntitySet> navPropEntitySetMap) {
- List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
- ArrayList<NavigationPropertySegment> navigationPropertySegmentList = new ArrayList<NavigationPropertySegment>();
- for (Map.Entry<EdmNavigationProperty, EdmEntitySet> entry : navPropEntitySetMap.entrySet()) {
- final EdmNavigationProperty edmNavigationProperty = entry.getKey();
- final EdmEntitySet edmEntitySet = entry.getValue();
- NavigationPropertySegment navigationPropertySegment = new NavigationPropertySegment() {
-
- @Override
- public EdmEntitySet getTargetEntitySet() {
- return edmEntitySet;
- }
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return edmNavigationProperty;
- }
- };
- navigationPropertySegmentList.add(navigationPropertySegment);
- }
- expandList.add(navigationPropertySegmentList);
- return expandList;
- }
-
- private static List<EdmProperty> buildSelectItemList(final List<SelectItem> selectItems, final EdmEntityType entity)
- throws ODataJPARuntimeException {
- boolean flag = false;
- List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
- try {
- for (SelectItem selectItem : selectItems) {
- selectPropertyList.add(selectItem.getProperty());
- }
- for (EdmProperty keyProperty : entity.getKeyProperties()) {
- flag = true;
- for (SelectItem selectedItem : selectItems) {
- if (selectedItem.getProperty().equals(keyProperty)) {
- flag = false;
- break;
- }
- }
- if (flag == true) {
- selectPropertyList.add(keyProperty);
- }
- }
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- return selectPropertyList;
- }
-
- private static List<EdmNavigationProperty> constructListofNavProperty(
- final List<ArrayList<NavigationPropertySegment>> expandList) {
- List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
- for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) {
- navigationPropertyList.add(navpropSegment.get(0).getNavigationProperty());
- }
- return navigationPropertyList;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
new file mode 100644
index 0000000..c11713c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderDefault.java
@@ -0,0 +1,646 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.UriParser;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAExpandCallBack;
+
+public final class ODataJPAResponseBuilderDefault implements ODataJPAResponseBuilder {
+
+ private final ODataJPAContext oDataJPAContext;
+
+ public ODataJPAResponseBuilderDefault(final ODataJPAContext context) {
+ oDataJPAContext = context;
+ }
+
+ /* Response for Read Entity Set */
+ @Override
+ public ODataResponse build(final GetEntitySetUriInfo resultsView, final List<Object> jpaEntities,
+ final String contentType) throws ODataJPARuntimeException {
+
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+ List<ArrayList<NavigationPropertySegment>> expandList = null;
+
+ try {
+ edmEntityType = resultsView.getTargetEntitySet().getEntityType();
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmPropertyValueMap = null;
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ final List<SelectItem> selectedItems = resultsView.getSelect();
+ if (selectedItems != null && selectedItems.size() > 0) {
+ for (Object jpaEntity : jpaEntities) {
+ edmPropertyValueMap =
+ jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, edmEntityType));
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ } else {
+ for (Object jpaEntity : jpaEntities) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ }
+ expandList = resultsView.getExpand();
+ if (expandList != null && expandList.size() != 0) {
+ int count = 0;
+ List<EdmNavigationProperty> edmNavPropertyList = constructListofNavProperty(expandList);
+ for (Object jpaEntity : jpaEntities) {
+ Map<String, Object> relationShipMap = edmEntityList.get(count);
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, edmNavPropertyList);
+ relationShipMap.putAll(navigationMap);
+ count++;
+ }
+ }
+
+ EntityProviderWriteProperties feedProperties = null;
+
+ feedProperties = getEntityProviderProperties(oDataJPAContext, resultsView, edmEntityList);
+ odataResponse =
+ EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties);
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
+
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Read Entity */
+ @Override
+ public ODataResponse build(final GetEntityUriInfo resultsView, final Object jpaEntity,
+ final String contentType) throws ODataJPARuntimeException,
+ ODataNotFoundException {
+
+ List<ArrayList<NavigationPropertySegment>> expandList = null;
+ if (jpaEntity == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ edmEntityType = resultsView.getTargetEntitySet().getEntityType();
+ Map<String, Object> edmPropertyValueMap = null;
+
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ final List<SelectItem> selectedItems = resultsView.getSelect();
+ if (selectedItems != null && selectedItems.size() > 0) {
+ edmPropertyValueMap =
+ jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, resultsView
+ .getTargetEntitySet().getEntityType()));
+ } else {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
+ }
+
+ expandList = resultsView.getExpand();
+ if (expandList != null && expandList.size() != 0) {
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, constructListofNavProperty(expandList));
+ edmPropertyValueMap.putAll(navigationMap);
+ }
+ EntityProviderWriteProperties feedProperties = null;
+ feedProperties = getEntityProviderProperties(oDataJPAContext, resultsView);
+ odataResponse =
+ EntityProvider.writeEntry(contentType, resultsView.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
+
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
+
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for $count */
+ @Override
+ public ODataResponse build(final long jpaEntityCount)
+ throws ODataJPARuntimeException {
+
+ ODataResponse odataResponse = null;
+ try {
+ odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount));
+ odataResponse = ODataResponse.fromResponse(odataResponse).build();
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ return odataResponse;
+ }
+
+ /* Response for Create Entity */
+ @SuppressWarnings("unchecked")
+ @Override
+ public ODataResponse build(final PostUriInfo uriInfo, final List<Object> createdObjectList,
+ final String contentType) throws ODataJPARuntimeException,
+ ODataNotFoundException {
+
+ if (createdObjectList == null || createdObjectList.size() == 0 || createdObjectList.get(0) == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ edmEntityType = uriInfo.getTargetEntitySet().getEntityType();
+ Map<String, Object> edmPropertyValueMap = null;
+
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(createdObjectList.get(0), edmEntityType);
+
+ List<ArrayList<NavigationPropertySegment>> expandList = null;
+ if (createdObjectList.get(1) != null
+ && ((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1)).size() > 0) {
+ expandList = getExpandList((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1));
+ HashMap<String, Object> navigationMap =
+ jpaResultParser.parse2EdmNavigationValueMap(createdObjectList.get(0),
+ constructListofNavProperty(expandList));
+ edmPropertyValueMap.putAll(navigationMap);
+ }
+ EntityProviderWriteProperties feedProperties = null;
+ try {
+ feedProperties = getEntityProviderPropertiesforPost(oDataJPAContext, uriInfo, expandList);
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ odataResponse =
+ EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
+
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.CREATED).build();
+
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Update Entity */
+ @Override
+ public ODataResponse build(final PutMergePatchUriInfo putUriInfo, final Object updatedObject)
+ throws ODataJPARuntimeException, ODataNotFoundException {
+ if (updatedObject == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
+ }
+
+ /* Response for Delete Entity */
+ @Override
+ public ODataResponse build(final DeleteUriInfo deleteUriInfo, final Object deletedObject)
+ throws ODataJPARuntimeException, ODataNotFoundException {
+
+ if (deletedObject == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
+ }
+
+ /* Response for Function Import Single Result */
+ @Override
+ public ODataResponse build(final GetFunctionImportUriInfo resultsView, final Object result)
+ throws ODataJPARuntimeException {
+
+ try {
+ final EdmFunctionImport functionImport = resultsView.getFunctionImport();
+ final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
+
+ if (result != null) {
+ ODataResponse response = null;
+
+ final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null);
+ response = EntityProvider.writeText(value);
+
+ return ODataResponse.fromResponse(response).build();
+ } else {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+ }
+
+ /* Response for Function Import Multiple Result */
+ @Override
+ public ODataResponse build(final GetFunctionImportUriInfo resultsView, final List<Object> resultList,
+ final String contentType) throws ODataJPARuntimeException,
+ ODataNotFoundException {
+
+ ODataResponse odataResponse = null;
+
+ if (resultList != null && !resultList.isEmpty()) {
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ EdmType edmType = null;
+ EdmFunctionImport functionImport = null;
+ Map<String, Object> edmPropertyValueMap = null;
+ List<Map<String, Object>> edmEntityList = null;
+ Object result = null;
+ try {
+ EntityProviderWriteProperties feedProperties = null;
+
+ feedProperties =
+ EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
+ .build();
+
+ functionImport = resultsView.getFunctionImport();
+ edmType = functionImport.getReturnType().getType();
+
+ if (edmType.getKind().equals(EdmTypeKind.ENTITY) || edmType.getKind().equals(EdmTypeKind.COMPLEX)) {
+ if (functionImport.getReturnType().getMultiplicity().equals(EdmMultiplicity.MANY)) {
+ edmEntityList = new ArrayList<Map<String, Object>>();
+ for (Object jpaEntity : resultList) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, (EdmStructuralType) edmType);
+ edmEntityList.add(edmPropertyValueMap);
+ }
+ result = edmEntityList;
+ } else {
+
+ Object resultObject = resultList.get(0);
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(resultObject, (EdmStructuralType) edmType);
+
+ result = edmPropertyValueMap;
+ }
+
+ } else if (edmType.getKind().equals(EdmTypeKind.SIMPLE)) {
+ result = resultList.get(0);
+ }
+
+ odataResponse =
+ EntityProvider.writeFunctionImport(contentType, resultsView.getFunctionImport(), result, feedProperties);
+ odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (EntityProviderException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ } else {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Read Entity Link */
+ @Override
+ public ODataResponse build(final GetEntityLinkUriInfo resultsView, final Object jpaEntity,
+ final String contentType) throws ODataNotFoundException,
+ ODataJPARuntimeException {
+
+ if (jpaEntity == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ EdmEntitySet entitySet = resultsView.getTargetEntitySet();
+ edmEntityType = entitySet.getEntityType();
+ Map<String, Object> edmPropertyValueMap = null;
+
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType.getKeyProperties());
+
+ EntityProviderWriteProperties entryProperties =
+ EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
+ .build();
+
+ ODataResponse response = EntityProvider.writeLink(contentType, entitySet, edmPropertyValueMap, entryProperties);
+
+ odataResponse = ODataResponse.fromResponse(response).build();
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+
+ }
+
+ return odataResponse;
+ }
+
+ /* Response for Read Entity Links */
+ @Override
+ public ODataResponse build(final GetEntitySetLinksUriInfo resultsView, final List<Object> jpaEntities,
+ final String contentType) throws ODataJPARuntimeException {
+ EdmEntityType edmEntityType = null;
+ ODataResponse odataResponse = null;
+
+ try {
+
+ EdmEntitySet entitySet = resultsView.getTargetEntitySet();
+ edmEntityType = entitySet.getEntityType();
+ List<EdmProperty> keyProperties = edmEntityType.getKeyProperties();
+
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmPropertyValueMap = null;
+ JPAEntityParser jpaResultParser = new JPAEntityParser();
+
+ for (Object jpaEntity : jpaEntities) {
+ edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, keyProperties);
+ edmEntityList.add(edmPropertyValueMap);
+ }
+
+ Integer count = null;
+ if (resultsView.getInlineCount() != null) {
+ if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
+ // when $skip and/or $top is present with $inlinecount
+ count = getInlineCountForNonFilterQueryLinks(edmEntityList, resultsView);
+ } else {
+ // In all other cases
+ count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
+ }
+ }
+
+ ODataContext context = oDataJPAContext.getODataContext();
+ EntityProviderWriteProperties entryProperties =
+ EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).inlineCountType(
+ resultsView.getInlineCount()).inlineCount(count).build();
+
+ odataResponse = EntityProvider.writeLinks(contentType, entitySet, edmEntityList, entryProperties);
+
+ odataResponse = ODataResponse.fromResponse(odataResponse).build();
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+
+ return odataResponse;
+
+ }
+
+ /*
+ * This method handles $inlinecount request. It also modifies the list of results in case of
+ * $inlinecount and $top/$skip combinations. Specific to LinksUriInfo.
+ *
+ * @param edmEntityList
+ *
+ * @param resultsView
+ *
+ * @return
+ */
+ private static Integer getInlineCountForNonFilterQueryLinks(final List<Map<String, Object>> edmEntityList,
+ final GetEntitySetLinksUriInfo resultsView) {
+ // when $skip and/or $top is present with $inlinecount, first get the total count
+ Integer count = null;
+ if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
+ if (resultsView.getSkip() != null || resultsView.getTop() != null) {
+ count = edmEntityList.size();
+ // Now update the list
+ if (resultsView.getSkip() != null) {
+ // Index checks to avoid IndexOutOfBoundsException
+ if (resultsView.getSkip() > edmEntityList.size()) {
+ edmEntityList.clear();
+ return count;
+ }
+ edmEntityList.subList(0, resultsView.getSkip()).clear();
+ }
+ if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
+ edmEntityList.subList(0, resultsView.getTop());
+ }
+ }
+ }// Inlinecount of None is handled by default - null
+ return count;
+ }
+
+ /*
+ * Method to build the entity provider Property.Callbacks for $expand would
+ * be registered here
+ */
+ private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
+ final GetEntitySetUriInfo resultsView, final List<Map<String, Object>> edmEntityList)
+ throws ODataJPARuntimeException {
+ ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
+
+ Integer count = null;
+ if (resultsView.getInlineCount() != null) {
+ if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
+ // when $skip and/or $top is present with $inlinecount
+ count = getInlineCountForNonFilterQueryEntitySet(edmEntityList, resultsView);
+ } else {
+ // In all other cases
+ count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
+ }
+ }
+
+ try {
+ entityFeedPropertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
+ entityFeedPropertiesBuilder.inlineCount(count);
+ entityFeedPropertiesBuilder.inlineCountType(resultsView.getInlineCount());
+ ExpandSelectTreeNode expandSelectTree =
+ UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
+ entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
+ .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
+ entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
+
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return entityFeedPropertiesBuilder.build();
+ }
+
+ /*
+ * This method handles $inlinecount request. It also modifies the list of results in case of
+ * $inlinecount and $top/$skip combinations. Specific to Entity Set.
+ */
+ private static Integer getInlineCountForNonFilterQueryEntitySet(final List<Map<String, Object>> edmEntityList,
+ final GetEntitySetUriInfo resultsView) {
+ // when $skip and/or $top is present with $inlinecount, first get the total count
+ Integer count = null;
+ if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
+ if (resultsView.getSkip() != null || resultsView.getTop() != null) {
+ count = edmEntityList.size();
+ // Now update the list
+ if (resultsView.getSkip() != null) {
+ // Index checks to avoid IndexOutOfBoundsException
+ if (resultsView.getSkip() > edmEntityList.size()) {
+ edmEntityList.clear();
+ return count;
+ }
+ edmEntityList.subList(0, resultsView.getSkip()).clear();
+ }
+ if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
+ edmEntityList.retainAll(edmEntityList.subList(0, resultsView.getTop()));
+ }
+ }
+ }// Inlinecount of None is handled by default - null
+ return count;
+ }
+
+ private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
+ final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
+ ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
+ ExpandSelectTreeNode expandSelectTree = null;
+ try {
+ entityFeedPropertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
+ expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
+ entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
+ entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
+ .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return entityFeedPropertiesBuilder.build();
+ }
+
+ private static EntityProviderWriteProperties getEntityProviderPropertiesforPost(
+ final ODataJPAContext odataJPAContext, final PostUriInfo resultsView,
+ final List<ArrayList<NavigationPropertySegment>> expandList) throws ODataJPARuntimeException {
+ ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
+ ExpandSelectTreeNode expandSelectTree = null;
+ try {
+ entityFeedPropertiesBuilder =
+ EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
+ expandSelectTree = UriParser.createExpandSelectTree(null, expandList);
+ entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
+ entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
+ .getPathInfo().getServiceRoot(), expandSelectTree, expandList));
+ } catch (ODataException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
+ }
+
+ return entityFeedPropertiesBuilder.build();
+ }
+
+ private static List<ArrayList<NavigationPropertySegment>> getExpandList(
+ final Map<EdmNavigationProperty, EdmEntitySet> navPropEntitySetMap) {
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navigationPropertySegmentList = new ArrayList<NavigationPropertySegment>();
+ for (Map.Entry<EdmNavigationProperty, EdmEntitySet> entry : navPropEntitySetMap.entrySet()) {
+ final EdmNavigationProperty edmNavigationProperty = entry.getKey();
+ final EdmEntitySet edmEntitySet = entry.getValue();
+ NavigationPropertySegment navigationPropertySegment = new NavigationPropertySegment() {
+
+ @Override
+ public EdmEntitySet getTargetEntitySet() {
+ return edmEntitySet;
+ }
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty() {
+ return edmNavigationProperty;
+ }
+ };
+ navigationPropertySegmentList.add(navigationPropertySegment);
+ }
+ expandList.add(navigationPropertySegmentList);
+ return expandList;
+ }
+
+ private static List<EdmProperty> buildSelectItemList(final List<SelectItem> selectItems, final EdmEntityType entity)
+ throws ODataJPARuntimeException {
+ boolean flag = false;
+ List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
+ try {
+ for (SelectItem selectItem : selectItems) {
+ selectPropertyList.add(selectItem.getProperty());
+ }
+ for (EdmProperty keyProperty : entity.getKeyProperties()) {
+ flag = true;
+ for (SelectItem selectedItem : selectItems) {
+ if (selectedItem.getProperty().equals(keyProperty)) {
+ flag = false;
+ break;
+ }
+ }
+ if (flag == true) {
+ selectPropertyList.add(keyProperty);
+ }
+ }
+
+ } catch (EdmException e) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
+ }
+ return selectPropertyList;
+ }
+
+ private static List<EdmNavigationProperty> constructListofNavProperty(
+ final List<ArrayList<NavigationPropertySegment>> expandList) {
+ List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
+ for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) {
+ navigationPropertyList.add(navpropSegment.get(0).getNavigationProperty());
+ }
+ return navigationPropertyList;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f8638bb7/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
index d27713f..789afde 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/jpa/processor/core/factory/ODataJPAFactoryImpl.java
@@ -23,21 +23,23 @@ import java.util.Locale;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAResponseBuilder;
import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
import org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext.JPAMethodContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAMessageService;
import org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory;
import org.apache.olingo.odata2.jpa.processor.api.factory.JPQLBuilderFactory;
import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory;
import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextView;
-import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
import org.apache.olingo.odata2.jpa.processor.core.ODataJPAProcessorDefault;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAResponseBuilderDefault;
import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAFunctionContext;
import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImpl;
import org.apache.olingo.odata2.jpa.processor.core.access.model.JPAEdmMappingModelService;
@@ -195,6 +197,11 @@ public class ODataJPAFactoryImpl extends ODataJPAFactory {
return ODataJPAMessageServiceDefault.getInstance(locale);
}
+ @Override
+ public ODataJPAResponseBuilder getODataJPAResponseBuilder(final ODataJPAContext oDataJPAContext) {
+ return new ODataJPAResponseBuilderDefault(oDataJPAContext);
+ }
+
}
private static class JPAAccessFactoryImpl implements JPAAccessFactory {
[02/47] git commit: [OLINGO-83] Renamed test packages
Posted by tb...@apache.org.
[OLINGO-83] Renamed test packages
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/636eed23
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/636eed23
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/636eed23
Branch: refs/heads/ODataServlet
Commit: 636eed236af0814653ff8346ab84f46168e718aa
Parents: 33aaa3a
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Dec 20 16:10:24 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Dec 20 16:13:13 2013 +0100
----------------------------------------------------------------------
.../core/AnnotationServiceFactoryImpl.java | 12 +-
.../core/AnnotationServiceFactoryImplTest.java | 74 +++
.../datasource/AnnotationsInMemoryDsTest.java | 628 +++++++++++++++++++
.../core/edm/AnnotationEdmProviderTest.java | 463 ++++++++++++++
.../processor/core/model/Building.java | 99 +++
.../annotation/processor/core/model/City.java | 61 ++
.../processor/core/model/Employee.java | 187 ++++++
.../processor/core/model/Location.java | 60 ++
.../processor/core/model/Manager.java | 47 ++
.../core/model/ModelSharedConstants.java | 25 +
.../annotation/processor/core/model/Photo.java | 128 ++++
.../processor/core/model/RefBase.java | 55 ++
.../processor/core/model/ResourceHelper.java | 66 ++
.../annotation/processor/core/model/Room.java | 93 +++
.../annotation/processor/core/model/Team.java | 81 +++
.../data/AnnotationsInMemoryDsTest.java | 628 -------------------
.../edm/AnnotationEdmProviderTest.java | 462 --------------
.../odata2/core/annotation/model/Building.java | 99 ---
.../odata2/core/annotation/model/City.java | 61 --
.../odata2/core/annotation/model/Employee.java | 187 ------
.../odata2/core/annotation/model/Location.java | 60 --
.../odata2/core/annotation/model/Manager.java | 47 --
.../annotation/model/ModelSharedConstants.java | 25 -
.../odata2/core/annotation/model/Photo.java | 128 ----
.../odata2/core/annotation/model/RefBase.java | 55 --
.../core/annotation/model/ResourceHelper.java | 66 --
.../odata2/core/annotation/model/Room.java | 93 ---
.../odata2/core/annotation/model/Team.java | 81 ---
28 files changed, 2068 insertions(+), 2003 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
index 9c673a3..7947d6b 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImpl.java
@@ -29,20 +29,10 @@ import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.rt.RuntimeDelegate;
/**
- * ODataServiceFactory implementation based on ListProcessor
+ * AnnotationServiceFactoryInstance (ODataServiceFactory) implementation based on ListProcessor
* in combination with Annotation-Support-Classes for EdmProvider, DataSource and ValueAccess.
*/
public class AnnotationServiceFactoryImpl implements AnnotationServiceFactoryInstance {
-
- /**
- * Create an instance which further can create an {@link ODataService}.
- *
- * @return instance which further can create an {@link ODataService}.
- */
- public AnnotationServiceFactoryInstance createInstance() {
- return new AnnotationServiceFactoryImpl();
- }
-
/**
* {@inheritDoc}
*/
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java
new file mode 100644
index 0000000..4feaac7
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/AnnotationServiceFactoryImplTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.annotation.processor.core.model.Employee;
+import org.apache.olingo.odata2.annotation.processor.core.model.Manager;
+import org.apache.olingo.odata2.annotation.processor.core.model.Photo;
+import org.apache.olingo.odata2.annotation.processor.core.model.RefBase;
+import org.apache.olingo.odata2.annotation.processor.core.model.Room;
+import org.apache.olingo.odata2.annotation.processor.core.model.Team;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AnnotationServiceFactoryImplTest {
+
+ @Test
+ public void createFromPackage() throws ODataException {
+ AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
+ ODataService service = factory.createAnnotationService(Building.class.getPackage().getName());
+
+ Assert.assertNotNull(service);
+ }
+
+ @Test
+ public void createFromAnnotatedClasses() throws ODataException {
+ AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
+ final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+ annotatedClasses.add(RefBase.class);
+ annotatedClasses.add(Building.class);
+ annotatedClasses.add(Employee.class);
+ annotatedClasses.add(Manager.class);
+ annotatedClasses.add(Photo.class);
+ annotatedClasses.add(Room.class);
+ annotatedClasses.add(Team.class);
+ ODataService service = factory.createAnnotationService(annotatedClasses);
+
+ Assert.assertNotNull(service);
+ }
+
+ @Test(expected=ODataException.class)
+ public void createFromClasses() throws ODataException {
+ AnnotationServiceFactoryImpl factory = new AnnotationServiceFactoryImpl();
+
+ final Collection<Class<?>> notAnnotatedClasses = new ArrayList<Class<?>>();
+ notAnnotatedClasses.add(String.class);
+ notAnnotatedClasses.add(Long.class);
+ ODataService service = factory.createAnnotationService(notAnnotatedClasses);
+
+ Assert.assertNotNull(service);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
new file mode 100644
index 0000000..b9ebcb3
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
@@ -0,0 +1,628 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.datasource;
+
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataStore;
+import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource.BinaryData;
+import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.annotation.processor.core.model.ModelSharedConstants;
+import org.apache.olingo.odata2.annotation.processor.core.model.Photo;
+import org.apache.olingo.odata2.annotation.processor.core.model.Room;
+import org.apache.olingo.odata2.annotation.processor.core.util.AnnotationHelper;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class AnnotationsInMemoryDsTest {
+
+ private final AnnotationInMemoryDs datasource;
+ private final AnnotationEdmProvider edmProvider;
+ private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
+
+ public AnnotationsInMemoryDsTest() throws ODataException {
+ datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
+ edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
+ }
+
+ @Test
+ @Ignore
+ public void multiThreadedSyncOnBuildingsTest() throws Exception {
+ final EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ CountDownLatch latch;
+
+ List<Thread> threads = new ArrayList<Thread>();
+ int max = 500;
+
+ latch = new CountDownLatch(max);
+ for (int i = 0; i < max; i++) {
+ threads.add(createBuildingThread(latch, datasource, edmEntitySet, String.valueOf("10")));
+ }
+
+ for (Thread thread : threads) {
+ thread.start();
+ }
+
+ latch.await(60, TimeUnit.SECONDS);
+
+ DataStore<Building> ds = datasource.getDataStore(Building.class);
+ Collection<Building> buildings = ds.read();
+ Assert.assertEquals(max, buildings.size());
+ }
+
+ @org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet
+ @org.apache.olingo.odata2.api.annotation.edm.EdmEntityType
+ private static class SimpleEntity {
+ @EdmKey
+ @EdmProperty
+ public Integer id;
+ @EdmProperty
+ public String name;
+ }
+
+ @Test
+ @Ignore
+ public void multiThreadedSyncCreateReadTest() throws Exception {
+ Collection<Class<?>> ac = new ArrayList<Class<?>>();
+ ac.add(SimpleEntity.class);
+ final AnnotationInMemoryDs localDs = new AnnotationInMemoryDs(SimpleEntity.class.getPackage().getName(), true);
+ final AnnotationEdmProvider localProvider = new AnnotationEdmProvider(ac);
+ final EdmEntitySet edmEntitySet = createMockedEdmEntitySet(localProvider, "SimpleEntitySet");
+ final CountDownLatch latch;
+
+ List<Thread> threads = new ArrayList<Thread>();
+ int max = 500;
+ latch = new CountDownLatch(max);
+ for (int i = 0; i < max; i++) {
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ SimpleEntity se = new SimpleEntity();
+ se.id = Integer.valueOf(String.valueOf(System.currentTimeMillis()).substring(8));
+ se.name = "Name: " + System.currentTimeMillis();
+ try {
+ localDs.createData(edmEntitySet, se);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }finally{
+ latch.countDown();
+ }
+ }
+ };
+
+ threads.add(new Thread(run));
+ }
+
+ for (Thread thread : threads) {
+ thread.start();
+ }
+
+ latch.await(60, TimeUnit.SECONDS);
+
+ DataStore<SimpleEntity> ds = localDs.getDataStore(SimpleEntity.class);
+ Collection<SimpleEntity> buildings = ds.read();
+ Assert.assertEquals(max, buildings.size());
+ }
+
+ private Thread createBuildingThread(final CountDownLatch latch, final DataSource datasource,
+ final EdmEntitySet edmEntitySet, final String id) {
+ Runnable run = new Runnable() {
+ @Override
+ public void run() {
+ Building building = new Building();
+ building.setName("Common Building - " + System.currentTimeMillis());
+ building.setId(id);
+ try {
+ datasource.createData(edmEntitySet, building);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ throw new RuntimeException(ex);
+ } finally {
+ latch.countDown();
+ }
+ }
+ };
+
+ return new Thread(run);
+ }
+
+ @Test
+ public void readBinaryData() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
+ Photo photo = new Photo();
+ photo.setName("SomePic");
+ photo.setType("PNG");
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ photo.setImage(image);
+ photo.setImageType("image/png");
+ photoDataStore.create(photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Name", "SomePic");
+ keys.put("ImageFormat", "PNG");
+ Photo toReadPhoto = (Photo) datasource.readData(entitySet, keys);
+
+ // execute
+ BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
+
+ // validate
+ Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
+ Assert.assertArrayEquals(image, readBinaryData.getData());
+ Assert.assertEquals("image/png", readBinaryData.getMimeType());
+ }
+
+ @Test
+ public void readBinaryDataDirect() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
+ Photo photo = new Photo();
+ photo.setName("SomePic");
+ photo.setType("PNG");
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ photo.setImage(image);
+ photo.setImageType("image/png");
+ photoDataStore.create(photo);
+
+ Photo toReadPhoto = new Photo();
+ toReadPhoto.setName("SomePic");
+ toReadPhoto.setType("PNG");
+ toReadPhoto.setImage(null);
+ toReadPhoto.setImageType(null);
+
+ BinaryData readBinaryData = datasource.readBinaryData(entitySet, toReadPhoto);
+
+ Assert.assertEquals("binary", new String(readBinaryData.getData(), Charset.defaultCharset()));
+ Assert.assertArrayEquals(image, readBinaryData.getData());
+ Assert.assertEquals("image/png", readBinaryData.getMimeType());
+ }
+
+
+ @Test
+ public void writeBinaryData() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ DataStore<Photo> photoDataStore = datasource.getDataStore(Photo.class);
+
+ Photo toWritePhoto = new Photo();
+ toWritePhoto.setName("SomePic");
+ toWritePhoto.setType("PNG");
+ photoDataStore.create(toWritePhoto);
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ String mimeType = "image/png";
+ BinaryData writeBinaryData = new BinaryData(image, mimeType);
+ // execute
+ datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
+
+ // validate
+ Photo photoKey = new Photo();
+ photoKey.setName("SomePic");
+ photoKey.setType("PNG");
+ Photo storedPhoto = photoDataStore.read(photoKey);
+ Assert.assertEquals("binary", new String(storedPhoto.getImage(), Charset.defaultCharset()));
+ Assert.assertArrayEquals(image, storedPhoto.getImage());
+ Assert.assertEquals("image/png", storedPhoto.getImageType());
+ }
+
+ @Test(expected=ODataNotFoundException.class)
+ public void writeBinaryDataNotFound() throws Exception {
+ EdmEntitySet entitySet = createMockedEdmEntitySet("Photos");
+
+ Photo toWritePhoto = new Photo();
+ toWritePhoto.setName("SomePic");
+ toWritePhoto.setType("PNG");
+ byte[] image = "binary".getBytes(Charset.defaultCharset());
+ String mimeType = "image/png";
+ BinaryData writeBinaryData = new BinaryData(image, mimeType);
+ // execute
+ datasource.writeBinaryData(entitySet, toWritePhoto, writeBinaryData);
+ }
+
+
+ @Test
+ public void newDataObject() throws Exception {
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+ Room room = (Room) datasource.newDataObject(roomsEntitySet);
+
+ Assert.assertNotNull(room);
+ }
+
+ @Test
+ public void readEntity() throws Exception {
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 3;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ building.getRooms().addAll(rooms);
+ datasource.createData(buildingsEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ // execute
+ Object relatedData = datasource.readData(buildingsEntitySet, keys);
+
+ // validate
+ Building readBuilding = (Building) relatedData;
+ Assert.assertEquals("Common Building", readBuilding.getName());
+ Assert.assertEquals("1", readBuilding.getId());
+
+ Collection<Room> relatedRooms = readBuilding.getRooms();
+ Assert.assertEquals(roomsCount, relatedRooms.size());
+ for (Room room : relatedRooms) {
+ Assert.assertNotNull(room.getId());
+ Assert.assertTrue(room.getName().matches("Room \\d*"));
+ Assert.assertEquals("Common Building", room.getBuilding().getName());
+ }
+ }
+
+ @Test
+ public void readEntities() throws Exception {
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 11;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ // execute
+ Object relatedData = datasource.readData(roomsEntitySet);
+
+ // validate
+ @SuppressWarnings("unchecked")
+ Collection<Room> relatedRooms = (Collection<Room>) relatedData;
+ Assert.assertEquals(roomsCount, relatedRooms.size());
+ for (Room room : relatedRooms) {
+ Assert.assertNotNull(room.getId());
+ Assert.assertTrue(room.getName().matches("Room \\d*"));
+ Assert.assertEquals("Common Building", room.getBuilding().getName());
+ }
+ }
+
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void readRelatedEntities() throws Exception {
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 10;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ building.getRooms().addAll(rooms);
+ datasource.createData(buildingsEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(buildingsEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+
+ // execute
+ Object relatedData = datasource.readRelatedData(
+ buildingsEntitySet, building, roomsEntitySet, Collections.EMPTY_MAP);
+
+ // validate
+ Assert.assertTrue("Result is no collection.", relatedData instanceof Collection);
+ Collection<Room> relatedRooms = (Collection<Room>) relatedData;
+ Assert.assertEquals(roomsCount, relatedRooms.size());
+ for (Room room : relatedRooms) {
+ Assert.assertNotNull(room.getId());
+ Assert.assertTrue(room.getName().matches("Room \\d*"));
+ Assert.assertEquals("Common Building", room.getBuilding().getName());
+ }
+ }
+
+ @Test
+ public void readRelatedTargetEntity() throws Exception {
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+
+ final int roomsCount = 10;
+ List<Room> rooms = new ArrayList<Room>();
+ for (int i = 0; i < roomsCount; i++) {
+ Room room = new Room(i, "Room " + i);
+ room.setBuilding(building);
+ datasource.createData(roomsEntitySet, room);
+ rooms.add(room);
+ }
+
+ building.getRooms().addAll(rooms);
+ datasource.createData(buildingsEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(buildingsEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+
+ // execute
+ Map<String, Object> targetKeys = new HashMap<String, Object>();
+ targetKeys.put("Id", 3);
+ Object relatedData = datasource.readRelatedData(
+ buildingsEntitySet, building, roomsEntitySet, targetKeys);
+
+ // validate
+ Assert.assertTrue("Result is no Room.", relatedData instanceof Room);
+ Room relatedRoom = (Room) relatedData;
+ Assert.assertEquals("3", relatedRoom.getId());
+ Assert.assertEquals("Room 3", relatedRoom.getName());
+ Assert.assertEquals("Common Building", relatedRoom.getBuilding().getName());
+ }
+
+ @Test
+ public void createSimpleEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+ }
+
+ @Test
+ public void createSimpleEntityWithOwnKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ AnnotationHelper ah = new AnnotationHelper();
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "42");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("42", read.getId());
+ }
+
+ @Test
+ public void createSimpleEntityWithDuplicateKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ AnnotationHelper ah = new AnnotationHelper();
+
+ Building building = new Building();
+ building.setName("Common Building");
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+ //
+ Building buildingDuplicate = new Building();
+ buildingDuplicate.setName("Duplicate Building");
+ ah.setValueForProperty(buildingDuplicate, "Id", "42");
+ datasource.createData(edmEntitySet, buildingDuplicate);
+
+ Map<String, Object> keys42 = new HashMap<String, Object>();
+ keys42.put("Id", "42");
+ Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
+ Assert.assertEquals("Common Building", read42.getName());
+ Assert.assertEquals("42", read42.getId());
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Duplicate Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+ }
+
+ @Test
+ public void createEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
+ Photo photo = new Photo();
+ photo.setName("BigPicture");
+ photo.setType("PNG");
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("ImageFormat", "PNG");
+ keys.put("Name", "BigPicture");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+ }
+
+ @Test
+ public void createAndUpdateEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
+ Photo photo = new Photo();
+ final String nameKeyValue = "BigPicture";
+ final String typeKeyValue = "PNG";
+ photo.setName(nameKeyValue);
+ photo.setType(typeKeyValue);
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Name", "BigPicture");
+ keys.put("ImageFormat", "PNG");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+
+ // update
+ Photo updatedPhoto = new Photo();
+ updatedPhoto.setName(nameKeyValue);
+ updatedPhoto.setType(typeKeyValue);
+ updatedPhoto.setImageUri("https://localhost/image.jpg");
+ updatedPhoto.setImageType("image/jpg");
+ datasource.updateData(edmEntitySet, updatedPhoto);
+
+ Map<String, Object> updatedKeys = new HashMap<String, Object>();
+ updatedKeys.put("Name", nameKeyValue);
+ updatedKeys.put("ImageFormat", typeKeyValue);
+
+ Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
+ Assert.assertEquals("BigPicture", readUpdated.getName());
+ Assert.assertEquals("PNG", readUpdated.getType());
+ Assert.assertEquals("image/jpg", readUpdated.getImageType());
+ Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
+ }
+
+
+ @Test
+ public void deleteSimpleEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ DataStore<Building> datastore = datasource.getDataStore(Building.class);
+
+ Building building = new Building();
+ building.setName("Common Building");
+ datastore.create(building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+
+ //
+ datasource.deleteData(edmEntitySet, keys);
+
+ // validate
+ try {
+ Building readAfterDelete = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.fail("Expected " + ODataNotFoundException.class + "was not thrown for '" + readAfterDelete + "'.");
+ } catch (ODataNotFoundException e) { }
+ }
+
+ @Test(expected=ODataRuntimeException.class)
+ public void unknownEntitySetForEntity() throws Exception {
+ String entitySetName = "Unknown";
+ FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+ //
+ datasource.readData(edmEntitySet, keys);
+ }
+
+ @Test(expected=ODataRuntimeException.class)
+ public void unknownEntitySetForEntities() throws Exception {
+ String entitySetName = "Unknown";
+ FullQualifiedName entityType = new FullQualifiedName(DEFAULT_CONTAINER, entitySetName);
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ //
+ datasource.readData(edmEntitySet);
+ }
+
+
+ private EdmEntitySet createMockedEdmEntitySet(final String entitySetName) throws ODataException {
+ return createMockedEdmEntitySet(edmProvider, entitySetName);
+ }
+
+ private EdmEntitySet createMockedEdmEntitySet(AnnotationEdmProvider edmProvider, final String entitySetName)
+ throws ODataException {
+ EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
+ FullQualifiedName entityType = entitySet.getEntityType();
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ return edmEntitySet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
new file mode 100644
index 0000000..7c35fca
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/edm/AnnotationEdmProviderTest.java
@@ -0,0 +1,463 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.edm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.olingo.odata2.annotation.processor.core.model.Building;
+import org.apache.olingo.odata2.annotation.processor.core.model.City;
+import org.apache.olingo.odata2.annotation.processor.core.model.Employee;
+import org.apache.olingo.odata2.annotation.processor.core.model.Location;
+import org.apache.olingo.odata2.annotation.processor.core.model.Manager;
+import org.apache.olingo.odata2.annotation.processor.core.model.ModelSharedConstants;
+import org.apache.olingo.odata2.annotation.processor.core.model.Photo;
+import org.apache.olingo.odata2.annotation.processor.core.model.RefBase;
+import org.apache.olingo.odata2.annotation.processor.core.model.Room;
+import org.apache.olingo.odata2.annotation.processor.core.model.Team;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AnnotationEdmProviderTest {
+
+ private static final String TEST_MODEL_PACKAGE = "org.apache.olingo.odata2.annotation.processor.core.model";
+
+ @EdmEntityType
+ @EdmEntitySet
+ private static final class GeneratedNamesTestClass {}
+
+ @EdmComplexType
+ private static final class GeneratedNamesComplexTestClass {}
+
+ @EdmEntityType(namespace = "MyTestNamespace")
+ @EdmEntitySet(container = "MyTestContainer")
+ private static final class DefinedNamesTestClass {}
+
+ private final AnnotationEdmProvider aep;
+ private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+
+ public AnnotationEdmProviderTest() {
+ annotatedClasses.add(RefBase.class);
+ annotatedClasses.add(Building.class);
+ annotatedClasses.add(City.class);
+ annotatedClasses.add(Employee.class);
+ annotatedClasses.add(Location.class);
+ annotatedClasses.add(Manager.class);
+ annotatedClasses.add(Photo.class);
+ annotatedClasses.add(Room.class);
+ annotatedClasses.add(Team.class);
+
+ aep = new AnnotationEdmProvider(annotatedClasses);
+ }
+
+ @Test
+ public void defaultNamespaceGeneration() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testType = localAep.getEntityType(new FullQualifiedName(
+ GeneratedNamesTestClass.class.getPackage().getName(),
+ GeneratedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultNamespaceGenerationComplexType() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ ComplexType testType = localAep.getComplexType(new FullQualifiedName(
+ GeneratedNamesComplexTestClass.class.getPackage().getName(),
+ GeneratedNamesComplexTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesComplexTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameGeneration() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep =
+ new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("DefaultContainer", containerInfo.getName());
+ }
+
+ @Test
+ public void defaultNamespaceDefined() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(DefinedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
+ DefinedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testClass);
+ assertEquals("DefinedNamesTestClass", testClass.getName());
+ assertNull("This should not have a base type", testClass.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameDefined() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("MyTestContainer", containerInfo.getName());
+ }
+
+ @Test
+ public void loadAnnotatedClassesFromPackage() throws Exception {
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(TEST_MODEL_PACKAGE);
+
+ // validate employee
+ EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(6, employee.getProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ List<Schema> schemas = localAep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+ }
+
+ @Test
+ public void annotationProviderBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+
+ FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
+ assertNull(funImp);
+
+ final FullQualifiedName associationFqn = new FullQualifiedName(
+ ModelSharedConstants.NAMESPACE_1, "NoAssociation");
+ Association noAssociation = aep.getAssociation(associationFqn);
+ assertNull(noAssociation);
+
+ AssociationSet noAssociationSet = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
+ assertNull(noAssociationSet);
+
+ AssociationSet asBuildingRooms = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
+ assertNotNull(asBuildingRooms);
+ assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
+ assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
+ assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
+ assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
+ }
+
+ @Test
+ public void annotationProviderGetDefaultContainer() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(null);
+ assertTrue(info.isDefaultEntityContainer());
+ assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
+ }
+
+ @Test
+ public void schemaBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+
+ Schema schema = schemas.get(0);
+ List<EntityContainer> containers = schema.getEntityContainers();
+ assertEquals(1, containers.size());
+ EntityContainer container = containers.get(0);
+ assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
+ final List<EntitySet> entitySets = container.getEntitySets();
+ assertEquals(6, entitySets.size());
+
+ List<Association> associations = schema.getAssociations();
+ assertEquals(4, associations.size());
+ for (Association association : associations) {
+ assertNotNull(association.getName());
+ validateAssociation(association);
+ }
+ }
+
+ private FullQualifiedName defaultFqn(final String name) {
+ return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
+ }
+
+ private void validateAssociation(final Association association) {
+ String name = association.getName();
+ if (name.equals("r_Employee-r_Room")) {
+ validateAssociation(association,
+ "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if (name.equals("BuildingRooms")) {
+ validateAssociation(association,
+ "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
+ "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
+ } else if (name.equals("ManagerEmployees")) {
+ validateAssociation(association,
+ "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if (name.equals("TeamEmployees")) {
+ validateAssociation(association,
+ "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else {
+ fail("Got unknown association to validate with name '" + name + "'.");
+ }
+ }
+
+ private void validateAssociation(final Association association,
+ final String fromRole, final EdmMultiplicity fromMulti, final FullQualifiedName fromType,
+ final String toRole, final EdmMultiplicity toMulti, final FullQualifiedName toType) {
+
+ AssociationEnd[] ends = new AssociationEnd[] { association.getEnd1(), association.getEnd2() };
+ for (AssociationEnd associationEnd : ends) {
+ if (associationEnd.getRole().equals(fromRole)) {
+ validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
+ } else if (associationEnd.getRole().equals(toRole)) {
+ validateAssociationEnd(associationEnd, toRole, toMulti, toType);
+ } else {
+ fail("Unexpected navigation end '" + associationEnd.getRole()
+ + "' for association with name '" + association.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateAssociationEnd(final AssociationEnd associationEnd,
+ final String role, final EdmMultiplicity multiplicity, final FullQualifiedName type) {
+ assertEquals(role, associationEnd.getRole());
+ assertEquals(multiplicity, associationEnd.getMultiplicity());
+ assertEquals(type, associationEnd.getType());
+ }
+
+ @Test
+ public void entitySetTeams() throws Exception {
+ // validate teams
+ EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
+ assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
+ assertEquals("Team", teams.getEntityType().getName());
+ }
+
+ @Test
+ public void entityTypeEmployee() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(6, employee.getProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
+ if (navigationProperty.getName().equals("ne_Manager")) {
+ validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
+ } else if (navigationProperty.getName().equals("ne_Team")) {
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
+ } else if (navigationProperty.getName().equals("ne_Room")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+ }
+
+ @Test
+ public void entityTypeTeam() throws Exception {
+ // validate team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+
+ assertEquals(1, team.getProperties().size());
+ assertEquals(1, team.getNavigationProperties().size());
+ NavigationProperty navigationProperty = team.getNavigationProperties().get(0);
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
+ }
+
+ @Test
+ public void entityTypePhotoWithTwoKeyProperties() throws Exception {
+ // validate team
+ EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
+ assertEquals("Photo", photo.getName());
+ final List<Property> properties = photo.getProperties();
+ assertEquals(5, properties.size());
+ assertTrue(containsProperty(properties, "Name"));
+ assertTrue(containsProperty(properties, "ImageFormat"));
+ assertTrue(containsProperty(properties, "MimeType"));
+ assertTrue(containsProperty(properties, "ImageUrl"));
+ assertTrue(containsProperty(properties, "Image"));
+ assertFalse(photo.isAbstract());
+ assertTrue(photo.isHasStream());
+
+ Key photoKey = photo.getKey();
+ List<PropertyRef> keyReferences = photoKey.getKeys();
+ assertEquals(2, keyReferences.size());
+ PropertyRef name = getPropertyRef(keyReferences, "Name");
+ assertEquals("Name", name.getName());
+ PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
+ assertEquals("ImageFormat", imageFormat.getName());
+
+// assertEquals(0, photo.getNavigationProperties().size());
+ assertNull(photo.getNavigationProperties());
+ }
+
+ @Test
+ public void entityTypeAbstractBaseType() throws Exception {
+ // validate employee
+ EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
+ assertEquals("Base", baseType.getName());
+ final List<PropertyRef> keys = baseType.getKey().getKeys();
+ assertEquals(1, keys.size());
+ assertEquals("Id", keys.get(0).getName());
+ assertEquals(2, baseType.getProperties().size());
+ assertTrue(baseType.isAbstract());
+
+ // validate base for team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+ }
+
+ @Test
+ public void complexTypeLocation() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ final List<Property> properties = employee.getProperties();
+ Property location = null;
+ for (Property property : properties) {
+ if (property.getName().equals("Location")) {
+ location = property;
+ }
+ }
+ assertNotNull(location);
+ assertEquals("Location", location.getName());
+
+ // validate location complex type
+ ComplexType locationType = aep.getComplexType(
+ new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
+ assertEquals("c_Location", locationType.getName());
+ assertEquals(2, locationType.getProperties().size());
+ }
+
+ @Test
+ public void entityTypeRoomWithNavigation() throws Exception {
+ // validate employee
+ EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
+ assertEquals("Room", room.getName());
+ assertEquals("Base", room.getBaseType().getName());
+ assertEquals(2, room.getProperties().size());
+ final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
+ assertEquals(2, navigationProperties.size());
+
+ for (NavigationProperty navigationProperty : navigationProperties) {
+ if (navigationProperty.getName().equals("nr_Employees")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
+ } else if (navigationProperty.getName().equals("nr_Building")) {
+ validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateNavProperty(final NavigationProperty navigationProperty, final String name,
+ final String relationship, final String fromRole, final String toRole) {
+ if (name != null) {
+ assertEquals(name, navigationProperty.getName());
+ }
+ FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
+ assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
+ assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
+ assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
+ }
+
+ private void validateNavProperty(final NavigationProperty navigationProperty,
+ final String relationship, final String fromRole, final String toRole) {
+ validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
+ }
+
+ private boolean containsProperty(final List<Property> properties, final String propertyName) {
+ return getProperty(properties, propertyName) != null;
+ }
+
+ private Property getProperty(final List<Property> properties, final String name) {
+ for (Property property : properties) {
+ if (name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ private PropertyRef getPropertyRef(final List<PropertyRef> properties, final String name) {
+ for (PropertyRef property : properties) {
+ if (name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java
new file mode 100644
index 0000000..bc9f54b
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Building.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Buildings")
+public class Building {
+ @EdmKey
+ @EdmProperty(type = EdmType.INT32)
+ private String id;
+ @EdmProperty
+ private String name;
+ @EdmProperty(name = "Image", type = EdmType.BINARY)
+ private byte[] image;
+ @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
+ association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
+ private List<Room> rooms = new ArrayList<Room>();
+
+ public Building() {}
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setImage(final byte[] byteArray) {
+ image = byteArray;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ } else {
+ return image.clone();
+ }
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ @Override
+ public int hashCode() {
+ return id == null ? 0 : id.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java
new file mode 100644
index 0000000..2e630ba
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/City.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexType(name = "c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+public class City {
+
+ @EdmProperty
+ private String postalCode;
+ @EdmProperty
+ private String cityName;
+
+ public City(final String postalCode, final String name) {
+ this.postalCode = postalCode;
+ cityName = name;
+ }
+
+ public void setPostalCode(final String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setCityName(final String cityName) {
+ this.cityName = cityName;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", cityName, postalCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java
new file mode 100644
index 0000000..136a2e1
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Employee.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Employees")
+public class Employee {
+ @EdmKey
+ @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
+ private String employeeId;
+ @EdmProperty(name = "EmployeeName")
+ private String employeeName;
+ @EdmProperty
+ private int age;
+ @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
+ private Manager manager;
+ @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
+ private Team team;
+ @EdmNavigationProperty(name = "ne_Room")
+ private Room room;
+ @EdmMediaResourceMimeType
+ private String imageType;
+ @EdmMediaResourceContent
+ private byte[] image;
+ @EdmProperty(name = "ImageUrl")
+ private String imageUrl;
+ @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
+ private Calendar entryDate;
+ @EdmProperty(name = "Location")
+ private Location location;
+
+ public Employee(final String employeeId, final String name) {
+ this.employeeId = employeeId;
+ setEmployeeName(name);
+ }
+
+ public String getId() {
+ return employeeId;
+ }
+
+ public void setEmployeeName(final String employeeName) {
+ this.employeeName = employeeName;
+ }
+
+ public String getEmployeeName() {
+ return employeeName;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setManager(final Manager manager) {
+ this.manager = manager;
+ }
+
+ public Manager getManager() {
+ return manager;
+ }
+
+ public void setTeam(final Team team) {
+ this.team = team;
+ }
+
+ public Team getTeam() {
+ return team;
+ }
+
+ public void setRoom(final Room room) {
+ this.room = room;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public void setImageUri(final String imageUri) {
+ imageUrl = imageUri;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setLocation(final Location location) {
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setEntryDate(final Calendar date) {
+ entryDate = date;
+ }
+
+ public Calendar getEntryDate() {
+ return entryDate;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ }
+ return image.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ if (employeeId == null) {
+ return 0;
+ }
+ return employeeId.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"EmployeeId\":\"" + employeeId + "\","
+ + "\"EmployeeName\":\"" + employeeName + "\","
+ + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
+ + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
+ + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
+ + "\"Location\":"
+ + (location == null ? "null" :
+ "{\"City\":" + (location.getCity() == null ? "null" :
+ "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
+ + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
+ + "\"Country\":\"" + location.getCountry() + "\"}") + ","
+ + "\"Age\":" + age + ","
+ + "\"EntryDate\":"
+ + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
+ + "\"ImageUrl\":\"" + imageUrl + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java
new file mode 100644
index 0000000..99f56c9
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Location.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+public class Location {
+ @EdmProperty
+ private String country;
+ @EdmProperty
+ private City city;
+
+ public Location(final String country, final String postalCode, final String cityName) {
+ this.country = country;
+ city = new City(postalCode, cityName);
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCity(final City city) {
+ this.city = city;
+ }
+
+ public City getCity() {
+ return city;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", country, city.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java
new file mode 100644
index 0000000..cd894f0
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Manager.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers")
+public class Manager extends Employee {
+
+ @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
+ toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Manager(final String id, final String name) {
+ super(id, name);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java
new file mode 100644
index 0000000..bd4d3d4
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ModelSharedConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+public interface ModelSharedConstants {
+
+ String NAMESPACE_1 = "RefScenario";
+ String CONTAINER_1 = "DefaultContainer";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java
new file mode 100644
index 0000000..83be665
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Photo.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
+public class Photo {
+ @EdmProperty
+ @EdmKey
+ private String name;
+ @EdmProperty(name = "ImageFormat")
+ @EdmKey
+ private String type;
+ @EdmProperty
+ @EdmMediaResourceMimeType
+ private String mimeType;
+ @EdmProperty
+ @EdmMediaResourceSource
+ private String imageUrl = "http://localhost/someResource.png";
+ @EdmProperty(type = EdmType.BINARY)
+ @EdmMediaResourceContent
+ private byte[] image = ResourceHelper.generateImage();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setImageUri(final String uri) {
+ imageUrl = uri;
+ }
+
+ public byte[] getImage() {
+ return image.clone();
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public String getImageType() {
+ return mimeType;
+ }
+
+ public void setImageType(final String imageType) {
+ mimeType = imageType;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 83 * hash + (name != null ? name.hashCode() : 0);
+ hash = 83 * hash + (type != null ? type.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Photo other = (Photo) obj;
+ if ((name == null) ? (other.name != null) : !name.equals(other.name)) {
+ return false;
+ }
+ if ((type == null) ? (other.type != null) : !type.equals(other.type)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Name\":\"" + name + "\","
+ + "\"Type\":\"" + type + "\","
+ + "\"ImageUrl\":\"" + imageUrl + "\","
+ + "\"Image\":\"" + Arrays.toString(image) + "\","
+ + "\"MimeType\":\"" + mimeType + "\"";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java
new file mode 100644
index 0000000..e998efc
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/RefBase.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Base", namespace = ModelSharedConstants.NAMESPACE_1)
+public abstract class RefBase {
+ @EdmProperty(name = "Name")
+ protected String name;
+ @EdmProperty(name = "Id", type = EdmType.STRING)
+ @EdmKey
+ protected int id;
+
+ public RefBase(final int id, final String name) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public void setId(final int id) {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java
new file mode 100644
index 0000000..f9e9d88
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/ResourceHelper.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.core.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+/**
+ *
+ */
+public class ResourceHelper {
+
+ public enum Format {
+ BMP, JPEG, PNG, GIF
+ };
+
+ public static byte[] generateImage() {
+ return generateImage(Format.PNG);
+ }
+
+ public static byte[] generateImage(final Format format) {
+ try {
+ int width = 320;
+ int height = 320;
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+ WritableRaster raster = image.getRaster();
+
+ int mod = format.ordinal() + 2;
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
+ raster.setSample(w, h, 0, 0);
+ } else {
+ raster.setSample(w, h, 0, 1);
+ }
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+ ImageIO.write(image, format.name(), out);
+ return out.toByteArray();
+ } catch (IOException ex) {
+ return new byte[0];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/636eed23/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java
new file mode 100644
index 0000000..57e42db
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/model/Room.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms")
+public class Room extends RefBase {
+
+ @EdmProperty
+ private Integer seats;
+ @EdmProperty
+ private Integer version;
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
+ private Building building;
+ @EdmNavigationProperty(name = "nr_Employees")
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Room() {
+ this(0, null);
+ }
+
+ public Room(final int id, final String name) {
+ super(id, name);
+ }
+
+ public void setSeats(final int seats) {
+ this.seats = seats;
+ }
+
+ public int getSeats() {
+ return seats;
+ }
+
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setBuilding(final Building building) {
+ this.building = building;
+ }
+
+ public Building getBuilding() {
+ return building;
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
+ }
+}
[28/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilder.java
deleted file mode 100644
index 2a96ac9..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmNameBuilder.java
+++ /dev/null
@@ -1,499 +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.odata2.processor.core.jpa.access.model;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-
-import javax.persistence.Column;
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.ManagedType;
-import javax.persistence.metamodel.PluralAttribute;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationEndView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmBaseView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmComplexType;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmMappingImpl;
-
-public class JPAEdmNameBuilder {
- private static final String ENTITY_CONTAINER_SUFFIX = "Container";
- private static final String ENTITY_SET_SUFFIX = "s";
- private static final String ASSOCIATIONSET_SUFFIX = "Set";
- private static final String NAVIGATION_NAME = "Details";
- private static final String UNDERSCORE = "_";
-
- public static FullQualifiedName build(final JPAEdmBaseView view, final String name) {
- FullQualifiedName fqName = new FullQualifiedName(buildNamespace(view), name);
- return fqName;
- }
-
- /*
- * ************************************************************************
- * EDM EntityType Name - RULES
- * ************************************************************************
- * EDM Entity Type Name = JPA Entity Name EDM Entity Type Internal Name =
- * JPA Entity Name
- * ************************************************************************
- * EDM Entity Type Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmEntityTypeView view) {
-
- EntityType edmEntityType = view.getEdmEntityType();
- String jpaEntityName = view.getJPAEntityType().getName();
- JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
- String edmEntityTypeName = null;
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- edmEntityTypeName = mappingModelAccess.mapJPAEntityType(jpaEntityName);
- }
-
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(view.getJPAEntityType().getJavaType());
-
- if (edmEntityTypeName == null) {
- edmEntityTypeName = jpaEntityName;
- }
- // Setting the mapping object
- edmEntityType.setMapping(((Mapping) mapping).setInternalName(jpaEntityName));
-
- edmEntityType.setName(edmEntityTypeName);
-
- }
-
- /*
- * ************************************************************************
- * EDM Schema Name - RULES
- * ************************************************************************
- * Java Persistence Unit name is set as Schema's Namespace
- * ************************************************************************
- * EDM Schema Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmSchemaView view) throws ODataJPAModelException {
- view.getEdmSchema().setNamespace(buildNamespace(view));
- }
-
- /*
- * ************************************************************************
- * EDM Property Name - RULES
- * ************************************************************************
- * OData Property Names are represented in Camel Case. The first character
- * of JPA Attribute Name is converted to an UpperCase Character and set as
- * OData Property Name. JPA Attribute Name is set as Internal Name for OData
- * Property. The Column name (annotated as @Column(name="x")) is set as
- * column name in the mapping object.
- * ************************************************************************
- * EDM Property Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmPropertyView view, final boolean isComplexMode,
- final boolean skipDefaultNaming) {
- Attribute<?, ?> jpaAttribute = view.getJPAAttribute();
- String jpaAttributeName = jpaAttribute.getName();
- String propertyName = null;
-
- JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- if (isComplexMode) {
- propertyName =
- mappingModelAccess.mapJPAEmbeddableTypeAttribute(view.getJPAEdmComplexTypeView().getJPAEmbeddableType()
- .getJavaType().getSimpleName(), jpaAttributeName);
- } else {
- propertyName =
- mappingModelAccess.mapJPAAttribute(view.getJPAEdmEntityTypeView().getJPAEntityType().getName(),
- jpaAttributeName);
- }
- }
- if (skipDefaultNaming == false && propertyName == null) {
- propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
- } else if (propertyName == null) {
- propertyName = jpaAttributeName;
- }
-
- view.getEdmSimpleProperty().setName(propertyName);
-
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(jpaAttributeName);
- mapping.setJPAType(jpaAttribute.getJavaType());
-
- AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember();
- if (annotatedElement != null) {
- Column column = annotatedElement.getAnnotation(Column.class);
- if (column != null) {
- mapping.setJPAColumnName(column.name());
- }
- } else {
- ManagedType<?> managedType = jpaAttribute.getDeclaringType();
- if (managedType != null) {
- Class<?> clazz = managedType.getJavaType();
- try {
- Field field = clazz.getField(jpaAttributeName);
- Column column = field.getAnnotation(Column.class);
- if (column != null) {
- mapping.setJPAColumnName(column.name());
- }
- } catch (SecurityException e) {
-
- } catch (NoSuchFieldException e) {
-
- }
- }
-
- }
- view.getEdmSimpleProperty().setMapping((Mapping) mapping);
- }
-
- /*
- * ************************************************************************
- * EDM EntityContainer Name - RULES
- * ************************************************************************
- * Entity Container Name = EDM Namespace + Literal "Container"
- * ************************************************************************
- * EDM EntityContainer Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmEntityContainerView view) {
- view.getEdmEntityContainer().setName(buildNamespace(view) + ENTITY_CONTAINER_SUFFIX);
- }
-
- /*
- * ************************************************************************
- * EDM EntitySet Name - RULES
- * ************************************************************************
- * Entity Set Name = JPA Entity Type Name + Literal "s"
- * ************************************************************************
- * EDM EntitySet Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmEntitySetView view, final JPAEdmEntityTypeView entityTypeView) {
- FullQualifiedName fQname = view.getEdmEntitySet().getEntityType();
- JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
- String entitySetName = null;
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- Mapping mapping = entityTypeView.getEdmEntityType().getMapping();
- if (mapping != null) {
- entitySetName = mappingModelAccess.mapJPAEntitySet(mapping.getInternalName());
- }
- }
-
- if (entitySetName == null) {
- entitySetName = fQname.getName() + ENTITY_SET_SUFFIX;
- }
-
- view.getEdmEntitySet().setName(entitySetName);
- }
-
- /*
- * ************************************************************************
- * EDM Complex Type Name - RULES
- * ************************************************************************
- * Complex Type Name = JPA Embeddable Type Simple Name.
- * ************************************************************************
- * EDM Complex Type Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmComplexType view) {
-
- JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
- String jpaEmbeddableTypeName = view.getJPAEmbeddableType().getJavaType().getSimpleName();
- String edmComplexTypeName = null;
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- edmComplexTypeName = mappingModelAccess.mapJPAEmbeddableType(jpaEmbeddableTypeName);
- }
-
- if (edmComplexTypeName == null) {
- edmComplexTypeName = jpaEmbeddableTypeName;
- }
-
- view.getEdmComplexType().setName(edmComplexTypeName);
- ComplexType complexType = view.getEdmComplexType();
- complexType.setName(edmComplexTypeName);
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(view.getJPAEmbeddableType().getJavaType());
- complexType.setMapping((Mapping) mapping);
-
- }
-
- /*
- * ************************************************************************
- * EDM Complex Property Name - RULES
- * ************************************************************************
- * The first character of JPA complex attribute name is converted to
- * uppercase. The modified JPA complex attribute name is assigned as EDM
- * complex property name. The unmodified JPA complex attribute name is
- * assigned as internal name.
- * ************************************************************************
- * EDM Complex Property Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmComplexPropertyView complexView,
- final JPAEdmPropertyView propertyView, final boolean skipDefaultNaming) {
-
- ComplexProperty complexProperty = complexView.getEdmComplexProperty();
-
- String jpaAttributeName = propertyView.getJPAAttribute().getName();
- String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView().getJPAEntityType().getName();
-
- JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
- String propertyName = null;
-
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- propertyName = mappingModelAccess.mapJPAAttribute(jpaEntityTypeName, jpaAttributeName);
- }
-
- if (skipDefaultNaming == false && propertyName == null) {
- propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
- } else if (propertyName == null) {
- propertyName = jpaAttributeName;
- }
-
- // change for navigation property issue
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(jpaAttributeName);
- mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
- complexProperty.setMapping((Mapping) mapping);
-
- complexProperty.setName(propertyName);
-
- }
-
- public static void build(final JPAEdmComplexPropertyView complexView,
- final String parentComplexTypeName, final boolean skipDefaultNaming) {
- ComplexProperty complexProperty = complexView.getEdmComplexProperty();
-
- JPAEdmMappingModelAccess mappingModelAccess = complexView.getJPAEdmMappingModelAccess();
- JPAEdmPropertyView propertyView = ((JPAEdmPropertyView) complexView);
- String jpaAttributeName = propertyView.getJPAAttribute().getName();
- String propertyName = null;
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- propertyName = mappingModelAccess.mapJPAEmbeddableTypeAttribute(parentComplexTypeName, jpaAttributeName);
- }
- if (skipDefaultNaming == false && propertyName == null) {
- propertyName = Character.toUpperCase(jpaAttributeName.charAt(0)) + jpaAttributeName.substring(1);
- } else if (propertyName == null) {
- propertyName = jpaAttributeName;
- }
-
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(jpaAttributeName);
- mapping.setJPAType(propertyView.getJPAAttribute().getJavaType());
- complexProperty.setMapping((Mapping) mapping);
- complexProperty.setName(propertyName);
-
- }
-
- /*
- * ************************************************************************
- * EDM Association End Name - RULES
- * ************************************************************************
- * Association End name = Namespace + Entity Type Name
- * ************************************************************************
- * EDM Association End Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmAssociationEndView assocaitionEndView,
- final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) {
-
- String namespace = buildNamespace(assocaitionEndView);
-
- String name = entityTypeView.getEdmEntityType().getName();
- FullQualifiedName fQName = new FullQualifiedName(namespace, name);
- assocaitionEndView.getEdmAssociationEnd1().setType(fQName);
-
- name = null;
- String jpaEntityTypeName = null;
- Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
- if (jpaAttribute.isCollection()) {
- jpaEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType()
- .getSimpleName();
- } else {
- jpaEntityTypeName = propertyView.getJPAAttribute().getJavaType()
- .getSimpleName();
- }
-
- JPAEdmMappingModelAccess mappingModelAccess = assocaitionEndView.getJPAEdmMappingModelAccess();
-
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- name = mappingModelAccess.mapJPAEntityType(jpaEntityTypeName);
- }
-
- if (name == null) {
- name = jpaEntityTypeName;
- }
-
- fQName = new FullQualifiedName(namespace, name);
- assocaitionEndView.getEdmAssociationEnd2().setType(fQName);
-
- }
-
- private static String buildNamespace(final JPAEdmBaseView view) {
- JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
- String namespace = null;
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- namespace = mappingModelAccess.mapJPAPersistenceUnit(view.getpUnitName());
- }
- if (namespace == null) {
- namespace = view.getpUnitName();
- }
-
- return namespace;
- }
-
- /*
- * ************************************************************************
- * EDM Association Name - RULES
- * ************************************************************************
- * Association name = Association + End1 Name + End2 Name
- * ************************************************************************
- * EDM Association Name - RULES
- * ************************************************************************
- */
-
- public static void build(final JPAEdmAssociationView view, final int count) {
- Association association = view.getEdmAssociation();
- String associationName = null;
- String end1Name = association.getEnd1().getType().getName();
- String end2Name = association.getEnd2().getType().getName();
-
- if (end1Name.compareToIgnoreCase(end2Name) > 0) {
- associationName = end2Name + UNDERSCORE + end1Name;
- } else {
- associationName = end1Name + UNDERSCORE + end2Name;
- }
- if (count > 1) {
- associationName = associationName + Integer.toString(count - 1);
- }
- association.setName(associationName);
-
- }
-
- /*
- * ************************************************************************
- * EDM Association Set Name - RULES
- * ************************************************************************
- * Association Set name = Association Name + "Set"
- * ************************************************************************
- * EDM Association Set Name - RULES
- * ************************************************************************
- */
- public static void build(final JPAEdmAssociationSetView view) {
- AssociationSet associationSet = view.getEdmAssociationSet();
-
- String name = view.getEdmAssociation().getName();
- associationSet.setName(name + ASSOCIATIONSET_SUFFIX);
-
- }
-
- public static void build(final JPAEdmAssociationView associationView,
- final JPAEdmPropertyView propertyView,
- final JPAEdmNavigationPropertyView navPropertyView, final boolean skipDefaultNaming, final int count) {
-
- String toName = null;
- String fromName = null;
- String navPropName = null;
- NavigationProperty navProp = navPropertyView.getEdmNavigationProperty();
- String namespace = buildNamespace(associationView);
-
- Association association = associationView.getEdmAssociation();
- navProp.setRelationship(new FullQualifiedName(namespace, association
- .getName()));
-
- FullQualifiedName associationEndTypeOne = association.getEnd1()
- .getType();
- FullQualifiedName associationEndTypeTwo = association.getEnd2()
- .getType();
-
- Attribute<?, ?> jpaAttribute = propertyView.getJPAAttribute();
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(jpaAttribute.getName());
- mapping.setJPAType(jpaAttribute.getJavaType());
- navProp.setMapping((Mapping) mapping);
-
- String jpaEntityTypeName = propertyView.getJPAEdmEntityTypeView()
- .getJPAEntityType().getName();
- JPAEdmMappingModelAccess mappingModelAccess = navPropertyView
- .getJPAEdmMappingModelAccess();
-
- String targetEntityTypeName = null;
- if (jpaAttribute.isCollection()) {
- targetEntityTypeName = ((PluralAttribute<?, ?, ?>) jpaAttribute).getElementType().getJavaType().getSimpleName();
- } else {
- targetEntityTypeName = jpaAttribute.getJavaType().getSimpleName();
- }
-
- if (mappingModelAccess != null
- && mappingModelAccess.isMappingModelExists()) {
- navPropName = mappingModelAccess.mapJPARelationship(
- jpaEntityTypeName, jpaAttribute.getName());
- toName = mappingModelAccess.mapJPAEntityType(targetEntityTypeName);
- fromName = mappingModelAccess
- .mapJPAEntityType(jpaEntityTypeName);
- }
- if (toName == null) {
- toName = targetEntityTypeName;
- }
-
- if (fromName == null) {
- fromName = jpaEntityTypeName;
- }
-
- if (skipDefaultNaming == false) {
- if (navPropName == null) {
- navPropName = toName.concat(NAVIGATION_NAME);
- }
- if (count > 1) {
- navPropName = navPropName + Integer.toString(count - 1);
- }
- } else if (navPropName == null) {
- navPropName = jpaAttribute.getName();
- }
-
- navProp.setName(navPropName);
-
- if (toName.equals(associationEndTypeOne.getName())) {
- navProp.setFromRole(association.getEnd2().getRole());
- navProp.setToRole(association.getEnd1().getRole());
- } else if (toName.equals(associationEndTypeTwo.getName())) {
-
- navProp.setToRole(association.getEnd2().getRole());
- navProp.setFromRole(association.getEnd1().getRole());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
deleted file mode 100644
index e7b8a6e..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPATypeConvertor.java
+++ /dev/null
@@ -1,119 +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.odata2.processor.core.jpa.access.model;
-
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.UUID;
-
-import javax.persistence.Temporal;
-import javax.persistence.TemporalType;
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-
-/**
- * This class holds utility methods for Type conversions between JPA and OData Types.
- *
- *
- *
- */
-public class JPATypeConvertor {
-
- /**
- * This utility method converts a given jpa Type to equivalent
- * EdmSimpleTypeKind for maintaining compatibility between Java and OData
- * Types.
- *
- * @param jpaType
- * The JPA Type input.
- * @return The corresponding EdmSimpleTypeKind.
- * @throws ODataJPAModelException
- * @throws org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException
- *
- * @see EdmSimpleTypeKind
- */
-
- private static final String OBJECT_TYPE = "java.lang.Object";
-
- public static EdmSimpleTypeKind
- convertToEdmSimpleType(final Class<?> jpaType, final Attribute<?, ?> currentAttribute)
- throws ODataJPAModelException {
- if (jpaType.equals(String.class) || jpaType.equals(Character.class) || jpaType.equals(char.class)
- || jpaType.equals(char[].class) ||
- jpaType.equals(Character[].class)) {
- return EdmSimpleTypeKind.String;
- } else if (jpaType.equals(Long.class) || jpaType.equals(long.class)) {
- return EdmSimpleTypeKind.Int64;
- } else if (jpaType.equals(Short.class) || jpaType.equals(short.class)) {
- return EdmSimpleTypeKind.Int16;
- } else if (jpaType.equals(Integer.class) || jpaType.equals(int.class)) {
- return EdmSimpleTypeKind.Int32;
- } else if (jpaType.equals(Double.class) || jpaType.equals(double.class)) {
- return EdmSimpleTypeKind.Double;
- } else if (jpaType.equals(Float.class) || jpaType.equals(float.class)) {
- return EdmSimpleTypeKind.Single;
- } else if (jpaType.equals(BigDecimal.class)) {
- return EdmSimpleTypeKind.Decimal;
- } else if (jpaType.equals(byte[].class)) {
- return EdmSimpleTypeKind.Binary;
- } else if (jpaType.equals(Byte.class) || jpaType.equals(byte.class)) {
- return EdmSimpleTypeKind.Byte;
- } else if (jpaType.equals(Byte[].class)) {
- return EdmSimpleTypeKind.Binary;
- } else if (jpaType.equals(Boolean.class) || jpaType.equals(boolean.class)) {
- return EdmSimpleTypeKind.Boolean;
- } else if ((jpaType.equals(Date.class)) || (jpaType.equals(Calendar.class))) {
- try {
- if ((currentAttribute != null)
- && (determineTemporalType(currentAttribute.getDeclaringType().getJavaType(), currentAttribute.getName())
- == TemporalType.TIME)) {
- return EdmSimpleTypeKind.Time;
- } else {
- return EdmSimpleTypeKind.DateTime;
- }
- } catch (SecurityException e) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
- }
- } else if (jpaType.equals(UUID.class)) {
- return EdmSimpleTypeKind.Guid;
- }
- throw ODataJPAModelException.throwException(ODataJPAModelException.TYPE_NOT_SUPPORTED
- .addContent(jpaType.toString()), null);
- }
-
- private static TemporalType determineTemporalType(final Class<?> type, final String fieldName)
- throws ODataJPAModelException {
- if (type != null && !type.getName().equals(OBJECT_TYPE)) {
- try {
- Field field = type.getField(fieldName);
- return field.getAnnotation(Temporal.class).value();
- } catch (NoSuchFieldException e) {
- determineTemporalType(type.getSuperclass(), fieldName);
- } catch (SecurityException e) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
- }
- }
- return null;
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProvider.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProvider.java
deleted file mode 100644
index e0014e5..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProvider.java
+++ /dev/null
@@ -1,295 +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.odata2.processor.core.jpa.edm;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
-
-public class ODataJPAEdmProvider extends EdmProvider {
-
- private ODataJPAContext oDataJPAContext;
- private JPAEdmModelView jpaEdmModel;
-
- private List<Schema> schemas;
- private HashMap<String, EntityType> entityTypes;
- private HashMap<String, EntityContainerInfo> entityContainerInfos;
- private HashMap<String, ComplexType> complexTypes;
- private HashMap<String, Association> associations;
- private HashMap<String, FunctionImport> functionImports;
-
- public ODataJPAEdmProvider() {
- entityTypes = new HashMap<String, EntityType>();
- entityContainerInfos = new HashMap<String, EntityContainerInfo>();
- complexTypes = new HashMap<String, ComplexType>();
- associations = new HashMap<String, Association>();
- functionImports = new HashMap<String, FunctionImport>();
- }
-
- public ODataJPAEdmProvider(final ODataJPAContext oDataJPAContext) {
- if (oDataJPAContext == null) {
- throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
- }
- entityTypes = new HashMap<String, EntityType>();
- entityContainerInfos = new HashMap<String, EntityContainerInfo>();
- complexTypes = new HashMap<String, ComplexType>();
- associations = new HashMap<String, Association>();
- functionImports = new HashMap<String, FunctionImport>();
- jpaEdmModel = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmModelView(oDataJPAContext);
- }
-
- public ODataJPAContext getODataJPAContext() {
- return oDataJPAContext;
- }
-
- public void setODataJPAContext(final ODataJPAContext jpaContext) {
- oDataJPAContext = jpaContext;
- }
-
- @Override
- public EntityContainerInfo getEntityContainerInfo(final String name) throws ODataException {
-
- if (entityContainerInfos.containsKey(name)) {
- return entityContainerInfos.get(name);
- } else {
-
- if (schemas == null) {
- getSchemas();
- }
- List<EntityContainer> containerList = schemas.get(0).getEntityContainers();
- if (containerList == null) {
- return null;
- }
- for (EntityContainer container : containerList) {
- if (name == null && container.isDefaultEntityContainer()) {
- entityContainerInfos.put(name, container);
- return container;
- } else if (name != null && name.equals(container.getName())) {
- return container;
- }
- }
- }
- return null;
- }
-
- @Override
- public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
-
- String strEdmFQName = edmFQName.toString();
-
- if (edmFQName != null) {
- if (entityTypes.containsKey(strEdmFQName)) {
- return entityTypes.get(strEdmFQName);
- } else if (schemas == null) {
- getSchemas();
- }
-
- String entityTypeNamespace = edmFQName.getNamespace();
- String entityTypeName = edmFQName.getName();
-
- for (Schema schema : schemas) {
- String schemaNamespace = schema.getNamespace();
- if (schemaNamespace.equals(entityTypeNamespace)) {
- if (schema.getEntityTypes() == null) {
- return null;
- }
- for (EntityType et : schema.getEntityTypes()) {
- if (et.getName().equals(entityTypeName)) {
- entityTypes.put(strEdmFQName, et);
- return et;
- }
- }
- }
- }
- }
-
- return null;
- }
-
- @Override
- public ComplexType getComplexType(final FullQualifiedName edmFQName) throws ODataException {
-
- if (edmFQName != null) {
- if (complexTypes.containsKey(edmFQName.toString())) {
- return complexTypes.get(edmFQName.toString());
- } else if (schemas == null) {
- getSchemas();
- }
-
- for (Schema schema : schemas) {
- if (schema.getNamespace().equals(edmFQName.getNamespace())) {
- if (schema.getComplexTypes() == null) {
- return null;
- }
- for (ComplexType ct : schema.getComplexTypes()) {
- if (ct.getName().equals(edmFQName.getName())) {
- complexTypes.put(edmFQName.toString(), ct);
- return ct;
- }
- }
- }
- }
- }
-
- return null;
- }
-
- @Override
- public Association getAssociation(final FullQualifiedName edmFQName) throws ODataException {
- if (edmFQName != null) {
- if (associations.containsKey(edmFQName.toString())) {
- return associations.get(edmFQName.toString());
- } else if (schemas == null) {
- getSchemas();
- }
-
- for (Schema schema : schemas) {
- if (schema.getNamespace().equals(edmFQName.getNamespace())) {
- if (schema.getAssociations() == null) {
- return null;
- }
- for (Association association : schema.getAssociations()) {
- if (association.getName().equals(edmFQName.getName())) {
- associations.put(edmFQName.toString(), association);
- return association;
- }
- }
- }
- }
-
- }
- return null;
- }
-
- @Override
- public EntitySet getEntitySet(final String entityContainer, final String name) throws ODataException {
-
- EntitySet returnedSet = null;
- EntityContainer container = null;
- if (!entityContainerInfos.containsKey(entityContainer)) {
- container = (EntityContainer) getEntityContainerInfo(entityContainer);
- } else {
- container = (EntityContainer) entityContainerInfos.get(entityContainer);
- }
-
- if (container != null && name != null) {
- for (EntitySet es : container.getEntitySets()) {
- if (name.equals(es.getName())) {
- returnedSet = es;
- break;
- }
- }
- }
-
- return returnedSet;
- }
-
- @Override
- public AssociationSet getAssociationSet(final String entityContainer, final FullQualifiedName association,
- final String sourceEntitySetName, final String sourceEntitySetRole) throws ODataException {
-
- EntityContainer container = null;
- if (!entityContainerInfos.containsKey(entityContainer)) {
- container = (EntityContainer) getEntityContainerInfo(entityContainer);
- } else {
- container = (EntityContainer) entityContainerInfos.get(entityContainer);
- }
-
- if (container != null && association != null && container.getAssociationSets() != null) {
- for (AssociationSet as : container.getAssociationSets()) {
- if (association.equals(as.getAssociation())) {
- AssociationSetEnd end = as.getEnd1();
- if (sourceEntitySetName.equals(end.getEntitySet()) && sourceEntitySetRole.equals(end.getRole())) {
- return as;
- } else {
- end = as.getEnd2();
- if (sourceEntitySetName.equals(end.getEntitySet()) && sourceEntitySetRole.equals(end.getRole())) {
- return as;
- }
- }
- }
- }
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException {
-
- if (functionImports.containsKey(name)) {
- return functionImports.get(name);
- }
-
- EntityContainer container = null;
- if (!entityContainerInfos.containsKey(entityContainer)) {
- container = (EntityContainer) getEntityContainerInfo(entityContainer);
- } else {
- container = (EntityContainer) entityContainerInfos.get(entityContainer);
- }
-
- if (container != null && name != null) {
- if (container.getFunctionImports() == null) {
- return null;
- }
- for (FunctionImport fi : container.getFunctionImports()) {
- if (name.equals(fi.getName())) {
- functionImports.put(name, fi);
- return fi;
- }
- }
- }
- return null;
- }
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- if (schemas == null && jpaEdmModel != null) {
- jpaEdmModel.getBuilder().build();
- schemas = new ArrayList<Schema>();
- schemas.add(jpaEdmModel.getEdmSchemaView().getEdmSchema());
- }
- if (jpaEdmModel == null) {
-
- throw ODataJPAModelException.throwException(ODataJPAModelException.BUILDER_NULL, null);
- }
-
- return schemas;
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/exception/ODataJPAMessageServiceDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/exception/ODataJPAMessageServiceDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/exception/ODataJPAMessageServiceDefault.java
deleted file mode 100644
index d7f3964..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/exception/ODataJPAMessageServiceDefault.java
+++ /dev/null
@@ -1,122 +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.odata2.processor.core.jpa.exception;
-
-import java.util.Arrays;
-import java.util.Formatter;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingFormatArgumentException;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-import org.apache.olingo.odata2.api.exception.MessageReference;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAMessageService;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAContextImpl;
-
-public class ODataJPAMessageServiceDefault implements ODataJPAMessageService {
-
- private static final String BUNDLE_NAME = "jpaprocessor_msg"; //$NON-NLS-1$
- private static final Map<Locale, ODataJPAMessageService> LOCALE_2_MESSAGE_SERVICE =
- new HashMap<Locale, ODataJPAMessageService>();
- private static final ResourceBundle defaultResourceBundle = ResourceBundle.getBundle(BUNDLE_NAME);
- private final ResourceBundle resourceBundle;
- private final Locale lanLocale;
-
- @Override
- public String getLocalizedMessage(final MessageReference context, final Throwable exception) {
-
- Object[] contentAsArray = context.getContent().toArray(new Object[0]);
-
- if (contentAsArray.length == 0 && exception != null) {
- contentAsArray = new Object[2];
- contentAsArray[0] = exception.getStackTrace()[1].getClassName();
- contentAsArray[1] = exception.getMessage();
- }
- String value = null;
- String key = context.getKey();
-
- try {
- value = getMessage(key);
- StringBuilder builder = new StringBuilder();
- Formatter f = null;
- if (lanLocale == null) {
- f = new Formatter();
- } else {
- f = new Formatter(builder, lanLocale);
- }
- f.format(value, contentAsArray);
- f.close();
- return builder.toString();
-
- } catch (MissingResourceException e) {
- return "Missing message for key '" + key + "'!";
- } catch (MissingFormatArgumentException e) {
- return "Missing replacement for place holder in value '" + value + "' for following arguments '"
- + Arrays.toString(contentAsArray) + "'!";
- }
- }
-
- private ODataJPAMessageServiceDefault(final ResourceBundle resourceBundle, final Locale locale) {
- this.resourceBundle = resourceBundle;
- lanLocale = locale;
- }
-
- public static ODataJPAMessageService getInstance(final Locale locale) {
-
- Locale acceptedLocale = Locale.ENGLISH;
- if ((ODataJPAContextImpl.getContextInThreadLocal() != null)
- && (ODataJPAContextImpl.getContextInThreadLocal().getAcceptableLanguages() != null)) {
-
- List<Locale> acceptedLanguages = ODataJPAContextImpl.getContextInThreadLocal().getAcceptableLanguages();
-
- Iterator<Locale> itr = acceptedLanguages.iterator();
-
- while (itr.hasNext()) {
-
- Locale tempLocale = itr.next();
- if (ResourceBundle.getBundle(BUNDLE_NAME, tempLocale).getLocale().equals(tempLocale)) {
- acceptedLocale = tempLocale;
- break;
- }
- }
- }
-
- ODataJPAMessageService messagesInstance = LOCALE_2_MESSAGE_SERVICE.get(acceptedLocale);
- if (messagesInstance == null) {
- ResourceBundle resourceBundle = ResourceBundle.getBundle(BUNDLE_NAME, acceptedLocale);
-
- if (resourceBundle != null) {
- messagesInstance = new ODataJPAMessageServiceDefault(resourceBundle, acceptedLocale);
- LOCALE_2_MESSAGE_SERVICE.put(acceptedLocale, messagesInstance);
- } else if (defaultResourceBundle != null) {
- messagesInstance = new ODataJPAMessageServiceDefault(defaultResourceBundle, null);
- }
-
- }
- return messagesInstance;
- }
-
- private String getMessage(final String key) {
- return resourceBundle.getString(key);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/factory/ODataJPAFactoryImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/factory/ODataJPAFactoryImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/factory/ODataJPAFactoryImpl.java
deleted file mode 100644
index 2b14f9d..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/factory/ODataJPAFactoryImpl.java
+++ /dev/null
@@ -1,237 +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.odata2.processor.core.jpa.factory;
-
-import java.util.Locale;
-
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext.JPAMethodContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAMessageService;
-import org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.factory.JPQLBuilderFactory;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAContextImpl;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAProcessorDefault;
-import org.apache.olingo.odata2.processor.core.jpa.access.data.JPAFunctionContext;
-import org.apache.olingo.odata2.processor.core.jpa.access.data.JPAProcessorImpl;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmMappingModelService;
-import org.apache.olingo.odata2.processor.core.jpa.edm.ODataJPAEdmProvider;
-import org.apache.olingo.odata2.processor.core.jpa.exception.ODataJPAMessageServiceDefault;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectContext;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectSingleContext;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectSingleStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectContext;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectSingleContext;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectSingleStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmModel;
-
-public class ODataJPAFactoryImpl extends ODataJPAFactory {
-
- @Override
- public JPQLBuilderFactory getJPQLBuilderFactory() {
- return JPQLBuilderFactoryImpl.create();
- };
-
- @Override
- public JPAAccessFactory getJPAAccessFactory() {
- return JPAAccessFactoryImpl.create();
- };
-
- @Override
- public ODataJPAAccessFactory getODataJPAAccessFactory() {
- return ODataJPAAccessFactoryImpl.create();
- };
-
- private static class JPQLBuilderFactoryImpl implements JPQLBuilderFactory {
-
- private static JPQLBuilderFactoryImpl factory = null;
-
- private JPQLBuilderFactoryImpl() {}
-
- @Override
- public JPQLStatementBuilder getStatementBuilder(final JPQLContextView context) {
- JPQLStatementBuilder builder = null;
- switch (context.getType()) {
- case SELECT:
- case SELECT_COUNT: // for $count, Same as select
- builder = new JPQLSelectStatementBuilder(context);
- break;
- case SELECT_SINGLE:
- builder = new JPQLSelectSingleStatementBuilder(context);
- break;
- case JOIN:
- case JOIN_COUNT: // for $count, Same as join
- builder = new JPQLJoinStatementBuilder(context);
- break;
- case JOIN_SINGLE:
- builder = new JPQLJoinSelectSingleStatementBuilder(context);
- default:
- break;
- }
-
- return builder;
- }
-
- @Override
- public JPQLContextBuilder getContextBuilder(final JPQLContextType contextType) {
- JPQLContextBuilder contextBuilder = null;
-
- switch (contextType) {
- case SELECT:
- JPQLSelectContext selectContext = new JPQLSelectContext(false);
- contextBuilder = selectContext.new JPQLSelectContextBuilder();
- break;
- case SELECT_SINGLE:
- JPQLSelectSingleContext singleSelectContext = new JPQLSelectSingleContext();
- contextBuilder = singleSelectContext.new JPQLSelectSingleContextBuilder();
- break;
- case JOIN:
- JPQLJoinSelectContext joinContext = new JPQLJoinSelectContext(false);
- contextBuilder = joinContext.new JPQLJoinContextBuilder();
- break;
- case JOIN_SINGLE:
- JPQLJoinSelectSingleContext joinSingleContext = new JPQLJoinSelectSingleContext();
- contextBuilder = joinSingleContext.new JPQLJoinSelectSingleContextBuilder();
- break;
- case SELECT_COUNT:
- JPQLSelectContext selectCountContext = new JPQLSelectContext(true);
- contextBuilder = selectCountContext.new JPQLSelectContextBuilder();
- break;
- case JOIN_COUNT:
- JPQLJoinSelectContext joinCountContext = new JPQLJoinSelectContext(true);
- contextBuilder = joinCountContext.new JPQLJoinContextBuilder();
- default:
- break;
- }
-
- return contextBuilder;
- }
-
- private static JPQLBuilderFactory create() {
- if (factory == null) {
- return new JPQLBuilderFactoryImpl();
- } else {
- return factory;
- }
- }
-
- @Override
- public JPAMethodContextBuilder getJPAMethodContextBuilder(final JPQLContextType contextType) {
-
- JPAMethodContextBuilder contextBuilder = null;
- switch (contextType) {
- case FUNCTION:
- JPAFunctionContext methodConext = new JPAFunctionContext();
- contextBuilder = methodConext.new JPAFunctionContextBuilder();
-
- break;
- default:
- break;
- }
- return contextBuilder;
- }
-
- }
-
- private static class ODataJPAAccessFactoryImpl implements ODataJPAAccessFactory {
-
- private static ODataJPAAccessFactoryImpl factory = null;
-
- private ODataJPAAccessFactoryImpl() {}
-
- @Override
- public ODataSingleProcessor createODataProcessor(final ODataJPAContext oDataJPAContext) {
- return new ODataJPAProcessorDefault(oDataJPAContext);
- }
-
- @Override
- public EdmProvider createJPAEdmProvider(final ODataJPAContext oDataJPAContext) {
- return new ODataJPAEdmProvider(oDataJPAContext);
- }
-
- @Override
- public ODataJPAContext createODataJPAContext() {
- return new ODataJPAContextImpl();
- }
-
- private static ODataJPAAccessFactoryImpl create() {
- if (factory == null) {
- return new ODataJPAAccessFactoryImpl();
- } else {
- return factory;
- }
- }
-
- @Override
- public ODataJPAMessageService getODataJPAMessageService(final Locale locale) {
- return ODataJPAMessageServiceDefault.getInstance(locale);
- }
-
- }
-
- private static class JPAAccessFactoryImpl implements JPAAccessFactory {
-
- private static JPAAccessFactoryImpl factory = null;
-
- private JPAAccessFactoryImpl() {}
-
- @Override
- public JPAEdmModelView getJPAEdmModelView(final ODataJPAContext oDataJPAContext) {
- JPAEdmModelView view = null;
-
- view = new JPAEdmModel(oDataJPAContext);
- return view;
- }
-
- @Override
- public JPAProcessor getJPAProcessor(final ODataJPAContext oDataJPAContext) {
- JPAProcessor jpaProcessor = new JPAProcessorImpl(oDataJPAContext);
-
- return jpaProcessor;
- }
-
- private static JPAAccessFactoryImpl create() {
- if (factory == null) {
- return new JPAAccessFactoryImpl();
- } else {
- return factory;
- }
- }
-
- @Override
- public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess(final ODataJPAContext oDataJPAContext) {
- JPAEdmMappingModelAccess mappingModelAccess = new JPAEdmMappingModelService(oDataJPAContext);
-
- return mappingModelAccess;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectContext.java
deleted file mode 100644
index 6026464..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectContext.java
+++ /dev/null
@@ -1,171 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLJoinContextView;
-import org.apache.olingo.odata2.processor.core.jpa.ODataExpressionParser;
-
-public class JPQLJoinSelectContext extends JPQLSelectContext implements JPQLJoinContextView {
-
- private List<JPAJoinClause> jpaJoinClauses = null;
-
- protected void setJPAOuterJoinClause(final List<JPAJoinClause> jpaOuterJoinClauses) {
- jpaJoinClauses = jpaOuterJoinClauses;
- }
-
- public JPQLJoinSelectContext(final boolean isCountOnly) {
- super(isCountOnly);
- }
-
- public class JPQLJoinContextBuilder extends JPQLSelectContextBuilder {
-
- protected int relationShipAliasCounter = 0;
-
- @Override
- public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
- try {
-
- if (JPQLJoinSelectContext.this.isCountOnly) {
- setType(JPQLContextType.JOIN_COUNT);
- } else {
- setType(JPQLContextType.JOIN);
- }
-
- setJPAOuterJoinClause(generateJoinClauses());
-
- if (!jpaJoinClauses.isEmpty()) {
- JPAJoinClause joinClause = jpaJoinClauses.get(jpaJoinClauses.size() - 1);
- setJPAEntityName(joinClause.getEntityName());
- setJPAEntityAlias(joinClause.getEntityRelationShipAlias());
- }
-
- setOrderByCollection(generateOrderByFileds());
-
- setSelectExpression(generateSelectExpression());
-
- setWhereExpression(generateWhereExpression());
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return JPQLJoinSelectContext.this;
- }
-
- protected List<JPAJoinClause> generateJoinClauses() throws ODataJPARuntimeException, EdmException {
-
- List<JPAJoinClause> jpaOuterJoinClauses = new ArrayList<JPAJoinClause>();
- JPAJoinClause jpaOuterJoinClause = null;
- String joinCondition = null;
- String entityAlias = generateJPAEntityAlias();
- joinCondition = ODataExpressionParser.parseKeyPredicates(entitySetView.getKeyPredicates(), entityAlias);
-
- EdmEntityType entityType = entitySetView.getStartEntitySet().getEntityType();
- Mapping mapping = (Mapping) entityType.getMapping();
- String entityTypeName = null;
- if (mapping != null) {
- entityTypeName = mapping.getInternalName();
- } else {
- entityTypeName = entityType.getName();
- }
-
- jpaOuterJoinClause =
- new JPAJoinClause(entityTypeName, entityAlias, null, null, joinCondition, JPAJoinClause.JOIN.INNER);
-
- jpaOuterJoinClauses.add(jpaOuterJoinClause);
-
- for (NavigationSegment navigationSegment : entitySetView.getNavigationSegments()) {
-
- EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty();
-
- String relationShipAlias = generateRelationShipAlias();
-
- joinCondition =
- ODataExpressionParser.parseKeyPredicates(navigationSegment.getKeyPredicates(), relationShipAlias);
-
- jpaOuterJoinClause =
- new JPAJoinClause(getFromEntityName(navigationProperty), entityAlias,
- getRelationShipName(navigationProperty), relationShipAlias, joinCondition, JPAJoinClause.JOIN.INNER);
-
- jpaOuterJoinClauses.add(jpaOuterJoinClause);
-
- }
-
- return jpaOuterJoinClauses;
- }
-
- private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException {
-
- String fromRole = navigationProperty.getFromRole();
-
- EdmEntityType toEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType();
-
- EdmMapping mapping = toEntityType.getMapping();
-
- String entityName = null;
- if (mapping != null) {
- entityName = mapping.getInternalName();
- } else {
- entityName = toEntityType.getName();
- }
-
- return entityName;
-
- }
-
- private String getRelationShipName(final EdmNavigationProperty navigationProperty) throws EdmException {
-
- EdmMapping mapping = navigationProperty.getMapping();
-
- String relationShipName = null;
- if (mapping != null) {
- relationShipName = mapping.getInternalName();
- } else {
- relationShipName = navigationProperty.getName();
- }
-
- return relationShipName;
- }
-
- private String generateRelationShipAlias() {
- return new String("R" + ++relationShipAliasCounter);
- }
- }
-
- @Override
- public List<JPAJoinClause> getJPAJoinClauses() {
- return jpaJoinClauses;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContext.java
deleted file mode 100644
index c25eae9..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContext.java
+++ /dev/null
@@ -1,158 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLJoinSelectSingleContextView;
-import org.apache.olingo.odata2.processor.core.jpa.ODataExpressionParser;
-
-public class JPQLJoinSelectSingleContext extends JPQLSelectSingleContext implements JPQLJoinSelectSingleContextView {
-
- private List<JPAJoinClause> jpaJoinClauses = null;
-
- protected void setJPAJoinClause(final List<JPAJoinClause> jpaJoinClauses) {
- this.jpaJoinClauses = jpaJoinClauses;
- }
-
- public class JPQLJoinSelectSingleContextBuilder extends JPQLSelectSingleContextBuilder {
-
- protected int relationShipAliasCounter = 0;
-
- @Override
- public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
- try {
- setType(JPQLContextType.JOIN_SINGLE);
- setJPAJoinClause(generateJoinClauses());
-
- if (!jpaJoinClauses.isEmpty()) {
- JPAJoinClause joinClause = jpaJoinClauses.get(jpaJoinClauses.size() - 1);
- setJPAEntityName(joinClause.getEntityName());
- setJPAEntityAlias(joinClause.getEntityRelationShipAlias());
- }
-
- setKeyPredicates(entityView.getKeyPredicates());
-
- setSelectExpression(generateSelectExpression());
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL, e);
- }
-
- return JPQLJoinSelectSingleContext.this;
- }
-
- protected List<JPAJoinClause> generateJoinClauses() throws ODataJPARuntimeException, EdmException {
-
- List<JPAJoinClause> jpaOuterJoinClauses = new ArrayList<JPAJoinClause>();
- JPAJoinClause jpaOuterJoinClause = null;
- String joinCondition = null;
- String entityAlias = generateJPAEntityAlias();
- joinCondition = ODataExpressionParser.parseKeyPredicates(entityView.getKeyPredicates(), entityAlias);
-
- EdmEntityType entityType = entityView.getStartEntitySet().getEntityType();
- Mapping mapping = (Mapping) entityType.getMapping();
- String entityTypeName = null;
- if (mapping != null) {
- entityTypeName = mapping.getInternalName();
- } else {
- entityTypeName = entityType.getName();
- }
-
- jpaOuterJoinClause =
- new JPAJoinClause(entityTypeName, entityAlias, null, null, joinCondition, JPAJoinClause.JOIN.INNER);
-
- jpaOuterJoinClauses.add(jpaOuterJoinClause);
-
- for (NavigationSegment navigationSegment : entityView.getNavigationSegments()) {
-
- EdmNavigationProperty navigationProperty = navigationSegment.getNavigationProperty();
-
- String relationShipAlias = generateRelationShipAlias();
-
- joinCondition =
- ODataExpressionParser.parseKeyPredicates(navigationSegment.getKeyPredicates(), relationShipAlias);
-
- jpaOuterJoinClause =
- new JPAJoinClause(getFromEntityName(navigationProperty), entityAlias,
- getRelationShipName(navigationProperty), relationShipAlias, joinCondition, JPAJoinClause.JOIN.INNER);
-
- jpaOuterJoinClauses.add(jpaOuterJoinClause);
-
- }
-
- return jpaOuterJoinClauses;
- }
-
- private String getFromEntityName(final EdmNavigationProperty navigationProperty) throws EdmException {
-
- String fromRole = navigationProperty.getFromRole();
-
- EdmEntityType fromEntityType = navigationProperty.getRelationship().getEnd(fromRole).getEntityType();
-
- EdmMapping mapping = fromEntityType.getMapping();
-
- String entityName = null;
- if (mapping != null) {
- entityName = mapping.getInternalName();
- } else {
- entityName = fromEntityType.getName();
- }
-
- return entityName;
-
- }
-
- private String getRelationShipName(final EdmNavigationProperty navigationProperty) throws EdmException {
-
- EdmMapping mapping = navigationProperty.getMapping();
-
- String relationShipName = null;
- if (mapping != null) {
- relationShipName = mapping.getInternalName();
- } else {
- relationShipName = navigationProperty.getName();
- }
-
- return relationShipName;
- }
-
- private String generateRelationShipAlias() {
- return new String("R" + ++relationShipAliasCounter);
- }
- }
-
- @Override
- public List<JPAJoinClause> getJPAJoinClauses() {
- return jpaJoinClauses;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilder.java
deleted file mode 100644
index fd06892..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilder.java
+++ /dev/null
@@ -1,106 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.List;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLJoinSelectSingleContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-
-public class JPQLJoinSelectSingleStatementBuilder extends JPQLStatementBuilder {
-
- JPQLStatement jpqlStatement;
- private JPQLJoinSelectSingleContextView context;
-
- public JPQLJoinSelectSingleStatementBuilder(final JPQLContextView context) {
- this.context = (JPQLJoinSelectSingleContextView) context;
- }
-
- @Override
- public JPQLStatement build() throws ODataJPARuntimeException {
- jpqlStatement = createStatement(createJPQLQuery());
- return jpqlStatement;
-
- }
-
- private String createJPQLQuery() throws ODataJPARuntimeException {
-
- StringBuilder jpqlQuery = new StringBuilder();
- StringBuilder joinWhereCondition = null;
-
- jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
-
- if (context.getJPAJoinClauses() != null && context.getJPAJoinClauses().size() > 0) {
- List<JPAJoinClause> joinClauseList = context.getJPAJoinClauses();
- JPAJoinClause joinClause = joinClauseList.get(0);
- String joinCondition = joinClause.getJoinCondition();
- joinWhereCondition = new StringBuilder();
- if (joinCondition != null) {
- joinWhereCondition.append(joinCondition);
- }
- String relationShipAlias = null;
- joinClause = joinClauseList.get(1);
- jpqlQuery.append(joinClause.getEntityName()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(joinClause.getEntityAlias());
-
- int i = 1;
- int limit = joinClauseList.size();
- relationShipAlias = joinClause.getEntityAlias();
- while (i < limit) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.JOIN).append(JPQLStatement.DELIMITER.SPACE);
-
- joinClause = joinClauseList.get(i);
- jpqlQuery.append(relationShipAlias).append(JPQLStatement.DELIMITER.PERIOD);
- jpqlQuery.append(joinClause.getEntityRelationShip()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(joinClause.getEntityRelationShipAlias());
-
- relationShipAlias = joinClause.getEntityRelationShipAlias();
- i++;
-
- joinCondition = joinClause.getJoinCondition();
- if (joinCondition != null) {
- joinWhereCondition.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND
- + JPQLStatement.DELIMITER.SPACE);
-
- joinWhereCondition.append(joinCondition);
- }
-
- }
- } else {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED, null);
- }
-
- if (joinWhereCondition.length() > 0) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(joinWhereCondition.toString());
- }
-
- return jpqlQuery.toString();
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilder.java
deleted file mode 100644
index 57d0e28..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilder.java
+++ /dev/null
@@ -1,145 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map.Entry;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLJoinContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-
-public class JPQLJoinStatementBuilder extends JPQLStatementBuilder {
-
- JPQLStatement jpqlStatement;
- private JPQLJoinContextView context;
-
- public JPQLJoinStatementBuilder(final JPQLContextView context) {
- this.context = (JPQLJoinContextView) context;
- }
-
- @Override
- public JPQLStatement build() throws ODataJPARuntimeException {
- jpqlStatement = createStatement(createJPQLQuery());
- return jpqlStatement;
-
- }
-
- private String createJPQLQuery() throws ODataJPARuntimeException {
-
- StringBuilder jpqlQuery = new StringBuilder();
- StringBuilder joinWhereCondition = null;
-
- jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
- if (context.getType().equals(JPQLContextType.JOIN_COUNT)) {// $COUNT
- jpqlQuery.append(JPQLStatement.KEYWORD.COUNT).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_LEFT).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_RIGHT).append(JPQLStatement.DELIMITER.SPACE);
- } else { // Normal
- jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
- }
-
- jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
-
- if (context.getJPAJoinClauses() != null && context.getJPAJoinClauses().size() > 0) {
- List<JPAJoinClause> joinClauseList = context.getJPAJoinClauses();
- JPAJoinClause joinClause = joinClauseList.get(0);
- String joinCondition = joinClause.getJoinCondition();
- joinWhereCondition = new StringBuilder();
- if (joinCondition != null) {
- joinWhereCondition.append(joinCondition);
- }
- String relationShipAlias = null;
- joinClause = joinClauseList.get(1);
- jpqlQuery.append(joinClause.getEntityName()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(joinClause.getEntityAlias());
-
- int i = 1;
- int limit = joinClauseList.size();
- relationShipAlias = joinClause.getEntityAlias();
- while (i < limit) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(JPQLStatement.KEYWORD.JOIN).append(JPQLStatement.DELIMITER.SPACE);
-
- joinClause = joinClauseList.get(i);
- jpqlQuery.append(relationShipAlias).append(JPQLStatement.DELIMITER.PERIOD);
- jpqlQuery.append(joinClause.getEntityRelationShip()).append(JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(joinClause.getEntityRelationShipAlias());
-
- relationShipAlias = joinClause.getEntityRelationShipAlias();
- i++;
-
- joinCondition = joinClause.getJoinCondition();
- if (joinCondition != null) {
- joinWhereCondition.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND
- + JPQLStatement.DELIMITER.SPACE);
-
- joinWhereCondition.append(joinCondition);
- }
- }
- } else {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED, null);
- }
- String whereExpression = context.getWhereExpression();
- if (whereExpression != null || joinWhereCondition.length() > 0) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.KEYWORD.WHERE).append(
- JPQLStatement.DELIMITER.SPACE);
- if (whereExpression != null) {
- jpqlQuery.append(whereExpression);
- if (joinWhereCondition != null) {
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE);
- }
- }
- if (joinWhereCondition != null) {
- jpqlQuery.append(joinWhereCondition.toString());
- }
-
- }
-
- if (context.getOrderByCollection() != null && context.getOrderByCollection().size() > 0) {
-
- StringBuilder orderByBuilder = new StringBuilder();
- Iterator<Entry<String, String>> orderItr = context.getOrderByCollection().entrySet().iterator();
-
- int i = 0;
-
- while (orderItr.hasNext()) {
- if (i != 0) {
- orderByBuilder.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.DELIMITER.COMMA).append(
- JPQLStatement.DELIMITER.SPACE);
- }
- Entry<String, String> entry = orderItr.next();
- orderByBuilder.append(entry.getKey()).append(JPQLStatement.DELIMITER.SPACE);
- orderByBuilder.append(entry.getValue());
- i++;
- }
- jpqlQuery.append(JPQLStatement.DELIMITER.SPACE).append(JPQLStatement.KEYWORD.ORDERBY).append(
- JPQLStatement.DELIMITER.SPACE);
- jpqlQuery.append(orderByBuilder);
- }
-
- return jpqlQuery.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContext.java
deleted file mode 100644
index ef588aa..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContext.java
+++ /dev/null
@@ -1,159 +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.odata2.processor.core.jpa.jpql;
-
-import java.util.HashMap;
-
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLSelectContextView;
-import org.apache.olingo.odata2.processor.core.jpa.ODataExpressionParser;
-
-public class JPQLSelectContext extends JPQLContext implements JPQLSelectContextView {
-
- protected String selectExpression;
- protected HashMap<String, String> orderByCollection;
- protected String whereCondition;
-
- protected boolean isCountOnly = false;// Support for $count
-
- public JPQLSelectContext(final boolean isCountOnly) {
- this.isCountOnly = isCountOnly;
- }
-
- protected final void setOrderByCollection(final HashMap<String, String> orderByCollection) {
- this.orderByCollection = orderByCollection;
- }
-
- protected final void setWhereExpression(final String filterExpression) {
- whereCondition = filterExpression;
- }
-
- protected final void setSelectExpression(final String selectExpression) {
- this.selectExpression = selectExpression;
- }
-
- @Override
- public String getSelectExpression() {
- return selectExpression;
- }
-
- @Override
- public HashMap<String, String> getOrderByCollection() {
- return orderByCollection;
- }
-
- @Override
- public String getWhereExpression() {
- return whereCondition;
- }
-
- public class JPQLSelectContextBuilder extends
- org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder {
-
- protected GetEntitySetUriInfo entitySetView;
-
- @Override
- public JPQLContext build() throws ODataJPAModelException, ODataJPARuntimeException {
- if (entitySetView != null) {
-
- try {
-
- if (isCountOnly) {
- setType(JPQLContextType.SELECT_COUNT);
- } else {
- setType(JPQLContextType.SELECT);
- }
- EdmEntityType entityType = entitySetView.getTargetEntitySet().getEntityType();
- EdmMapping mapping = entityType.getMapping();
- if (mapping != null) {
- setJPAEntityName(mapping.getInternalName());
- } else {
- setJPAEntityName(entityType.getName());
- }
-
- setJPAEntityAlias(generateJPAEntityAlias());
-
- setOrderByCollection(generateOrderByFileds());
-
- setSelectExpression(generateSelectExpression());
-
- setWhereExpression(generateWhereExpression());
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- }
-
- return JPQLSelectContext.this;
-
- }
-
- @Override
- protected void setResultsView(final Object resultsView) {
- if (resultsView instanceof GetEntitySetUriInfo) {
- entitySetView = (GetEntitySetUriInfo) resultsView;
- }
-
- }
-
- /*
- * Generate Select Clause
- */
- protected String generateSelectExpression() throws EdmException {
- return getJPAEntityAlias();
- }
-
- /*
- * Generate Order By Clause Fields
- */
- protected HashMap<String, String> generateOrderByFileds() throws ODataJPARuntimeException, EdmException {
-
- if (entitySetView.getOrderBy() != null) {
-
- return ODataExpressionParser.parseToJPAOrderByExpression(entitySetView.getOrderBy(), getJPAEntityAlias());
-
- } else if (entitySetView.getTop() != null || entitySetView.getSkip() != null) {
-
- return ODataExpressionParser.parseKeyPropertiesToJPAOrderByExpression(entitySetView.getTargetEntitySet()
- .getEntityType().getKeyProperties(), getJPAEntityAlias());
- } else {
- return null;
- }
-
- }
-
- /*
- * Generate Where Clause Expression
- */
- protected String generateWhereExpression() throws ODataException {
- if (entitySetView.getFilter() != null) {
- return ODataExpressionParser.parseToJPAWhereExpression(entitySetView.getFilter(), getJPAEntityAlias());
- }
- return null;
- }
- }
-
-}
[18/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java
new file mode 100644
index 0000000..a453984
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintRoleTest.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView.RoleType;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAJavaMemberMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAManagedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmReferentialConstraintRole;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmReferentialConstraintRoleTest extends JPAEdmTestModelView {
+
+ private static JPAEdmReferentialConstraintRole objJPAEdmReferentialConstraintRole = null;
+ private static JPAEdmReferentialConstraintRoleTest objJPAEdmReferentialConstraintRoleTest = null;
+
+ @Before
+ public void setUp() {
+ objJPAEdmReferentialConstraintRoleTest = new JPAEdmReferentialConstraintRoleTest();
+
+ objJPAEdmReferentialConstraintRole =
+ new JPAEdmReferentialConstraintRole(RoleType.PRINCIPAL, objJPAEdmReferentialConstraintRoleTest,
+ objJPAEdmReferentialConstraintRoleTest, objJPAEdmReferentialConstraintRoleTest);
+
+ try {
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testIsExists() {
+ assertTrue(objJPAEdmReferentialConstraintRole.isExists());// Default
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmReferentialConstraintRole.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmReferentialConstraintRole.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmReferentialConstraintRole.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetRoleTypePrincipal() {
+ assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.PRINCIPAL);
+ }
+
+ @Test
+ public void testGetRoleTypeDependent() {
+ objJPAEdmReferentialConstraintRoleTest = new JPAEdmReferentialConstraintRoleTest();
+ objJPAEdmReferentialConstraintRole =
+ new JPAEdmReferentialConstraintRole(RoleType.DEPENDENT, objJPAEdmReferentialConstraintRoleTest,
+ objJPAEdmReferentialConstraintRoleTest, objJPAEdmReferentialConstraintRoleTest);
+
+ try {
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(objJPAEdmReferentialConstraintRole.getRoleType(), RoleType.DEPENDENT);
+ }
+
+ @Test
+ public void testGetEdmReferentialConstraintRole() {
+ try {
+ objJPAEdmReferentialConstraintRole.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(objJPAEdmReferentialConstraintRole.getEdmReferentialConstraintRole());
+ }
+
+ @Test
+ public void testGetJPAColumnName() {
+ assertNull(objJPAEdmReferentialConstraintRole.getJPAColumnName());
+ }
+
+ @Test
+ public void testGetEdmEntityTypeName() {
+ assertNull(objJPAEdmReferentialConstraintRole.getEdmEntityTypeName());
+ }
+
+ @Test
+ public void testGetEdmAssociationName() {
+ assertNull(objJPAEdmReferentialConstraintRole.getEdmAssociationName());
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
+ association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
+ "SalesOrderHeader"));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
+ .setRole("SalesOrderItem"));
+ return association;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+
+ EntityType entityType = new EntityType();
+
+ JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
+ mapping.setJPAColumnName("SOID");
+
+ List<Property> propList = new ArrayList<Property>();
+
+ Property property = new Property() {};
+ property.setMapping((Mapping) mapping);
+ property.setName("SOID");
+ propList.add(property);
+
+ entityType.setProperties(propList);
+
+ return entityType;
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @SuppressWarnings("hiding")
+ private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @Override
+ public Member getJavaMember() {
+ return new JavaMemberMock();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public ManagedType<Object> getDeclaringType() {
+ return (ManagedType<Object>) getManagedTypeLocal();
+ }
+
+ private ManagedType<?> getManagedTypeLocal() {
+ ManagedTypeMock<String> managedTypeMock = new ManagedTypeMock<String>();
+ return managedTypeMock;
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class ManagedTypeMock<String> extends JPAManagedTypeMock<String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+ }
+
+ private class JavaMemberMock extends JPAJavaMemberMock {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
+ JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+ EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID");
+ EasyMock.expect(joinColumn.name()).andReturn("SOID");
+
+ EasyMock.replay(joinColumn);
+ return (T) joinColumn;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java
new file mode 100644
index 0000000..885ff86
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmReferentialConstraintTest.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAJavaMemberMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAManagedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmReferentialConstraint;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmReferentialConstraintTest extends JPAEdmTestModelView {
+
+ private static JPAEdmReferentialConstraint objJPAEdmReferentialConstraint = null;
+ private static JPAEdmReferentialConstraintTest objJPAEdmReferentialConstraintTest = null;
+
+ @Before
+ public void setUp() {
+ objJPAEdmReferentialConstraintTest = new JPAEdmReferentialConstraintTest();
+ objJPAEdmReferentialConstraint =
+ new JPAEdmReferentialConstraint(objJPAEdmReferentialConstraintTest, objJPAEdmReferentialConstraintTest,
+ objJPAEdmReferentialConstraintTest);
+ try {
+ objJPAEdmReferentialConstraint.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmReferentialConstraint.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmReferentialConstraint.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmReferentialConstraint.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetEdmReferentialConstraint() {
+ assertNotNull(objJPAEdmReferentialConstraint.getEdmReferentialConstraint());
+ }
+
+ @Test
+ public void testIsExistsTrue() {
+ objJPAEdmReferentialConstraintTest = new JPAEdmReferentialConstraintTest();
+ objJPAEdmReferentialConstraint =
+ new JPAEdmReferentialConstraint(objJPAEdmReferentialConstraintTest, objJPAEdmReferentialConstraintTest,
+ objJPAEdmReferentialConstraintTest);
+ try {
+ objJPAEdmReferentialConstraint.getBuilder().build();
+ objJPAEdmReferentialConstraint.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertTrue(objJPAEdmReferentialConstraint.isExists());
+ }
+
+ @Test
+ public void testGetRelationShipName() {
+ assertEquals("Assoc_SalesOrderHeader_SalesOrderItem", objJPAEdmReferentialConstraint.getEdmRelationShipName());
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
+ association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
+ "SalesOrderHeader"));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
+ .setRole("SalesOrderItem"));
+ return association;
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @SuppressWarnings("hiding")
+ private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @Override
+ public Member getJavaMember() {
+ return new JavaMemberMock();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public ManagedType<Object> getDeclaringType() {
+ return (ManagedType<Object>) getManagedTypeLocal();
+ }
+
+ private ManagedType<?> getManagedTypeLocal() {
+ ManagedTypeMock<String> managedTypeMock = new ManagedTypeMock<String>();
+ return managedTypeMock;
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class ManagedTypeMock<String> extends JPAManagedTypeMock<String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+ }
+
+ private class JavaMemberMock extends JPAJavaMemberMock {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
+ JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+ EasyMock.expect(joinColumn.referencedColumnName()).andReturn("SOID");
+ EasyMock.expect(joinColumn.name()).andReturn("SOID");
+
+ EasyMock.replay(joinColumn);
+ return (T) joinColumn;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java
new file mode 100644
index 0000000..b366191
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmSchemaTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmSchema;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmSchemaTest extends JPAEdmTestModelView {
+ private JPAEdmSchemaTest objJPAEdmSchemaTest;
+ private JPAEdmSchema objJPAEdmSchema;
+
+ @Before
+ public void setUp() {
+ objJPAEdmSchemaTest = new JPAEdmSchemaTest();
+ objJPAEdmSchema = new JPAEdmSchema(objJPAEdmSchemaTest);
+ // building schema is not required as downstream structure already tested
+
+ }
+
+ @Test
+ public void testClean() {
+ assertTrue(objJPAEdmSchema.isConsistent());
+ objJPAEdmSchema.clean();
+ assertFalse(objJPAEdmSchema.isConsistent());
+ }
+
+ @Test
+ public void testGetEdmSchema() {
+ assertNull(objJPAEdmSchema.getEdmSchema());
+ }
+
+ @Test
+ public void testGetJPAEdmEntityContainerView() {
+ assertNull(objJPAEdmSchema.getJPAEdmEntityContainerView());
+ }
+
+ @Test
+ public void testGetJPAEdmComplexTypeView() {
+ assertNull(objJPAEdmSchema.getJPAEdmComplexTypeView());
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmSchema.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmSchema.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmSchema.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetJPAEdmAssociationView() {
+ assertNull(objJPAEdmSchema.getJPAEdmAssociationView());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmSchema.isConsistent());
+ objJPAEdmSchema.clean();
+ assertFalse(objJPAEdmSchema.isConsistent());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAMetaModelMock();
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java
new file mode 100644
index 0000000..d145239
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmTestModelView.java
@@ -0,0 +1,400 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import java.util.HashMap;
+import java.util.List;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmBaseView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView;
+
+public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAssociationSetView, JPAEdmAssociationView,
+ JPAEdmBaseView, JPAEdmComplexPropertyView, JPAEdmComplexTypeView, JPAEdmEntityContainerView, JPAEdmEntitySetView,
+ JPAEdmEntityTypeView, JPAEdmKeyView, JPAEdmModelView, JPAEdmNavigationPropertyView, JPAEdmPropertyView,
+ JPAEdmReferentialConstraintView, JPAEdmSchemaView {
+
+ protected JPAEdmMappingModelAccess mappingModelAccess;
+
+ @Override
+ public Schema getEdmSchema() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmAssociationView getJPAEdmAssociationView() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return null;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmKeyView getJPAEdmKeyView() {
+ return null;
+ }
+
+ @Override
+ public List<Property> getEdmPropertyList() {
+ return null;
+ }
+
+ @Override
+ public SimpleProperty getEdmSimpleProperty() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmSchemaView getEdmSchemaView() {
+ return null;
+ }
+
+ @Override
+ public Key getEdmKey() {
+ return null;
+ }
+
+ @Override
+ public List<EntityType> getConsistentEdmEntityTypes() {
+ return null;
+ }
+
+ @Override
+ public EntityType getEdmEntityType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.EntityType<?> getJPAEntityType() {
+ return null;
+ }
+
+ @Override
+ public List<EntitySet> getConsistentEdmEntitySetList() {
+ return null;
+ }
+
+ @Override
+ public EntitySet getEdmEntitySet() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return null;
+ }
+
+ @Override
+ public List<EntityContainer> getConsistentEdmEntityContainerList() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmAssociationSetView getEdmAssociationSetView() {
+ return null;
+ }
+
+ @Override
+ public EntityContainer getEdmEntityContainer() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmCompleTypeView(final JPAEdmComplexTypeView arg0) {
+
+ }
+
+ @Override
+ public List<ComplexType> getConsistentEdmComplexTypes() {
+ return null;
+ }
+
+ @Override
+ public ComplexType getEdmComplexType() {
+ return null;
+ }
+
+ @Override
+ public EmbeddableType<?> getJPAEmbeddableType() {
+ return null;
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final FullQualifiedName arg0) {
+ return null;
+ }
+
+ @Override
+ public ComplexProperty getEdmComplexProperty() {
+ return null;
+ }
+
+ @Override
+ public void clean() {
+
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ return null;
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return null;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return null;
+ }
+
+ @Override
+ public boolean isConsistent() {
+ return false;
+ }
+
+ @Override
+ public void addJPAEdmRefConstraintView(final JPAEdmReferentialConstraintView arg0) {
+
+ }
+
+ @Override
+ public ReferentialConstraint getEdmReferentialConstraint() {
+ return null;
+ }
+
+ @Override
+ public String getEdmRelationShipName() {
+ return null;
+ }
+
+ @Override
+ public boolean isExists() {
+ return false;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
+ return null;
+ }
+
+ @Override
+ public List<Association> getConsistentEdmAssociationList() {
+ return null;
+ }
+
+ @Override
+ public Association searchAssociation(final JPAEdmAssociationEndView arg0) {
+ return null;
+ }
+
+ @Override
+ public List<AssociationSet> getConsistentEdmAssociationSetList() {
+ return null;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ return null;
+ }
+
+ @Override
+ public AssociationSet getEdmAssociationSet() {
+ return null;
+ }
+
+ @Override
+ public boolean compare(final AssociationEnd arg0, final AssociationEnd arg1) {
+ return false;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd1() {
+ return null;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd2() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() {
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmNavigationPropertyView(final JPAEdmNavigationPropertyView view) {
+
+ }
+
+ @Override
+ public List<NavigationProperty> getConsistentEdmNavigationProperties() {
+ return null;
+ }
+
+ @Override
+ public NavigationProperty getEdmNavigationProperty() {
+ return null;
+ }
+
+ @Override
+ public void expandEdmComplexType(final ComplexType complexType, final List<Property> expandedPropertyList,
+ final String embeddablePropertyName) {
+
+ }
+
+ @Override
+ public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
+ return null;
+ }
+
+ @Override
+ public void registerOperations(final Class<?> customClass, final String[] methodNames) {
+ // Do nothing
+ }
+
+ @Override
+ public HashMap<Class<?>, String[]> getRegisteredOperations() {
+ return null;
+ }
+
+ @Override
+ public JPAEdmExtension getJPAEdmExtension() {
+ return null;
+ }
+
+ @Override
+ public void addJPAEdmAssociationView(final JPAEdmAssociationView associationView,
+ final JPAEdmAssociationEndView associationEndView) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getJoinColumnName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getJoinColumnReferenceColumnName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getMappedByName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getOwningPropertyName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isDefaultNamingSkipped() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
new file mode 100644
index 0000000..02b6c9f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/_JPAEdmFunctionImportTest.java
@@ -0,0 +1,571 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorNegativeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmFunctionImport;
+import org.junit.Before;
+import org.junit.Test;
+
+@Deprecated
+public class _JPAEdmFunctionImportTest extends JPAEdmTestModelView {
+ private static final int METHOD_COUNT = 6;
+ private static int VARIANT = 0;
+ private JPAEdmFunctionImport jpaEdmfunctionImport;
+
+ @Before
+ public void setup() {
+ jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
+ }
+
+ /**
+ * Test Case - Function Import Basic test - Positive Case
+ */
+ @Test
+ public void testFunctionImportBasic() {
+ VARIANT = 0;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+ for (FunctionImport functionImport : functionImportList) {
+ assertEquals(functionImport.getName(), "Method1");
+ assertNotNull(functionImport.getMapping());
+ Mapping mapping = new Mapping();
+ mapping.setInternalName("method1");
+
+ assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
+
+ List<FunctionImportParameter> funcImpList = functionImport.getParameters();
+ assertEquals(2, funcImpList.size());
+ assertEquals("Param1", funcImpList.get(0).getName());
+ assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType());
+ assertEquals(Mode.IN.toString(), funcImpList.get(0).getMode());
+
+ assertEquals("Param3", funcImpList.get(1).getName());
+ assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType());
+ assertEquals(Mode.IN.toString(), funcImpList.get(1).getMode());
+
+ }
+
+ }
+
+ /**
+ * Test Case - Enable a method that does not exists
+ */
+ @Test
+ public void testFunctionImportNoSuchMethod() {
+ VARIANT = 1;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ /**
+ * Test Case - Enable all annotated methods in a class as function imports
+ */
+ @Test
+ public void testFunctionImportAllMethods() {
+ VARIANT = 2;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(METHOD_COUNT, functionImportList.size());
+
+ }
+
+ /**
+ * Test Case - Function Import with no names. Default name is Java method
+ * name.
+ */
+ @Test
+ public void testFunctionImportNoName() {
+ VARIANT = 3;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method3");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString());
+ }
+
+ /**
+ * Test Case - Function Import with No return type defined - Negative case
+ */
+ @Test
+ public void testNoReturnType() {
+ VARIANT = 4;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ /**
+ * Test Case - Function Import with return type as Entity and Multiplicity
+ * as Many but no Entity set defined. --> Negative Case
+ */
+ @Test
+ public void testNoEntitySet() {
+ VARIANT = 5;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+ }
+
+ /**
+ * Test Case - Function Import with return type as Entity Type but method
+ * has returns void. --> Negative Case
+ */
+ @Test
+ public void testNoReturnTypeButAnnotated() {
+ VARIANT = 6;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+ }
+
+ /**
+ * Test Case - Function Import that returns an Entity Type with Multiplicity
+ * as ONE. -->Positive Case
+ */
+ @Test
+ public void testFunctionImportEntityTypeSingleReturn() {
+ VARIANT = 7;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method7");
+ assertNotNull(functionImport.getMapping());
+ JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping();
+ assertEquals(_JPACustomProcessorMock.class, mapping.getJPAType());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + _JPACustomProcessorMock.edmName);
+ }
+
+ /**
+ * Test Case - Function Import that returns an Entity Type that is not found
+ * in JPA Model
+ */
+ @Test
+ public void testFunctionImportEntityTypeInvalid() {
+ VARIANT = 8;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that returns a complex Type
+ */
+ @Test
+ public void testFunctionImportComplexType() {
+ VARIANT = 9;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method9");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + _JPACustomProcessorMock.edmName);
+
+ }
+
+ /**
+ * Test Case - Function Import that returns a complex Type with multiplicity
+ * Many
+ */
+ @Test
+ public void testFunctionImportComplexTypeMany() {
+ VARIANT = 10;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method10");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + _JPACustomProcessorMock.edmName);
+
+ }
+
+ /**
+ * Test Case - Function Import that returns an Complex Type that is not
+ * found in JPA Model
+ */
+ @Test
+ public void testFunctionImportComplexTypeInvalid() {
+ VARIANT = 11;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that returns an scalar Type that is not valid
+ */
+ @Test
+ public void testFunctionImportScalarTypeInvalid() {
+ VARIANT = 12;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that takes a parameter with no name
+ */
+ @Test
+ public void testFunctionImportParamNoName() {
+ VARIANT = 13;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import test for facets
+ */
+ @Test
+ public void testFunctionImportParamFacets() {
+ VARIANT = 14;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
+ EdmFacets facets = funcImpParamList.get(0).getFacets();
+ assertNotNull(facets);
+ assertEquals(2, facets.getMaxLength().intValue());
+ assertEquals(true, facets.isNullable());
+
+ facets = funcImpParamList.get(1).getFacets();
+ assertNotNull(facets);
+ assertEquals(false, facets.isNullable());
+ assertEquals(10, facets.getPrecision().intValue());
+ assertEquals(2, facets.getScale().intValue());
+
+ }
+
+ /**
+ * Test Case - Function Import test for default facets
+ */
+ @Test
+ public void testFunctionImportParamFacetsDefault() {
+ VARIANT = 15;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
+ EdmFacets facets = funcImpParamList.get(0).getFacets();
+ assertNotNull(facets);
+ assertNull(facets.getMaxLength());
+ assertEquals(false, facets.isNullable());
+ assertNull(facets.getPrecision());
+ assertNull(facets.getScale());
+
+ }
+
+ /**
+ * Test Case - Function Import test for ReturnType.SCALAR but method returns
+ * void
+ */
+ @Test
+ public void testWrongReturnTypeScalar() {
+ VARIANT = 16;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import test for ReturnType.COMPLEX but method returns
+ * void
+ */
+ @Test
+ public void testWrongReturnTypeComplex() {
+ VARIANT = 17;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ @Test
+ public void testNoFunctionImport() {
+ VARIANT = 99;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
+
+ JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder();
+ JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public HashMap<Class<?>, String[]> getRegisteredOperations() {
+
+ HashMap<Class<?>, String[]> customOperations = new HashMap<Class<?>, String[]>();
+
+ if (VARIANT == 0) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
+ } else if (VARIANT == 1) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "XYX" });
+ } else if (VARIANT == 2) {
+ customOperations.put(_JPACustomProcessorMock.class, null);
+ } else if (VARIANT == 3) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
+ } else if (VARIANT == 4) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method4" });
+ } else if (VARIANT == 5) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
+ } else if (VARIANT == 6) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
+ } else if (VARIANT == 7) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method7" });
+ } else if (VARIANT == 8) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
+ } else if (VARIANT == 9) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method9" });
+ } else if (VARIANT == 10) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method10" });
+ } else if (VARIANT == 11) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
+ } else if (VARIANT == 12) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
+ } else if (VARIANT == 13) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
+ } else if (VARIANT == 14) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method1" });
+ } else if (VARIANT == 15) {
+ customOperations.put(_JPACustomProcessorMock.class, new String[] { "method3" });
+ } else if (VARIANT == 16) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
+ } else if (VARIANT == 17) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
+ } else {
+ return null;
+ }
+
+ return customOperations;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return this;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+ if (arg0.equals(_JPACustomProcessorMock.class.getSimpleName())) {
+ return new EntityType().setName(_JPACustomProcessorMock.edmName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String arg0) {
+ if (arg0.equals(_JPACustomProcessorMock.class.getName())) {
+ return new ComplexType().setName(_JPACustomProcessorMock.edmName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getpUnitName() {
+ return ODataJPAContextMock.PERSISTENCE_UNIT_NAME;
+ }
+
+ private void build() {
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java
deleted file mode 100644
index 390c7fe..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParserTest.java
+++ /dev/null
@@ -1,515 +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.odata2.processor.core.jpa;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
-import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
-import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
-import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
-import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
-import org.apache.olingo.odata2.api.uri.expression.MethodOperator;
-import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
-import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
-import org.apache.olingo.odata2.api.uri.expression.UnaryOperator;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class ODataExpressionParserTest {
-
- private static final String EXPECTED_STR_1 = "gwt1.SalesOrder = 1234";
- private static final String EXPECTED_STR_2 = "gwt1.SalesOrder >= 1234 AND gwt1.SalesABC <> XYZ";
- private static final String EXPECTED_STR_3 = "gwt1.SalesOrder >= 1234 OR gwt1.SalesABC <> XYZ";
- private static final String EXPECTED_STR_4 = "gwt1.SalesOrder < 1234 AND gwt1.SalesABC <= XYZ";
- private static final String EXPECTED_STR_5 = "gwt1.LineItems > 2345 AND gwt1.SalesOrder >= Amazon";
- private static final String EXPECTED_STR_6 = "gwt1.Address.city = \'City_3\'";
- private static final String EXPECTED_STR_7 = "gwt1.Address.city.area = \'BTM\'";
- private static final String EXPECTED_STR_8 = "gwt1.field1 = 1 AND gwt1.field2 = 'abc'";
- private static final String EXPECTED_STR_9 = "gwt1.BuyerAddress, gwt1.BuyerName, gwt1.BuyerId";
- private static final String EXPECTED_STR_10 = "gwt1.SalesOrder";
- private static final String EXPECTED_STR_11 = "NOT(gwt1.deliveryStatus)";
- private static final String EXPECTED_STR_12 =
- "(CASE WHEN (gwt1.currencyCode LIKE '%Ru%') THEN TRUE ELSE FALSE END) = true";
- private static final String EXPECTED_STR_13 = "SUBSTRING(gwt1.currencyCode, 1 + 1 , 2) = 'NR'";
- private static final String EXPECTED_STR_14 = "LOWER(gwt1.currencyCode) = 'inr rupees'";
- private static final String EXPECTED_STR_15 =
- "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END) = true";
- private static final String EXPECTED_STR_16 =
- "(CASE WHEN (gwt1.currencyCode LIKE '%INR%') THEN TRUE ELSE FALSE END) = true";
- private static final String EXPECTED_STR_17 =
- "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END) = true";
-
- private static final String ADDRESS = "Address";
- private static final String CITY = "city";
- private static final String AREA = "area";
- private static final String SALES_ORDER = "SalesOrder";
- private static final String SALES_ABC = "SalesABC";
- private static final String SAMPLE_DATA_1 = "1234";
- private static final String SAMPLE_DATA_2 = "2345";
- private static final String SAMPLE_DATA_XYZ = "XYZ";
- private static final String SAMPLE_DATA_BTM = "\'BTM\'";
- private static final String SAMPLE_DATA_CITY_3 = "\'City_3\'";
- private static final String SAMPLE_DATA_LINE_ITEMS = "LineItems";
- private static final String SAMPLE_DATA_AMAZON = "Amazon";
- private static final String SAMPLE_DATA_FIELD1 = "field1";
- private static final String SAMPLE_DATA_FIELD2 = "field2";
-
- private static final String TABLE_ALIAS = "gwt1"; //$NON-NLS-1$
-
- @Test
- public void testParseWhereExpression() {
- try {
- String parsedStr = ODataJPATestConstants.EMPTY_STRING;
- // Simple Binary query -
- parsedStr =
- ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpressionMockedObj(BinaryOperator.EQ,
- ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1), TABLE_ALIAS);
-
- assertEquals(EXPECTED_STR_1, parsedStr);
- // complex query -
- parsedStr = ODataJPATestConstants.EMPTY_STRING;
-
- CommonExpression exp1 =
- getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
- CommonExpression exp2 =
- getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
- parsedStr =
- ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.AND, exp2),
- TABLE_ALIAS);
- assertEquals(EXPECTED_STR_2, parsedStr);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testMoreThanOneBinaryExpression() {
- // complex query -
- String parsedStr = ODataJPATestConstants.EMPTY_STRING;
- CommonExpression exp1 =
- getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
- CommonExpression exp2 =
- getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
- try {
- parsedStr =
- ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.AND, exp2),
- TABLE_ALIAS);
- assertEquals(EXPECTED_STR_2, parsedStr);
- parsedStr =
- ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.OR, exp2),
- TABLE_ALIAS);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals(EXPECTED_STR_3, parsedStr);
- }
-
- @Test
- public void testParseFilterExpression() {
- try {
- assertEquals(EXPECTED_STR_10, ODataExpressionParser.parseToJPAWhereExpression(getFilterExpressionMockedObj(
- ExpressionKind.PROPERTY, SALES_ORDER), TABLE_ALIAS));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testAllBinaryOperators() { // Test for all Binary Operators
- // complex query -
- String parsedStr1 = ODataJPATestConstants.EMPTY_STRING;
- String parsedStr2 = ODataJPATestConstants.EMPTY_STRING;
-
- CommonExpression exp1 =
- getBinaryExpressionMockedObj(BinaryOperator.LT, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
- CommonExpression exp2 =
- getBinaryExpressionMockedObj(BinaryOperator.LE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
-
- try {
- parsedStr1 =
- ODataExpressionParser.parseToJPAWhereExpression((BinaryExpression) getBinaryExpression(exp1,
- BinaryOperator.AND, exp2), TABLE_ALIAS);
- assertEquals(EXPECTED_STR_4, parsedStr1);
-
- CommonExpression exp3 =
- getBinaryExpressionMockedObj(BinaryOperator.GT, ExpressionKind.PROPERTY, SAMPLE_DATA_LINE_ITEMS,
- SAMPLE_DATA_2);
- CommonExpression exp4 =
- getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_AMAZON);
-
- parsedStr2 =
- ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp3, BinaryOperator.AND, exp4),
- TABLE_ALIAS);
-
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals(EXPECTED_STR_5, parsedStr2);
- }
-
- @Test
- public void testParseMemberExpression() {
- try {
- assertEquals(EXPECTED_STR_6, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
- getMemberExpressionMockedObj(ADDRESS, CITY), BinaryOperator.EQ,
- getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3)), TABLE_ALIAS));
- assertEquals(EXPECTED_STR_7, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
- getMultipleMemberExpressionMockedObj(ADDRESS, CITY, AREA), BinaryOperator.EQ,
- getLiteralExpressionMockedObj(SAMPLE_DATA_BTM)), TABLE_ALIAS));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testParseMethodExpression() {
- try {
- assertEquals(EXPECTED_STR_12, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
- getMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'Ru'", "currencyCode", null, 2), BinaryOperator.EQ,
- getLiteralExpressionMockedObj("true")), TABLE_ALIAS));
- assertEquals(EXPECTED_STR_13, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
- getMethodExpressionMockedObj(MethodOperator.SUBSTRING, "currencyCode", "1", "2", 3), BinaryOperator.EQ,
- getLiteralExpressionMockedObj("'NR'")), TABLE_ALIAS));
- assertEquals(EXPECTED_STR_14, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
- getMethodExpressionMockedObj(MethodOperator.TOLOWER, "currencyCode", null, null, 1), BinaryOperator.EQ,
- getLiteralExpressionMockedObj("'inr rupees'")), TABLE_ALIAS));
- assertEquals(EXPECTED_STR_15, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
- getMultipleMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER,
- "currencyCode", 2, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS));
- assertEquals(EXPECTED_STR_16, ODataExpressionParser.parseToJPAWhereExpression(
- getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'INR'", null, "currencyCode", 2, null)
- /*
- * getBinaryExpression(
- * getMemberExpressionMockedObj(ADDRESS,
- * CITY),
- * BinaryOperator.EQ,
- * getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3))
- */, TABLE_ALIAS));
- assertEquals(EXPECTED_STR_17, ODataExpressionParser.parseToJPAWhereExpression(
- getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER,
- "currencyCode", 2, 1)
- /*
- * getBinaryExpression(
- * getMemberExpressionMockedObj(ADDRESS,
- * CITY),
- * BinaryOperator.EQ,
- * getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3))
- */, TABLE_ALIAS));
-
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- private CommonExpression getMethodExpressionMockedObj(final MethodOperator methodOperator, final String firstName,
- final String secondName, final String thirdName, final Integer parameterCount) {
-
- List<CommonExpression> parameters = new ArrayList<CommonExpression>();
-
- if (methodOperator == MethodOperator.SUBSTRINGOF) {
- parameters.add(getLiteralExpressionMockedObj(firstName));
- parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, secondName));
- } else if (methodOperator == MethodOperator.SUBSTRING) {
- parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, firstName));
- parameters.add(getLiteralExpressionMockedObj(secondName));
- parameters.add(getLiteralExpressionMockedObj(thirdName));
- } else if (methodOperator == MethodOperator.TOLOWER) {
- parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, firstName));
- }
-
- MethodExpression methodExpression = EasyMock.createMock(MethodExpression.class);
-
- EasyMock.expect(methodExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
- EasyMock.expect(methodExpression.getMethod()).andStubReturn(methodOperator);
- EasyMock.expect(methodExpression.getParameterCount()).andStubReturn(parameterCount);
- EasyMock.expect(methodExpression.getParameters()).andStubReturn(parameters);
- EasyMock.replay(methodExpression);
-
- return methodExpression;
- }
-
- private CommonExpression getMultipleMethodExpressionMockedObj(final MethodOperator methodOperator1,
- final String firstName, final MethodOperator methodOperator2, final String secondName,
- final Integer parameterCount1, final Integer parameterCount2) {
-
- // complex query
- List<CommonExpression> parameters = new ArrayList<CommonExpression>();
-
- parameters.add(getLiteralExpressionMockedObj(firstName));
- parameters.add(getMethodExpressionMockedObj(methodOperator2, secondName, null, null, 1));
-
- MethodExpression methodExpression = EasyMock.createMock(MethodExpression.class);
-
- EasyMock.expect(methodExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
- EasyMock.expect(methodExpression.getMethod()).andStubReturn(methodOperator1);
- EasyMock.expect(methodExpression.getParameterCount()).andStubReturn(parameterCount1);
- EasyMock.expect(methodExpression.getParameters()).andStubReturn(parameters);
- EasyMock.replay(methodExpression);
-
- return methodExpression;
- }
-
- private CommonExpression getMultipleMemberExpressionMockedObj(final String string1, final String string2,
- final String string3) {
-
- MemberExpression memberExpression = EasyMock.createMock(MemberExpression.class);
-
- EasyMock.expect(memberExpression.getPath()).andStubReturn(getMemberExpressionMockedObj(string1, string2));
- EasyMock.expect(memberExpression.getProperty()).andStubReturn(
- getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, string3));
- EasyMock.expect(memberExpression.getKind()).andStubReturn(ExpressionKind.MEMBER);
- EasyMock.replay(memberExpression);
-
- return memberExpression;
- }
-
- @Test
- public void testParseUnaryExpression() {
-
- UnaryExpression unaryExpression =
- getUnaryExpressionMockedObj(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, "deliveryStatus"),
- org.apache.olingo.odata2.api.uri.expression.UnaryOperator.NOT);
- try {
- assertEquals(EXPECTED_STR_11, ODataExpressionParser.parseToJPAWhereExpression(unaryExpression, TABLE_ALIAS));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- private UnaryExpression
- getUnaryExpressionMockedObj(final CommonExpression operand, final UnaryOperator unaryOperator) {
- UnaryExpression unaryExpression = EasyMock.createMock(UnaryExpression.class);
- EasyMock.expect(unaryExpression.getKind()).andStubReturn(ExpressionKind.UNARY);
- EasyMock.expect(unaryExpression.getOperand()).andStubReturn(operand);
- EasyMock.expect(unaryExpression.getOperator()).andStubReturn(unaryOperator);
-
- EasyMock.replay(unaryExpression);
- return unaryExpression;
- }
-
- private CommonExpression getMemberExpressionMockedObj(final String pathUriLiteral, final String propertyUriLiteral) {
- MemberExpression memberExpression = EasyMock.createMock(MemberExpression.class);
- EasyMock.expect(memberExpression.getPath()).andStubReturn(
- getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, pathUriLiteral));
- EasyMock.expect(memberExpression.getProperty()).andStubReturn(
- getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, propertyUriLiteral));
- EasyMock.expect(memberExpression.getKind()).andStubReturn(ExpressionKind.MEMBER);
-
- EasyMock.replay(memberExpression);
- return memberExpression;
- }
-
- private LiteralExpression getLiteralExpressionMockedObj(final String uriLiteral) {
- LiteralExpression rightOperandLiteralExpresion = EasyMock.createMock(LiteralExpression.class);
- EasyMock.expect(rightOperandLiteralExpresion.getKind()).andStubReturn(ExpressionKind.LITERAL);
- EasyMock.expect(rightOperandLiteralExpresion.getUriLiteral()).andStubReturn(uriLiteral);// SAMPLE_DATA
- EasyMock.expect(rightOperandLiteralExpresion.getEdmType()).andStubReturn(getEdmSimpleTypeMockedObj(uriLiteral));
- EasyMock.replay(rightOperandLiteralExpresion);
- return rightOperandLiteralExpresion;
-
- }
-
- private EdmSimpleType getEdmSimpleTypeMockedObj(final String value) {
- EdmSimpleType edmSimpleType = EasyMock.createMock(EdmSimpleType.class);
- try {
- EasyMock.expect(edmSimpleType.getName()).andReturn(value);
- EasyMock.expect(edmSimpleType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.expect(edmSimpleType.valueOfString(value, EdmLiteralKind.URI, getEdmFacetsMockedObj(), null))
- .andStubReturn(value);
- EasyMock.expect(edmSimpleType.valueOfString(value, EdmLiteralKind.URI, null, null)).andStubReturn(value);
- EasyMock.expect(edmSimpleType.valueToString(value, EdmLiteralKind.DEFAULT, getEdmFacetsMockedObj()))
- .andStubReturn(value);
- EasyMock.expect(edmSimpleType.valueToString(value, EdmLiteralKind.DEFAULT, null)).andStubReturn(value);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.expect(edmSimpleType.getDefaultType()).andStubReturn(null);
- EasyMock.replay(edmSimpleType);
- return edmSimpleType;
- }
-
- private EdmFacets getEdmFacetsMockedObj() {
- EdmFacets facets = EasyMock.createMock(EdmFacets.class);
-
- EasyMock.replay(facets);
- return facets;
- }
-
- private PropertyExpression getPropertyExpressionMockedObj(final ExpressionKind expKind, final String propertyName) {
- PropertyExpression leftOperandPropertyExpresion = EasyMock.createMock(PropertyExpression.class);
- EasyMock.expect(leftOperandPropertyExpresion.getKind()).andStubReturn(ExpressionKind.PROPERTY);
- EasyMock.expect(leftOperandPropertyExpresion.getPropertyName()).andStubReturn(propertyName);
- EasyMock.expect(leftOperandPropertyExpresion.getEdmProperty()).andStubReturn(getEdmTypedMockedObj(propertyName));
- EasyMock.replay(leftOperandPropertyExpresion);
- return leftOperandPropertyExpresion;
- }
-
- private EdmTyped getEdmTypedMockedObj(final String propertyName) {
- EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
- try {
- EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
- EasyMock.replay(mockedEdmProperty);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- return mockedEdmProperty;
- }
-
- private EdmMapping getEdmMappingMockedObj(final String propertyName) {
- EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
- EasyMock.replay(mockedEdmMapping);
- return mockedEdmMapping;
- }
-
- private BinaryExpression getBinaryExpressionMockedObj(final BinaryOperator operator,
- final ExpressionKind leftOperandExpKind, final String propertyName, final String literalStr) {
- BinaryExpression binaryExpression = EasyMock.createMock(BinaryExpression.class);
- EasyMock.expect(binaryExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
- EasyMock.expect(binaryExpression.getLeftOperand()).andStubReturn(
- getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
- EasyMock.expect(binaryExpression.getOperator()).andStubReturn(operator);
- EasyMock.expect(binaryExpression.getRightOperand()).andStubReturn(getLiteralExpressionMockedObj(literalStr));
-
- EasyMock.replay(binaryExpression);
- return binaryExpression;
- }
-
- private FilterExpression getFilterExpressionMockedObj(final ExpressionKind leftOperandExpKind,
- final String propertyName) {
- FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
- EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
- EasyMock.expect(filterExpression.getExpression()).andStubReturn(
- getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
-
- EasyMock.replay(filterExpression);
- return filterExpression;
- }
-
- private FilterExpression getFilterExpressionForFunctionsMockedObj(final MethodOperator methodOperator1,
- final String firstName, final MethodOperator methodOperator2, final String secondName,
- final Integer parameterCount1, final Integer parameterCount2) {
- // default value handling of SUBSTRINGOF
- FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
- EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
- if ((methodOperator2 != null) && (parameterCount2 != null)) {
- EasyMock.expect(filterExpression.getExpression()).andStubReturn(
- getMultipleMethodExpressionMockedObj(methodOperator1, firstName, methodOperator2, secondName,
- parameterCount1, parameterCount2));
- } else {
- EasyMock.expect(filterExpression.getExpression()).andStubReturn(
- getMethodExpressionMockedObj(methodOperator1, firstName, secondName, null, parameterCount1));
- }
-
- EasyMock.replay(filterExpression);
- return filterExpression;
- }
-
- private CommonExpression getBinaryExpression(final CommonExpression leftOperand, final BinaryOperator operator,
- final CommonExpression rightOperand) {
- BinaryExpression binaryExpression = EasyMock.createMock(BinaryExpression.class);
- EasyMock.expect(binaryExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
- EasyMock.expect(binaryExpression.getLeftOperand()).andStubReturn(leftOperand);
- EasyMock.expect(binaryExpression.getRightOperand()).andStubReturn(rightOperand);
- EasyMock.expect(binaryExpression.getOperator()).andStubReturn(operator);
-
- EasyMock.replay(binaryExpression);
- return binaryExpression;
- }
-
- @Test
- public void testParseKeyPredicates() {
- // Setting up the expected value
- KeyPredicate keyPredicate1 = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty1 = EasyMock.createMock(EdmProperty.class);
- EasyMock.expect(keyPredicate1.getLiteral()).andStubReturn("1");
- KeyPredicate keyPredicate2 = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty2 = EasyMock.createMock(EdmProperty.class);
- EasyMock.expect(keyPredicate2.getLiteral()).andStubReturn("abc");
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- try {
- EasyMock.expect(kpProperty1.getName()).andStubReturn(SAMPLE_DATA_FIELD1);
- EasyMock.expect(kpProperty1.getType()).andStubReturn(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance());
- EasyMock.expect(kpProperty2.getName()).andStubReturn(SAMPLE_DATA_FIELD2);
- EasyMock.expect(kpProperty2.getType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
- EasyMock.expect(keyPredicate1.getProperty()).andStubReturn(kpProperty1);
- EasyMock.expect(kpProperty1.getMapping()).andReturn(edmMapping);
- EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD1);
- EasyMock.expect(keyPredicate2.getProperty()).andStubReturn(kpProperty2);
- EasyMock.expect(kpProperty2.getMapping()).andReturn(edmMapping);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD2);
- EasyMock.replay(edmMapping);
- EasyMock.replay(kpProperty1, keyPredicate1, kpProperty2, keyPredicate2);
-
- ArrayList<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate1);
- keyPredicates.add(keyPredicate2);
- String str = null;
-
- try {
- str = ODataExpressionParser.parseKeyPredicates(keyPredicates, TABLE_ALIAS);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals(EXPECTED_STR_8, str);
- }
-
- @Test
- public void testParseToJPASelectExpression() {
-
- ArrayList<String> selectedFields = new ArrayList<String>();
- selectedFields.add("BuyerAddress");
- selectedFields.add("BuyerName");
- selectedFields.add("BuyerId");
-
- assertEquals(EXPECTED_STR_9, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields));
- assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, null));
-
- selectedFields.clear();
- assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java
deleted file mode 100644
index 10e65c0..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImplTest.java
+++ /dev/null
@@ -1,98 +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.odata2.processor.core.jpa;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.core.jpa.edm.ODataJPAEdmProvider;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ODataJPAContextImplTest {
-
- private ODataContext odataContext = null;
- private ODataJPAContext odataJPAContext = null;
- private EdmProvider edmProvider = null;
- private EntityManagerFactory emf = null;
- private EntityManager em = null;
- private ODataProcessor processor = null;
-
- @Before
- public void setup() {
-
- edmProvider = new ODataJPAEdmProvider();
- emf = EasyMock.createMock(EntityManagerFactory.class);
- em = EasyMock.createMock(EntityManager.class);
- EasyMock.replay(em);
-
- EasyMock.expect(emf.createEntityManager()).andStubReturn(em);
- EasyMock.replay(emf);
-
- odataContext = EasyMock.createMock(ODataContext.class);
- List<Locale> listLocale = new ArrayList<Locale>();
- listLocale.add(Locale.ENGLISH);
- listLocale.add(Locale.GERMAN);
-
- EasyMock.expect(odataContext.getAcceptableLanguages()).andStubReturn(listLocale);
- EasyMock.replay(odataContext);
-
- processor = EasyMock.createMock(ODataProcessor.class);
- EasyMock.replay(processor);
-
- odataJPAContext = new ODataJPAContextImpl();
- odataJPAContext.setEdmProvider(edmProvider);
- odataJPAContext.setEntityManagerFactory(emf);
- odataJPAContext.setODataContext(odataContext);
- odataJPAContext.setODataProcessor(processor);
- odataJPAContext.setPersistenceUnitName(ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
- odataJPAContext.setJPAEdmMappingModel(ODataJPAContextMock.MAPPING_MODEL);
- }
-
- @Test
- public void testgetMethodsOfODataJPAContext() {
-
- assertEquals(odataJPAContext.getEdmProvider().hashCode(), edmProvider.hashCode());
- assertEquals(odataJPAContext.getEntityManagerFactory().hashCode(), emf.hashCode());
- assertEquals(odataJPAContext.getODataContext().hashCode(), odataContext.hashCode());
- assertEquals(odataJPAContext.getODataProcessor().hashCode(), processor.hashCode());
- assertEquals(odataJPAContext.getPersistenceUnitName(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
- assertEquals(odataJPAContext.getJPAEdmMappingModel(), ODataJPAContextMock.MAPPING_MODEL);
-
- EntityManager em1 = odataJPAContext.getEntityManager();
- EntityManager em2 = odataJPAContext.getEntityManager();
- if (em1 != null && em2 != null) {
- assertEquals(em1.hashCode(), em2.hashCode());
- }
-
- }
-
-}
[24/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
new file mode 100644
index 0000000..f4cc3f0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAResponseBuilderTest.java
@@ -0,0 +1,567 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.Facets;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAResponseBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmTestModelView;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class ODataJPAResponseBuilderTest extends JPAEdmTestModelView {
+
+ /*
+ * This Unit is supposed to test the building of Entity Provider Properties for query with $expand
+ */
+ @Test
+ public void testGetEntityProviderPropertiesQuery() {
+ GetEntitySetUriInfo getEntitySetUriInfo = mockEntitySetUriInfoForExpand();
+ ODataJPAContext oDataJPAContext = getODataJPAContext();
+ // Building the edm entity
+ List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
+ Map<String, Object> edmEntity = new HashMap<String, Object>();
+ edmEntity.put("ID", 1);
+ edmEntityList.add(edmEntity);
+ // Invoking the private static method using reflection
+ Class<?> clazz = ODataJPAResponseBuilder.class;
+ Object[] actualParameters = { oDataJPAContext, getEntitySetUriInfo, edmEntityList };
+ Class<?>[] formalParameters = { ODataJPAContext.class, GetEntitySetUriInfo.class, List.class };
+ EntityProviderWriteProperties providerProperties = null;
+ try {
+ ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
+ Method method = clazz.getDeclaredMethod("getEntityProviderProperties", formalParameters);
+ method.setAccessible(true);
+ providerProperties = (EntityProviderWriteProperties) method.invoke(responseBuilder, actualParameters);
+ assertEquals(1, providerProperties.getExpandSelectTree().getLinks().size());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InstantiationException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ /*
+ * This Unit is supposed to test the building of Entity Provider Properties for read with $expand
+ */
+ @Test
+ public void testGetEntityProviderPropertiesRead() {
+
+ // Getting the EntityUriInfo
+ GetEntityUriInfo getEntityUriInfo = mockEntityUriInfoForExpand();
+ ODataJPAContext oDataJPAContext = getODataJPAContext();
+ Class<?> clazz = ODataJPAResponseBuilder.class;
+ Object[] actualParameters = { oDataJPAContext, getEntityUriInfo };
+ Class<?>[] formalParameters = { ODataJPAContext.class, GetEntityUriInfo.class };
+ EntityProviderWriteProperties providerProperties = null;
+ try {
+ ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
+ Method method = clazz.getDeclaredMethod("getEntityProviderProperties", formalParameters);
+ method.setAccessible(true);
+ providerProperties = (EntityProviderWriteProperties) method.invoke(responseBuilder, actualParameters);
+ assertEquals(1, providerProperties.getExpandSelectTree().getLinks().size());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InstantiationException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testConstructListofNavProperty() {
+ List<ArrayList<NavigationPropertySegment>> expand = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navPropList1 = new ArrayList<NavigationPropertySegment>();
+ navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties11"));
+ navPropList1.add(getNavigationPropertySegment("DemoNavigationProperties12"));
+ expand.add(navPropList1);
+ ArrayList<NavigationPropertySegment> navPropList2 = new ArrayList<NavigationPropertySegment>();
+ navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties21"));
+ navPropList2.add(getNavigationPropertySegment("DemoNavigationProperties22"));
+ expand.add(navPropList2);
+ Class<?> clazz = ODataJPAResponseBuilder.class;
+ Object[] actualParameters = { expand };
+ Class<?>[] formalParameters = { List.class };
+ List<EdmNavigationProperty> navigationProperties = null;
+ try {
+ ODataJPAResponseBuilder responseBuilder = (ODataJPAResponseBuilder) clazz.newInstance();
+ Method method = clazz.getDeclaredMethod("constructListofNavProperty", formalParameters);
+ method.setAccessible(true);
+ navigationProperties = (List<EdmNavigationProperty>) method.invoke(responseBuilder, actualParameters);
+ assertEquals("DemoNavigationProperties21", navigationProperties.get(1).getName());
+ assertEquals("DemoNavigationProperties11", navigationProperties.get(0).getName());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InstantiationException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testBuildListOfTGetEntitySetUriInfoStringODataJPAContext() {
+ try {
+ assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "application/xml",
+ getODataJPAContext()));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testBuildNegatives() {// Bad content type
+ try {
+ EntityType entity = new EntityType();
+ entity.setName("SalesOrderHeader");
+ try {
+ assertNotNull(ODataJPAResponseBuilder.build(getEntity(), getLocalGetURIInfo(), "xml", getODataJPAContext()));
+ } catch (ODataNotFoundException e) {
+ assertTrue(true);
+ }
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);// Nothing to do, Expected.
+ }
+ try {// Bad content type
+ assertNotNull(ODataJPAResponseBuilder.build(getJPAEntities(), getResultsView(), "xml", getODataJPAContext()));
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);// Nothing to do, Expected.
+ }
+
+ }
+
+ @Test
+ public void testBuildObjectGetEntityUriInfoStringODataJPAContext() throws ODataNotFoundException {
+ try {
+ assertNotNull(ODataJPAResponseBuilder.build(new SalesOrderHeader(2, 10), getLocalGetURIInfo(), "application/xml",
+ getODataJPAContext()));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testBuildNullSelects() {// Bad content type
+ try {
+ ODataJPAResponseBuilder.build(getJPAEntities(), getResultsViewWithNullSelects(), "xml", getODataJPAContext());
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);// Nothing to do, Expected.
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testBuildGetCount() {
+ ODataResponse objODataResponse = null;
+ try {
+ objODataResponse = ODataJPAResponseBuilder.build(1, getODataJPAContext());
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertNotNull(objODataResponse);
+ }
+
+ private ODataJPAContext getODataJPAContext() {
+ ODataJPAContext objODataJPAContext = EasyMock.createMock(ODataJPAContext.class);
+ EasyMock.expect(objODataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
+ EasyMock.replay(objODataJPAContext);
+ return objODataJPAContext;
+ }
+
+ private ODataContext getLocalODataContext() {
+ ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
+ try {
+ EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objODataContext);
+ return objODataContext;
+ }
+
+ private PathInfo getLocalPathInfo() {
+ PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
+ EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
+ EasyMock.replay(pathInfo);
+ return pathInfo;
+ }
+
+ private URI getLocalURI() {
+ URI uri = null;
+ try {
+ uri = new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/");
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return uri;
+ }
+
+ private GetEntitySetUriInfo getResultsView() {
+ GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
+ EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(getLocalInlineCount());
+ EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
+ EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(getSelectItemList());
+ EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(getExpandList());
+ EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
+ EasyMock.replay(objGetEntitySetUriInfo);
+ return objGetEntitySetUriInfo;
+ }
+
+ private List<ArrayList<NavigationPropertySegment>> getExpandList() {
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ return expandList;
+ }
+
+ private GetEntitySetUriInfo getResultsViewWithNullSelects() {
+ GetEntitySetUriInfo objGetEntitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
+ EasyMock.expect(objGetEntitySetUriInfo.getInlineCount()).andStubReturn(getLocalInlineCount());
+ EasyMock.expect(objGetEntitySetUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
+ EasyMock.expect(objGetEntitySetUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objGetEntitySetUriInfo.getExpand()).andStubReturn(null);
+ EasyMock.expect(objGetEntitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
+
+ EasyMock.replay(objGetEntitySetUriInfo);
+ return objGetEntitySetUriInfo;
+ }
+
+ private GetEntityUriInfo getLocalGetURIInfo() {
+ GetEntityUriInfo objGetEntityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
+ EasyMock.expect(objGetEntityUriInfo.getSelect()).andStubReturn(getSelectItemList());
+ EasyMock.expect(objGetEntityUriInfo.getTargetEntitySet()).andStubReturn(getLocalTargetEntitySet());
+ EasyMock.expect(objGetEntityUriInfo.getExpand()).andStubReturn(getExpandList());
+ EasyMock.replay(objGetEntityUriInfo);
+ return objGetEntityUriInfo;
+ }
+
+ private List<SelectItem> getSelectItemList() {
+ List<SelectItem> selectItems = new ArrayList<SelectItem>();
+ selectItems.add(getSelectItem());
+ return selectItems;
+ }
+
+ private SelectItem getSelectItem() {
+ SelectItem selectItem = EasyMock.createMock(SelectItem.class);
+ EasyMock.expect(selectItem.getProperty()).andStubReturn(getEdmPropertyForSelect());
+ List<NavigationPropertySegment> navigationSegmentList = new ArrayList<NavigationPropertySegment>();
+ EasyMock.expect(selectItem.getNavigationPropertySegments()).andStubReturn(navigationSegmentList);
+ EasyMock.replay(selectItem);
+ return selectItem;
+ }
+
+ private EdmProperty getEdmPropertyForSelect() {
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ Facets facets = new Facets().setNullable(false);
+ try {
+ EasyMock.expect(edmType.valueToString(new Integer(2), EdmLiteralKind.URI, facets)).andStubReturn("2");
+ EasyMock.expect(edmType.valueToString(new Integer(2), EdmLiteralKind.DEFAULT, facets)).andStubReturn("2");
+ } catch (EdmSimpleTypeException e1) {
+ fail("There is an exception in mocking EdmType object " + e1.getMessage());
+ }
+ EasyMock.replay(edmType);
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
+ EasyMock.expect(edmMapping.getMimeType()).andReturn(null);
+ EasyMock.replay(edmMapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmProperty.getFacets()).andStubReturn(facets);
+ EasyMock.expect(edmProperty.getCustomizableFeedMappings()).andStubReturn(null);
+ EasyMock.expect(edmProperty.getMimeType()).andStubReturn(null);
+ EasyMock.replay(edmProperty);
+
+ } catch (EdmException e) {
+ fail("There is an exception in mocking some object " + e.getMessage());
+ }
+
+ return edmProperty;
+
+ }
+
+ private EdmEntitySet getLocalTargetEntitySet() {
+ EdmEntitySet objEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(objEdmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
+ EasyMock.expect(objEdmEntitySet.getName()).andStubReturn("SalesOderHeaders");
+ EasyMock.expect(objEdmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(objEdmEntitySet);
+ return objEdmEntitySet;
+ }
+
+ private EdmEntityContainer getLocalEdmEntityContainer() {
+ EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
+ EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
+ try {
+ EasyMock.expect(edmEntityContainer.getName()).andStubReturn("salesorderprocessingContainer");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmEntityContainer);
+ return edmEntityContainer;
+ }
+
+ private EdmEntityType getLocalEdmEntityType() {
+ EdmEntityType objEdmEntityType = EasyMock.createMock(EdmEntityType.class);
+ try {
+ EasyMock.expect(objEdmEntityType.getName()).andStubReturn("SalesOderHeaders");
+ EasyMock.expect(objEdmEntityType.getNamespace()).andStubReturn("SalesOderHeaders");
+ EasyMock.expect(objEdmEntityType.hasStream()).andStubReturn(false);
+ EasyMock.expect(objEdmEntityType.hasStream()).andStubReturn(false);
+ ArrayList<String> propertyNames = new ArrayList<String>();
+ propertyNames.add("ID");
+ EasyMock.expect(objEdmEntityType.getProperty("ID")).andStubReturn(getEdmPropertyForSelect());
+ EasyMock.expect(objEdmEntityType.getPropertyNames()).andStubReturn(propertyNames);
+ EasyMock.expect(objEdmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(objEdmEntityType.getKeyPropertyNames()).andStubReturn(propertyNames);
+ EasyMock.expect(objEdmEntityType.getKeyProperties()).andStubReturn(getKeyProperties());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objEdmEntityType);
+ return objEdmEntityType;
+ }
+
+ private List<EdmProperty> getKeyProperties() {
+ List<EdmProperty> edmProperties = new ArrayList<EdmProperty>();
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType);
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soId");
+ EasyMock.replay(edmMapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("ID");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.replay(edmProperty);
+ } catch (EdmException e) {
+ fail("There is an exception is mocking some object " + e.getMessage());
+ }
+
+ edmProperties.add(edmProperty);
+ return edmProperties;
+ }
+
+ private InlineCount getLocalInlineCount() {
+ return InlineCount.NONE;
+ }
+
+ class SalesOrderHeader {
+ private int soId;
+ private int Field1;
+
+ public SalesOrderHeader(final int soId, final int field) {
+ this.soId = soId;
+ Field1 = field;
+ }
+
+ public int getField1() {
+ return Field1;
+ }
+
+ public void setField1(final int field1) {
+ Field1 = field1;
+ }
+
+ public int getSoId() {
+ return soId;
+ }
+
+ public void setSoId(final int soId) {
+ this.soId = soId;
+ }
+
+ }
+
+ private List<Object> getJPAEntities() {
+ List<Object> listJPAEntities = new ArrayList<Object>();
+ SalesOrderHeader entity;
+ entity = new SalesOrderHeader(2, 10);
+ listJPAEntities.add(entity);
+ return listJPAEntities;
+ }
+
+ private Object getEntity() {
+ SalesOrderHeader sHeader = new SalesOrderHeader(10, 34);
+ return sHeader;
+ }
+
+ private GetEntityUriInfo mockEntityUriInfoForExpand() {
+
+ List<SelectItem> selectItemList = new ArrayList<SelectItem>();
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
+ // Mocking the navigation property
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ try {
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderItemDetails");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ // Mocking the navigation property segments and adding to expand list
+ NavigationPropertySegment navigationPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navigationPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
+ EasyMock.expect(navigationPropertySegment.getTargetEntitySet()).andStubReturn(getTargetEntitySetForExpand());
+ EasyMock.replay(navigationPropertySegment);
+ navigationPropertyList.add(navigationPropertySegment);
+ expandList.add(navigationPropertyList);
+ // Mocking EntityUriInfo
+ GetEntityUriInfo entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
+ EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(selectItemList);
+ EasyMock.expect(entityUriInfo.getExpand()).andStubReturn(expandList);
+ EasyMock.replay(entityUriInfo);
+ return entityUriInfo;
+ }
+
+ private GetEntitySetUriInfo mockEntitySetUriInfoForExpand() {
+
+ List<SelectItem> selectItemList = new ArrayList<SelectItem>();
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> navigationPropertyList = new ArrayList<NavigationPropertySegment>();
+ // Mocking the navigation property
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ try {
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderItemDetails");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ // Mocking the navigation property segments and adding to expand list
+ NavigationPropertySegment navigationPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navigationPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
+ EasyMock.expect(navigationPropertySegment.getTargetEntitySet()).andStubReturn(getTargetEntitySetForExpand());
+ EasyMock.replay(navigationPropertySegment);
+ navigationPropertyList.add(navigationPropertySegment);
+ expandList.add(navigationPropertyList);
+ // Mocking EntityUriInfo
+ GetEntitySetUriInfo entitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
+ EasyMock.expect(entitySetUriInfo.getSelect()).andStubReturn(selectItemList);
+ EasyMock.expect(entitySetUriInfo.getExpand()).andStubReturn(expandList);
+ EasyMock.expect(entitySetUriInfo.getInlineCount()).andStubReturn(InlineCount.ALLPAGES);
+ EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(new Integer(1));
+ EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(new Integer(2));
+ EasyMock.replay(entitySetUriInfo);
+ return entitySetUriInfo;
+ }
+
+ private EdmEntitySet getTargetEntitySetForExpand() {
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(entitySet.getName()).andStubReturn("SalesOrderHeaders");
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(null);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entitySet);
+ return entitySet;
+ }
+
+ private NavigationPropertySegment getNavigationPropertySegment(final String navPropertyName) {
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ try {
+ EasyMock.expect(navigationProperty.getName()).andStubReturn(navPropertyName);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ NavigationPropertySegment navPropertySegment = EasyMock.createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navPropertySegment.getNavigationProperty()).andStubReturn(navigationProperty);
+ EasyMock.replay(navPropertySegment);
+ return navPropertySegment;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
new file mode 100644
index 0000000..213b51b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTest.java
@@ -0,0 +1,600 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class JPAEntityParserTest {
+ /*
+ * TestCase - JPAResultParser is a singleton class Check if the same
+ * instance is returned when create method is called
+ */
+ @Test
+ public void testCreate() {
+ JPAEntityParser resultParser1 = new JPAEntityParser();
+ JPAEntityParser resultParser2 = new JPAEntityParser();
+
+ if (resultParser1.equals(resultParser2)) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testparse2EdmPropertyValueMap() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ Object jpaEntity = new demoItem("abc", 10);
+ EdmStructuralType structuralType = EasyMock.createMock(EdmStructuralType.class);
+ EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType01 = EasyMock.createMock(EdmType.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EdmMapping edmMapping01 = EasyMock.createMock(EdmMapping.class);
+
+ try {
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmTyped.getName()).andStubReturn("identifier");
+ EasyMock.replay(edmType);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id");
+ EasyMock.replay(edmMapping);
+ EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
+ EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+ EasyMock.replay(edmTyped);
+ EasyMock.expect(structuralType.getProperty("identifier")).andStubReturn(edmTyped);
+
+ EasyMock.expect(edmType01.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmTyped01.getName()).andStubReturn("Value");
+ EasyMock.replay(edmType01);
+ EasyMock.expect(edmMapping01.getInternalName()).andStubReturn("value");
+ EasyMock.replay(edmMapping01);
+ EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
+ EasyMock.expect(edmTyped01.getMapping()).andStubReturn(edmMapping01);
+ EasyMock.replay(edmTyped01);
+ EasyMock.expect(structuralType.getProperty("value")).andStubReturn(edmTyped01);
+
+ List<String> propNames = new ArrayList<String>();
+ propNames.add("identifier");
+ propNames.add("value");
+ EasyMock.expect(structuralType.getPropertyNames()).andReturn(propNames);
+ EasyMock.replay(structuralType);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ try {
+ Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, structuralType);
+ assertEquals(2, result.size());
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testparse2EdmPropertyValueMapEdmExcep() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ Object jpaEntity = new demoItem("abc", 10);
+ EdmStructuralType structuralType = EasyMock
+ .createMock(EdmStructuralType.class);
+ EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EdmProperty edmTyped01 = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType01 = EasyMock.createMock(EdmType.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EdmMapping edmMapping01 = EasyMock.createMock(EdmMapping.class);
+
+ try {
+ EasyMock.expect(edmType.getKind())
+ .andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmType.getName()).andReturn("identifier");
+ EasyMock.replay(edmType);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("id");
+ EasyMock.replay(edmMapping);
+ EasyMock.expect(edmTyped.getType()).andStubThrow(
+ new EdmException(null));
+ EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmTyped.getName()).andReturn("identifier");
+ EasyMock.replay(edmTyped);
+ EasyMock.expect(structuralType.getProperty("identifier"))
+ .andStubReturn(edmTyped);
+
+ EasyMock.expect(edmType01.getKind()).andStubReturn(
+ EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmType01.getName()).andStubReturn("value");
+ EasyMock.replay(edmType01);
+ EasyMock.expect(edmMapping01.getInternalName()).andStubReturn(
+ "value");
+ EasyMock.replay(edmMapping01);
+ EasyMock.expect(edmTyped01.getName()).andReturn("value");
+ EasyMock.expect(edmTyped01.getType()).andStubReturn(edmType01);
+ EasyMock.expect(edmTyped01.getMapping())
+ .andStubReturn(edmMapping01);
+ EasyMock.replay(edmTyped01);
+ EasyMock.expect(structuralType.getProperty("value")).andStubReturn(
+ edmTyped01);
+
+ List<String> propNames = new ArrayList<String>();
+ propNames.add("identifier");
+ propNames.add("value");
+ EasyMock.expect(structuralType.getPropertyNames()).andReturn(
+ propNames);
+ EasyMock.replay(structuralType);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2); // assertTrue(false);
+ }
+
+ try {
+ resultParser.parse2EdmPropertyValueMap(jpaEntity, structuralType);
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testparse2EdmPropertyListMap() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ Map<String, Object> edmEntity = new HashMap<String, Object>();
+ edmEntity.put("SoId", 1);
+ DemoRelatedEntity relatedEntity = new DemoRelatedEntity("NewOrder");
+ demoItem jpaEntity = new demoItem("laptop", 1);
+ jpaEntity.setRelatedEntity(relatedEntity);
+ List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
+ // Mocking a navigation property and its mapping object
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ try {
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("relatedEntity");
+ EasyMock.replay(edmMapping);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("RelatedEntities");
+ EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.replay(navigationProperty);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ navigationPropertyList.add(navigationProperty);
+ try {
+ HashMap<String, Object> result = resultParser.parse2EdmNavigationValueMap(jpaEntity, navigationPropertyList);
+ assertEquals(relatedEntity, result.get("RelatedEntities"));
+
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testparse2EdmPropertyValueMapFromList() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ demoItem jpaEntity = new demoItem("laptop", 1);
+ DemoRelatedEntity relatedEntity = new DemoRelatedEntity("DemoOrder");
+ jpaEntity.setRelatedEntity(relatedEntity);
+ List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
+ // Mocking EdmProperties
+ EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
+ EdmProperty edmProperty2 = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType1 = EasyMock.createMock(EdmType.class);
+ EdmType edmType2 = EasyMock.createMock(EdmType.class);
+ EdmMapping mapping1 = EasyMock.createMock(EdmMapping.class);
+ EdmMapping mapping2 = EasyMock.createMock(EdmMapping.class);
+ try {
+ EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType1);
+ EasyMock.expect(mapping1.getInternalName()).andStubReturn("id");
+ EasyMock.replay(mapping1);
+ EasyMock.expect(edmProperty1.getName()).andStubReturn("Id");
+ EasyMock.expect(edmProperty1.getMapping()).andStubReturn(mapping1);
+ EasyMock.expect(edmProperty1.getType()).andStubReturn(edmType1);
+ EasyMock.replay(edmProperty1);
+ EasyMock.expect(edmType2.getKind()).andStubReturn(EdmTypeKind.COMPLEX);
+ EasyMock.replay(edmType2);
+ EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity.order");
+ EasyMock.replay(mapping2);
+ EasyMock.expect(edmProperty2.getName()).andStubReturn("Order");
+ EasyMock.expect(edmProperty2.getMapping()).andStubReturn(mapping2);
+ EasyMock.expect(edmProperty2.getType()).andStubReturn(edmType2);
+ EasyMock.replay(edmProperty2);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ selectPropertyList.add(edmProperty1);
+ selectPropertyList.add(edmProperty2);
+ try {
+ Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, selectPropertyList);
+ assertEquals("DemoOrder", result.get("Order"));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ // This unit tests when there is a complex type in the select list
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testparse2EdmPropertyValueMapFromListComplex() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ demoItem jpaEntity = new demoItem("laptop", 1);
+ DemoRelatedEntity relatedEntity = new DemoRelatedEntity("DemoOrder");
+ jpaEntity.setRelatedEntity(relatedEntity);
+ List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
+ // Mocking EdmProperties
+ EdmProperty edmProperty1 = EasyMock.createMock(EdmProperty.class);
+ EdmProperty edmProperty2 = EasyMock.createMock(EdmProperty.class);
+ EdmProperty edmComplexProperty = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType1 = EasyMock.createMock(EdmType.class);
+ EdmStructuralType edmType2 = EasyMock.createMock(EdmStructuralType.class);
+ EdmType edmComplexType = EasyMock.createMock(EdmType.class);
+ EdmMapping mapping1 = EasyMock.createMock(EdmMapping.class);
+ EdmMapping mapping2 = EasyMock.createMock(EdmMapping.class);
+ EdmMapping complexMapping = EasyMock.createMock(EdmMapping.class);
+ try {
+ EasyMock.expect(edmType1.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType1);
+ EasyMock.expect(mapping1.getInternalName()).andStubReturn("id");
+ EasyMock.replay(mapping1);
+ EasyMock.expect(edmProperty1.getName()).andStubReturn("Id");
+ EasyMock.expect(edmProperty1.getMapping()).andStubReturn(mapping1);
+ EasyMock.expect(edmProperty1.getType()).andStubReturn(edmType1);
+ EasyMock.replay(edmProperty1);
+ // Mocking the complex properties
+ EasyMock.expect(edmComplexType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmComplexType);
+ EasyMock.expect(complexMapping.getInternalName()).andStubReturn("order");
+ EasyMock.replay(complexMapping);
+ EasyMock.expect(edmComplexProperty.getName()).andStubReturn("OrderName");
+ EasyMock.expect(edmComplexProperty.getMapping()).andStubReturn(complexMapping);
+ EasyMock.expect(edmComplexProperty.getType()).andStubReturn(edmComplexType);
+ EasyMock.replay(edmComplexProperty);
+ EasyMock.expect(edmType2.getKind()).andStubReturn(EdmTypeKind.COMPLEX);
+ EasyMock.expect(edmType2.getProperty("OrderName")).andStubReturn(edmComplexProperty);
+ List<String> propertyNames = new ArrayList<String>();
+ propertyNames.add("OrderName");
+ EasyMock.expect(edmType2.getPropertyNames()).andStubReturn(propertyNames);
+ EasyMock.replay(edmType2);
+ EasyMock.expect(mapping2.getInternalName()).andStubReturn("relatedEntity");
+ EasyMock.replay(mapping2);
+ EasyMock.expect(edmProperty2.getName()).andStubReturn("Order");
+ EasyMock.expect(edmProperty2.getMapping()).andStubReturn(mapping2);
+ EasyMock.expect(edmProperty2.getType()).andStubReturn(edmType2);
+ EasyMock.replay(edmProperty2);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ selectPropertyList.add(edmProperty1);
+ selectPropertyList.add(edmProperty2);
+ try {
+ Map<String, Object> result = resultParser.parse2EdmPropertyValueMap(jpaEntity, selectPropertyList);
+ assertEquals(1, ((HashMap<String, Object>) result.get("Order")).size());
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ /*
+ * TestCase - getGetterName is a private method in JPAResultParser. The
+ * method is uses reflection to derive the property access methods from
+ * EdmProperty
+ */
+ @Test
+ public void testGetGettersWithOutMapping() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ try {
+
+ /*
+ * Case 1 - Property having No mapping
+ */
+ Class<?>[] pars = { String.class, EdmMapping.class, String.class };
+ Object[] params = { "Field1", null, "get" };
+ Method getGetterName = resultParser.getClass().getDeclaredMethod("getAccessModifierName", pars);
+ getGetterName.setAccessible(true);
+ String name = (String) getGetterName.invoke(resultParser, params);
+
+ assertEquals("getField1", name);
+
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+
+ }
+ }
+
+ @Test
+ public void testGetGettersWithNullPropname() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ try {
+
+ /*
+ * Case 1 - Property having No mapping and no name
+ */
+ Class<?>[] pars = { String.class, EdmMapping.class, String.class };
+ Object[] params = { null, null, null };
+ Method getGetterName = resultParser.getClass().getDeclaredMethod("getAccessModifierName", pars);
+ getGetterName.setAccessible(true);
+
+ String name = (String) getGetterName.invoke(resultParser, params);
+ assertNull(name);
+
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+
+ }
+ }
+
+ /*
+ * TestCase - getGetterName is a private method in JPAResultParser. The
+ * method is uses reflection to derive the property access methods from
+ * EdmProperty
+ *
+ * EdmProperty name could have been modified. Then mapping object of
+ * EdmProperty should be used for deriving the name
+ */
+ @Test
+ public void testGetGettersWithMapping() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("field1");
+ EasyMock.replay(edmMapping);
+ try {
+
+ Class<?>[] pars = { String.class, EdmMapping.class, String.class };
+ Object[] params = { "myField", edmMapping, "get" };
+ Method getGetterName = resultParser.getClass().getDeclaredMethod("getAccessModifierName", pars);
+ getGetterName.setAccessible(true);
+
+ String name = (String) getGetterName.invoke(resultParser, params);
+ assertEquals("getField1", name);
+
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+
+ }
+ }
+
+ @Test
+ public void testGetGettersNoSuchMethodException() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ try {
+
+ Method getGetterName = resultParser.getClass().getDeclaredMethod("getGetterName1", EdmProperty.class);
+ getGetterName.setAccessible(true);
+
+ } catch (NoSuchMethodException e) {
+ assertEquals(
+ "org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser.getGetterName1" +
+ "(org.apache.olingo.odata2.api.edm.EdmProperty)",
+ e.getMessage());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+
+ }
+ }
+
+ @Test
+ public void testParse2EdmPropertyValueMap() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ Object jpaEntity = new DemoItem2("abc");
+ try {
+ resultParser.parse2EdmPropertyValueMap(jpaEntity, getEdmPropertyList());
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetGetterEdmException() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ Object jpaEntity = new demoItem("abc", 10);
+ EdmStructuralType structuralType = EasyMock.createMock(EdmStructuralType.class);
+ try {
+ EasyMock.expect(structuralType.getPropertyNames()).andStubThrow(new EdmException(null));
+ EasyMock.replay(structuralType);
+ Method getGetters =
+ resultParser.getClass().getDeclaredMethod("getGetters", Object.class, EdmStructuralType.class);
+ getGetters.setAccessible(true);
+ try {
+ getGetters.invoke(resultParser, jpaEntity, structuralType);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ assertTrue(true);
+ }
+ } catch (NoSuchMethodException e) {
+ assertEquals(
+ "org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser.getGetters(java.lang.Object, " +
+ "org.apache.olingo.odata2.api.edm.EdmStructuralType)",
+ e.getMessage());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testForNullJPAEntity() {
+ JPAEntityParser resultParser = new JPAEntityParser();
+ EdmStructuralType structuralType = EasyMock.createMock(EdmStructuralType.class);
+ Object map;
+ try {
+ map = resultParser.parse2EdmPropertyValueMap(null, structuralType);
+ assertNull(map);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ class demoItem {
+ private String id;
+ private int value;
+ private DemoRelatedEntity relatedEntity;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(final String id) {
+ this.id = id;
+ }
+
+ public DemoRelatedEntity getRelatedEntity() {
+ return relatedEntity;
+ }
+
+ public void setRelatedEntity(final DemoRelatedEntity relatedEntity) {
+ this.relatedEntity = relatedEntity;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(final int value) {
+ this.value = value;
+ }
+
+ demoItem(final String id, final int value) {
+ this.id = id;
+ this.value = value;
+ }
+
+ }
+
+ class DemoRelatedEntity {
+ String order;
+
+ public String getOrder() {
+ return order;
+ }
+
+ public void setOrder(final String order) {
+ this.order = order;
+ }
+
+ public DemoRelatedEntity(final String order) {
+ super();
+ this.order = order;
+ }
+
+ }
+
+ private List<EdmProperty> getEdmPropertyList() {
+ List<EdmProperty> properties = new ArrayList<EdmProperty>();
+ properties.add(getEdmProperty());
+ return properties;
+ }
+
+ class DemoItem2 {
+ private String field1;
+
+ public String getField1() {
+ return field1;
+ }
+
+ public void setField1(final String field) {
+ field1 = field;
+ }
+
+ public DemoItem2(final String field) {
+ field1 = field;
+ }
+
+ }
+
+ private EdmProperty getEdmProperty() {
+ EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
+
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
+ EasyMock.replay(edmMapping);
+
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+
+ try {
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmType.getName()).andStubReturn("identifier");
+ EasyMock.expect(edmTyped.getName()).andStubReturn("SalesOrderHeader");
+ EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+
+ EasyMock.expect(edmTyped.getType()).andStubReturn(edmType);
+ EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmType);
+ EasyMock.replay(edmTyped);
+ return edmTyped;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
new file mode 100644
index 0000000..d87d2c1
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityParserTestForStaticMethods.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Method;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntityParser;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.junit.Test;
+
+public class JPAEntityParserTestForStaticMethods {
+
+ @Test
+ public void testToStringDefault() {
+
+ Character[] input = new Character[] { 'A', 'B' };
+ assertEquals("AB", JPAEntityParser.toString(input));
+
+ }
+
+ @Test
+ public void testToStringNull() {
+ Character[] input = null;
+ assertNull(JPAEntityParser.toString(input));
+ }
+
+ @Test
+ public void testToStringPartialNull() {
+ Character[] input = new Character[] { 'A', null };
+ assertEquals("A", JPAEntityParser.toString(input));
+ }
+
+ @Test
+ public void testToCharacterArrayDefault() {
+ String input = new String("AB");
+ Character[] ch = JPAEntityParser.toCharacterArray(input);
+
+ assertEquals(2, ch.length);
+ assertTrue(ch[0].equals('A'));
+ assertTrue(ch[1].equals('B'));
+ }
+
+ @Test
+ public void testToCharacterArrayNull() {
+ String input = null;
+ Character[] ch = JPAEntityParser.toCharacterArray(input);
+
+ assertNull(ch);
+ }
+
+ @Test
+ public void testGetPropertyCharacter() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacter", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertEquals("A", output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharacterNull() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterNull", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertNull(output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharacterArray() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterArray", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertEquals("AB", output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharacterArrayNull() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharacterArrayNull", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertNull(output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyChar() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getChar", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertEquals("A", output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharNull() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharNull", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertNull(output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharArray() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArray", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertEquals("AB", output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharArrayNull() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArrayNull", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertNull(output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetPropertyCharArrayValueNull() {
+ try {
+ Method method = JPAEntityParserTestForStaticMethods.class.getMethod("getCharArrayValueNull", (Class<?>[]) null);
+ String output = (String) JPAEntityParser.getProperty(method, this);
+ assertEquals("A\u0000", output);
+
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ public Character getCharacter() {
+ return new Character('A');
+ }
+
+ public Character getCharacterNull() {
+ return null;
+ }
+
+ public Character[] getCharacterArray() {
+ return new Character[] { 'A', 'B' };
+ }
+
+ public Character[] getCharacterArrayNull() {
+ return null;
+ }
+
+ public char getChar() {
+ return 'A';
+ }
+
+ public char getCharNull() {
+ return '\u0000';
+ }
+
+ public char[] getCharArray() {
+ return new char[] { 'A', 'B' };
+ }
+
+ public char[] getCharArrayNull() {
+ return null;
+ }
+
+ public char[] getCharArrayValueNull() {
+ return new char[] { 'A', '\u0000' };
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
new file mode 100644
index 0000000..a93c4e0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAEntityTest.java
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAEntity;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.EdmMockUtilV2;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.ODataEntryMockUtil;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2;
+import org.junit.Test;
+
+public class JPAEntityTest {
+
+ private JPAEntity jpaEntity = null;
+
+ @Test
+ public void testCreateODataEntryWithComplexType() {
+ try {
+ EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, true);
+ EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+
+ jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
+ jpaEntity.create(ODataEntryMockUtil.mockODataEntryWithComplexType(JPATypeMock.ENTITY_NAME));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
+ assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
+ assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+ assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
+ JPATypeEmbeddableMock jpaEmbeddableMock = jpaTypeMock.getComplexType();
+ assertNotNull(jpaEmbeddableMock);
+
+ assertEquals(jpaEmbeddableMock.getMShort(), ODataEntryMockUtil.VALUE_SHORT);
+ JPATypeEmbeddableMock2 jpaEmbeddableMock2 = jpaEmbeddableMock.getMEmbeddable();
+ assertNotNull(jpaEmbeddableMock2);
+ assertEquals(jpaEmbeddableMock2.getMFloat(), ODataEntryMockUtil.VALUE_MFLOAT, 1);
+ assertEquals(jpaEmbeddableMock2.getMUUID(), ODataEntryMockUtil.VALUE_UUID);
+ }
+
+ @Test
+ public void testCreateODataEntry() {
+ try {
+ EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
+ EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+
+ jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
+ jpaEntity.create(ODataEntryMockUtil.mockODataEntry(JPATypeMock.ENTITY_NAME));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
+ assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
+ assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+ assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
+ }
+
+ @Test
+ public void testCreateODataEntryWithInline() {
+ try {
+ EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
+ EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+
+ jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
+ jpaEntity.create(ODataEntryMockUtil.mockODataEntryWithInline(JPATypeMock.ENTITY_NAME));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
+ assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
+ assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+ assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
+
+ JPARelatedTypeMock relatedType = jpaTypeMock.getMRelatedEntity();
+ assertNotNull(jpaTypeMock.getMRelatedEntity());
+ assertEquals(relatedType.getMByte(), ODataEntryMockUtil.VALUE_MBYTE);
+ assertEquals(relatedType.getMByteArray(), ODataEntryMockUtil.VALUE_MBYTEARRAY);
+ assertEquals(relatedType.getMDouble(), ODataEntryMockUtil.VALUE_MDOUBLE, 0.0);
+ assertEquals(relatedType.getMLong(), ODataEntryMockUtil.VALUE_MLONG);
+ }
+
+ @Test
+ public void testCreateODataEntryProperty() {
+ try {
+ EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
+ EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+
+ jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
+ jpaEntity.create(ODataEntryMockUtil.mockODataEntryProperties(JPATypeMock.ENTITY_NAME));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
+ assertEquals(jpaTypeMock.getMInt(), ODataEntryMockUtil.VALUE_MINT);
+ assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+ assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
+ }
+
+ @Test
+ public void testUpdateODataEntry() {
+ try {
+ EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
+ EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+
+ jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
+ JPATypeMock jpaTypeMock = new JPATypeMock();
+ jpaEntity.setJPAEntity(jpaTypeMock);
+ jpaEntity.update(ODataEntryMockUtil.mockODataEntry(JPATypeMock.ENTITY_NAME));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
+ assertEquals(jpaTypeMock.getMInt(), 0);// Key should not be changed
+ assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+ assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
+ }
+
+ @Test
+ public void testUpdateODataEntryProperty() {
+ try {
+ EdmEntitySet edmEntitySet = EdmMockUtilV2.mockEdmEntitySet(JPATypeMock.ENTITY_NAME, false);
+ EdmEntityType edmEntityType = edmEntitySet.getEntityType();
+
+ jpaEntity = new JPAEntity(edmEntityType, edmEntitySet);
+ JPATypeMock jpaTypeMock = new JPATypeMock();
+ jpaEntity.setJPAEntity(jpaTypeMock);
+ jpaEntity.update(ODataEntryMockUtil.mockODataEntryProperties(JPATypeMock.ENTITY_NAME));
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage()
+ + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ JPATypeMock jpaTypeMock = (JPATypeMock) jpaEntity.getJPAEntity();
+ assertEquals(jpaTypeMock.getMInt(), 0);// Key should not be changed
+ assertEquals(jpaTypeMock.getMString(), ODataEntryMockUtil.VALUE_MSTRING);
+ assertTrue(jpaTypeMock.getMDateTime().equals(ODataEntryMockUtil.VALUE_DATE_TIME));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBackTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBackTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBackTest.java
new file mode 100644
index 0000000..d6f9153
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/access/data/JPAExpandCallBackTest.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.access.data;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAExpandCallBack;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.EdmMockUtil;
+import org.junit.Test;
+
+public class JPAExpandCallBackTest {
+
+ @Test
+ public void testRetrieveEntryResult() {
+ JPAExpandCallBack callBack = getJPAExpandCallBackObject();
+ WriteEntryCallbackContext writeFeedContext = EdmMockUtil.getWriteEntryCallBackContext();
+ try {
+ Field field = callBack.getClass().getDeclaredField("nextEntitySet");
+ field.setAccessible(true);
+ field.set(callBack, EdmMockUtil.mockTargetEntitySet());
+ WriteEntryCallbackResult result = callBack.retrieveEntryResult(writeFeedContext);
+ assertEquals(1, result.getEntryData().size());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testRetrieveFeedResult() {
+ JPAExpandCallBack callBack = getJPAExpandCallBackObject();
+ WriteFeedCallbackContext writeFeedContext = EdmMockUtil.getWriteFeedCallBackContext();
+ try {
+ Field field = callBack.getClass().getDeclaredField("nextEntitySet");
+ field.setAccessible(true);
+ field.set(callBack, EdmMockUtil.mockTargetEntitySet());
+ WriteFeedCallbackResult result = callBack.retrieveFeedResult(writeFeedContext);
+ assertEquals(2, result.getFeedData().size());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetCallbacks() {
+ Map<String, ODataCallback> callBacks = null;
+ try {
+ URI baseUri =
+ new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/");
+ ExpandSelectTreeNode expandSelectTreeNode = EdmMockUtil.mockExpandSelectTreeNode();
+ List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList();
+ callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(1, callBacks.size());
+
+ }
+
+ @Test
+ public void testGetNextNavigationProperty() {
+ JPAExpandCallBack callBack = getJPAExpandCallBackObject();
+ List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList();
+ ArrayList<NavigationPropertySegment> expands = expandList.get(0);
+ expands.add(EdmMockUtil.mockThirdNavigationPropertySegment());
+ EdmNavigationProperty result = null;
+ try {
+ Field field = callBack.getClass().getDeclaredField("expandList");
+ field.setAccessible(true);
+ field.set(callBack, expandList);
+ Class<?>[] formalParams = { EdmEntityType.class, EdmNavigationProperty.class };
+ Object[] actualParams = { EdmMockUtil.mockSourceEdmEntityType(), EdmMockUtil.mockNavigationProperty() };
+ Method method = callBack.getClass().getDeclaredMethod("getNextNavigationProperty", formalParams);
+ method.setAccessible(true);
+ result = (EdmNavigationProperty) method.invoke(callBack, actualParams);
+ assertEquals("MaterialDetails", result.getName());
+
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchMethodException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (InvocationTargetException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ private JPAExpandCallBack getJPAExpandCallBackObject() {
+ Map<String, ODataCallback> callBacks = null;
+ try {
+ URI baseUri =
+ new URI("http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/");
+ ExpandSelectTreeNode expandSelectTreeNode = EdmMockUtil.mockExpandSelectTreeNode();
+ List<ArrayList<NavigationPropertySegment>> expandList = EdmMockUtil.getExpandList();
+ callBacks = JPAExpandCallBack.getCallbacks(baseUri, expandSelectTreeNode, expandList);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return (JPAExpandCallBack) callBacks.get("SalesOrderLineItemDetails");
+ }
+
+}
[30/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataEntityParser.java
deleted file mode 100644
index ee54290..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataEntityParser.java
+++ /dev/null
@@ -1,163 +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.odata2.processor.core.jpa;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.uri.PathSegment;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.UriParser;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-
-public final class ODataEntityParser {
-
- private ODataJPAContext context;
-
- public ODataEntityParser(final ODataJPAContext context) {
- this.context = context;
- }
-
- public final ODataEntry parseEntry(final EdmEntitySet entitySet,
- final InputStream content, final String requestContentType, final boolean merge)
- throws ODataBadRequestException {
- ODataEntry entryValues;
- try {
- EntityProviderReadProperties entityProviderProperties =
- EntityProviderReadProperties.init().mergeSemantic(merge).build();
- entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, entityProviderProperties);
- } catch (EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
- return entryValues;
-
- }
-
- public final UriInfo parseLinkURI() throws ODataJPARuntimeException {
- UriInfo uriInfo = null;
-
- Edm edm;
- try {
- edm = context.getODataContext().getService().getEntityDataModel();
-
- List<PathSegment> pathSegments = context.getODataContext().getPathInfo().getODataSegments();
- List<PathSegment> subPathSegments = pathSegments.subList(0, pathSegments.size() - 2);
-
- uriInfo = UriParser.parse(edm, subPathSegments, Collections.<String, String> emptyMap());
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return uriInfo;
- }
-
- public final UriInfo parseLink(final EdmEntitySet entitySet, final InputStream content, final String contentType)
- throws ODataJPARuntimeException {
-
- String uriString = null;
- UriInfo uri = null;
-
- try {
- uriString = EntityProvider.readLink(contentType, entitySet, content);
- ODataContext odataContext = context.getODataContext();
- final String serviceRoot = odataContext.getPathInfo().getServiceRoot().toString();
-
- final String path =
- uriString.startsWith(serviceRoot.toString()) ? uriString.substring(serviceRoot.length()) : uriString;
-
- final PathSegment pathSegment = new PathSegment() {
- @Override
- public String getPath() {
- return path;
- }
-
- @Override
- public Map<String, List<String>> getMatrixParameters() {
- return null;
- }
- };
-
- final Edm edm = odataContext.getService().getEntityDataModel();
-
- uri = UriParser.parse(edm, Arrays.asList(pathSegment), Collections.<String, String> emptyMap());
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return uri;
-
- }
-
- public List<UriInfo> parseLinks(final EdmEntitySet entitySet, final InputStream content, final String contentType)
- throws ODataJPARuntimeException {
-
- List<String> uriList = new ArrayList<String>();
- List<UriInfo> uriInfoList = new ArrayList<UriInfo>();
-
- try {
-
- uriList = EntityProvider.readLinks(contentType, entitySet, content);
- ODataContext odataContext = context.getODataContext();
- final String serviceRoot = odataContext.getPathInfo().getServiceRoot().toString();
- final int length = serviceRoot.length();
- final Edm edm = odataContext.getService().getEntityDataModel();
-
- for (String uriString : uriList) {
- final String path = uriString.startsWith(serviceRoot) ? uriString.substring(length) : uriString;
-
- final PathSegment pathSegment = new PathSegment() {
- @Override
- public String getPath() {
- return path;
- }
-
- @Override
- public Map<String, List<String>> getMatrixParameters() {
- return null;
- }
- };
-
- UriInfo uriInfo = UriParser.parse(edm, Arrays.asList(pathSegment), Collections.<String, String> emptyMap());
- uriInfoList.add(uriInfo);
- }
- } catch (EntityProviderException e) {
- return null;
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return uriInfoList;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParser.java
deleted file mode 100644
index 2993221..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataExpressionParser.java
+++ /dev/null
@@ -1,381 +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.odata2.processor.core.jpa;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
-import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
-import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
-import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
-import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
-import org.apache.olingo.odata2.api.uri.expression.MethodOperator;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
-import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
-import org.apache.olingo.odata2.api.uri.expression.SortOrder;
-import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-
-/**
- * This class contains utility methods for parsing the filter expressions built by core library from user OData Query.
- *
- *
- *
- */
-public class ODataExpressionParser {
-
- public static final String EMPTY = ""; //$NON-NLS-1$
- public static Integer methodFlag = 0;
-
- /**
- * This method returns the parsed where condition corresponding to the filter input in the user query.
- *
- * @param whereExpression
- *
- * @return Parsed where condition String
- * @throws ODataException
- */
-
- public static String parseToJPAWhereExpression(final CommonExpression whereExpression, final String tableAlias)
- throws ODataException {
- switch (whereExpression.getKind()) {
- case UNARY:
- final UnaryExpression unaryExpression = (UnaryExpression) whereExpression;
- final String operand = parseToJPAWhereExpression(unaryExpression.getOperand(), tableAlias);
-
- switch (unaryExpression.getOperator()) {
- case NOT:
- return JPQLStatement.Operator.NOT + "(" + operand + ")"; //$NON-NLS-1$ //$NON-NLS-2$
- case MINUS:
- if (operand.startsWith("-")) {
- return operand.substring(1);
- } else {
- return "-" + operand; //$NON-NLS-1$
- }
- default:
- throw new ODataNotImplementedException();
- }
-
- case FILTER:
- return parseToJPAWhereExpression(((FilterExpression) whereExpression).getExpression(), tableAlias);
- case BINARY:
- final BinaryExpression binaryExpression = (BinaryExpression) whereExpression;
- if ((binaryExpression.getLeftOperand().getKind() == ExpressionKind.METHOD)
- && ((binaryExpression.getOperator() == BinaryOperator.EQ) ||
- (binaryExpression.getOperator() == BinaryOperator.NE))
- && (((MethodExpression) binaryExpression.getLeftOperand()).getMethod() == MethodOperator.SUBSTRINGOF)) {
- methodFlag = 1;
- }
- final String left = parseToJPAWhereExpression(binaryExpression.getLeftOperand(), tableAlias);
- final String right = parseToJPAWhereExpression(binaryExpression.getRightOperand(), tableAlias);
-
- switch (binaryExpression.getOperator()) {
- case AND:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE
- + right;
- case OR:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.OR + JPQLStatement.DELIMITER.SPACE + right;
- case EQ:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + right;
- case NE:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.NE + JPQLStatement.DELIMITER.SPACE + right;
- case LT:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LT + JPQLStatement.DELIMITER.SPACE + right;
- case LE:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.LE + JPQLStatement.DELIMITER.SPACE + right;
- case GT:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GT + JPQLStatement.DELIMITER.SPACE + right;
- case GE:
- return left + JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.GE + JPQLStatement.DELIMITER.SPACE + right;
- case PROPERTY_ACCESS:
- throw new ODataNotImplementedException();
- default:
- throw new ODataNotImplementedException();
- }
-
- case PROPERTY:
- String returnStr =
- tableAlias + JPQLStatement.DELIMITER.PERIOD
- + ((EdmProperty) ((PropertyExpression) whereExpression).getEdmProperty()).getMapping().getInternalName();
- return returnStr;
-
- case MEMBER:
- String memberExpStr = EMPTY;
- int i = 0;
- MemberExpression member = null;
- CommonExpression tempExp = whereExpression;
- while (tempExp != null && tempExp.getKind() == ExpressionKind.MEMBER) {
- member = (MemberExpression) tempExp;
- if (i > 0) {
- memberExpStr = JPQLStatement.DELIMITER.PERIOD + memberExpStr;
- }
- i++;
- memberExpStr =
- ((EdmProperty) ((PropertyExpression) member.getProperty()).getEdmProperty()).getMapping().getInternalName()
- + memberExpStr;
- tempExp = member.getPath();
- }
- memberExpStr =
- ((EdmProperty) ((PropertyExpression) tempExp).getEdmProperty()).getMapping().getInternalName()
- + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
- return tableAlias + JPQLStatement.DELIMITER.PERIOD + memberExpStr;
-
- case LITERAL:
- final LiteralExpression literal = (LiteralExpression) whereExpression;
- final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
- String value =
- literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
- literalType.getDefaultType()), EdmLiteralKind.DEFAULT, null);
- return evaluateComparingExpression(value, literalType);
-
- case METHOD:
- final MethodExpression methodExpression = (MethodExpression) whereExpression;
- String first = parseToJPAWhereExpression(methodExpression.getParameters().get(0), tableAlias);
- final String second =
- methodExpression.getParameterCount() > 1 ? parseToJPAWhereExpression(methodExpression.getParameters().get(1),
- tableAlias) : null;
- String third =
- methodExpression.getParameterCount() > 2 ? parseToJPAWhereExpression(methodExpression.getParameters().get(2),
- tableAlias) : null;
-
- switch (methodExpression.getMethod()) {
- case SUBSTRING:
- third = third != null ? ", " + third : "";
- return String.format("SUBSTRING(%s, %s + 1 %s)", first, second, third);
- case SUBSTRINGOF:
- first = first.substring(1, first.length() - 1);
- if (methodFlag == 1) {
- methodFlag = 0;
- return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END)", second, first);
- } else {
- return String.format("(CASE WHEN (%s LIKE '%%%s%%') THEN TRUE ELSE FALSE END) = true", second, first);
- }
- case TOLOWER:
- return String.format("LOWER(%s)", first);
- default:
- throw new ODataNotImplementedException();
- }
-
- default:
- throw new ODataNotImplementedException();
- }
- }
-
- /**
- * This method parses the select clause
- *
- * @param tableAlias
- * @param selectedFields
- * @return a select expression
- */
- public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) {
-
- if ((selectedFields == null) || (selectedFields.size() == 0)) {
- return tableAlias;
- }
-
- String selectClause = EMPTY;
- Iterator<String> itr = selectedFields.iterator();
- int count = 0;
-
- while (itr.hasNext()) {
- selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next();
- count++;
-
- if (count < selectedFields.size()) {
- selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE;
- }
- }
- return selectClause;
- }
-
- /**
- * This method parses the order by condition in the query.
- *
- * @param orderByExpression
- * @return a map of JPA attributes and their sort order
- * @throws ODataJPARuntimeException
- */
- public static HashMap<String, String> parseToJPAOrderByExpression(final OrderByExpression orderByExpression,
- final String tableAlias) throws ODataJPARuntimeException {
- HashMap<String, String> orderByMap = new HashMap<String, String>();
- if (orderByExpression != null && orderByExpression.getOrders() != null) {
- List<OrderExpression> orderBys = orderByExpression.getOrders();
- String orderByField = null;
- String orderByDirection = null;
- for (OrderExpression orderBy : orderBys) {
-
- try {
- orderByField =
- ((EdmProperty) ((PropertyExpression) orderBy.getExpression()).getEdmProperty()).getMapping()
- .getInternalName();
- orderByDirection = (orderBy.getSortOrder() == SortOrder.asc) ? EMPTY : "DESC"; //$NON-NLS-1$
- orderByMap.put(tableAlias + JPQLStatement.DELIMITER.PERIOD + orderByField, orderByDirection);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- }
- }
- return orderByMap;
- }
-
- /**
- * This method evaluated the where expression for read of an entity based on the keys specified in the query.
- *
- * @param keyPredicates
- * @return the evaluated where expression
- */
-
- public static String parseKeyPredicates(final List<KeyPredicate> keyPredicates, final String tableAlias)
- throws ODataJPARuntimeException {
- String literal = null;
- String propertyName = null;
- EdmSimpleType edmSimpleType = null;
- StringBuilder keyFilters = new StringBuilder();
- int i = 0;
- for (KeyPredicate keyPredicate : keyPredicates) {
- if (i > 0) {
- keyFilters.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND + JPQLStatement.DELIMITER.SPACE);
- }
- i++;
- literal = keyPredicate.getLiteral();
- try {
- propertyName = keyPredicate.getProperty().getMapping().getInternalName();
- edmSimpleType = (EdmSimpleType) keyPredicate.getProperty().getType();
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- literal = evaluateComparingExpression(literal, edmSimpleType);
-
- if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
- literal = literal.substring(literal.indexOf('\''), literal.indexOf('}'));
- }
-
- keyFilters.append(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + JPQLStatement.DELIMITER.SPACE
- + JPQLStatement.Operator.EQ + JPQLStatement.DELIMITER.SPACE + literal);
- }
- if (keyFilters.length() > 0) {
- return keyFilters.toString();
- } else {
- return null;
- }
- }
-
- /**
- * This method evaluates the expression based on the type instance. Used for adding escape characters where necessary.
- *
- * @param value
- * @param edmSimpleType
- * @return the evaluated expression
- * @throws ODataJPARuntimeException
- */
- private static String evaluateComparingExpression(String value, final EdmSimpleType edmSimpleType)
- throws ODataJPARuntimeException {
-
- if (edmSimpleType == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || edmSimpleType == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()) {
- value = "\'" + value + "\'"; //$NON-NLS-1$ //$NON-NLS-2$
- } else if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
- try {
- Calendar datetime =
- (Calendar) edmSimpleType.valueOfString(value, EdmLiteralKind.DEFAULT, null, edmSimpleType.getDefaultType());
-
- String year = String.format("%04d", datetime.get(Calendar.YEAR));
- String month = String.format("%02d", datetime.get(Calendar.MONTH) + 1);
- String day = String.format("%02d", datetime.get(Calendar.DAY_OF_MONTH));
- String hour = String.format("%02d", datetime.get(Calendar.HOUR_OF_DAY));
- String min = String.format("%02d", datetime.get(Calendar.MINUTE));
- String sec = String.format("%02d", datetime.get(Calendar.SECOND));
-
- value =
- JPQLStatement.DELIMITER.LEFT_BRACE + JPQLStatement.KEYWORD.TIMESTAMP + JPQLStatement.DELIMITER.SPACE + "\'"
- + year + JPQLStatement.DELIMITER.HYPHEN + month + JPQLStatement.DELIMITER.HYPHEN + day
- + JPQLStatement.DELIMITER.SPACE + hour + JPQLStatement.DELIMITER.COLON + min
- + JPQLStatement.DELIMITER.COLON + sec + JPQLStatement.KEYWORD.OFFSET + "\'"
- + JPQLStatement.DELIMITER.RIGHT_BRACE;
-
- } catch (EdmSimpleTypeException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- } else if (edmSimpleType == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- try {
- Calendar time =
- (Calendar) edmSimpleType.valueOfString(value, EdmLiteralKind.DEFAULT, null, edmSimpleType.getDefaultType());
-
- String hourValue = String.format("%02d", time.get(Calendar.HOUR_OF_DAY));
- String minValue = String.format("%02d", time.get(Calendar.MINUTE));
- String secValue = String.format("%02d", time.get(Calendar.SECOND));
-
- value =
- "\'" + hourValue + JPQLStatement.DELIMITER.COLON + minValue + JPQLStatement.DELIMITER.COLON + secValue
- + "\'";
- } catch (EdmSimpleTypeException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- } else if (edmSimpleType == EdmSimpleTypeKind.Int64.getEdmSimpleTypeInstance()) {
- value = value + JPQLStatement.DELIMITER.LONG; //$NON-NLS-1$
- }
- return value;
- }
-
- public static HashMap<String, String> parseKeyPropertiesToJPAOrderByExpression(
- final List<EdmProperty> edmPropertylist, final String tableAlias) throws ODataJPARuntimeException {
- HashMap<String, String> orderByMap = new HashMap<String, String>();
- String propertyName = null;
- for (EdmProperty edmProperty : edmPropertylist) {
- try {
- EdmMapping mapping = edmProperty.getMapping();
- if (mapping != null && mapping.getInternalName() != null) {
- propertyName = mapping.getInternalName();// For embedded/complex keys
- } else {
- propertyName = edmProperty.getName();
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- orderByMap.put(tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName, EMPTY);
- }
- return orderByMap;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImpl.java
deleted file mode 100644
index 5529d2c..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAContextImpl.java
+++ /dev/null
@@ -1,146 +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.odata2.processor.core.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
-
-public class ODataJPAContextImpl implements ODataJPAContext {
-
- private String pUnitName;
- private EntityManagerFactory emf;
- private EntityManager em;
- private ODataContext odataContext;
- private ODataProcessor processor;
- private EdmProvider edmProvider;
- private String jpaEdmMappingModelName;
- private JPAEdmExtension jpaEdmExtension;
- private static final ThreadLocal<ODataContext> oDataContextThreadLocal = new ThreadLocal<ODataContext>();
- private boolean defaultNaming = true;
-
- @Override
- public String getPersistenceUnitName() {
- return pUnitName;
- }
-
- @Override
- public void setPersistenceUnitName(final String pUnitName) {
- this.pUnitName = pUnitName;
- }
-
- @Override
- public EntityManagerFactory getEntityManagerFactory() {
- return emf;
- }
-
- @Override
- public void setEntityManagerFactory(final EntityManagerFactory emf) {
- this.emf = emf;
- }
-
- @Override
- public void setODataContext(final ODataContext ctx) {
- odataContext = ctx;
- setContextInThreadLocal(odataContext);
- }
-
- @Override
- public ODataContext getODataContext() {
- return odataContext;
- }
-
- @Override
- public void setODataProcessor(final ODataProcessor processor) {
- this.processor = processor;
- }
-
- @Override
- public ODataProcessor getODataProcessor() {
- return processor;
- }
-
- @Override
- public void setEdmProvider(final EdmProvider edmProvider) {
- this.edmProvider = edmProvider;
- }
-
- @Override
- public EdmProvider getEdmProvider() {
- return edmProvider;
- }
-
- @Override
- public void setJPAEdmMappingModel(final String name) {
- jpaEdmMappingModelName = name;
-
- }
-
- @Override
- public String getJPAEdmMappingModel() {
- return jpaEdmMappingModelName;
- }
-
- public static void setContextInThreadLocal(final ODataContext ctx) {
- oDataContextThreadLocal.set(ctx);
- }
-
- public static void unsetContextInThreadLocal() {
- oDataContextThreadLocal.remove();
- }
-
- public static ODataContext getContextInThreadLocal() {
- return (ODataContext) oDataContextThreadLocal.get();
- }
-
- @Override
- public EntityManager getEntityManager() {
- if (em == null) {
- em = emf.createEntityManager();
- }
-
- return em;
- }
-
- @Override
- public void setJPAEdmExtension(final JPAEdmExtension jpaEdmExtension) {
- this.jpaEdmExtension = jpaEdmExtension;
-
- }
-
- @Override
- public JPAEdmExtension getJPAEdmExtension() {
- return jpaEdmExtension;
- }
-
- @Override
- public void setDefaultNaming(final boolean defaultNaming) {
- this.defaultNaming = defaultNaming;
- }
-
- @Override
- public boolean getDefaultNaming() {
- return defaultNaming;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefault.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefault.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefault.java
deleted file mode 100644
index 1d5929d..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAProcessorDefault.java
+++ /dev/null
@@ -1,194 +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.odata2.processor.core.jpa;
-
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException;
-
-public class ODataJPAProcessorDefault extends ODataJPAProcessor {
-
- public ODataJPAProcessorDefault(final ODataJPAContext oDataJPAContext) {
- super(oDataJPAContext);
- if (oDataJPAContext == null) {
- throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
- }
- }
-
- @Override
- public ODataResponse readEntitySet(final GetEntitySetUriInfo uriParserResultView, final String contentType)
- throws ODataException {
-
- List<?> jpaEntities = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntities, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse readEntity(final GetEntityUriInfo uriParserResultView, final String contentType)
- throws ODataException {
-
- Object jpaEntity = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriParserResultView, final String contentType)
- throws ODataException {
-
- long jpaEntityCount = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntityCount, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
- throws ODataException {
-
- long jpaEntityCount = jpaProcessor.process(uriInfo);
-
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntityCount, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse createEntity(final PostUriInfo uriParserResultView, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
-
- List<Object> createdJpaEntityList = jpaProcessor.process(uriParserResultView, content, requestContentType);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(createdJpaEntityList, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse updateEntity(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
- final String requestContentType, final boolean merge, final String contentType) throws ODataException {
-
- Object jpaEntity = jpaProcessor.process(uriParserResultView, content, requestContentType);
-
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse deleteEntity(final DeleteUriInfo uriParserResultView, final String contentType)
- throws ODataException {
-
- Object deletedObj = jpaProcessor.process(uriParserResultView, contentType);
-
- ODataResponse oDataResponse = ODataJPAResponseBuilder.build(deletedObj, uriParserResultView);
- return oDataResponse;
- }
-
- @Override
- public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriParserResultView,
- final String contentType) throws ODataException {
-
- List<Object> resultEntity = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(resultEntity, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriParserResultView,
- final String contentType) throws ODataException {
-
- List<Object> result = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(result, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriParserResultView, final String contentType)
- throws ODataException {
-
- Object jpaEntity = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriParserResultView, final String contentType)
- throws ODataException {
-
- List<Object> jpaEntity = jpaProcessor.process(uriParserResultView);
-
- ODataResponse oDataResponse =
- ODataJPAResponseBuilder.build(jpaEntity, uriParserResultView, contentType, oDataJPAContext);
-
- return oDataResponse;
- }
-
- @Override
- public ODataResponse createEntityLink(final PostUriInfo uriParserResultView, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
-
- jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriParserResultView, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
-
- jpaProcessor.process(uriParserResultView, content, requestContentType, contentType);
-
- return ODataResponse.newBuilder().build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilder.java
deleted file mode 100644
index 8f3487e..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/ODataJPAResponseBuilder.java
+++ /dev/null
@@ -1,629 +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.odata2.processor.core.jpa;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.UriParser;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.access.data.JPAEntityParser;
-import org.apache.olingo.odata2.processor.core.jpa.access.data.JPAExpandCallBack;
-
-public final class ODataJPAResponseBuilder {
-
- /* Response for Read Entity Set */
- public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetUriInfo resultsView,
- final String contentType, final ODataJPAContext odataJPAContext) throws ODataJPARuntimeException {
-
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
- List<ArrayList<NavigationPropertySegment>> expandList = null;
-
- try {
- edmEntityType = resultsView.getTargetEntitySet().getEntityType();
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- final List<SelectItem> selectedItems = resultsView.getSelect();
- if (selectedItems != null && selectedItems.size() > 0) {
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap =
- jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, edmEntityType));
- edmEntityList.add(edmPropertyValueMap);
- }
- } else {
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
- edmEntityList.add(edmPropertyValueMap);
- }
- }
- expandList = resultsView.getExpand();
- if (expandList != null && expandList.size() != 0) {
- int count = 0;
- List<EdmNavigationProperty> edmNavPropertyList = constructListofNavProperty(expandList);
- for (Object jpaEntity : jpaEntities) {
- Map<String, Object> relationShipMap = edmEntityList.get(count);
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, edmNavPropertyList);
- relationShipMap.putAll(navigationMap);
- count++;
- }
- }
-
- EntityProviderWriteProperties feedProperties = null;
-
- feedProperties = getEntityProviderProperties(odataJPAContext, resultsView, edmEntityList);
- odataResponse =
- EntityProvider.writeFeed(contentType, resultsView.getTargetEntitySet(), edmEntityList, feedProperties);
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
-
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
- }
-
- /* Response for Read Entity */
- public static ODataResponse build(final Object jpaEntity, final GetEntityUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
- ODataNotFoundException {
-
- List<ArrayList<NavigationPropertySegment>> expandList = null;
- if (jpaEntity == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- edmEntityType = resultsView.getTargetEntitySet().getEntityType();
- Map<String, Object> edmPropertyValueMap = null;
-
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- final List<SelectItem> selectedItems = resultsView.getSelect();
- if (selectedItems != null && selectedItems.size() > 0) {
- edmPropertyValueMap =
- jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, buildSelectItemList(selectedItems, resultsView
- .getTargetEntitySet().getEntityType()));
- } else {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType);
- }
-
- expandList = resultsView.getExpand();
- if (expandList != null && expandList.size() != 0) {
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(jpaEntity, constructListofNavProperty(expandList));
- edmPropertyValueMap.putAll(navigationMap);
- }
- EntityProviderWriteProperties feedProperties = null;
- feedProperties = getEntityProviderProperties(oDataJPAContext, resultsView);
- odataResponse =
- EntityProvider.writeEntry(contentType, resultsView.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
-
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
-
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
- }
-
- /* Response for $count */
- public static ODataResponse build(final long jpaEntityCount, final ODataJPAContext oDataJPAContext)
- throws ODataJPARuntimeException {
-
- ODataResponse odataResponse = null;
- try {
- odataResponse = EntityProvider.writeText(String.valueOf(jpaEntityCount));
- odataResponse = ODataResponse.fromResponse(odataResponse).build();
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- return odataResponse;
- }
-
- /* Response for Create Entity */
- @SuppressWarnings("unchecked")
- public static ODataResponse build(final List<Object> createdObjectList, final PostUriInfo uriInfo,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
- ODataNotFoundException {
-
- if (createdObjectList == null || createdObjectList.size() == 0 || createdObjectList.get(0) == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- edmEntityType = uriInfo.getTargetEntitySet().getEntityType();
- Map<String, Object> edmPropertyValueMap = null;
-
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(createdObjectList.get(0), edmEntityType);
-
- List<ArrayList<NavigationPropertySegment>> expandList = null;
- if (createdObjectList.get(1) != null
- && ((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1)).size() > 0) {
- expandList = getExpandList((Map<EdmNavigationProperty, EdmEntitySet>) createdObjectList.get(1));
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(createdObjectList.get(0),
- constructListofNavProperty(expandList));
- edmPropertyValueMap.putAll(navigationMap);
- }
- EntityProviderWriteProperties feedProperties = null;
- try {
- feedProperties = getEntityProviderPropertiesforPost(oDataJPAContext, uriInfo, expandList);
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- odataResponse =
- EntityProvider.writeEntry(contentType, uriInfo.getTargetEntitySet(), edmPropertyValueMap, feedProperties);
-
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.CREATED).build();
-
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
- }
-
- /* Response for Update Entity */
- public static ODataResponse build(final Object updatedObject, final PutMergePatchUriInfo putUriInfo)
- throws ODataJPARuntimeException, ODataNotFoundException {
- if (updatedObject == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- }
-
- /* Response for Delete Entity */
- public static ODataResponse build(final Object deletedObject, final DeleteUriInfo deleteUriInfo)
- throws ODataJPARuntimeException, ODataNotFoundException {
-
- if (deletedObject == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- }
-
- /* Response for Function Import Single Result */
- public static ODataResponse build(final Object result, final GetFunctionImportUriInfo resultsView)
- throws ODataJPARuntimeException {
-
- try {
- final EdmFunctionImport functionImport = resultsView.getFunctionImport();
- final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
-
- if (result != null) {
- ODataResponse response = null;
-
- final String value = type.valueToString(result, EdmLiteralKind.DEFAULT, null);
- response = EntityProvider.writeText(value);
-
- return ODataResponse.fromResponse(response).build();
- } else {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- }
-
- /* Response for Function Import Multiple Result */
- public static ODataResponse build(final List<Object> resultList, final GetFunctionImportUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException,
- ODataNotFoundException {
-
- ODataResponse odataResponse = null;
-
- if (resultList != null && !resultList.isEmpty()) {
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- EdmType edmType = null;
- EdmFunctionImport functionImport = null;
- Map<String, Object> edmPropertyValueMap = null;
- List<Map<String, Object>> edmEntityList = null;
- Object result = null;
- try {
- EntityProviderWriteProperties feedProperties = null;
-
- feedProperties =
- EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
- .build();
-
- functionImport = resultsView.getFunctionImport();
- edmType = functionImport.getReturnType().getType();
-
- if (edmType.getKind().equals(EdmTypeKind.ENTITY) || edmType.getKind().equals(EdmTypeKind.COMPLEX)) {
- if (functionImport.getReturnType().getMultiplicity().equals(EdmMultiplicity.MANY)) {
- edmEntityList = new ArrayList<Map<String, Object>>();
- for (Object jpaEntity : resultList) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, (EdmStructuralType) edmType);
- edmEntityList.add(edmPropertyValueMap);
- }
- result = edmEntityList;
- } else {
-
- Object resultObject = resultList.get(0);
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(resultObject, (EdmStructuralType) edmType);
-
- result = edmPropertyValueMap;
- }
-
- } else if (edmType.getKind().equals(EdmTypeKind.SIMPLE)) {
- result = resultList.get(0);
- }
-
- odataResponse =
- EntityProvider.writeFunctionImport(contentType, resultsView.getFunctionImport(), result, feedProperties);
- odataResponse = ODataResponse.fromResponse(odataResponse).status(HttpStatusCodes.OK).build();
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EntityProviderException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- } else {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- return odataResponse;
- }
-
- /* Response for Read Entity Link */
- public static ODataResponse build(final Object jpaEntity, final GetEntityLinkUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataNotFoundException,
- ODataJPARuntimeException {
-
- if (jpaEntity == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- EdmEntitySet entitySet = resultsView.getTargetEntitySet();
- edmEntityType = entitySet.getEntityType();
- Map<String, Object> edmPropertyValueMap = null;
-
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, edmEntityType.getKeyProperties());
-
- EntityProviderWriteProperties entryProperties =
- EntityProviderWriteProperties.serviceRoot(oDataJPAContext.getODataContext().getPathInfo().getServiceRoot())
- .build();
-
- ODataResponse response = EntityProvider.writeLink(contentType, entitySet, edmPropertyValueMap, entryProperties);
-
- odataResponse = ODataResponse.fromResponse(response).build();
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
-
- }
-
- return odataResponse;
- }
-
- /* Response for Read Entity Links */
- public static <T> ODataResponse build(final List<T> jpaEntities, final GetEntitySetLinksUriInfo resultsView,
- final String contentType, final ODataJPAContext oDataJPAContext) throws ODataJPARuntimeException {
- EdmEntityType edmEntityType = null;
- ODataResponse odataResponse = null;
-
- try {
-
- EdmEntitySet entitySet = resultsView.getTargetEntitySet();
- edmEntityType = entitySet.getEntityType();
- List<EdmProperty> keyProperties = edmEntityType.getKeyProperties();
-
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
- JPAEntityParser jpaResultParser = new JPAEntityParser();
-
- for (Object jpaEntity : jpaEntities) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(jpaEntity, keyProperties);
- edmEntityList.add(edmPropertyValueMap);
- }
-
- Integer count = null;
- if (resultsView.getInlineCount() != null) {
- if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
- // when $skip and/or $top is present with $inlinecount
- count = getInlineCountForNonFilterQueryLinks(edmEntityList, resultsView);
- } else {
- // In all other cases
- count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
- }
- }
-
- ODataContext context = oDataJPAContext.getODataContext();
- EntityProviderWriteProperties entryProperties =
- EntityProviderWriteProperties.serviceRoot(context.getPathInfo().getServiceRoot()).inlineCountType(
- resultsView.getInlineCount()).inlineCount(count).build();
-
- odataResponse = EntityProvider.writeLinks(contentType, entitySet, edmEntityList, entryProperties);
-
- odataResponse = ODataResponse.fromResponse(odataResponse).build();
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- return odataResponse;
-
- }
-
- /*
- * This method handles $inlinecount request. It also modifies the list of results in case of
- * $inlinecount and $top/$skip combinations. Specific to LinksUriInfo.
- *
- * @param edmEntityList
- *
- * @param resultsView
- *
- * @return
- */
- private static Integer getInlineCountForNonFilterQueryLinks(final List<Map<String, Object>> edmEntityList,
- final GetEntitySetLinksUriInfo resultsView) {
- // when $skip and/or $top is present with $inlinecount, first get the total count
- Integer count = null;
- if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
- if (resultsView.getSkip() != null || resultsView.getTop() != null) {
- count = edmEntityList.size();
- // Now update the list
- if (resultsView.getSkip() != null) {
- // Index checks to avoid IndexOutOfBoundsException
- if (resultsView.getSkip() > edmEntityList.size()) {
- edmEntityList.clear();
- return count;
- }
- edmEntityList.subList(0, resultsView.getSkip()).clear();
- }
- if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
- edmEntityList.subList(0, resultsView.getTop());
- }
- }
- }// Inlinecount of None is handled by default - null
- return count;
- }
-
- /*
- * Method to build the entity provider Property.Callbacks for $expand would
- * be registered here
- */
- private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
- final GetEntitySetUriInfo resultsView, final List<Map<String, Object>> edmEntityList)
- throws ODataJPARuntimeException {
- ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
-
- Integer count = null;
- if (resultsView.getInlineCount() != null) {
- if ((resultsView.getSkip() != null || resultsView.getTop() != null)) {
- // when $skip and/or $top is present with $inlinecount
- count = getInlineCountForNonFilterQueryEntitySet(edmEntityList, resultsView);
- } else {
- // In all other cases
- count = resultsView.getInlineCount() == InlineCount.ALLPAGES ? edmEntityList.size() : null;
- }
- }
-
- try {
- entityFeedPropertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
- entityFeedPropertiesBuilder.inlineCount(count);
- entityFeedPropertiesBuilder.inlineCountType(resultsView.getInlineCount());
- ExpandSelectTreeNode expandSelectTree =
- UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
- entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
- .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
- entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
-
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return entityFeedPropertiesBuilder.build();
- }
-
- /*
- * This method handles $inlinecount request. It also modifies the list of results in case of
- * $inlinecount and $top/$skip combinations. Specific to Entity Set.
- */
- private static Integer getInlineCountForNonFilterQueryEntitySet(final List<Map<String, Object>> edmEntityList,
- final GetEntitySetUriInfo resultsView) {
- // when $skip and/or $top is present with $inlinecount, first get the total count
- Integer count = null;
- if (resultsView.getInlineCount() == InlineCount.ALLPAGES) {
- if (resultsView.getSkip() != null || resultsView.getTop() != null) {
- count = edmEntityList.size();
- // Now update the list
- if (resultsView.getSkip() != null) {
- // Index checks to avoid IndexOutOfBoundsException
- if (resultsView.getSkip() > edmEntityList.size()) {
- edmEntityList.clear();
- return count;
- }
- edmEntityList.subList(0, resultsView.getSkip()).clear();
- }
- if (resultsView.getTop() != null && resultsView.getTop() >= 0 && resultsView.getTop() < edmEntityList.size()) {
- edmEntityList.retainAll(edmEntityList.subList(0, resultsView.getTop()));
- }
- }
- }// Inlinecount of None is handled by default - null
- return count;
- }
-
- private static EntityProviderWriteProperties getEntityProviderProperties(final ODataJPAContext odataJPAContext,
- final GetEntityUriInfo resultsView) throws ODataJPARuntimeException {
- ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
- ExpandSelectTreeNode expandSelectTree = null;
- try {
- entityFeedPropertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
- expandSelectTree = UriParser.createExpandSelectTree(resultsView.getSelect(), resultsView.getExpand());
- entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
- entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
- .getPathInfo().getServiceRoot(), expandSelectTree, resultsView.getExpand()));
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return entityFeedPropertiesBuilder.build();
- }
-
- private static EntityProviderWriteProperties getEntityProviderPropertiesforPost(
- final ODataJPAContext odataJPAContext, final PostUriInfo resultsView,
- final List<ArrayList<NavigationPropertySegment>> expandList) throws ODataJPARuntimeException {
- ODataEntityProviderPropertiesBuilder entityFeedPropertiesBuilder = null;
- ExpandSelectTreeNode expandSelectTree = null;
- try {
- entityFeedPropertiesBuilder =
- EntityProviderWriteProperties.serviceRoot(odataJPAContext.getODataContext().getPathInfo().getServiceRoot());
- expandSelectTree = UriParser.createExpandSelectTree(null, expandList);
- entityFeedPropertiesBuilder.expandSelectTree(expandSelectTree);
- entityFeedPropertiesBuilder.callbacks(JPAExpandCallBack.getCallbacks(odataJPAContext.getODataContext()
- .getPathInfo().getServiceRoot(), expandSelectTree, expandList));
- } catch (ODataException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return entityFeedPropertiesBuilder.build();
- }
-
- private static List<ArrayList<NavigationPropertySegment>> getExpandList(
- final Map<EdmNavigationProperty, EdmEntitySet> navPropEntitySetMap) {
- List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
- ArrayList<NavigationPropertySegment> navigationPropertySegmentList = new ArrayList<NavigationPropertySegment>();
- for (Map.Entry<EdmNavigationProperty, EdmEntitySet> entry : navPropEntitySetMap.entrySet()) {
- final EdmNavigationProperty edmNavigationProperty = entry.getKey();
- final EdmEntitySet edmEntitySet = entry.getValue();
- NavigationPropertySegment navigationPropertySegment = new NavigationPropertySegment() {
-
- @Override
- public EdmEntitySet getTargetEntitySet() {
- return edmEntitySet;
- }
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return edmNavigationProperty;
- }
- };
- navigationPropertySegmentList.add(navigationPropertySegment);
- }
- expandList.add(navigationPropertySegmentList);
- return expandList;
- }
-
- private static List<EdmProperty> buildSelectItemList(final List<SelectItem> selectItems, final EdmEntityType entity)
- throws ODataJPARuntimeException {
- boolean flag = false;
- List<EdmProperty> selectPropertyList = new ArrayList<EdmProperty>();
- try {
- for (SelectItem selectItem : selectItems) {
- selectPropertyList.add(selectItem.getProperty());
- }
- for (EdmProperty keyProperty : entity.getKeyProperties()) {
- flag = true;
- for (SelectItem selectedItem : selectItems) {
- if (selectedItem.getProperty().equals(keyProperty)) {
- flag = false;
- break;
- }
- }
- if (flag == true) {
- selectPropertyList.add(keyProperty);
- }
- }
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- return selectPropertyList;
- }
-
- private static List<EdmNavigationProperty> constructListofNavProperty(
- final List<ArrayList<NavigationPropertySegment>> expandList) {
- List<EdmNavigationProperty> navigationPropertyList = new ArrayList<EdmNavigationProperty>();
- for (ArrayList<NavigationPropertySegment> navpropSegment : expandList) {
- navigationPropertyList.add(navpropSegment.get(0).getNavigationProperty());
- }
- return navigationPropertyList;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
deleted file mode 100644
index 7c2ad29..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntity.java
+++ /dev/null
@@ -1,355 +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.odata2.processor.core.jpa.access.data;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-
-public class JPAEntity {
-
- private Object jpaEntity = null;
- private EdmEntityType oDataEntityType = null;
- private EdmEntitySet oDataEntitySet = null;
- private Class<?> jpaType = null;
- private HashMap<String, Method> accessModifiersWrite = null;
- private JPAEntityParser jpaEntityParser = null;
- public HashMap<EdmNavigationProperty, EdmEntitySet> inlinedEntities = null;
-
- public JPAEntity(final EdmEntityType oDataEntityType, final EdmEntitySet oDataEntitySet) {
- this.oDataEntityType = oDataEntityType;
- this.oDataEntitySet = oDataEntitySet;
- try {
- JPAEdmMapping mapping = (JPAEdmMapping) oDataEntityType.getMapping();
- jpaType = mapping.getJPAType();
- } catch (EdmException e) {
- return;
- }
- jpaEntityParser = new JPAEntityParser();
- }
-
- public void setAccessModifersWrite(final HashMap<String, Method> accessModifiersWrite) {
- this.accessModifiersWrite = accessModifiersWrite;
- }
-
- public Object getJPAEntity() {
- return jpaEntity;
- }
-
- @SuppressWarnings("unchecked")
- private void write(final Map<String, Object> oDataEntryProperties, final boolean isCreate)
- throws ODataJPARuntimeException {
- try {
-
- EdmStructuralType structuralType = null;
- final List<String> keyNames = oDataEntityType.getKeyPropertyNames();
-
- if (isCreate) {
- jpaEntity = instantiateJPAEntity();
- } else if (jpaEntity == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.RESOURCE_NOT_FOUND, null);
- }
-
- if (accessModifiersWrite == null) {
- accessModifiersWrite =
- jpaEntityParser.getAccessModifiers(jpaEntity, oDataEntityType, JPAEntityParser.ACCESS_MODIFIER_SET);
- }
-
- if (oDataEntityType == null || oDataEntryProperties == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL, null);
- }
-
- final HashMap<String, String> embeddableKeys =
- jpaEntityParser.getJPAEmbeddableKeyMap(jpaEntity.getClass().getName());
- Set<String> propertyNames = null;
- if (embeddableKeys != null) {
- setEmbeddableKeyProperty(embeddableKeys, oDataEntityType.getKeyProperties(), oDataEntryProperties, jpaEntity);
- propertyNames = new HashSet<String>();
- propertyNames.addAll(oDataEntryProperties.keySet());
- for (String propertyName : oDataEntityType.getKeyPropertyNames()) {
- propertyNames.remove(propertyName);
- }
- } else {
- propertyNames = oDataEntryProperties.keySet();
- }
-
- for (String propertyName : propertyNames) {
- EdmTyped edmTyped = (EdmTyped) oDataEntityType.getProperty(propertyName);
-
- Method accessModifier = null;
-
- switch (edmTyped.getType().getKind()) {
- case SIMPLE:
- if (isCreate == false) {
- if (keyNames.contains(edmTyped.getName())) {
- continue;
- }
- }
- accessModifier = accessModifiersWrite.get(propertyName);
- setProperty(accessModifier, jpaEntity, oDataEntryProperties.get(propertyName));
- break;
- case COMPLEX:
- structuralType = (EdmStructuralType) edmTyped.getType();
- accessModifier = accessModifiersWrite.get(propertyName);
- setComplexProperty(accessModifier, jpaEntity,
- structuralType,
- (HashMap<String, Object>) oDataEntryProperties.get(propertyName));
- break;
- case NAVIGATION:
- case ENTITY:
- structuralType = (EdmStructuralType) edmTyped.getType();
- EdmNavigationProperty navProperty = (EdmNavigationProperty) edmTyped;
- accessModifier =
- jpaEntityParser.getAccessModifier(jpaEntity, navProperty,
- JPAEntityParser.ACCESS_MODIFIER_SET);
- EdmEntitySet edmRelatedEntitySet = oDataEntitySet.getRelatedEntitySet(navProperty);
- List<ODataEntry> relatedEntries = (List<ODataEntry>) oDataEntryProperties.get(propertyName);
- Collection<Object> relatedJPAEntites = instantiateRelatedJPAEntities(jpaEntity, navProperty);
- JPAEntity relatedEntity = new JPAEntity((EdmEntityType) structuralType, edmRelatedEntitySet);
- for (ODataEntry oDataEntry : relatedEntries) {
- relatedEntity.create(oDataEntry);
- relatedJPAEntites.add(relatedEntity.getJPAEntity());
- }
-
- switch (navProperty.getMultiplicity()) {
- case MANY:
- accessModifier.invoke(jpaEntity, relatedJPAEntites);
- break;
- case ONE:
- case ZERO_TO_ONE:
- accessModifier.invoke(jpaEntity, relatedJPAEntites.iterator().next());
- break;
- }
-
- if (inlinedEntities == null) {
- inlinedEntities = new HashMap<EdmNavigationProperty, EdmEntitySet>();
- }
-
- inlinedEntities.put((EdmNavigationProperty) edmTyped, edmRelatedEntitySet);
- default:
- continue;
- }
- }
- } catch (Exception e) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL
- .addContent(e.getMessage()), e);
- }
- }
-
- @SuppressWarnings("unchecked")
- private Collection<Object> instantiateRelatedJPAEntities(final Object jpaEntity,
- final EdmNavigationProperty navProperty)
- throws InstantiationException,
- IllegalAccessException, EdmException, ODataJPARuntimeException, IllegalArgumentException,
- InvocationTargetException {
- Method accessModifier =
- jpaEntityParser.getAccessModifier(jpaEntity, navProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
- Collection<Object> relatedJPAEntities = (Collection<Object>) accessModifier.invoke(jpaEntity);
- if (relatedJPAEntities == null) {
- relatedJPAEntities = new ArrayList<Object>();
- }
- return relatedJPAEntities;
- }
-
- public void create(final ODataEntry oDataEntry) throws ODataJPARuntimeException {
- if (oDataEntry == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL, null);
- }
- Map<String, Object> oDataEntryProperties = oDataEntry.getProperties();
- if (oDataEntry.containsInlineEntry()) {
- normalizeInlineEntries(oDataEntryProperties);
- }
- write(oDataEntryProperties, true);
- }
-
- public void create(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
- normalizeInlineEntries(oDataEntryProperties);
- write(oDataEntryProperties, true);
- }
-
- public void update(final ODataEntry oDataEntry) throws ODataJPARuntimeException {
- if (oDataEntry == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL, null);
- }
- Map<String, Object> oDataEntryProperties = oDataEntry.getProperties();
- write(oDataEntryProperties, false);
- }
-
- public void update(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
- write(oDataEntryProperties, false);
- }
-
- public HashMap<EdmNavigationProperty, EdmEntitySet> getInlineJPAEntities() {
- return inlinedEntities;
- }
-
- public void setJPAEntity(final Object jpaEntity) {
- this.jpaEntity = jpaEntity;
- }
-
- @SuppressWarnings("unchecked")
- protected void setComplexProperty(Method accessModifier, final Object jpaEntity,
- final EdmStructuralType edmComplexType, final HashMap<String, Object> propertyValue)
- throws EdmException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
- InstantiationException, ODataJPARuntimeException {
-
- JPAEdmMapping mapping = (JPAEdmMapping) edmComplexType.getMapping();
- Object embeddableObject = mapping.getJPAType().newInstance();
- accessModifier.invoke(jpaEntity, embeddableObject);
-
- HashMap<String, Method> accessModifiers =
- jpaEntityParser.getAccessModifiers(embeddableObject, edmComplexType, JPAEntityParser.ACCESS_MODIFIER_SET);
-
- for (String edmPropertyName : edmComplexType.getPropertyNames()) {
- EdmTyped edmTyped = (EdmTyped) edmComplexType.getProperty(edmPropertyName);
- accessModifier = accessModifiers.get(edmPropertyName);
- if (edmTyped.getType().getKind().toString().equals(EdmTypeKind.COMPLEX.toString())) {
- EdmStructuralType structualType = (EdmStructuralType) edmTyped.getType();
- setComplexProperty(accessModifier, embeddableObject, structualType, (HashMap<String, Object>) propertyValue
- .get(edmPropertyName));
- } else {
- setProperty(accessModifier, embeddableObject, propertyValue.get(edmPropertyName));
- }
- }
- }
-
- protected void setProperty(final Method method, final Object entity, final Object entityPropertyValue) throws
- IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- if (entityPropertyValue != null) {
- Class<?> parameterType = method.getParameterTypes()[0];
- if (parameterType.equals(char[].class)) {
- char[] characters = ((String) entityPropertyValue).toCharArray();
- method.invoke(entity, characters);
- } else if (parameterType.equals(char.class)) {
- char c = ((String) entityPropertyValue).charAt(0);
- method.invoke(entity, c);
- } else if (parameterType.equals(Character[].class)) {
- Character[] characters = JPAEntityParser.toCharacterArray((String) entityPropertyValue);
- method.invoke(entity, (Object) characters);
- } else if (parameterType.equals(Character.class)) {
- Character c = Character.valueOf(((String) entityPropertyValue).charAt(0));
- method.invoke(entity, c);
- } else {
- method.invoke(entity, entityPropertyValue);
- }
- }
- }
-
- protected void setEmbeddableKeyProperty(final HashMap<String, String> embeddableKeys,
- final List<EdmProperty> oDataEntryKeyProperties,
- final Map<String, Object> oDataEntryProperties, final Object entity)
- throws ODataJPARuntimeException, EdmException, IllegalAccessException, IllegalArgumentException,
- InvocationTargetException, InstantiationException {
-
- HashMap<String, Object> embeddableObjMap = new HashMap<String, Object>();
- List<EdmProperty> leftODataEntryKeyProperties = new ArrayList<EdmProperty>();
- HashMap<String, String> leftEmbeddableKeys = new HashMap<String, String>();
-
- for (EdmProperty edmProperty : oDataEntryKeyProperties) {
- if (oDataEntryProperties.containsKey(edmProperty.getName()) == false) {
- continue;
- }
-
- String edmPropertyName = edmProperty.getName();
- String embeddableKeyNameComposite = embeddableKeys.get(edmPropertyName);
- String embeddableKeyNameSplit[] = embeddableKeyNameComposite.split("\\.");
- String methodPartName = null;
- Method method = null;
- Object embeddableObj = null;
-
- if (embeddableObjMap.containsKey(embeddableKeyNameSplit[0]) == false) {
- methodPartName = embeddableKeyNameSplit[0];
- method = jpaEntityParser.getAccessModifierSet(entity, methodPartName);
- embeddableObj = method.getParameterTypes()[0].newInstance();
- method.invoke(entity, embeddableObj);
- embeddableObjMap.put(embeddableKeyNameSplit[0], embeddableObj);
- } else {
- embeddableObj = embeddableObjMap.get(embeddableKeyNameSplit[0]);
- }
-
- if (embeddableKeyNameSplit.length == 2) {
- methodPartName = embeddableKeyNameSplit[1];
- method = jpaEntityParser.getAccessModifierSet(embeddableObj, methodPartName);
- Object simpleObj = oDataEntryProperties.get(edmProperty.getName());
- method.invoke(embeddableObj, simpleObj);
- } else if (embeddableKeyNameSplit.length > 2) { // Deeply nested
- leftODataEntryKeyProperties.add(edmProperty);
- leftEmbeddableKeys
- .put(edmPropertyName, embeddableKeyNameComposite.split(embeddableKeyNameSplit[0] + ".", 2)[1]);
- setEmbeddableKeyProperty(leftEmbeddableKeys, leftODataEntryKeyProperties, oDataEntryProperties, embeddableObj);
- }
-
- }
- }
-
- protected Object instantiateJPAEntity() throws InstantiationException, IllegalAccessException {
- if (jpaType == null) {
- throw new InstantiationException();
- }
-
- return jpaType.newInstance();
- }
-
- private void normalizeInlineEntries(final Map<String, Object> oDataEntryProperties) throws ODataJPARuntimeException {
- List<ODataEntry> entries = null;
- try {
- for (String navigationPropertyName : oDataEntityType.getNavigationPropertyNames()) {
- Object inline = oDataEntryProperties.get(navigationPropertyName);
- if (inline instanceof ODataFeed) {
- entries = ((ODataFeed) inline).getEntries();
- } else if (inline instanceof ODataEntry) {
- entries = new ArrayList<ODataEntry>();
- entries.add((ODataEntry) inline);
- }
- if (entries != null) {
- oDataEntryProperties.put(navigationPropertyName, entries);
- entries = null;
- }
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL
- .addContent(e.getMessage()), e);
- }
- }
-}
\ No newline at end of file
[15/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java
deleted file mode 100644
index f00cc61..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderNegativeTest.java
+++ /dev/null
@@ -1,191 +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.odata2.processor.core.jpa.edm;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmModel;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ODataJPAEdmProviderNegativeTest {
-
- private static ODataJPAEdmProvider edmProvider;
-
- @BeforeClass
- public static void setup() {
-
- edmProvider = new ODataJPAEdmProvider();
- try {
- Class<? extends ODataJPAEdmProvider> clazz = edmProvider.getClass();
- Field field = clazz.getDeclaredField("schemas");
- field.setAccessible(true);
- List<Schema> schemas = new ArrayList<Schema>();
- schemas.add(new Schema().setNamespace("salesorderprocessing")); // Empty Schema
- field.set(edmProvider, schemas);
- field = clazz.getDeclaredField("oDataJPAContext");
- field.setAccessible(true);
- field.set(edmProvider, ODataJPAContextMock.mockODataJPAContext());
- field = clazz.getDeclaredField("jpaEdmModel");
- field.setAccessible(true);
- field.set(edmProvider, new JPAEdmModel(null, null));
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testNullGetEntityContainerInfo() {
- EntityContainerInfo entityContainer = null;
- try {
- entityContainer = edmProvider.getEntityContainerInfo("salesorderprocessingContainer");
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNull(entityContainer);
- }
-
- @Test
- public void testNullGetEntityType() {
- FullQualifiedName entityTypeName = new FullQualifiedName("salesorderprocessing", "SalesOrderHeader");
- try {
- assertNull(edmProvider.getEntityType(entityTypeName));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testNullGetComplexType() {
- FullQualifiedName complexTypeName = new FullQualifiedName("salesorderprocessing", "Address");
- try {
- assertNull(edmProvider.getComplexType(complexTypeName));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetAssociationFullQualifiedName() {
- Association association = null;
- try {
- association =
- edmProvider.getAssociation(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader_SalesOrderItem"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNull(association);
- }
-
- @Test
- public void testGetEntitySet() {
- try {
- assertNull(edmProvider.getEntitySet("salesorderprocessingContainer", "SalesOrderHeaders"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetAssociationSet() {
- try {
- assertNull(edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName(
- "salesorderprocessing", "SalesOrderHeader_SalesOrderItem"), "SalesOrderHeaders", "SalesOrderHeader"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testNullGetFunctionImport() {
-
- try {
- assertNull(edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testNullGetFunctionImport2() {
-
- try {
- ODataJPAEdmProvider provider = new ODataJPAEdmProvider();
- try {
- Class<? extends ODataJPAEdmProvider> clazz = provider.getClass();
- Field field = clazz.getDeclaredField("schemas");
- field.setAccessible(true);
- List<Schema> schemas = new ArrayList<Schema>();
- Schema schema = new Schema().setNamespace("salesorderprocessing");
- EntityContainer container = new EntityContainer().setName("salesorderprocessingContainer");
- List<EntityContainer> containerList = new ArrayList<EntityContainer>();
- containerList.add(container); // Empty Container
- schema.setEntityContainers(containerList);
- schemas.add(schema); // Empty Schema
- field.set(provider, schemas);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertNull(provider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testGetSchemas() {
- try {
- assertNotNull(edmProvider.getSchemas());
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java
deleted file mode 100644
index 8dbd9da..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/edm/ODataJPAEdmProviderTest.java
+++ /dev/null
@@ -1,385 +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.odata2.processor.core.jpa.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.EdmSchemaMock;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmModel;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class ODataJPAEdmProviderTest {
-
- private static ODataJPAEdmProvider edmProvider;
-
- @BeforeClass
- public static void setup() {
-
- edmProvider = new ODataJPAEdmProvider();
- try {
- Class<? extends ODataJPAEdmProvider> clazz = edmProvider.getClass();
- Field field = clazz.getDeclaredField("schemas");
- field.setAccessible(true);
- List<Schema> schemas = new ArrayList<Schema>();
- schemas.add(EdmSchemaMock.createMockEdmSchema());
- field.set(edmProvider, schemas);
- field = clazz.getDeclaredField("oDataJPAContext");
- field.setAccessible(true);
- field.set(edmProvider, ODataJPAContextMock.mockODataJPAContext());
- field = clazz.getDeclaredField("jpaEdmModel");
- field.setAccessible(true);
- field.set(edmProvider, new JPAEdmModel(null, null));
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testConstructor() {
- try {
- ODataJPAEdmProvider edmProv = new ODataJPAEdmProvider(ODataJPAContextMock.mockODataJPAContext());
- edmProv.getClass();
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(true);
- }
- }
-
- @Test
- public void testGetODataJPAContext() {
- String pUnitName = edmProvider.getODataJPAContext().getPersistenceUnitName();
- assertEquals("salesorderprocessing", pUnitName);
- }
-
- @Test
- public void testGetEntityContainerInfo() {
- String entityContainerName = null;
- EntityContainerInfo entityContainer = null;
- try {
- entityContainer = edmProvider.getEntityContainerInfo("salesorderprocessingContainer");
- entityContainerName = entityContainer.getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals("salesorderprocessingContainer", entityContainerName);
- assertNotNull(entityContainer);
- }
-
- @Test
- public void testDefaultGetEntityContainerInfo() {
- String entityContainerName = null;
- EntityContainerInfo entityContainer = null;
- try {
- entityContainer = edmProvider.getEntityContainerInfo(null);
- entityContainerName = entityContainer.getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals("salesorderprocessingContainer", entityContainerName);
- assertNotNull(entityContainer);
- }
-
- @Test
- public void testGetEntityType() {
- FullQualifiedName entityTypeName = new FullQualifiedName("salesorderprocessing", "SalesOrderHeader");
- String entityName = null;
- try {
- entityName = edmProvider.getEntityType(entityTypeName).getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("SalesOrderHeader", entityName);
- try {
- edmProvider.getEntityType(new FullQualifiedName("salesorder", "abc"));
- } catch (ODataException e) {
- assertTrue(true);
- }
-
- }
-
- @Test
- public void testGetComplexType() {
- FullQualifiedName complexTypeName = new FullQualifiedName("salesorderprocessing", "Address");
- String nameStr = null;
- try {
- nameStr = edmProvider.getComplexType(complexTypeName).getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("Address", nameStr);
- }
-
- @Test
- public void testGetAssociationFullQualifiedName() {
- Association association = null;
- try {
- association =
- edmProvider.getAssociation(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader_SalesOrderItem"));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(association);
- assertEquals("SalesOrderHeader_SalesOrderItem", association.getName());
- }
-
- @Test
- public void testGetEntitySet() {
- String entitySetName = null;
- try {
- entitySetName = edmProvider.getEntitySet("salesorderprocessingContainer", "SalesOrderHeaders").getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("SalesOrderHeaders", entitySetName);
- try {
- assertNull(edmProvider.getEntitySet("salesorderprocessing", "SalesOrderHeaders"));
- } catch (ODataException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testGetAssociationSet() {
- AssociationSet associationSet = null;
-
- try {
- associationSet =
- edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem"), "SalesOrderHeaders", "SalesOrderHeader");
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(associationSet);
- assertEquals("SalesOrderHeader_SalesOrderItemSet", associationSet.getName());
- try {
- associationSet =
- edmProvider.getAssociationSet("salesorderprocessingContainer", new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem"), "SalesOrderItems", "SalesOrderItem");
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertNotNull(associationSet);
- try {
- associationSet =
- edmProvider.getAssociationSet("salesorderproceContainer", new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem"), "SalesOrderItems", "SalesOrderItem");
- } catch (ODataException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testGetFunctionImport() {
- String functionImportName = null;
- try {
- functionImportName =
- edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1").getName();
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals("SalesOrder_FunctionImport1", functionImportName);
- try {
- functionImportName =
- edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1").getName();
- } catch (ODataException e) {
- assertTrue(true);
- }
- try {
- assertNotNull(edmProvider.getFunctionImport("salesorderprocessingContainer", "SalesOrder_FunctionImport1"));
- } catch (ODataException e) {
- e.printStackTrace();
- }
- }
-
- @Test
- public void testGetSchemas() {
- try {
- assertNotNull(edmProvider.getSchemas());
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testgetComplexTypeWithBuffer() {
- HashMap<String, ComplexType> compTypes = new HashMap<String, ComplexType>();
- ComplexType comp = new ComplexType();
- comp.setName("Address");
- compTypes.put("salesorderprocessing" + "." + "Address", comp);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- Field f;
- try {
- f = claz.getDeclaredField("complexTypes");
- f.setAccessible(true);
- f.set(jpaEdmProv, compTypes);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- try {
- assertEquals(comp, jpaEdmProv.getComplexType(new FullQualifiedName("salesorderprocessing", "Address")));
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- try {
- jpaEdmProv.getComplexType(new FullQualifiedName("salesorderessing", "abc"));
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetEntityContainerInfoWithBuffer() {
- HashMap<String, EntityContainerInfo> entityContainerInfos = new HashMap<String, EntityContainerInfo>();
- EntityContainerInfo entityContainer = new EntityContainerInfo();
- entityContainer.setName("salesorderprocessingContainer");
- entityContainerInfos.put("salesorderprocessingContainer", entityContainer);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- try {
- Field f = claz.getDeclaredField("entityContainerInfos");
- f.setAccessible(true);
- f.set(jpaEdmProv, entityContainerInfos);
- assertEquals(entityContainer, jpaEdmProv.getEntityContainerInfo("salesorderprocessingContainer"));
- jpaEdmProv.getEntityContainerInfo("abc");
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetEntityTypeWithBuffer() {
- HashMap<String, org.apache.olingo.odata2.api.edm.provider.EntityType> entityTypes =
- new HashMap<String, org.apache.olingo.odata2.api.edm.provider.EntityType>();
- org.apache.olingo.odata2.api.edm.provider.EntityType entity =
- new org.apache.olingo.odata2.api.edm.provider.EntityType();
- entity.setName("SalesOrderHeader");
- entityTypes.put("salesorderprocessing" + "." + "SalesorderHeader", entity);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- Field f;
- try {
- f = claz.getDeclaredField("entityTypes");
- f.setAccessible(true);
- f.set(jpaEdmProv, entityTypes);
- assertEquals(entity, jpaEdmProv.getEntityType(new FullQualifiedName("salesorderprocessing", "SalesorderHeader")));
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- try {
- jpaEdmProv.getEntityType(new FullQualifiedName("salesoprocessing", "abc"));
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetAssociationWithBuffer() {
- HashMap<String, Association> associations = new HashMap<String, Association>();
- Association association = new Association();
- association.setName("SalesOrderHeader_SalesOrderItem");
- associations.put("salesorderprocessing" + "." + "SalesOrderHeader_SalesOrderItem", association);
- ODataJPAEdmProvider jpaEdmProv = new ODataJPAEdmProvider();
- Class<?> claz = jpaEdmProv.getClass();
- Field f;
- try {
- f = claz.getDeclaredField("associations");
- f.setAccessible(true);
- f.set(jpaEdmProv, associations);
- assertEquals(association, jpaEdmProv.getAssociation(new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader_SalesOrderItem")));
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- try {
- jpaEdmProv.getAssociation(new FullQualifiedName("salesorderprocessing", "abc"));
- } catch (ODataJPAModelException e) {
- assertTrue(true);
- } catch (ODataException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java
deleted file mode 100644
index 7da02d8..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLBuilderFactoryTest.java
+++ /dev/null
@@ -1,377 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.persistence.Cache;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnitUtil;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement.JPQLStatementBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.ODataJPAContextImpl;
-import org.apache.olingo.odata2.processor.core.jpa.access.data.JPAProcessorImplTest;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.factory.ODataJPAFactoryImpl;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectContext.JPQLSelectContextBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectSingleContext.JPQLSelectSingleContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPQLBuilderFactoryTest {
-
- @Test
- public void testGetStatementBuilderFactoryforSelect() throws ODataException {
-
- GetEntitySetUriInfo getEntitySetView = getUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.SELECT, getEntitySetView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLSelectStatementBuilder);
-
- }
-
- @Test
- public void testGetStatementBuilderFactoryforSelectSingle() throws ODataException {
-
- GetEntityUriInfo getEntityView = getEntityUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLSelectSingleStatementBuilder);
-
- }
-
- @Test
- public void testGetStatementBuilderFactoryforJoinSelect() throws ODataException {
-
- GetEntitySetUriInfo getEntitySetView = getUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.JOIN, getEntitySetView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLJoinStatementBuilder);
-
- }
-
- @Test
- public void testGetStatementBuilderFactoryforJoinSelectSingle() throws ODataException {
-
- GetEntityUriInfo getEntityView = getEntityUriInfo();
-
- // Build JPQL Context
- JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.JOIN_SINGLE, getEntityView).build();
- JPQLStatementBuilder statementBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
-
- assertTrue(statementBuilder instanceof JPQLJoinSelectSingleStatementBuilder);
-
- }
-
- @Test
- public void testGetContextBuilderforDelete() throws ODataException {
-
- // Build JPQL ContextBuilder
- JPQLContextBuilder contextBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.DELETE);
-
- assertNull(contextBuilder);
-
- }
-
- @Test
- public void testGetContextBuilderforSelect() throws ODataException {
-
- // Build JPQL ContextBuilder
- JPQLContextBuilder contextBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.SELECT);
-
- assertNotNull(contextBuilder);
- assertTrue(contextBuilder instanceof JPQLSelectContextBuilder);
-
- }
-
- @Test
- public void testGetContextBuilderforSelectSingle() throws ODataException {
-
- // Build JPQL ContextBuilder
- JPQLContextBuilder contextBuilder =
- new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.SELECT_SINGLE);
-
- assertNotNull(contextBuilder);
- assertTrue(contextBuilder instanceof JPQLSelectSingleContextBuilder);
-
- }
-
- private GetEntitySetUriInfo getUriInfo() throws EdmException {
- GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SOItem");
- EasyMock.replay(edmEntityType);
- OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
- EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(getEntitySetView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression);
- EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(null);
- EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(null);
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- EasyMock.expect(getEntitySetView.getNavigationSegments()).andStubReturn(navigationSegments);
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- try {
- EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
- EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
-
- EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);
-
- } catch (EdmException e2) {
- fail("this should not happen");
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
- EasyMock.replay(edmMapping, edmType, kpProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- EasyMock.expect(getEntitySetView.getKeyPredicates()).andStubReturn(keyPredicates);
- EasyMock.replay(getEntitySetView);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.replay(edmEntitySet);
- return getEntitySetView;
- }
-
- private GetEntityUriInfo getEntityUriInfo() throws EdmException {
- GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("");
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
- EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(getEntityView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.replay(edmEntityType, edmEntitySet);
- EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- EasyMock.expect(getEntityView.getNavigationSegments()).andStubReturn(navigationSegments);
- EasyMock.replay(getEntityView);
- return getEntityView;
- }
-
- @Test
- public void testJPAAccessFactory() {
- ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
- JPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getJPAAccessFactory();
- ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
- Class<?> clazz = oDataJPAContextImpl.getClass();
- try {
- Field field = clazz.getDeclaredField("em");
- field.setAccessible(true);
- field.set(oDataJPAContextImpl, new JPAProcessorImplTest().getLocalEntityManager());
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EntityManagerFactory emf = new EntityManagerFactory() {
-
- @Override
- public boolean isOpen() {
- return false;
- }
-
- @Override
- public Map<String, Object> getProperties() {
- return null;
- }
-
- @Override
- public PersistenceUnitUtil getPersistenceUnitUtil() {
- return null;
- }
-
- @Override
- public Metamodel getMetamodel() {
- return null;
- }
-
- @Override
- public CriteriaBuilder getCriteriaBuilder() {
- return null;
- }
-
- @Override
- public Cache getCache() {
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public EntityManager createEntityManager(final Map arg0) {
- return null;
- }
-
- @Override
- public EntityManager createEntityManager() {
- return null;
- }
-
- @Override
- public void close() {}
- };
- oDataJPAContextImpl.setEntityManagerFactory(emf);
- oDataJPAContextImpl.setPersistenceUnitName("pUnit");
-
- assertNotNull(jpaAccessFactory.getJPAProcessor(oDataJPAContextImpl));
- assertNotNull(jpaAccessFactory.getJPAEdmModelView(oDataJPAContextImpl));
-
- }
-
- @Test
- public void testOdataJpaAccessFactory() {
-
- ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
- ODataJPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getODataJPAAccessFactory();
- ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
-
- EntityManagerFactory emf = new EntityManagerFactory() {
-
- @Override
- public boolean isOpen() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public Map<String, Object> getProperties() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public PersistenceUnitUtil getPersistenceUnitUtil() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Metamodel getMetamodel() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public CriteriaBuilder getCriteriaBuilder() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Cache getCache() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public EntityManager createEntityManager(final Map arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public EntityManager createEntityManager() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void close() {
- // TODO Auto-generated method stub
-
- }
- };
- oDataJPAContextImpl.setEntityManagerFactory(emf);
- oDataJPAContextImpl.setPersistenceUnitName("pUnit");
-
- assertNotNull(jpaAccessFactory.getODataJPAMessageService(new Locale("en")));
- assertNotNull(jpaAccessFactory.createODataJPAContext());
- assertNotNull(jpaAccessFactory.createJPAEdmProvider(oDataJPAContextImpl));
- assertNotNull(jpaAccessFactory.createODataProcessor(oDataJPAContextImpl));
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java
deleted file mode 100644
index 509591f..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinContextTest.java
+++ /dev/null
@@ -1,198 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectContext.JPQLJoinContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLJoinContextTest {
-
- GetEntitySetUriInfo entitySetUriInfo;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {}
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {}
-
- @Before
- public void setUp() throws Exception {
- entitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
- final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
- final List<KeyPredicate> keyPredicates = createKeyPredicates();
- NavigationSegment navigationSegment = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- NavigationSegment navigationSegment1 = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty1;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- navigationSegments.add(navigationSegment);
- navigationSegments.add(navigationSegment1);
- EasyMock.expect(entitySetUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
- EasyMock.expect(entitySetUriInfo.getOrderBy()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getFilter()).andStubReturn(null);
- EasyMock.expect(entitySetUriInfo.getKeyPredicates()).andStubReturn(keyPredicates);
- EasyMock.expect(entitySetUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(entitySetUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.replay(edmEntityType, edmEntitySet, entitySetUriInfo);
-
- }
-
- @After
- public void tearDown() throws Exception {}
-
- @Test
- public void testGetJPAOuterJoinClauses() {
- JPQLJoinSelectContext joinContext = new JPQLJoinSelectContext(false);
- JPQLJoinContextBuilder joinContextBuilder = joinContext.new JPQLJoinContextBuilder();
- try {
- joinContextBuilder.entitySetView = entitySetUriInfo;
- joinContextBuilder.build();
- } catch (ODataJPAModelException e) {
- fail("Should not come here");
- } catch (ODataJPARuntimeException e) {
- fail("Should not come here");
- }
- List<JPAJoinClause> joinClauses = joinContext.getJPAJoinClauses();
- assertNotNull(joinClauses);
- assertTrue(joinClauses.size() > 0);
- assertEquals("E1", joinClauses.get(0).getEntityAlias());
- assertEquals("SOHeader", joinClauses.get(0).getEntityName());
- assertEquals("s_Itema", joinClauses.get(1).getEntityRelationShip());
- assertEquals("R1", joinClauses.get(1).getEntityRelationShipAlias());
- }
-
- private EdmNavigationProperty createNavigationProperty(final String z) throws EdmException {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
- EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
- EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("roleA" + z);
- EasyMock.expect(navigationProperty.getToRole()).andStubReturn("roleB" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("sItem" + z);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("soItem" + z);
- EasyMock.expect(associationEnd.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(association.getEnd("roleA" + z)).andStubReturn(associationEnd);
- EasyMock.expect(navigationProperty.getRelationship()).andStubReturn(association);
- EdmMapping edmMapping1 = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping1.getInternalName()).andStubReturn("s_Item" + z);
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping1);
- EasyMock.replay(edmMapping, edmMapping1, edmEntityType, associationEnd, association, navigationProperty);
- return navigationProperty;
- }
-
- private List<KeyPredicate> createKeyPredicates() throws EdmException {
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
-
- EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- return keyPredicates;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java
deleted file mode 100644
index b7c9c7d..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleContextTest.java
+++ /dev/null
@@ -1,215 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLJoinSelectSingleContext.JPQLJoinSelectSingleContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLJoinSelectSingleContextTest {
-
- GetEntityUriInfo entityUriInfo;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {}
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {}
-
- public void setUp(final boolean toThrowException) throws Exception {
- entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
- final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
- final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
- final List<KeyPredicate> keyPredicates = createKeyPredicates(toThrowException);
- NavigationSegment navigationSegment = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- NavigationSegment navigationSegment1 = new NavigationSegment() {
-
- @Override
- public EdmNavigationProperty getNavigationProperty() {
- return navigationProperty1;
- }
-
- @Override
- public List<KeyPredicate> getKeyPredicates() {
- return keyPredicates;
- }
-
- @Override
- public EdmEntitySet getEntitySet() {
- // TODO Auto-generated method stub
- return null;
- }
- };
- navigationSegments.add(navigationSegment);
- navigationSegments.add(navigationSegment1);
- EasyMock.expect(entityUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
- EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(null);
- EasyMock.expect(entityUriInfo.getFilter()).andStubReturn(null);
- EasyMock.expect(entityUriInfo.getKeyPredicates()).andStubReturn(createKeyPredicates(toThrowException));
- EasyMock.expect(entityUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
- EasyMock.expect(entityUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
- EasyMock.replay(startEdmEntityType, startEdmEntitySet);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
- EasyMock.replay(edmEntityType, edmEntitySet, entityUriInfo);
-
- }
-
- @After
- public void tearDown() throws Exception {}
-
- @Test
- public void testGetJPAOuterJoinClauses() throws Exception {
- setUp(false);
-
- JPQLJoinSelectSingleContext joinContext = new JPQLJoinSelectSingleContext();
- JPQLJoinSelectSingleContextBuilder joinContextBuilder = joinContext.new JPQLJoinSelectSingleContextBuilder();
- try {
- joinContextBuilder.entityView = entityUriInfo;
- joinContextBuilder.build();
- } catch (ODataJPAModelException e) {
- fail("Should not come here");
- } catch (ODataJPARuntimeException e) {
- fail("Should not come here");
- }
- List<JPAJoinClause> joinClauses = joinContext.getJPAJoinClauses();
- assertNotNull(joinClauses);
- assertTrue(joinClauses.size() > 0);
- assertEquals("E1", joinClauses.get(0).getEntityAlias());
- assertEquals("SOHeader", joinClauses.get(0).getEntityName());
- assertEquals("s_Itema", joinClauses.get(1).getEntityRelationShip());
- assertEquals("R1", joinClauses.get(1).getEntityRelationShipAlias());
- }
-
- @Test
- public void testExceptionThrown() throws Exception {
- setUp(true);
- JPQLJoinSelectSingleContext joinContext = new JPQLJoinSelectSingleContext();
- JPQLJoinSelectSingleContextBuilder joinContextBuilder = joinContext.new JPQLJoinSelectSingleContextBuilder();
- try {
- joinContextBuilder.entityView = entityUriInfo;
- joinContextBuilder.build();
- fail("Should not come here");
- } catch (ODataJPAModelException e) {
- fail("Should not come here");
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
- private EdmNavigationProperty createNavigationProperty(final String z) throws EdmException {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
- EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
- EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("roleA" + z);
- EasyMock.expect(navigationProperty.getToRole()).andStubReturn("roleB" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
- EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("sItem" + z);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("soItem" + z);
- EasyMock.expect(associationEnd.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.expect(association.getEnd("roleA" + z)).andStubReturn(associationEnd);
- EasyMock.expect(navigationProperty.getRelationship()).andStubReturn(association);
- EdmMapping edmMapping1 = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping1.getInternalName()).andStubReturn("s_Item" + z);
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping1);
- EasyMock.replay(edmMapping, edmMapping1, edmEntityType, associationEnd, association, navigationProperty);
- return navigationProperty;
- }
-
- private List<KeyPredicate> createKeyPredicates(final boolean toThrowException) throws EdmException {
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- if (toThrowException) {
- EasyMock.expect(edmProperty.getType()).andStubThrow(new EdmException(null));
- } else {
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
-
- EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- return keyPredicates;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilderTest.java
deleted file mode 100644
index c7df74b..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinSelectSingleStatementBuilderTest.java
+++ /dev/null
@@ -1,142 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLJoinSelectSingleContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLJoinSelectSingleStatementBuilderTest {
- JPQLJoinSelectSingleContextView context = null;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {}
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {}
-
- public void setUp(final List<JPAJoinClause> joinClauseList) throws Exception {
- context = EasyMock.createMock(JPQLJoinSelectSingleContextView.class);
- EasyMock.expect(context.getJPAEntityAlias()).andStubReturn("gt1");
- EasyMock.expect(context.getJPAEntityName()).andStubReturn("SOHeader");
- EasyMock.expect(context.getType()).andStubReturn(JPQLContextType.SELECT);
- EasyMock.expect(context.getKeyPredicates()).andStubReturn(createKeyPredicates());
- EasyMock.expect(context.getSelectExpression()).andStubReturn("gt1");
- EasyMock.expect(context.getJPAJoinClauses()).andStubReturn(joinClauseList);
- EasyMock.replay(context);
- }
-
- private List<JPAJoinClause> getJoinClauseList() {
- List<JPAJoinClause> joinClauseList = new ArrayList<JPAJoinClause>();
- JPAJoinClause jpaOuterJoinClause =
- new JPAJoinClause("SOHeader", "soh", null, null, "soh.soId = 1", JPAJoinClause.JOIN.LEFT);
- joinClauseList.add(jpaOuterJoinClause);
- jpaOuterJoinClause =
- new JPAJoinClause("SOHeader", "soh", "soItem", "soi", "soi.shId = soh.soId", JPAJoinClause.JOIN.LEFT);
- joinClauseList.add(jpaOuterJoinClause);
- jpaOuterJoinClause =
- new JPAJoinClause("SOItem", "si", "material", "mat", "mat.id = 'abc'", JPAJoinClause.JOIN.LEFT);
- joinClauseList.add(jpaOuterJoinClause);
- return joinClauseList;
- }
-
- @After
- public void tearDown() throws Exception {}
-
- @Test
- public void testBuild() throws Exception {
- setUp(getJoinClauseList());
- JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
- new JPQLJoinSelectSingleStatementBuilder(context);
- try {
- JPQLStatement jpqlStatement = jpqlJoinSelectsingleStatementBuilder.build();
- assertEquals(
- "SELECT gt1 FROM SOHeader soh JOIN soh.soItem soi JOIN soi.material mat WHERE soh.soId = 1 AND " +
- "soi.shId = soh.soId AND mat.id = 'abc'",
- jpqlStatement.toString());
- } catch (ODataJPARuntimeException e) {
- fail("Should not have come here");
- }
-
- }
-
- private List<KeyPredicate> createKeyPredicates() throws EdmException {
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
-
- EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
- List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
- keyPredicates.add(keyPredicate);
- return keyPredicates;
- }
-
- @Test
- public void testJoinClauseAsNull() throws Exception {
- setUp(null);
- JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
- new JPQLJoinSelectSingleStatementBuilder(context);
- try {
- jpqlJoinSelectsingleStatementBuilder.build();
- fail("Should not have come here");
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testJoinClauseListAsEmpty() throws Exception {
- List<JPAJoinClause> joinClauseList = new ArrayList<JPAJoinClause>();
- setUp(joinClauseList);
- JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
- new JPQLJoinSelectSingleStatementBuilder(context);
- try {
- jpqlJoinSelectsingleStatementBuilder.build();
- fail("Should not have come here");
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilderTest.java
deleted file mode 100644
index dad45e3..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLJoinStatementBuilderTest.java
+++ /dev/null
@@ -1,124 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLJoinContextView;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLJoinStatementBuilderTest {
- JPQLJoinContextView context = null;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {}
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {}
-
- public void setUp(final List<JPAJoinClause> joinClauseList) throws Exception {
- context = EasyMock.createMock(JPQLJoinContextView.class);
- EasyMock.expect(context.getJPAEntityAlias()).andStubReturn("mat");
- EasyMock.expect(context.getJPAEntityName()).andStubReturn("SOHeader");
- EasyMock.expect(context.getType()).andStubReturn(JPQLContextType.SELECT);
- EasyMock.expect(context.getSelectExpression()).andStubReturn("mat");
- EasyMock.expect(context.getWhereExpression()).andStubReturn("soh.buyerId = 2");
- HashMap<String, String> orderByMap = new HashMap<String, String>();
- orderByMap.put("mat.buyerId", "asc");
- orderByMap.put("mat.city", "desc");
- EasyMock.expect(context.getOrderByCollection()).andStubReturn(orderByMap);
- EasyMock.expect(context.getJPAJoinClauses()).andStubReturn(joinClauseList);
- EasyMock.replay(context);
- }
-
- private List<JPAJoinClause> getJoinClauseList() {
- List<JPAJoinClause> joinClauseList = new ArrayList<JPAJoinClause>();
- JPAJoinClause jpaOuterJoinClause =
- new JPAJoinClause("SOHeader", "soh", null, null, "soh.createdBy = 'Peter'", JPAJoinClause.JOIN.LEFT);
- joinClauseList.add(jpaOuterJoinClause);
- jpaOuterJoinClause =
- new JPAJoinClause("SOHeader", "soh", "soItem", "soi", "soi.shId = soh.soId", JPAJoinClause.JOIN.LEFT);
- joinClauseList.add(jpaOuterJoinClause);
- jpaOuterJoinClause =
- new JPAJoinClause("SOItem", "si", "material", "mat", "mat.id = 'abc'", JPAJoinClause.JOIN.LEFT);
- joinClauseList.add(jpaOuterJoinClause);
- return joinClauseList;
- }
-
- @After
- public void tearDown() throws Exception {}
-
- @Test
- public void testBuild() throws Exception {
- setUp(getJoinClauseList());
- JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
- try {
- JPQLStatement jpqlStatement = jpqlJoinStatementBuilder.build();
- assertEquals(
- "SELECT mat FROM SOHeader soh JOIN soh.soItem soi JOIN soi.material mat WHERE soh.buyerId = 2 AND "
- +
- "soh.createdBy = 'Peter' AND soi.shId = soh.soId AND mat.id = 'abc' "
- +
- "ORDER BY mat.buyerId asc , mat.city desc",
- jpqlStatement.toString());
- } catch (ODataJPARuntimeException e) {
- fail("Should not have come here");
- }
-
- }
-
- @Test
- public void testJoinClauseAsNull() throws Exception {
- setUp(null);
- JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
- try {
- jpqlJoinStatementBuilder.build();
- fail("Should not have come here");
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testJoinClauseListAsEmpty() throws Exception {
- setUp(new ArrayList<JPAJoinClause>());
- JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
- try {
- jpqlJoinStatementBuilder.build();
- fail("Should not have come here");
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
-}
[04/47] git commit: [OLINGO-28] Support EDM Extension
Posted by tb...@apache.org.
[OLINGO-28] Support EDM Extension
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/ecdc476c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/ecdc476c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/ecdc476c
Branch: refs/heads/ODataServlet
Commit: ecdc476c1b2d7abce675c3307e7c1ed72ea84eed
Parents: 636eed2
Author: Chandan V A <ch...@sap.com>
Authored: Mon Dec 23 17:56:09 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Mon Dec 23 17:56:09 2013 +0530
----------------------------------------------------------------------
.../api/jpa/model/JPAEdmComplexTypeView.java | 21 ++++++++++
.../api/jpa/model/JPAEdmSchemaView.java | 5 ---
.../core/jpa/model/JPAEdmComplexType.java | 18 ++++++++-
.../core/jpa/model/JPAEdmEntityContainer.java | 9 -----
.../core/jpa/model/JPAEdmFunctionImport.java | 28 ++++++++++---
.../core/jpa/model/JPAEdmProperty.java | 5 +--
.../processor/core/jpa/model/JPAEdmSchema.java | 36 ++++++++---------
.../core/jpa/model/JPAEdmPropertyTest.java | 6 +--
.../core/jpa/model/JPAEdmTestModelView.java | 20 ++++++----
.../jpa/processor/ref/extension/OrderValue.java | 42 ++++++++++++++++++++
.../extension/SalesOrderHeaderProcessor.java | 18 +++++++++
.../SalesOrderProcessingExtension.java | 34 +++++++++++++++-
12 files changed, 186 insertions(+), 56 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
index bbee5e4..9ec27c4 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmComplexTypeView.java
@@ -83,6 +83,8 @@ public interface JPAEdmComplexTypeView extends JPAEdmBaseView {
* The method add a JPA EDM complex type view to the container.
*
* @param view
+ * @param isReferencedInKey
+ * is the complex type referenced in an Entity as a key property
* is an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}
*/
public void addJPAEdmCompleTypeView(JPAEdmComplexTypeView view);
@@ -113,4 +115,23 @@ public interface JPAEdmComplexTypeView extends JPAEdmBaseView {
public void expandEdmComplexType(ComplexType complexType, List<Property> expandedPropertyList,
String embeddablePropertyName);
+ /**
+ * The method checks if the given EDM complex type is referenced as a Key property in any Entity
+ * @param complexTypeName
+ * EDM complex type name
+ * @return
+ * <ul><li><b>true</b> : if the complex type is referenced as an entity's key property</li>
+ * <li><b>false</b> : if the complex type is not referenced as an entity's key property</li>
+ * </ul>
+ *
+ */
+ public boolean isReferencedInKey(String complexTypeName);
+
+ /**
+ * The method sets the given EDM complex type as referenced in an Entity as a key property
+ * @param complexTypeName
+ * EDM complex Type name
+ */
+ public void setReferencedInKey(String complexTypeName);
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
index d52d9a3..0400271 100644
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/model/JPAEdmSchemaView.java
@@ -19,7 +19,6 @@
package org.apache.olingo.odata2.processor.api.jpa.model;
import java.util.HashMap;
-import java.util.List;
import org.apache.olingo.odata2.api.edm.provider.Schema;
@@ -109,8 +108,4 @@ public interface JPAEdmSchemaView extends JPAEdmBaseView {
*/
public HashMap<Class<?>, String[]> getRegisteredOperations();
- public List<String> getNonKeyComplexTypeList();
-
- public void addNonKeyComplexName(String complexTypeName);
-
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
index ad25a1b..31831dd 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexType.java
@@ -52,11 +52,15 @@ public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmCompl
private List<ComplexType> consistentComplextTypes = null;
private boolean directBuild;
private EmbeddableType<?> nestedComplexType = null;
+ private List<String> nonKeyComplexList = null;
public JPAEdmComplexType(final JPAEdmSchemaView view) {
super(view);
schemaView = view;
directBuild = true;
+ if (nonKeyComplexList == null) {
+ nonKeyComplexList = new ArrayList<String>();
+ }
}
public JPAEdmComplexType(final JPAEdmSchemaView view, final Attribute<?, ?> complexAttribute) {
@@ -69,6 +73,19 @@ public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmCompl
}
}
directBuild = false;
+ if (nonKeyComplexList == null) {
+ nonKeyComplexList = new ArrayList<String>();
+ }
+ }
+
+ @Override
+ public boolean isReferencedInKey(final String complexTypeName) {
+ return nonKeyComplexList.contains(complexTypeName);
+ }
+
+ @Override
+ public void setReferencedInKey(final String complexTypeName) {
+ nonKeyComplexList.add(complexTypeName);
}
@Override
@@ -151,7 +168,6 @@ public class JPAEdmComplexType extends JPAEdmBaseViewImpl implements JPAEdmCompl
JPAEdmMapping oldMapping = (JPAEdmMapping) mapping;
newMapping.setJPAColumnName(oldMapping.getJPAColumnName());
newMapping.setInternalName(embeddablePropertyName + "." + mapping.getInternalName());
- newMapping.setMimeType(mapping.getMimeType());
newMapping.setObject(mapping.getObject());
newMapping.setJPAType(oldMapping.getJPAType());
newSimpleProperty.setMapping(newMapping);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
index fee40c2..1bb60be 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainer.java
@@ -28,7 +28,6 @@ import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeExcep
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmFunctionImportView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
@@ -137,14 +136,6 @@ public class JPAEdmEntityContainer extends JPAEdmBaseViewImpl implements JPAEdmE
}
JPAEdmNameBuilder.build(JPAEdmEntityContainer.this);
- if (schemaView.getJPAEdmExtension() != null) {
- JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(schemaView);
- functionImportView.getBuilder().build();
- if (functionImportView.getConsistentFunctionImportList() != null) {
- currentEntityContainer.setFunctionImports(functionImportView.getConsistentFunctionImportList());
- }
- }
-
consistentEntityContainerList.add(currentEntityContainer);
isConsistent = true;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
index b64f61c..464b548 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
@@ -289,15 +289,33 @@ public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFu
break;
case COMPLEX:
+ String embeddableTypeName = null;
ComplexType complexType = null;
+ boolean exists = false;
+
if (returnType.isCollection() == false) {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(methodReturnType.getName());
+ embeddableTypeName = methodReturnType.getName();
} else {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(getReturnTypeName(method));
+ embeddableTypeName = getReturnTypeName(method);
}
- if (complexType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+
+ complexType = jpaEdmComplexTypeView.searchEdmComplexType(embeddableTypeName);
+
+ if (complexType == null) {// This could occure of non JPA Embeddable Types : Extension Scenario
+ List<ComplexType> complexTypeList = schemaView.getEdmSchema().getComplexTypes();
+ String[] complexTypeNameParts = embeddableTypeName.split("\\.");
+ String complexTypeName = complexTypeNameParts[complexTypeNameParts.length - 1];
+ for (ComplexType complexType1 : complexTypeList) {
+ if (complexType1.getName().equals(complexTypeName)) {
+ complexType = complexType1;
+ exists = true;
+ break;
+ }
+ }
+ if (exists == false) {
+ throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
+ .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
+ }
}
functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
break;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
index b34a71d..edd1c6e 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
@@ -264,10 +264,9 @@ public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
complexType.getName()));
properties.add(currentComplexProperty);
- List<String> nonKeyComplexTypes = schemaView.getNonKeyComplexTypeList();
- if (!nonKeyComplexTypes.contains(currentComplexProperty.getType().getName()))
+ if (!complexTypeView.isReferencedInKey(currentComplexProperty.getType().getName()))
{
- schemaView.addNonKeyComplexName(currentComplexProperty.getType().getName());
+ complexTypeView.setReferencedInKey(currentComplexProperty.getType().getName());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
index b9ded8b..c6f543a 100644
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
+++ b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
@@ -35,6 +35,8 @@ import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
+import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmFunctionImportView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
@@ -45,24 +47,10 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
private JPAEdmComplexTypeView complexTypeView;
private JPAEdmEntityContainerView entityContainerView;
private JPAEdmAssociationView associationView = null;
- private List<String> nonKeyComplexList = null;
private HashMap<Class<?>, String[]> customOperations = null;
public JPAEdmSchema(final JPAEdmModelView modelView) {
super(modelView);
- if (nonKeyComplexList == null) {
- nonKeyComplexList = new ArrayList<String>();
- }
- }
-
- @Override
- public List<String> getNonKeyComplexTypeList() {
- return nonKeyComplexList;
- }
-
- @Override
- public void addNonKeyComplexName(final String complexTypeName) {
- nonKeyComplexList.add(complexTypeName);
}
@Override
@@ -127,10 +115,6 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
complexTypeView = new JPAEdmComplexType(JPAEdmSchema.this);
complexTypeView.getBuilder().build();
- if (getJPAEdmExtension() != null) {
- getJPAEdmExtension().extendWithOperation(JPAEdmSchema.this);
- }
-
entityContainerView = new JPAEdmEntityContainer(JPAEdmSchema.this);
entityContainerView.getBuilder().build();
schema.setEntityContainers(entityContainerView.getConsistentEdmEntityContainerList());
@@ -146,7 +130,8 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
List<ComplexType> complexTypes = complexTypeView.getConsistentEdmComplexTypes();
List<ComplexType> existingComplexTypes = new ArrayList<ComplexType>();
for (ComplexType complexType : complexTypes) {
- if (complexType != null && nonKeyComplexList.contains(complexType.getName())) {// null check for exclude
+ if (complexType != null && complexTypeView.isReferencedInKey(complexType.getName())) {// null check for
+ // exclude
existingComplexTypes.add(complexType);
}
}
@@ -190,6 +175,19 @@ public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView
}
}
+ JPAEdmExtension edmExtension = getJPAEdmExtension();
+ if (edmExtension != null) {
+ edmExtension.extendJPAEdmSchema(JPAEdmSchema.this);
+ edmExtension.extendWithOperation(JPAEdmSchema.this);
+
+ JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(JPAEdmSchema.this);
+ functionImportView.getBuilder().build();
+ if (functionImportView.getConsistentFunctionImportList() != null) {
+ entityContainerView.getEdmEntityContainer().setFunctionImports(
+ functionImportView.getConsistentFunctionImportList());
+ }
+
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
index 633459f..a0bcbce 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmPropertyTest.java
@@ -24,9 +24,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.util.ArrayList;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import javax.persistence.metamodel.Attribute;
@@ -178,8 +176,8 @@ public class JPAEdmPropertyTest extends JPAEdmTestModelView {
}
@Override
- public List<String> getNonKeyComplexTypeList() {
- return new ArrayList<String>();
+ public boolean isReferencedInKey(final String complexType) {
+ return false;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
index cf96ac7..1b15b75 100644
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmTestModelView.java
@@ -323,14 +323,6 @@ public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAsso
}
@Override
- public List<String> getNonKeyComplexTypeList() {
- return null;
- }
-
- @Override
- public void addNonKeyComplexName(final String complexTypeName) {}
-
- @Override
public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess() {
return null;
}
@@ -393,4 +385,16 @@ public class JPAEdmTestModelView implements JPAEdmAssociationEndView, JPAEdmAsso
return false;
}
+ @Override
+ public boolean isReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setReferencedInKey(String complexTypeName) {
+ // TODO Auto-generated method stub
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java
new file mode 100644
index 0000000..9dde58f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/OrderValue.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.ref.extension;
+
+public class OrderValue {
+
+ private double amount;
+ private String currency;
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(double amount) {
+ this.amount = amount;
+ }
+
+ public String getCurrency() {
+ return currency;
+ }
+
+ public void setCurrency(String currency) {
+ this.currency = currency;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
index 0ff659b..72a8fbd 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
@@ -112,4 +112,22 @@ public class SalesOrderHeaderProcessor {
}
}
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX))
+ public OrderValue getOrderValue(
+ @EdmFunctionImportParameter(name = "SoId", facets = @EdmFacets(nullable = false)) final Long soID) {
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ + soID + "l");
+ @SuppressWarnings("unchecked")
+ List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
+ .getResultList();
+ OrderValue orderValue = new OrderValue();
+ if (!soList.isEmpty()) {
+
+ orderValue.setAmount(soList.get(0).getNetAmount());
+ orderValue.setCurrency(soList.get(0).getCurrencyCode());
+ }
+ return orderValue;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ecdc476c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
index 6b82899..3dacd7e 100644
--- a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.java
@@ -18,15 +18,45 @@
******************************************************************************/
package org.apache.olingo.odata2.jpa.processor.ref.extension;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
public class SalesOrderProcessingExtension implements JPAEdmExtension {
@Override
- public void extendJPAEdmSchema(final JPAEdmSchemaView arg0) {
- // TODO Auto-generated method stub
+ public void extendJPAEdmSchema(final JPAEdmSchemaView view) {
+ Schema edmSchema = view.getEdmSchema();
+ edmSchema.getComplexTypes().add(getComplexType());
+ }
+ private ComplexType getComplexType() {
+ ComplexType complexType = new ComplexType();
+
+ List<Property> properties = new ArrayList<Property>();
+ SimpleProperty property = new SimpleProperty();
+
+ property.setName("Amount");
+ property.setType(EdmSimpleTypeKind.Double);
+ properties.add(property);
+
+ property = new SimpleProperty();
+ property.setName("Currency");
+ property.setType(EdmSimpleTypeKind.String);
+ properties.add(property);
+
+ complexType.setName("OrderValue");
+ complexType.setProperties(properties);
+
+ return complexType;
+
}
@Override
[14/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContextImplTest.java
deleted file mode 100644
index 817d8d3..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectContextImplTest.java
+++ /dev/null
@@ -1,385 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
-import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
-import org.apache.olingo.odata2.api.uri.expression.SortOrder;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectContext.JPQLSelectContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPQLSelectContextImplTest {
-
- private static String entityTypeName = "MockEntity";
- private static String[] fields = { "Field1", "Field2" };
- private static List<KeyPredicate> keyPredicates;
- private static SortOrder[] orderType = { SortOrder.asc, SortOrder.desc };
-
- private static JPQLSelectContextBuilder builder;
- private static JPQLSelectContext selectContext;
-
- @BeforeClass
- public static void setup() {
-
- }
-
- private void buildSelectContext(final boolean orderByIsNull, final boolean selectFieldsIsNull,
- final boolean filterIsNull, final boolean isTopNull, final boolean isSkipNull) {
- builder = null;
- selectContext = null;
- keyPredicates = new ArrayList<KeyPredicate>();
- GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);
-
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
- EdmType edmType1 = EasyMock.createMock(EdmType.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- try {
- EasyMock.expect(mapping.getInternalName()).andStubReturn("Field1");
- EasyMock.expect(kpProperty.getMapping()).andStubReturn(mapping);
- EasyMock.expect(kpProperty.getType()).andStubReturn(edmType1);
-
- } catch (EdmException e2) {
- fail("this should not happen");
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
- EasyMock.replay(mapping, edmType1, kpProperty, keyPredicate);
- keyPredicates.add(keyPredicate);
- int i = 0;
- List<OrderExpression> orderList = new ArrayList<OrderExpression>(2);
- do {
-
- EdmType edmType = EasyMock.createMock(EdmType.class);
- try {
- EasyMock.expect(edmType.getName()).andStubReturn(fields[i]);
- EasyMock.replay(edmType);
- } catch (EdmException e2) {
- fail("Exception not Expected");
- }
-
- PropertyExpression commonExpression = EasyMock.createMock(PropertyExpression.class);
- EasyMock.expect(commonExpression.getEdmType()).andStubReturn(edmType);
-
- EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
- try {
- EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
- } catch (EdmException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- EasyMock.expect(commonExpression.getEdmProperty()).andStubReturn(edmTyped);
- OrderExpression order = EasyMock.createMock(OrderExpression.class);
- EasyMock.expect(order.getExpression()).andStubReturn(commonExpression);
- EasyMock.expect(order.getSortOrder()).andStubReturn(orderType[i]);
- EasyMock.replay(edmMapping, edmTyped, commonExpression);
- EasyMock.replay(order);
-
- orderList.add(order);
-
- } while (++i < 2);
-
- OrderByExpression orderBy = EasyMock.createMock(OrderByExpression.class);
- EasyMock.expect(orderBy.getOrders()).andStubReturn(orderList);
- EasyMock.replay(orderBy);
-
- try {
- i = 0;
- List<SelectItem> selectItemList = new ArrayList<SelectItem>(2);
- do {
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.replay(edmMapping, edmProperty);
-
- SelectItem selectItem = EasyMock.createMock(SelectItem.class);
- EasyMock.expect(selectItem.getProperty()).andStubReturn(edmProperty);
- EasyMock.replay(selectItem);
-
- selectItemList.add(selectItem);
-
- } while (++i < 2);
- EasyMock.expect(entityType.getMapping()).andStubReturn(null);
- EasyMock.expect(entityType.getName()).andStubReturn(entityTypeName);
- EasyMock.expect(entityType.getKeyProperties()).andStubReturn(getLocalKeyProperties());
-
- EasyMock.replay(entityType);
- EasyMock.expect(entitySet.getEntityType()).andStubReturn(entityType);
- EasyMock.replay(entitySet);
-
- EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
- if (orderByIsNull) {
- EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);
- } else {
- EasyMock.expect(resultsView.getOrderBy()).andStubReturn(orderBy);
- }
- if (selectFieldsIsNull) {
- EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
- } else {
- EasyMock.expect(resultsView.getSelect()).andStubReturn(selectItemList);
- }
- // FilterExpression filterExpression =
- // EasyMock.createMock(FilterExpression.class);
- // EasyMock.expect(filterExpression.g)
- if (filterIsNull) {
- EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
- } else {
- EasyMock.expect(resultsView.getFilter()).andStubReturn(
- getFilterExpressionMockedObj(ExpressionKind.PROPERTY, "SalesOrder"));
- }
- if (isTopNull) {
- EasyMock.expect(resultsView.getTop()).andStubReturn(null);
- } else {
- EasyMock.expect(resultsView.getTop()).andStubReturn(10);
- }
- if (isSkipNull) {
- EasyMock.expect(resultsView.getSkip()).andStubReturn(null);
- } else {
- EasyMock.expect(resultsView.getSkip()).andStubReturn(0);
- }
- EasyMock.expect(resultsView.getKeyPredicates()).andStubReturn(keyPredicates);
- EasyMock.replay(resultsView);
-
- } catch (EdmException e1) {
- fail("Exception not Expected");
- }
- try {
- builder = (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);
-
- selectContext = (JPQLSelectContext) builder.build();
- } catch (ODataJPAModelException e) {
- fail("Exception not Expected");
- } catch (ODataJPARuntimeException e) {
- fail("Runtime Exception thrown");
- }
- }
-
- private List<EdmProperty> getLocalKeyProperties() {
- List<EdmProperty> propertyList = new ArrayList<EdmProperty>();
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- try {
- EasyMock.expect(edmProperty.getName()).andStubReturn("Field1");
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(null);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(edmProperty);
- propertyList.add(edmProperty);
- return propertyList;
- }
-
- @Test
- public void testEntityNameThrowingException() {
- // buildSelectContext(false, false, false);
- GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);
-
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
-
- try {
- EasyMock.expect(entityType.getName()).andStubThrow(new EdmException(null));
- EasyMock.expect(entitySet.getEntityType()).andStubThrow(new EdmException(null));
- } catch (EdmException e1) {
- // throw new ODataException();
- }
-
- EasyMock.replay(entityType);
- EasyMock.replay(entitySet);
-
- EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
- EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);
- EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
- EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
- EasyMock.replay(resultsView);
- try {
- JPQLSelectContextBuilder builder1 =
- (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);
-
- builder1.build();
- fail("Should not come here");
- } catch (ODataJPAModelException e) {
- fail();
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testSelectFieldsAsNull() {
- buildSelectContext(false, true, true, true, true);
-
- try {
- selectContext = (JPQLSelectContext) builder.build();
- assertEquals("E2", selectContext.getSelectExpression());
- } catch (ODataJPAModelException e) {
- fail();
- } catch (ODataJPARuntimeException e) {
- fail();
- }
- }
-
- @Test
- public void testGetOrderByCollection() {
- buildSelectContext(false, false, true, true, true);
- assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[0]));
- assertEquals("", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[0]));
-
- assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[1]));
- assertEquals("DESC", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[1]));
- }
-
- @Test
- public void testGetWhereExpression() {
- buildSelectContext(false, false, true, true, true);
- // fail("Not yet implemented");
- }
-
- @Test
- public void testGetJPAEntityName() {
- buildSelectContext(false, false, true, true, true);
- assertEquals(JPQLSelectContextImplTest.entityTypeName, selectContext.getJPAEntityName());
- }
-
- @Test
- public void testGetType() {
- buildSelectContext(false, false, true, true, true);
- assertEquals(JPQLContextType.SELECT, selectContext.getType());
- }
-
- @Test
- public void testCreateBuilder() {
- buildSelectContext(false, false, true, true, true);
- assertEquals(JPQLSelectContextBuilder.class.toString(), builder.getClass().toString());
- }
-
- @Test
- public void testEntitySetAsNull() {
- buildSelectContext(false, false, true, true, true);
- try {
- JPQLSelectContextBuilder builder =
- (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, null);
-
- JPQLSelectContext selectContext1 = (JPQLSelectContext) builder.build();
- assertNull(selectContext1.getJPAEntityAlias());
- assertNull(selectContext1.getJPAEntityName());
- assertNull(selectContext1.getOrderByCollection());
- assertNull(selectContext1.getSelectExpression());
- assertNull(selectContext1.getType());
- assertNull(selectContext1.getWhereExpression());
- } catch (ODataJPAModelException e) {
- fail("Exception not Expected");
- } catch (ODataJPARuntimeException e) {
- fail("Runtime Exception thrown");
- }
- }
-
- @Test
- public void testOrderingWithSkip() {
- buildSelectContext(true, false, true, true, false);
- assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[0]));
- assertEquals("", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[0]));
-
- assertEquals(false, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[1]));
-
- }
-
- @Test
- public void testOrderingWithTop() {
- buildSelectContext(true, false, true, false, true);
- assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[0]));
- assertEquals("", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[0]));
-
- assertEquals(false, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[1]));
-
- }
-
- @Test
- public void testOrderByTopSkipAsNull() {
- buildSelectContext(true, true, true, true, true);
- assertNull(selectContext.getOrderByCollection());
- }
-
- @Test
- public void testFilter() {
- buildSelectContext(true, false, false, false, false);
- assertEquals("E1.field", selectContext.whereCondition);
-
- }
-
- private FilterExpression getFilterExpressionMockedObj(final ExpressionKind leftOperandExpKind,
- final String propertyName) throws EdmException {
- FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
- EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
- EasyMock.expect(filterExpression.getExpression()).andStubReturn(
- getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
- EasyMock.replay(filterExpression);
- return filterExpression;
- }
-
- private PropertyExpression getPropertyExpressionMockedObj(final ExpressionKind expKind, final String propertyName) {
- PropertyExpression leftOperandPropertyExpresion = EasyMock.createMock(PropertyExpression.class);
- EasyMock.expect(leftOperandPropertyExpresion.getKind()).andReturn(ExpressionKind.PROPERTY);
- EasyMock.expect(leftOperandPropertyExpresion.getPropertyName()).andReturn(propertyName);
- EdmProperty edmtTyped = EasyMock.createMock(EdmProperty.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mapping.getInternalName()).andStubReturn("field");
- try {
- EasyMock.expect(edmtTyped.getMapping()).andStubReturn(mapping);
- } catch (EdmException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- EasyMock.expect(leftOperandPropertyExpresion.getEdmProperty()).andReturn(edmtTyped);
- EasyMock.replay(mapping, edmtTyped, leftOperandPropertyExpresion);
- return leftOperandPropertyExpresion;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContextImplTest.java
deleted file mode 100644
index 841ff5a..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleContextImplTest.java
+++ /dev/null
@@ -1,198 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.core.jpa.jpql.JPQLSelectSingleContext.JPQLSelectSingleContextBuilder;
-import org.easymock.EasyMock;
-import org.junit.Test;
-
-public class JPQLSelectSingleContextImplTest {
-
- private static String entityTypeName = "MockEntity";
- private static String[] fields = { "Field1", "Field2" };
- private static List<KeyPredicate> keyPredicates;
-
- private static JPQLSelectSingleContextBuilder builder;
- private static JPQLSelectSingleContext selectContext;
-
- private void buildContextBuilder(final boolean isSelectNull) {
- builder = null;
- selectContext = null;
- keyPredicates = new ArrayList<KeyPredicate>();
- GetEntityUriInfo resultsView = EasyMock.createMock(GetEntityUriInfo.class);
-
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
-
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- try {
- EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
- EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
-
- } catch (EdmException e2) {
- fail("this should not happen");
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
- EasyMock.replay(edmType, kpProperty, keyPredicate);
- keyPredicates.add(keyPredicate);
- int i = 0;
- try {
-
- List<SelectItem> selectItemList = new ArrayList<SelectItem>(2);
- do {
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
- EasyMock.replay(edmMapping, edmProperty);
-
- SelectItem selectItem = EasyMock.createMock(SelectItem.class);
- EasyMock.expect(selectItem.getProperty()).andStubReturn(edmProperty);
- EasyMock.replay(selectItem);
-
- selectItemList.add(selectItem);
-
- } while (++i < 2);
-
- EasyMock.expect(entityType.getMapping()).andStubReturn(null);
- EasyMock.expect(entityType.getName()).andStubReturn(entityTypeName);
- EasyMock.replay(entityType);
- EasyMock.expect(entitySet.getEntityType()).andStubReturn(entityType);
- EasyMock.replay(entitySet);
-
- EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
- if (isSelectNull) {
- selectItemList = null;
- }
- EasyMock.expect(resultsView.getSelect()).andStubReturn(selectItemList);
- ArrayList<KeyPredicate> arrayList = new ArrayList<KeyPredicate>();
- arrayList.add(keyPredicate);
- EasyMock.expect(resultsView.getKeyPredicates()).andStubReturn(arrayList);
- EasyMock.replay(resultsView);
-
- } catch (EdmException e1) {
- fail("Exception not Expected");
- }
- try {
- builder = (JPQLSelectSingleContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, resultsView);
-
- selectContext = (JPQLSelectSingleContext) builder.build();
- } catch (ODataJPAModelException e) {
- fail("Exception not Expected");
- } catch (ODataJPARuntimeException e) {
- fail("Runtime Exception thrown");
- }
- }
-
- @Test
- public void testEntityNameThrowingException() {
- // buildSelectContext(false, false, false);
- GetEntityUriInfo resultsView = EasyMock.createMock(GetEntityUriInfo.class);
-
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
-
- try {
- EasyMock.expect(entityType.getName()).andStubThrow(new EdmException(null));
- EasyMock.expect(entitySet.getEntityType()).andStubThrow(new EdmException(null));
- } catch (EdmException e1) {
- // throw new ODataException();
- }
-
- EasyMock.replay(entityType);
- EasyMock.replay(entitySet);
-
- EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
- EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
- EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
- EasyMock.replay(resultsView);
- try {
- JPQLSelectSingleContextBuilder builder1 =
- (JPQLSelectSingleContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, resultsView);
- builder1.build();
- fail("Should not come here");
- } catch (ODataJPAModelException e) {
- fail();
- } catch (ODataJPARuntimeException e) {
- assertTrue(true);
- }
- }
-
- @Test
- public void testSlectedFieldsAsNull() {
- buildContextBuilder(true);
- try {
- selectContext = (JPQLSelectSingleContext) builder.build();
- assertEquals("E2", selectContext.getSelectExpression());
- } catch (ODataJPAModelException e) {
- fail();
- } catch (ODataJPARuntimeException e) {
- fail();
- }
- }
-
- @Test
- public void getKeyPredicates() {
- buildContextBuilder(false);
- assertEquals(keyPredicates.size(), selectContext.getKeyPredicates().size());
- assertEquals(keyPredicates, selectContext.getKeyPredicates());
- }
-
- @Test
- public void testGetJPAEntityName() {
- buildContextBuilder(false);
- assertEquals(JPQLSelectSingleContextImplTest.entityTypeName, selectContext.getJPAEntityName());
- }
-
- @Test
- public void testGetType() {
- buildContextBuilder(false);
- assertEquals(JPQLContextType.SELECT_SINGLE, selectContext.getType());
- }
-
- @Test
- public void testCreateBuilder() {
- buildContextBuilder(false);
- assertEquals(JPQLSelectSingleContextBuilder.class.toString(), builder.getClass().toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilderTest.java
deleted file mode 100644
index c5d5f95..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectSingleStatementBuilderTest.java
+++ /dev/null
@@ -1,123 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPQLSelectSingleStatementBuilderTest {
-
- /**
- * @throws java.lang.Exception
- */
- private JPQLSelectSingleStatementBuilder JPQLSelectSingleStatementBuilder;
-
- @Before
- public void setUp() throws Exception {
-
- }
-
- private JPQLSelectSingleContext createSelectContext() throws ODataJPARuntimeException, EdmException {
- // Object Instantiation
-
- JPQLSelectSingleContext JPQLSelectSingleContextImpl = null;// new JPQLSelectSingleContextImpl();
- GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
-
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- List<SelectItem> selectItemList = null;
-
- // Setting up the expected value
- KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
- EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
- EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
- EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
- EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
- try {
- EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
- EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
-
- EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);
-
- } catch (EdmException e2) {
- fail("this should not happen");
- }
- EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
- EasyMock.replay(edmMapping, edmType, kpProperty, keyPredicate);
- EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EasyMock.expect(getEntityView.getSelect()).andStubReturn(selectItemList);
-
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.replay(edmEntitySet);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader");
- EasyMock.replay(edmEntityType);
- ArrayList<KeyPredicate> arrayList = new ArrayList<KeyPredicate>();
- arrayList.add(keyPredicate);
- EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(arrayList);
- EasyMock.replay(getEntityView);
-
- JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView);
- try {
- JPQLSelectSingleContextImpl = (JPQLSelectSingleContext) contextBuilder1.build();
- } catch (ODataJPAModelException e) {
- fail("Model Exception thrown");
- }
-
- return JPQLSelectSingleContextImpl;
- }
-
- /**
- * Test method for {@link org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectSingleStatementBuilder#build)}.
- * @throws EdmException
- * @throws ODataJPARuntimeException
- */
-
- @Test
- public void testBuildSimpleQuery() throws EdmException, ODataJPARuntimeException {
- JPQLSelectSingleContext JPQLSelectSingleContextImpl = createSelectContext();
- JPQLSelectSingleStatementBuilder = new JPQLSelectSingleStatementBuilder(JPQLSelectSingleContextImpl);
-
- assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.Field1 = 1", JPQLSelectSingleStatementBuilder.build()
- .toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilderTest.java
deleted file mode 100644
index 2434809..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/jpql/JPQLSelectStatementBuilderTest.java
+++ /dev/null
@@ -1,135 +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.odata2.processor.core.jpa.jpql;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.uri.SelectItem;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext.JPQLContextBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPQLSelectStatementBuilderTest {
-
- /**
- * @throws java.lang.Exception
- */
- private JPQLSelectStatementBuilder jpqlSelectStatementBuilder;
-
- @Before
- public void setUp() throws Exception {
-
- }
-
- private JPQLSelectContext createSelectContext(final OrderByExpression orderByExpression,
- final FilterExpression filterExpression) throws ODataJPARuntimeException, EdmException {
- // Object Instantiation
-
- JPQLSelectContext jpqlSelectContextImpl = null;
- GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class);
-
- EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
- EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
- List<SelectItem> selectItemList = null;
-
- // Setting up the expected value
-
- EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet);
- EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression);
- EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(selectItemList);
- EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(filterExpression);
- EasyMock.replay(getEntitySetView);
- EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
- EasyMock.replay(edmEntitySet);
- EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
- EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader");
- EasyMock.replay(edmEntityType);
-
- JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT, getEntitySetView);
- try {
- jpqlSelectContextImpl = (JPQLSelectContext) contextBuilder1.build();
- } catch (ODataJPAModelException e) {
- fail("Model Exception thrown");
- }
-
- return jpqlSelectContextImpl;
- }
-
- /**
- * Test method for {@link org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectStatementBuilder#build)}.
- * @throws EdmException
- * @throws ODataJPARuntimeException
- */
-
- @Test
- public void testBuildSimpleQuery() throws EdmException, ODataJPARuntimeException {
- OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
- JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, null);
- jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl);
-
- assertEquals("SELECT E1 FROM SalesOrderHeader E1", jpqlSelectStatementBuilder.build().toString());
- }
-
- @Test
- public void testBuildQueryWithOrderBy() throws EdmException, ODataJPARuntimeException {
- OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
-
- JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, null);
- HashMap<String, String> orderByCollection = new HashMap<String, String>();
- orderByCollection.put("E1.soID", "ASC");
- orderByCollection.put("E1.buyerId", "DESC");
- jpqlSelectContextImpl.setOrderByCollection(orderByCollection);
- jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl);
-
- assertEquals("SELECT E1 FROM SalesOrderHeader E1 ORDER BY E1.soID ASC , E1.buyerId DESC",
- jpqlSelectStatementBuilder.build().toString());
- }
-
- @Test
- public void testBuildQueryWithFilter() throws EdmException, ODataJPARuntimeException {
- OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
- FilterExpression filterExpression = null;// getFilterExpressionMockedObj();
- JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, filterExpression);
- jpqlSelectContextImpl.setWhereExpression("E1.soID >= 1234");
-
- jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl);
-
- assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.soID >= 1234", jpqlSelectStatementBuilder.build()
- .toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/ODataJPAContextMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/ODataJPAContextMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/ODataJPAContextMock.java
deleted file mode 100644
index 7fc3a6d..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/ODataJPAContextMock.java
+++ /dev/null
@@ -1,57 +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.odata2.processor.core.jpa.mock;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.easymock.EasyMock;
-
-public abstract class ODataJPAContextMock {
-
- public static final String NAMESPACE = "salesorderprocessing";
- public static final String MAPPING_MODEL = "SalesOrderProcessingMappingModel";
- public static final String PERSISTENCE_UNIT_NAME = "salesorderprocessing";
-
- public static ODataJPAContext mockODataJPAContext() {
- ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
- EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn(NAMESPACE);
- EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andReturn(mockEntityManagerFactory());
- EasyMock.expect(odataJPAContext.getJPAEdmMappingModel()).andReturn(MAPPING_MODEL);
- EasyMock.expect(odataJPAContext.getJPAEdmExtension()).andReturn(null);
- EasyMock.expect(odataJPAContext.getDefaultNaming()).andReturn(true);
- EasyMock.replay(odataJPAContext);
- return odataJPAContext;
- }
-
- private static EntityManagerFactory mockEntityManagerFactory() {
- EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
- EasyMock.expect(emf.getMetamodel()).andReturn(mockMetaModel());
- EasyMock.replay(emf);
- return emf;
- }
-
- private static Metamodel mockMetaModel() {
- Metamodel metaModel = EasyMock.createMock(Metamodel.class);
- EasyMock.replay(metaModel);
- return metaModel;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtil.java
deleted file mode 100644
index 57866e3..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtil.java
+++ /dev/null
@@ -1,337 +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.odata2.processor.core.jpa.mock.data;
-
-import static org.junit.Assert.fail;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.easymock.EasyMock;
-
-public class EdmMockUtil {
-
- public static ExpandSelectTreeNode mockExpandSelectTreeNode() {
- ExpandSelectTreeNode nextExpandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
- Map<String, ExpandSelectTreeNode> nextLink = null;
- EasyMock.expect(nextExpandNode.getLinks()).andStubReturn(nextLink);
- EasyMock.replay(nextExpandNode);
- ExpandSelectTreeNode expandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
- Map<String, ExpandSelectTreeNode> links = new HashMap<String, ExpandSelectTreeNode>();
- links.put("SalesOrderLineItemDetails", nextExpandNode);
- EasyMock.expect(expandNode.getLinks()).andStubReturn(links);
- EasyMock.replay(expandNode);
- return expandNode;
- }
-
- public static ExpandSelectTreeNode mockCurrentExpandSelectTreeNode() {
- ExpandSelectTreeNode expandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
- Map<String, ExpandSelectTreeNode> links = new HashMap<String, ExpandSelectTreeNode>();
- EasyMock.expect(expandNode.getLinks()).andStubReturn(links);
- EasyMock.replay(expandNode);
- return expandNode;
- }
-
- public static List<ArrayList<NavigationPropertySegment>> getExpandList() {
- List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
- ArrayList<NavigationPropertySegment> expands = new ArrayList<NavigationPropertySegment>();
- expands.add(mockNavigationPropertySegment());
- expandList.add(expands);
- return expandList;
- }
-
- public static WriteFeedCallbackContext getWriteFeedCallBackContext() {
- URI selfLink = null;
- WriteFeedCallbackContext writeContext = new WriteFeedCallbackContext();
- try {
- selfLink = new URI("SalesOrders(2L)/SalesOrderLineItemDetails");
- writeContext.setSelfLink(selfLink);
- writeContext.setCurrentExpandSelectTreeNode(mockCurrentExpandSelectTreeNode());
- writeContext.setNavigationProperty(mockNavigationProperty());
- writeContext.setSourceEntitySet(mockSourceEntitySet());
- writeContext.setEntryData(getFeedData());
-
- } catch (URISyntaxException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- return writeContext;
- }
-
- public static WriteEntryCallbackContext getWriteEntryCallBackContext() {
- WriteEntryCallbackContext writeContext = new WriteEntryCallbackContext();
- writeContext.setCurrentExpandSelectTreeNode(mockCurrentExpandSelectTreeNode());
- writeContext.setNavigationProperty(mockNavigationProperty());
- writeContext.setSourceEntitySet(mockSourceEntitySet());
- writeContext.setEntryData(getEntryData());
- return writeContext;
- }
-
- private static EdmEntitySet mockSourceEntitySet() {
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockSourceEdmEntityType());
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entitySet);
- return entitySet;
- }
-
- public static EdmEntityType mockSourceEdmEntityType() {
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- List<String> navigationPropertyNames = new ArrayList<String>();
- List<String> propertyNames = new ArrayList<String>();
- propertyNames.add("id");
- propertyNames.add("description");
- navigationPropertyNames.add("SalesOrderLineItemDetails");
- try {
- EasyMock.expect(mapping.getInternalName()).andStubReturn("SalesOrderHeader");
- EasyMock.replay(mapping);
- EasyMock.expect(entityType.getName()).andStubReturn("SalesOrderHeader");
- EasyMock.expect(entityType.getMapping()).andStubReturn(mapping);
- EasyMock.expect(entityType.getNavigationPropertyNames()).andStubReturn(navigationPropertyNames);
- EasyMock.expect(entityType.getProperty("SalesOrderLineItemDetails")).andStubReturn(mockNavigationProperty());
- EdmProperty property1 = mockEdmPropertyOfSource1();
- EasyMock.expect(entityType.getProperty("id")).andStubReturn(property1);
- EasyMock.expect(entityType.getProperty("description")).andStubReturn(mockEdmPropertyOfSource2());
- EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entityType);
- return entityType;
- }
-
- private static EdmTyped mockEdmPropertyOfSource2() {
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmType type = EasyMock.createMock(EdmType.class);
- EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(type);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mapping.getInternalName()).andStubReturn("description");
- EasyMock.replay(mapping);
- try {
- EasyMock.expect(edmProperty.getName()).andStubReturn("description");
- EasyMock.expect(edmProperty.getType()).andStubReturn(type);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(edmProperty);
- return edmProperty;
- }
-
- private static EdmProperty mockEdmPropertyOfSource1() {
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
- EdmType type = EasyMock.createMock(EdmType.class);
- EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(type);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mapping.getInternalName()).andStubReturn("id");
- EasyMock.replay(mapping);
- try {
- EasyMock.expect(edmProperty.getName()).andStubReturn("id");
- EasyMock.expect(edmProperty.getType()).andStubReturn(type);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(edmProperty);
- return edmProperty;
- }
-
- private static Map<String, Object> getFeedData() {
- Map<String, Object> entryData = new HashMap<String, Object>();
- entryData.put("id", 1);
- entryData.put("description", "laptop");
- List<SalesOrderLineItem> salesOrderLineItems = new ArrayList<SalesOrderLineItem>();
- salesOrderLineItems.add(new SalesOrderLineItem(23));
- salesOrderLineItems.add(new SalesOrderLineItem(45));
- entryData.put("SalesOrderLineItemDetails", salesOrderLineItems);
- return entryData;
- }
-
- private static Map<String, Object> getEntryData() {
- Map<String, Object> entryData = new HashMap<String, Object>();
- entryData.put("id", 1);
- entryData.put("description", "laptop");
- entryData.put("SalesOrderLineItemDetails", new SalesOrderLineItem(23));
- return entryData;
- }
-
- private static NavigationPropertySegment mockNavigationPropertySegment() {
- NavigationPropertySegment navigationPropSegment = EasyMock.createMock(NavigationPropertySegment.class);
- EasyMock.expect(navigationPropSegment.getNavigationProperty()).andStubReturn(mockNavigationProperty());
- EasyMock.expect(navigationPropSegment.getTargetEntitySet()).andStubReturn(mockTargetEntitySet());
- EasyMock.replay(navigationPropSegment);
- return navigationPropSegment;
- }
-
- public static NavigationPropertySegment mockThirdNavigationPropertySegment() {
- NavigationPropertySegment navigationPropSegment = EasyMock.createMock(NavigationPropertySegment.class);
- EasyMock.expect(navigationPropSegment.getNavigationProperty()).andStubReturn(mockSecondNavigationProperty());
- EasyMock.expect(navigationPropSegment.getTargetEntitySet()).andStubReturn(mockThirdEntitySet());
- EasyMock.replay(navigationPropSegment);
- return navigationPropSegment;
- }
-
- public static EdmNavigationProperty mockSecondNavigationProperty() {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mapping.getInternalName()).andStubReturn("materials");
- EasyMock.replay(mapping);
- try {
- EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(mapping);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("MaterialDetails");
- EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("SalesOrderLineItem");
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(navigationProperty);
- return navigationProperty;
- }
-
- public static EdmEntitySet mockTargetEntitySet() {
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockTargetEdmEntityType());
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entitySet);
- return entitySet;
- }
-
- public static EdmEntitySet mockThirdEntitySet() {
- EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
- try {
- EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockThirdEdmEntityType());
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entitySet);
- return entitySet;
-
- }
-
- private static EdmEntityType mockThirdEdmEntityType() {
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
-
- List<String> propertyNames = new ArrayList<String>();
- propertyNames.add("price");
- try {
- EasyMock.expect(mapping.getInternalName()).andStubReturn("Material");
- EasyMock.replay(mapping);
- EasyMock.expect(entityType.getName()).andStubReturn("Material");
- EasyMock.expect(entityType.getMapping()).andStubReturn(mapping);
- EdmProperty property = mockEdmPropertyOfTarget();
- EasyMock.expect(entityType.getProperty("price")).andStubReturn(property);
- EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entityType);
- return entityType;
- }
-
- public static EdmEntityType mockTargetEdmEntityType() {
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
-
- List<String> propertyNames = new ArrayList<String>();
- propertyNames.add("price");
- try {
- EasyMock.expect(mapping.getInternalName()).andStubReturn("SalesOrderLineItem");
- EasyMock.replay(mapping);
- EasyMock.expect(entityType.getName()).andStubReturn("SalesOrderLineItem");
- EasyMock.expect(entityType.getMapping()).andStubReturn(mapping);
- EdmProperty property = mockEdmPropertyOfTarget();
- EasyMock.expect(entityType.getProperty("price")).andStubReturn(property);
- EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
-
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(entityType);
- return entityType;
- }
-
- private static EdmProperty mockEdmPropertyOfTarget() {
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
-
- EdmType type = EasyMock.createMock(EdmType.class);
- EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
- EasyMock.replay(type);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mapping.getInternalName()).andStubReturn("price");
- EasyMock.replay(mapping);
- try {
- EasyMock.expect(edmProperty.getName()).andStubReturn("price");
- EasyMock.expect(edmProperty.getType()).andStubReturn(type);
- EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(edmProperty);
- return edmProperty;
- }
-
- public static EdmNavigationProperty mockNavigationProperty() {
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
- EasyMock.expect(mapping.getInternalName()).andStubReturn("salesOrderLineItems");
- EasyMock.replay(mapping);
- try {
- EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.MANY);
- EasyMock.expect(navigationProperty.getMapping()).andStubReturn(mapping);
- EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderLineItemDetails");
- EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("SalesOrderHeader");
- } catch (EdmException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- EasyMock.replay(navigationProperty);
- return navigationProperty;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtilV2.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtilV2.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtilV2.java
deleted file mode 100644
index 6611fb1..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/EdmMockUtilV2.java
+++ /dev/null
@@ -1,324 +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.odata2.processor.core.jpa.mock.data;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociation;
-import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
-import org.apache.olingo.odata2.api.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPARelatedTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPATypeEmbeddableMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.data.JPATypeMock.JPATypeEmbeddableMock2;
-import org.apache.olingo.odata2.processor.core.jpa.model.JPAEdmMappingImpl;
-import org.easymock.EasyMock;
-
-public class EdmMockUtilV2 {
-
- public static interface JPAEdmMappingMock extends JPAEdmMapping, EdmMapping {
-
- }
-
- public static EdmEntityType mockEdmEntityType(final String entityName, final boolean withComplexType)
- throws EdmException {
-
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(entityType.getName()).andReturn(entityName).anyTimes();
- EasyMock.expect(entityType.getKeyPropertyNames()).andReturn(mockSimpleKeyPropertyNames(entityName));
- if (withComplexType == false) {
- EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNames(entityName)).anyTimes();
- } else {
- EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNamesWithComplexType(entityName)).anyTimes();
- }
-
- EasyMock.expect(entityType.getNavigationPropertyNames()).andReturn(mockNavigationPropertyNames(entityName));
- EasyMock.expect(entityType.getKind()).andReturn(EdmTypeKind.ENTITY);
- EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, null, null));
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MINT)).andReturn(
- mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MSTRING)).andReturn(
- mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MSTRING)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MDATETIME)).andReturn(
- mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MDATETIME)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).andReturn(
- mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPATypeMock.NAVIGATION_PROPERTY_X)).andReturn(
- mockEdmNavigationProperty(JPATypeMock.NAVIGATION_PROPERTY_X, EdmMultiplicity.ONE)).anyTimes();
- } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
- EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MLONG)).andReturn(
- mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MLONG)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).andReturn(
- mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).andReturn(
- mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).anyTimes();
- EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).andReturn(
- mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).anyTimes();
- }
- EasyMock.replay(entityType);
- return entityType;
- }
-
- public static List<String> mockNavigationPropertyNames(final String entityName) {
- List<String> propertyNames = new ArrayList<String>();
- propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_X);
- propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_XS);
- return propertyNames;
- }
-
- public static List<String> mockSimpleKeyPropertyNames(final String entityName) {
- List<String> keyPropertyNames = new ArrayList<String>();
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- keyPropertyNames.add(JPATypeMock.PROPERTY_NAME_MINT);
- } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
- keyPropertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
- }
-
- return keyPropertyNames;
- }
-
- public static List<String> mockPropertyNames(final String entityName) {
- List<String> propertyNames = new ArrayList<String>();
-
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- propertyNames.add(JPATypeMock.PROPERTY_NAME_MINT);
- propertyNames.add(JPATypeMock.PROPERTY_NAME_MDATETIME);
- propertyNames.add(JPATypeMock.PROPERTY_NAME_MSTRING);
- } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
- propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
- propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTE);
- propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY);
- propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE);
- } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
- propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT);
- propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE);
- } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
- propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT);
- propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID);
- }
-
- return propertyNames;
- }
-
- public static List<String> mockPropertyNamesWithComplexType(final String entityName) {
- List<String> propertyNames = mockPropertyNames(entityName);
- propertyNames.add(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE);
-
- return propertyNames;
-
- }
-
- public static EdmAssociationEnd mockEdmAssociatioEnd(final String navigationPropertyName, final String role)
- throws EdmException {
- EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
- EasyMock.expect(associationEnd.getMultiplicity()).andReturn(EdmMultiplicity.ONE);
- EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
- EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping("JPARelatedTypeMock", null, null));
- EasyMock.replay(entityType);
-
- EasyMock.expect(associationEnd.getEntityType()).andReturn(entityType);
- EasyMock.replay(associationEnd);
- return associationEnd;
- }
-
- public static EdmAssociation mockEdmAssociation(final String navigationPropertyName) throws EdmException {
- EdmAssociation edmAssociation = EasyMock.createMock(EdmAssociation.class);
- EasyMock.expect(edmAssociation.getEnd("TO")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "TO"));
- EasyMock.expect(edmAssociation.getEnd("FROM")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "FROM"));
- EasyMock.replay(edmAssociation);
- return edmAssociation;
- }
-
- public static EdmEntitySet mockEdmEntitySet(final String entityName, final boolean withComplexType)
- throws EdmException {
- EdmEntitySet entitySet = null;
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- entitySet = EasyMock.createMock(EdmEntitySet.class);
- EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes();
- EasyMock.expect(entitySet.getRelatedEntitySet(EasyMock.isA(EdmNavigationProperty.class))).andReturn(
- mockEdmEntitySet(JPARelatedTypeMock.ENTITY_NAME, false)).anyTimes();
- } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
- entitySet = EasyMock.createMock(EdmEntitySet.class);
- EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes();
- }
-
- EasyMock.replay(entitySet);
- return entitySet;
- }
-
- public static EdmNavigationProperty mockEdmNavigationProperty(final String navigationPropertyName,
- final EdmMultiplicity multiplicity) throws EdmException {
-
- EdmEntityType edmEntityType = mockEdmEntityType(JPARelatedTypeMock.ENTITY_NAME, false);
-
- EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
- EasyMock.expect(navigationProperty.getType()).andReturn(edmEntityType).anyTimes();
- EasyMock.expect(navigationProperty.getMultiplicity()).andReturn(multiplicity);
- EasyMock.expect(navigationProperty.getMapping()).andReturn(
- (EdmMapping) mockEdmMapping(null, null, navigationPropertyName)).anyTimes();
- EasyMock.expect(navigationProperty.getToRole()).andReturn("TO");
- EasyMock.expect(navigationProperty.getRelationship()).andReturn(mockEdmAssociation(navigationPropertyName));
- if (multiplicity.equals(EdmMultiplicity.ONE)) {
- EasyMock.expect(navigationProperty.getName()).andReturn(JPATypeMock.NAVIGATION_PROPERTY_X).anyTimes();
- }
-
- EasyMock.replay(navigationProperty);
-
- return navigationProperty;
- }
-
- public static EdmProperty mockEdmProperty(final String entityName, final String propertyName) throws EdmException {
- EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
-
- if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT) ||
- propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) ||
- propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME) ||
- propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT) ||
- propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT) ||
- propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID) ||
- propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG) ||
- propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE) ||
- propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE) ||
- propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) {
-
- EdmType edmType = EasyMock.createMock(EdmType.class);
- EasyMock.expect(edmProperty.getType()).andReturn(edmType).anyTimes();
- EasyMock.expect(edmType.getKind()).andReturn(EdmTypeKind.SIMPLE).anyTimes();
- EasyMock.replay(edmType);
- EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes();
- EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, propertyName, null))
- .anyTimes();
-
- } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE) ||
- propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) {
- EdmComplexType complexType = mockComplexType(propertyName);
-
- EasyMock.expect(edmProperty.getType()).andReturn(complexType).anyTimes();
- EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes();
- EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(null, propertyName, null))
- .anyTimes();
-
- }
-
- EasyMock.replay(edmProperty);
- return edmProperty;
- }
-
- public static EdmComplexType mockComplexType(final String complexPropertyName) throws EdmException {
-
- String complexTypeName = null;
- if (complexPropertyName.equals(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) {
- complexTypeName = JPATypeEmbeddableMock2.ENTITY_NAME;
- } else if (complexPropertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) {
- complexTypeName = JPATypeEmbeddableMock.ENTITY_NAME;
- }
-
- EdmComplexType edmComplexType = EasyMock.createMock(EdmComplexType.class);
- EasyMock.expect(edmComplexType.getKind()).andReturn(EdmTypeKind.COMPLEX);
- EasyMock.expect(edmComplexType.getPropertyNames()).andReturn(mockPropertyNames(complexTypeName)).anyTimes();
- EasyMock.expect(edmComplexType.getMapping()).andReturn((EdmMapping) mockEdmMapping(complexTypeName, null, null));
-
- if (complexTypeName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
- EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).andReturn(
- mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).anyTimes();
- EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).andReturn(
- mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).anyTimes();
- } else if (complexTypeName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
- EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).andReturn(
- mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).anyTimes();
- EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).andReturn(
- mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).anyTimes();
- }
-
- EasyMock.replay(edmComplexType);
- return edmComplexType;
- }
-
- public static JPAEdmMapping mockEdmMapping(final String entityName, final String propertyName,
- final String navigationPropertyName) {
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
-
- if (propertyName == null && entityName != null) {
- if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
- mapping.setJPAType(JPATypeMock.class);
- } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
- mapping.setJPAType(JPARelatedTypeMock.class);
- } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
- mapping.setJPAType(JPATypeEmbeddableMock.class);
- } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
- mapping.setJPAType(JPATypeEmbeddableMock2.class);
- }
- } else if (entityName == null && navigationPropertyName != null) {
- mapping.setJPAType(JPARelatedTypeMock.class);
- mapping.setJPAColumnName(JPATypeMock.NAVIGATION_PROPERTY_X);
- } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT)) {
- mapping.setJPAType(int.class);
- ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MINT);
- } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING)) {
- mapping.setJPAType(String.class);
- ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MSTRING);
- } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME)) {
- mapping.setJPAType(Calendar.class);
- ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MDATETIME);
- } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG)) {
- mapping.setJPAType(long.class);
- ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
- } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)) {
- mapping.setJPAType(double.class);
- ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE);
- } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)) {
- mapping.setJPAType(byte.class);
- ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTE);
- } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) {
- mapping.setJPAType(byte[].class);
- ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY);
- } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)) {
- mapping.setJPAType(Short.TYPE);
- ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT);
- } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)) {
- mapping.setJPAType(Float.TYPE);
- ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT);
- } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)) {
- mapping.setJPAType(UUID.class);
- ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID);
- } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) {
- mapping.setJPAType(JPATypeEmbeddableMock2.class);
- ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE);
- } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) {
- mapping.setJPAType(JPATypeEmbeddableMock.class);
- ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE);
- }
- return mapping;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/JPATypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/JPATypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/JPATypeMock.java
deleted file mode 100644
index d7bb703..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/mock/data/JPATypeMock.java
+++ /dev/null
@@ -1,205 +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.odata2.processor.core.jpa.mock.data;
-
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.UUID;
-
-/* ========================================================================= */
-public class JPATypeMock {
-
- public static final String ENTITY_NAME = "JPATypeMock";
- public static final String PROPERTY_NAME_MINT = "mInt";
- public static final String PROPERTY_NAME_MSTRING = "mString";
- public static final String PROPERTY_NAME_MDATETIME = "mDateTime";
- public static final String PROPERTY_NAME_MKEY = "key";
- public static final String PROPERTY_NAME_MCOMPLEXTYPE = "complexType";
-
- public static final String NAVIGATION_PROPERTY_X = "mRelatedEntity";
- public static final String NAVIGATION_PROPERTY_XS = "mRelatedEntities";
-
- private JPATypeEmbeddableMock key;
- private JPATypeEmbeddableMock complexType;
- private int mInt;
- private String mString;
- private Calendar mDateTime;
- private JPARelatedTypeMock mRelatedEntity;
- private List<JPARelatedTypeMock> mRelatedEntities = new ArrayList<JPATypeMock.JPARelatedTypeMock>();
-
- public String getMString() {
- return mString;
- }
-
- public void setMString(final String mString) {
- this.mString = mString;
- }
-
- public JPATypeEmbeddableMock getKey() {
- return key;
- }
-
- public void setKey(final JPATypeEmbeddableMock key) {
- this.key = key;
- }
-
- public int getMInt() {
- return mInt;
- }
-
- public void setMInt(final int mInt) {
- this.mInt = mInt;
- }
-
- public Calendar getMDateTime() {
- return mDateTime;
- }
-
- public void setMDateTime(final Calendar mDateTime) {
- this.mDateTime = mDateTime;
- }
-
- public JPARelatedTypeMock getMRelatedEntity() {
- return mRelatedEntity;
- }
-
- public void setMRelatedEntity(final JPARelatedTypeMock mRelatedEntity) {
- this.mRelatedEntity = mRelatedEntity;
- }
-
- public List<JPARelatedTypeMock> getMRelatedEntities() {
- return mRelatedEntities;
- }
-
- public void setMRelatedEntities(final List<JPARelatedTypeMock> mRelatedEntities) {
- this.mRelatedEntities = mRelatedEntities;
- }
-
- public JPATypeEmbeddableMock getComplexType() {
- return complexType;
- }
-
- public void setComplexType(final JPATypeEmbeddableMock complexType) {
- this.complexType = complexType;
- }
-
- /* ========================================================================= */
- public static class JPATypeEmbeddableMock {
-
- public static final String ENTITY_NAME = "JPATypeEmbeddableMock";
- public static final String PROPERTY_NAME_MSHORT = "mShort";
- public static final String PROPERTY_NAME_MEMBEDDABLE = "mEmbeddable";
-
- private short mShort;
- private JPATypeEmbeddableMock2 mEmbeddable;
-
- public short getMShort() {
- return mShort;
- }
-
- public void setMShort(final short mShort) {
- this.mShort = mShort;
- }
-
- public JPATypeEmbeddableMock2 getMEmbeddable() {
- return mEmbeddable;
- }
-
- public void setMEmbeddable(final JPATypeEmbeddableMock2 mEmbeddable) {
- this.mEmbeddable = mEmbeddable;
- }
-
- }
-
- /* ========================================================================= */
- public static class JPATypeEmbeddableMock2 {
-
- public static final String ENTITY_NAME = "JPATypeEmbeddableMock2";
- public static final String PROPERTY_NAME_MUUID = "mUUID";
- public static final String PROPERTY_NAME_MFLOAT = "mFloat";
-
- private UUID mUUID;
- private float mFloat;
-
- public UUID getMUUID() {
- return mUUID;
- }
-
- public void setMUUID(final UUID mUUID) {
- this.mUUID = mUUID;
- }
-
- public float getMFloat() {
- return mFloat;
- }
-
- public void setMFloat(final float mFloat) {
- this.mFloat = mFloat;
- }
-
- }
-
- /* ========================================================================= */
- public static final class JPARelatedTypeMock {
- public static final String ENTITY_NAME = "JPARelatedTypeMock";
- public static final String PROPERTY_NAME_MLONG = "mLong";
- public static final String PROPERTY_NAME_MDOUBLE = "mDouble";
- public static final String PROPERTY_NAME_MBYTE = "mByte";
- public static final String PROPERTY_NAME_MBYTEARRAY = "mByteArray";
-
- private long mLong;
- private double mDouble;
- private byte mByte;
- private byte mByteArray[];
-
- public long getMLong() {
- return mLong;
- }
-
- public void setMLong(final long key) {
- mLong = key;
- }
-
- public double getMDouble() {
- return mDouble;
- }
-
- public void setMDouble(final double mDouble) {
- this.mDouble = mDouble;
- }
-
- public byte getMByte() {
- return mByte;
- }
-
- public void setMByte(final byte mByte) {
- this.mByte = mByte;
- }
-
- public byte[] getMByteArray() {
- return mByteArray;
- }
-
- public void setMByteArray(final byte mByteArray[]) {
- this.mByteArray = mByteArray;
- }
-
- }
-}
[25/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties b/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
index 5eb96fb..db8d857 100644
--- a/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
+++ b/odata2-jpa-processor/jpa-core/src/main/resources/jpaprocessor_msg.properties
@@ -20,42 +20,42 @@
#
#JPA EDM Provider Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.GENERAL="OData - JPA Metadata: Internal error [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INNER_EXCEPTION="%1$s: %2$s.\n"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ENTITY_TYPE="OData - JPA Model Processor: Invalid Entity Type [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_COMPLEX_TYPE="OData - JPA Model Processor: Invalid Complex Type [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ASSOCIATION ="OData - JPA Model Processor: Invalid Association [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ENTITYSET="OData - JPA Model Processor: Invalid Entity set [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_ENTITYCONTAINER="OData - JPA Model Processor: Invalid Entity Container [%1$s]"
-org.apache.olingo.odata2.processor.jap.exception.ODataJPAModelException.INVALID_ASSOCIATION_SET="OData - JPA Model Processor: Invalid Association Set [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.INVALID_FUNC_IMPORT="OData - JPA Model Processor: Invalid Function Import [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.BUILDER_NULL="OData - JPA Model Processor: JPA Builder not initialized"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_ENTITYSET_EXP="OData - JPA Model Processor: Entity Set expected for Function Import with return type as Entity Type with Multiplicity Many"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_RETURN_TYPE_EXP="OData - JPA Model Processor: Return type expected. Class: [%1$s], Method: [%2$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND="OData - JPA Model Processor: Return type not found. Class: [%1$s], Method: [%2$s], Type: [%3$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.FUNC_PARAM_NAME_EXP="OData - JPA Model Processor: Parameter Name for function import expected. Class: [%1$s]", Method: [%2$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.GENERAL="OData - JPA Metadata: Internal error [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INNER_EXCEPTION="%1$s: %2$s.\n"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ENTITY_TYPE="OData - JPA Model Processor: Invalid Entity Type [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_COMPLEX_TYPE="OData - JPA Model Processor: Invalid Complex Type [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ASSOCIATION ="OData - JPA Model Processor: Invalid Association [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ENTITYSET="OData - JPA Model Processor: Invalid Entity set [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ENTITYCONTAINER="OData - JPA Model Processor: Invalid Entity Container [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_ASSOCIATION_SET="OData - JPA Model Processor: Invalid Association Set [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.INVALID_FUNC_IMPORT="OData - JPA Model Processor: Invalid Function Import [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.BUILDER_NULL="OData - JPA Model Processor: JPA Builder not initialized"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_ENTITYSET_EXP="OData - JPA Model Processor: Entity Set expected for Function Import with return type as Entity Type with Multiplicity Many"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_RETURN_TYPE_EXP="OData - JPA Model Processor: Return type expected. Class: [%1$s], Method: [%2$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND="OData - JPA Model Processor: Return type not found. Class: [%1$s], Method: [%2$s], Type: [%3$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.FUNC_PARAM_NAME_EXP="OData - JPA Model Processor: Parameter Name for function import expected. Class: [%1$s]", Method: [%2$s]"
#JPA Type converter Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException.TYPE_NOT_SUPPORTED="OData - JPA Type Converter: Type [%1$s] not supported"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException.TYPE_NOT_SUPPORTED="OData - JPA Type Converter: Type [%1$s] not supported"
#JPA Runtime Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED="OData - JPA Service Factory: Java Persistence Entity Manager not initialized"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.GENERAL="OData - JPA Runtime: Internal error [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.INNER_EXCEPTION="%1$s: %2$s.\n"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED="OData - JPA Runtime: Join Clause expected"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.RESOURCE_NOT_FOUND="OData - JPA Runtime: Resource not found"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_ODATA_FILTER_CONDITION="OData - JPA Runtime: Filter condition not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE="OData - JPA Runtime: JPA query syntax is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST="OData - JPA Runtime: JPA create request is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST="OData - JPA Runtime: JPA update request is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST="OData - JPA Runtime: JPA delete URL is not correct"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_KEY_VALUE="Key parameter value is not correct for [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_PARAM_VALUE="Parameter value is not correct for [%1$s]"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_UNIQUE_CONSTRAINT="Violation of unique constraint"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQL_INTEGRITY_CONSTRAINT="Integrity constraint violation"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.RELATIONSHIP_INVALID="OData - JPA Runtime: Invalid link"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.RESOURCE_X_NOT_FOUND="OData - JPA Runtime: Resource [%1$s] not found"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED="OData - JPA Service Factory: Java Persistence Entity Manager not initialized"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.GENERAL="OData - JPA Runtime: Internal error [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.INNER_EXCEPTION="%1$s: %2$s.\n"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED="OData - JPA Runtime: Join Clause expected"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.RESOURCE_NOT_FOUND="OData - JPA Runtime: Resource not found"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_ODATA_FILTER_CONDITION="OData - JPA Runtime: Filter condition not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE="OData - JPA Runtime: JPA query syntax is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST="OData - JPA Runtime: JPA create request is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST="OData - JPA Runtime: JPA update request is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST="OData - JPA Runtime: JPA delete URL is not correct"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_KEY_VALUE="Key parameter value is not correct for [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_PARAM_VALUE="Parameter value is not correct for [%1$s]"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_UNIQUE_CONSTRAINT="Violation of unique constraint"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQL_INTEGRITY_CONSTRAINT="Integrity constraint violation"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.RELATIONSHIP_INVALID="OData - JPA Runtime: Invalid link"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.RESOURCE_X_NOT_FOUND="OData - JPA Runtime: Resource [%1$s] not found"
#JPA Common Errors
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException.ODATA_JPACTX_NULL="OData JPA: OData JPA Context cannot be null"
-org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE="OData JPA: Error creating JPQL Context Builder"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException.ODATA_JPACTX_NULL="OData JPA: OData JPA Context cannot be null"
+org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE="OData JPA: Error creating JPQL Context Builder"
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
new file mode 100644
index 0000000..c0d364c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataExpressionParserTest.java
@@ -0,0 +1,516 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.BinaryOperator;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
+import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodOperator;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.UnaryOperator;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.ODataExpressionParser;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class ODataExpressionParserTest {
+
+ private static final String EXPECTED_STR_1 = "gwt1.SalesOrder = 1234";
+ private static final String EXPECTED_STR_2 = "gwt1.SalesOrder >= 1234 AND gwt1.SalesABC <> XYZ";
+ private static final String EXPECTED_STR_3 = "gwt1.SalesOrder >= 1234 OR gwt1.SalesABC <> XYZ";
+ private static final String EXPECTED_STR_4 = "gwt1.SalesOrder < 1234 AND gwt1.SalesABC <= XYZ";
+ private static final String EXPECTED_STR_5 = "gwt1.LineItems > 2345 AND gwt1.SalesOrder >= Amazon";
+ private static final String EXPECTED_STR_6 = "gwt1.Address.city = \'City_3\'";
+ private static final String EXPECTED_STR_7 = "gwt1.Address.city.area = \'BTM\'";
+ private static final String EXPECTED_STR_8 = "gwt1.field1 = 1 AND gwt1.field2 = 'abc'";
+ private static final String EXPECTED_STR_9 = "gwt1.BuyerAddress, gwt1.BuyerName, gwt1.BuyerId";
+ private static final String EXPECTED_STR_10 = "gwt1.SalesOrder";
+ private static final String EXPECTED_STR_11 = "NOT(gwt1.deliveryStatus)";
+ private static final String EXPECTED_STR_12 =
+ "(CASE WHEN (gwt1.currencyCode LIKE '%Ru%') THEN TRUE ELSE FALSE END) = true";
+ private static final String EXPECTED_STR_13 = "SUBSTRING(gwt1.currencyCode, 1 + 1 , 2) = 'NR'";
+ private static final String EXPECTED_STR_14 = "LOWER(gwt1.currencyCode) = 'inr rupees'";
+ private static final String EXPECTED_STR_15 =
+ "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END) = true";
+ private static final String EXPECTED_STR_16 =
+ "(CASE WHEN (gwt1.currencyCode LIKE '%INR%') THEN TRUE ELSE FALSE END) = true";
+ private static final String EXPECTED_STR_17 =
+ "(CASE WHEN (LOWER(gwt1.currencyCode) LIKE '%nr rupees%') THEN TRUE ELSE FALSE END) = true";
+
+ private static final String ADDRESS = "Address";
+ private static final String CITY = "city";
+ private static final String AREA = "area";
+ private static final String SALES_ORDER = "SalesOrder";
+ private static final String SALES_ABC = "SalesABC";
+ private static final String SAMPLE_DATA_1 = "1234";
+ private static final String SAMPLE_DATA_2 = "2345";
+ private static final String SAMPLE_DATA_XYZ = "XYZ";
+ private static final String SAMPLE_DATA_BTM = "\'BTM\'";
+ private static final String SAMPLE_DATA_CITY_3 = "\'City_3\'";
+ private static final String SAMPLE_DATA_LINE_ITEMS = "LineItems";
+ private static final String SAMPLE_DATA_AMAZON = "Amazon";
+ private static final String SAMPLE_DATA_FIELD1 = "field1";
+ private static final String SAMPLE_DATA_FIELD2 = "field2";
+
+ private static final String TABLE_ALIAS = "gwt1"; //$NON-NLS-1$
+
+ @Test
+ public void testParseWhereExpression() {
+ try {
+ String parsedStr = ODataJPATestConstants.EMPTY_STRING;
+ // Simple Binary query -
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpressionMockedObj(BinaryOperator.EQ,
+ ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1), TABLE_ALIAS);
+
+ assertEquals(EXPECTED_STR_1, parsedStr);
+ // complex query -
+ parsedStr = ODataJPATestConstants.EMPTY_STRING;
+
+ CommonExpression exp1 =
+ getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
+ CommonExpression exp2 =
+ getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.AND, exp2),
+ TABLE_ALIAS);
+ assertEquals(EXPECTED_STR_2, parsedStr);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testMoreThanOneBinaryExpression() {
+ // complex query -
+ String parsedStr = ODataJPATestConstants.EMPTY_STRING;
+ CommonExpression exp1 =
+ getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
+ CommonExpression exp2 =
+ getBinaryExpressionMockedObj(BinaryOperator.NE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
+ try {
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.AND, exp2),
+ TABLE_ALIAS);
+ assertEquals(EXPECTED_STR_2, parsedStr);
+ parsedStr =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp1, BinaryOperator.OR, exp2),
+ TABLE_ALIAS);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(EXPECTED_STR_3, parsedStr);
+ }
+
+ @Test
+ public void testParseFilterExpression() {
+ try {
+ assertEquals(EXPECTED_STR_10, ODataExpressionParser.parseToJPAWhereExpression(getFilterExpressionMockedObj(
+ ExpressionKind.PROPERTY, SALES_ORDER), TABLE_ALIAS));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testAllBinaryOperators() { // Test for all Binary Operators
+ // complex query -
+ String parsedStr1 = ODataJPATestConstants.EMPTY_STRING;
+ String parsedStr2 = ODataJPATestConstants.EMPTY_STRING;
+
+ CommonExpression exp1 =
+ getBinaryExpressionMockedObj(BinaryOperator.LT, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_1);
+ CommonExpression exp2 =
+ getBinaryExpressionMockedObj(BinaryOperator.LE, ExpressionKind.PROPERTY, SALES_ABC, SAMPLE_DATA_XYZ);
+
+ try {
+ parsedStr1 =
+ ODataExpressionParser.parseToJPAWhereExpression((BinaryExpression) getBinaryExpression(exp1,
+ BinaryOperator.AND, exp2), TABLE_ALIAS);
+ assertEquals(EXPECTED_STR_4, parsedStr1);
+
+ CommonExpression exp3 =
+ getBinaryExpressionMockedObj(BinaryOperator.GT, ExpressionKind.PROPERTY, SAMPLE_DATA_LINE_ITEMS,
+ SAMPLE_DATA_2);
+ CommonExpression exp4 =
+ getBinaryExpressionMockedObj(BinaryOperator.GE, ExpressionKind.PROPERTY, SALES_ORDER, SAMPLE_DATA_AMAZON);
+
+ parsedStr2 =
+ ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(exp3, BinaryOperator.AND, exp4),
+ TABLE_ALIAS);
+
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(EXPECTED_STR_5, parsedStr2);
+ }
+
+ @Test
+ public void testParseMemberExpression() {
+ try {
+ assertEquals(EXPECTED_STR_6, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMemberExpressionMockedObj(ADDRESS, CITY), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3)), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_7, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMultipleMemberExpressionMockedObj(ADDRESS, CITY, AREA), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj(SAMPLE_DATA_BTM)), TABLE_ALIAS));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testParseMethodExpression() {
+ try {
+ assertEquals(EXPECTED_STR_12, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'Ru'", "currencyCode", null, 2), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj("true")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_13, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMethodExpressionMockedObj(MethodOperator.SUBSTRING, "currencyCode", "1", "2", 3), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj("'NR'")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_14, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMethodExpressionMockedObj(MethodOperator.TOLOWER, "currencyCode", null, null, 1), BinaryOperator.EQ,
+ getLiteralExpressionMockedObj("'inr rupees'")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_15, ODataExpressionParser.parseToJPAWhereExpression(getBinaryExpression(
+ getMultipleMethodExpressionMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER,
+ "currencyCode", 2, 1), BinaryOperator.EQ, getLiteralExpressionMockedObj("true")), TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_16, ODataExpressionParser.parseToJPAWhereExpression(
+ getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'INR'", null, "currencyCode", 2, null)
+ /*
+ * getBinaryExpression(
+ * getMemberExpressionMockedObj(ADDRESS,
+ * CITY),
+ * BinaryOperator.EQ,
+ * getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3))
+ */, TABLE_ALIAS));
+ assertEquals(EXPECTED_STR_17, ODataExpressionParser.parseToJPAWhereExpression(
+ getFilterExpressionForFunctionsMockedObj(MethodOperator.SUBSTRINGOF, "'nr rupees'", MethodOperator.TOLOWER,
+ "currencyCode", 2, 1)
+ /*
+ * getBinaryExpression(
+ * getMemberExpressionMockedObj(ADDRESS,
+ * CITY),
+ * BinaryOperator.EQ,
+ * getLiteralExpressionMockedObj(SAMPLE_DATA_CITY_3))
+ */, TABLE_ALIAS));
+
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ private CommonExpression getMethodExpressionMockedObj(final MethodOperator methodOperator, final String firstName,
+ final String secondName, final String thirdName, final Integer parameterCount) {
+
+ List<CommonExpression> parameters = new ArrayList<CommonExpression>();
+
+ if (methodOperator == MethodOperator.SUBSTRINGOF) {
+ parameters.add(getLiteralExpressionMockedObj(firstName));
+ parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, secondName));
+ } else if (methodOperator == MethodOperator.SUBSTRING) {
+ parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, firstName));
+ parameters.add(getLiteralExpressionMockedObj(secondName));
+ parameters.add(getLiteralExpressionMockedObj(thirdName));
+ } else if (methodOperator == MethodOperator.TOLOWER) {
+ parameters.add(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, firstName));
+ }
+
+ MethodExpression methodExpression = EasyMock.createMock(MethodExpression.class);
+
+ EasyMock.expect(methodExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
+ EasyMock.expect(methodExpression.getMethod()).andStubReturn(methodOperator);
+ EasyMock.expect(methodExpression.getParameterCount()).andStubReturn(parameterCount);
+ EasyMock.expect(methodExpression.getParameters()).andStubReturn(parameters);
+ EasyMock.replay(methodExpression);
+
+ return methodExpression;
+ }
+
+ private CommonExpression getMultipleMethodExpressionMockedObj(final MethodOperator methodOperator1,
+ final String firstName, final MethodOperator methodOperator2, final String secondName,
+ final Integer parameterCount1, final Integer parameterCount2) {
+
+ // complex query
+ List<CommonExpression> parameters = new ArrayList<CommonExpression>();
+
+ parameters.add(getLiteralExpressionMockedObj(firstName));
+ parameters.add(getMethodExpressionMockedObj(methodOperator2, secondName, null, null, 1));
+
+ MethodExpression methodExpression = EasyMock.createMock(MethodExpression.class);
+
+ EasyMock.expect(methodExpression.getKind()).andStubReturn(ExpressionKind.METHOD);
+ EasyMock.expect(methodExpression.getMethod()).andStubReturn(methodOperator1);
+ EasyMock.expect(methodExpression.getParameterCount()).andStubReturn(parameterCount1);
+ EasyMock.expect(methodExpression.getParameters()).andStubReturn(parameters);
+ EasyMock.replay(methodExpression);
+
+ return methodExpression;
+ }
+
+ private CommonExpression getMultipleMemberExpressionMockedObj(final String string1, final String string2,
+ final String string3) {
+
+ MemberExpression memberExpression = EasyMock.createMock(MemberExpression.class);
+
+ EasyMock.expect(memberExpression.getPath()).andStubReturn(getMemberExpressionMockedObj(string1, string2));
+ EasyMock.expect(memberExpression.getProperty()).andStubReturn(
+ getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, string3));
+ EasyMock.expect(memberExpression.getKind()).andStubReturn(ExpressionKind.MEMBER);
+ EasyMock.replay(memberExpression);
+
+ return memberExpression;
+ }
+
+ @Test
+ public void testParseUnaryExpression() {
+
+ UnaryExpression unaryExpression =
+ getUnaryExpressionMockedObj(getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, "deliveryStatus"),
+ org.apache.olingo.odata2.api.uri.expression.UnaryOperator.NOT);
+ try {
+ assertEquals(EXPECTED_STR_11, ODataExpressionParser.parseToJPAWhereExpression(unaryExpression, TABLE_ALIAS));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ private UnaryExpression
+ getUnaryExpressionMockedObj(final CommonExpression operand, final UnaryOperator unaryOperator) {
+ UnaryExpression unaryExpression = EasyMock.createMock(UnaryExpression.class);
+ EasyMock.expect(unaryExpression.getKind()).andStubReturn(ExpressionKind.UNARY);
+ EasyMock.expect(unaryExpression.getOperand()).andStubReturn(operand);
+ EasyMock.expect(unaryExpression.getOperator()).andStubReturn(unaryOperator);
+
+ EasyMock.replay(unaryExpression);
+ return unaryExpression;
+ }
+
+ private CommonExpression getMemberExpressionMockedObj(final String pathUriLiteral, final String propertyUriLiteral) {
+ MemberExpression memberExpression = EasyMock.createMock(MemberExpression.class);
+ EasyMock.expect(memberExpression.getPath()).andStubReturn(
+ getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, pathUriLiteral));
+ EasyMock.expect(memberExpression.getProperty()).andStubReturn(
+ getPropertyExpressionMockedObj(ExpressionKind.PROPERTY, propertyUriLiteral));
+ EasyMock.expect(memberExpression.getKind()).andStubReturn(ExpressionKind.MEMBER);
+
+ EasyMock.replay(memberExpression);
+ return memberExpression;
+ }
+
+ private LiteralExpression getLiteralExpressionMockedObj(final String uriLiteral) {
+ LiteralExpression rightOperandLiteralExpresion = EasyMock.createMock(LiteralExpression.class);
+ EasyMock.expect(rightOperandLiteralExpresion.getKind()).andStubReturn(ExpressionKind.LITERAL);
+ EasyMock.expect(rightOperandLiteralExpresion.getUriLiteral()).andStubReturn(uriLiteral);// SAMPLE_DATA
+ EasyMock.expect(rightOperandLiteralExpresion.getEdmType()).andStubReturn(getEdmSimpleTypeMockedObj(uriLiteral));
+ EasyMock.replay(rightOperandLiteralExpresion);
+ return rightOperandLiteralExpresion;
+
+ }
+
+ private EdmSimpleType getEdmSimpleTypeMockedObj(final String value) {
+ EdmSimpleType edmSimpleType = EasyMock.createMock(EdmSimpleType.class);
+ try {
+ EasyMock.expect(edmSimpleType.getName()).andReturn(value);
+ EasyMock.expect(edmSimpleType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmSimpleType.valueOfString(value, EdmLiteralKind.URI, getEdmFacetsMockedObj(), null))
+ .andStubReturn(value);
+ EasyMock.expect(edmSimpleType.valueOfString(value, EdmLiteralKind.URI, null, null)).andStubReturn(value);
+ EasyMock.expect(edmSimpleType.valueToString(value, EdmLiteralKind.DEFAULT, getEdmFacetsMockedObj()))
+ .andStubReturn(value);
+ EasyMock.expect(edmSimpleType.valueToString(value, EdmLiteralKind.DEFAULT, null)).andStubReturn(value);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.expect(edmSimpleType.getDefaultType()).andStubReturn(null);
+ EasyMock.replay(edmSimpleType);
+ return edmSimpleType;
+ }
+
+ private EdmFacets getEdmFacetsMockedObj() {
+ EdmFacets facets = EasyMock.createMock(EdmFacets.class);
+
+ EasyMock.replay(facets);
+ return facets;
+ }
+
+ private PropertyExpression getPropertyExpressionMockedObj(final ExpressionKind expKind, final String propertyName) {
+ PropertyExpression leftOperandPropertyExpresion = EasyMock.createMock(PropertyExpression.class);
+ EasyMock.expect(leftOperandPropertyExpresion.getKind()).andStubReturn(ExpressionKind.PROPERTY);
+ EasyMock.expect(leftOperandPropertyExpresion.getPropertyName()).andStubReturn(propertyName);
+ EasyMock.expect(leftOperandPropertyExpresion.getEdmProperty()).andStubReturn(getEdmTypedMockedObj(propertyName));
+ EasyMock.replay(leftOperandPropertyExpresion);
+ return leftOperandPropertyExpresion;
+ }
+
+ private EdmTyped getEdmTypedMockedObj(final String propertyName) {
+ EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
+ try {
+ EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
+ EasyMock.replay(mockedEdmProperty);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return mockedEdmProperty;
+ }
+
+ private EdmMapping getEdmMappingMockedObj(final String propertyName) {
+ EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
+ EasyMock.replay(mockedEdmMapping);
+ return mockedEdmMapping;
+ }
+
+ private BinaryExpression getBinaryExpressionMockedObj(final BinaryOperator operator,
+ final ExpressionKind leftOperandExpKind, final String propertyName, final String literalStr) {
+ BinaryExpression binaryExpression = EasyMock.createMock(BinaryExpression.class);
+ EasyMock.expect(binaryExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
+ EasyMock.expect(binaryExpression.getLeftOperand()).andStubReturn(
+ getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
+ EasyMock.expect(binaryExpression.getOperator()).andStubReturn(operator);
+ EasyMock.expect(binaryExpression.getRightOperand()).andStubReturn(getLiteralExpressionMockedObj(literalStr));
+
+ EasyMock.replay(binaryExpression);
+ return binaryExpression;
+ }
+
+ private FilterExpression getFilterExpressionMockedObj(final ExpressionKind leftOperandExpKind,
+ final String propertyName) {
+ FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
+ EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
+
+ EasyMock.replay(filterExpression);
+ return filterExpression;
+ }
+
+ private FilterExpression getFilterExpressionForFunctionsMockedObj(final MethodOperator methodOperator1,
+ final String firstName, final MethodOperator methodOperator2, final String secondName,
+ final Integer parameterCount1, final Integer parameterCount2) {
+ // default value handling of SUBSTRINGOF
+ FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
+ EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
+ if ((methodOperator2 != null) && (parameterCount2 != null)) {
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getMultipleMethodExpressionMockedObj(methodOperator1, firstName, methodOperator2, secondName,
+ parameterCount1, parameterCount2));
+ } else {
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getMethodExpressionMockedObj(methodOperator1, firstName, secondName, null, parameterCount1));
+ }
+
+ EasyMock.replay(filterExpression);
+ return filterExpression;
+ }
+
+ private CommonExpression getBinaryExpression(final CommonExpression leftOperand, final BinaryOperator operator,
+ final CommonExpression rightOperand) {
+ BinaryExpression binaryExpression = EasyMock.createMock(BinaryExpression.class);
+ EasyMock.expect(binaryExpression.getKind()).andStubReturn(ExpressionKind.BINARY);
+ EasyMock.expect(binaryExpression.getLeftOperand()).andStubReturn(leftOperand);
+ EasyMock.expect(binaryExpression.getRightOperand()).andStubReturn(rightOperand);
+ EasyMock.expect(binaryExpression.getOperator()).andStubReturn(operator);
+
+ EasyMock.replay(binaryExpression);
+ return binaryExpression;
+ }
+
+ @Test
+ public void testParseKeyPredicates() {
+ // Setting up the expected value
+ KeyPredicate keyPredicate1 = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty1 = EasyMock.createMock(EdmProperty.class);
+ EasyMock.expect(keyPredicate1.getLiteral()).andStubReturn("1");
+ KeyPredicate keyPredicate2 = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty2 = EasyMock.createMock(EdmProperty.class);
+ EasyMock.expect(keyPredicate2.getLiteral()).andStubReturn("abc");
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ try {
+ EasyMock.expect(kpProperty1.getName()).andStubReturn(SAMPLE_DATA_FIELD1);
+ EasyMock.expect(kpProperty1.getType()).andStubReturn(EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance());
+ EasyMock.expect(kpProperty2.getName()).andStubReturn(SAMPLE_DATA_FIELD2);
+ EasyMock.expect(kpProperty2.getType()).andStubReturn(EdmSimpleTypeKind.String.getEdmSimpleTypeInstance());
+ EasyMock.expect(keyPredicate1.getProperty()).andStubReturn(kpProperty1);
+ EasyMock.expect(kpProperty1.getMapping()).andReturn(edmMapping);
+ EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD1);
+ EasyMock.expect(keyPredicate2.getProperty()).andStubReturn(kpProperty2);
+ EasyMock.expect(kpProperty2.getMapping()).andReturn(edmMapping);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.expect(edmMapping.getInternalName()).andReturn(SAMPLE_DATA_FIELD2);
+ EasyMock.replay(edmMapping);
+ EasyMock.replay(kpProperty1, keyPredicate1, kpProperty2, keyPredicate2);
+
+ ArrayList<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ keyPredicates.add(keyPredicate1);
+ keyPredicates.add(keyPredicate2);
+ String str = null;
+
+ try {
+ str = ODataExpressionParser.parseKeyPredicates(keyPredicates, TABLE_ALIAS);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertEquals(EXPECTED_STR_8, str);
+ }
+
+ @Test
+ public void testParseToJPASelectExpression() {
+
+ ArrayList<String> selectedFields = new ArrayList<String>();
+ selectedFields.add("BuyerAddress");
+ selectedFields.add("BuyerName");
+ selectedFields.add("BuyerId");
+
+ assertEquals(EXPECTED_STR_9, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields));
+ assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, null));
+
+ selectedFields.clear();
+ assertEquals(TABLE_ALIAS, ODataExpressionParser.parseToJPASelectExpression(TABLE_ALIAS, selectedFields));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java
new file mode 100644
index 0000000..fe981fc
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAContextImplTest.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+import org.apache.olingo.odata2.jpa.processor.core.edm.ODataJPAEdmProvider;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ODataJPAContextImplTest {
+
+ private ODataContext odataContext = null;
+ private ODataJPAContext odataJPAContext = null;
+ private EdmProvider edmProvider = null;
+ private EntityManagerFactory emf = null;
+ private EntityManager em = null;
+ private ODataProcessor processor = null;
+
+ @Before
+ public void setup() {
+
+ edmProvider = new ODataJPAEdmProvider();
+ emf = EasyMock.createMock(EntityManagerFactory.class);
+ em = EasyMock.createMock(EntityManager.class);
+ EasyMock.replay(em);
+
+ EasyMock.expect(emf.createEntityManager()).andStubReturn(em);
+ EasyMock.replay(emf);
+
+ odataContext = EasyMock.createMock(ODataContext.class);
+ List<Locale> listLocale = new ArrayList<Locale>();
+ listLocale.add(Locale.ENGLISH);
+ listLocale.add(Locale.GERMAN);
+
+ EasyMock.expect(odataContext.getAcceptableLanguages()).andStubReturn(listLocale);
+ EasyMock.replay(odataContext);
+
+ processor = EasyMock.createMock(ODataProcessor.class);
+ EasyMock.replay(processor);
+
+ odataJPAContext = new ODataJPAContextImpl();
+ odataJPAContext.setEdmProvider(edmProvider);
+ odataJPAContext.setEntityManagerFactory(emf);
+ odataJPAContext.setODataContext(odataContext);
+ odataJPAContext.setODataProcessor(processor);
+ odataJPAContext.setPersistenceUnitName(ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
+ odataJPAContext.setJPAEdmMappingModel(ODataJPAContextMock.MAPPING_MODEL);
+ }
+
+ @Test
+ public void testgetMethodsOfODataJPAContext() {
+
+ assertEquals(odataJPAContext.getEdmProvider().hashCode(), edmProvider.hashCode());
+ assertEquals(odataJPAContext.getEntityManagerFactory().hashCode(), emf.hashCode());
+ assertEquals(odataJPAContext.getODataContext().hashCode(), odataContext.hashCode());
+ assertEquals(odataJPAContext.getODataProcessor().hashCode(), processor.hashCode());
+ assertEquals(odataJPAContext.getPersistenceUnitName(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME);
+ assertEquals(odataJPAContext.getJPAEdmMappingModel(), ODataJPAContextMock.MAPPING_MODEL);
+
+ EntityManager em1 = odataJPAContext.getEntityManager();
+ EntityManager em2 = odataJPAContext.getEntityManager();
+ if (em1 != null && em2 != null) {
+ assertEquals(em1.hashCode(), em2.hashCode());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
new file mode 100644
index 0000000..ced012e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/ODataJPAProcessorDefaultTest.java
@@ -0,0 +1,555 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.Query;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAProcessorDefault;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmTestModelView;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ODataJPAProcessorDefaultTest extends JPAEdmTestModelView {
+
+ ODataJPAProcessorDefault objODataJPAProcessorDefault;
+ ODataJPAProcessorDefaultTest objODataJPAProcessorDefaultTest;
+
+ private static final String STR_LOCAL_URI = "http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/";
+ private static final String SALESORDERPROCESSING_CONTAINER = "salesorderprocessingContainer";
+ private static final String SO_ID = "SoId";
+ private static final String SALES_ORDER = "SalesOrder";
+ private static final String SALES_ORDER_HEADERS = "SalesOrderHeaders";
+ private static final String STR_CONTENT_TYPE = "Content-Type";
+
+ @Before
+ public void setUp() {
+ objODataJPAProcessorDefaultTest = new ODataJPAProcessorDefaultTest();
+ objODataJPAProcessorDefault = new ODataJPAProcessorDefault(getLocalmockODataJPAContext());
+ }
+
+ @Test
+ public void testReadEntitySetGetEntitySetUriInfoString() {
+ try {
+ GetEntityUriInfo getEntityView = getEntityUriInfo();
+ Assert.assertNotNull(objODataJPAProcessorDefault.readEntity(getEntityView, HttpContentType.APPLICATION_XML));
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e1) {// Expected
+ assertTrue(true);
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testcountEntitySet() {
+ try {
+ ODataResponse countEntitySet =
+ objODataJPAProcessorDefault.countEntitySet(getEntitySetCountUriInfo(), HttpContentType.APPLICATION_XML);
+ Assert.assertNotNull(countEntitySet);
+ Object entity = countEntitySet.getEntity();
+ Assert.assertNotNull(entity);
+
+ byte[] b = new byte[2];
+ ((ByteArrayInputStream) entity).read(b);
+ Assert.assertEquals("11", new String(b, Charset.forName("utf-8")));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testExistsEntity() {
+ try {
+ Assert.assertNotNull(objODataJPAProcessorDefault.existsEntity(getEntityCountCountUriInfo(),
+ HttpContentType.APPLICATION_XML));
+ Assert.assertNull("ContentType MUST NOT set by entity provider", objODataJPAProcessorDefault.existsEntity(
+ getEntityCountCountUriInfo(), HttpContentType.APPLICATION_XML).getHeader(STR_CONTENT_TYPE));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (Exception e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testDeleteEntity() {
+ try {
+ Assert.assertNotNull(objODataJPAProcessorDefault.deleteEntity(getDeletetUriInfo(),
+ HttpContentType.APPLICATION_XML));
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testCreateEntity() {
+ try {
+ Assert.assertNotNull(objODataJPAProcessorDefault.createEntity(getPostUriInfo(), getMockedInputStreamContent(),
+ HttpContentType.APPLICATION_XML, HttpContentType.APPLICATION_XML));
+ } catch (ODataException e) {
+ Assert.assertTrue(true); // Expected TODO - need to revisit
+ }
+ }
+
+ @Test
+ public void testUpdateEntity() {
+ try {
+ Assert.assertNotNull(objODataJPAProcessorDefault.updateEntity(getPutUriInfo(), getMockedInputStreamContent(),
+ HttpContentType.APPLICATION_XML, false, HttpContentType.APPLICATION_XML));
+ } catch (ODataException e) {
+ Assert.assertTrue(true); // Expected TODO - need to revisit
+ }
+ }
+
+ private PutMergePatchUriInfo getPutUriInfo() {
+ return (PutMergePatchUriInfo) getDeletetUriInfo();
+ }
+
+ private PostUriInfo getPostUriInfo() {
+ return (PostUriInfo) getDeletetUriInfo();
+ }
+
+ private InputStream getMockedInputStreamContent() {
+ return new ByteArrayInputStream(getEntityBody().getBytes());
+ }
+
+ private String getEntityBody() {
+ return "<entry xmlns=\"http://www.w3.org/2005/Atom\" " +
+ "xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" " +
+ "xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" " +
+ "xml:base=\"http://localhost:8080/org.apache.olingo.odata2.processor.ref.web/SalesOrderProcessing.svc/\">"
+ + "<content type=\"application/xml\">"
+ + "<m:properties>"
+ + "<d:ID>2</d:ID>"
+ + "<d:CreationDate>2013-01-02T00:00:00</d:CreationDate>"
+ + "<d:CurrencyCode>Code_555</d:CurrencyCode>"
+ + "<d:BuyerAddressInfo m:type=\"SalesOrderProcessing.AddressInfo\">"
+ + "<d:Street>Test_Street_Name_055</d:Street>"
+ + "<d:Number>2</d:Number>"
+ + "<d:Country>Test_Country_2</d:Country>"
+ + "<d:City>Test_City_2</d:City>"
+ + "</d:BuyerAddressInfo>"
+ + "<d:GrossAmount>0.0</d:GrossAmount>"
+ + "<d:BuyerId>2</d:BuyerId>"
+ + "<d:DeliveryStatus>true</d:DeliveryStatus>"
+ + "<d:BuyerName>buyerName_2</d:BuyerName>"
+ + "<d:NetAmount>0.0</d:NetAmount>" + "</m:properties>" + "</content>" + "</entry>";
+ }
+
+ private GetEntitySetCountUriInfo getEntitySetCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private GetEntityCountUriInfo getEntityCountCountUriInfo() {
+ return getLocalUriInfo();
+ }
+
+ private DeleteUriInfo getDeletetUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ EasyMock.expect(objUriInfo.getKeyPredicates()).andStubReturn(getKeyPredicates());
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ private List<KeyPredicate> getKeyPredicates() {
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ return keyPredicates;
+ }
+
+ /**
+ * @return
+ */
+ private UriInfo getLocalUriInfo() {
+ UriInfo objUriInfo = EasyMock.createMock(UriInfo.class);
+ EasyMock.expect(objUriInfo.getStartEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getTargetEntitySet()).andStubReturn(getLocalEdmEntitySet());
+ EasyMock.expect(objUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(objUriInfo.getOrderBy()).andStubReturn(getOrderByExpression());
+ EasyMock.expect(objUriInfo.getTop()).andStubReturn(getTop());
+ EasyMock.expect(objUriInfo.getSkip()).andStubReturn(getSkip());
+ EasyMock.expect(objUriInfo.getInlineCount()).andStubReturn(getInlineCount());
+ EasyMock.expect(objUriInfo.getFilter()).andStubReturn(getFilter());
+ EasyMock.expect(objUriInfo.getFunctionImport()).andStubReturn(null);
+ EasyMock.replay(objUriInfo);
+ return objUriInfo;
+ }
+
+ /**
+ * @return
+ * @throws EdmException
+ */
+ private EdmEntitySet getLocalEdmEntitySet() {
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(getLocalEdmEntityType());
+ EasyMock.replay(edmEntitySet);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return edmEntitySet;
+ }
+
+ /**
+ * @return
+ * @throws EdmException
+ */
+ private EdmEntityType getLocalEdmEntityType() {
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ try {
+ EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+ EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
+ EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SALES_ORDER));
+ EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
+ EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));// ID vs Salesorder
+ // ID
+ EasyMock.replay(edmEntityType);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return edmEntityType;
+ }
+
+ private InlineCount getInlineCount() {
+ return InlineCount.NONE;
+ }
+
+ private FilterExpression getFilter() {
+ return null;
+ }
+
+ private Integer getSkip() {
+ return null;
+ }
+
+ private Integer getTop() {
+ return null;
+ }
+
+ private OrderByExpression getOrderByExpression() {
+ return null;
+ }
+
+ private ODataJPAContext getLocalmockODataJPAContext() {
+ ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
+ EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn("salesorderprocessing");
+ EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory());
+ EasyMock.expect(odataJPAContext.getODataContext()).andStubReturn(getLocalODataContext());
+ EasyMock.expect(odataJPAContext.getEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(odataJPAContext);
+ return odataJPAContext;
+ }
+
+ private EntityManagerFactory mockEntityManagerFactory() {
+ EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+ EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
+ EasyMock.expect(emf.createEntityManager()).andStubReturn(getLocalEntityManager());
+ EasyMock.replay(emf);
+ return emf;
+ }
+
+ private EntityManagerFactory mockEntityManagerFactory2() {// For create, to avoid stackoverflow
+ EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+ EasyMock.expect(emf.getMetamodel()).andStubReturn(mockMetaModel());
+ EasyMock.replay(emf);
+ return emf;
+ }
+
+ private EntityManager getLocalEntityManager() {
+ EntityManager em = EasyMock.createMock(EntityManager.class);
+ EasyMock.expect(em.createQuery("SELECT E1 FROM SalesOrderHeaders E1")).andStubReturn(getQuery());
+ EasyMock.expect(em.createQuery("SELECT COUNT ( E1 ) FROM SalesOrderHeaders E1")).andStubReturn(
+ getQueryForSelectCount());
+ EasyMock.expect(em.getEntityManagerFactory()).andStubReturn(mockEntityManagerFactory2());// For create
+ EasyMock.expect(em.getTransaction()).andStubReturn(getLocalTransaction()); // For Delete
+ Address obj = new Address();
+ em.remove(obj);// testing void method
+ em.flush();
+ EasyMock.replay(em);
+ return em;
+ }
+
+ private EntityTransaction getLocalTransaction() {
+ EntityTransaction entityTransaction = EasyMock.createMock(EntityTransaction.class);
+ entityTransaction.begin(); // testing void method
+ entityTransaction.commit();// testing void method
+ entityTransaction.rollback();// testing void method
+ EasyMock.replay(entityTransaction);
+ return entityTransaction;
+ }
+
+ private Query getQuery() {
+ Query query = EasyMock.createMock(Query.class);
+ EasyMock.expect(query.getResultList()).andStubReturn(getResultList());
+ EasyMock.replay(query);
+ return query;
+ }
+
+ private Query getQueryForSelectCount() {
+ Query query = EasyMock.createMock(Query.class);
+ EasyMock.expect(query.getResultList()).andStubReturn(getResultListForSelectCount());
+ EasyMock.replay(query);
+ return query;
+ }
+
+ private List<?> getResultList() {
+ List<Object> list = new ArrayList<Object>();
+ list.add(new Address());
+ return list;
+ }
+
+ private List<?> getResultListForSelectCount() {
+ List<Object> list = new ArrayList<Object>();
+ list.add(new Long(11));
+ return list;
+ }
+
+ class Address {
+ private String soId = "12";
+
+ public String getSoId() {
+ return soId;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ boolean isEqual = false;
+ if (obj instanceof Address) {
+ isEqual = getSoId().equalsIgnoreCase(((Address) obj).getSoId());//
+ }
+ return isEqual;
+ }
+ }
+
+ private Metamodel mockMetaModel() {
+ Metamodel metaModel = EasyMock.createMock(Metamodel.class);
+ EasyMock.expect(metaModel.getEntities()).andStubReturn(getLocalEntities());
+ EasyMock.replay(metaModel);
+ return metaModel;
+ }
+
+ private Set<EntityType<?>> getLocalEntities() {
+ Set<EntityType<?>> entityTypeSet = new HashSet<EntityType<?>>();
+ entityTypeSet.add(getLocalJPAEntityType());
+ return entityTypeSet;
+ }
+
+ @SuppressWarnings("rawtypes")
+ private EntityType<EntityType> getLocalJPAEntityType() {
+ @SuppressWarnings("unchecked")
+ EntityType<EntityType> entityType = EasyMock.createMock(EntityType.class);
+ EasyMock.expect(entityType.getJavaType()).andStubReturn(EntityType.class);
+ EasyMock.replay(entityType);
+ return entityType;
+ }
+
+ private GetEntityUriInfo getEntityUriInfo() {
+ GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ try {
+ EasyMock.expect(getEntityView.getExpand()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.expect(edmEntitySet.getName()).andStubReturn(SALES_ORDER_HEADERS);
+
+ EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
+ EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EasyMock.expect(edmEntityType.getPropertyNames()).andStubReturn(getLocalPropertyNames());
+ EasyMock.expect(edmEntityType.getProperty(SO_ID)).andStubReturn(getEdmTypedMockedObj(SO_ID));
+
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(getEdmMappingMockedObj(SALES_ORDER));
+
+ EasyMock.expect(edmEntityType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.expect(edmEntityType.getNamespace()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn(SALES_ORDER_HEADERS);
+ EasyMock.expect(edmEntityType.hasStream()).andStubReturn(false);
+ EasyMock.expect(edmEntityType.getNavigationPropertyNames()).andStubReturn(new ArrayList<String>());
+ EasyMock.expect(edmEntityType.getKeyPropertyNames()).andStubReturn(new ArrayList<String>());
+
+ EasyMock.expect(edmEntitySet.getEntityContainer()).andStubReturn(getLocalEdmEntityContainer());
+
+ EasyMock.replay(edmEntityType, edmEntitySet);
+ EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
+ List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
+ EasyMock.expect(getEntityView.getNavigationSegments()).andReturn(navigationSegments);
+ EasyMock.expect(getEntityView.getStartEntitySet()).andReturn(edmEntitySet);
+
+ EasyMock.replay(getEntityView);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return getEntityView;
+ }
+
+ private EdmEntityContainer getLocalEdmEntityContainer() {
+ EdmEntityContainer edmEntityContainer = EasyMock.createMock(EdmEntityContainer.class);
+ EasyMock.expect(edmEntityContainer.isDefaultEntityContainer()).andStubReturn(true);
+ try {
+ EasyMock.expect(edmEntityContainer.getName()).andStubReturn(SALESORDERPROCESSING_CONTAINER);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ EasyMock.replay(edmEntityContainer);
+ return edmEntityContainer;
+ }
+
+ private EdmTyped getEdmTypedMockedObj(final String propertyName) {
+ EdmProperty mockedEdmProperty = EasyMock.createMock(EdmProperty.class);
+ try {
+ EasyMock.expect(mockedEdmProperty.getMapping()).andStubReturn(getEdmMappingMockedObj(propertyName));
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(edmType.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(edmType);
+ EasyMock.expect(mockedEdmProperty.getName()).andStubReturn("identifier");
+ EasyMock.expect(mockedEdmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(mockedEdmProperty.getFacets()).andStubReturn(getEdmFacetsMockedObj());
+
+ EasyMock.replay(mockedEdmProperty);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return mockedEdmProperty;
+ }
+
+ private EdmFacets getEdmFacetsMockedObj() {
+ EdmFacets facets = EasyMock.createMock(EdmFacets.class);
+ EasyMock.expect(facets.getConcurrencyMode()).andStubReturn(EdmConcurrencyMode.Fixed);
+
+ EasyMock.replay(facets);
+ return facets;
+ }
+
+ private EdmMapping getEdmMappingMockedObj(final String propertyName) {
+ EdmMapping mockedEdmMapping = EasyMock.createMock(EdmMapping.class);
+ if (propertyName.equalsIgnoreCase(SALES_ORDER)) {
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(SALES_ORDER_HEADERS);
+ } else {
+ EasyMock.expect(mockedEdmMapping.getInternalName()).andStubReturn(propertyName);
+ }
+ EasyMock.replay(mockedEdmMapping);
+ return mockedEdmMapping;
+ }
+
+ private List<String> getLocalPropertyNames() {
+ List<String> list = new ArrayList<String>();
+ list.add(SO_ID);
+ return list;
+ }
+
+ private ODataContext getLocalODataContext() {
+ ODataContext objODataContext = EasyMock.createMock(ODataContext.class);
+ try {
+ EasyMock.expect(objODataContext.getPathInfo()).andStubReturn(getLocalPathInfo());
+ } catch (ODataException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(objODataContext);
+ return objODataContext;
+ }
+
+ private PathInfo getLocalPathInfo() {
+ PathInfo pathInfo = EasyMock.createMock(PathInfo.class);
+ EasyMock.expect(pathInfo.getServiceRoot()).andStubReturn(getLocalURI());
+ EasyMock.replay(pathInfo);
+ return pathInfo;
+ }
+
+ private URI getLocalURI() {
+ URI uri = null;
+ try {
+ uri = new URI(STR_LOCAL_URI);
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ return uri;
+ }
+
+}
[41/47] git commit: [OLINGO-99] Re-factor Package Names. Following
are the changes
Posted by tb...@apache.org.
[OLINGO-99] Re-factor Package Names. Following are the changes
Module jpa-api
1) Package name is re-factored from
org.apache.olingo.odata2.processor.api.jpa.* to
org.apache.olingo.odata2.jpa.processor.api.*
2) The namespace for the mapping model schema is changed from
http://www.apache.org/olingo/odata2/processor/api/jpa/model/mapping
to
http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping
Module jpa-core
1) Package name is re-factored from
org.apache.olingo.odata2.processor.core.jpa to
org.apache.olingo.odata2.jpa.processor.core
Signed-off-by: Chandan V A <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/63b621a8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/63b621a8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/63b621a8
Branch: refs/heads/ODataServlet
Commit: 63b621a8016283e28e55b4b4d1f2c089bd536795
Parents: 8695302
Author: Chandan V A <ch...@sap.com>
Authored: Sat Dec 28 19:46:19 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Sat Dec 28 19:47:17 2013 +0530
----------------------------------------------------------------------
odata2-jpa-processor/jpa-api/pom.xml | 4 +-
.../jpa/processor/api/ODataJPAContext.java | 206 ++++++
.../jpa/processor/api/ODataJPAProcessor.java | 69 ++
.../processor/api/ODataJPAServiceFactory.java | 190 ++++++
.../jpa/processor/api/access/JPAEdmBuilder.java | 57 ++
.../api/access/JPAEdmMappingModelAccess.java | 191 ++++++
.../jpa/processor/api/access/JPAFunction.java | 85 +++
.../jpa/processor/api/access/JPAJoinClause.java | 148 +++++
.../processor/api/access/JPAMethodContext.java | 130 ++++
.../api/access/JPAMethodContextView.java | 46 ++
.../jpa/processor/api/access/JPAProcessor.java | 260 ++++++++
.../jpa/processor/api/access/package-info.java | 26 +
.../api/exception/ODataJPAErrorCallback.java | 45 ++
.../api/exception/ODataJPAException.java | 68 ++
.../api/exception/ODataJPAMessageService.java | 49 ++
.../api/exception/ODataJPAModelException.java | 92 +++
.../api/exception/ODataJPARuntimeException.java | 97 +++
.../processor/api/exception/package-info.java | 31 +
.../processor/api/factory/JPAAccessFactory.java | 69 ++
.../api/factory/JPQLBuilderFactory.java | 77 +++
.../api/factory/ODataJPAAccessFactory.java | 82 +++
.../processor/api/factory/ODataJPAFactory.java | 105 ++++
.../jpa/processor/api/factory/package-info.java | 33 +
.../jpa/processor/api/jpql/JPQLContext.java | 204 ++++++
.../jpa/processor/api/jpql/JPQLContextType.java | 73 +++
.../jpa/processor/api/jpql/JPQLContextView.java | 53 ++
.../processor/api/jpql/JPQLJoinContextView.java | 44 ++
.../jpql/JPQLJoinSelectSingleContextView.java | 45 ++
.../api/jpql/JPQLSelectContextView.java | 62 ++
.../api/jpql/JPQLSelectSingleContextView.java | 53 ++
.../jpa/processor/api/jpql/JPQLStatement.java | 148 +++++
.../jpa/processor/api/jpql/package-info.java | 27 +
.../api/model/JPAEdmAssociationEndView.java | 91 +++
.../api/model/JPAEdmAssociationSetView.java | 69 ++
.../api/model/JPAEdmAssociationView.java | 128 ++++
.../jpa/processor/api/model/JPAEdmBaseView.java | 101 +++
.../api/model/JPAEdmComplexPropertyView.java | 45 ++
.../api/model/JPAEdmComplexTypeView.java | 137 ++++
.../api/model/JPAEdmEntityContainerView.java | 72 +++
.../api/model/JPAEdmEntitySetView.java | 64 ++
.../api/model/JPAEdmEntityTypeView.java | 76 +++
.../processor/api/model/JPAEdmExtension.java | 50 ++
.../api/model/JPAEdmFunctionImportView.java | 51 ++
.../jpa/processor/api/model/JPAEdmKeyView.java | 51 ++
.../jpa/processor/api/model/JPAEdmMapping.java | 63 ++
.../processor/api/model/JPAEdmModelView.java | 43 ++
.../api/model/JPAEdmNavigationPropertyView.java | 72 +++
.../processor/api/model/JPAEdmPropertyView.java | 104 +++
.../JPAEdmReferentialConstraintRoleView.java | 101 +++
.../model/JPAEdmReferentialConstraintView.java | 69 ++
.../processor/api/model/JPAEdmSchemaView.java | 111 ++++
.../api/model/mapping/JPAAttributeMapType.java | 202 ++++++
.../api/model/mapping/JPAEdmMappingModel.java | 79 +++
.../mapping/JPAEdmMappingModelFactory.java | 85 +++
.../model/mapping/JPAEmbeddableTypeMapType.java | 161 +++++
.../mapping/JPAEmbeddableTypesMapType.java | 89 +++
.../api/model/mapping/JPAEntityTypeMapType.java | 213 +++++++
.../model/mapping/JPAEntityTypesMapType.java | 89 +++
.../mapping/JPAPersistenceUnitMapType.java | 157 +++++
.../model/mapping/JPARelationshipMapType.java | 175 ++++++
.../api/model/mapping/package-info.java | 28 +
.../jpa/processor/api/model/package-info.java | 27 +
.../odata2/jpa/processor/api/package-info.java | 33 +
.../processor/api/jpa/ODataJPAContext.java | 206 ------
.../processor/api/jpa/ODataJPAProcessor.java | 69 --
.../api/jpa/ODataJPAServiceFactory.java | 190 ------
.../processor/api/jpa/access/JPAEdmBuilder.java | 57 --
.../jpa/access/JPAEdmMappingModelAccess.java | 191 ------
.../processor/api/jpa/access/JPAFunction.java | 85 ---
.../processor/api/jpa/access/JPAJoinClause.java | 148 -----
.../api/jpa/access/JPAMethodContext.java | 130 ----
.../api/jpa/access/JPAMethodContextView.java | 46 --
.../processor/api/jpa/access/JPAProcessor.java | 260 --------
.../processor/api/jpa/access/package-info.java | 26 -
.../jpa/exception/ODataJPAErrorCallback.java | 45 --
.../api/jpa/exception/ODataJPAException.java | 68 --
.../jpa/exception/ODataJPAMessageService.java | 49 --
.../jpa/exception/ODataJPAModelException.java | 92 ---
.../jpa/exception/ODataJPARuntimeException.java | 97 ---
.../api/jpa/exception/package-info.java | 31 -
.../api/jpa/factory/JPAAccessFactory.java | 69 --
.../api/jpa/factory/JPQLBuilderFactory.java | 77 ---
.../api/jpa/factory/ODataJPAAccessFactory.java | 82 ---
.../api/jpa/factory/ODataJPAFactory.java | 105 ----
.../processor/api/jpa/factory/package-info.java | 33 -
.../processor/api/jpa/jpql/JPQLContext.java | 204 ------
.../processor/api/jpa/jpql/JPQLContextType.java | 73 ---
.../processor/api/jpa/jpql/JPQLContextView.java | 53 --
.../api/jpa/jpql/JPQLJoinContextView.java | 44 --
.../jpql/JPQLJoinSelectSingleContextView.java | 45 --
.../api/jpa/jpql/JPQLSelectContextView.java | 62 --
.../jpa/jpql/JPQLSelectSingleContextView.java | 53 --
.../processor/api/jpa/jpql/JPQLStatement.java | 148 -----
.../processor/api/jpa/jpql/package-info.java | 27 -
.../api/jpa/model/JPAEdmAssociationEndView.java | 91 ---
.../api/jpa/model/JPAEdmAssociationSetView.java | 69 --
.../api/jpa/model/JPAEdmAssociationView.java | 128 ----
.../processor/api/jpa/model/JPAEdmBaseView.java | 101 ---
.../jpa/model/JPAEdmComplexPropertyView.java | 45 --
.../api/jpa/model/JPAEdmComplexTypeView.java | 137 ----
.../jpa/model/JPAEdmEntityContainerView.java | 72 ---
.../api/jpa/model/JPAEdmEntitySetView.java | 64 --
.../api/jpa/model/JPAEdmEntityTypeView.java | 76 ---
.../api/jpa/model/JPAEdmExtension.java | 50 --
.../api/jpa/model/JPAEdmFunctionImportView.java | 51 --
.../processor/api/jpa/model/JPAEdmKeyView.java | 51 --
.../processor/api/jpa/model/JPAEdmMapping.java | 63 --
.../api/jpa/model/JPAEdmModelView.java | 43 --
.../jpa/model/JPAEdmNavigationPropertyView.java | 72 ---
.../api/jpa/model/JPAEdmPropertyView.java | 104 ---
.../JPAEdmReferentialConstraintRoleView.java | 101 ---
.../model/JPAEdmReferentialConstraintView.java | 69 --
.../api/jpa/model/JPAEdmSchemaView.java | 111 ----
.../jpa/model/mapping/JPAAttributeMapType.java | 202 ------
.../jpa/model/mapping/JPAEdmMappingModel.java | 79 ---
.../mapping/JPAEdmMappingModelFactory.java | 85 ---
.../model/mapping/JPAEmbeddableTypeMapType.java | 161 -----
.../mapping/JPAEmbeddableTypesMapType.java | 89 ---
.../jpa/model/mapping/JPAEntityTypeMapType.java | 213 -------
.../model/mapping/JPAEntityTypesMapType.java | 89 ---
.../mapping/JPAPersistenceUnitMapType.java | 157 -----
.../model/mapping/JPARelationshipMapType.java | 175 ------
.../api/jpa/model/mapping/package-info.java | 28 -
.../processor/api/jpa/model/package-info.java | 27 -
.../odata2/processor/api/jpa/package-info.java | 33 -
.../src/main/resources/JPAEDMMappingModel.xsd | 4 +-
odata2-jpa-processor/jpa-core/pom.xml | 2 +-
.../jpa/processor/core/ODataEntityParser.java | 163 +++++
.../processor/core/ODataExpressionParser.java | 381 +++++++++++
.../jpa/processor/core/ODataJPAContextImpl.java | 146 +++++
.../core/ODataJPAProcessorDefault.java | 194 ++++++
.../processor/core/ODataJPAResponseBuilder.java | 629 +++++++++++++++++++
.../processor/core/access/data/JPAEntity.java | 355 +++++++++++
.../core/access/data/JPAEntityParser.java | 453 +++++++++++++
.../core/access/data/JPAExpandCallBack.java | 180 ++++++
.../core/access/data/JPAFunctionContext.java | 170 +++++
.../jpa/processor/core/access/data/JPALink.java | 225 +++++++
.../core/access/data/JPAProcessorImpl.java | 491 +++++++++++++++
.../core/access/model/EdmTypeConvertor.java | 69 ++
.../access/model/JPAEdmMappingModelService.java | 247 ++++++++
.../core/access/model/JPAEdmNameBuilder.java | 499 +++++++++++++++
.../core/access/model/JPATypeConvertor.java | 119 ++++
.../processor/core/edm/ODataJPAEdmProvider.java | 295 +++++++++
.../ODataJPAMessageServiceDefault.java | 122 ++++
.../core/factory/ODataJPAFactoryImpl.java | 237 +++++++
.../core/jpql/JPQLJoinSelectContext.java | 171 +++++
.../core/jpql/JPQLJoinSelectSingleContext.java | 158 +++++
.../JPQLJoinSelectSingleStatementBuilder.java | 106 ++++
.../core/jpql/JPQLJoinStatementBuilder.java | 145 +++++
.../processor/core/jpql/JPQLSelectContext.java | 159 +++++
.../core/jpql/JPQLSelectSingleContext.java | 109 ++++
.../jpql/JPQLSelectSingleStatementBuilder.java | 66 ++
.../core/jpql/JPQLSelectStatementBuilder.java | 98 +++
.../processor/core/model/JPAEdmAssociation.java | 237 +++++++
.../core/model/JPAEdmAssociationEnd.java | 183 ++++++
.../core/model/JPAEdmAssociationSet.java | 131 ++++
.../core/model/JPAEdmBaseViewImpl.java | 101 +++
.../processor/core/model/JPAEdmComplexType.java | 270 ++++++++
.../core/model/JPAEdmEntityContainer.java | 145 +++++
.../processor/core/model/JPAEdmEntitySet.java | 112 ++++
.../processor/core/model/JPAEdmEntityType.java | 230 +++++++
.../jpa/processor/core/model/JPAEdmFacets.java | 94 +++
.../core/model/JPAEdmFunctionImport.java | 349 ++++++++++
.../jpa/processor/core/model/JPAEdmKey.java | 129 ++++
.../processor/core/model/JPAEdmMappingImpl.java | 51 ++
.../jpa/processor/core/model/JPAEdmModel.java | 65 ++
.../core/model/JPAEdmNavigationProperty.java | 98 +++
.../processor/core/model/JPAEdmProperty.java | 377 +++++++++++
.../core/model/JPAEdmReferentialConstraint.java | 147 +++++
.../model/JPAEdmReferentialConstraintRole.java | 258 ++++++++
.../jpa/processor/core/model/JPAEdmSchema.java | 214 +++++++
.../model/_JPAEdmFunctionImportBuilder.java | 237 +++++++
.../processor/core/jpa/ODataEntityParser.java | 163 -----
.../core/jpa/ODataExpressionParser.java | 381 -----------
.../processor/core/jpa/ODataJPAContextImpl.java | 146 -----
.../core/jpa/ODataJPAProcessorDefault.java | 194 ------
.../core/jpa/ODataJPAResponseBuilder.java | 629 -------------------
.../core/jpa/access/data/JPAEntity.java | 355 -----------
.../core/jpa/access/data/JPAEntityParser.java | 453 -------------
.../core/jpa/access/data/JPAExpandCallBack.java | 180 ------
.../jpa/access/data/JPAFunctionContext.java | 170 -----
.../processor/core/jpa/access/data/JPALink.java | 225 -------
.../core/jpa/access/data/JPAProcessorImpl.java | 491 ---------------
.../core/jpa/access/model/EdmTypeConvertor.java | 69 --
.../access/model/JPAEdmMappingModelService.java | 247 --------
.../jpa/access/model/JPAEdmNameBuilder.java | 499 ---------------
.../core/jpa/access/model/JPATypeConvertor.java | 119 ----
.../core/jpa/edm/ODataJPAEdmProvider.java | 295 ---------
.../ODataJPAMessageServiceDefault.java | 122 ----
.../core/jpa/factory/ODataJPAFactoryImpl.java | 237 -------
.../core/jpa/jpql/JPQLJoinSelectContext.java | 171 -----
.../jpa/jpql/JPQLJoinSelectSingleContext.java | 158 -----
.../JPQLJoinSelectSingleStatementBuilder.java | 106 ----
.../core/jpa/jpql/JPQLJoinStatementBuilder.java | 145 -----
.../core/jpa/jpql/JPQLSelectContext.java | 159 -----
.../core/jpa/jpql/JPQLSelectSingleContext.java | 109 ----
.../jpql/JPQLSelectSingleStatementBuilder.java | 66 --
.../jpa/jpql/JPQLSelectStatementBuilder.java | 98 ---
.../core/jpa/model/JPAEdmAssociation.java | 237 -------
.../core/jpa/model/JPAEdmAssociationEnd.java | 183 ------
.../core/jpa/model/JPAEdmAssociationSet.java | 131 ----
.../core/jpa/model/JPAEdmBaseViewImpl.java | 101 ---
.../core/jpa/model/JPAEdmComplexType.java | 270 --------
.../core/jpa/model/JPAEdmEntityContainer.java | 145 -----
.../core/jpa/model/JPAEdmEntitySet.java | 112 ----
.../core/jpa/model/JPAEdmEntityType.java | 230 -------
.../processor/core/jpa/model/JPAEdmFacets.java | 94 ---
.../core/jpa/model/JPAEdmFunctionImport.java | 349 ----------
.../processor/core/jpa/model/JPAEdmKey.java | 129 ----
.../core/jpa/model/JPAEdmMappingImpl.java | 51 --
.../processor/core/jpa/model/JPAEdmModel.java | 65 --
.../jpa/model/JPAEdmNavigationProperty.java | 98 ---
.../core/jpa/model/JPAEdmProperty.java | 377 -----------
.../jpa/model/JPAEdmReferentialConstraint.java | 147 -----
.../model/JPAEdmReferentialConstraintRole.java | 258 --------
.../processor/core/jpa/model/JPAEdmSchema.java | 214 -------
.../jpa/model/_JPAEdmFunctionImportBuilder.java | 237 -------
.../main/resources/jpaprocessor_msg.properties | 66 +-
.../core/ODataExpressionParserTest.java | 516 +++++++++++++++
.../processor/core/ODataJPAContextImplTest.java | 99 +++
.../core/ODataJPAProcessorDefaultTest.java | 555 ++++++++++++++++
.../core/ODataJPAResponseBuilderTest.java | 567 +++++++++++++++++
.../core/access/data/JPAEntityParserTest.java | 600 ++++++++++++++++++
.../JPAEntityParserTestForStaticMethods.java | 252 ++++++++
.../core/access/data/JPAEntityTest.java | 188 ++++++
.../core/access/data/JPAExpandCallBackTest.java | 161 +++++
.../access/data/JPAFunctionContextTest.java | 144 +++++
.../core/access/data/JPAProcessorImplTest.java | 448 +++++++++++++
.../model/JPAEdmMappingModelServiceTest.java | 214 +++++++
.../access/model/JPAEdmNameBuilderTest.java | 153 +++++
.../core/access/model/JPATypeConvertorTest.java | 95 +++
.../core/common/ODataJPATestConstants.java | 27 +
.../edm/ODataJPAEdmProviderNegativeTest.java | 192 ++++++
.../core/edm/ODataJPAEdmProviderTest.java | 386 ++++++++++++
.../core/jpql/JPQLBuilderFactoryTest.java | 381 +++++++++++
.../core/jpql/JPQLJoinContextTest.java | 199 ++++++
.../jpql/JPQLJoinSelectSingleContextTest.java | 216 +++++++
...PQLJoinSelectSingleStatementBuilderTest.java | 143 +++++
.../core/jpql/JPQLJoinStatementBuilderTest.java | 125 ++++
.../core/jpql/JPQLSelectContextImplTest.java | 386 ++++++++++++
.../jpql/JPQLSelectSingleContextImplTest.java | 199 ++++++
.../JPQLSelectSingleStatementBuilderTest.java | 125 ++++
.../jpql/JPQLSelectStatementBuilderTest.java | 137 ++++
.../core/mock/ODataJPAContextMock.java | 57 ++
.../processor/core/mock/data/EdmMockUtil.java | 337 ++++++++++
.../processor/core/mock/data/EdmMockUtilV2.java | 324 ++++++++++
.../processor/core/mock/data/JPATypeMock.java | 205 ++++++
.../core/mock/data/ODataEntryMockUtil.java | 127 ++++
.../core/mock/data/SalesOrderHeader.java | 63 ++
.../core/mock/data/SalesOrderLineItem.java | 38 ++
.../core/mock/data/SalesOrderLineItemKey.java | 52 ++
.../core/mock/model/EdmSchemaMock.java | 213 +++++++
.../core/mock/model/JPAAttributeMock.java | 63 ++
.../core/mock/model/JPACustomProcessorMock.java | 74 +++
.../core/mock/model/JPAEdmMockData.java | 72 +++
.../core/mock/model/JPAEmbeddableMock.java | 184 ++++++
.../core/mock/model/JPAEmbeddableTypeMock.java | 184 ++++++
.../core/mock/model/JPAEntityTypeMock.java | 246 ++++++++
.../core/mock/model/JPAJavaMemberMock.java | 74 +++
.../core/mock/model/JPAManagedTypeMock.java | 184 ++++++
.../core/mock/model/JPAMetaModelMock.java | 60 ++
.../core/mock/model/JPAPluralAttributeMock.java | 95 +++
.../mock/model/JPASingularAttributeMock.java | 94 +++
.../mock/model/_JPACustomProcessorMock.java | 77 +++
.../model/_JPACustomProcessorNegativeMock.java | 70 +++
.../core/model/JPAEdmAssociationEndTest.java | 178 ++++++
.../core/model/JPAEdmAssociationSetTest.java | 185 ++++++
.../core/model/JPAEdmAssociationTest.java | 426 +++++++++++++
.../core/model/JPAEdmBaseViewImplTest.java | 90 +++
.../core/model/JPAEdmComplexTypeTest.java | 270 ++++++++
.../core/model/JPAEdmEntityContainerTest.java | 235 +++++++
.../core/model/JPAEdmEntitySetTest.java | 225 +++++++
.../core/model/JPAEdmEntityTypeTest.java | 199 ++++++
.../core/model/JPAEdmFunctionImportTest.java | 567 +++++++++++++++++
.../jpa/processor/core/model/JPAEdmKeyTest.java | 177 ++++++
.../processor/core/model/JPAEdmModelTest.java | 146 +++++
.../model/JPAEdmNavigationPropertyTest.java | 219 +++++++
.../core/model/JPAEdmPropertyTest.java | 439 +++++++++++++
.../JPAEdmReferentialConstraintRoleTest.java | 235 +++++++
.../model/JPAEdmReferentialConstraintTest.java | 178 ++++++
.../processor/core/model/JPAEdmSchemaTest.java | 104 +++
.../core/model/JPAEdmTestModelView.java | 400 ++++++++++++
.../core/model/_JPAEdmFunctionImportTest.java | 571 +++++++++++++++++
.../core/jpa/ODataExpressionParserTest.java | 515 ---------------
.../core/jpa/ODataJPAContextImplTest.java | 98 ---
.../core/jpa/ODataJPAProcessorDefaultTest.java | 554 ----------------
.../core/jpa/ODataJPAResponseBuilderTest.java | 566 -----------------
.../jpa/access/data/JPAEntityParserTest.java | 599 ------------------
.../JPAEntityParserTestForStaticMethods.java | 251 --------
.../core/jpa/access/data/JPAEntityTest.java | 187 ------
.../jpa/access/data/JPAExpandCallBackTest.java | 160 -----
.../jpa/access/data/JPAFunctionContextTest.java | 143 -----
.../jpa/access/data/JPAProcessorImplTest.java | 447 -------------
.../model/JPAEdmMappingModelServiceTest.java | 213 -------
.../jpa/access/model/JPAEdmNameBuilderTest.java | 151 -----
.../jpa/access/model/JPATypeConvertorTest.java | 94 ---
.../core/jpa/common/ODataJPATestConstants.java | 27 -
.../edm/ODataJPAEdmProviderNegativeTest.java | 191 ------
.../core/jpa/edm/ODataJPAEdmProviderTest.java | 385 ------------
.../core/jpa/jpql/JPQLBuilderFactoryTest.java | 377 -----------
.../core/jpa/jpql/JPQLJoinContextTest.java | 198 ------
.../jpql/JPQLJoinSelectSingleContextTest.java | 215 -------
...PQLJoinSelectSingleStatementBuilderTest.java | 142 -----
.../jpa/jpql/JPQLJoinStatementBuilderTest.java | 124 ----
.../jpa/jpql/JPQLSelectContextImplTest.java | 385 ------------
.../jpql/JPQLSelectSingleContextImplTest.java | 198 ------
.../JPQLSelectSingleStatementBuilderTest.java | 123 ----
.../jpql/JPQLSelectStatementBuilderTest.java | 135 ----
.../core/jpa/mock/ODataJPAContextMock.java | 57 --
.../core/jpa/mock/data/EdmMockUtil.java | 337 ----------
.../core/jpa/mock/data/EdmMockUtilV2.java | 324 ----------
.../core/jpa/mock/data/JPATypeMock.java | 205 ------
.../core/jpa/mock/data/ODataEntryMockUtil.java | 127 ----
.../core/jpa/mock/data/SalesOrderHeader.java | 63 --
.../core/jpa/mock/data/SalesOrderLineItem.java | 38 --
.../jpa/mock/data/SalesOrderLineItemKey.java | 52 --
.../core/jpa/mock/model/EdmSchemaMock.java | 213 -------
.../core/jpa/mock/model/JPAAttributeMock.java | 63 --
.../jpa/mock/model/JPACustomProcessorMock.java | 74 ---
.../core/jpa/mock/model/JPAEdmMockData.java | 72 ---
.../core/jpa/mock/model/JPAEmbeddableMock.java | 184 ------
.../jpa/mock/model/JPAEmbeddableTypeMock.java | 184 ------
.../core/jpa/mock/model/JPAEntityTypeMock.java | 246 --------
.../core/jpa/mock/model/JPAJavaMemberMock.java | 74 ---
.../core/jpa/mock/model/JPAManagedTypeMock.java | 184 ------
.../core/jpa/mock/model/JPAMetaModelMock.java | 60 --
.../jpa/mock/model/JPAPluralAttributeMock.java | 95 ---
.../mock/model/JPASingularAttributeMock.java | 94 ---
.../jpa/mock/model/_JPACustomProcessorMock.java | 77 ---
.../model/_JPACustomProcessorNegativeMock.java | 70 ---
.../jpa/model/JPAEdmAssociationEndTest.java | 177 ------
.../jpa/model/JPAEdmAssociationSetTest.java | 184 ------
.../core/jpa/model/JPAEdmAssociationTest.java | 423 -------------
.../core/jpa/model/JPAEdmBaseViewImplTest.java | 89 ---
.../core/jpa/model/JPAEdmComplexTypeTest.java | 268 --------
.../jpa/model/JPAEdmEntityContainerTest.java | 234 -------
.../core/jpa/model/JPAEdmEntitySetTest.java | 224 -------
.../core/jpa/model/JPAEdmEntityTypeTest.java | 198 ------
.../jpa/model/JPAEdmFunctionImportTest.java | 566 -----------------
.../processor/core/jpa/model/JPAEdmKeyTest.java | 176 ------
.../core/jpa/model/JPAEdmModelTest.java | 145 -----
.../jpa/model/JPAEdmNavigationPropertyTest.java | 218 -------
.../core/jpa/model/JPAEdmPropertyTest.java | 438 -------------
.../JPAEdmReferentialConstraintRoleTest.java | 233 -------
.../model/JPAEdmReferentialConstraintTest.java | 177 ------
.../core/jpa/model/JPAEdmSchemaTest.java | 103 ---
.../core/jpa/model/JPAEdmTestModelView.java | 400 ------------
.../jpa/model/_JPAEdmFunctionImportTest.java | 570 -----------------
.../SalesOrderProcessingMappingModels.xml | 2 +-
.../SalesOrderProcessingExtension.java | 4 +-
.../ref/web/JPAReferenceServiceFactory.java | 8 +-
.../webapp/SalesOrderProcessingMappingModel.xml | 2 +-
352 files changed, 29407 insertions(+), 29356 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/pom.xml b/odata2-jpa-processor/jpa-api/pom.xml
index d0c8e0b..1c69c7a 100644
--- a/odata2-jpa-processor/jpa-api/pom.xml
+++ b/odata2-jpa-processor/jpa-api/pom.xml
@@ -58,11 +58,11 @@
<configuration>
<instructions>
<Import-Package>
- org.apache.olingo.odata2.processor.core.jpa.factory;resolution:=optional,
+ org.apache.olingo.odata2.jpa.processor.core.factory;resolution:=optional,
*
</Import-Package>
<Export-Package>
- org.apache.olingo.odata2.processor.api.*;version=${project.version}
+ org.apache.olingo.odata2.jpa.processor.api.*;version=${project.version}
</Export-Package>
<Bundle-DocURL>${project.url}</Bundle-DocURL>
<Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
new file mode 100644
index 0000000..f1e529c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAContext.java
@@ -0,0 +1,206 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension;
+
+/**
+ * This class does the compilation of context objects required for OData JPA
+ * Runtime. The context object should be properly initialized with values else
+ * the behavior of processor and EDM provider can result in exception.
+ *
+ * Following are the mandatory parameter to be set into the context object
+ * <ol>
+ * <li>Persistence Unit Name</li>
+ * <li>An instance of Java Persistence Entity Manager Factory</li>
+ * </ol>
+ *
+ * <br>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory
+ *
+ */
+public interface ODataJPAContext {
+
+ /**
+ * The method gets the Java Persistence Unit Name set into the context.
+ *
+ * @return Java Persistence Unit Name
+ */
+ public String getPersistenceUnitName();
+
+ /**
+ * The method sets the Java Persistence Unit Name into the context.
+ *
+ * @param pUnitName
+ * is the Java Persistence Unit Name.
+ *
+ */
+ public void setPersistenceUnitName(String pUnitName);
+
+ /**
+ * The method gets the OData Processor for JPA from the context.
+ *
+ * @return OData JPA Processor
+ */
+ public ODataProcessor getODataProcessor();
+
+ /**
+ * The method sets the OData Processor for JPA into the context.
+ *
+ * @param processor
+ * is the specific implementation of {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAProcessor} for
+ * processing OData service requests.
+ */
+ public void setODataProcessor(ODataProcessor processor);
+
+ /**
+ * The method gets the EDM provider for JPA from the context.
+ *
+ * @return EDM provider
+ */
+ public EdmProvider getEdmProvider();
+
+ /**
+ * The method sets EDM provider into the context
+ *
+ * @param edmProvider
+ * is the specific implementation of {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider} for
+ * transforming Java persistence models to Entity Data Model
+ *
+ */
+ public void setEdmProvider(EdmProvider edmProvider);
+
+ /**
+ * The method gets the Java Persistence Entity Manager factory from the
+ * context. <br>
+ * <b>CAUTION:-</b> Don't use the Entity Manager Factory to instantiate
+ * Entity Managers. Instead get reference to Entity Manager using
+ * {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext#getEntityManager()}
+ *
+ * @return an instance of Java Persistence Entity Manager Factory
+ */
+ public EntityManagerFactory getEntityManagerFactory();
+
+ /**
+ * The method sets the Java Persistence Entity Manager factory into the
+ * context.
+ *
+ * @param emf
+ * is of type {@link javax.persistence.EntityManagerFactory}
+ *
+ */
+ public void setEntityManagerFactory(EntityManagerFactory emf);
+
+ /**
+ * The method gets OData Context into the context.
+ *
+ * @return OData Context
+ */
+ public ODataContext getODataContext();
+
+ /**
+ * The method sets OData context into the context.
+ *
+ * @param ctx
+ * is an OData context of type {@link org.apache.olingo.odata2.api.processor.ODataContext}
+ */
+ public void setODataContext(ODataContext ctx);
+
+ /**
+ * The method sets the JPA EDM mapping model name into the context. JPA EDM
+ * mapping model is an XML document based on JPAEDMMappingModel.xsd
+ *
+ * @param name
+ * is the name of JPA EDM mapping model
+ */
+ public void setJPAEdmMappingModel(String name);
+
+ /**
+ * The method gets the JPA EDM mapping model name from the context.
+ *
+ * @return name of JPA EDM mapping model
+ */
+ public String getJPAEdmMappingModel();
+
+ /**
+ * The method returns an instance of type entity manager. The entity manager
+ * thus returns a single persistence context for the current OData request.
+ * Hence all entities that are accessed within JPA processor are managed by
+ * single entity manager.
+ *
+ * @return an instance of type {@link javax.persistence.EntityManager}
+ */
+ public EntityManager getEntityManager();
+
+ /**
+ * The method sets the JPA Edm Extension instance into the context. There
+ * can be at most only one extension for a context. Invoking the method
+ * several times overwrites already set extension instance in the context.
+ *
+ * @param jpaEdmExtension
+ * is an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmExtension}
+ *
+ */
+ public void setJPAEdmExtension(JPAEdmExtension jpaEdmExtension);
+
+ /**
+ * The method returns the JPA Edm Extension instance set into the context.
+ *
+ * @return an instance of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEmbeddableTypeMapType}
+ */
+ public JPAEdmExtension getJPAEdmExtension();
+
+ /**
+ * The method sets into the context whether the library should consider default naming for
+ * <ul><li>EdmProperty</li>
+ * <li>EdmComplexProperty</li>
+ * <li>EdmNavigationProperty</li></ul>
+ *
+ * @param defaultNaming is a boolean value that indicates if set to
+ * <ul><li>true - default naming is considered in case no mapping is provided.</li>
+ * <li>false - default naming is not considered in case no mapping is provided. The
+ * name provided in JPA Entity Model is considered.</li>
+ * </ul>
+ */
+ public void setDefaultNaming(boolean defaultNaming);
+
+ /**
+ * The method returns whether the library should consider default naming for
+ * <ul><li>EdmProperty</li>
+ * <li>EdmComplexProperty</li>
+ * <li>EdmNavigationProperty</li></ul>
+ *
+ * @return
+ * <ul><li>true - default naming is considered in case no mapping is provided.</li>
+ * <li>false - default naming is not considered in case no mapping is provided. The
+ * name provided in JPA Entity Model is considered.</li>
+ * </ul>
+ */
+ public boolean getDefaultNaming();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
new file mode 100644
index 0000000..4ce0f19
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAProcessor.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api;
+
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+
+/**
+ * Extend this class and implement an OData JPA processor if the default
+ * behavior of OData JPA Processor library has to be overwritten.
+ *
+ *
+ *
+ *
+ */
+public abstract class ODataJPAProcessor extends ODataSingleProcessor {
+
+ /**
+ * An instance of {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} object
+ */
+ protected ODataJPAContext oDataJPAContext;
+
+ /**
+ * An instance of {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAProcessor}. The
+ * instance is created using {@link org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory}.
+ */
+ protected JPAProcessor jpaProcessor;
+
+ public ODataJPAContext getOdataJPAContext() {
+ return oDataJPAContext;
+ }
+
+ public void setOdataJPAContext(final ODataJPAContext odataJPAContext) {
+ oDataJPAContext = odataJPAContext;
+ }
+
+ /**
+ * Constructor
+ *
+ * @param oDataJPAContext
+ * non null OData JPA Context object
+ */
+ public ODataJPAProcessor(final ODataJPAContext oDataJPAContext) {
+ if (oDataJPAContext == null) {
+ throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
+ }
+ this.oDataJPAContext = oDataJPAContext;
+ jpaProcessor = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAProcessor(this.oDataJPAContext);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
new file mode 100644
index 0000000..66d29f9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/ODataJPAServiceFactory.java
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAErrorCallback;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+
+/**
+ * <p>
+ * Extend this factory class and create own instance of {@link org.apache.olingo.odata2.api.ODataService} that
+ * transforms Java Persistence
+ * Models into an OData Service. The factory class instantiates instances of
+ * type {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider} and
+ * {@link org.apache.olingo.odata2.api.processor.ODataSingleProcessor}. The OData
+ * JPA Processor library provides a default implementation for EdmProvider and
+ * OData Single Processor.
+ * </p>
+ * <p>
+ * The factory implementation is passed as servlet init parameter to a JAX-RS
+ * runtime which will instantiate a {@link org.apache.olingo.odata2.api.ODataService} implementation using this factory.
+ * </p>
+ *
+ * <p>
+ * <b>Mandatory:</b> Implement the abstract method initializeODataJPAContext. Fill
+ * {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} with context
+ * values.
+ * </p>
+ *
+ * <b>Sample Configuration:</b>
+ *
+ * <pre> {@code
+ * <servlet>
+ * <servlet-name>ReferenceScenarioServlet</servlet-name>
+ * <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
+ * <init-param>
+ * <param-name>javax.ws.rs.Application</param-name>
+ * <param-value>org.apache.olingo.odata2.core.rest.ODataApplication</param-value>
+ * </init-param>
+ * <init-param>
+ * <param-name>org.apache.olingo.odata2.processor.factory</param-name>
+ * <param-value>foo.bar.sample.processor.SampleProcessorFactory</param-value>
+ * </init-param>
+ * <init-param>
+ * <param-name>org.apache.olingo.odata2.path.split</param-name>
+ * <param-value>2</param-value>
+ * </init-param>
+ * <load-on-startup>1</load-on-startup>
+ * </servlet>
+ * } </pre>
+ */
+
+public abstract class ODataJPAServiceFactory extends ODataServiceFactory {
+
+ private ODataJPAContext oDataJPAContext;
+ private ODataContext oDataContext;
+ private boolean setDetailErrors = false;
+
+ /**
+ * Creates an OData Service based on the values set in
+ * {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext} and
+ * {@link org.apache.olingo.odata2.api.processor.ODataContext}.
+ */
+ @Override
+ public final ODataService createService(final ODataContext ctx) throws ODataException {
+
+ oDataContext = ctx;
+
+ // Initialize OData JPA Context
+ oDataJPAContext = initializeODataJPAContext();
+
+ validatePreConditions();
+
+ ODataJPAFactory factory = ODataJPAFactory.createFactory();
+ ODataJPAAccessFactory accessFactory = factory.getODataJPAAccessFactory();
+
+ // OData JPA Processor
+ if (oDataJPAContext.getODataContext() == null) {
+ oDataJPAContext.setODataContext(ctx);
+ }
+
+ ODataSingleProcessor odataJPAProcessor = accessFactory.createODataProcessor(oDataJPAContext);
+
+ // OData Entity Data Model Provider based on JPA
+ EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);
+
+ return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
+ }
+
+ private void validatePreConditions() throws ODataJPARuntimeException {
+
+ if (oDataJPAContext.getEntityManagerFactory() == null) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED, null);
+ }
+
+ }
+
+ /**
+ * Implement this method and initialize OData JPA Context. It is mandatory
+ * to set an instance of type {@link javax.persistence.EntityManagerFactory} into the context. An exception of type
+ * {@link org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException} is thrown if
+ * EntityManagerFactory is not initialized. <br>
+ * <br>
+ * <b>Sample Code:</b> <code>
+ * <p>public class JPAReferenceServiceFactory extends ODataJPAServiceFactory{</p>
+ *
+ * <blockquote>private static final String PUNIT_NAME = "punit";
+ * <br>
+ * public ODataJPAContext initializeODataJPAContext() {
+ * <blockquote>ODataJPAContext oDataJPAContext = this.getODataJPAContext();
+ * <br>
+ * EntityManagerFactory emf = Persistence.createEntityManagerFactory(PUNIT_NAME);
+ * <br>
+ * oDataJPAContext.setEntityManagerFactory(emf);
+ * oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
+ * <br> return oDataJPAContext;</blockquote>
+ * }</blockquote>
+ * } </code>
+ * <p>
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext}
+ * @throws ODataJPARuntimeException
+ */
+ public abstract ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException;
+
+ /**
+ * @return an instance of type {@link ODataJPAContext}
+ * @throws ODataJPARuntimeException
+ */
+ public final ODataJPAContext getODataJPAContext() throws ODataJPARuntimeException {
+ if (oDataJPAContext == null) {
+ oDataJPAContext = ODataJPAFactory.createFactory().getODataJPAAccessFactory().createODataJPAContext();
+ }
+ if (oDataContext != null) {
+ oDataJPAContext.setODataContext(oDataContext);
+ }
+ return oDataJPAContext;
+
+ }
+
+ /**
+ * The method sets the context whether a detail error message should be thrown
+ * or a less detail error message should be thrown by the library.
+ * @param setDetailErrors takes
+ * <ul><li>true - to indicate that library should throw a detailed error message</li>
+ * <li>false - to indicate that library should not throw a detailed error message</li>
+ * </ul>
+ *
+ */
+ protected void setDetailErrors(final boolean setDetailErrors) {
+ this.setDetailErrors = setDetailErrors;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
+ if (setDetailErrors == true) {
+ if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
+ return (T) new ODataJPAErrorCallback();
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmBuilder.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmBuilder.java
new file mode 100644
index 0000000..01b9d9f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmBuilder.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+
+/**
+ * JPAEdmBuilder interface provides methods for building elements of an Entity Data Model (EDM) from
+ * a Java Persistence Model.
+ *
+ *
+ *
+ */
+public interface JPAEdmBuilder {
+ /**
+ * The Method builds EDM Elements by transforming JPA MetaModel. The method
+ * processes EDM JPA Containers which could be accessed using the following
+ * views,
+ * <ul>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView} </li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmBaseView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView} </li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView} </li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmModelView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView} </li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView} </li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView} </li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView}</li>
+ * </ul>
+ *
+ * @throws ODataJPARuntimeException
+ **/
+ public void build() throws ODataJPAModelException, ODataJPARuntimeException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmMappingModelAccess.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmMappingModelAccess.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmMappingModelAccess.java
new file mode 100644
index 0000000..f4420dc
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAEdmMappingModelAccess.java
@@ -0,0 +1,191 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+import org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEdmMappingModel;
+
+/**
+ * Interface provides methods to access JPA EDM mapping model.
+ *
+ *
+ * @see JPAEdmMappingModel
+ *
+ */
+public interface JPAEdmMappingModelAccess {
+
+ /**
+ * The method searches and loads the mapping model stored in <file>.xml
+ * file into the java object {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEdmMappingModel} . The
+ * name of the file is set into ODataJPAContext method.
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext#setJPAEdmMappingModel(String)
+ */
+ public void loadMappingModel();
+
+ /**
+ * The method returns if there exists a mapping model.
+ *
+ * @return true - if there exists a mapping model for the OData service else
+ * false
+ */
+ public boolean isMappingModelExists();
+
+ /**
+ * The method returns a JPA EDM mapping model Java object. The mapping model
+ * in XML files is un-marshaled into the Java object.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEdmMappingModel}
+ */
+ public JPAEdmMappingModel getJPAEdmMappingModel();
+
+ /**
+ * The method returns EDM Schema namespace for the persistence unit name
+ *
+ * @param persistenceUnitName
+ * is the Java persistence unit name
+ * @return EDM schema name space mapped to Java persistence unit name or
+ * null if no mapping is available
+ */
+ public String mapJPAPersistenceUnit(String persistenceUnitName);
+
+ /**
+ * The method returns EDM entity type name for the Java persistence entity
+ * type name
+ *
+ * @param jpaEntityTypeName
+ * is the Java persistence entity type name
+ * @return EDM entity type name mapped to Java persistence entity type name
+ * or null if no mapping is available
+ */
+ public String mapJPAEntityType(String jpaEntityTypeName);
+
+ /**
+ * The method returns EDM entity set name for the Java persistence entity
+ * type name
+ *
+ * @param jpaEntityTypeName
+ * is the Java persistence entity type name
+ * @return EDM entity set name mapped to Java persistence entity type name
+ * or null if no mapping is available
+ */
+ public String mapJPAEntitySet(String jpaEntityTypeName);
+
+ /**
+ * The method returns EDM property name for the Java persistence entity
+ * attribute name.
+ *
+ * @param jpaEntityTypeName
+ * is the Java persistence entity type name
+ * @param jpaAttributeName
+ * is the Java persistence attribute name
+ * @return EDM property name mapped to Java persistence attribute name or
+ * null if no mapping is available
+ */
+ public String mapJPAAttribute(String jpaEntityTypeName, String jpaAttributeName);
+
+ /**
+ * The method returns EDM navigation property name for the Java persistence
+ * entity relationship name.
+ *
+ * @param jpaEntityTypeName
+ * is the Java persistence entity type name
+ * @param jpaRelationshipName
+ * is the Java persistence relationship name
+ * @return EDM navigation property name mapped to Java persistence entity
+ * relationship name or null if no mapping is available
+ */
+ public String mapJPARelationship(String jpaEntityTypeName, String jpaRelationshipName);
+
+ /**
+ * The method returns EDM complex type name for the Java embeddable type
+ * name.
+ *
+ * @param jpaEmbeddableTypeName
+ * is the Java persistence embeddable type name
+ * @return EDM complex type name mapped to Java persistence entity
+ * relationship name or null if no mapping is available
+ */
+ public String mapJPAEmbeddableType(String jpaEmbeddableTypeName);
+
+ /**
+ * The method returns EDM property name for the Java persistence embeddable
+ * type's attribute name.
+ *
+ * @param jpaEmbeddableTypeName
+ * is the Java persistence
+ * @param jpaAttributeName
+ * is the Java persistence attribute name
+ * @return EDM property name mapped to Java persistence attribute name or
+ * null if no mapping is available
+ */
+ public String mapJPAEmbeddableTypeAttribute(String jpaEmbeddableTypeName, String jpaAttributeName);
+
+ /**
+ * The method returns whether the JPA Entity should be excluded from EDM
+ * model
+ *
+ * @param jpaEntityTypeName
+ * is the name of JPA Entity Type
+ * @return <b>true</b> - if JPA Entity should be excluded<br>
+ * <b>false</b> - if JPA Entity should be not be excluded
+ *
+ */
+ public boolean checkExclusionOfJPAEntityType(String jpaEntityTypeName);
+
+ /**
+ * The method returns whether the JPA Attribute should be excluded from EDM
+ * Entity Type
+ *
+ * @param jpaEntityTypeName
+ * is the name of JPA Entity Type
+ * @param jpaAttributeName
+ * is the name of JPA attribute
+ * @return <b>true</b> - if JPA attribute should be excluded<br>
+ * <b>false</b> - if JPA attribute should be not be excluded
+ *
+ */
+ public boolean checkExclusionOfJPAAttributeType(String jpaEntityTypeName, String jpaAttributeName);
+
+ /**
+ * The method returns whether the JPA Embeddable Type should be excluded
+ * from EDM model
+ *
+ * @param jpaEmbeddableTypeName
+ * is the name of JPA Embeddable Type
+ * @return <b>true</b> - if JPA Embeddable Type should be excluded<br>
+ * <b>false</b> - if JPA Embeddable Type should be not be excluded
+ *
+ */
+ public boolean checkExclusionOfJPAEmbeddableType(String jpaEmbeddableTypeName);
+
+ /**
+ * The method returns whether the JPA Embeddable Attribute Type should be
+ * excluded from EDM model
+ *
+ * @param jpaEmbeddableTypeName
+ * is the name of JPA Embeddable Attribute Type
+ * @param jpaAttributeName
+ * is the name of JPA Attribute name
+ * @return <b>true</b> - if JPA Embeddable Attribute Type should be excluded<br>
+ * <b>false</b> - if JPA Embeddable Attribute Type should be not be
+ * excluded
+ *
+ */
+ public boolean checkExclusionOfJPAEmbeddableAttributeType(String jpaEmbeddableTypeName, String jpaAttributeName);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAFunction.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAFunction.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAFunction.java
new file mode 100644
index 0000000..a380e33
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAFunction.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+/**
+ * A container for JPA Functions. A JPA function can be
+ * <ol>
+ * <li>Property Access method</li>
+ * <li>Custom Operation (Annotated with EDM Annotation FunctionImport)</li>
+ * </ol>
+ *
+ *
+ *
+ */
+public class JPAFunction {
+
+ private Method function;
+ private Class<?>[] parameterTypes;
+ private Type returnType;
+ private Object[] args;
+
+ public JPAFunction(final Method function, final Class<?>[] parameterTypes, final Type returnType,
+ final Object[] args) {
+ this.function = function;
+ this.parameterTypes = parameterTypes;
+ this.returnType = returnType;
+ this.args = args;
+ }
+
+ /**
+ * The method returns the Java method.
+ *
+ * @return an instance of {@link java.lang.reflect.Method}
+ */
+ public Method getFunction() {
+ return function;
+ }
+
+ /**
+ * The method returns the parameter types for the Java method.
+ *
+ * @return an array of type {@link java.lang.Class}
+ */
+ public Class<?>[] getParameterTypes() {
+ return parameterTypes;
+ }
+
+ /**
+ * The method returns the return type for the Java method.
+ *
+ * @return an instance of {@link java.lang.reflect.Type}
+ */
+ public Type getReturnType() {
+ return returnType;
+ }
+
+ /**
+ * The method returns an array of arguments for invoking the Java method.
+ *
+ * @return an array of Objects
+ */
+ public Object[] getArguments() {
+ return args;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAJoinClause.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAJoinClause.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAJoinClause.java
new file mode 100644
index 0000000..007c508
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAJoinClause.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+/**
+ * A container for Java Persistence Join Clause that can be used for building
+ * JPQL statements. The container has two main elements <b>
+ * <ol>
+ * <li>Java Persistence Entity -</li> is the source entity participating in the
+ * join. <br>
+ * <li>Java Persistence Entity Relationship -</li> is the entity relationship of
+ * the source entity participating in the join.
+ * </ol>
+ * </b>
+ *
+ *
+ *
+ */
+public class JPAJoinClause {
+
+ /**
+ * Enumerated list of possible Joins in JPQL
+ * <ol>
+ * <li>LEFT - left outer join</li>
+ * <li>FETCH - enable fetching of an association as a side effect of the
+ * execution of a query</li>
+ * <li>INNER - inner join
+ * </ol>
+ *
+ *
+ *
+ */
+ public enum JOIN {
+ LEFT, FETCH, INNER
+ }
+
+ private String entityName;
+ private String entityAlias;
+ private String entityRelationShip;
+ private String entityRelationShipAlias;
+ private JOIN joinType;
+ private String joinCondition;
+
+ /**
+ * The method returns Java Persistence Entity participating in the join.
+ *
+ * @return an entity name
+ */
+ public String getEntityName() {
+ return entityName;
+ }
+
+ /**
+ * The method returns Java Persistence Entity alias name participating in
+ * the join.
+ *
+ * @return a entity alias name
+ */
+ public String getEntityAlias() {
+ return entityAlias;
+ }
+
+ /**
+ * The method returns Java Persistence Entity Relationship name
+ * participating in the join.
+ *
+ * @return entity alias relationship
+ */
+ public String getEntityRelationShip() {
+ return entityRelationShip;
+ }
+
+ /**
+ * The method returns Java Persistence Entity Relationship Alias name
+ * participating in the join.
+ *
+ * @return entity entity relationship alias
+ */
+ public String getEntityRelationShipAlias() {
+ return entityRelationShipAlias;
+ }
+
+ /**
+ * Constructor for creating elements of JPA Join Clause container.
+ *
+ * @param entityName
+ * is the name of the JPA entity participating in the join
+ * @param entityAlias
+ * is the alias for the JPA entity participating in the join
+ * @param entityRelationShip
+ * is the name of the JPA entity relationship participating in
+ * the join
+ * @param entityRelationShipAlias
+ * is the alias name of the JPA entity relationship participating
+ * in the join
+ * @param joinCondition
+ * is the condition on which the joins should occur
+ * @param joinType
+ * is the type of join {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause.JOIN} to execute
+ */
+ public JPAJoinClause(final String entityName, final String entityAlias, final String entityRelationShip,
+ final String entityRelationShipAlias, final String joinCondition, final JOIN joinType) {
+
+ this.entityName = entityName;
+ this.entityAlias = entityAlias;
+ this.entityRelationShip = entityRelationShip;
+ this.entityRelationShipAlias = entityRelationShipAlias;
+ this.joinCondition = joinCondition;
+ this.joinType = joinType;
+ }
+
+ /**
+ * The method returns a join condition that can be used for building JPQL
+ * join statements.
+ *
+ * @return a join condition
+ */
+ public String getJoinCondition() {
+ return joinCondition;
+ }
+
+ /**
+ * The method returns the type of {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause.JOIN} that
+ * can be used for building JPQL join statements.
+ *
+ * @return join type
+ */
+ public JOIN getJoinType() {
+ return joinType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContext.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContext.java
new file mode 100644
index 0000000..9ad7c8c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContext.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAFactory;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+
+/**
+ * The abstract class is a compilation of objects required for building specific
+ * instances of JPA Method Context. Extend this class to implement specific
+ * implementations of JPQL context types (Create,Update,Function). A JPA method
+ * Context is constructed from an OData request. Depending on OData
+ * CUD/FunctionImport operation performed on an Entity, a corresponding JPA
+ * method context object is built. The object thus built can be used for
+ * executing operations on JPA Entity/Custom processor objects. <br>
+ * A default implementation is provided by the library.
+ *
+ *
+ * @see org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContextView
+ * @see org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType
+ *
+ */
+
+public abstract class JPAMethodContext implements JPAMethodContextView {
+
+ protected Object enclosingObject;
+ protected ArrayList<JPAFunction> jpaFunction;
+
+ @Override
+ /**
+ * The method returns list of JPA functions that can be executed on the
+ * enclosing object.
+ *
+ * @return an instance of list of JPA Function
+ */
+ public Object getEnclosingObject() {
+ return enclosingObject;
+ }
+
+ @Override
+ /**
+ * The method returns list of JPA functions that can be executed on the
+ * enclosing object.
+ *
+ * @return an instance of list of JPA Function
+ */
+ public List<JPAFunction> getJPAFunctionList() {
+ return jpaFunction;
+ }
+
+ protected void setEnclosingObject(final Object enclosingObject) {
+ this.enclosingObject = enclosingObject;
+ }
+
+ protected void setJpaFunction(final List<JPAFunction> jpaFunctionList) {
+ jpaFunction = (ArrayList<JPAFunction>) jpaFunctionList;
+ }
+
+ /**
+ * the method instantiates an instance of type JPAMethodContextBuilder.
+ *
+ * @param contextType
+ * indicates the type of JPQLContextBuilder to instantiate.
+ * @param resultsView
+ * is the OData request view
+ * @return {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAMethodContext.JPAMethodContextBuilder}
+ *
+ * @throws ODataJPARuntimeException
+ */
+ public final static JPAMethodContextBuilder
+ createBuilder(final JPQLContextType contextType, final Object resultsView) throws ODataJPARuntimeException {
+ return JPAMethodContextBuilder.create(contextType, resultsView);
+ }
+
+ /**
+ * The abstract class is extended by specific JPA Method Context Builder to
+ * build JPA Method Context types.
+ *
+ *
+ *
+ */
+ public static abstract class JPAMethodContextBuilder {
+
+ /**
+ * Implement this method to build JPAMethodContext
+ *
+ * @return an instance of type JPAMethodContext
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public abstract JPAMethodContext build() throws ODataJPAModelException, ODataJPARuntimeException;
+
+ protected JPAMethodContextBuilder() {}
+
+ private static JPAMethodContextBuilder create(final JPQLContextType contextType, final Object resultsView)
+ throws ODataJPARuntimeException {
+ JPAMethodContextBuilder contextBuilder =
+ ODataJPAFactory.createFactory().getJPQLBuilderFactory().getJPAMethodContextBuilder(contextType);
+
+ if (contextBuilder == null) {
+ throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE, null);
+ }
+ contextBuilder.setResultsView(resultsView);
+ return contextBuilder;
+ }
+
+ protected abstract void setResultsView(Object resultsView);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContextView.java
new file mode 100644
index 0000000..dc9a86d
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAMethodContextView.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+import java.util.List;
+
+/**
+ * The interface provides view on JPA Method Context. JPA Method context can be
+ * used to access custom operations or JPA Entity property access methods.
+ *
+ *
+ *
+ */
+public interface JPAMethodContextView {
+ /**
+ * The method returns an instance of Object on which the methods/custom
+ * operations can be executed.
+ *
+ * @return instance of enclosing object for the method
+ */
+ public Object getEnclosingObject();
+
+ /**
+ * The method returns list of JPA functions that can be executed on the
+ * enclosing object.
+ *
+ * @return an instance of list of JPA Function
+ */
+ public List<JPAFunction> getJPAFunctionList();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAProcessor.java
new file mode 100644
index 0000000..4b063cc
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/JPAProcessor.java
@@ -0,0 +1,260 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.access;
+
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+
+/**
+ * The interface provides methods for processing OData Requests for Create, Read, Update, Delete operations.
+ * Pass the OData request or parsed OData request (Map of properties) as request.
+ * A JPA entity is returned as a response.
+ *
+ */
+public interface JPAProcessor {
+ /**
+ * Processes OData request for querying an Entity Set. The method returns
+ * list of Objects of type representing JPA Entity Types.
+ *
+ * @param <T>
+ * Template parameter representing Java Persistence Entity Type.
+ * <p>
+ * <b>Note:-</b> Default parameter is Object.
+ * </p>
+ *
+ * @param requestView
+ * is an OData request for querying an entity set
+ * <p>
+ * @return list of objects representing JPA entity types
+ **/
+ public <T> List<T> process(GetEntitySetUriInfo requestView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for reading an Entity. The method returns an
+ * Object of type representing JPA Entity Type.
+ *
+ * @param <T>
+ * Template parameter representing Java Persistence Entity Type.
+ * <p>
+ * <b>Note:-</b> Default parameter is Object.
+ * </p>
+ *
+ * @param requestView
+ * OData request for reading an entity
+ *
+ * <p>
+ * @return object representing JPA entity type
+ **/
+ public <T> Object process(GetEntityUriInfo requestView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for fetching Entity count. The method returns JPA Entity count
+ *
+ * @param requestView
+ * OData request for counting an entity set
+ * @return long value representing count of JPA entity set
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+
+ public long process(GetEntitySetCountUriInfo requestView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for fetching Entity count. The method returns count of target entity.
+ * This is specific to situation where cardinality is 1:1
+ *
+ * @param resultsView
+ * OData request for counting target entity.
+ * @return long value representing count of JPA entity
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public long process(GetEntityCountUriInfo resultsView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for executing custom operations. The method
+ * returns a List of Object. The list contains one entry if the the custom
+ * operations return type has multiplicity of ONE.
+ *
+ * @param requestView
+ * OData request for executing function import
+ * @return result of executing function import
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public List<Object> process(GetFunctionImportUriInfo requestView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for executing $links OData command for N:1 relation.
+ * The method returns an Object of type representing OData entity.
+ *
+ * @param uriParserResultView
+ * OData request for Entity Link URI
+ * @return an object representing JPA entity
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public Object process(GetEntityLinkUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for executing $links OData command for N:1 relation.
+ * The method returns an Object of type representing OData entity.
+ *
+ * @param uriParserResultView
+ * OData request for Entity Set Link URI
+ * @return a list of object representing JPA entities
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public <T> List<T> process(GetEntitySetLinksUriInfo uriParserResultView)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for creating Entity. The method returns an Object
+ * which is created. A Null reference implies object was not created.
+ *
+ * @param createView
+ * @param content
+ * @param requestContentType
+ * @return Created Object
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+
+ public <T> List<T> process(PostUriInfo createView, InputStream content,
+ String requestContentType) throws ODataJPAModelException,
+ ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for creating Entity. The method expects a parsed OData request which is a Map of
+ * properties.
+ * The method returns an Object that is created. A Null reference implies object was not created.
+ *
+ * @param createView
+ * @param content
+ * @return Created Object
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+
+ public <T> List<T> process(PostUriInfo createView, Map<String, Object> content) throws ODataJPAModelException,
+ ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for updating Entity. The method returns an Object
+ * which is updated. A Null reference implies object was not created.
+ *
+ * @param updateView
+ * @param content
+ * @param requestContentType
+ * @return Deleted Object
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public <T> Object process(PutMergePatchUriInfo updateView,
+ InputStream content, String requestContentType)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for updating Entity. The method returns an Object
+ * which is updated. A Null reference implies object was not created.
+ *
+ * @param updateView
+ * @param content
+ * @return Deleted Object
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public <T> Object process(PutMergePatchUriInfo updateView, Map<String, Object> content)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Processes OData request for deleting Entity. The method returns an Object
+ * which is deleted. A Null reference implies object was not created.
+ *
+ * @param deleteuriInfo
+ * @param contentType
+ * @return Deleted Object
+ *
+ * @throws ODataJPAModelException
+ * @throws ODataJPARuntimeException
+ */
+ public Object process(DeleteUriInfo deleteuriInfo, String contentType)
+ throws ODataJPAModelException, ODataJPARuntimeException;
+
+ /**
+ * Process OData request for creating Links. The OData request should contain
+ * $links OData command.
+ *
+ * @param uriParserResultView
+ * OData request for creating Links
+ * @param content
+ * @param requestContentType
+ * @param contentType
+ *
+ * @throws ODataJPARuntimeException
+ * @throws ODataJPAModelException
+ */
+ public void process(PostUriInfo uriParserResultView,
+ InputStream content, String requestContentType, String contentType)
+ throws ODataJPARuntimeException, ODataJPAModelException;
+
+ /**
+ * Process OData request for updating Links. The OData request should contain
+ * $links OData command.
+ *
+ * @param uriParserResultView
+ * OData request for updating Links
+ * @param content
+ * @param requestContentType
+ * @param contentType
+ *
+ * @throws ODataJPARuntimeException
+ * @throws ODataJPAModelException
+ */
+ public void process(PutMergePatchUriInfo uriParserResultView,
+ InputStream content, String requestContentType, String contentType)
+ throws ODataJPARuntimeException, ODataJPAModelException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/package-info.java
new file mode 100644
index 0000000..d24f7a8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/access/package-info.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library - Java Persistence Access</h3>
+ * The library provides a set of APIs to access Java Persistence Models and Data.
+ *
+ *
+ */
+package org.apache.olingo.odata2.jpa.processor.api.access;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAErrorCallback.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAErrorCallback.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAErrorCallback.java
new file mode 100644
index 0000000..6d7e737
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/exception/ODataJPAErrorCallback.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.odata2.jpa.processor.api.exception;
+
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+
+public class ODataJPAErrorCallback implements ODataErrorCallback {
+
+ @Override
+ public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
+
+ final String SEPARATOR = " : ";
+
+ Throwable t = context.getException();
+ if (t instanceof ODataJPAException) {
+ StringBuilder errorBuilder = new StringBuilder();
+ errorBuilder.append(t.getCause().getClass().toString());
+ errorBuilder.append(SEPARATOR);
+ errorBuilder.append(t.getCause().getMessage());
+ context.setInnerError(errorBuilder.toString());
+ }
+ return EntityProvider.writeErrorDocument(context);
+ }
+
+}
[22/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLBuilderFactoryTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLBuilderFactoryTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLBuilderFactoryTest.java
new file mode 100644
index 0000000..a127e60
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLBuilderFactoryTest.java
@@ -0,0 +1,381 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.persistence.Cache;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnitUtil;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory;
+import org.apache.olingo.odata2.jpa.processor.api.factory.ODataJPAAccessFactory;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement.JPQLStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.ODataJPAContextImpl;
+import org.apache.olingo.odata2.jpa.processor.core.access.data.JPAProcessorImplTest;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.factory.ODataJPAFactoryImpl;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectSingleStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectStatementBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext.JPQLSelectContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleContext.JPQLSelectSingleContextBuilder;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class JPQLBuilderFactoryTest {
+
+ @Test
+ public void testGetStatementBuilderFactoryforSelect() throws ODataException {
+
+ GetEntitySetUriInfo getEntitySetView = getUriInfo();
+
+ // Build JPQL Context
+ JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.SELECT, getEntitySetView).build();
+ JPQLStatementBuilder statementBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
+
+ assertTrue(statementBuilder instanceof JPQLSelectStatementBuilder);
+
+ }
+
+ @Test
+ public void testGetStatementBuilderFactoryforSelectSingle() throws ODataException {
+
+ GetEntityUriInfo getEntityView = getEntityUriInfo();
+
+ // Build JPQL Context
+ JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView).build();
+ JPQLStatementBuilder statementBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
+
+ assertTrue(statementBuilder instanceof JPQLSelectSingleStatementBuilder);
+
+ }
+
+ @Test
+ public void testGetStatementBuilderFactoryforJoinSelect() throws ODataException {
+
+ GetEntitySetUriInfo getEntitySetView = getUriInfo();
+
+ // Build JPQL Context
+ JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.JOIN, getEntitySetView).build();
+ JPQLStatementBuilder statementBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
+
+ assertTrue(statementBuilder instanceof JPQLJoinStatementBuilder);
+
+ }
+
+ @Test
+ public void testGetStatementBuilderFactoryforJoinSelectSingle() throws ODataException {
+
+ GetEntityUriInfo getEntityView = getEntityUriInfo();
+
+ // Build JPQL Context
+ JPQLContext selectContext = JPQLContext.createBuilder(JPQLContextType.JOIN_SINGLE, getEntityView).build();
+ JPQLStatementBuilder statementBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getStatementBuilder(selectContext);
+
+ assertTrue(statementBuilder instanceof JPQLJoinSelectSingleStatementBuilder);
+
+ }
+
+ @Test
+ public void testGetContextBuilderforDelete() throws ODataException {
+
+ // Build JPQL ContextBuilder
+ JPQLContextBuilder contextBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.DELETE);
+
+ assertNull(contextBuilder);
+
+ }
+
+ @Test
+ public void testGetContextBuilderforSelect() throws ODataException {
+
+ // Build JPQL ContextBuilder
+ JPQLContextBuilder contextBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.SELECT);
+
+ assertNotNull(contextBuilder);
+ assertTrue(contextBuilder instanceof JPQLSelectContextBuilder);
+
+ }
+
+ @Test
+ public void testGetContextBuilderforSelectSingle() throws ODataException {
+
+ // Build JPQL ContextBuilder
+ JPQLContextBuilder contextBuilder =
+ new ODataJPAFactoryImpl().getJPQLBuilderFactory().getContextBuilder(JPQLContextType.SELECT_SINGLE);
+
+ assertNotNull(contextBuilder);
+ assertTrue(contextBuilder instanceof JPQLSelectSingleContextBuilder);
+
+ }
+
+ private GetEntitySetUriInfo getUriInfo() throws EdmException {
+ GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class);
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("SOItem");
+ EasyMock.replay(edmEntityType);
+ OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
+ EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
+ EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
+ EasyMock.expect(getEntitySetView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
+ EasyMock.replay(startEdmEntityType, startEdmEntitySet);
+ EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression);
+ EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(null);
+ EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(null);
+ List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
+ EasyMock.expect(getEntitySetView.getNavigationSegments()).andStubReturn(navigationSegments);
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ try {
+ EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
+ EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
+
+ EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);
+
+ } catch (EdmException e2) {
+ fail("this should not happen");
+ }
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
+ EasyMock.replay(edmMapping, edmType, kpProperty, keyPredicate);
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ keyPredicates.add(keyPredicate);
+ EasyMock.expect(getEntitySetView.getKeyPredicates()).andStubReturn(keyPredicates);
+ EasyMock.replay(getEntitySetView);
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.replay(edmEntitySet);
+ return getEntitySetView;
+ }
+
+ private GetEntityUriInfo getEntityUriInfo() throws EdmException {
+ GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(edmEntityType.getKeyProperties()).andStubReturn(new ArrayList<EdmProperty>());
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("");
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.expect(getEntityView.getSelect()).andStubReturn(null);
+ EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
+ EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
+ EasyMock.expect(getEntityView.getStartEntitySet()).andStubReturn(startEdmEntitySet);
+ EasyMock.replay(startEdmEntityType, startEdmEntitySet);
+ EasyMock.replay(edmEntityType, edmEntitySet);
+ EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(new ArrayList<KeyPredicate>());
+ List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
+ EasyMock.expect(getEntityView.getNavigationSegments()).andStubReturn(navigationSegments);
+ EasyMock.replay(getEntityView);
+ return getEntityView;
+ }
+
+ @Test
+ public void testJPAAccessFactory() {
+ ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
+ JPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getJPAAccessFactory();
+ ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
+ Class<?> clazz = oDataJPAContextImpl.getClass();
+ try {
+ Field field = clazz.getDeclaredField("em");
+ field.setAccessible(true);
+ field.set(oDataJPAContextImpl, new JPAProcessorImplTest().getLocalEntityManager());
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EntityManagerFactory emf = new EntityManagerFactory() {
+
+ @Override
+ public boolean isOpen() {
+ return false;
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return null;
+ }
+
+ @Override
+ public PersistenceUnitUtil getPersistenceUnitUtil() {
+ return null;
+ }
+
+ @Override
+ public Metamodel getMetamodel() {
+ return null;
+ }
+
+ @Override
+ public CriteriaBuilder getCriteriaBuilder() {
+ return null;
+ }
+
+ @Override
+ public Cache getCache() {
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public EntityManager createEntityManager(final Map arg0) {
+ return null;
+ }
+
+ @Override
+ public EntityManager createEntityManager() {
+ return null;
+ }
+
+ @Override
+ public void close() {}
+ };
+ oDataJPAContextImpl.setEntityManagerFactory(emf);
+ oDataJPAContextImpl.setPersistenceUnitName("pUnit");
+
+ assertNotNull(jpaAccessFactory.getJPAProcessor(oDataJPAContextImpl));
+ assertNotNull(jpaAccessFactory.getJPAEdmModelView(oDataJPAContextImpl));
+
+ }
+
+ @Test
+ public void testOdataJpaAccessFactory() {
+
+ ODataJPAFactoryImpl oDataJPAFactoryImpl = new ODataJPAFactoryImpl();
+ ODataJPAAccessFactory jpaAccessFactory = oDataJPAFactoryImpl.getODataJPAAccessFactory();
+ ODataJPAContextImpl oDataJPAContextImpl = new ODataJPAContextImpl();
+
+ EntityManagerFactory emf = new EntityManagerFactory() {
+
+ @Override
+ public boolean isOpen() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public PersistenceUnitUtil getPersistenceUnitUtil() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Metamodel getMetamodel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public CriteriaBuilder getCriteriaBuilder() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Cache getCache() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public EntityManager createEntityManager(final Map arg0) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public EntityManager createEntityManager() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+ };
+ oDataJPAContextImpl.setEntityManagerFactory(emf);
+ oDataJPAContextImpl.setPersistenceUnitName("pUnit");
+
+ assertNotNull(jpaAccessFactory.getODataJPAMessageService(new Locale("en")));
+ assertNotNull(jpaAccessFactory.createODataJPAContext());
+ assertNotNull(jpaAccessFactory.createJPAEdmProvider(oDataJPAContextImpl));
+ assertNotNull(jpaAccessFactory.createODataProcessor(oDataJPAContextImpl));
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinContextTest.java
new file mode 100644
index 0000000..33e44e2
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinContextTest.java
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmAssociation;
+import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectContext.JPQLJoinContextBuilder;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPQLJoinContextTest {
+
+ GetEntitySetUriInfo entitySetUriInfo;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {}
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {}
+
+ @Before
+ public void setUp() throws Exception {
+ entitySetUriInfo = EasyMock.createMock(GetEntitySetUriInfo.class);
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
+ final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
+ final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
+ final List<KeyPredicate> keyPredicates = createKeyPredicates();
+ NavigationSegment navigationSegment = new NavigationSegment() {
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty() {
+ return navigationProperty;
+ }
+
+ @Override
+ public List<KeyPredicate> getKeyPredicates() {
+ return keyPredicates;
+ }
+
+ @Override
+ public EdmEntitySet getEntitySet() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ NavigationSegment navigationSegment1 = new NavigationSegment() {
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty() {
+ return navigationProperty1;
+ }
+
+ @Override
+ public List<KeyPredicate> getKeyPredicates() {
+ return keyPredicates;
+ }
+
+ @Override
+ public EdmEntitySet getEntitySet() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ navigationSegments.add(navigationSegment);
+ navigationSegments.add(navigationSegment1);
+ EasyMock.expect(entitySetUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
+ EasyMock.expect(entitySetUriInfo.getOrderBy()).andStubReturn(null);
+ EasyMock.expect(entitySetUriInfo.getTop()).andStubReturn(null);
+ EasyMock.expect(entitySetUriInfo.getSkip()).andStubReturn(null);
+ EasyMock.expect(entitySetUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(entitySetUriInfo.getFilter()).andStubReturn(null);
+ EasyMock.expect(entitySetUriInfo.getKeyPredicates()).andStubReturn(keyPredicates);
+ EasyMock.expect(entitySetUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
+ EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
+ EasyMock.expect(entitySetUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
+ EasyMock.replay(startEdmEntityType, startEdmEntitySet);
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
+ EasyMock.replay(edmEntityType, edmEntitySet, entitySetUriInfo);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {}
+
+ @Test
+ public void testGetJPAOuterJoinClauses() {
+ JPQLJoinSelectContext joinContext = new JPQLJoinSelectContext(false);
+ JPQLJoinContextBuilder joinContextBuilder = joinContext.new JPQLJoinContextBuilder();
+ try {
+ joinContextBuilder.entitySetView = entitySetUriInfo;
+ joinContextBuilder.build();
+ } catch (ODataJPAModelException e) {
+ fail("Should not come here");
+ } catch (ODataJPARuntimeException e) {
+ fail("Should not come here");
+ }
+ List<JPAJoinClause> joinClauses = joinContext.getJPAJoinClauses();
+ assertNotNull(joinClauses);
+ assertTrue(joinClauses.size() > 0);
+ assertEquals("E1", joinClauses.get(0).getEntityAlias());
+ assertEquals("SOHeader", joinClauses.get(0).getEntityName());
+ assertEquals("s_Itema", joinClauses.get(1).getEntityRelationShip());
+ assertEquals("R1", joinClauses.get(1).getEntityRelationShipAlias());
+ }
+
+ private EdmNavigationProperty createNavigationProperty(final String z) throws EdmException {
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
+ EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
+ EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("roleA" + z);
+ EasyMock.expect(navigationProperty.getToRole()).andStubReturn("roleB" + z);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
+ EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("sItem" + z);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("soItem" + z);
+ EasyMock.expect(associationEnd.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.expect(association.getEnd("roleA" + z)).andStubReturn(associationEnd);
+ EasyMock.expect(navigationProperty.getRelationship()).andStubReturn(association);
+ EdmMapping edmMapping1 = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping1.getInternalName()).andStubReturn("s_Item" + z);
+ EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping1);
+ EasyMock.replay(edmMapping, edmMapping1, edmEntityType, associationEnd, association, navigationProperty);
+ return navigationProperty;
+ }
+
+ private List<KeyPredicate> createKeyPredicates() throws EdmException {
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
+
+ EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ keyPredicates.add(keyPredicate);
+ return keyPredicates;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContextTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContextTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContextTest.java
new file mode 100644
index 0000000..de5532c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleContextTest.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmAssociation;
+import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectSingleContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectSingleContext.JPQLJoinSelectSingleContextBuilder;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPQLJoinSelectSingleContextTest {
+
+ GetEntityUriInfo entityUriInfo;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {}
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {}
+
+ public void setUp(final boolean toThrowException) throws Exception {
+ entityUriInfo = EasyMock.createMock(GetEntityUriInfo.class);
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ List<NavigationSegment> navigationSegments = new ArrayList<NavigationSegment>();
+ final EdmNavigationProperty navigationProperty = createNavigationProperty("a");
+ final EdmNavigationProperty navigationProperty1 = createNavigationProperty("b");
+ final List<KeyPredicate> keyPredicates = createKeyPredicates(toThrowException);
+ NavigationSegment navigationSegment = new NavigationSegment() {
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty() {
+ return navigationProperty;
+ }
+
+ @Override
+ public List<KeyPredicate> getKeyPredicates() {
+ return keyPredicates;
+ }
+
+ @Override
+ public EdmEntitySet getEntitySet() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ NavigationSegment navigationSegment1 = new NavigationSegment() {
+
+ @Override
+ public EdmNavigationProperty getNavigationProperty() {
+ return navigationProperty1;
+ }
+
+ @Override
+ public List<KeyPredicate> getKeyPredicates() {
+ return keyPredicates;
+ }
+
+ @Override
+ public EdmEntitySet getEntitySet() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ };
+ navigationSegments.add(navigationSegment);
+ navigationSegments.add(navigationSegment1);
+ EasyMock.expect(entityUriInfo.getNavigationSegments()).andStubReturn(navigationSegments);
+ EasyMock.expect(entityUriInfo.getSelect()).andStubReturn(null);
+ EasyMock.expect(entityUriInfo.getFilter()).andStubReturn(null);
+ EasyMock.expect(entityUriInfo.getKeyPredicates()).andStubReturn(createKeyPredicates(toThrowException));
+ EasyMock.expect(entityUriInfo.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EdmEntitySet startEdmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType startEdmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(startEdmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(startEdmEntityType.getName()).andStubReturn("SOHeader");
+ EasyMock.expect(startEdmEntitySet.getEntityType()).andStubReturn(startEdmEntityType);
+ EasyMock.expect(entityUriInfo.getStartEntitySet()).andStubReturn(startEdmEntitySet);
+ EasyMock.replay(startEdmEntityType, startEdmEntitySet);
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("SOHeader");
+ EasyMock.replay(edmEntityType, edmEntitySet, entityUriInfo);
+
+ }
+
+ @After
+ public void tearDown() throws Exception {}
+
+ @Test
+ public void testGetJPAOuterJoinClauses() throws Exception {
+ setUp(false);
+
+ JPQLJoinSelectSingleContext joinContext = new JPQLJoinSelectSingleContext();
+ JPQLJoinSelectSingleContextBuilder joinContextBuilder = joinContext.new JPQLJoinSelectSingleContextBuilder();
+ try {
+ joinContextBuilder.entityView = entityUriInfo;
+ joinContextBuilder.build();
+ } catch (ODataJPAModelException e) {
+ fail("Should not come here");
+ } catch (ODataJPARuntimeException e) {
+ fail("Should not come here");
+ }
+ List<JPAJoinClause> joinClauses = joinContext.getJPAJoinClauses();
+ assertNotNull(joinClauses);
+ assertTrue(joinClauses.size() > 0);
+ assertEquals("E1", joinClauses.get(0).getEntityAlias());
+ assertEquals("SOHeader", joinClauses.get(0).getEntityName());
+ assertEquals("s_Itema", joinClauses.get(1).getEntityRelationShip());
+ assertEquals("R1", joinClauses.get(1).getEntityRelationShipAlias());
+ }
+
+ @Test
+ public void testExceptionThrown() throws Exception {
+ setUp(true);
+ JPQLJoinSelectSingleContext joinContext = new JPQLJoinSelectSingleContext();
+ JPQLJoinSelectSingleContextBuilder joinContextBuilder = joinContext.new JPQLJoinSelectSingleContextBuilder();
+ try {
+ joinContextBuilder.entityView = entityUriInfo;
+ joinContextBuilder.build();
+ fail("Should not come here");
+ } catch (ODataJPAModelException e) {
+ fail("Should not come here");
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+ private EdmNavigationProperty createNavigationProperty(final String z) throws EdmException {
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ EdmAssociation association = EasyMock.createMock(EdmAssociation.class);
+ EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
+ EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("roleA" + z);
+ EasyMock.expect(navigationProperty.getToRole()).andStubReturn("roleB" + z);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("navP" + z);
+ EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("sItem" + z);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("soItem" + z);
+ EasyMock.expect(associationEnd.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.expect(association.getEnd("roleA" + z)).andStubReturn(associationEnd);
+ EasyMock.expect(navigationProperty.getRelationship()).andStubReturn(association);
+ EdmMapping edmMapping1 = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping1.getInternalName()).andStubReturn("s_Item" + z);
+ EasyMock.expect(navigationProperty.getMapping()).andStubReturn(edmMapping1);
+ EasyMock.replay(edmMapping, edmMapping1, edmEntityType, associationEnd, association, navigationProperty);
+ return navigationProperty;
+ }
+
+ private List<KeyPredicate> createKeyPredicates(final boolean toThrowException) throws EdmException {
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.expect(edmProperty.getName()).andStubReturn("soid");
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ if (toThrowException) {
+ EasyMock.expect(edmProperty.getType()).andStubThrow(new EdmException(null));
+ } else {
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ }
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
+
+ EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ keyPredicates.add(keyPredicate);
+ return keyPredicates;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilderTest.java
new file mode 100644
index 0000000..13f1ca5
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinSelectSingleStatementBuilderTest.java
@@ -0,0 +1,143 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLJoinSelectSingleContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinSelectSingleStatementBuilder;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPQLJoinSelectSingleStatementBuilderTest {
+ JPQLJoinSelectSingleContextView context = null;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {}
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {}
+
+ public void setUp(final List<JPAJoinClause> joinClauseList) throws Exception {
+ context = EasyMock.createMock(JPQLJoinSelectSingleContextView.class);
+ EasyMock.expect(context.getJPAEntityAlias()).andStubReturn("gt1");
+ EasyMock.expect(context.getJPAEntityName()).andStubReturn("SOHeader");
+ EasyMock.expect(context.getType()).andStubReturn(JPQLContextType.SELECT);
+ EasyMock.expect(context.getKeyPredicates()).andStubReturn(createKeyPredicates());
+ EasyMock.expect(context.getSelectExpression()).andStubReturn("gt1");
+ EasyMock.expect(context.getJPAJoinClauses()).andStubReturn(joinClauseList);
+ EasyMock.replay(context);
+ }
+
+ private List<JPAJoinClause> getJoinClauseList() {
+ List<JPAJoinClause> joinClauseList = new ArrayList<JPAJoinClause>();
+ JPAJoinClause jpaOuterJoinClause =
+ new JPAJoinClause("SOHeader", "soh", null, null, "soh.soId = 1", JPAJoinClause.JOIN.LEFT);
+ joinClauseList.add(jpaOuterJoinClause);
+ jpaOuterJoinClause =
+ new JPAJoinClause("SOHeader", "soh", "soItem", "soi", "soi.shId = soh.soId", JPAJoinClause.JOIN.LEFT);
+ joinClauseList.add(jpaOuterJoinClause);
+ jpaOuterJoinClause =
+ new JPAJoinClause("SOItem", "si", "material", "mat", "mat.id = 'abc'", JPAJoinClause.JOIN.LEFT);
+ joinClauseList.add(jpaOuterJoinClause);
+ return joinClauseList;
+ }
+
+ @After
+ public void tearDown() throws Exception {}
+
+ @Test
+ public void testBuild() throws Exception {
+ setUp(getJoinClauseList());
+ JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
+ new JPQLJoinSelectSingleStatementBuilder(context);
+ try {
+ JPQLStatement jpqlStatement = jpqlJoinSelectsingleStatementBuilder.build();
+ assertEquals(
+ "SELECT gt1 FROM SOHeader soh JOIN soh.soItem soi JOIN soi.material mat WHERE soh.soId = 1 AND " +
+ "soi.shId = soh.soId AND mat.id = 'abc'",
+ jpqlStatement.toString());
+ } catch (ODataJPARuntimeException e) {
+ fail("Should not have come here");
+ }
+
+ }
+
+ private List<KeyPredicate> createKeyPredicates() throws EdmException {
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("soid");
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ EasyMock.expect(edmProperty.getType()).andStubReturn(edmType);
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(edmProperty);
+
+ EasyMock.replay(edmType, edmMapping, edmProperty, keyPredicate);
+ List<KeyPredicate> keyPredicates = new ArrayList<KeyPredicate>();
+ keyPredicates.add(keyPredicate);
+ return keyPredicates;
+ }
+
+ @Test
+ public void testJoinClauseAsNull() throws Exception {
+ setUp(null);
+ JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
+ new JPQLJoinSelectSingleStatementBuilder(context);
+ try {
+ jpqlJoinSelectsingleStatementBuilder.build();
+ fail("Should not have come here");
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testJoinClauseListAsEmpty() throws Exception {
+ List<JPAJoinClause> joinClauseList = new ArrayList<JPAJoinClause>();
+ setUp(joinClauseList);
+ JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
+ new JPQLJoinSelectSingleStatementBuilder(context);
+ try {
+ jpqlJoinSelectsingleStatementBuilder.build();
+ fail("Should not have come here");
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilderTest.java
new file mode 100644
index 0000000..e1637d1
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLJoinStatementBuilderTest.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAJoinClause;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLJoinContextView;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLJoinStatementBuilder;
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPQLJoinStatementBuilderTest {
+ JPQLJoinContextView context = null;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {}
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {}
+
+ public void setUp(final List<JPAJoinClause> joinClauseList) throws Exception {
+ context = EasyMock.createMock(JPQLJoinContextView.class);
+ EasyMock.expect(context.getJPAEntityAlias()).andStubReturn("mat");
+ EasyMock.expect(context.getJPAEntityName()).andStubReturn("SOHeader");
+ EasyMock.expect(context.getType()).andStubReturn(JPQLContextType.SELECT);
+ EasyMock.expect(context.getSelectExpression()).andStubReturn("mat");
+ EasyMock.expect(context.getWhereExpression()).andStubReturn("soh.buyerId = 2");
+ HashMap<String, String> orderByMap = new HashMap<String, String>();
+ orderByMap.put("mat.buyerId", "asc");
+ orderByMap.put("mat.city", "desc");
+ EasyMock.expect(context.getOrderByCollection()).andStubReturn(orderByMap);
+ EasyMock.expect(context.getJPAJoinClauses()).andStubReturn(joinClauseList);
+ EasyMock.replay(context);
+ }
+
+ private List<JPAJoinClause> getJoinClauseList() {
+ List<JPAJoinClause> joinClauseList = new ArrayList<JPAJoinClause>();
+ JPAJoinClause jpaOuterJoinClause =
+ new JPAJoinClause("SOHeader", "soh", null, null, "soh.createdBy = 'Peter'", JPAJoinClause.JOIN.LEFT);
+ joinClauseList.add(jpaOuterJoinClause);
+ jpaOuterJoinClause =
+ new JPAJoinClause("SOHeader", "soh", "soItem", "soi", "soi.shId = soh.soId", JPAJoinClause.JOIN.LEFT);
+ joinClauseList.add(jpaOuterJoinClause);
+ jpaOuterJoinClause =
+ new JPAJoinClause("SOItem", "si", "material", "mat", "mat.id = 'abc'", JPAJoinClause.JOIN.LEFT);
+ joinClauseList.add(jpaOuterJoinClause);
+ return joinClauseList;
+ }
+
+ @After
+ public void tearDown() throws Exception {}
+
+ @Test
+ public void testBuild() throws Exception {
+ setUp(getJoinClauseList());
+ JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
+ try {
+ JPQLStatement jpqlStatement = jpqlJoinStatementBuilder.build();
+ assertEquals(
+ "SELECT mat FROM SOHeader soh JOIN soh.soItem soi JOIN soi.material mat WHERE soh.buyerId = 2 AND "
+ +
+ "soh.createdBy = 'Peter' AND soi.shId = soh.soId AND mat.id = 'abc' "
+ +
+ "ORDER BY mat.buyerId asc , mat.city desc",
+ jpqlStatement.toString());
+ } catch (ODataJPARuntimeException e) {
+ fail("Should not have come here");
+ }
+
+ }
+
+ @Test
+ public void testJoinClauseAsNull() throws Exception {
+ setUp(null);
+ JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
+ try {
+ jpqlJoinStatementBuilder.build();
+ fail("Should not have come here");
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testJoinClauseListAsEmpty() throws Exception {
+ setUp(new ArrayList<JPAJoinClause>());
+ JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
+ try {
+ jpqlJoinStatementBuilder.build();
+ fail("Should not have come here");
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContextImplTest.java
new file mode 100644
index 0000000..03eb651
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectContextImplTest.java
@@ -0,0 +1,386 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+import org.apache.olingo.odata2.api.uri.expression.SortOrder;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext.JPQLSelectContextBuilder;
+import org.easymock.EasyMock;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPQLSelectContextImplTest {
+
+ private static String entityTypeName = "MockEntity";
+ private static String[] fields = { "Field1", "Field2" };
+ private static List<KeyPredicate> keyPredicates;
+ private static SortOrder[] orderType = { SortOrder.asc, SortOrder.desc };
+
+ private static JPQLSelectContextBuilder builder;
+ private static JPQLSelectContext selectContext;
+
+ @BeforeClass
+ public static void setup() {
+
+ }
+
+ private void buildSelectContext(final boolean orderByIsNull, final boolean selectFieldsIsNull,
+ final boolean filterIsNull, final boolean isTopNull, final boolean isSkipNull) {
+ builder = null;
+ selectContext = null;
+ keyPredicates = new ArrayList<KeyPredicate>();
+ GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);
+
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType1 = EasyMock.createMock(EdmType.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ try {
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("Field1");
+ EasyMock.expect(kpProperty.getMapping()).andStubReturn(mapping);
+ EasyMock.expect(kpProperty.getType()).andStubReturn(edmType1);
+
+ } catch (EdmException e2) {
+ fail("this should not happen");
+ }
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
+ EasyMock.replay(mapping, edmType1, kpProperty, keyPredicate);
+ keyPredicates.add(keyPredicate);
+ int i = 0;
+ List<OrderExpression> orderList = new ArrayList<OrderExpression>(2);
+ do {
+
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ try {
+ EasyMock.expect(edmType.getName()).andStubReturn(fields[i]);
+ EasyMock.replay(edmType);
+ } catch (EdmException e2) {
+ fail("Exception not Expected");
+ }
+
+ PropertyExpression commonExpression = EasyMock.createMock(PropertyExpression.class);
+ EasyMock.expect(commonExpression.getEdmType()).andStubReturn(edmType);
+
+ EdmProperty edmTyped = EasyMock.createMock(EdmProperty.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
+ try {
+ EasyMock.expect(edmTyped.getMapping()).andStubReturn(edmMapping);
+ } catch (EdmException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ EasyMock.expect(commonExpression.getEdmProperty()).andStubReturn(edmTyped);
+ OrderExpression order = EasyMock.createMock(OrderExpression.class);
+ EasyMock.expect(order.getExpression()).andStubReturn(commonExpression);
+ EasyMock.expect(order.getSortOrder()).andStubReturn(orderType[i]);
+ EasyMock.replay(edmMapping, edmTyped, commonExpression);
+ EasyMock.replay(order);
+
+ orderList.add(order);
+
+ } while (++i < 2);
+
+ OrderByExpression orderBy = EasyMock.createMock(OrderByExpression.class);
+ EasyMock.expect(orderBy.getOrders()).andStubReturn(orderList);
+ EasyMock.replay(orderBy);
+
+ try {
+ i = 0;
+ List<SelectItem> selectItemList = new ArrayList<SelectItem>(2);
+ do {
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.replay(edmMapping, edmProperty);
+
+ SelectItem selectItem = EasyMock.createMock(SelectItem.class);
+ EasyMock.expect(selectItem.getProperty()).andStubReturn(edmProperty);
+ EasyMock.replay(selectItem);
+
+ selectItemList.add(selectItem);
+
+ } while (++i < 2);
+ EasyMock.expect(entityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(entityType.getName()).andStubReturn(entityTypeName);
+ EasyMock.expect(entityType.getKeyProperties()).andStubReturn(getLocalKeyProperties());
+
+ EasyMock.replay(entityType);
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(entityType);
+ EasyMock.replay(entitySet);
+
+ EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
+ if (orderByIsNull) {
+ EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);
+ } else {
+ EasyMock.expect(resultsView.getOrderBy()).andStubReturn(orderBy);
+ }
+ if (selectFieldsIsNull) {
+ EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
+ } else {
+ EasyMock.expect(resultsView.getSelect()).andStubReturn(selectItemList);
+ }
+ // FilterExpression filterExpression =
+ // EasyMock.createMock(FilterExpression.class);
+ // EasyMock.expect(filterExpression.g)
+ if (filterIsNull) {
+ EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
+ } else {
+ EasyMock.expect(resultsView.getFilter()).andStubReturn(
+ getFilterExpressionMockedObj(ExpressionKind.PROPERTY, "SalesOrder"));
+ }
+ if (isTopNull) {
+ EasyMock.expect(resultsView.getTop()).andStubReturn(null);
+ } else {
+ EasyMock.expect(resultsView.getTop()).andStubReturn(10);
+ }
+ if (isSkipNull) {
+ EasyMock.expect(resultsView.getSkip()).andStubReturn(null);
+ } else {
+ EasyMock.expect(resultsView.getSkip()).andStubReturn(0);
+ }
+ EasyMock.expect(resultsView.getKeyPredicates()).andStubReturn(keyPredicates);
+ EasyMock.replay(resultsView);
+
+ } catch (EdmException e1) {
+ fail("Exception not Expected");
+ }
+ try {
+ builder = (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);
+
+ selectContext = (JPQLSelectContext) builder.build();
+ } catch (ODataJPAModelException e) {
+ fail("Exception not Expected");
+ } catch (ODataJPARuntimeException e) {
+ fail("Runtime Exception thrown");
+ }
+ }
+
+ private List<EdmProperty> getLocalKeyProperties() {
+ List<EdmProperty> propertyList = new ArrayList<EdmProperty>();
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("Field1");
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(null);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmProperty);
+ propertyList.add(edmProperty);
+ return propertyList;
+ }
+
+ @Test
+ public void testEntityNameThrowingException() {
+ // buildSelectContext(false, false, false);
+ GetEntitySetUriInfo resultsView = EasyMock.createMock(GetEntitySetUriInfo.class);
+
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+
+ try {
+ EasyMock.expect(entityType.getName()).andStubThrow(new EdmException(null));
+ EasyMock.expect(entitySet.getEntityType()).andStubThrow(new EdmException(null));
+ } catch (EdmException e1) {
+ // throw new ODataException();
+ }
+
+ EasyMock.replay(entityType);
+ EasyMock.replay(entitySet);
+
+ EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
+ EasyMock.expect(resultsView.getOrderBy()).andStubReturn(null);
+ EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
+ EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
+ EasyMock.replay(resultsView);
+ try {
+ JPQLSelectContextBuilder builder1 =
+ (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, resultsView);
+
+ builder1.build();
+ fail("Should not come here");
+ } catch (ODataJPAModelException e) {
+ fail();
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testSelectFieldsAsNull() {
+ buildSelectContext(false, true, true, true, true);
+
+ try {
+ selectContext = (JPQLSelectContext) builder.build();
+ assertEquals("E2", selectContext.getSelectExpression());
+ } catch (ODataJPAModelException e) {
+ fail();
+ } catch (ODataJPARuntimeException e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testGetOrderByCollection() {
+ buildSelectContext(false, false, true, true, true);
+ assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[0]));
+ assertEquals("", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[0]));
+
+ assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[1]));
+ assertEquals("DESC", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[1]));
+ }
+
+ @Test
+ public void testGetWhereExpression() {
+ buildSelectContext(false, false, true, true, true);
+ // fail("Not yet implemented");
+ }
+
+ @Test
+ public void testGetJPAEntityName() {
+ buildSelectContext(false, false, true, true, true);
+ assertEquals(JPQLSelectContextImplTest.entityTypeName, selectContext.getJPAEntityName());
+ }
+
+ @Test
+ public void testGetType() {
+ buildSelectContext(false, false, true, true, true);
+ assertEquals(JPQLContextType.SELECT, selectContext.getType());
+ }
+
+ @Test
+ public void testCreateBuilder() {
+ buildSelectContext(false, false, true, true, true);
+ assertEquals(JPQLSelectContextBuilder.class.toString(), builder.getClass().toString());
+ }
+
+ @Test
+ public void testEntitySetAsNull() {
+ buildSelectContext(false, false, true, true, true);
+ try {
+ JPQLSelectContextBuilder builder =
+ (JPQLSelectContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT, null);
+
+ JPQLSelectContext selectContext1 = (JPQLSelectContext) builder.build();
+ assertNull(selectContext1.getJPAEntityAlias());
+ assertNull(selectContext1.getJPAEntityName());
+ assertNull(selectContext1.getOrderByCollection());
+ assertNull(selectContext1.getSelectExpression());
+ assertNull(selectContext1.getType());
+ assertNull(selectContext1.getWhereExpression());
+ } catch (ODataJPAModelException e) {
+ fail("Exception not Expected");
+ } catch (ODataJPARuntimeException e) {
+ fail("Runtime Exception thrown");
+ }
+ }
+
+ @Test
+ public void testOrderingWithSkip() {
+ buildSelectContext(true, false, true, true, false);
+ assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[0]));
+ assertEquals("", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[0]));
+
+ assertEquals(false, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[1]));
+
+ }
+
+ @Test
+ public void testOrderingWithTop() {
+ buildSelectContext(true, false, true, false, true);
+ assertEquals(true, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[0]));
+ assertEquals("", selectContext.getOrderByCollection().get("E1." + JPQLSelectContextImplTest.fields[0]));
+
+ assertEquals(false, selectContext.getOrderByCollection().containsKey("E1." + JPQLSelectContextImplTest.fields[1]));
+
+ }
+
+ @Test
+ public void testOrderByTopSkipAsNull() {
+ buildSelectContext(true, true, true, true, true);
+ assertNull(selectContext.getOrderByCollection());
+ }
+
+ @Test
+ public void testFilter() {
+ buildSelectContext(true, false, false, false, false);
+ assertEquals("E1.field", selectContext.whereCondition);
+
+ }
+
+ private FilterExpression getFilterExpressionMockedObj(final ExpressionKind leftOperandExpKind,
+ final String propertyName) throws EdmException {
+ FilterExpression filterExpression = EasyMock.createMock(FilterExpression.class);
+ EasyMock.expect(filterExpression.getKind()).andStubReturn(ExpressionKind.FILTER);
+ EasyMock.expect(filterExpression.getExpression()).andStubReturn(
+ getPropertyExpressionMockedObj(leftOperandExpKind, propertyName));
+ EasyMock.replay(filterExpression);
+ return filterExpression;
+ }
+
+ private PropertyExpression getPropertyExpressionMockedObj(final ExpressionKind expKind, final String propertyName) {
+ PropertyExpression leftOperandPropertyExpresion = EasyMock.createMock(PropertyExpression.class);
+ EasyMock.expect(leftOperandPropertyExpresion.getKind()).andReturn(ExpressionKind.PROPERTY);
+ EasyMock.expect(leftOperandPropertyExpresion.getPropertyName()).andReturn(propertyName);
+ EdmProperty edmtTyped = EasyMock.createMock(EdmProperty.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("field");
+ try {
+ EasyMock.expect(edmtTyped.getMapping()).andStubReturn(mapping);
+ } catch (EdmException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ EasyMock.expect(leftOperandPropertyExpresion.getEdmProperty()).andReturn(edmtTyped);
+ EasyMock.replay(mapping, edmtTyped, leftOperandPropertyExpresion);
+ return leftOperandPropertyExpresion;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContextImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContextImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContextImplTest.java
new file mode 100644
index 0000000..69952fd
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleContextImplTest.java
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleContext.JPQLSelectSingleContextBuilder;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class JPQLSelectSingleContextImplTest {
+
+ private static String entityTypeName = "MockEntity";
+ private static String[] fields = { "Field1", "Field2" };
+ private static List<KeyPredicate> keyPredicates;
+
+ private static JPQLSelectSingleContextBuilder builder;
+ private static JPQLSelectSingleContext selectContext;
+
+ private void buildContextBuilder(final boolean isSelectNull) {
+ builder = null;
+ selectContext = null;
+ keyPredicates = new ArrayList<KeyPredicate>();
+ GetEntityUriInfo resultsView = EasyMock.createMock(GetEntityUriInfo.class);
+
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ try {
+ EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
+ EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
+
+ } catch (EdmException e2) {
+ fail("this should not happen");
+ }
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
+ EasyMock.replay(edmType, kpProperty, keyPredicate);
+ keyPredicates.add(keyPredicate);
+ int i = 0;
+ try {
+
+ List<SelectItem> selectItemList = new ArrayList<SelectItem>(2);
+ do {
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn(fields[i]);
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(edmMapping);
+ EasyMock.replay(edmMapping, edmProperty);
+
+ SelectItem selectItem = EasyMock.createMock(SelectItem.class);
+ EasyMock.expect(selectItem.getProperty()).andStubReturn(edmProperty);
+ EasyMock.replay(selectItem);
+
+ selectItemList.add(selectItem);
+
+ } while (++i < 2);
+
+ EasyMock.expect(entityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(entityType.getName()).andStubReturn(entityTypeName);
+ EasyMock.replay(entityType);
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(entityType);
+ EasyMock.replay(entitySet);
+
+ EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
+ if (isSelectNull) {
+ selectItemList = null;
+ }
+ EasyMock.expect(resultsView.getSelect()).andStubReturn(selectItemList);
+ ArrayList<KeyPredicate> arrayList = new ArrayList<KeyPredicate>();
+ arrayList.add(keyPredicate);
+ EasyMock.expect(resultsView.getKeyPredicates()).andStubReturn(arrayList);
+ EasyMock.replay(resultsView);
+
+ } catch (EdmException e1) {
+ fail("Exception not Expected");
+ }
+ try {
+ builder = (JPQLSelectSingleContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, resultsView);
+
+ selectContext = (JPQLSelectSingleContext) builder.build();
+ } catch (ODataJPAModelException e) {
+ fail("Exception not Expected");
+ } catch (ODataJPARuntimeException e) {
+ fail("Runtime Exception thrown");
+ }
+ }
+
+ @Test
+ public void testEntityNameThrowingException() {
+ // buildSelectContext(false, false, false);
+ GetEntityUriInfo resultsView = EasyMock.createMock(GetEntityUriInfo.class);
+
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+
+ try {
+ EasyMock.expect(entityType.getName()).andStubThrow(new EdmException(null));
+ EasyMock.expect(entitySet.getEntityType()).andStubThrow(new EdmException(null));
+ } catch (EdmException e1) {
+ // throw new ODataException();
+ }
+
+ EasyMock.replay(entityType);
+ EasyMock.replay(entitySet);
+
+ EasyMock.expect(resultsView.getTargetEntitySet()).andStubReturn(entitySet);
+ EasyMock.expect(resultsView.getSelect()).andStubReturn(null);
+ EasyMock.expect(resultsView.getFilter()).andStubReturn(null);
+ EasyMock.replay(resultsView);
+ try {
+ JPQLSelectSingleContextBuilder builder1 =
+ (JPQLSelectSingleContextBuilder) JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, resultsView);
+ builder1.build();
+ fail("Should not come here");
+ } catch (ODataJPAModelException e) {
+ fail();
+ } catch (ODataJPARuntimeException e) {
+ assertTrue(true);
+ }
+ }
+
+ @Test
+ public void testSlectedFieldsAsNull() {
+ buildContextBuilder(true);
+ try {
+ selectContext = (JPQLSelectSingleContext) builder.build();
+ assertEquals("E2", selectContext.getSelectExpression());
+ } catch (ODataJPAModelException e) {
+ fail();
+ } catch (ODataJPARuntimeException e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void getKeyPredicates() {
+ buildContextBuilder(false);
+ assertEquals(keyPredicates.size(), selectContext.getKeyPredicates().size());
+ assertEquals(keyPredicates, selectContext.getKeyPredicates());
+ }
+
+ @Test
+ public void testGetJPAEntityName() {
+ buildContextBuilder(false);
+ assertEquals(JPQLSelectSingleContextImplTest.entityTypeName, selectContext.getJPAEntityName());
+ }
+
+ @Test
+ public void testGetType() {
+ buildContextBuilder(false);
+ assertEquals(JPQLContextType.SELECT_SINGLE, selectContext.getType());
+ }
+
+ @Test
+ public void testCreateBuilder() {
+ buildContextBuilder(false);
+ assertEquals(JPQLSelectSingleContextBuilder.class.toString(), builder.getClass().toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
new file mode 100644
index 0000000..c65aee4
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectSingleStatementBuilderTest.java
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectSingleStatementBuilder;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPQLSelectSingleStatementBuilderTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ private JPQLSelectSingleStatementBuilder JPQLSelectSingleStatementBuilder;
+
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ private JPQLSelectSingleContext createSelectContext() throws ODataJPARuntimeException, EdmException {
+ // Object Instantiation
+
+ JPQLSelectSingleContext JPQLSelectSingleContextImpl = null;// new JPQLSelectSingleContextImpl();
+ GetEntityUriInfo getEntityView = EasyMock.createMock(GetEntityUriInfo.class);
+
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ List<SelectItem> selectItemList = null;
+
+ // Setting up the expected value
+ KeyPredicate keyPredicate = EasyMock.createMock(KeyPredicate.class);
+ EdmProperty kpProperty = EasyMock.createMock(EdmProperty.class);
+ EdmSimpleType edmType = EasyMock.createMock(EdmSimpleType.class);
+ EdmMapping edmMapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(edmMapping.getInternalName()).andStubReturn("Field1");
+ EasyMock.expect(keyPredicate.getLiteral()).andStubReturn("1");
+ try {
+ EasyMock.expect(kpProperty.getName()).andStubReturn("Field1");
+ EasyMock.expect(kpProperty.getType()).andStubReturn(edmType);
+
+ EasyMock.expect(kpProperty.getMapping()).andStubReturn(edmMapping);
+
+ } catch (EdmException e2) {
+ fail("this should not happen");
+ }
+ EasyMock.expect(keyPredicate.getProperty()).andStubReturn(kpProperty);
+ EasyMock.replay(edmMapping, edmType, kpProperty, keyPredicate);
+ EasyMock.expect(getEntityView.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EasyMock.expect(getEntityView.getSelect()).andStubReturn(selectItemList);
+
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.replay(edmEntitySet);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader");
+ EasyMock.replay(edmEntityType);
+ ArrayList<KeyPredicate> arrayList = new ArrayList<KeyPredicate>();
+ arrayList.add(keyPredicate);
+ EasyMock.expect(getEntityView.getKeyPredicates()).andStubReturn(arrayList);
+ EasyMock.replay(getEntityView);
+
+ JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT_SINGLE, getEntityView);
+ try {
+ JPQLSelectSingleContextImpl = (JPQLSelectSingleContext) contextBuilder1.build();
+ } catch (ODataJPAModelException e) {
+ fail("Model Exception thrown");
+ }
+
+ return JPQLSelectSingleContextImpl;
+ }
+
+ /**
+ * Test method for {@link org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectSingleStatementBuilder#build)}.
+ * @throws EdmException
+ * @throws ODataJPARuntimeException
+ */
+
+ @Test
+ public void testBuildSimpleQuery() throws EdmException, ODataJPARuntimeException {
+ JPQLSelectSingleContext JPQLSelectSingleContextImpl = createSelectContext();
+ JPQLSelectSingleStatementBuilder = new JPQLSelectSingleStatementBuilder(JPQLSelectSingleContextImpl);
+
+ assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.Field1 = 1", JPQLSelectSingleStatementBuilder.build()
+ .toString());
+ }
+
+}
[47/47] git commit: [OLINGO-67] Merge remote-tracking branch
'origin/master' into ODataServlet
Posted by tb...@apache.org.
[OLINGO-67] Merge remote-tracking branch 'origin/master' into ODataServlet
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/33ae8e8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/33ae8e8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/33ae8e8a
Branch: refs/heads/ODataServlet
Commit: 33ae8e8a29a1cd5b11d850877d68e2d3c1db8255
Parents: 051af1c f8638bb
Author: Tamara Boehm <ta...@sap.com>
Authored: Thu Jan 2 13:41:28 2014 +0100
Committer: Tamara Boehm <ta...@sap.com>
Committed: Thu Jan 2 13:41:28 2014 +0100
----------------------------------------------------------------------
.../processor/core/util/AnnotationHelper.java | 26 +-
.../processor/core/ListsProcessorTest.java | 40 ++
.../datasource/AnnotationValueAccessTest.java | 237 +++++++
.../datasource/AnnotationsInMemoryDsTest.java | 60 +-
.../core/datasource/BeanPropertyAccessTest.java | 261 ++++++++
.../core/util/AnnotationHelperTest.java | 270 ++++++++
.../annotation-processor-webref/pom.xml | 6 +
.../processor/ref/AbstractRefTest.java | 195 ++++++
.../processor/ref/AbstractRefXmlTest.java | 89 +++
.../processor/ref/ServiceJsonTest.java | 87 +++
.../processor/ref/ServiceXmlTest.java | 123 ++++
odata2-jpa-processor/jpa-api/pom.xml | 4 +-
.../jpa/processor/api/ODataJPAContext.java | 206 ++++++
.../jpa/processor/api/ODataJPAProcessor.java | 77 +++
.../processor/api/ODataJPAResponseBuilder.java | 158 +++++
.../processor/api/ODataJPAServiceFactory.java | 190 ++++++
.../jpa/processor/api/access/JPAEdmBuilder.java | 57 ++
.../api/access/JPAEdmMappingModelAccess.java | 191 ++++++
.../jpa/processor/api/access/JPAFunction.java | 85 +++
.../jpa/processor/api/access/JPAJoinClause.java | 148 +++++
.../processor/api/access/JPAMethodContext.java | 130 ++++
.../api/access/JPAMethodContextView.java | 46 ++
.../jpa/processor/api/access/JPAProcessor.java | 260 ++++++++
.../jpa/processor/api/access/package-info.java | 26 +
.../api/exception/ODataJPAErrorCallback.java | 45 ++
.../api/exception/ODataJPAException.java | 68 ++
.../api/exception/ODataJPAMessageService.java | 49 ++
.../api/exception/ODataJPAModelException.java | 92 +++
.../api/exception/ODataJPARuntimeException.java | 97 +++
.../processor/api/exception/package-info.java | 31 +
.../processor/api/factory/JPAAccessFactory.java | 69 ++
.../api/factory/JPQLBuilderFactory.java | 77 +++
.../api/factory/ODataJPAAccessFactory.java | 94 +++
.../processor/api/factory/ODataJPAFactory.java | 105 +++
.../jpa/processor/api/factory/package-info.java | 33 +
.../jpa/processor/api/jpql/JPQLContext.java | 204 ++++++
.../jpa/processor/api/jpql/JPQLContextType.java | 73 +++
.../jpa/processor/api/jpql/JPQLContextView.java | 53 ++
.../processor/api/jpql/JPQLJoinContextView.java | 44 ++
.../jpql/JPQLJoinSelectSingleContextView.java | 45 ++
.../api/jpql/JPQLSelectContextView.java | 62 ++
.../api/jpql/JPQLSelectSingleContextView.java | 53 ++
.../jpa/processor/api/jpql/JPQLStatement.java | 148 +++++
.../jpa/processor/api/jpql/package-info.java | 27 +
.../api/model/JPAEdmAssociationEndView.java | 91 +++
.../api/model/JPAEdmAssociationSetView.java | 69 ++
.../api/model/JPAEdmAssociationView.java | 128 ++++
.../jpa/processor/api/model/JPAEdmBaseView.java | 101 +++
.../api/model/JPAEdmComplexPropertyView.java | 45 ++
.../api/model/JPAEdmComplexTypeView.java | 137 ++++
.../api/model/JPAEdmEntityContainerView.java | 72 +++
.../api/model/JPAEdmEntitySetView.java | 64 ++
.../api/model/JPAEdmEntityTypeView.java | 76 +++
.../processor/api/model/JPAEdmExtension.java | 50 ++
.../api/model/JPAEdmFunctionImportView.java | 51 ++
.../jpa/processor/api/model/JPAEdmKeyView.java | 51 ++
.../jpa/processor/api/model/JPAEdmMapping.java | 63 ++
.../processor/api/model/JPAEdmModelView.java | 43 ++
.../api/model/JPAEdmNavigationPropertyView.java | 72 +++
.../processor/api/model/JPAEdmPropertyView.java | 104 +++
.../JPAEdmReferentialConstraintRoleView.java | 101 +++
.../model/JPAEdmReferentialConstraintView.java | 69 ++
.../processor/api/model/JPAEdmSchemaView.java | 111 ++++
.../api/model/mapping/JPAAttributeMapType.java | 202 ++++++
.../api/model/mapping/JPAEdmMappingModel.java | 79 +++
.../mapping/JPAEdmMappingModelFactory.java | 85 +++
.../model/mapping/JPAEmbeddableTypeMapType.java | 161 +++++
.../mapping/JPAEmbeddableTypesMapType.java | 89 +++
.../api/model/mapping/JPAEntityTypeMapType.java | 213 ++++++
.../model/mapping/JPAEntityTypesMapType.java | 89 +++
.../mapping/JPAPersistenceUnitMapType.java | 157 +++++
.../model/mapping/JPARelationshipMapType.java | 175 +++++
.../api/model/mapping/package-info.java | 28 +
.../jpa/processor/api/model/package-info.java | 27 +
.../odata2/jpa/processor/api/package-info.java | 33 +
.../processor/api/jpa/ODataJPAContext.java | 206 ------
.../processor/api/jpa/ODataJPAProcessor.java | 69 --
.../api/jpa/ODataJPAServiceFactory.java | 190 ------
.../processor/api/jpa/access/JPAEdmBuilder.java | 57 --
.../jpa/access/JPAEdmMappingModelAccess.java | 191 ------
.../processor/api/jpa/access/JPAFunction.java | 85 ---
.../processor/api/jpa/access/JPAJoinClause.java | 148 -----
.../api/jpa/access/JPAMethodContext.java | 130 ----
.../api/jpa/access/JPAMethodContextView.java | 46 --
.../processor/api/jpa/access/JPAProcessor.java | 260 --------
.../processor/api/jpa/access/package-info.java | 26 -
.../jpa/exception/ODataJPAErrorCallback.java | 45 --
.../api/jpa/exception/ODataJPAException.java | 68 --
.../jpa/exception/ODataJPAMessageService.java | 49 --
.../jpa/exception/ODataJPAModelException.java | 92 ---
.../jpa/exception/ODataJPARuntimeException.java | 97 ---
.../api/jpa/exception/package-info.java | 31 -
.../api/jpa/factory/JPAAccessFactory.java | 69 --
.../api/jpa/factory/JPQLBuilderFactory.java | 77 ---
.../api/jpa/factory/ODataJPAAccessFactory.java | 82 ---
.../api/jpa/factory/ODataJPAFactory.java | 105 ---
.../processor/api/jpa/factory/package-info.java | 33 -
.../processor/api/jpa/jpql/JPQLContext.java | 204 ------
.../processor/api/jpa/jpql/JPQLContextType.java | 73 ---
.../processor/api/jpa/jpql/JPQLContextView.java | 53 --
.../api/jpa/jpql/JPQLJoinContextView.java | 44 --
.../jpql/JPQLJoinSelectSingleContextView.java | 45 --
.../api/jpa/jpql/JPQLSelectContextView.java | 62 --
.../jpa/jpql/JPQLSelectSingleContextView.java | 53 --
.../processor/api/jpa/jpql/JPQLStatement.java | 148 -----
.../processor/api/jpa/jpql/package-info.java | 27 -
.../api/jpa/model/JPAEdmAssociationEndView.java | 91 ---
.../api/jpa/model/JPAEdmAssociationSetView.java | 69 --
.../api/jpa/model/JPAEdmAssociationView.java | 128 ----
.../processor/api/jpa/model/JPAEdmBaseView.java | 101 ---
.../jpa/model/JPAEdmComplexPropertyView.java | 45 --
.../api/jpa/model/JPAEdmComplexTypeView.java | 116 ----
.../jpa/model/JPAEdmEntityContainerView.java | 72 ---
.../api/jpa/model/JPAEdmEntitySetView.java | 64 --
.../api/jpa/model/JPAEdmEntityTypeView.java | 76 ---
.../api/jpa/model/JPAEdmExtension.java | 50 --
.../api/jpa/model/JPAEdmFunctionImportView.java | 51 --
.../processor/api/jpa/model/JPAEdmKeyView.java | 51 --
.../processor/api/jpa/model/JPAEdmMapping.java | 63 --
.../api/jpa/model/JPAEdmModelView.java | 43 --
.../jpa/model/JPAEdmNavigationPropertyView.java | 72 ---
.../api/jpa/model/JPAEdmPropertyView.java | 104 ---
.../JPAEdmReferentialConstraintRoleView.java | 101 ---
.../model/JPAEdmReferentialConstraintView.java | 69 --
.../api/jpa/model/JPAEdmSchemaView.java | 116 ----
.../jpa/model/mapping/JPAAttributeMapType.java | 202 ------
.../jpa/model/mapping/JPAEdmMappingModel.java | 79 ---
.../mapping/JPAEdmMappingModelFactory.java | 85 ---
.../model/mapping/JPAEmbeddableTypeMapType.java | 161 -----
.../mapping/JPAEmbeddableTypesMapType.java | 89 ---
.../jpa/model/mapping/JPAEntityTypeMapType.java | 213 ------
.../model/mapping/JPAEntityTypesMapType.java | 89 ---
.../mapping/JPAPersistenceUnitMapType.java | 157 -----
.../model/mapping/JPARelationshipMapType.java | 175 -----
.../api/jpa/model/mapping/package-info.java | 28 -
.../processor/api/jpa/model/package-info.java | 27 -
.../odata2/processor/api/jpa/package-info.java | 33 -
.../src/main/resources/JPAEDMMappingModel.xsd | 4 +-
odata2-jpa-processor/jpa-core/pom.xml | 2 +-
.../jpa/processor/core/ODataEntityParser.java | 163 +++++
.../processor/core/ODataExpressionParser.java | 381 +++++++++++
.../jpa/processor/core/ODataJPAContextImpl.java | 146 +++++
.../core/ODataJPAProcessorDefault.java | 194 ++++++
.../core/ODataJPAResponseBuilderDefault.java | 646 +++++++++++++++++++
.../processor/core/access/data/JPAEntity.java | 355 ++++++++++
.../core/access/data/JPAEntityParser.java | 453 +++++++++++++
.../core/access/data/JPAExpandCallBack.java | 180 ++++++
.../core/access/data/JPAFunctionContext.java | 170 +++++
.../jpa/processor/core/access/data/JPALink.java | 225 +++++++
.../core/access/data/JPAProcessorImpl.java | 491 ++++++++++++++
.../core/access/model/EdmTypeConvertor.java | 69 ++
.../access/model/JPAEdmMappingModelService.java | 247 +++++++
.../core/access/model/JPAEdmNameBuilder.java | 499 ++++++++++++++
.../core/access/model/JPATypeConvertor.java | 119 ++++
.../processor/core/edm/ODataJPAEdmProvider.java | 295 +++++++++
.../ODataJPAMessageServiceDefault.java | 122 ++++
.../core/factory/ODataJPAFactoryImpl.java | 244 +++++++
.../core/jpql/JPQLJoinSelectContext.java | 171 +++++
.../core/jpql/JPQLJoinSelectSingleContext.java | 158 +++++
.../JPQLJoinSelectSingleStatementBuilder.java | 106 +++
.../core/jpql/JPQLJoinStatementBuilder.java | 145 +++++
.../processor/core/jpql/JPQLSelectContext.java | 159 +++++
.../core/jpql/JPQLSelectSingleContext.java | 109 ++++
.../jpql/JPQLSelectSingleStatementBuilder.java | 66 ++
.../core/jpql/JPQLSelectStatementBuilder.java | 98 +++
.../processor/core/model/JPAEdmAssociation.java | 237 +++++++
.../core/model/JPAEdmAssociationEnd.java | 183 ++++++
.../core/model/JPAEdmAssociationSet.java | 131 ++++
.../core/model/JPAEdmBaseViewImpl.java | 101 +++
.../processor/core/model/JPAEdmComplexType.java | 270 ++++++++
.../core/model/JPAEdmEntityContainer.java | 145 +++++
.../processor/core/model/JPAEdmEntitySet.java | 112 ++++
.../processor/core/model/JPAEdmEntityType.java | 230 +++++++
.../jpa/processor/core/model/JPAEdmFacets.java | 94 +++
.../core/model/JPAEdmFunctionImport.java | 349 ++++++++++
.../jpa/processor/core/model/JPAEdmKey.java | 129 ++++
.../processor/core/model/JPAEdmMappingImpl.java | 51 ++
.../jpa/processor/core/model/JPAEdmModel.java | 65 ++
.../core/model/JPAEdmNavigationProperty.java | 98 +++
.../processor/core/model/JPAEdmProperty.java | 377 +++++++++++
.../core/model/JPAEdmReferentialConstraint.java | 147 +++++
.../model/JPAEdmReferentialConstraintRole.java | 258 ++++++++
.../jpa/processor/core/model/JPAEdmSchema.java | 214 ++++++
.../model/_JPAEdmFunctionImportBuilder.java | 237 +++++++
.../processor/core/jpa/ODataEntityParser.java | 163 -----
.../core/jpa/ODataExpressionParser.java | 381 -----------
.../processor/core/jpa/ODataJPAContextImpl.java | 146 -----
.../core/jpa/ODataJPAProcessorDefault.java | 194 ------
.../core/jpa/ODataJPAResponseBuilder.java | 629 ------------------
.../core/jpa/access/data/JPAEntity.java | 355 ----------
.../core/jpa/access/data/JPAEntityParser.java | 453 -------------
.../core/jpa/access/data/JPAExpandCallBack.java | 180 ------
.../jpa/access/data/JPAFunctionContext.java | 170 -----
.../processor/core/jpa/access/data/JPALink.java | 225 -------
.../core/jpa/access/data/JPAProcessorImpl.java | 491 --------------
.../core/jpa/access/model/EdmTypeConvertor.java | 69 --
.../access/model/JPAEdmMappingModelService.java | 247 -------
.../jpa/access/model/JPAEdmNameBuilder.java | 499 --------------
.../core/jpa/access/model/JPATypeConvertor.java | 119 ----
.../core/jpa/edm/ODataJPAEdmProvider.java | 295 ---------
.../ODataJPAMessageServiceDefault.java | 122 ----
.../core/jpa/factory/ODataJPAFactoryImpl.java | 237 -------
.../core/jpa/jpql/JPQLJoinSelectContext.java | 171 -----
.../jpa/jpql/JPQLJoinSelectSingleContext.java | 158 -----
.../JPQLJoinSelectSingleStatementBuilder.java | 106 ---
.../core/jpa/jpql/JPQLJoinStatementBuilder.java | 145 -----
.../core/jpa/jpql/JPQLSelectContext.java | 159 -----
.../core/jpa/jpql/JPQLSelectSingleContext.java | 109 ----
.../jpql/JPQLSelectSingleStatementBuilder.java | 66 --
.../jpa/jpql/JPQLSelectStatementBuilder.java | 98 ---
.../core/jpa/model/JPAEdmAssociation.java | 237 -------
.../core/jpa/model/JPAEdmAssociationEnd.java | 183 ------
.../core/jpa/model/JPAEdmAssociationSet.java | 131 ----
.../core/jpa/model/JPAEdmBaseViewImpl.java | 101 ---
.../core/jpa/model/JPAEdmComplexType.java | 254 --------
.../core/jpa/model/JPAEdmEntityContainer.java | 154 -----
.../core/jpa/model/JPAEdmEntitySet.java | 112 ----
.../core/jpa/model/JPAEdmEntityType.java | 230 -------
.../processor/core/jpa/model/JPAEdmFacets.java | 94 ---
.../core/jpa/model/JPAEdmFunctionImport.java | 331 ----------
.../processor/core/jpa/model/JPAEdmKey.java | 129 ----
.../core/jpa/model/JPAEdmMappingImpl.java | 51 --
.../processor/core/jpa/model/JPAEdmModel.java | 65 --
.../jpa/model/JPAEdmNavigationProperty.java | 98 ---
.../core/jpa/model/JPAEdmProperty.java | 378 -----------
.../jpa/model/JPAEdmReferentialConstraint.java | 147 -----
.../model/JPAEdmReferentialConstraintRole.java | 258 --------
.../processor/core/jpa/model/JPAEdmSchema.java | 216 -------
.../jpa/model/_JPAEdmFunctionImportBuilder.java | 237 -------
.../main/resources/jpaprocessor_msg.properties | 66 +-
.../core/ODataExpressionParserTest.java | 516 +++++++++++++++
.../processor/core/ODataJPAContextImplTest.java | 99 +++
.../core/ODataJPAProcessorDefaultTest.java | 555 ++++++++++++++++
.../core/ODataJPAResponseBuilderTest.java | 565 ++++++++++++++++
.../core/access/data/JPAEntityParserTest.java | 600 +++++++++++++++++
.../JPAEntityParserTestForStaticMethods.java | 252 ++++++++
.../core/access/data/JPAEntityTest.java | 188 ++++++
.../core/access/data/JPAExpandCallBackTest.java | 161 +++++
.../access/data/JPAFunctionContextTest.java | 144 +++++
.../core/access/data/JPAProcessorImplTest.java | 448 +++++++++++++
.../model/JPAEdmMappingModelServiceTest.java | 214 ++++++
.../access/model/JPAEdmNameBuilderTest.java | 153 +++++
.../core/access/model/JPATypeConvertorTest.java | 95 +++
.../core/common/ODataJPATestConstants.java | 27 +
.../edm/ODataJPAEdmProviderNegativeTest.java | 192 ++++++
.../core/edm/ODataJPAEdmProviderTest.java | 386 +++++++++++
.../core/jpql/JPQLBuilderFactoryTest.java | 381 +++++++++++
.../core/jpql/JPQLJoinContextTest.java | 199 ++++++
.../jpql/JPQLJoinSelectSingleContextTest.java | 216 +++++++
...PQLJoinSelectSingleStatementBuilderTest.java | 143 ++++
.../core/jpql/JPQLJoinStatementBuilderTest.java | 125 ++++
.../core/jpql/JPQLSelectContextImplTest.java | 386 +++++++++++
.../jpql/JPQLSelectSingleContextImplTest.java | 199 ++++++
.../JPQLSelectSingleStatementBuilderTest.java | 125 ++++
.../jpql/JPQLSelectStatementBuilderTest.java | 137 ++++
.../core/mock/ODataJPAContextMock.java | 57 ++
.../processor/core/mock/data/EdmMockUtil.java | 337 ++++++++++
.../processor/core/mock/data/EdmMockUtilV2.java | 324 ++++++++++
.../processor/core/mock/data/JPATypeMock.java | 205 ++++++
.../core/mock/data/ODataEntryMockUtil.java | 127 ++++
.../core/mock/data/SalesOrderHeader.java | 63 ++
.../core/mock/data/SalesOrderLineItem.java | 38 ++
.../core/mock/data/SalesOrderLineItemKey.java | 52 ++
.../core/mock/model/EdmSchemaMock.java | 213 ++++++
.../core/mock/model/JPAAttributeMock.java | 63 ++
.../core/mock/model/JPACustomProcessorMock.java | 74 +++
.../core/mock/model/JPAEdmMockData.java | 72 +++
.../core/mock/model/JPAEmbeddableMock.java | 184 ++++++
.../core/mock/model/JPAEmbeddableTypeMock.java | 184 ++++++
.../core/mock/model/JPAEntityTypeMock.java | 246 +++++++
.../core/mock/model/JPAJavaMemberMock.java | 74 +++
.../core/mock/model/JPAManagedTypeMock.java | 184 ++++++
.../core/mock/model/JPAMetaModelMock.java | 60 ++
.../core/mock/model/JPAPluralAttributeMock.java | 95 +++
.../mock/model/JPASingularAttributeMock.java | 94 +++
.../mock/model/_JPACustomProcessorMock.java | 77 +++
.../model/_JPACustomProcessorNegativeMock.java | 70 ++
.../core/model/JPAEdmAssociationEndTest.java | 178 +++++
.../core/model/JPAEdmAssociationSetTest.java | 185 ++++++
.../core/model/JPAEdmAssociationTest.java | 426 ++++++++++++
.../core/model/JPAEdmBaseViewImplTest.java | 90 +++
.../core/model/JPAEdmComplexTypeTest.java | 270 ++++++++
.../core/model/JPAEdmEntityContainerTest.java | 235 +++++++
.../core/model/JPAEdmEntitySetTest.java | 225 +++++++
.../core/model/JPAEdmEntityTypeTest.java | 199 ++++++
.../core/model/JPAEdmFunctionImportTest.java | 567 ++++++++++++++++
.../jpa/processor/core/model/JPAEdmKeyTest.java | 177 +++++
.../processor/core/model/JPAEdmModelTest.java | 146 +++++
.../model/JPAEdmNavigationPropertyTest.java | 219 +++++++
.../core/model/JPAEdmPropertyTest.java | 439 +++++++++++++
.../JPAEdmReferentialConstraintRoleTest.java | 235 +++++++
.../model/JPAEdmReferentialConstraintTest.java | 178 +++++
.../processor/core/model/JPAEdmSchemaTest.java | 104 +++
.../core/model/JPAEdmTestModelView.java | 400 ++++++++++++
.../core/model/_JPAEdmFunctionImportTest.java | 571 ++++++++++++++++
.../core/jpa/ODataExpressionParserTest.java | 515 ---------------
.../core/jpa/ODataJPAContextImplTest.java | 98 ---
.../core/jpa/ODataJPAProcessorDefaultTest.java | 554 ----------------
.../core/jpa/ODataJPAResponseBuilderTest.java | 566 ----------------
.../jpa/access/data/JPAEntityParserTest.java | 599 -----------------
.../JPAEntityParserTestForStaticMethods.java | 251 -------
.../core/jpa/access/data/JPAEntityTest.java | 187 ------
.../jpa/access/data/JPAExpandCallBackTest.java | 160 -----
.../jpa/access/data/JPAFunctionContextTest.java | 143 ----
.../jpa/access/data/JPAProcessorImplTest.java | 447 -------------
.../model/JPAEdmMappingModelServiceTest.java | 213 ------
.../jpa/access/model/JPAEdmNameBuilderTest.java | 151 -----
.../jpa/access/model/JPATypeConvertorTest.java | 94 ---
.../core/jpa/common/ODataJPATestConstants.java | 27 -
.../edm/ODataJPAEdmProviderNegativeTest.java | 191 ------
.../core/jpa/edm/ODataJPAEdmProviderTest.java | 385 -----------
.../core/jpa/jpql/JPQLBuilderFactoryTest.java | 377 -----------
.../core/jpa/jpql/JPQLJoinContextTest.java | 198 ------
.../jpql/JPQLJoinSelectSingleContextTest.java | 215 ------
...PQLJoinSelectSingleStatementBuilderTest.java | 142 ----
.../jpa/jpql/JPQLJoinStatementBuilderTest.java | 124 ----
.../jpa/jpql/JPQLSelectContextImplTest.java | 385 -----------
.../jpql/JPQLSelectSingleContextImplTest.java | 198 ------
.../JPQLSelectSingleStatementBuilderTest.java | 123 ----
.../jpql/JPQLSelectStatementBuilderTest.java | 135 ----
.../core/jpa/mock/ODataJPAContextMock.java | 57 --
.../core/jpa/mock/data/EdmMockUtil.java | 337 ----------
.../core/jpa/mock/data/EdmMockUtilV2.java | 324 ----------
.../core/jpa/mock/data/JPATypeMock.java | 205 ------
.../core/jpa/mock/data/ODataEntryMockUtil.java | 127 ----
.../core/jpa/mock/data/SalesOrderHeader.java | 63 --
.../core/jpa/mock/data/SalesOrderLineItem.java | 38 --
.../jpa/mock/data/SalesOrderLineItemKey.java | 52 --
.../core/jpa/mock/model/EdmSchemaMock.java | 213 ------
.../core/jpa/mock/model/JPAAttributeMock.java | 63 --
.../jpa/mock/model/JPACustomProcessorMock.java | 74 ---
.../core/jpa/mock/model/JPAEdmMockData.java | 72 ---
.../core/jpa/mock/model/JPAEmbeddableMock.java | 184 ------
.../jpa/mock/model/JPAEmbeddableTypeMock.java | 184 ------
.../core/jpa/mock/model/JPAEntityTypeMock.java | 246 -------
.../core/jpa/mock/model/JPAJavaMemberMock.java | 74 ---
.../core/jpa/mock/model/JPAManagedTypeMock.java | 184 ------
.../core/jpa/mock/model/JPAMetaModelMock.java | 60 --
.../jpa/mock/model/JPAPluralAttributeMock.java | 95 ---
.../mock/model/JPASingularAttributeMock.java | 94 ---
.../jpa/mock/model/_JPACustomProcessorMock.java | 77 ---
.../model/_JPACustomProcessorNegativeMock.java | 70 --
.../jpa/model/JPAEdmAssociationEndTest.java | 177 -----
.../jpa/model/JPAEdmAssociationSetTest.java | 184 ------
.../core/jpa/model/JPAEdmAssociationTest.java | 423 ------------
.../core/jpa/model/JPAEdmBaseViewImplTest.java | 89 ---
.../core/jpa/model/JPAEdmComplexTypeTest.java | 268 --------
.../jpa/model/JPAEdmEntityContainerTest.java | 234 -------
.../core/jpa/model/JPAEdmEntitySetTest.java | 224 -------
.../core/jpa/model/JPAEdmEntityTypeTest.java | 198 ------
.../jpa/model/JPAEdmFunctionImportTest.java | 566 ----------------
.../processor/core/jpa/model/JPAEdmKeyTest.java | 176 -----
.../core/jpa/model/JPAEdmModelTest.java | 145 -----
.../jpa/model/JPAEdmNavigationPropertyTest.java | 218 -------
.../core/jpa/model/JPAEdmPropertyTest.java | 440 -------------
.../JPAEdmReferentialConstraintRoleTest.java | 233 -------
.../model/JPAEdmReferentialConstraintTest.java | 177 -----
.../core/jpa/model/JPAEdmSchemaTest.java | 103 ---
.../core/jpa/model/JPAEdmTestModelView.java | 396 ------------
.../jpa/model/_JPAEdmFunctionImportTest.java | 570 ----------------
.../SalesOrderProcessingMappingModels.xml | 2 +-
.../jpa/processor/ref/extension/OrderValue.java | 42 ++
.../extension/SalesOrderHeaderProcessor.java | 21 +
.../SalesOrderProcessingExtension.java | 38 +-
.../ref/web/JPAReferenceServiceFactory.java | 8 +-
.../resources/SalesOrderItemSQLs.properties | 22 +-
.../webapp/SalesOrderProcessingMappingModel.xml | 2 +-
.../jpa-web/src/main/webapp/index.jsp | 9 +
368 files changed, 31108 insertions(+), 29337 deletions(-)
----------------------------------------------------------------------
[26/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
deleted file mode 100644
index 464b548..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImport.java
+++ /dev/null
@@ -1,349 +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.odata2.processor.core.jpa.model;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmFunctionImportView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPATypeConvertor;
-
-public class JPAEdmFunctionImport extends JPAEdmBaseViewImpl implements JPAEdmFunctionImportView {
-
- private List<FunctionImport> consistentFunctionImportList = new ArrayList<FunctionImport>();
- private JPAEdmBuilder builder = null;
- private JPAEdmSchemaView schemaView;
-
- public JPAEdmFunctionImport(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmFunctionImportBuilder();
- }
- return builder;
- }
-
- @Override
- public List<FunctionImport> getConsistentFunctionImportList() {
- return consistentFunctionImportList;
- }
-
- protected class JPAEdmFunctionImportBuilder implements JPAEdmBuilder {
-
- private JPAEdmEntityTypeView jpaEdmEntityTypeView = null;
- private JPAEdmComplexTypeView jpaEdmComplexTypeView = null;
- @SuppressWarnings("deprecation")
- private _JPAEdmFunctionImportBuilder builderDeprecated = new _JPAEdmFunctionImportBuilder();
-
- @SuppressWarnings("deprecation")
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- HashMap<Class<?>, String[]> customOperations = schemaView.getRegisteredOperations();
-
- jpaEdmEntityTypeView =
- schemaView.getJPAEdmEntityContainerView().getJPAEdmEntitySetView().getJPAEdmEntityTypeView();
- jpaEdmComplexTypeView = schemaView.getJPAEdmComplexTypeView();
-
- if (customOperations != null) {
- // Initialize deprecated Builder
- builderDeprecated.setJPAEdmComplexTypeView(jpaEdmComplexTypeView);
- builderDeprecated.setJPAEdmEntityTypeView(jpaEdmEntityTypeView);
- builderDeprecated.setSchemaView(schemaView);
-
- for (Class<?> clazz : customOperations.keySet()) {
-
- String[] operationNames = customOperations.get(clazz);
- Method[] methods = clazz.getMethods();
- Method method = null;
-
- int length = 0;
- if (operationNames != null) {
- length = operationNames.length;
- } else {
- length = methods.length;
- }
-
- boolean found = false;
- for (int i = 0; i < length; i++) {
-
- try {
- if (operationNames != null) {
- for (Method method2 : methods) {
- if (method2.getName().equals(operationNames[i])) {
- found = true;
- method = method2;
- break;
- }
- }
- if (found == true) {
- found = false;
- } else {
- continue;
- }
- } else {
- method = methods[i];
- }
-
- FunctionImport functionImport = buildFunctionImport(method);
- if (functionImport != null) {
- consistentFunctionImportList.add(functionImport);
- }
-
- } catch (SecurityException e) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL, e);
- }
- }
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- private FunctionImport buildFunctionImport(final Method method) throws ODataJPAModelException {
-
- EdmFunctionImport edmAnnotationFunctionImport = method.getAnnotation(EdmFunctionImport.class);
- if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
- return buildEdmFunctionImport(method, edmAnnotationFunctionImport);
- }
-
- org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation =
- method.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.FunctionImport.class);
-
- if (annotation != null) {
- FunctionImport functionImport = builderDeprecated.buildFunctionImport(method, annotation);
-
- return functionImport;
- }
- return null;
- }
-
- private FunctionImport buildEdmFunctionImport(final Method method,
- final EdmFunctionImport edmAnnotationFunctionImport)
- throws ODataJPAModelException {
- if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
- FunctionImport functionImport = new FunctionImport();
-
- if (edmAnnotationFunctionImport.name().equals("")) {
- functionImport.setName(method.getName());
- } else {
- functionImport.setName(edmAnnotationFunctionImport.name());
- }
-
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(method.getName());
- mapping.setJPAType(method.getDeclaringClass());
- functionImport.setMapping((Mapping) mapping);
-
- functionImport.setHttpMethod(edmAnnotationFunctionImport.httpMethod().name().toString());
-
- buildEdmReturnType(functionImport, method, edmAnnotationFunctionImport);
- buildEdmParameter(functionImport, method);
-
- return functionImport;
- }
- return null;
- }
-
- private void buildEdmParameter(final FunctionImport functionImport, final Method method)
- throws ODataJPAModelException {
- Annotation[][] annotations = method.getParameterAnnotations();
- Class<?>[] parameterTypes = method.getParameterTypes();
- List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
- JPAEdmMapping mapping = null;
- int j = 0;
- for (Annotation[] annotationArr : annotations) {
- Class<?> parameterType = parameterTypes[j++];
-
- for (Annotation element : annotationArr) {
- if (element instanceof EdmFunctionImportParameter) {
- EdmFunctionImportParameter annotation = (EdmFunctionImportParameter) element;
- FunctionImportParameter functionImportParameter = new FunctionImportParameter();
- if (annotation.name().equals("")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method
- .getDeclaringClass().getName(), method.getName()), null);
- } else {
- functionImportParameter.setName(annotation.name());
- }
-
- functionImportParameter.setType(JPATypeConvertor.convertToEdmSimpleType(parameterType, null));
-
- Facets facets = new Facets();
- if (annotation.facets().maxLength() > 0) {
- facets.setMaxLength(annotation.facets().maxLength());
- }
- if (annotation.facets().nullable() == false) {
- facets.setNullable(false);
- } else {
- facets.setNullable(true);
- }
-
- if (annotation.facets().precision() > 0) {
- facets.setPrecision(annotation.facets().precision());
- }
- if (annotation.facets().scale() >= 0) {
- facets.setScale(annotation.facets().scale());
- }
-
- functionImportParameter.setFacets(facets);
- mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(parameterType);
- functionImportParameter.setMapping((Mapping) mapping);
- funcImpList.add(functionImportParameter);
- }
- }
- }
- if (!funcImpList.isEmpty()) {
- functionImport.setParameters(funcImpList);
- }
- }
-
- private void buildEdmReturnType(final FunctionImport functionImport, final Method method,
- final EdmFunctionImport edmAnnotationFunctionImport) throws ODataJPAModelException {
- ReturnType returnType = edmAnnotationFunctionImport.returnType();
-
- if (returnType != null) {
- org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType =
- new org.apache.olingo.odata2.api.edm.provider.ReturnType();
-
- if (returnType.isCollection()) {
- functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
- } else {
- functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
- }
-
- if (returnType.type() == ReturnType.Type.ENTITY) {
- String entitySet = edmAnnotationFunctionImport.entitySet();
- if (entitySet.equals("")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
- }
- functionImport.setEntitySet(entitySet);
- }
-
- Class<?> methodReturnType = method.getReturnType();
- if (methodReturnType == null || methodReturnType.getName().equals("void")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method
- .getDeclaringClass(), method.getName()), null);
- }
- switch (returnType.type()) {
- case ENTITY:
- EntityType edmEntityType = null;
- if (returnType.isCollection() == false) {
- edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName());
- } else {
- edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method));
- }
-
- if (edmEntityType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
- }
- functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName()));
- break;
- case SIMPLE:
- EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConvertor.convertToEdmSimpleType(methodReturnType, null);
- functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName());
-
- break;
- case COMPLEX:
- String embeddableTypeName = null;
- ComplexType complexType = null;
- boolean exists = false;
-
- if (returnType.isCollection() == false) {
- embeddableTypeName = methodReturnType.getName();
- } else {
- embeddableTypeName = getReturnTypeName(method);
- }
-
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(embeddableTypeName);
-
- if (complexType == null) {// This could occure of non JPA Embeddable Types : Extension Scenario
- List<ComplexType> complexTypeList = schemaView.getEdmSchema().getComplexTypes();
- String[] complexTypeNameParts = embeddableTypeName.split("\\.");
- String complexTypeName = complexTypeNameParts[complexTypeNameParts.length - 1];
- for (ComplexType complexType1 : complexTypeList) {
- if (complexType1.getName().equals(complexTypeName)) {
- complexType = complexType1;
- exists = true;
- break;
- }
- }
- if (exists == false) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
- }
- }
- functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
- break;
- default:
- break;
- }
- functionImport.setReturnType(functionReturnType);
- }
- }
-
- private String getReturnTypeName(final Method method) {
- try {
- ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
- Type t = pt.getActualTypeArguments()[0];
- return ((Class<?>) t).getName();
- } catch (ClassCastException e) {
- return method.getReturnType().getName();
- }
- }
-
- private String getReturnTypeSimpleName(final Method method) {
- try {
- ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
- Type t = pt.getActualTypeArguments()[0];
- return ((Class<?>) t).getSimpleName();
- } catch (ClassCastException e) {
- return method.getReturnType().getSimpleName();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKey.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKey.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKey.java
deleted file mode 100644
index 15cd26e..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKey.java
+++ /dev/null
@@ -1,129 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-
-public class JPAEdmKey extends JPAEdmBaseViewImpl implements JPAEdmKeyView {
-
- private JPAEdmPropertyView propertyView;
- private JPAEdmComplexTypeView complexTypeView = null;
- private boolean isBuildModeComplexType = false;
- private Key key;
-
- public JPAEdmKey(final JPAEdmProperty view) {
- super(view);
- propertyView = view;
- }
-
- public JPAEdmKey(final JPAEdmComplexTypeView complexTypeView, final JPAEdmPropertyView propertyView) {
- super(complexTypeView);
- this.propertyView = propertyView;
- this.complexTypeView = complexTypeView;
- isBuildModeComplexType = true;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmKeyBuider();
- }
-
- return builder;
- }
-
- @Override
- public Key getEdmKey() {
- return key;
- }
-
- private class JPAEdmKeyBuider implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException {
-
- List<PropertyRef> propertyRefList = null;
- if (key == null) {
- key = new Key();
- }
-
- if (key.getKeys() == null) {
- propertyRefList = new ArrayList<PropertyRef>();
- key.setKeys(propertyRefList);
- } else {
- propertyRefList = key.getKeys();
- }
-
- if (isBuildModeComplexType) {
- ComplexType complexType =
- complexTypeView.searchEdmComplexType(propertyView.getJPAAttribute().getJavaType().getName());
- normalizeComplexKey(complexType, propertyRefList);
- } else {
- PropertyRef propertyRef = new PropertyRef();
- propertyRef.setName(propertyView.getEdmSimpleProperty().getName());
- Facets facets = (Facets) propertyView.getEdmSimpleProperty().getFacets();
- if (facets == null) {
- propertyView.getEdmSimpleProperty().setFacets(new Facets().setNullable(false));
- } else {
- facets.setNullable(false);
- }
- propertyRefList.add(propertyRef);
- }
-
- }
-
- // TODO think how to stop the recursion if A includes B and B includes A!!!!!!
- public void normalizeComplexKey(final ComplexType complexType, final List<PropertyRef> propertyRefList) {
- for (Property property : complexType.getProperties()) {
- try {
-
- SimpleProperty simpleProperty = (SimpleProperty) property;
- Facets facets = (Facets) simpleProperty.getFacets();
- if (facets == null) {
- simpleProperty.setFacets(new Facets().setNullable(false));
- } else {
- facets.setNullable(false);
- }
- PropertyRef propertyRef = new PropertyRef();
- propertyRef.setName(simpleProperty.getName());
- propertyRefList.add(propertyRef);
-
- } catch (ClassCastException e) {
- ComplexProperty complexProperty = (ComplexProperty) property;
- normalizeComplexKey(complexTypeView.searchEdmComplexType(complexProperty.getType()), propertyRefList);
- }
-
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmMappingImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmMappingImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmMappingImpl.java
deleted file mode 100644
index 99d9f5f..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmMappingImpl.java
+++ /dev/null
@@ -1,51 +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.odata2.processor.core.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-
-public class JPAEdmMappingImpl extends Mapping implements JPAEdmMapping {
-
- private String columnName = null;
- private Class<?> type = null;
-
- @Override
- public void setJPAColumnName(final String name) {
- columnName = name;
-
- }
-
- @Override
- public String getJPAColumnName() {
- return columnName;
- }
-
- @Override
- public void setJPAType(final Class<?> type) {
- this.type = type;
-
- }
-
- @Override
- public Class<?> getJPAType() {
- return type;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModel.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModel.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModel.java
deleted file mode 100644
index fac5614..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmModel.java
+++ /dev/null
@@ -1,65 +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.odata2.processor.core.jpa.model;
-
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-
-public class JPAEdmModel extends JPAEdmBaseViewImpl implements JPAEdmModelView {
-
- protected JPAEdmSchemaView schemaView;
-
- public JPAEdmModel(final Metamodel metaModel, final String pUnitName) {
- super(metaModel, pUnitName);
- }
-
- public JPAEdmModel(final ODataJPAContext ctx) {
- super(ctx);
- }
-
- @Override
- public JPAEdmSchemaView getEdmSchemaView() {
- return schemaView;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmModelBuilder();
- }
-
- return builder;
- }
-
- private class JPAEdmModelBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
- schemaView = new JPAEdmSchema(JPAEdmModel.this);
- schemaView.getBuilder().build();
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationProperty.java
deleted file mode 100644
index 4757c9a..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmNavigationProperty.java
+++ /dev/null
@@ -1,98 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmNavigationProperty extends JPAEdmBaseViewImpl implements JPAEdmNavigationPropertyView {
-
- private JPAEdmAssociationView associationView = null;
- private NavigationProperty currentNavigationProperty = null;
- private JPAEdmPropertyView propertyView = null;
- private List<NavigationProperty> consistentNavigationProperties = null;
- private int count;
-
- public JPAEdmNavigationProperty(final JPAEdmAssociationView associationView, final JPAEdmPropertyView propertyView,
- final int countNumber) {
- super(associationView);
- this.associationView = associationView;
- this.propertyView = propertyView;
- count = countNumber;
- if (consistentNavigationProperties == null) {
- consistentNavigationProperties = new ArrayList<NavigationProperty>();
- }
- }
-
- public JPAEdmNavigationProperty(final JPAEdmSchemaView schemaView) {
- super(schemaView);
- consistentNavigationProperties = new ArrayList<NavigationProperty>();
-
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmNavigationPropertyBuilder();
- }
-
- return builder;
- }
-
- private class JPAEdmNavigationPropertyBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException {
-
- currentNavigationProperty = new NavigationProperty();
- JPAEdmNameBuilder.build(associationView, propertyView, JPAEdmNavigationProperty.this, skipDefaultNaming, count);
- consistentNavigationProperties.add(currentNavigationProperty);
- }
-
- }
-
- @Override
- public NavigationProperty getEdmNavigationProperty() {
- return currentNavigationProperty;
- }
-
- @Override
- public List<NavigationProperty> getConsistentEdmNavigationProperties() {
- return consistentNavigationProperties;
- }
-
- @Override
- public void addJPAEdmNavigationPropertyView(final JPAEdmNavigationPropertyView view) {
- if (view != null && view.isConsistent()) {
- currentNavigationProperty = view.getEdmNavigationProperty();
- consistentNavigationProperties.add(currentNavigationProperty);
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
deleted file mode 100644
index edd1c6e..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmProperty.java
+++ /dev/null
@@ -1,377 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.Attribute.PersistentAttributeType;
-import javax.persistence.metamodel.PluralAttribute;
-import javax.persistence.metamodel.SingularAttribute;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationEndView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPATypeConvertor;
-
-public class JPAEdmProperty extends JPAEdmBaseViewImpl implements
- JPAEdmPropertyView, JPAEdmComplexPropertyView {
-
- private JPAEdmSchemaView schemaView;
- private JPAEdmEntityTypeView entityTypeView;
- private JPAEdmComplexTypeView complexTypeView;
- private JPAEdmNavigationPropertyView navigationPropertyView = null;
-
- private JPAEdmKeyView keyView;
- private List<Property> properties;
- private SimpleProperty currentSimpleProperty = null;
- private ComplexProperty currentComplexProperty = null;
- private Attribute<?, ?> currentAttribute;
- private boolean isBuildModeComplexType;
- private Map<String, Integer> associationCount;
-
- public JPAEdmProperty(final JPAEdmSchemaView view) {
- super(view);
- schemaView = view;
- entityTypeView = schemaView.getJPAEdmEntityContainerView()
- .getJPAEdmEntitySetView().getJPAEdmEntityTypeView();
- complexTypeView = schemaView.getJPAEdmComplexTypeView();
- navigationPropertyView = new JPAEdmNavigationProperty(schemaView);
- isBuildModeComplexType = false;
- associationCount = new HashMap<String, Integer>();
- }
-
- public JPAEdmProperty(final JPAEdmSchemaView schemaView,
- final JPAEdmComplexTypeView view) {
- super(view);
- this.schemaView = schemaView;
- complexTypeView = view;
- isBuildModeComplexType = true;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmPropertyBuilder();
- }
-
- return builder;
- }
-
- @Override
- public List<Property> getEdmPropertyList() {
- return properties;
- }
-
- @Override
- public JPAEdmKeyView getJPAEdmKeyView() {
- return keyView;
- }
-
- @Override
- public SimpleProperty getEdmSimpleProperty() {
- return currentSimpleProperty;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return currentAttribute;
- }
-
- @Override
- public ComplexProperty getEdmComplexProperty() {
- return currentComplexProperty;
- }
-
- @Override
- public JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView() {
- return navigationPropertyView;
- }
-
- private class JPAEdmPropertyBuilder implements JPAEdmBuilder {
- /*
- *
- * Each call to build method creates a new EDM Property List.
- * The Property List can be created either by an Entity type or
- * ComplexType. The flag isBuildModeComplexType tells if the
- * Properties are built for complex type or for Entity Type.
- *
- * While Building Properties Associations are built. However
- * the associations thus built does not contain Referential
- * constraint. Associations thus built only contains
- * information about Referential constraints. Adding of
- * referential constraints to Associations is the taken care
- * by Schema.
- *
- * Building Properties is divided into four parts
- * A) Building Simple Properties
- * B) Building Complex Properties
- * C) Building Associations
- * D) Building Navigation Properties
- *
- * ************************************************************
- * Build EDM Schema - STEPS
- * ************************************************************
- * A) Building Simple Properties:
- *
- * 1) Fetch JPA Attribute List from
- * A) Complex Type
- * B) Entity Type
- * depending on isBuildModeComplexType.
- * B) Building Complex Properties
- * C) Building Associations
- * D) Building Navigation Properties
- *
- * ************************************************************
- * Build EDM Schema - STEPS
- * ************************************************************
- */
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- JPAEdmBuilder keyViewBuilder = null;
-
- properties = new ArrayList<Property>();
-
- List<Attribute<?, ?>> jpaAttributes = null;
- String currentEntityName = null;
- String targetEntityName = null;
- String entityTypeName = null;
- if (isBuildModeComplexType) {
- jpaAttributes = sortInAscendingOrder(complexTypeView.getJPAEmbeddableType()
- .getAttributes());
- entityTypeName = complexTypeView.getJPAEmbeddableType().getJavaType()
- .getSimpleName();
- } else {
- jpaAttributes = sortInAscendingOrder(entityTypeView.getJPAEntityType()
- .getAttributes());
- entityTypeName = entityTypeView.getJPAEntityType().getName();
- }
-
- for (Object jpaAttribute : jpaAttributes) {
- currentAttribute = (Attribute<?, ?>) jpaAttribute;
-
- // Check for need to Exclude
- if (isExcluded((JPAEdmPropertyView) JPAEdmProperty.this, entityTypeName, currentAttribute.getName())) {
- continue;
- }
-
- PersistentAttributeType attributeType = currentAttribute
- .getPersistentAttributeType();
-
- switch (attributeType) {
- case BASIC:
-
- currentSimpleProperty = new SimpleProperty();
- JPAEdmNameBuilder
- .build((JPAEdmPropertyView) JPAEdmProperty.this, isBuildModeComplexType, skipDefaultNaming);
-
- EdmSimpleTypeKind simpleTypeKind = JPATypeConvertor
- .convertToEdmSimpleType(currentAttribute
- .getJavaType(), currentAttribute);
-
- currentSimpleProperty.setType(simpleTypeKind);
- JPAEdmFacets.setFacets(currentAttribute, currentSimpleProperty);
-
- properties.add(currentSimpleProperty);
-
- if (((SingularAttribute<?, ?>) currentAttribute).isId()) {
- if (keyView == null) {
- keyView = new JPAEdmKey(JPAEdmProperty.this);
- keyViewBuilder = keyView.getBuilder();
- }
-
- keyViewBuilder.build();
- }
-
- break;
- case EMBEDDED:
- ComplexType complexType = complexTypeView
- .searchEdmComplexType(currentAttribute.getJavaType().getName());
-
- if (complexType == null) {
- JPAEdmComplexTypeView complexTypeViewLocal = new JPAEdmComplexType(
- schemaView, currentAttribute);
- complexTypeViewLocal.getBuilder().build();
- complexType = complexTypeViewLocal.getEdmComplexType();
- complexTypeView.addJPAEdmCompleTypeView(complexTypeViewLocal);
-
- }
-
- if (isBuildModeComplexType == false
- && entityTypeView.getJPAEntityType().getIdType()
- .getJavaType()
- .equals(currentAttribute.getJavaType())) {
-
- if (keyView == null) {
- keyView = new JPAEdmKey(complexTypeView,
- JPAEdmProperty.this);
- }
- keyView.getBuilder().build();
- complexTypeView.expandEdmComplexType(complexType, properties, currentAttribute.getName());
- } else {
- currentComplexProperty = new ComplexProperty();
- if (isBuildModeComplexType) {
- JPAEdmNameBuilder
- .build((JPAEdmComplexPropertyView) JPAEdmProperty.this,
- complexTypeView.getJPAEmbeddableType().getJavaType().getSimpleName());
- } else {
- JPAEdmNameBuilder
- .build((JPAEdmComplexPropertyView) JPAEdmProperty.this,
- JPAEdmProperty.this, skipDefaultNaming);
- }
- currentComplexProperty.setType(new FullQualifiedName(
- schemaView.getEdmSchema().getNamespace(),
- complexType.getName()));
-
- properties.add(currentComplexProperty);
- if (!complexTypeView.isReferencedInKey(currentComplexProperty.getType().getName()))
- {
- complexTypeView.setReferencedInKey(currentComplexProperty.getType().getName());
- }
- }
-
- break;
- case MANY_TO_MANY:
- case ONE_TO_MANY:
- case ONE_TO_ONE:
- case MANY_TO_ONE:
-
- JPAEdmAssociationEndView associationEndView = new JPAEdmAssociationEnd(entityTypeView, JPAEdmProperty.this);
- associationEndView.getBuilder().build();
- JPAEdmAssociationView associationView = schemaView.getJPAEdmAssociationView();
- if (associationView.searchAssociation(associationEndView) == null) {
- int count = associationView.getNumberOfAssociationsWithSimilarEndPoints(associationEndView);
- JPAEdmAssociationView associationViewLocal =
- new JPAEdmAssociation(associationEndView, entityTypeView, JPAEdmProperty.this, count);
- associationViewLocal.getBuilder().build();
- associationView.addJPAEdmAssociationView(associationViewLocal, associationEndView);
- }
-
- JPAEdmReferentialConstraintView refConstraintView = new JPAEdmReferentialConstraint(
- associationView, entityTypeView, JPAEdmProperty.this);
- refConstraintView.getBuilder().build();
-
- if (refConstraintView.isExists()) {
- associationView.addJPAEdmRefConstraintView(refConstraintView);
- }
-
- if (navigationPropertyView == null) {
- navigationPropertyView = new JPAEdmNavigationProperty(schemaView);
- }
- currentEntityName = entityTypeView.getJPAEntityType().getName();
-
- if (currentAttribute.isCollection()) {
- targetEntityName = ((PluralAttribute<?, ?, ?>) currentAttribute).getElementType().getJavaType()
- .getSimpleName();
- } else {
- targetEntityName = currentAttribute.getJavaType().getSimpleName();
- }
- Integer sequenceNumber = associationCount.get(currentEntityName + targetEntityName);
- if (sequenceNumber == null) {
- sequenceNumber = new Integer(1);
- } else {
- sequenceNumber = new Integer(sequenceNumber.intValue() + 1);
- }
- associationCount.put(currentEntityName + targetEntityName, sequenceNumber);
- JPAEdmNavigationPropertyView localNavigationPropertyView =
- new JPAEdmNavigationProperty(associationView, JPAEdmProperty.this, sequenceNumber.intValue());
- localNavigationPropertyView.getBuilder().build();
- navigationPropertyView.addJPAEdmNavigationPropertyView(localNavigationPropertyView);
- break;
- default:
- break;
- }
- }
-
- }
-
- @SuppressWarnings("rawtypes")
- private List<Attribute<?, ?>> sortInAscendingOrder(final Set<?> jpaAttributes) {
- List<Attribute<?, ?>> jpaAttributeList = new ArrayList<Attribute<?, ?>>();
- Iterator itr = null;
- Attribute<?, ?> smallestJpaAttribute;
- Attribute<?, ?> currentJpaAttribute;
- while (!jpaAttributes.isEmpty()) {
- itr = jpaAttributes.iterator();
- smallestJpaAttribute = (Attribute<?, ?>) itr.next();
- while (itr.hasNext()) {
- currentJpaAttribute = (Attribute<?, ?>) itr.next();
- if (smallestJpaAttribute.getName().compareTo(currentJpaAttribute.getName()) > 0) {
- smallestJpaAttribute = currentJpaAttribute;
- }
- }
- jpaAttributeList.add(smallestJpaAttribute);
- jpaAttributes.remove(smallestJpaAttribute);
- }
- return jpaAttributeList;
- }
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return entityTypeView;
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return complexTypeView;
- }
-
- private boolean isExcluded(final JPAEdmPropertyView jpaEdmPropertyView, final String jpaEntityTypeName,
- final String jpaAttributeName) {
- JPAEdmMappingModelAccess mappingModelAccess = jpaEdmPropertyView
- .getJPAEdmMappingModelAccess();
- boolean isExcluded = false;
- if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
- // Exclusion of a simple property in a complex type
- if (isBuildModeComplexType
- && mappingModelAccess.checkExclusionOfJPAEmbeddableAttributeType(jpaEntityTypeName, jpaAttributeName)
- // Exclusion of a simple property of an Entity Type
- || (!isBuildModeComplexType && mappingModelAccess.checkExclusionOfJPAAttributeType(jpaEntityTypeName,
- jpaAttributeName))) {
- isExcluded = true;
- }
- }
- return isExcluded;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraint.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraint.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraint.java
deleted file mode 100644
index 2888a9a..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraint.java
+++ /dev/null
@@ -1,147 +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.odata2.processor.core.jpa.model;
-
-import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView.RoleType;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView;
-
-public class JPAEdmReferentialConstraint extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintView {
-
- private JPAEdmRefConstraintBuilder builder = null;
-
- private boolean exists = false;
- private boolean firstBuild = true;
-
- private JPAEdmAssociationView associationView;
- private JPAEdmPropertyView propertyView;
- private JPAEdmEntityTypeView entityTypeView;
-
- private ReferentialConstraint referentialConstraint;
-
- private JPAEdmReferentialConstraintRoleView principalRoleView;
- private JPAEdmReferentialConstraintRoleView dependentRoleView;
-
- private String relationShipName;
-
- public JPAEdmReferentialConstraint(final JPAEdmAssociationView associationView,
- final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView) {
- super(associationView);
- this.associationView = associationView;
- this.propertyView = propertyView;
- this.entityTypeView = entityTypeView;
-
- relationShipName = associationView.getEdmAssociation().getName();
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmRefConstraintBuilder();
- }
-
- return builder;
- }
-
- @Override
- public ReferentialConstraint getEdmReferentialConstraint() {
- return referentialConstraint;
- }
-
- @Override
- public boolean isExists() {
- return exists;
- }
-
- @Override
- public String getEdmRelationShipName() {
- return relationShipName;
- }
-
- private class JPAEdmRefConstraintBuilder implements JPAEdmBuilder {
- /*
- * Check if Ref Constraint was already Built. If Ref constraint was
- * already built consistently then do not build referential constraint.
- *
- * For Ref Constraint to be consistently built Principal and Dependent
- * roles must be consistently built. If Principal or Dependent roles are
- * not consistently built then try building them again.
- *
- * The Principal and Dependent roles could be have been built
- * inconsistently if the required EDM Entity Types or EDM properties are
- * yet to be built. In such cases rebuilding these roles would make them
- * consistent.
- */
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- if (firstBuild) {
- firstBuild();
- } else {
- if (exists && !firstBuild && principalRoleView.isConsistent() == false) {
- principalRoleView.getBuilder().build();
- }
-
- if (exists && !firstBuild && dependentRoleView.isConsistent() == false) {
- dependentRoleView.getBuilder().build();
- }
- }
-
- if (principalRoleView.isConsistent()) {
- referentialConstraint.setPrincipal(principalRoleView.getEdmReferentialConstraintRole());
- }
-
- if (dependentRoleView.isConsistent()) {
- referentialConstraint.setDependent(dependentRoleView.getEdmReferentialConstraintRole());
- }
-
- exists = principalRoleView.isExists() & dependentRoleView.isExists();
-
- isConsistent = principalRoleView.isConsistent() & dependentRoleView.isConsistent();
-
- }
-
- private void firstBuild() throws ODataJPAModelException, ODataJPARuntimeException {
- firstBuild = false;
- if (principalRoleView == null && dependentRoleView == null) {
-
- principalRoleView =
- new JPAEdmReferentialConstraintRole(RoleType.PRINCIPAL, entityTypeView, propertyView, associationView);
- principalRoleView.getBuilder().build();
-
- dependentRoleView =
- new JPAEdmReferentialConstraintRole(RoleType.DEPENDENT, entityTypeView, propertyView, associationView);
- dependentRoleView.getBuilder().build();
-
- if (referentialConstraint == null) {
- referentialConstraint = new ReferentialConstraint();
- }
- }
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRole.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRole.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRole.java
deleted file mode 100644
index 3761d4b..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmReferentialConstraintRole.java
+++ /dev/null
@@ -1,258 +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.odata2.processor.core.jpa.model;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView;
-
-public class JPAEdmReferentialConstraintRole extends JPAEdmBaseViewImpl implements JPAEdmReferentialConstraintRoleView {
- /*
- * Static Buffer
- */
- private static Attribute<?, ?> bufferedJPAAttribute = null;
- private static ArrayList<JoinColumn> bufferedJoinColumns = new ArrayList<JoinColumn>();
- /*
- * Static Buffer
- */
-
- private boolean firstBuild = true;
-
- private JPAEdmEntityTypeView entityTypeView;
- private JPAEdmReferentialConstraintRoleView.RoleType roleType;
-
- private Attribute<?, ?> jpaAttribute;
- private ArrayList<String> jpaColumnNames;
- private Association association;
-
- private boolean roleExists = false;
-
- private JPAEdmRefConstraintRoleBuilder builder;
- private ReferentialConstraintRole currentRole;
-
- public JPAEdmReferentialConstraintRole(final JPAEdmReferentialConstraintRoleView.RoleType roleType,
- final JPAEdmEntityTypeView entityTypeView, final JPAEdmPropertyView propertyView,
- final JPAEdmAssociationView associationView) {
-
- super(entityTypeView);
- this.entityTypeView = entityTypeView;
- this.roleType = roleType;
-
- jpaAttribute = propertyView.getJPAAttribute();
- association = associationView.getEdmAssociation();
-
- }
-
- @Override
- public boolean isExists() {
- return roleExists;
-
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmRefConstraintRoleBuilder();
- }
-
- return builder;
- }
-
- @Override
- public RoleType getRoleType() {
- return roleType;
- }
-
- @Override
- public ReferentialConstraintRole getEdmReferentialConstraintRole() {
- return currentRole;
- }
-
- @Override
- public String getJPAColumnName() {
- return null;
- }
-
- @Override
- public String getEdmEntityTypeName() {
- return null;
- }
-
- @Override
- public String getEdmAssociationName() {
- return null;
- }
-
- private class JPAEdmRefConstraintRoleBuilder implements JPAEdmBuilder {
-
- @Override
- public void build() throws ODataJPAModelException {
- if (firstBuild) {
- firstBuild();
- } else if (roleExists) {
- try {
- buildRole();
- } catch (SecurityException e) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
- } catch (NoSuchFieldException e) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.GENERAL.addContent(e.getMessage()), e);
- }
- }
-
- }
-
- private void firstBuild() {
- firstBuild = false;
- isConsistent = false;
-
- extractJoinColumns();
-
- if (!roleExists) {
- return;
- }
-
- jpaColumnNames = new ArrayList<String>();
-
- for (JoinColumn joinColumn : bufferedJoinColumns) {
- if (roleType == RoleType.PRINCIPAL) {
- jpaColumnNames.add(joinColumn.referencedColumnName());
- } else if (roleType == RoleType.DEPENDENT) {
- jpaColumnNames.add(joinColumn.name());
- }
- }
-
- }
-
- private void buildRole() throws SecurityException, NoSuchFieldException {
-
- if (currentRole == null) {
- currentRole = new ReferentialConstraintRole();
- String jpaAttributeType = null;
- EntityType edmEntityType = null;
-
- if (roleType == RoleType.PRINCIPAL) {
- jpaAttributeType = jpaAttribute.getJavaType().getSimpleName();
- if (jpaAttributeType.equals("List")) {
- Type type =
- ((ParameterizedType) jpaAttribute.getJavaMember().getDeclaringClass().getDeclaredField(
- jpaAttribute.getName()).getGenericType()).getActualTypeArguments()[0];
- int lastIndexOfDot = type.toString().lastIndexOf(".");
- jpaAttributeType = type.toString().substring(lastIndexOfDot + 1);
- }
- edmEntityType = entityTypeView.searchEdmEntityType(jpaAttributeType);
- } else if (roleType == RoleType.DEPENDENT) {
- edmEntityType =
- entityTypeView.searchEdmEntityType(jpaAttribute.getDeclaringType().getJavaType().getSimpleName());
- }
-
- List<PropertyRef> propertyRefs = new ArrayList<PropertyRef>();
- if (edmEntityType != null) {
- for (String columnName : jpaColumnNames) {
- for (Property property : edmEntityType.getProperties()) {
- if (columnName.equals(((JPAEdmMapping) property.getMapping()).getJPAColumnName())) {
- PropertyRef propertyRef = new PropertyRef();
- propertyRef.setName(property.getName());
- propertyRefs.add(propertyRef);
- break;
- }
- }
- }
- currentRole.setPropertyRefs(propertyRefs);
- if (propertyRefs.isEmpty()) {
- isConsistent = false;
- return;
- }
- AssociationEnd end = association.getEnd1();
- if (end.getType().getName().equals(edmEntityType.getName())) {
- currentRole.setRole(end.getRole());
- isConsistent = true;
- } else {
- end = association.getEnd2();
- if (end.getType().getName().equals(edmEntityType.getName())) {
- currentRole.setRole(end.getRole());
- isConsistent = true;
- }
- }
- }
-
- }
- }
-
- private void extractJoinColumns() {
- /*
- * Check against Static Buffer whether the join column was already
- * extracted.
- */
- if (!jpaAttribute.equals(bufferedJPAAttribute)) {
- bufferedJPAAttribute = jpaAttribute;
- bufferedJoinColumns.clear();
- } else if (bufferedJoinColumns.isEmpty()) {
- roleExists = false;
- return;
- } else {
- roleExists = true;
- return;
- }
-
- AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember();
-
- if (annotatedElement == null) {
- return;
- }
-
- JoinColumn joinColumn = annotatedElement.getAnnotation(JoinColumn.class);
- if (joinColumn == null) {
- JoinColumns joinColumns = annotatedElement.getAnnotation(JoinColumns.class);
-
- if (joinColumns != null) {
- JoinColumn[] joinColumnArray = joinColumns.value();
-
- for (JoinColumn element : joinColumnArray) {
- bufferedJoinColumns.add(element);
- }
- } else {
- return;
- }
- } else {
- bufferedJoinColumns.add(joinColumn);
- }
- roleExists = true;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
deleted file mode 100644
index c6f543a..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmSchema.java
+++ /dev/null
@@ -1,214 +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.odata2.processor.core.jpa.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmFunctionImportView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-
-public class JPAEdmSchema extends JPAEdmBaseViewImpl implements JPAEdmSchemaView {
-
- private Schema schema;
- private JPAEdmComplexTypeView complexTypeView;
- private JPAEdmEntityContainerView entityContainerView;
- private JPAEdmAssociationView associationView = null;
- private HashMap<Class<?>, String[]> customOperations = null;
-
- public JPAEdmSchema(final JPAEdmModelView modelView) {
- super(modelView);
- }
-
- @Override
- public Schema getEdmSchema() {
- return schema;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return entityContainerView;
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return complexTypeView;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- if (builder == null) {
- builder = new JPAEdmSchemaBuilder();
- }
-
- return builder;
- }
-
- @Override
- public void clean() {
- super.clean();
- schema = null;
- }
-
- private class JPAEdmSchemaBuilder implements JPAEdmBuilder {
- /*
- *
- * Each call to build method creates a new EDM Schema. The newly created
- * schema is built with Entity Containers, associations, Complex Types
- * and Entity Types.
- *
- * ************************************************************ Build
- * EDM Schema - STEPS
- * ************************************************************ 1) Build
- * Name for EDM Schema 2) Build EDM Complex Types from JPA Embeddable
- * Types 3) Add EDM Complex Types to EDM Schema 4) Build EDM Entity
- * Container 5) Add EDM Entity Container to EDM Schema 6) Fetch Built
- * EDM Entity Types from EDM Entity Container 7) Add EDM Entity Types to
- * EDM Schema 8) Fetch Built EDM Association Sets from EDM Entity
- * Container 9) Fetch Built EDM Associations from EDM Association Set
- * 10) Add EDM Association to EDM Schema
- * ************************************************************ Build
- * EDM Schema - STEPS
- * ************************************************************
- */
- @Override
- public void build() throws ODataJPAModelException, ODataJPARuntimeException {
-
- schema = new Schema();
- JPAEdmNameBuilder.build(JPAEdmSchema.this);
-
- associationView = new JPAEdmAssociation(JPAEdmSchema.this);
-
- complexTypeView = new JPAEdmComplexType(JPAEdmSchema.this);
- complexTypeView.getBuilder().build();
-
- entityContainerView = new JPAEdmEntityContainer(JPAEdmSchema.this);
- entityContainerView.getBuilder().build();
- schema.setEntityContainers(entityContainerView.getConsistentEdmEntityContainerList());
-
- JPAEdmEntitySetView entitySetView = entityContainerView.getJPAEdmEntitySetView();
- if (entitySetView.isConsistent() && entitySetView.getJPAEdmEntityTypeView() != null) {
- JPAEdmEntityTypeView entityTypeView = entitySetView.getJPAEdmEntityTypeView();
- if (entityTypeView.isConsistent() && !entityTypeView.getConsistentEdmEntityTypes().isEmpty()) {
- schema.setEntityTypes(entityTypeView.getConsistentEdmEntityTypes());
- }
- }
- if (complexTypeView.isConsistent()) {
- List<ComplexType> complexTypes = complexTypeView.getConsistentEdmComplexTypes();
- List<ComplexType> existingComplexTypes = new ArrayList<ComplexType>();
- for (ComplexType complexType : complexTypes) {
- if (complexType != null && complexTypeView.isReferencedInKey(complexType.getName())) {// null check for
- // exclude
- existingComplexTypes.add(complexType);
- }
- }
- if (!existingComplexTypes.isEmpty()) {
- schema.setComplexTypes(existingComplexTypes);
- }
- }
-
- List<String> existingAssociationList = new ArrayList<String>();
- if (associationView.isConsistent() && !associationView.getConsistentEdmAssociationList().isEmpty()) {
-
- List<Association> consistentAssociationList = associationView.getConsistentEdmAssociationList();
- schema.setAssociations(consistentAssociationList);
- for (Association association : consistentAssociationList) {
- existingAssociationList.add(association.getName());
- }
-
- }
- List<EntityType> entityTypes =
- entityContainerView.getJPAEdmEntitySetView().getJPAEdmEntityTypeView().getConsistentEdmEntityTypes();
- List<NavigationProperty> navigationProperties;
- if (entityTypes != null && !entityTypes.isEmpty()) {
- for (EntityType entityType : entityTypes) {
-
- List<NavigationProperty> consistentNavigationProperties = null;
- navigationProperties = entityType.getNavigationProperties();
- if (navigationProperties != null) {
- consistentNavigationProperties = new ArrayList<NavigationProperty>();
- for (NavigationProperty navigationProperty : navigationProperties) {
- if (existingAssociationList.contains(navigationProperty.getRelationship().getName())) {
- consistentNavigationProperties.add(navigationProperty);
- }
- }
- if (consistentNavigationProperties.isEmpty()) {
- entityType.setNavigationProperties(null);
- } else {
- entityType.setNavigationProperties(consistentNavigationProperties);
- }
- }
-
- }
- }
-
- JPAEdmExtension edmExtension = getJPAEdmExtension();
- if (edmExtension != null) {
- edmExtension.extendJPAEdmSchema(JPAEdmSchema.this);
- edmExtension.extendWithOperation(JPAEdmSchema.this);
-
- JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(JPAEdmSchema.this);
- functionImportView.getBuilder().build();
- if (functionImportView.getConsistentFunctionImportList() != null) {
- entityContainerView.getEdmEntityContainer().setFunctionImports(
- functionImportView.getConsistentFunctionImportList());
- }
-
- }
- }
-
- }
-
- @Override
- public final JPAEdmAssociationView getJPAEdmAssociationView() {
- return associationView;
- }
-
- @Override
- public void registerOperations(final Class<?> customClass, final String[] methodNames) {
- if (customOperations == null) {
- customOperations = new HashMap<Class<?>, String[]>();
- }
-
- customOperations.put(customClass, methodNames);
-
- }
-
- @Override
- public HashMap<Class<?>, String[]> getRegisteredOperations() {
- return customOperations;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportBuilder.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportBuilder.java
deleted file mode 100644
index da8054c..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/model/_JPAEdmFunctionImportBuilder.java
+++ /dev/null
@@ -1,237 +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.odata2.processor.core.jpa.model;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
-import org.apache.olingo.odata2.api.annotation.edm.Parameter;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.Facets;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPAEdmNameBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.access.model.JPATypeConvertor;
-
-@Deprecated
-public final class _JPAEdmFunctionImportBuilder {
-
- private JPAEdmEntityTypeView jpaEdmEntityTypeView = null;
- private JPAEdmComplexTypeView jpaEdmComplexTypeView = null;
- private JPAEdmSchemaView schemaView;
-
- public void setJPAEdmEntityTypeView(final JPAEdmEntityTypeView jpaEdmEntityTypeView) {
- this.jpaEdmEntityTypeView = jpaEdmEntityTypeView;
- }
-
- public void setSchemaView(final JPAEdmSchemaView schemaView) {
- this.schemaView = schemaView;
- }
-
- public void setJPAEdmComplexTypeView(final JPAEdmComplexTypeView jpaEdmComplexTypeView) {
- this.jpaEdmComplexTypeView = jpaEdmComplexTypeView;
- }
-
- public FunctionImport buildFunctionImport(final Method method,
- final org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation) throws ODataJPAModelException {
-
- if (method != null && annotation != null && annotation.returnType() != ReturnType.NONE) {
- FunctionImport functionImport = new FunctionImport();
-
- if (annotation.name().equals("")) {
- functionImport.setName(method.getName());
- } else {
- functionImport.setName(annotation.name());
- }
-
- JPAEdmMapping mapping = new JPAEdmMappingImpl();
- ((Mapping) mapping).setInternalName(method.getName());
- mapping.setJPAType(method.getDeclaringClass());
- functionImport.setMapping((Mapping) mapping);
-
- functionImport.setHttpMethod(annotation.httpMethod().name().toString());
-
- buildReturnType(functionImport, method, annotation);
- buildParameter(functionImport, method);
- return functionImport;
- }
- return null;
-
- }
-
- private void buildParameter(final FunctionImport functionImport, final Method method)
- throws ODataJPAModelException {
-
- Annotation[][] annotations = method.getParameterAnnotations();
- Class<?>[] parameterTypes = method.getParameterTypes();
- List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>();
- JPAEdmMapping mapping = null;
- int j = 0;
- for (Annotation[] annotationArr : annotations) {
- Class<?> parameterType = parameterTypes[j++];
-
- for (Annotation element : annotationArr) {
- if (element instanceof Parameter) {
- Parameter annotation = (Parameter) element;
- FunctionImportParameter functionImportParameter = new FunctionImportParameter();
- if (annotation.name().equals("")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method
- .getDeclaringClass().getName(), method.getName()), null);
- } else {
- functionImportParameter.setName(annotation.name());
- }
-
- functionImportParameter.setType(JPATypeConvertor.convertToEdmSimpleType(parameterType, null));
- functionImportParameter.setMode(annotation.mode().toString());
-
- Facets facets = new Facets();
- if (annotation.facets().maxLength() > 0) {
- facets.setMaxLength(annotation.facets().maxLength());
- }
- if (annotation.facets().nullable() == false) {
- facets.setNullable(false);
- } else {
- facets.setNullable(true);
- }
-
- if (annotation.facets().precision() > 0) {
- facets.setPrecision(annotation.facets().precision());
- }
- if (annotation.facets().scale() >= 0) {
- facets.setScale(annotation.facets().scale());
- }
-
- functionImportParameter.setFacets(facets);
- mapping = new JPAEdmMappingImpl();
- mapping.setJPAType(parameterType);
- functionImportParameter.setMapping((Mapping) mapping);
- funcImpList.add(functionImportParameter);
- }
- }
- }
- if (!funcImpList.isEmpty()) {
- functionImport.setParameters(funcImpList);
- }
- }
-
- private void buildReturnType(final FunctionImport functionImport, final Method method,
- final org.apache.olingo.odata2.api.annotation.edm.FunctionImport annotation) throws ODataJPAModelException {
- org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType returnType = annotation.returnType();
- Multiplicity multiplicity = null;
-
- if (returnType != ReturnType.NONE) {
- org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType =
- new org.apache.olingo.odata2.api.edm.provider.ReturnType();
- multiplicity = annotation.multiplicity();
-
- if (multiplicity == Multiplicity.MANY) {
- functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
- } else {
- functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
- }
-
- if (returnType == ReturnType.ENTITY_TYPE) {
- String entitySet = annotation.entitySet();
- if (entitySet.equals("")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
- }
- functionImport.setEntitySet(entitySet);
- }
-
- Class<?> methodReturnType = method.getReturnType();
- if (methodReturnType == null || methodReturnType.getName().equals("void")) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method
- .getDeclaringClass(), method.getName()), null);
- }
- switch (returnType) {
- case ENTITY_TYPE:
- EntityType edmEntityType = null;
- if (multiplicity == Multiplicity.ONE) {
- edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName());
- } else if (multiplicity == Multiplicity.MANY) {
- edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method));
- }
-
- if (edmEntityType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
- }
- functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName()));
- break;
- case SCALAR:
-
- EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConvertor.convertToEdmSimpleType(methodReturnType, null);
- functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName());
-
- break;
- case COMPLEX_TYPE:
- ComplexType complexType = null;
- if (multiplicity == Multiplicity.ONE) {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(methodReturnType.getName());
- } else if (multiplicity == Multiplicity.MANY) {
- complexType = jpaEdmComplexTypeView.searchEdmComplexType(getReturnTypeName(method));
- }
- if (complexType == null) {
- throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
- .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
- }
- functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
- break;
- default:
- break;
- }
- functionImport.setReturnType(functionReturnType);
- }
- }
-
- private String getReturnTypeName(final Method method) {
- try {
- ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
- Type t = pt.getActualTypeArguments()[0];
- return ((Class<?>) t).getName();
- } catch (ClassCastException e) {
- return method.getReturnType().getName();
- }
- }
-
- private String getReturnTypeSimpleName(final Method method) {
- try {
- ParameterizedType pt = (ParameterizedType) method.getGenericReturnType();
- Type t = pt.getActualTypeArguments()[0];
- return ((Class<?>) t).getSimpleName();
- } catch (ClassCastException e) {
- return method.getReturnType().getSimpleName();
- }
- }
-}
[39/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmBaseView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmBaseView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmBaseView.java
new file mode 100644
index 0000000..56aa8b3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmBaseView.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmMappingModelAccess;
+
+/**
+ * <p>
+ * A base view on Java Persistence Model and Entity Data Model.
+ * </p>
+ * <p>
+ * The implementation of the view acts as a base container for containers of
+ * Java Persistence Model and Entity Data Model elements.
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ *
+ */
+public interface JPAEdmBaseView {
+ /**
+ *
+ * @return Java Persistence Unit Name
+ */
+ public String getpUnitName();
+
+ /**
+ * The method returns the Java Persistence MetaModel
+ *
+ * @return a meta model of type {@link javax.persistence.metamodel.Metamodel}
+ */
+ public Metamodel getJPAMetaModel();
+
+ /**
+ * The method returns a builder for building Entity Data Model elements from
+ * Java Persistence Model Elements
+ *
+ * @return a builder of type {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder}
+ */
+ public JPAEdmBuilder getBuilder();
+
+ /**
+ * The method returns the if the container is consistent without any errors
+ *
+ * @return <ul>
+ * <li>true - if the container is consistent without errors</li>
+ * <li>false - if the container is inconsistent with errors</li>
+ * </ul>
+ *
+ */
+ public boolean isConsistent();
+
+ /**
+ * The method cleans the container.
+ */
+ public void clean();
+
+ /**
+ * The method returns a reference to JPA EDM mapping model access.
+ *
+ * @return an instance to JPA EDM mapping model access
+ */
+ public JPAEdmMappingModelAccess getJPAEdmMappingModelAccess();
+
+ /**
+ * The method returns a reference to JPA EDM extension if available else
+ * null.
+ *
+ * @return an instance of JPA Edm Extension
+ */
+ public JPAEdmExtension getJPAEdmExtension();
+
+ /**
+ * The method returns whether the default naming logic is skipped for the
+ * current view.
+ *
+ * @return <ul><li>true - skip default naming logic</li>
+ * <li>false - do not skip default naming logic</li>
+ * </ul>
+ */
+ public boolean isDefaultNamingSkipped();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexPropertyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexPropertyView.java
new file mode 100644
index 0000000..6b4918c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexPropertyView.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.odata2.jpa.processor.api.model;
+
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+
+/**
+ * <p>
+ * A view on properties of Java Persistence embeddable type and EDM complex
+ * type. Properties of JPA embeddable types are converted into EDM properties of
+ * EDM complex type.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to properties of EDM complex
+ * type created for a given JPA EDM complex type. The implementation acts as a
+ * container for the properties of EDM complex type.
+ * </p>
+ *
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView
+ */
+public interface JPAEdmComplexPropertyView extends JPAEdmBaseView {
+ /**
+ * The method returns a complex property for a complex type.
+ *
+ * @return an instance of {@link org.apache.olingo.odata2.api.edm.provider.ComplexProperty}
+ */
+ ComplexProperty getEdmComplexProperty();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexTypeView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexTypeView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexTypeView.java
new file mode 100644
index 0000000..8b087c8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmComplexTypeView.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+
+/**
+ * A view on Java Persistence embeddable types and EDM complex types. Java
+ * persistence embeddable types are converted into EDM entity types. Only those
+ * embeddable types that are
+ * <ol>
+ * <li>used in a java persistence Entity type</li>
+ * <li>used as non embeddable id of a java persistence entity type</li>
+ * </ol>
+ * are converted into EDM complex types.
+ * <p>
+ * The implementation of the view provides access to EDM complex types for the
+ * given JPA EDM model. The view acts as a container for consistent list of EDM
+ * complex types. An EDM complex type is said to be consistent only if it used
+ * in at least one of the EDM entity type.
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexPropertyView
+ *
+ */
+public interface JPAEdmComplexTypeView extends JPAEdmBaseView {
+
+ /**
+ * The method returns an EDM complex type that is currently being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.ComplexType}
+ */
+ public ComplexType getEdmComplexType();
+
+ /**
+ * The method returns an JPA embeddable type that is currently being
+ * processed.
+ *
+ * @return an instance of type {@link javax.persistence.metamodel.EmbeddableType}
+ */
+ public javax.persistence.metamodel.EmbeddableType<?> getJPAEmbeddableType();
+
+ /**
+ * The method returns a consistent list of EDM complex types.
+ *
+ * @return a list of {@link org.apache.olingo.odata2.api.edm.provider.ComplexType}
+ */
+ public List<ComplexType> getConsistentEdmComplexTypes();
+
+ /**
+ * The method searches for the EDM complex type with in the container for
+ * the given JPA embeddable type name.
+ *
+ * @param embeddableTypeName
+ * is the name of JPA embeddable type
+ * @return a reference to EDM complex type if found else null
+ */
+ public ComplexType searchEdmComplexType(String embeddableTypeName);
+
+ /**
+ * The method add a JPA EDM complex type view to the container.
+ *
+ * @param view
+ * @param isReferencedInKey
+ * is the complex type referenced in an Entity as a key property
+ * is an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView}
+ */
+ public void addJPAEdmCompleTypeView(JPAEdmComplexTypeView view);
+
+ /**
+ * The method searches for the EDM complex type with in the container for
+ * the given EDM complex type's fully qualified name.
+ *
+ * @param type
+ * is the fully qualified name of EDM complex type
+ * @return a reference to EDM complex type if found else null
+ */
+ public ComplexType searchEdmComplexType(FullQualifiedName type);
+
+ /**
+ * The method expands the given EDM complex type into a list of EDM simple
+ * properties.
+ *
+ * @param complexType
+ * is the EDM complex type to expand
+ * @param expandedPropertyList
+ * is the list to be populated with expanded EDM simple
+ * properties
+ * @param embeddablePropertyName
+ * is the name of the complex property. The name is used as the
+ * qualifier for the expanded simple property names.
+ */
+ public void expandEdmComplexType(ComplexType complexType, List<Property> expandedPropertyList,
+ String embeddablePropertyName);
+
+ /**
+ * The method checks if the given EDM complex type is referenced as a Key property in any Entity
+ * @param complexTypeName
+ * EDM complex type name
+ * @return
+ * <ul><li><b>true</b> : if the complex type is referenced as an entity's key property</li>
+ * <li><b>false</b> : if the complex type is not referenced as an entity's key property</li>
+ * </ul>
+ *
+ */
+ public boolean isReferencedInKey(String complexTypeName);
+
+ /**
+ * The method sets the given EDM complex type as referenced in an Entity as a key property
+ * @param complexTypeName
+ * EDM complex Type name
+ */
+ public void setReferencedInKey(String complexTypeName);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityContainerView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityContainerView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityContainerView.java
new file mode 100644
index 0000000..b0e5e3d
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityContainerView.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+
+/**
+ * A view on JPA EDM entity container. JPA EDM entity container is built from
+ * consistent JPA EDM entity set and consistent JPA EDM association set views.
+ *
+ * <p>
+ * The implementation of the view provides access to EDM entity containers. The
+ * view acts as container for JPA EDM entity containers. A JPA EDM entity
+ * container is said to be consistent only if the JPA EDM association set and
+ * JPA EDM Entity Set view are consistent.
+ *
+ *
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView
+ *
+ */
+public interface JPAEdmEntityContainerView extends JPAEdmBaseView {
+ /**
+ * The method returns the EDM entity container that is currently being
+ * processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.EntityContainer}
+ */
+ public EntityContainer getEdmEntityContainer();
+
+ /**
+ * The method returns a list of consistent EDM entity containers
+ *
+ * @return a list of consistent EDM entity containers
+ */
+ public List<EntityContainer> getConsistentEdmEntityContainerList();
+
+ /**
+ * The method returns the JPA EDM entity set view that is currently being
+ * processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView}
+ */
+ public JPAEdmEntitySetView getJPAEdmEntitySetView();
+
+ /**
+ * The method returns the JPA EDM association set view that is currently
+ * being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationSetView}
+ */
+ public JPAEdmAssociationSetView getEdmAssociationSetView();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntitySetView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntitySetView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntitySetView.java
new file mode 100644
index 0000000..7cd5e73
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntitySetView.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+
+/**
+ * A view on Java Persistence entity type and EDM entity sets. Java persistence
+ * entity types are converted into EDM entity types and EDM entity sets.
+ * <p>
+ * The implementation of the view provides access to EDM entity sets for the
+ * given JPA EDM entity type. The view acts as a container for consistent list
+ * of EDM entity sets. An EDM entity set is said to be consistent only if it has
+ * consistent EDM entity types.
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView
+ *
+ */
+public interface JPAEdmEntitySetView extends JPAEdmBaseView {
+ /**
+ * The method returns an EDM entity set that is currently being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.EntitySet}
+ */
+ public EntitySet getEdmEntitySet();
+
+ /**
+ * The method returns a list of consistent EDM entity sets.
+ *
+ * @return a list of EDM entity sets
+ */
+ public List<EntitySet> getConsistentEdmEntitySetList();
+
+ /**
+ * The method returns a JPA EDM entity type view that is currently being
+ * processed. JPA EDM entity set view is built from JPA EDM entity type
+ * view.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView}
+ */
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityTypeView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityTypeView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityTypeView.java
new file mode 100644
index 0000000..80de084
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmEntityTypeView.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+
+/**
+ * A view on Java Persistence entity types and EDM entity types. Java
+ * persistence entity types are converted into EDM entity types.
+ * <p>
+ * The implementation of the view provides access to EDM entity types for the
+ * given JPA EDM model. The view acts as a container for consistent list of EDM
+ * entity types. An EDM entity type is said to be consistent only if it has at
+ * least one consistent EDM property and at least one consistent EDM key.
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView
+ *
+ */
+public interface JPAEdmEntityTypeView extends JPAEdmBaseView {
+ /**
+ * The method returns an EDM entity currently being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.EntityType}
+ */
+ public EntityType getEdmEntityType();
+
+ /**
+ * The method returns java persistence Entity type currently being
+ * processed.
+ *
+ * @return an instance of type {@link javax.persistence.metamodel.EntityType}
+ */
+ public javax.persistence.metamodel.EntityType<?> getJPAEntityType();
+
+ /**
+ * The method returns a consistent list of EDM entity types for a given java
+ * persistence meta model.
+ *
+ * @return a list of {@link org.apache.olingo.odata2.api.edm.provider.EntityType}
+ */
+ public List<EntityType> getConsistentEdmEntityTypes();
+
+ /**
+ * The method searches in the consistent list of EDM entity types for the
+ * given EDM entity type's name.
+ *
+ * @param jpaEntityTypeName
+ * is the name of EDM entity type
+ * @return a reference to EDM entity type if found else null
+ */
+ public EntityType searchEdmEntityType(String jpaEntityTypeName);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmExtension.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmExtension.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmExtension.java
new file mode 100644
index 0000000..18f43a0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmExtension.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+/**
+ * The interface provides methods to extend JPA EDM containers.
+ *
+ *
+ *
+ */
+public interface JPAEdmExtension {
+
+ /**
+ * The method is used to extend the JPA EDM schema view with custom operations. Use this method to
+ * register custom operations.
+ *
+ * @param view
+ * is the schema view
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView#registerOperations(Class, String[])
+ *
+ */
+ public void extendWithOperation(JPAEdmSchemaView view);
+
+ /**
+ * The method is used to extend the JPA EDM schema view with Entities, Entity Sets, Navigation Property and
+ * Association.
+ *
+ * @param view
+ * is the schema view
+ *
+ */
+ public void extendJPAEdmSchema(JPAEdmSchemaView view);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmFunctionImportView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmFunctionImportView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmFunctionImportView.java
new file mode 100644
index 0000000..214f834
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmFunctionImportView.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+
+/**
+ * <p>
+ * A view on EDM Function Imports. EDM function imports are derived from Java
+ * class methods annotated with EDM Annotations.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM Function Import created
+ * from Java class methods. The implementation act as a container for list of
+ * function imports that are consistent.
+ * </p>
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ *
+ */
+public interface JPAEdmFunctionImportView extends JPAEdmBaseView {
+
+ /**
+ * The method returns a list of consistent Function Imports. A function
+ * import is said to be consistent only if it adheres to the rules defined
+ * in CSDL.
+ *
+ * @return a list of type {@link org.apache.olingo.odata2.api.edm.provider.FunctionImport}
+ */
+ List<FunctionImport> getConsistentFunctionImportList();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmKeyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmKeyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmKeyView.java
new file mode 100644
index 0000000..431a93e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmKeyView.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import org.apache.olingo.odata2.api.edm.provider.Key;
+
+/**
+ * A view on Java Persistence Entity Key Attributes and EDM Key properties. Java
+ * Persistence Key Attributes of type
+ * <ol>
+ * <li>embedded ID</li>
+ * <li>ID</li>
+ * </ol>
+ * are converted into EDM keys. Embedded IDs are expanded into simple EDM
+ * properties.
+ * <p>
+ * The implementation of the view provides access to EDM key properties for a
+ * given JPA EDM entity type. The view acts as a container for consistent EDM
+ * key property of an EDM entity type.
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmPropertyView
+ *
+ */
+public interface JPAEdmKeyView extends JPAEdmBaseView {
+ /**
+ * The method returns an instance of EDM key for the given JPA EDM Entity
+ * type.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.Key}
+ */
+ public Key getEdmKey();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
new file mode 100644
index 0000000..4b77b6d
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmMapping.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+/**
+ * The interface acts a container for storing Java persistence column name. The
+ * JPA EDM mapping instance can be associated with any EDM simple, EDM complex
+ * property to denote the properties Java persistence column name.
+ *
+ *
+ *
+ */
+public interface JPAEdmMapping {
+ /**
+ * The method sets the Java persistence column name into the mapping
+ * container.
+ *
+ * @param name
+ * is the Java persistence column name
+ */
+ public void setJPAColumnName(String name);
+
+ /**
+ * The method gets the Java persistence column name from the mapping
+ * container.
+ *
+ * @return a String representing the Java persistence column name set into
+ * the container
+ */
+ public String getJPAColumnName();
+
+ /**
+ * The method sets the Java persistence entity/property type.
+ *
+ * @param type
+ * is an instance of type Class<?>
+ */
+ public void setJPAType(Class<?> type);
+
+ /**
+ * The method returns the Java persistence entity/property type.
+ *
+ * @return type
+ */
+ public Class<?> getJPAType();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmModelView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmModelView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmModelView.java
new file mode 100644
index 0000000..0dcbe87
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmModelView.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+/**
+ * A view on JPA meta model and EDM meta model. The view acts as the base for
+ * the construction of EDM meta model from a JPA meta model.
+ * <p>
+ * The implementation of the view acts as the container for JPA meta model and
+ * EDM meta model. The instance of JPA EDM meta model can be created using
+ * {@link org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory}. The
+ * instance thus obtained can be used for constructing other elements of the
+ * meta model using {@link org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder}.
+ *
+ *
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.factory.JPAAccessFactory
+ */
+public interface JPAEdmModelView extends JPAEdmBaseView {
+ /**
+ * The method returns a consistent JPA EDM schema view created from the JPA
+ * meta model.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmSchemaView}
+ */
+ public JPAEdmSchemaView getEdmSchemaView();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmNavigationPropertyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmNavigationPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmNavigationPropertyView.java
new file mode 100644
index 0000000..f8fce6d
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmNavigationPropertyView.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.provider.NavigationProperty;
+
+/**
+ * A view on Java persistence entity relationship and EDM navigation property.
+ * Java persistence entity relationships annotated as
+ * <ol>
+ * <li>Many To Many</li>
+ * <li>One To Many</li>
+ * <li>One To One</li>
+ * <li>Many To One</li>
+ * </ol>
+ * are transformed into navigation properties.
+ * <p>
+ * The implementation of the view provides access to EDM navigation properties
+ * for a given JPA EDM entity type. The view acts as a container for consistent
+ * list of EDM navigation properties of an EDM entity type. EDM navigation
+ * property is consistent only if there exists a consistent EDM association.
+ *
+ *
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView
+ *
+ */
+public interface JPAEdmNavigationPropertyView extends JPAEdmBaseView {
+ /**
+ * The method adds a navigation property view to its container.
+ *
+ * @param view
+ * is an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView}
+ */
+ void addJPAEdmNavigationPropertyView(JPAEdmNavigationPropertyView view);
+
+ /**
+ * The method returns a consistent list of EDM navigation property. A
+ * navigation property is consistent only if all its mandatory properties
+ * can be built with no errors from Java persistence entity relationship.
+ *
+ * @return a list of consistent EDM navigation property for the Entity
+ */
+ List<NavigationProperty> getConsistentEdmNavigationProperties();
+
+ /**
+ * The method returns the navigation property that is currently being
+ * processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.NavigationProperty}
+ */
+ NavigationProperty getEdmNavigationProperty();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java
new file mode 100644
index 0000000..c363844
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmPropertyView.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.List;
+
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+
+/**
+ * A view on Java Persistence Entity Attributes and EDM properties. Java
+ * Persistence Attributes of type
+ * <ol>
+ * <li>embedded ID - are converted into EDM keys</li>
+ * <li>ID - are converted into EDM keys</li>
+ * <li>attributes - are converted into EDM properties</li>
+ * <li>embeddable type - are converted into EDM complex properties</li>
+ * <li>relationships - are converted into Associations/Navigation properties</li>
+ * </ol>
+ * <p>
+ * The implementation of the view provides access to EDM properties for a given
+ * JPA EDM entity type. The view acts as a container for consistent list of EDM
+ * properties of an EDM entity type. EDM property is consistent only if there
+ * exists at least one property in the entity type and there is at least one key
+ * property.
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView
+ *
+ */
+public interface JPAEdmPropertyView extends JPAEdmBaseView {
+ /**
+ * The method returns a simple EDM property.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.SimpleProperty}
+ */
+ SimpleProperty getEdmSimpleProperty();
+
+ /**
+ * The method returns a JPA EDM key view.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView}
+ */
+ JPAEdmKeyView getJPAEdmKeyView();
+
+ /**
+ * The method returns a list of Properties for the given Entity Type.
+ *
+ * @return a list of {@link org.apache.olingo.odata2.api.edm.provider.Property}
+ */
+ List<Property> getEdmPropertyList();
+
+ /**
+ * The method returns a JPA Attribute for the given JPA entity type.
+ *
+ * @return an instance of type {@link javax.persistence.metamodel.Attribute
+ * <?, ?>}
+ */
+ Attribute<?, ?> getJPAAttribute();
+
+ /**
+ * The method returns a JPA EDM navigation property view.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmNavigationPropertyView}
+ */
+ JPAEdmNavigationPropertyView getJPAEdmNavigationPropertyView();
+
+ /**
+ * The method returns a JPA EDM Entity Type view that holds the property
+ * view.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView}
+ */
+ JPAEdmEntityTypeView getJPAEdmEntityTypeView();
+
+ /**
+ * The method returns a JPA EDM Complex Type view that holds the property
+ * view.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView}
+ */
+ JPAEdmComplexTypeView getJPAEdmComplexTypeView();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintRoleView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintRoleView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintRoleView.java
new file mode 100644
index 0000000..d90f57f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintRoleView.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole;
+
+/**
+ * <p>
+ * A view on Java Persistence Entity Join Column's "name" and
+ * "referenced column name" attributes and Entity Data Model Referential
+ * Constraint's dependent and principal roles respectively. Each java
+ * persistence entity with properties annotated with Join Columns are
+ * transformed into Referential constraints and Referential constraint roles.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM referential constraint
+ * roles created from Java Persistence Entity Join Columns. The implementation
+ * acts as a container for EDM referential constraint roles. A referential
+ * constraint role is consistent only if the principal role and dependent roles
+ * can be created from JPA Entity relationships.
+ * </p>
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView
+ *
+ */
+public interface JPAEdmReferentialConstraintRoleView extends JPAEdmBaseView {
+ /**
+ * Two types of EDM roles of a referential constraint.
+ */
+ public enum RoleType {
+ PRINCIPAL, DEPENDENT
+ }
+
+ /**
+ * The method returns the role type (PRINCIPAL or DEPENDENT)
+ *
+ * @return a {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView.RoleType}
+ */
+ RoleType getRoleType();
+
+ /**
+ * The method returns the Referential constraint role that is currently
+ * being processed.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.ReferentialConstraintRole}
+ */
+ ReferentialConstraintRole getEdmReferentialConstraintRole();
+
+ /**
+ * The method returns the name of JPA attribute's column name (annotated
+ * with @Column). The returned Column Name acts as the PRINCIPAL entity
+ * type.
+ *
+ * @return name of JPA Column name
+ */
+ String getJPAColumnName();
+
+ /**
+ * The method returns the EDM entity type name that holds the
+ * relationship/referential constraint. The entity type that acts as a
+ * DEPENDENT entity type.
+ *
+ * @return name of EDM entity type
+ */
+ String getEdmEntityTypeName();
+
+ /**
+ * The method returns the EDM association name.
+ *
+ * @return name of EDM association
+ */
+ String getEdmAssociationName();
+
+ /**
+ * The method tells if there exists a valid referential constraint for a
+ * given association.
+ *
+ * @return true - if valid referential constraint exits else false
+ */
+ boolean isExists();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintView.java
new file mode 100644
index 0000000..1d5433d
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmReferentialConstraintView.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint;
+
+/**
+ * <p>
+ * A view on Java Persistence Entity Join Columns and Entity Data Model
+ * Referential Constraint. Each java persistence entity with properties
+ * annotated with Join Columns are transformed into Referential constraints.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM referential constraint
+ * created from Java Persistence Entity Join Columns. The implementation acts as
+ * a container for EDM referential constraint. A referential constraint is said
+ * to be consistent only if referential constraint role is consistent.
+ * </p>
+ *
+ * <br>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * <br>
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintRoleView
+ *
+ */
+public interface JPAEdmReferentialConstraintView extends JPAEdmBaseView {
+
+ /**
+ * The method returns EDM referential constraint created from Java
+ * persistence Entity Join Columns.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.api.edm.provider.ReferentialConstraint}
+ */
+ public ReferentialConstraint getEdmReferentialConstraint();
+
+ /**
+ * The method returns if a valid referential constraint exists for a given
+ * EDM association. If there exists a JPA entity relationship with join
+ * column having a valid "Name" and "ReferenceColumnName", that can be
+ * mapped to EDM properties in dependent and source EDM entities
+ * respectively then a valid EDM referential constraint exists.
+ *
+ * @return true if there exists a valid referential constraint else false.
+ */
+ public boolean isExists();
+
+ /**
+ * The method returns the name of EDM Association.
+ *
+ * @return name of an EDM association
+ */
+ public String getEdmRelationShipName();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmSchemaView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmSchemaView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmSchemaView.java
new file mode 100644
index 0000000..980cf47
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/JPAEdmSchemaView.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model;
+
+import java.util.HashMap;
+
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+
+/**
+ * <p>
+ * A view on Java Persistence Model and Entity Data Model Schema. Each java
+ * persistence unit corresponds to a one EDM schema.
+ * </p>
+ * <p>
+ * The implementation of the view provides access to EDM schema created from
+ * Java Persistence unit. The implementation acts as a container for schema. The
+ * schema is consistent only if following elements are consistent
+ * <ol>
+ * <li>{@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}</li>
+ * <li> {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView}</li>
+ * <li>{@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView}</li>
+ * </ol>
+ * </p>
+ *
+ *
+ * <p>
+ * @org.apache.olingo.odata2.DoNotImplement
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView
+ * @see org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView
+ *
+ */
+public interface JPAEdmSchemaView extends JPAEdmBaseView {
+ /**
+ * The method returns the EDM schema present in the container.
+ *
+ * @return an instance EDM schema of type {@link org.apache.olingo.odata2.api.edm.provider.Schema}
+ */
+ public Schema getEdmSchema();
+
+ /**
+ * The method returns JPA EDM container view. The JPA EDM container view can
+ * be used to access EDM Entity Container elements.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView}
+ */
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView();
+
+ /**
+ * The method returns JPA EDM complex view. The JPA EDM complex view can be
+ * used to access EDM complex types and JPA Embeddable Types.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView}
+ */
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView();
+
+ /**
+ * The method returns JPA EDM association view. The JPA EDM association view
+ * can be used to access EDM associations and JPA Relationships.
+ *
+ * @return an instance of type {@link org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView}
+ */
+ public JPAEdmAssociationView getJPAEdmAssociationView();
+
+ /**
+ * The method registers custom operations that shall be represented as Edm
+ * Function Imports. Custom operations are created using Edm Annotation
+ * {@link org.apache.olingo.odata2.api.annotation.edm.FunctionImport}.
+ * <p>
+ * Custom Operations can be part of JPA Entity or can be created in a class
+ * other than JPA Entity. Such custom operations can be registered using
+ * this method.
+ * <p>
+ * The method is a callback.
+ *
+ * @param customClass
+ * is the class that contains custom operations
+ * @param methodNames
+ * is the name of the method that needs to be transformed into
+ * Function Imports. It is an optional parameter. If null is
+ * passed then all annotated methods are transformed into
+ * Function Imports.
+ *
+ */
+ public void registerOperations(Class<?> customClass, String methodNames[]);
+
+ /**
+ * The method returns an Hash Map containing the registered custom
+ * operations.
+ *
+ * @return a HashMap of Class and the methods in the class
+ */
+ public HashMap<Class<?>, String[]> getRegisteredOperations();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAAttributeMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAAttributeMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAAttributeMapType.java
new file mode 100644
index 0000000..e7bcbe9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAAttributeMapType.java
@@ -0,0 +1,202 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+/**
+ *
+ * The default name for EDM
+ * property is derived from JPA attribute name. This can be overriden
+ * using
+ * JPAAttributeMapType.
+ *
+ *
+ * <p>Java class for JPAAttributeMapType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="JPAAttributeMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="JPAAttribute" maxOccurs="unbounded" minOccurs="0">
+ * <complexType>
+ * <simpleContent>
+ * <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ * </extension>
+ * </simpleContent>
+ * </complexType>
+ * </element>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPAAttributeMapType", propOrder = { "jpaAttribute" })
+public class JPAAttributeMapType {
+
+ @XmlElement(name = "JPAAttribute")
+ protected List<JPAAttributeMapType.JPAAttribute> jpaAttribute;
+
+ /**
+ * Gets the value of the jpaAttribute property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list,
+ * not a snapshot. Therefore any modification you make to the
+ * returned list will be present inside the JAXB object.
+ * This is why there is not a <CODE>set</CODE> method for the jpaAttribute property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ * <pre>
+ * getJPAAttribute().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list {@link JPAAttributeMapType.JPAAttribute }
+ *
+ *
+ */
+ public List<JPAAttributeMapType.JPAAttribute> getJPAAttribute() {
+ if (jpaAttribute == null) {
+ jpaAttribute = new ArrayList<JPAAttributeMapType.JPAAttribute>();
+ }
+ return jpaAttribute;
+ }
+
+ /**
+ * <p>Java class for anonymous complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType>
+ * <simpleContent>
+ * <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ * </extension>
+ * </simpleContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = { "value" })
+ public static class JPAAttribute {
+
+ @XmlValue
+ protected String value;
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+ @XmlAttribute(name = "exclude")
+ protected Boolean exclude;
+
+ /**
+ * Gets the value of the value property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value of the value property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setValue(final String value) {
+ this.value = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setName(final String value) {
+ name = value;
+ }
+
+ /**
+ * Gets the value of the exclude property.
+ *
+ * @return
+ * possible object is {@link Boolean }
+ *
+ */
+ public boolean isExclude() {
+ if (exclude == null) {
+ return false;
+ } else {
+ return exclude;
+ }
+ }
+
+ /**
+ * Sets the value of the exclude property.
+ *
+ * @param value
+ * allowed object is {@link Boolean }
+ *
+ */
+ public void setExclude(final Boolean value) {
+ exclude = value;
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModel.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModel.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModel.java
new file mode 100644
index 0000000..a4175d4
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModel.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * <p>
+ * Java class for anonymous complex type.
+ *
+ * <p>
+ * The following schema fragment specifies the expected content contained within
+ * this class.
+ *
+ * <pre>
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="PersistenceUnit"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAPersistenceUnitMapType"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = { "persistenceUnit" })
+@XmlRootElement(name = "JPAEDMMappingModel")
+public class JPAEdmMappingModel {
+
+ @XmlElement(name = "PersistenceUnit", required = true)
+ protected JPAPersistenceUnitMapType persistenceUnit;
+
+ /**
+ * Gets the value of the persistenceUnit property.
+ *
+ * @return possible object is {@link JPAPersistenceUnitMapType }
+ *
+ */
+ public JPAPersistenceUnitMapType getPersistenceUnit() {
+ return persistenceUnit;
+ }
+
+ /**
+ * Sets the value of the persistenceUnit property.
+ *
+ * @param value
+ * allowed object is {@link JPAPersistenceUnitMapType }
+ *
+ */
+ public void setPersistenceUnit(final JPAPersistenceUnitMapType value) {
+ persistenceUnit = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModelFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModelFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModelFactory.java
new file mode 100644
index 0000000..84f8b28
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEdmMappingModelFactory.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import javax.xml.bind.annotation.XmlRegistry;
+
+/**
+ * This object contains factory methods for each Java content interface and Java
+ * element interface generated in the
+ * org.apache.olingo.odata2.processor.api.jpa.model.mapping package.
+ * <p>
+ * An ObjectFactory allows you to programatically construct new instances of the
+ * Java representation for XML content. The Java representation of XML content
+ * can consist of schema derived interfaces and classes representing the binding
+ * of schema type definitions, element declarations and model groups. Factory
+ * methods for each of these are provided in this class.
+ *
+ */
+@XmlRegistry
+public class JPAEdmMappingModelFactory {
+
+ /**
+ * Create a new ObjectFactory that can be used to create new instances of
+ * schema derived classes for package:
+ * org.apache.olingo.odata2.processor.api.jpa.model.mapping
+ *
+ */
+ public JPAEdmMappingModelFactory() {}
+
+ /**
+ * Create an instance of {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPARelationshipMapType }
+ *
+ */
+ public JPARelationshipMapType createJPARelationshipMapType() {
+ return new JPARelationshipMapType();
+ }
+
+ /**
+ * Create an instance of {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAAttributeMapType }
+ *
+ */
+ public JPAAttributeMapType createJPAAttributeMapType() {
+ return new JPAAttributeMapType();
+ }
+
+ /**
+ * Create an instance of {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEdmMappingModel }
+ *
+ */
+ public JPAEdmMappingModel createJPAEDMMappingModel() {
+ return new JPAEdmMappingModel();
+ }
+
+ /**
+ * Create an instance of {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAPersistenceUnitMapType }
+ *
+ */
+ public JPAPersistenceUnitMapType createJPAPersistenceUnitMapType() {
+ return new JPAPersistenceUnitMapType();
+ }
+
+ /**
+ * Create an instance of {@link org.apache.olingo.odata2.jpa.processor.api.model.mapping.JPAEmbeddableTypeMapType }
+ *
+ */
+ public JPAEmbeddableTypeMapType createJPAEmbeddableTypeMapType() {
+ return new JPAEmbeddableTypeMapType();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypeMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypeMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypeMapType.java
new file mode 100644
index 0000000..e640673
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypeMapType.java
@@ -0,0 +1,161 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ *
+ * The default name for EDM
+ * complex type is derived from JPA Embeddable type name. This can be
+ * overriden using JPAEmbeddableTypeMapType.
+ *
+ *
+ * <p>Java class for JPAEmbeddableTypeMapType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="JPAEmbeddableTypeMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="EDMComplexType" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ * <element name="JPAAttributes"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAAttributeMapType"/>
+ * </sequence>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPAEmbeddableTypeMapType", propOrder = { "edmComplexType", "jpaAttributes" })
+public class JPAEmbeddableTypeMapType {
+
+ @XmlElement(name = "EDMComplexType")
+ protected String edmComplexType;
+ @XmlElement(name = "JPAAttributes", required = true)
+ protected JPAAttributeMapType jpaAttributes;
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+ @XmlAttribute(name = "exclude")
+ protected Boolean exclude;
+
+ /**
+ * Gets the value of the edmComplexType property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getEDMComplexType() {
+ return edmComplexType;
+ }
+
+ /**
+ * Sets the value of the edmComplexType property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setEDMComplexType(final String value) {
+ edmComplexType = value;
+ }
+
+ /**
+ * Gets the value of the jpaAttributes property.
+ *
+ * @return
+ * possible object is {@link JPAAttributeMapType }
+ *
+ */
+ public JPAAttributeMapType getJPAAttributes() {
+ return jpaAttributes;
+ }
+
+ /**
+ * Sets the value of the jpaAttributes property.
+ *
+ * @param value
+ * allowed object is {@link JPAAttributeMapType }
+ *
+ */
+ public void setJPAAttributes(final JPAAttributeMapType value) {
+ jpaAttributes = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setName(final String value) {
+ name = value;
+ }
+
+ /**
+ * Gets the value of the exclude property.
+ *
+ * @return
+ * possible object is {@link Boolean }
+ *
+ */
+ public boolean isExclude() {
+ if (exclude == null) {
+ return false;
+ } else {
+ return exclude;
+ }
+ }
+
+ /**
+ * Sets the value of the exclude property.
+ *
+ * @param value
+ * allowed object is {@link Boolean }
+ *
+ */
+ public void setExclude(final Boolean value) {
+ exclude = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypesMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypesMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypesMapType.java
new file mode 100644
index 0000000..6293124
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEmbeddableTypesMapType.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * <p>
+ * Java class for JPAEmbeddableTypesMapType complex type.
+ *
+ * <p>
+ * The following schema fragment specifies the expected content contained within
+ * this class.
+ *
+ * <pre>
+ * <complexType name="JPAEmbeddableTypesMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="JPAEmbeddableType"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAEmbeddableTypeMapType"
+ * maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPAEmbeddableTypesMapType", propOrder = { "jpaEmbeddableType" })
+public class JPAEmbeddableTypesMapType {
+
+ @XmlElement(name = "JPAEmbeddableType")
+ protected List<JPAEmbeddableTypeMapType> jpaEmbeddableType;
+
+ /**
+ * Gets the value of the jpaEmbeddableType property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list, not a
+ * snapshot. Therefore any modification you make to the returned list will
+ * be present inside the JAXB object. This is why there is not a
+ * <CODE>set</CODE> method for the jpaEmbeddableType property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ *
+ * <pre>
+ * getJPAEmbeddableType().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list {@link JPAEmbeddableTypeMapType }
+ *
+ *
+ */
+ public List<JPAEmbeddableTypeMapType> getJPAEmbeddableType() {
+ if (jpaEmbeddableType == null) {
+ jpaEmbeddableType = new ArrayList<JPAEmbeddableTypeMapType>();
+ }
+ return jpaEmbeddableType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypeMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypeMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypeMapType.java
new file mode 100644
index 0000000..22e1819
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypeMapType.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ *
+ * The default name for EDM
+ * entity type is derived from JPA entity type name. This can be
+ * overriden using JPAEntityTypeMapType.
+ *
+ *
+ * <p>Java class for JPAEntityTypeMapType complex type.
+ *
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ *
+ * <pre>
+ * <complexType name="JPAEntityTypeMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="EDMEntityType" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ * <element name="EDMEntitySet" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ * <element name="JPAAttributes"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAAttributeMapType"/>
+ * <element name="JPARelationships"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPARelationshipMapType"/>
+ * </sequence>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * <attribute name="exclude" type="{http://www.w3.org/2001/XMLSchema}boolean" default="false" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPAEntityTypeMapType", propOrder = { "edmEntityType", "edmEntitySet", "jpaAttributes",
+ "jpaRelationships" })
+public class JPAEntityTypeMapType {
+
+ @XmlElement(name = "EDMEntityType")
+ protected String edmEntityType;
+ @XmlElement(name = "EDMEntitySet")
+ protected String edmEntitySet;
+ @XmlElement(name = "JPAAttributes", required = true)
+ protected JPAAttributeMapType jpaAttributes;
+ @XmlElement(name = "JPARelationships", required = true)
+ protected JPARelationshipMapType jpaRelationships;
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+ @XmlAttribute(name = "exclude")
+ protected Boolean exclude;
+
+ /**
+ * Gets the value of the edmEntityType property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getEDMEntityType() {
+ return edmEntityType;
+ }
+
+ /**
+ * Sets the value of the edmEntityType property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setEDMEntityType(final String value) {
+ edmEntityType = value;
+ }
+
+ /**
+ * Gets the value of the edmEntitySet property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getEDMEntitySet() {
+ return edmEntitySet;
+ }
+
+ /**
+ * Sets the value of the edmEntitySet property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setEDMEntitySet(final String value) {
+ edmEntitySet = value;
+ }
+
+ /**
+ * Gets the value of the jpaAttributes property.
+ *
+ * @return
+ * possible object is {@link JPAAttributeMapType }
+ *
+ */
+ public JPAAttributeMapType getJPAAttributes() {
+ return jpaAttributes;
+ }
+
+ /**
+ * Sets the value of the jpaAttributes property.
+ *
+ * @param value
+ * allowed object is {@link JPAAttributeMapType }
+ *
+ */
+ public void setJPAAttributes(final JPAAttributeMapType value) {
+ jpaAttributes = value;
+ }
+
+ /**
+ * Gets the value of the jpaRelationships property.
+ *
+ * @return
+ * possible object is {@link JPARelationshipMapType }
+ *
+ */
+ public JPARelationshipMapType getJPARelationships() {
+ return jpaRelationships;
+ }
+
+ /**
+ * Sets the value of the jpaRelationships property.
+ *
+ * @param value
+ * allowed object is {@link JPARelationshipMapType }
+ *
+ */
+ public void setJPARelationships(final JPARelationshipMapType value) {
+ jpaRelationships = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return
+ * possible object is {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setName(final String value) {
+ name = value;
+ }
+
+ /**
+ * Gets the value of the exclude property.
+ *
+ * @return
+ * possible object is {@link Boolean }
+ *
+ */
+ public boolean isExclude() {
+ if (exclude == null) {
+ return false;
+ } else {
+ return exclude;
+ }
+ }
+
+ /**
+ * Sets the value of the exclude property.
+ *
+ * @param value
+ * allowed object is {@link Boolean }
+ *
+ */
+ public void setExclude(final Boolean value) {
+ exclude = value;
+ }
+
+}
[19/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainerTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainerTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainerTest.java
new file mode 100644
index 0000000..0d6a2c1
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityContainerTest.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmEntityContainer;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmEntityContainerTest extends JPAEdmTestModelView {
+
+ private JPAEdmEntityContainer objJPAEdmEntityContainer;
+ private JPAEdmEntityContainerTest objJPAEdmEntityContainerTest;
+
+ @Before
+ public void setUp() {
+ objJPAEdmEntityContainerTest = new JPAEdmEntityContainerTest();
+ objJPAEdmEntityContainer = new JPAEdmEntityContainer(objJPAEdmEntityContainerTest);
+ try {
+ objJPAEdmEntityContainer.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmEntityContainer.getBuilder());
+ }
+
+ @Test
+ public void testGetEdmEntityContainer() {
+ assertNotNull(objJPAEdmEntityContainer.getEdmEntityContainer());
+ assertTrue(objJPAEdmEntityContainer.getEdmEntityContainer().getEntitySets().size() > 0);
+ }
+
+ @Test
+ public void testGetConsistentEdmEntityContainerList() {
+ assertNotNull(objJPAEdmEntityContainer.getConsistentEdmEntityContainerList());
+ assertTrue(objJPAEdmEntityContainer.getConsistentEdmEntityContainerList().size() > 0);
+
+ }
+
+ @Test
+ public void testGetJPAEdmEntitySetView() {
+ assertNotNull(objJPAEdmEntityContainer.getJPAEdmEntitySetView());
+ assertEquals("salesorderprocessing", objJPAEdmEntityContainer.getJPAEdmEntitySetView().getpUnitName());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmEntityContainer.isConsistent());
+ objJPAEdmEntityContainer.clean();
+ assertFalse(objJPAEdmEntityContainer.isConsistent());
+ }
+
+ @Test
+ public void testGetEdmAssociationSetView() {
+ assertNotNull(objJPAEdmEntityContainer.getEdmAssociationSetView());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmEntityContainer.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmEntityContainer.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAEdmMetaModel();
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public EntityType<?> getJPAEntityType() {
+ return new JPAEdmEntityType<String>();
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public Schema getEdmSchema() {
+ Schema schema = new Schema();
+ schema.setNamespace("salesordereprocessing");
+ return schema;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @Override
+ public JPAEdmAssociationView getJPAEdmAssociationView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ return new JPAEdmBuilder() {
+
+ @Override
+ public void build() {
+ // Nothing to do?
+ }
+ };
+ }
+
+ private class JPAEdmMetaModel extends JPAMetaModelMock {
+ Set<EntityType<?>> entities;
+
+ public JPAEdmMetaModel() {
+ entities = new HashSet<EntityType<?>>();
+ }
+
+ @Override
+ public Set<EntityType<?>> getEntities() {
+ entities.add(new JPAEdmEntityType());
+ return entities;
+ }
+
+ private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
+ @Override
+ public String getName() {
+ return "SalesOrderHeader";
+ }
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return PersistentAttributeType.BASIC;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return true;
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySetTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySetTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySetTest.java
new file mode 100644
index 0000000..f8f5321
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntitySetTest.java
@@ -0,0 +1,225 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmEntitySet;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmEntitySetTest extends JPAEdmTestModelView {
+
+ private static JPAEdmEntitySet objJPAEdmEntitySet;
+ private static JPAEdmEntitySetTest objJPAEdmEntitySetTest;
+
+ @Before
+ public void setUp() {
+ objJPAEdmEntitySetTest = new JPAEdmEntitySetTest();
+ objJPAEdmEntitySet = new JPAEdmEntitySet(objJPAEdmEntitySetTest);
+ try {
+ objJPAEdmEntitySet.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmEntitySet.getBuilder());
+ }
+
+ @Test
+ public void testGetEdmEntitySet() {
+ assertNotNull(objJPAEdmEntitySet.getEdmEntitySet());
+ assertNotNull(objJPAEdmEntitySet.getEdmEntitySet().getEntityType());
+ }
+
+ @Test
+ public void testGetConsistentEntitySetList() {
+ assertTrue(objJPAEdmEntitySet.getConsistentEdmEntitySetList().size() > 0);
+ }
+
+ @Test
+ public void testGetJPAEdmEntityTypeView() {
+ assertNotNull(objJPAEdmEntitySet.getJPAEdmEntityTypeView());
+ assertEquals("salesorderprocessing", objJPAEdmEntitySet.getJPAEdmEntityTypeView().getpUnitName());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmEntitySet.isConsistent());
+
+ objJPAEdmEntitySet.getJPAEdmEntityTypeView().clean();
+ assertFalse(objJPAEdmEntitySet.getJPAEdmEntityTypeView().isConsistent());
+
+ objJPAEdmEntitySet.clean();
+ assertFalse(objJPAEdmEntitySet.isConsistent());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmEntitySet.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmEntitySet.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAEdmMetaModel();
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public EntityType<?> getJPAEntityType() {
+ return new JPAEdmEntityType<String>();
+ }
+
+ @Override
+ public JPAEdmKeyView getJPAEdmKeyView() {
+ return this;
+ }
+
+ @Override
+ public Schema getEdmSchema() {
+ Schema schema = new Schema();
+ schema.setNamespace("salesordereprocessing");
+ return schema;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return "SalesOrderHeader";
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return PersistentAttributeType.BASIC;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return true;
+ }
+ }
+ }
+
+ private class JPAEdmMetaModel extends JPAMetaModelMock {
+ Set<EntityType<?>> entities;
+
+ public JPAEdmMetaModel() {
+ entities = new HashSet<EntityType<?>>();
+ }
+
+ @Override
+ public Set<EntityType<?>> getEntities() {
+ entities.add(new JPAEdmEntityType());
+ return entities;
+ }
+
+ private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
+ @Override
+ public String getName() {
+ return "SalesOrderHeader";
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityTypeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityTypeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityTypeTest.java
new file mode 100644
index 0000000..ad1a5c0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmEntityTypeTest.java
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmEntityType;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmEntityTypeTest extends JPAEdmTestModelView {
+
+ private static JPAEdmEntityTypeTest objJPAEdmEntityTypeTest;
+ private static JPAEdmEntityType objJPAEdmEntityType;
+
+ @Before
+ public void setUp() {
+ objJPAEdmEntityTypeTest = new JPAEdmEntityTypeTest();
+ objJPAEdmEntityType = new JPAEdmEntityType(objJPAEdmEntityTypeTest);
+ try {
+ objJPAEdmEntityType.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmEntityType.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmEntityType.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmEntityType.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetEdmEntityType() {
+ assertNotNull(objJPAEdmEntityType.getEdmEntityType());
+ assertNotNull(objJPAEdmEntityType.getEdmEntityType().getKey());
+ }
+
+ @Test
+ public void testGetJPAEntityType() {
+ assertNotNull(objJPAEdmEntityType.getJPAEntityType());
+
+ }
+
+ @Test
+ public void testGetConsistentEdmEntityTypes() {
+ assertTrue(objJPAEdmEntityType.getConsistentEdmEntityTypes().size() > 0);
+ }
+
+ @Test
+ public void testSearchEdmEntityType() {
+ assertNotNull(objJPAEdmEntityType.searchEdmEntityType("SalesOrderHeader"));
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmEntityType.isConsistent());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAEdmMetaModel();
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public EntityType<?> getJPAEntityType() {
+ return new JPAEdmEntityTypeLocal<String>();
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ private class JPAEdmMetaModel extends JPAMetaModelMock {
+ Set<EntityType<?>> entities;
+
+ public JPAEdmMetaModel() {
+ entities = new HashSet<EntityType<?>>();
+ }
+
+ @Override
+ public Set<EntityType<?>> getEntities() {
+ entities.add(new JPAEdmEntityType());
+ return entities;
+ }
+
+ private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
+ @Override
+ public String getName() {
+ return "SalesOrderHeader";
+ }
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEntityTypeLocal<String> extends JPAEntityTypeMock<String> {
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return PersistentAttributeType.BASIC;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return true;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
new file mode 100644
index 0000000..5992418
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmFunctionImportTest.java
@@ -0,0 +1,567 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.ReturnType;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPACustomProcessorMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model._JPACustomProcessorNegativeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmFunctionImport;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
+ private static final int METHOD_COUNT = 6;
+ private static int VARIANT = 0;
+ private JPAEdmFunctionImport jpaEdmfunctionImport;
+
+ @Before
+ public void setup() {
+ jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
+ }
+
+ /**
+ * Test Case - Function Import Basic test - Positive Case
+ */
+ @Test
+ public void testFunctionImportBasic() {
+ VARIANT = 0;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+ for (FunctionImport functionImport : functionImportList) {
+ assertEquals(functionImport.getName(), "Method1");
+ assertNotNull(functionImport.getMapping());
+ Mapping mapping = new Mapping();
+ mapping.setInternalName("method1");
+
+ assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
+
+ List<FunctionImportParameter> funcImpList = functionImport.getParameters();
+ assertEquals(2, funcImpList.size());
+ assertEquals("Param1", funcImpList.get(0).getName());
+ assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType());
+
+ assertEquals("Param3", funcImpList.get(1).getName());
+ assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType());
+
+ }
+
+ }
+
+ /**
+ * Test Case - Enable a method that does not exists
+ */
+ @Test
+ public void testFunctionImportNoSuchMethod() {
+ VARIANT = 1;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ /**
+ * Test Case - Enable all annotated methods in a class as function imports
+ */
+ @Test
+ public void testFunctionImportAllMethods() {
+ VARIANT = 2;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(METHOD_COUNT, functionImportList.size());
+
+ }
+
+ /**
+ * Test Case - Function Import with no names. Default name is Java method
+ * name.
+ */
+ @Test
+ public void testFunctionImportNoName() {
+ VARIANT = 3;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method3");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString());
+ }
+
+ /**
+ * Test Case - Function Import with No return type defined - Negative case
+ */
+ @Test
+ public void testNoReturnType() {
+ VARIANT = 4;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ /**
+ * Test Case - Function Import with return type as Entity and Multiplicity
+ * as Many but no Entity set defined. --> Negative Case
+ */
+ @Test
+ public void testNoEntitySet() {
+ VARIANT = 5;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+ }
+
+ /**
+ * Test Case - Function Import with return type as Entity Type but method
+ * has returns void. --> Negative Case
+ */
+ @Test
+ public void testNoReturnTypeButAnnotated() {
+ VARIANT = 6;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+ }
+
+ /**
+ * Test Case - Function Import that returns an Entity Type with Multiplicity
+ * as ONE. -->Positive Case
+ */
+ @Test
+ public void testFunctionImportEntityTypeSingleReturn() {
+ VARIANT = 7;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method7");
+ assertNotNull(functionImport.getMapping());
+ JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping();
+ assertEquals(JPACustomProcessorMock.class, mapping.getJPAType());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + JPACustomProcessorMock.edmName);
+ }
+
+ /**
+ * Test Case - Function Import that returns an Entity Type that is not found
+ * in JPA Model
+ */
+ @Test
+ public void testFunctionImportEntityTypeInvalid() {
+ VARIANT = 8;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that returns a complex Type
+ */
+ @Test
+ public void testFunctionImportComplexType() {
+ VARIANT = 9;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method9");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + JPACustomProcessorMock.edmName);
+
+ }
+
+ /**
+ * Test Case - Function Import that returns a complex Type with multiplicity
+ * Many
+ */
+ @Test
+ public void testFunctionImportComplexTypeMany() {
+ VARIANT = 10;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ FunctionImport functionImport = functionImportList.get(0);
+ assertEquals(functionImport.getName(), "method10");
+ assertNotNull(functionImport.getMapping());
+
+ ReturnType returnType = functionImport.getReturnType();
+ assertNotNull(returnType);
+ assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
+ assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
+ + JPACustomProcessorMock.edmName);
+
+ }
+
+ /**
+ * Test Case - Function Import that returns an Complex Type that is not
+ * found in JPA Model
+ */
+ @Test
+ public void testFunctionImportComplexTypeInvalid() {
+ VARIANT = 11;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that returns an scalar Type that is not valid
+ */
+ @Test
+ public void testFunctionImportScalarTypeInvalid() {
+ VARIANT = 12;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import that takes a parameter with no name
+ */
+ @Test
+ public void testFunctionImportParamNoName() {
+ VARIANT = 13;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import test for facets
+ */
+ @Test
+ public void testFunctionImportParamFacets() {
+ VARIANT = 14;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
+ EdmFacets facets = funcImpParamList.get(0).getFacets();
+ assertNotNull(facets);
+ assertEquals(2, facets.getMaxLength().intValue());
+ assertEquals(true, facets.isNullable());
+
+ facets = funcImpParamList.get(1).getFacets();
+ assertNotNull(facets);
+ assertEquals(false, facets.isNullable());
+ assertEquals(10, facets.getPrecision().intValue());
+ assertEquals(2, facets.getScale().intValue());
+
+ }
+
+ /**
+ * Test Case - Function Import test for default facets
+ */
+ @Test
+ public void testFunctionImportParamFacetsDefault() {
+ VARIANT = 15;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 1);
+
+ List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
+ EdmFacets facets = funcImpParamList.get(0).getFacets();
+ assertNotNull(facets);
+ assertNull(facets.getMaxLength());
+ assertEquals(false, facets.isNullable());
+ assertNull(facets.getPrecision());
+ assertNull(facets.getScale());
+
+ }
+
+ /**
+ * Test Case - Function Import test for ReturnType.SCALAR but method returns
+ * void
+ */
+ @Test
+ public void testWrongReturnTypeScalar() {
+ VARIANT = 16;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ /**
+ * Test Case - Function Import test for ReturnType.COMPLEX but method returns
+ * void
+ */
+ @Test
+ public void testWrongReturnTypeComplex() {
+ VARIANT = 17;
+
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ fail("Exception Expected");
+ } catch (ODataJPAModelException e) {
+ assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
+ } catch (ODataJPARuntimeException e) {
+ fail("Model Exception Expected");
+ }
+
+ }
+
+ @Test
+ public void testNoFunctionImport() {
+ VARIANT = 99;
+
+ build();
+
+ List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
+
+ assertEquals(functionImportList.size(), 0);
+
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
+
+ JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder();
+ JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public HashMap<Class<?>, String[]> getRegisteredOperations() {
+
+ HashMap<Class<?>, String[]> customOperations = new HashMap<Class<?>, String[]>();
+
+ if (VARIANT == 0) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method1" });
+ } else if (VARIANT == 1) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "XYX" });
+ } else if (VARIANT == 2) {
+ customOperations.put(JPACustomProcessorMock.class, null);
+ } else if (VARIANT == 3) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method3" });
+ } else if (VARIANT == 4) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method4" });
+ } else if (VARIANT == 5) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
+ } else if (VARIANT == 6) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
+ } else if (VARIANT == 7) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method7" });
+ } else if (VARIANT == 8) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
+ } else if (VARIANT == 9) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method9" });
+ } else if (VARIANT == 10) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method10" });
+ } else if (VARIANT == 11) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
+ } else if (VARIANT == 12) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
+ } else if (VARIANT == 13) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
+ } else if (VARIANT == 14) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method1" });
+ } else if (VARIANT == 15) {
+ customOperations.put(JPACustomProcessorMock.class, new String[] { "method3" });
+ } else if (VARIANT == 16) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
+ } else if (VARIANT == 17) {
+ customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
+ } else {
+ return null;
+ }
+
+ return customOperations;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return this;
+ }
+
+ @Override
+ public EntityType searchEdmEntityType(final String arg0) {
+ if (arg0.equals(JPACustomProcessorMock.class.getSimpleName())) {
+ return new EntityType().setName(JPACustomProcessorMock.edmName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String arg0) {
+ if (arg0.equals(JPACustomProcessorMock.class.getName())) {
+ return new ComplexType().setName(JPACustomProcessorMock.edmName);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getpUnitName() {
+ return ODataJPAContextMock.PERSISTENCE_UNIT_NAME;
+ }
+
+ private void build() {
+ try {
+ jpaEdmfunctionImport.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKeyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKeyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKeyTest.java
new file mode 100644
index 0000000..533e4e8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmKeyTest.java
@@ -0,0 +1,177 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmKeyView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.ODataJPAContextMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.ComplexType.ComplexTypeA;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmKey;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPAEdmKeyTest extends JPAEdmTestModelView {
+
+ private static JPAEdmKeyView keyView;
+ private static JPAEdmKeyTest objJpaEdmKeyTest;
+
+ @BeforeClass
+ public static void setup() {
+ objJpaEdmKeyTest = new JPAEdmKeyTest();
+ keyView = new JPAEdmKey(objJpaEdmKeyTest, objJpaEdmKeyTest);
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAAttributeA<Object, ComplexTypeA> extends JPAAttributeMock<Object, ComplexTypeA> {
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<ComplexTypeA> getJavaType() {
+ return (Class<ComplexTypeA>) JPAEdmMockData.ComplexType.ComplexTypeA.class;
+ }
+ }
+
+ @Test
+ public void testBuildComplexKey() {
+ try {
+ keyView.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ Key key = keyView.getEdmKey();
+
+ assertEquals(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_A, key.getKeys().get(0).getName());
+ assertEquals(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_B, key.getKeys().get(1).getName());
+ assertEquals(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_D, key.getKeys().get(2).getName());
+ assertEquals(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_E, key.getKeys().get(3).getName());
+
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = keyView.getBuilder();
+ JPAEdmBuilder builder2 = keyView.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return new JPAAttributeA<Object, ComplexTypeA>();
+
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final FullQualifiedName arg0) {
+ return searchEdmComplexType(arg0.getName());
+ }
+
+ @Override
+ public ComplexType searchEdmComplexType(final String arg0) {
+ if (arg0.equals(JPAEdmMockData.ComplexType.ComplexTypeA.class.getName())) {
+ return buildComplexTypeA();
+ } else if (arg0.equals(JPAEdmMockData.ComplexType.ComplexTypeB.class.getSimpleName())) {
+ return buildComplexTypeB();
+ }
+
+ return null;
+
+ }
+
+ private ComplexType buildComplexTypeB() {
+ ComplexType complexType = new ComplexType();
+ complexType.setProperties(buildPropertiesB());
+
+ return complexType;
+ }
+
+ private List<Property> buildPropertiesB() {
+ List<Property> propertyList = new ArrayList<Property>();
+
+ SimpleProperty property = new SimpleProperty();
+ property.setName(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_D);
+ property.setType(EdmSimpleTypeKind.Int16);
+
+ propertyList.add(property);
+
+ property = new SimpleProperty();
+ property.setName(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_E);
+ property.setType(EdmSimpleTypeKind.Int16);
+
+ propertyList.add(property);
+
+ return propertyList;
+ }
+
+ private ComplexType buildComplexTypeA() {
+ ComplexType complexType = new ComplexType();
+ complexType.setProperties(buildPropertiesA());
+
+ return complexType;
+ }
+
+ private List<Property> buildPropertiesA() {
+
+ List<Property> propertyList = new ArrayList<Property>();
+
+ SimpleProperty property = new SimpleProperty();
+ property.setName(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_A);
+ property.setType(EdmSimpleTypeKind.Int16);
+
+ propertyList.add(property);
+
+ property = new SimpleProperty();
+ property.setName(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_B);
+ property.setType(EdmSimpleTypeKind.Int16);
+
+ propertyList.add(property);
+
+ ComplexProperty complexProperty = new ComplexProperty();
+ complexProperty.setName(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_C);
+ complexProperty.setType(new FullQualifiedName(ODataJPAContextMock.NAMESPACE,
+ JPAEdmMockData.ComplexType.ComplexTypeB.name));
+
+ propertyList.add(complexProperty);
+ return propertyList;
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModelTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModelTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModelTest.java
new file mode 100644
index 0000000..354f910
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmModelTest.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEmbeddableMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmModel;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmModelTest extends JPAEdmTestModelView {
+
+ private JPAEdmModel objJPAEdmModel;
+
+ @Before
+ public void setUp() {
+ objJPAEdmModel = new JPAEdmModel(getJPAMetaModel(), "salesorderprocessing");
+ try {
+ objJPAEdmModel.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetEdmSchemaView() {
+ assertNotNull(objJPAEdmModel.getEdmSchemaView());
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmModel.getBuilder());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAEdmMetaModel();
+ }
+
+ private class JPAEdmMetaModel extends JPAMetaModelMock {
+ Set<EmbeddableType<?>> embeddableSet;
+
+ public JPAEdmMetaModel() {
+ embeddableSet = new HashSet<EmbeddableType<?>>();
+ }
+
+ @Override
+ public Set<EmbeddableType<?>> getEmbeddables() {
+ embeddableSet.add(new JPAEdmEmbeddable<String>());
+ return embeddableSet;
+ }
+
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEmbeddable<String> extends JPAEmbeddableMock<String> {
+
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return PersistentAttributeType.BASIC;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return false;
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationPropertyTest.java
new file mode 100644
index 0000000..8c7aea6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmNavigationPropertyTest.java
@@ -0,0 +1,219 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Type;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAPluralAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmNavigationProperty;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPAEdmNavigationPropertyTest extends JPAEdmTestModelView {
+
+ private static JPAEdmNavigationProperty objNavigationProperty;
+ private static JPAEdmNavigationPropertyTest navPropView;
+
+ @BeforeClass
+ public static void setup() {
+ JPAEdmNavigationPropertyTest localView = new JPAEdmNavigationPropertyTest();
+ navPropView = new JPAEdmNavigationPropertyTest();
+ objNavigationProperty = new JPAEdmNavigationProperty(localView,
+ localView, 1);
+ try {
+ objNavigationProperty.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public EntityType<?> getJPAEntityType() {
+ return new JPAEdmEntityType();
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+
+ Association association = new Association();
+ association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
+ association.setEnd1(new AssociationEnd().setType(
+ new FullQualifiedName("salesorderprocessing", "String"))
+ .setRole("SalesOrderHeader"));
+ association.setEnd2(new AssociationEnd()
+ .setType(
+ new FullQualifiedName("salesorderprocessing",
+ "SalesOrderItem")).setRole("SalesOrderItem"));
+ return association;
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objNavigationProperty.getBuilder());
+
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objNavigationProperty.getBuilder();
+ JPAEdmBuilder builder2 = objNavigationProperty.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetEdmNavigationProperty() {
+ if (objNavigationProperty == null || objNavigationProperty.getEdmNavigationProperty() == null) {
+ JPAEdmNavigationPropertyTest localView = new JPAEdmNavigationPropertyTest();
+ navPropView = new JPAEdmNavigationPropertyTest();
+ objNavigationProperty = new JPAEdmNavigationProperty(localView,
+ localView, 1);
+ try {
+ objNavigationProperty.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+ assertEquals(
+ objNavigationProperty.getEdmNavigationProperty().getName(),
+ "StringDetails");
+ }
+
+ @Test
+ public void testGetConsistentEdmNavigationProperties() {
+ assertTrue(objNavigationProperty.getConsistentEdmNavigationProperties()
+ .size() > 0);
+ }
+
+ @Test
+ public void testAddJPAEdmNavigationPropertyView() {
+ JPAEdmNavigationPropertyTest localView = new JPAEdmNavigationPropertyTest();
+ navPropView = new JPAEdmNavigationPropertyTest();
+ objNavigationProperty = new JPAEdmNavigationProperty(localView,
+ localView, 1);
+ try {
+ objNavigationProperty.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ objNavigationProperty.addJPAEdmNavigationPropertyView(navPropView);
+ assertTrue(objNavigationProperty.getConsistentEdmNavigationProperties()
+ .size() > 1);
+ }
+
+ @Override
+ public boolean isConsistent() {
+ return true;
+ }
+
+ @Test
+ public void testBuildNavigationProperty() {
+
+ try {
+ objNavigationProperty.getBuilder().build();
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(objNavigationProperty.getEdmNavigationProperty()
+ .getFromRole(), "SalesOrderItem");
+ assertEquals(objNavigationProperty.getEdmNavigationProperty()
+ .getToRole(), "SalesOrderHeader");
+
+ }
+
+ @SuppressWarnings("hiding")
+ private class AttributeMock<Object, String> extends
+ JPAPluralAttributeMock {
+
+ @Override
+ public boolean isCollection() {
+ return true;
+ }
+
+ @Override
+ public Type<java.lang.String> getElementType() {
+ return new ElementType();
+ }
+ }
+
+ private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
+ @Override
+ public String getName() {
+ return "SalesOrderHeader";
+ }
+ }
+
+ private class ElementType implements Type<String> {
+
+ @Override
+ public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
+ return PersistenceType.BASIC;
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return String.class;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
new file mode 100644
index 0000000..877d883
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmPropertyTest.java
@@ -0,0 +1,439 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.Attribute.PersistentAttributeType;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.Metamodel;
+import javax.persistence.metamodel.Type;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmComplexTypeView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityTypeView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEmbeddableTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEntityTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAPluralAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.ComplexType;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.SimpleType;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmProperty;
+import org.junit.Test;
+
+public class JPAEdmPropertyTest extends JPAEdmTestModelView {
+
+ private JPAEdmPropertyTest objJPAEdmPropertyTest;
+ private JPAEdmProperty objJPAEdmProperty;
+
+ private static PersistentAttributeType ATTRIBUTE_TYPE = PersistentAttributeType.BASIC;
+
+ public void setUp() {
+ ATTRIBUTE_TYPE = PersistentAttributeType.BASIC;
+ objJPAEdmPropertyTest = new JPAEdmPropertyTest();
+ objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest);
+ try {
+ objJPAEdmProperty.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testGetBuilder() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.getBuilder());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ setUp();
+ JPAEdmBuilder builder1 = objJPAEdmProperty.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmProperty.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetPropertyList() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.getEdmPropertyList());
+ assertTrue(objJPAEdmProperty.getEdmPropertyList().size() > 0);
+ }
+
+ @Test
+ public void testGetJPAEdmKeyView() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.getJPAEdmKeyView());
+ }
+
+ @Test
+ public void testGetSimpleProperty() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.getEdmSimpleProperty());
+ }
+
+ @Test
+ public void testGetJPAAttribute() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.getJPAAttribute());
+ }
+
+ @Test
+ public void testGetEdmComplexProperty() {
+
+ // builder for complex type
+ ATTRIBUTE_TYPE = PersistentAttributeType.EMBEDDED;
+ objJPAEdmPropertyTest = new JPAEdmPropertyTest();
+ objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest, objJPAEdmPropertyTest);
+ try {
+ objJPAEdmProperty.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertNotNull(objJPAEdmProperty.getEdmComplexProperty());
+ }
+
+ @Test
+ public void testGetJPAEdmNavigationPropertyView() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ setUp();
+ assertNotNull(objJPAEdmProperty.isConsistent());
+ }
+
+ @Test
+ public void testClean() {
+ setUp();
+ objJPAEdmProperty.clean();
+ assertFalse(objJPAEdmProperty.isConsistent());
+ }
+
+ @Test
+ public void testBuildManyToOne() {
+ ATTRIBUTE_TYPE = PersistentAttributeType.MANY_TO_ONE;
+ objJPAEdmPropertyTest = new JPAEdmPropertyTest();
+ objJPAEdmProperty = new JPAEdmProperty(objJPAEdmPropertyTest);
+ try {
+ objJPAEdmProperty.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertNotNull(objJPAEdmProperty.getJPAEdmNavigationPropertyView().getEdmNavigationProperty());
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAEdmMetaModel();
+ }
+
+ @Override
+ public boolean isReferencedInKey(final String complexType) {
+ return false;
+ }
+
+ @Override
+ public Schema getEdmSchema() {
+ Schema schema = new Schema();
+ schema.setNamespace(getpUnitName());
+ return schema;
+ }
+
+ @Override
+ public org.apache.olingo.odata2.api.edm.provider.ComplexType searchEdmComplexType(final String arg0) {
+ org.apache.olingo.odata2.api.edm.provider.ComplexType complexType =
+ new org.apache.olingo.odata2.api.edm.provider.ComplexType();
+ complexType.setName("ComplexTypeA");
+ return complexType;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public EntityType<?> getJPAEntityType() {
+ return new JPAEdmEntityType<String>();
+ }
+
+ @Override
+ public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
+ return this;
+ }
+
+ @Override
+ public org.apache.olingo.odata2.api.edm.provider.EntityType getEdmEntityType() {
+ org.apache.olingo.odata2.api.edm.provider.EntityType entityType =
+ new org.apache.olingo.odata2.api.edm.provider.EntityType();
+ entityType.setName("SalesOrderHeader");
+
+ return entityType;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association
+ .setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader")));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")));
+
+ return association;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @Override
+ public JPAEdmAssociationView getJPAEdmAssociationView() {
+ return this;
+ }
+
+ @Override
+ public EmbeddableType<?> getJPAEmbeddableType() {
+ return new JPAEdmEmbeddable<java.lang.String>();
+ }
+
+ @Override
+ public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
+ return this;
+ }
+
+ private class JPAEdmMetaModel extends JPAMetaModelMock {
+ Set<EntityType<?>> entities;
+ Set<EmbeddableType<?>> embeddableSet;
+
+ public JPAEdmMetaModel() {
+ entities = new HashSet<EntityType<?>>();
+ embeddableSet = new HashSet<EmbeddableType<?>>();
+ }
+
+ @Override
+ public Set<EntityType<?>> getEntities() {
+ entities.add(new JPAEdmEntityType());
+ return entities;
+ }
+
+ @Override
+ public Set<EmbeddableType<?>> getEmbeddables() {
+ embeddableSet.add(new JPAEdmEmbeddable<String>());
+ return embeddableSet;
+ }
+
+ private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
+ @Override
+ public String getName() {
+ return "SalesOrderHeader";
+ }
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ if (JPAEdmPropertyTest.ATTRIBUTE_TYPE.equals(PersistentAttributeType.BASIC)) {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ } else if (JPAEdmPropertyTest.ATTRIBUTE_TYPE.equals(PersistentAttributeType.EMBEDDED)) {
+ attributeSet.add(new JPAEdmAttribute(JPAEdmEmbeddable.class, ComplexType.ComplexTypeA.clazz.getName()));
+ } else if (JPAEdmPropertyTest.ATTRIBUTE_TYPE.equals(PersistentAttributeType.MANY_TO_ONE)) {
+ attributeSet.add(new JPAEdmPluralAttribute());
+ }
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ private class JPAEdmPluralAttribute extends JPAPluralAttributeMock {
+ @Override
+ public java.lang.String getName() {
+ return "salesorderheaderdetails";
+ }
+
+ @Override
+ public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
+ return ATTRIBUTE_TYPE;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return true;
+ }
+
+ @Override
+ public Type<java.lang.String> getElementType() {
+ return new Type<java.lang.String>() {
+
+ @Override
+ public Class<java.lang.String> getJavaType() {
+ return java.lang.String.class;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
+ return null;
+ }
+
+ };
+ }
+ }
+
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return ATTRIBUTE_TYPE;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return true;
+ }
+ }
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEmbeddable<String> extends JPAEmbeddableTypeMock<String> {
+
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ Class<?> clazz = null;
+ if (ATTRIBUTE_TYPE.equals(PersistentAttributeType.BASIC)) {
+ clazz = (Class<java.lang.String>) SimpleType.SimpleTypeA.clazz;
+ } else {
+ clazz = (Class<?>) ComplexType.ComplexTypeA.clazz;
+ }
+ return (Class<String>) clazz;
+ }
+
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return ATTRIBUTE_TYPE;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return true;
+ }
+ }
+
+ }
+
+}
[20/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableMock.java
new file mode 100644
index 0000000..f9c57b5
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableMock.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class JPAEmbeddableMock<X> implements EmbeddableType<X> {
+
+ @Override
+ public Attribute<? super X, ?> getAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<? super X, ?>> getAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<X, ?>> getDeclaredAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<X, ?> getDeclaredList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<? super X, ?> getList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<? super X, ?> getSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public Class<X> getJavaType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableTypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableTypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableTypeMock.java
new file mode 100644
index 0000000..f7383ce
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEmbeddableTypeMock.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class JPAEmbeddableTypeMock<X> implements EmbeddableType<X> {
+
+ @Override
+ public Attribute<? super X, ?> getAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<? super X, ?>> getAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<X, ?>> getDeclaredAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<X, ?> getDeclaredList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<? super X, ?> getList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<? super X, ?> getSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public Class<X> getJavaType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEntityTypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEntityTypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEntityTypeMock.java
new file mode 100644
index 0000000..1069815
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEntityTypeMock.java
@@ -0,0 +1,246 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.IdentifiableType;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+import javax.persistence.metamodel.Type;
+
+public abstract class JPAEntityTypeMock<X> implements EntityType<X> {
+
+ @Override
+ public <Y> SingularAttribute<X, Y> getDeclaredId(final Class<Y> arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<X, Y> getDeclaredVersion(final Class<Y> arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<? super X, Y> getId(final Class<Y> arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<? super X, ?>> getIdClassAttributes() {
+ return null;
+ }
+
+ @Override
+ public Type<?> getIdType() {
+ return null;
+ }
+
+ @Override
+ public IdentifiableType<? super X> getSupertype() {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<? super X, Y> getVersion(final Class<Y> arg0) {
+ return null;
+ }
+
+ @Override
+ public boolean hasSingleIdAttribute() {
+ return false;
+ }
+
+ @Override
+ public boolean hasVersionAttribute() {
+ return false;
+ }
+
+ @Override
+ public Attribute<? super X, ?> getAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<? super X, ?>> getAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<X, ?>> getDeclaredAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<X, ?> getDeclaredList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<? super X, ?> getList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<? super X, ?> getSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public Class<X> getJavaType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
+ return null;
+ }
+
+ @Override
+ public Class<X> getBindableJavaType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Bindable.BindableType getBindableType() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAJavaMemberMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAJavaMemberMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAJavaMemberMock.java
new file mode 100644
index 0000000..58a852f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAJavaMemberMock.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Member;
+
+import javax.persistence.JoinColumns;
+
+public class JPAJavaMemberMock implements Member, AnnotatedElement, Annotation {
+
+ @Override
+ public Class<?> getDeclaringClass() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public int getModifiers() {
+ return 0;
+ }
+
+ @Override
+ public boolean isSynthetic() {
+ return false;
+ }
+
+ @Override
+ public boolean isAnnotationPresent(final Class<? extends Annotation> annotationClass) {
+ return false;
+ }
+
+ @Override
+ public Annotation[] getAnnotations() {
+ return null;
+ }
+
+ @Override
+ public Annotation[] getDeclaredAnnotations() {
+ return null;
+ }
+
+ @Override
+ public Class<? extends Annotation> annotationType() {
+ return JoinColumns.class;
+ }
+
+ @Override
+ public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAManagedTypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAManagedTypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAManagedTypeMock.java
new file mode 100644
index 0000000..a7b025f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAManagedTypeMock.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.CollectionAttribute;
+import javax.persistence.metamodel.ListAttribute;
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.MapAttribute;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.SetAttribute;
+import javax.persistence.metamodel.SingularAttribute;
+
+public class JPAManagedTypeMock<X> implements ManagedType<X> {
+
+ @Override
+ public Class<X> getJavaType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Type.PersistenceType getPersistenceType() {
+ return null;
+ }
+
+ @Override
+ public Attribute<? super X, ?> getAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<? super X, ?>> getAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<? super X, ?> getCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<? super X, E> getCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public Attribute<X, ?> getDeclaredAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<Attribute<X, ?>> getDeclaredAttributes() {
+ return null;
+ }
+
+ @Override
+ public CollectionAttribute<X, ?> getDeclaredCollection(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> CollectionAttribute<X, E> getDeclaredCollection(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<X, ?> getDeclaredList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<X, E> getDeclaredList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<X, ?, ?> getDeclaredMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<X, K, V> getDeclaredMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<X, ?, ?>> getDeclaredPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<X, ?> getDeclaredSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<X, E> getDeclaredSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<X, ?> getDeclaredSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<X, Y> getDeclaredSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<X, ?>> getDeclaredSingularAttributes() {
+ return null;
+ }
+
+ @Override
+ public ListAttribute<? super X, ?> getList(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> ListAttribute<? super X, E> getList(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public MapAttribute<? super X, ?, ?> getMap(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <K, V> MapAttribute<? super X, K, V> getMap(final String arg0, final Class<K> arg1, final Class<V> arg2) {
+ return null;
+ }
+
+ @Override
+ public Set<PluralAttribute<? super X, ?, ?>> getPluralAttributes() {
+ return null;
+ }
+
+ @Override
+ public SetAttribute<? super X, ?> getSet(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <E> SetAttribute<? super X, E> getSet(final String arg0, final Class<E> arg1) {
+ return null;
+ }
+
+ @Override
+ public SingularAttribute<? super X, ?> getSingularAttribute(final String arg0) {
+ return null;
+ }
+
+ @Override
+ public <Y> SingularAttribute<? super X, Y> getSingularAttribute(final String arg0, final Class<Y> arg1) {
+ return null;
+ }
+
+ @Override
+ public Set<SingularAttribute<? super X, ?>> getSingularAttributes() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAMetaModelMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAMetaModelMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAMetaModelMock.java
new file mode 100644
index 0000000..d06b930
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAMetaModelMock.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.Set;
+
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.EntityType;
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.Metamodel;
+
+public class JPAMetaModelMock implements Metamodel {
+
+ @Override
+ public <X> EmbeddableType<X> embeddable(final Class<X> arg0) {
+ return null;
+ }
+
+ @Override
+ public <X> EntityType<X> entity(final Class<X> arg0) {
+ return null;
+ }
+
+ @Override
+ public Set<EmbeddableType<?>> getEmbeddables() {
+ return null;
+ }
+
+ @Override
+ public Set<EntityType<?>> getEntities() {
+ return null;
+ }
+
+ @Override
+ public Set<ManagedType<?>> getManagedTypes() {
+ return null;
+ }
+
+ @Override
+ public <X> ManagedType<X> managedType(final Class<X> arg0) {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java
new file mode 100644
index 0000000..23e7330
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAPluralAttributeMock.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.PluralAttribute;
+import javax.persistence.metamodel.Type;
+
+public class JPAPluralAttributeMock implements PluralAttribute<Object, ArrayList<String>, String> {
+
+ @Override
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ManagedType<Object> getDeclaringType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<ArrayList<String>> getJavaType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Member getJavaMember() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean isAssociation() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Bindable.BindableType getBindableType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Class<String> getBindableJavaType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.PluralAttribute.CollectionType getCollectionType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Type<String> getElementType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPASingularAttributeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPASingularAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPASingularAttributeMock.java
new file mode 100644
index 0000000..e64303e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPASingularAttributeMock.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.lang.reflect.Member;
+
+import javax.persistence.metamodel.ManagedType;
+import javax.persistence.metamodel.SingularAttribute;
+import javax.persistence.metamodel.Type;
+
+public class JPASingularAttributeMock<X, T> implements SingularAttribute<X, T> {
+
+ @Override
+ public ManagedType<X> getDeclaringType() {
+ return null;
+ }
+
+ @Override
+ public Member getJavaMember() {
+ return null;
+ }
+
+ @Override
+ public Class<T> getJavaType() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
+ return null;
+ }
+
+ @Override
+ public boolean isAssociation() {
+ return false;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ @Override
+ public Class<T> getBindableJavaType() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Bindable.BindableType getBindableType() {
+ return null;
+ }
+
+ @Override
+ public Type<T> getType() {
+ return null;
+ }
+
+ @Override
+ public boolean isId() {
+ return false;
+ }
+
+ @Override
+ public boolean isOptional() {
+ return false;
+ }
+
+ @Override
+ public boolean isVersion() {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java
new file mode 100644
index 0000000..1cdd158
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorMock.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.Facets;
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.Parameter;
+import org.apache.olingo.odata2.api.annotation.edm.Parameter.Mode;
+
+@Deprecated
+public class _JPACustomProcessorMock {
+
+ public static final String className = "_JPACustomProcessorMock";
+ public static final String edmName = "JPACustomProcessor";
+
+ @FunctionImport(name = "Method1", entitySet = "MockSet", returnType = ReturnType.ENTITY_TYPE,
+ multiplicity = Multiplicity.MANY)
+ public List<_JPACustomProcessorMock> method1(@Parameter(name = "Param1", facets = @Facets(nullable = true,
+ maxLength = 2), mode = Mode.IN) final String param1, final int param2, @Parameter(name = "Param3",
+ facets = @Facets(precision = 10, scale = 2), mode = Mode.IN) final double param3) {
+ return new ArrayList<_JPACustomProcessorMock>();
+ }
+
+ @FunctionImport(name = "Method2", entitySet = "MockSet", returnType = ReturnType.ENTITY_TYPE,
+ multiplicity = Multiplicity.MANY)
+ public List<_JPACustomProcessorMock> method2(
+ @Parameter(facets = @Facets(maxLength = 2), name = "Param2") final String param2) {
+ return new ArrayList<_JPACustomProcessorMock>();
+ }
+
+ @FunctionImport(returnType = ReturnType.SCALAR)
+ public int method3(@Parameter(name = "Param3") final String param3) {
+ return 0;
+ }
+
+ @FunctionImport(returnType = ReturnType.NONE)
+ public void method4() {
+ return;
+ }
+
+ @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.ONE)
+ public _JPACustomProcessorMock method7() {
+ return null;
+ }
+
+ @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
+ public _JPACustomProcessorMock method9() {
+ return null;
+ }
+
+ @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.MANY)
+ public List<_JPACustomProcessorMock> method10() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java
new file mode 100644
index 0000000..a727d5b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/_JPACustomProcessorNegativeMock.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport;
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.FunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.Parameter;
+
+@Deprecated
+public class _JPACustomProcessorNegativeMock {
+
+ @FunctionImport(returnType = ReturnType.ENTITY_TYPE, multiplicity = Multiplicity.MANY)
+ public List<_JPACustomProcessorNegativeMock> method5() {
+ return null;
+ }
+
+ @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.MANY)
+ public void method6() {
+ return;
+ }
+
+ @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "MockSet", multiplicity = Multiplicity.MANY)
+ public _JPACustomProcessorNegativeMock method8() {
+ return null;
+ }
+
+ @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
+ public _JPACustomProcessorNegativeMock method11() {
+ return null;
+ }
+
+ @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
+ public JPACustomProcessorMock method12() {
+ return null;
+ }
+
+ @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
+ public int method13(@Parameter(name = "") final int y) {
+ return 0;
+ }
+
+ @FunctionImport(returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE)
+ public void method16(@Parameter(name = "") final int y) {
+ return;
+ }
+
+ @FunctionImport(returnType = ReturnType.COMPLEX_TYPE, multiplicity = Multiplicity.ONE)
+ public void method17(@Parameter(name = "") final int y) {
+ return;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEndTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEndTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEndTest.java
new file mode 100644
index 0000000..b756f91
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationEndTest.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.SimpleType;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.SimpleType.SimpleTypeA;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmAssociationEnd;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPAEdmAssociationEndTest extends JPAEdmTestModelView {
+
+ private final static int VARIANT1 = 1;
+ private final static int VARIANT2 = 2;
+ private final static int VARIANT3 = 3;
+
+ private static int variant;
+
+ private static final String PUNIT_NAME = "salesorderprocessing";
+ private static JPAEdmAssociationEnd objJPAEdmAssociationEnd = null;
+ private static JPAEdmAssociationEndTest objJPAEdmAssociationEndTest = null;
+
+ @BeforeClass
+ public static void setup() {
+ objJPAEdmAssociationEndTest = new JPAEdmAssociationEndTest();
+ objJPAEdmAssociationEnd = new JPAEdmAssociationEnd(objJPAEdmAssociationEndTest, objJPAEdmAssociationEndTest);
+ try {
+ objJPAEdmAssociationEnd.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Test
+ public void testGetBuilder() {
+ JPAEdmBuilder builder = objJPAEdmAssociationEnd.getBuilder();
+ assertNotNull(builder);
+
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmAssociationEnd.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmAssociationEnd.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testGetAssociationEnd1() {
+ AssociationEnd associationEnd = objJPAEdmAssociationEnd.getEdmAssociationEnd1();
+ assertEquals(associationEnd.getType().getName(), "SOID");
+ }
+
+ @Test
+ public void testGetAssociationEnd2() {
+ AssociationEnd associationEnd = objJPAEdmAssociationEnd.getEdmAssociationEnd2();
+ assertEquals(associationEnd.getType().getName(), "String");
+ }
+
+ @Test
+ public void testCompare() {
+ assertTrue(objJPAEdmAssociationEnd.compare(getAssociationEnd("SOID", 1), getAssociationEnd("String", 1)));
+ assertFalse(objJPAEdmAssociationEnd.compare(getAssociationEnd("String", 2), getAssociationEnd("SOID", 1)));
+ }
+
+ @Test
+ public void testBuildAssociationEnd() {
+ assertEquals("SOID", objJPAEdmAssociationEnd.getEdmAssociationEnd1().getType().getName());
+ assertEquals(new FullQualifiedName("salesorderprocessing", "SOID"), objJPAEdmAssociationEnd.getEdmAssociationEnd1()
+ .getType());
+ assertTrue(objJPAEdmAssociationEnd.isConsistent());
+
+ }
+
+ private AssociationEnd getAssociationEnd(final String typeName, final int variant) {
+ AssociationEnd associationEnd = new AssociationEnd();
+ associationEnd.setType(getFullQualifiedName(typeName));
+ if (variant == VARIANT1) {
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ } else if (variant == VARIANT2) {
+ associationEnd.setMultiplicity(EdmMultiplicity.ONE);
+ } else if (variant == VARIANT3) {
+ associationEnd.setMultiplicity(EdmMultiplicity.ZERO_TO_ONE);
+ } else {
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);//
+ }
+ return associationEnd;
+ }
+
+ private FullQualifiedName getFullQualifiedName(final String typeName) {
+ FullQualifiedName fullQualifiedName = new FullQualifiedName(PUNIT_NAME, typeName);
+ return fullQualifiedName;
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @Override
+ public String getpUnitName() {
+ return PUNIT_NAME;
+ }
+
+ @Override
+ public EntityType getEdmEntityType() {
+ EntityType entityType = new EntityType();
+ entityType.setName(SimpleTypeA.NAME);
+ return entityType;
+ }
+
+ // The inner class which gives us an replica of the jpa attribute
+ @SuppressWarnings("hiding")
+ public class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) SimpleType.SimpleTypeA.clazz;
+ }
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ if (variant == VARIANT1) {
+ return PersistentAttributeType.ONE_TO_MANY;
+ } else if (variant == VARIANT2) {
+ return PersistentAttributeType.ONE_TO_ONE;
+ } else if (variant == VARIANT3) {
+ return PersistentAttributeType.MANY_TO_ONE;
+ } else {
+ return PersistentAttributeType.MANY_TO_MANY;
+ }
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSetTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSetTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSetTest.java
new file mode 100644
index 0000000..cb7d252
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationSetTest.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntityContainerView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmEntitySetView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmAssociationSet;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmAssociationSetTest extends JPAEdmTestModelView {
+
+ private JPAEdmAssociationSetTest objJPAEdmAssociationSetTest;
+ private JPAEdmAssociationSet objJPAEdmAssociationSet;
+
+ @Before
+ public void setUp() {
+ objJPAEdmAssociationSetTest = new JPAEdmAssociationSetTest();
+ objJPAEdmAssociationSet = new JPAEdmAssociationSet(objJPAEdmAssociationSetTest);
+ try {
+ objJPAEdmAssociationSet.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objJPAEdmAssociationSet.getBuilder());
+ }
+
+ @Test
+ public void testGetConsistentEdmAssociationSetList() {
+ assertNotNull(objJPAEdmAssociationSet.getConsistentEdmAssociationSetList());
+ }
+
+ @Test
+ public void testGetEdmAssociationSet() {
+ assertNotNull(objJPAEdmAssociationSet.getEdmAssociationSet());
+ }
+
+ @Test
+ public void testGetEdmAssociation() {
+ assertNotNull(objJPAEdmAssociationSet.getEdmAssociation());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmAssociationSet.isConsistent());
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objJPAEdmAssociationSet.getBuilder();
+ JPAEdmBuilder builder2 = objJPAEdmAssociationSet.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Override
+ public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmEntitySetView getJPAEdmEntitySetView() {
+ return this;
+ }
+
+ @Override
+ public JPAEdmAssociationView getJPAEdmAssociationView() {
+ return this;
+ }
+
+ @Override
+ public AssociationSet getEdmAssociationSet() {
+ AssociationSet associationSet = new AssociationSet();
+ associationSet.setEnd1(new AssociationSetEnd());
+ associationSet.setEnd2(new AssociationSetEnd());
+
+ return associationSet;
+ }
+
+ @Override
+ public List<Association> getConsistentEdmAssociationList() {
+ return getEdmAssociationListLocal();
+ }
+
+ @Override
+ public List<AssociationSet> getConsistentEdmAssociationSetList() {
+
+ List<AssociationSet> associationSetList = new ArrayList<AssociationSet>();
+ associationSetList.add(getEdmAssociationSet());
+ associationSetList.add(getEdmAssociationSet());
+
+ return associationSetList;
+ }
+
+ @Override
+ public List<EntitySet> getConsistentEdmEntitySetList() {
+ return getEntitySetListLocal();
+ }
+
+ @Override
+ public boolean isConsistent() {
+ return true;
+ }
+
+ @Override
+ public Schema getEdmSchema() {
+ Schema schema = new Schema();
+ schema.setNamespace("salesordereprocessing");
+ return schema;
+ }
+
+ private List<EntitySet> getEntitySetListLocal() {
+ List<EntitySet> entitySetList = new ArrayList<EntitySet>();
+
+ EntitySet entitySet = new EntitySet();
+ entitySet.setName("SalesOrderHeader");
+ entitySet.setEntityType(new FullQualifiedName("salesorderprocessing", "SOID"));
+
+ EntitySet entitySet2 = new EntitySet();
+ entitySet2.setName("SalesOrderItem");
+ entitySet2.setEntityType(new FullQualifiedName("salesorderprocessing", "SOID"));
+
+ entitySetList.add(entitySet);
+ entitySetList.add(entitySet2);
+ return entitySetList;
+ }
+
+ private List<Association> getEdmAssociationListLocal() {
+ List<Association> associationList = new ArrayList<Association>();
+
+ Association association = new Association();
+ association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
+ association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
+ "SalesOrderHeader"));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
+ .setRole("SalesOrderItem"));
+
+ associationList.add(association);
+ return associationList;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationTest.java
new file mode 100644
index 0000000..3923dd8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmAssociationTest.java
@@ -0,0 +1,426 @@
+/*******************************************************************************
+
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.metamodel.Attribute;
+
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmAssociationEndView;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmReferentialConstraintView;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.SimpleType;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.SimpleType.SimpleTypeA;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmAssociation;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmAssociationEnd;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmReferentialConstraint;
+import org.easymock.EasyMock;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPAEdmAssociationTest extends JPAEdmTestModelView {
+
+ private static JPAEdmAssociation objAssociation = null;
+ private static String ASSOCIATION_NAME = "SalesOrderHeader_String";
+ private static JPAEdmAssociationTest localView = null;
+ private static final String PUNIT_NAME = "salesorderprocessing";
+ private int variant;
+
+ @BeforeClass
+ public static void setup() {
+ localView = new JPAEdmAssociationTest();
+ objAssociation = new JPAEdmAssociation(localView, localView, localView, 1);
+ try {
+ objAssociation.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd1() {
+ AssociationEnd associationEnd = new AssociationEnd();
+ associationEnd.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader"));
+ associationEnd.setRole("SalesOrderHeader");
+ associationEnd.setMultiplicity(EdmMultiplicity.ONE);
+ return associationEnd;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd2() {
+ AssociationEnd associationEnd = new AssociationEnd();
+ associationEnd.setType(new FullQualifiedName("salesorderprocessing", "String"));
+ associationEnd.setRole("String");
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ return associationEnd;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association
+ .setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader")));
+ association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")));
+
+ return association;
+ }
+
+ @Override
+ public boolean isExists() {
+ return true;
+ }
+
+ @Override
+ public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
+ JPAEdmReferentialConstraint refConstraintView = new JPAEdmReferentialConstraint(localView, localView, localView);
+ return refConstraintView;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @Override
+ public String getpUnitName() {
+ return PUNIT_NAME;
+ }
+
+ @Override
+ public EntityType getEdmEntityType() {
+ EntityType entityType = new EntityType();
+ entityType.setName(SimpleTypeA.NAME);
+ return entityType;
+ }
+
+ // The inner class which gives us an replica of the jpa attribute
+ @SuppressWarnings("hiding")
+ private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) SimpleType.SimpleTypeA.clazz;
+ }
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ if (variant == 1) {
+ return PersistentAttributeType.ONE_TO_MANY;
+ } else if (variant == 2) {
+ return PersistentAttributeType.ONE_TO_ONE;
+ } else if (variant == 2) {
+ return PersistentAttributeType.MANY_TO_ONE;
+ } else {
+ return PersistentAttributeType.MANY_TO_MANY;
+ }
+
+ }
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @Test
+ public void testGetBuilder() {
+ assertNotNull(objAssociation.getBuilder());
+ }
+
+ @Test
+ public void testGetEdmAssociation() {
+ assertNotNull(objAssociation.getEdmAssociation());
+ assertEquals(objAssociation.getEdmAssociation().getName(), ASSOCIATION_NAME);
+ }
+
+ @Test
+ public void testGetConsistentEdmAssociationList() {
+ assertTrue(objAssociation.getConsistentEdmAssociationList().size() > 0);
+ }
+
+ @Override
+ public String getEdmRelationShipName() {
+ return "Association_SalesOrderHeader_String";
+ }
+
+ @Test
+ public void testSearchAssociation1() {
+ class TestAssociationEndView extends JPAEdmTestModelView {
+ @Override
+ public String getEdmRelationShipName() {
+ return "SalesOrderHeader_String1";
+ }
+
+ private Attribute<?, ?> getJPAAttributeLocal() {
+ AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
+ return attr;
+ }
+
+ @Override
+ public Attribute<?, ?> getJPAAttribute() {
+ return getJPAAttributeLocal();
+ }
+
+ @Override
+ public String getJoinColumnName() {
+ return "SO_ID";
+ }
+
+ @Override
+ public String getJoinColumnReferenceColumnName() {
+ return "DEMO_ID";
+ }
+
+ @Override
+ public String getMappedByName() {
+ return "demo";
+ }
+
+ @Override
+ public String getOwningPropertyName() {
+ return "salesOrder";
+ }
+
+ @Override
+ public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
+ return 1;
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @Override
+ public EntityType getEdmEntityType() {
+ EntityType entityType = new EntityType();
+ entityType.setName("SalesOrderHeader");
+ return entityType;
+ }
+
+ @SuppressWarnings("hiding")
+ class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) SimpleType.SimpleTypeA.clazz;
+ }
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+
+ return PersistentAttributeType.ONE_TO_MANY;
+
+ }
+
+ @Override
+ public Member getJavaMember() {
+ return new AnnotatedElementMock();
+ }
+
+ @Override
+ public java.lang.String getName() {
+ // TODO Auto-generated method stub
+ return super.getName();
+ }
+
+ class AnnotatedElementMock implements AnnotatedElement, Member {
+
+ @Override
+ public boolean isAnnotationPresent(final Class<? extends Annotation> annotationClass) {
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Annotation getAnnotation(@SuppressWarnings("rawtypes") final Class annotationClass) {
+ if (annotationClass.equals(JoinColumn.class)) {
+ JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
+ EasyMock.expect(joinColumn.name()).andStubReturn("SO_ID");
+ EasyMock.expect(joinColumn.referencedColumnName()).andStubReturn("DEMO_ID");
+ EasyMock.replay(joinColumn);
+ return joinColumn;
+ } else {
+ OneToMany oneToMany = EasyMock.createMock(OneToMany.class);
+ EasyMock.expect(oneToMany.mappedBy()).andStubReturn("demo");
+ EasyMock.replay(oneToMany);
+ return oneToMany;
+ }
+ }
+
+ @Override
+ public Annotation[] getAnnotations() {
+ return null;
+ }
+
+ @Override
+ public Annotation[] getDeclaredAnnotations() {
+ return null;
+ }
+
+ @Override
+ public Class<?> getDeclaringClass() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getModifiers() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean isSynthetic() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ }
+
+ }
+ }
+ TestAssociationEndView objJPAEdmAssociationEndTest = new TestAssociationEndView();
+ JPAEdmAssociationEnd objJPAEdmAssociationEnd =
+ new JPAEdmAssociationEnd(objJPAEdmAssociationEndTest, objJPAEdmAssociationEndTest);
+ try {
+ objJPAEdmAssociationEnd.getBuilder().build();
+ Field field = objAssociation.getClass().getDeclaredField("associationEndMap");
+ field.setAccessible(true);
+ Map<String, JPAEdmAssociationEndView> associationEndMap = new HashMap<String, JPAEdmAssociationEndView>();
+ associationEndMap.put("SalesOrderHeader_String", objJPAEdmAssociationEnd);
+ field.set(objAssociation, associationEndMap);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (SecurityException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (NoSuchFieldException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalArgumentException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (IllegalAccessException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ assertEquals("SalesOrderHeader_String", objAssociation.searchAssociation(objJPAEdmAssociationEnd).getName());
+
+ }
+
+ @Test
+ public void testAddJPAEdmAssociationView() {
+
+ class LocalJPAAssociationView extends JPAEdmTestModelView {
+ @Override
+ public AssociationEnd getEdmAssociationEnd1() {
+ AssociationEnd associationEnd = new AssociationEnd();
+ associationEnd.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader"));
+ associationEnd.setRole("SalesOrderHeader");
+ associationEnd.setMultiplicity(EdmMultiplicity.ONE);
+ return associationEnd;
+ }
+
+ @Override
+ public AssociationEnd getEdmAssociationEnd2() {
+ AssociationEnd associationEnd = new AssociationEnd();
+ associationEnd.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"));
+ associationEnd.setRole("SalesOrderItem");
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ return associationEnd;
+ }
+
+ @Override
+ public Association getEdmAssociation() {
+ Association association = new Association();
+ association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing",
+ "SalesOrderHeader")));
+ association.setEnd2(new AssociationEnd()
+ .setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem")));
+
+ return association;
+ }
+ }
+ LocalJPAAssociationView assocViewObj = new LocalJPAAssociationView();
+ JPAEdmAssociation objLocalAssociation = new JPAEdmAssociation(assocViewObj, assocViewObj, assocViewObj, 1);
+ try {
+ objLocalAssociation.getBuilder().build();
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ objAssociation.addJPAEdmAssociationView(objLocalAssociation, localView);
+
+ }
+
+ @Test
+ public void testAddJPAEdmRefConstraintView() {
+
+ localView = new JPAEdmAssociationTest();
+ objAssociation = new JPAEdmAssociation(localView, localView, localView, 1);
+ try {
+ objAssociation.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ objAssociation.addJPAEdmRefConstraintView(localView);
+ assertTrue(objAssociation.getConsistentEdmAssociationList().size() > 0);
+ }
+
+ @Test
+ public void testGetJPAEdmReferentialConstraintView() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImplTest.java
new file mode 100644
index 0000000..237a6a3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmBaseViewImplTest.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmBaseViewImpl;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPAEdmBaseViewImplTest extends JPAEdmTestModelView {
+
+ private JPAEdmBaseViewImplTest objJPAEdmBaseViewImplTest;
+ private JPAEdmBaseViewImpl objJPAEdmBaseViewImpl;
+
+ @Before
+ public void setUp() {
+ objJPAEdmBaseViewImplTest = new JPAEdmBaseViewImplTest();
+ objJPAEdmBaseViewImpl = new JPAEdmBaseViewImpl(objJPAEdmBaseViewImplTest) {
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ return null;
+ }
+ };
+
+ objJPAEdmBaseViewImpl = new JPAEdmBaseViewImpl(getJPAMetaModel(), getpUnitName()) {
+
+ @Override
+ public JPAEdmBuilder getBuilder() {
+ return null;
+ }
+ };
+
+ }
+
+ @Test
+ public void testGetpUnitName() {
+ assertTrue(objJPAEdmBaseViewImpl.getpUnitName().equals("salesorderprocessing"));
+ }
+
+ @Test
+ public void testGetJPAMetaModel() {
+ assertNotNull(objJPAEdmBaseViewImpl.getJPAMetaModel());
+ }
+
+ @Test
+ public void testIsConsistent() {
+ assertTrue(objJPAEdmBaseViewImpl.isConsistent());
+ }
+
+ @Test
+ public void testClean() {
+ objJPAEdmBaseViewImpl.clean();
+ assertFalse(objJPAEdmBaseViewImpl.isConsistent());
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAMetaModelMock();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexTypeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexTypeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexTypeTest.java
new file mode 100644
index 0000000..9ab7872
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/model/JPAEdmComplexTypeTest.java
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.EmbeddableType;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.access.JPAEdmBuilder;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEmbeddableMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAMetaModelMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPASingularAttributeMock;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmComplexType;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JPAEdmComplexTypeTest extends JPAEdmTestModelView {
+
+ private static JPAEdmComplexType objComplexType = null;
+ private static JPAEdmComplexTypeTest localView = null;
+
+ @BeforeClass
+ public static void setup() {
+ localView = new JPAEdmComplexTypeTest();
+ objComplexType = new JPAEdmComplexType(localView);
+ try {
+ objComplexType.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public EmbeddableType<?> getJPAEmbeddableType() {
+ @SuppressWarnings("hiding")
+ class JPAComplexAttribute<Long> extends JPAEmbeddableMock<Long> {
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<Long> getJavaType() {
+
+ return (Class<Long>) java.lang.Long.class;
+ }
+
+ }
+ return new JPAComplexAttribute();
+ }
+
+ @Override
+ public String getpUnitName() {
+ return "salesorderprocessing";
+ }
+
+ @Override
+ public Metamodel getJPAMetaModel() {
+ return new JPAEdmMetaModel();
+ }
+
+ @Test
+ public void testGetBuilder() {
+
+ assertNotNull(objComplexType.getBuilder());
+ }
+
+ @Test
+ public void testGetEdmComplexType() {
+ assertEquals(objComplexType.getEdmComplexType().getName(), "String");
+ }
+
+ @Test
+ public void testSearchComplexTypeString() {
+ assertNotNull(objComplexType.searchEdmComplexType("java.lang.String"));
+
+ }
+
+ @Test
+ public void testGetJPAEmbeddableType() {
+ assertTrue(objComplexType.getJPAEmbeddableType().getAttributes().size() > 0);
+
+ }
+
+ @Test
+ public void testGetConsistentEdmComplexTypes() {
+ assertTrue(objComplexType.getConsistentEdmComplexTypes().size() > 0);
+ }
+
+ @Test
+ public void testSearchComplexTypeFullQualifiedName() {
+ assertNotNull(objComplexType.searchEdmComplexType(new FullQualifiedName("salesorderprocessing", "String")));
+
+ }
+
+ @Test
+ public void testSearchComplexTypeFullQualifiedNameNegative() {
+ assertNull(objComplexType.searchEdmComplexType(new FullQualifiedName("salesorderprocessing", "lang.String")));
+ }
+
+ @Test
+ public void testGetBuilderIdempotent() {
+ JPAEdmBuilder builder1 = objComplexType.getBuilder();
+ JPAEdmBuilder builder2 = objComplexType.getBuilder();
+
+ assertEquals(builder1.hashCode(), builder2.hashCode());
+ }
+
+ @Test
+ public void testAddCompleTypeView() {
+ localView = new JPAEdmComplexTypeTest();
+ objComplexType = new JPAEdmComplexType(localView);
+ try {
+ objComplexType.getBuilder().build();
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ objComplexType.addJPAEdmCompleTypeView(localView);
+ assertTrue(objComplexType.getConsistentEdmComplexTypes().size() > 1);
+ }
+
+ @Test
+ public void testExpandEdmComplexType() {
+ ComplexType complexType = new ComplexType();
+ List<Property> properties = new ArrayList<Property>();
+ JPAEdmMapping mapping1 = new JPAEdmMappingImpl();
+ mapping1.setJPAColumnName("LINEITEMID");
+ ((Mapping) mapping1).setInternalName("LineItemKey.LiId");
+ JPAEdmMapping mapping2 = new JPAEdmMappingImpl();
+ mapping2.setJPAColumnName("LINEITEMNAME");
+ ((Mapping) mapping2).setInternalName("LineItemKey.LiName");
+ properties.add(new SimpleProperty().setName("LIID").setMapping((Mapping) mapping1));
+ properties.add(new SimpleProperty().setName("LINAME").setMapping((Mapping) mapping2));
+ complexType.setProperties(properties);
+ List<Property> expandedList = null;
+ try {
+ objComplexType.expandEdmComplexType(complexType, expandedList, "SalesOrderItemKey");
+ } catch (ClassCastException e) {
+ assertTrue(false);
+ }
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testComplexTypeCreation() {
+ try {
+ objComplexType.getBuilder().build();
+ } catch (ODataJPARuntimeException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ } catch (ODataJPAModelException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ assertEquals(objComplexType.pUnitName, "salesorderprocessing");
+ }
+
+ private class JPAEdmMetaModel extends JPAMetaModelMock {
+ Set<EmbeddableType<?>> embeddableSet;
+
+ public JPAEdmMetaModel() {
+ embeddableSet = new HashSet<EmbeddableType<?>>();
+ }
+
+ @Override
+ public Set<EmbeddableType<?>> getEmbeddables() {
+ embeddableSet.add(new JPAEdmEmbeddable<String>());
+ return embeddableSet;
+ }
+
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmEmbeddable<String> extends JPAEmbeddableMock<String> {
+
+ Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ private void setValuesToSet() {
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
+ attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
+ }
+
+ @Override
+ public Set<Attribute<? super String, ?>> getAttributes() {
+ setValuesToSet();
+ return attributeSet;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<String> getJavaType() {
+ return (Class<String>) java.lang.String.class;
+ }
+
+ }
+
+ @SuppressWarnings("hiding")
+ private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
+
+ @Override
+ public PersistentAttributeType getPersistentAttributeType() {
+ return PersistentAttributeType.BASIC;
+ }
+
+ Class<String> clazz;
+ java.lang.String attributeName;
+
+ public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
+ this.clazz = javaType;
+ this.attributeName = name;
+
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return clazz;
+ }
+
+ @Override
+ public java.lang.String getName() {
+ return this.attributeName;
+ }
+
+ @Override
+ public boolean isId() {
+ return false;
+ }
+
+ }
+}
[21/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilderTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilderTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilderTest.java
new file mode 100644
index 0000000..7a14f6c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/jpql/JPQLSelectStatementBuilderTest.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.jpql;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.uri.SelectItem;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPAModelException;
+import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContextType;
+import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLContext.JPQLContextBuilder;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectContext;
+import org.apache.olingo.odata2.jpa.processor.core.jpql.JPQLSelectStatementBuilder;
+import org.easymock.EasyMock;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JPQLSelectStatementBuilderTest {
+
+ /**
+ * @throws java.lang.Exception
+ */
+ private JPQLSelectStatementBuilder jpqlSelectStatementBuilder;
+
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ private JPQLSelectContext createSelectContext(final OrderByExpression orderByExpression,
+ final FilterExpression filterExpression) throws ODataJPARuntimeException, EdmException {
+ // Object Instantiation
+
+ JPQLSelectContext jpqlSelectContextImpl = null;
+ GetEntitySetUriInfo getEntitySetView = EasyMock.createMock(GetEntitySetUriInfo.class);
+
+ EdmEntitySet edmEntitySet = EasyMock.createMock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = EasyMock.createMock(EdmEntityType.class);
+ List<SelectItem> selectItemList = null;
+
+ // Setting up the expected value
+
+ EasyMock.expect(getEntitySetView.getTargetEntitySet()).andStubReturn(edmEntitySet);
+ EasyMock.expect(getEntitySetView.getOrderBy()).andStubReturn(orderByExpression);
+ EasyMock.expect(getEntitySetView.getSelect()).andStubReturn(selectItemList);
+ EasyMock.expect(getEntitySetView.getFilter()).andStubReturn(filterExpression);
+ EasyMock.replay(getEntitySetView);
+ EasyMock.expect(edmEntitySet.getEntityType()).andStubReturn(edmEntityType);
+ EasyMock.replay(edmEntitySet);
+ EasyMock.expect(edmEntityType.getMapping()).andStubReturn(null);
+ EasyMock.expect(edmEntityType.getName()).andStubReturn("SalesOrderHeader");
+ EasyMock.replay(edmEntityType);
+
+ JPQLContextBuilder contextBuilder1 = JPQLContext.createBuilder(JPQLContextType.SELECT, getEntitySetView);
+ try {
+ jpqlSelectContextImpl = (JPQLSelectContext) contextBuilder1.build();
+ } catch (ODataJPAModelException e) {
+ fail("Model Exception thrown");
+ }
+
+ return jpqlSelectContextImpl;
+ }
+
+ /**
+ * Test method for {@link org.apache.olingo.odata2.processor.jpa.jpql.JPQLSelectStatementBuilder#build)}.
+ * @throws EdmException
+ * @throws ODataJPARuntimeException
+ */
+
+ @Test
+ public void testBuildSimpleQuery() throws EdmException, ODataJPARuntimeException {
+ OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
+ JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, null);
+ jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl);
+
+ assertEquals("SELECT E1 FROM SalesOrderHeader E1", jpqlSelectStatementBuilder.build().toString());
+ }
+
+ @Test
+ public void testBuildQueryWithOrderBy() throws EdmException, ODataJPARuntimeException {
+ OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
+
+ JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, null);
+ HashMap<String, String> orderByCollection = new HashMap<String, String>();
+ orderByCollection.put("E1.soID", "ASC");
+ orderByCollection.put("E1.buyerId", "DESC");
+ jpqlSelectContextImpl.setOrderByCollection(orderByCollection);
+ jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl);
+
+ assertEquals("SELECT E1 FROM SalesOrderHeader E1 ORDER BY E1.soID ASC , E1.buyerId DESC",
+ jpqlSelectStatementBuilder.build().toString());
+ }
+
+ @Test
+ public void testBuildQueryWithFilter() throws EdmException, ODataJPARuntimeException {
+ OrderByExpression orderByExpression = EasyMock.createMock(OrderByExpression.class);
+ FilterExpression filterExpression = null;// getFilterExpressionMockedObj();
+ JPQLSelectContext jpqlSelectContextImpl = createSelectContext(orderByExpression, filterExpression);
+ jpqlSelectContextImpl.setWhereExpression("E1.soID >= 1234");
+
+ jpqlSelectStatementBuilder = new JPQLSelectStatementBuilder(jpqlSelectContextImpl);
+
+ assertEquals("SELECT E1 FROM SalesOrderHeader E1 WHERE E1.soID >= 1234", jpqlSelectStatementBuilder.build()
+ .toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/ODataJPAContextMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/ODataJPAContextMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/ODataJPAContextMock.java
new file mode 100644
index 0000000..83ae7c0
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/ODataJPAContextMock.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.metamodel.Metamodel;
+
+import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
+import org.easymock.EasyMock;
+
+public abstract class ODataJPAContextMock {
+
+ public static final String NAMESPACE = "salesorderprocessing";
+ public static final String MAPPING_MODEL = "SalesOrderProcessingMappingModel";
+ public static final String PERSISTENCE_UNIT_NAME = "salesorderprocessing";
+
+ public static ODataJPAContext mockODataJPAContext() {
+ ODataJPAContext odataJPAContext = EasyMock.createMock(ODataJPAContext.class);
+ EasyMock.expect(odataJPAContext.getPersistenceUnitName()).andStubReturn(NAMESPACE);
+ EasyMock.expect(odataJPAContext.getEntityManagerFactory()).andReturn(mockEntityManagerFactory());
+ EasyMock.expect(odataJPAContext.getJPAEdmMappingModel()).andReturn(MAPPING_MODEL);
+ EasyMock.expect(odataJPAContext.getJPAEdmExtension()).andReturn(null);
+ EasyMock.expect(odataJPAContext.getDefaultNaming()).andReturn(true);
+ EasyMock.replay(odataJPAContext);
+ return odataJPAContext;
+ }
+
+ private static EntityManagerFactory mockEntityManagerFactory() {
+ EntityManagerFactory emf = EasyMock.createMock(EntityManagerFactory.class);
+ EasyMock.expect(emf.getMetamodel()).andReturn(mockMetaModel());
+ EasyMock.replay(emf);
+ return emf;
+ }
+
+ private static Metamodel mockMetaModel() {
+ Metamodel metaModel = EasyMock.createMock(Metamodel.class);
+ EasyMock.replay(metaModel);
+ return metaModel;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
new file mode 100644
index 0000000..e525ffd
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtil.java
@@ -0,0 +1,337 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+import static org.junit.Assert.fail;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
+import org.apache.olingo.odata2.jpa.processor.core.common.ODataJPATestConstants;
+import org.easymock.EasyMock;
+
+public class EdmMockUtil {
+
+ public static ExpandSelectTreeNode mockExpandSelectTreeNode() {
+ ExpandSelectTreeNode nextExpandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
+ Map<String, ExpandSelectTreeNode> nextLink = null;
+ EasyMock.expect(nextExpandNode.getLinks()).andStubReturn(nextLink);
+ EasyMock.replay(nextExpandNode);
+ ExpandSelectTreeNode expandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
+ Map<String, ExpandSelectTreeNode> links = new HashMap<String, ExpandSelectTreeNode>();
+ links.put("SalesOrderLineItemDetails", nextExpandNode);
+ EasyMock.expect(expandNode.getLinks()).andStubReturn(links);
+ EasyMock.replay(expandNode);
+ return expandNode;
+ }
+
+ public static ExpandSelectTreeNode mockCurrentExpandSelectTreeNode() {
+ ExpandSelectTreeNode expandNode = EasyMock.createMock(ExpandSelectTreeNode.class);
+ Map<String, ExpandSelectTreeNode> links = new HashMap<String, ExpandSelectTreeNode>();
+ EasyMock.expect(expandNode.getLinks()).andStubReturn(links);
+ EasyMock.replay(expandNode);
+ return expandNode;
+ }
+
+ public static List<ArrayList<NavigationPropertySegment>> getExpandList() {
+ List<ArrayList<NavigationPropertySegment>> expandList = new ArrayList<ArrayList<NavigationPropertySegment>>();
+ ArrayList<NavigationPropertySegment> expands = new ArrayList<NavigationPropertySegment>();
+ expands.add(mockNavigationPropertySegment());
+ expandList.add(expands);
+ return expandList;
+ }
+
+ public static WriteFeedCallbackContext getWriteFeedCallBackContext() {
+ URI selfLink = null;
+ WriteFeedCallbackContext writeContext = new WriteFeedCallbackContext();
+ try {
+ selfLink = new URI("SalesOrders(2L)/SalesOrderLineItemDetails");
+ writeContext.setSelfLink(selfLink);
+ writeContext.setCurrentExpandSelectTreeNode(mockCurrentExpandSelectTreeNode());
+ writeContext.setNavigationProperty(mockNavigationProperty());
+ writeContext.setSourceEntitySet(mockSourceEntitySet());
+ writeContext.setEntryData(getFeedData());
+
+ } catch (URISyntaxException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+
+ return writeContext;
+ }
+
+ public static WriteEntryCallbackContext getWriteEntryCallBackContext() {
+ WriteEntryCallbackContext writeContext = new WriteEntryCallbackContext();
+ writeContext.setCurrentExpandSelectTreeNode(mockCurrentExpandSelectTreeNode());
+ writeContext.setNavigationProperty(mockNavigationProperty());
+ writeContext.setSourceEntitySet(mockSourceEntitySet());
+ writeContext.setEntryData(getEntryData());
+ return writeContext;
+ }
+
+ private static EdmEntitySet mockSourceEntitySet() {
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockSourceEdmEntityType());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entitySet);
+ return entitySet;
+ }
+
+ public static EdmEntityType mockSourceEdmEntityType() {
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ List<String> navigationPropertyNames = new ArrayList<String>();
+ List<String> propertyNames = new ArrayList<String>();
+ propertyNames.add("id");
+ propertyNames.add("description");
+ navigationPropertyNames.add("SalesOrderLineItemDetails");
+ try {
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("SalesOrderHeader");
+ EasyMock.replay(mapping);
+ EasyMock.expect(entityType.getName()).andStubReturn("SalesOrderHeader");
+ EasyMock.expect(entityType.getMapping()).andStubReturn(mapping);
+ EasyMock.expect(entityType.getNavigationPropertyNames()).andStubReturn(navigationPropertyNames);
+ EasyMock.expect(entityType.getProperty("SalesOrderLineItemDetails")).andStubReturn(mockNavigationProperty());
+ EdmProperty property1 = mockEdmPropertyOfSource1();
+ EasyMock.expect(entityType.getProperty("id")).andStubReturn(property1);
+ EasyMock.expect(entityType.getProperty("description")).andStubReturn(mockEdmPropertyOfSource2());
+ EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entityType);
+ return entityType;
+ }
+
+ private static EdmTyped mockEdmPropertyOfSource2() {
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmType type = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(type);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("description");
+ EasyMock.replay(mapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("description");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(type);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmProperty);
+ return edmProperty;
+ }
+
+ private static EdmProperty mockEdmPropertyOfSource1() {
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+ EdmType type = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(type);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("id");
+ EasyMock.replay(mapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("id");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(type);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmProperty);
+ return edmProperty;
+ }
+
+ private static Map<String, Object> getFeedData() {
+ Map<String, Object> entryData = new HashMap<String, Object>();
+ entryData.put("id", 1);
+ entryData.put("description", "laptop");
+ List<SalesOrderLineItem> salesOrderLineItems = new ArrayList<SalesOrderLineItem>();
+ salesOrderLineItems.add(new SalesOrderLineItem(23));
+ salesOrderLineItems.add(new SalesOrderLineItem(45));
+ entryData.put("SalesOrderLineItemDetails", salesOrderLineItems);
+ return entryData;
+ }
+
+ private static Map<String, Object> getEntryData() {
+ Map<String, Object> entryData = new HashMap<String, Object>();
+ entryData.put("id", 1);
+ entryData.put("description", "laptop");
+ entryData.put("SalesOrderLineItemDetails", new SalesOrderLineItem(23));
+ return entryData;
+ }
+
+ private static NavigationPropertySegment mockNavigationPropertySegment() {
+ NavigationPropertySegment navigationPropSegment = EasyMock.createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navigationPropSegment.getNavigationProperty()).andStubReturn(mockNavigationProperty());
+ EasyMock.expect(navigationPropSegment.getTargetEntitySet()).andStubReturn(mockTargetEntitySet());
+ EasyMock.replay(navigationPropSegment);
+ return navigationPropSegment;
+ }
+
+ public static NavigationPropertySegment mockThirdNavigationPropertySegment() {
+ NavigationPropertySegment navigationPropSegment = EasyMock.createMock(NavigationPropertySegment.class);
+ EasyMock.expect(navigationPropSegment.getNavigationProperty()).andStubReturn(mockSecondNavigationProperty());
+ EasyMock.expect(navigationPropSegment.getTargetEntitySet()).andStubReturn(mockThirdEntitySet());
+ EasyMock.replay(navigationPropSegment);
+ return navigationPropSegment;
+ }
+
+ public static EdmNavigationProperty mockSecondNavigationProperty() {
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("materials");
+ EasyMock.replay(mapping);
+ try {
+ EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.ONE);
+ EasyMock.expect(navigationProperty.getMapping()).andStubReturn(mapping);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("MaterialDetails");
+ EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("SalesOrderLineItem");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ return navigationProperty;
+ }
+
+ public static EdmEntitySet mockTargetEntitySet() {
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockTargetEdmEntityType());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entitySet);
+ return entitySet;
+ }
+
+ public static EdmEntitySet mockThirdEntitySet() {
+ EdmEntitySet entitySet = EasyMock.createMock(EdmEntitySet.class);
+ try {
+ EasyMock.expect(entitySet.getEntityType()).andStubReturn(mockThirdEdmEntityType());
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entitySet);
+ return entitySet;
+
+ }
+
+ private static EdmEntityType mockThirdEdmEntityType() {
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+
+ List<String> propertyNames = new ArrayList<String>();
+ propertyNames.add("price");
+ try {
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("Material");
+ EasyMock.replay(mapping);
+ EasyMock.expect(entityType.getName()).andStubReturn("Material");
+ EasyMock.expect(entityType.getMapping()).andStubReturn(mapping);
+ EdmProperty property = mockEdmPropertyOfTarget();
+ EasyMock.expect(entityType.getProperty("price")).andStubReturn(property);
+ EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entityType);
+ return entityType;
+ }
+
+ public static EdmEntityType mockTargetEdmEntityType() {
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+
+ List<String> propertyNames = new ArrayList<String>();
+ propertyNames.add("price");
+ try {
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("SalesOrderLineItem");
+ EasyMock.replay(mapping);
+ EasyMock.expect(entityType.getName()).andStubReturn("SalesOrderLineItem");
+ EasyMock.expect(entityType.getMapping()).andStubReturn(mapping);
+ EdmProperty property = mockEdmPropertyOfTarget();
+ EasyMock.expect(entityType.getProperty("price")).andStubReturn(property);
+ EasyMock.expect(entityType.getPropertyNames()).andStubReturn(propertyNames);
+
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(entityType);
+ return entityType;
+ }
+
+ private static EdmProperty mockEdmPropertyOfTarget() {
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+
+ EdmType type = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(type.getKind()).andStubReturn(EdmTypeKind.SIMPLE);
+ EasyMock.replay(type);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("price");
+ EasyMock.replay(mapping);
+ try {
+ EasyMock.expect(edmProperty.getName()).andStubReturn("price");
+ EasyMock.expect(edmProperty.getType()).andStubReturn(type);
+ EasyMock.expect(edmProperty.getMapping()).andStubReturn(mapping);
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(edmProperty);
+ return edmProperty;
+ }
+
+ public static EdmNavigationProperty mockNavigationProperty() {
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ EdmMapping mapping = EasyMock.createMock(EdmMapping.class);
+ EasyMock.expect(mapping.getInternalName()).andStubReturn("salesOrderLineItems");
+ EasyMock.replay(mapping);
+ try {
+ EasyMock.expect(navigationProperty.getMultiplicity()).andStubReturn(EdmMultiplicity.MANY);
+ EasyMock.expect(navigationProperty.getMapping()).andStubReturn(mapping);
+ EasyMock.expect(navigationProperty.getName()).andStubReturn("SalesOrderLineItemDetails");
+ EasyMock.expect(navigationProperty.getFromRole()).andStubReturn("SalesOrderHeader");
+ } catch (EdmException e) {
+ fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
+ }
+ EasyMock.replay(navigationProperty);
+ return navigationProperty;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
new file mode 100644
index 0000000..2189219
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/EdmMockUtilV2.java
@@ -0,0 +1,324 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.olingo.odata2.api.edm.EdmAssociation;
+import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
+import org.apache.olingo.odata2.api.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+import org.easymock.EasyMock;
+
+public class EdmMockUtilV2 {
+
+ public static interface JPAEdmMappingMock extends JPAEdmMapping, EdmMapping {
+
+ }
+
+ public static EdmEntityType mockEdmEntityType(final String entityName, final boolean withComplexType)
+ throws EdmException {
+
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(entityType.getName()).andReturn(entityName).anyTimes();
+ EasyMock.expect(entityType.getKeyPropertyNames()).andReturn(mockSimpleKeyPropertyNames(entityName));
+ if (withComplexType == false) {
+ EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNames(entityName)).anyTimes();
+ } else {
+ EasyMock.expect(entityType.getPropertyNames()).andReturn(mockPropertyNamesWithComplexType(entityName)).anyTimes();
+ }
+
+ EasyMock.expect(entityType.getNavigationPropertyNames()).andReturn(mockNavigationPropertyNames(entityName));
+ EasyMock.expect(entityType.getKind()).andReturn(EdmTypeKind.ENTITY);
+ EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, null, null));
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MINT)).andReturn(
+ mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MINT)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MSTRING)).andReturn(
+ mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MSTRING)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MDATETIME)).andReturn(
+ mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MDATETIME)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).andReturn(
+ mockEdmProperty(entityName, JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPATypeMock.NAVIGATION_PROPERTY_X)).andReturn(
+ mockEdmNavigationProperty(JPATypeMock.NAVIGATION_PROPERTY_X, EdmMultiplicity.ONE)).anyTimes();
+ } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
+ EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MLONG)).andReturn(
+ mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MLONG)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).andReturn(
+ mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTE)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).andReturn(
+ mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)).anyTimes();
+ EasyMock.expect(entityType.getProperty(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).andReturn(
+ mockEdmProperty(entityName, JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)).anyTimes();
+ }
+ EasyMock.replay(entityType);
+ return entityType;
+ }
+
+ public static List<String> mockNavigationPropertyNames(final String entityName) {
+ List<String> propertyNames = new ArrayList<String>();
+ propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_X);
+ propertyNames.add(JPATypeMock.NAVIGATION_PROPERTY_XS);
+ return propertyNames;
+ }
+
+ public static List<String> mockSimpleKeyPropertyNames(final String entityName) {
+ List<String> keyPropertyNames = new ArrayList<String>();
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ keyPropertyNames.add(JPATypeMock.PROPERTY_NAME_MINT);
+ } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
+ keyPropertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
+ }
+
+ return keyPropertyNames;
+ }
+
+ public static List<String> mockPropertyNames(final String entityName) {
+ List<String> propertyNames = new ArrayList<String>();
+
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ propertyNames.add(JPATypeMock.PROPERTY_NAME_MINT);
+ propertyNames.add(JPATypeMock.PROPERTY_NAME_MDATETIME);
+ propertyNames.add(JPATypeMock.PROPERTY_NAME_MSTRING);
+ } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
+ propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
+ propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTE);
+ propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY);
+ propertyNames.add(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE);
+ } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
+ propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT);
+ propertyNames.add(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE);
+ } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
+ propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT);
+ propertyNames.add(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID);
+ }
+
+ return propertyNames;
+ }
+
+ public static List<String> mockPropertyNamesWithComplexType(final String entityName) {
+ List<String> propertyNames = mockPropertyNames(entityName);
+ propertyNames.add(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE);
+
+ return propertyNames;
+
+ }
+
+ public static EdmAssociationEnd mockEdmAssociatioEnd(final String navigationPropertyName, final String role)
+ throws EdmException {
+ EdmAssociationEnd associationEnd = EasyMock.createMock(EdmAssociationEnd.class);
+ EasyMock.expect(associationEnd.getMultiplicity()).andReturn(EdmMultiplicity.ONE);
+ EdmEntityType entityType = EasyMock.createMock(EdmEntityType.class);
+ EasyMock.expect(entityType.getMapping()).andReturn((EdmMapping) mockEdmMapping("JPARelatedTypeMock", null, null));
+ EasyMock.replay(entityType);
+
+ EasyMock.expect(associationEnd.getEntityType()).andReturn(entityType);
+ EasyMock.replay(associationEnd);
+ return associationEnd;
+ }
+
+ public static EdmAssociation mockEdmAssociation(final String navigationPropertyName) throws EdmException {
+ EdmAssociation edmAssociation = EasyMock.createMock(EdmAssociation.class);
+ EasyMock.expect(edmAssociation.getEnd("TO")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "TO"));
+ EasyMock.expect(edmAssociation.getEnd("FROM")).andReturn(mockEdmAssociatioEnd(navigationPropertyName, "FROM"));
+ EasyMock.replay(edmAssociation);
+ return edmAssociation;
+ }
+
+ public static EdmEntitySet mockEdmEntitySet(final String entityName, final boolean withComplexType)
+ throws EdmException {
+ EdmEntitySet entitySet = null;
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ entitySet = EasyMock.createMock(EdmEntitySet.class);
+ EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes();
+ EasyMock.expect(entitySet.getRelatedEntitySet(EasyMock.isA(EdmNavigationProperty.class))).andReturn(
+ mockEdmEntitySet(JPARelatedTypeMock.ENTITY_NAME, false)).anyTimes();
+ } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
+ entitySet = EasyMock.createMock(EdmEntitySet.class);
+ EasyMock.expect(entitySet.getEntityType()).andReturn(mockEdmEntityType(entityName, withComplexType)).anyTimes();
+ }
+
+ EasyMock.replay(entitySet);
+ return entitySet;
+ }
+
+ public static EdmNavigationProperty mockEdmNavigationProperty(final String navigationPropertyName,
+ final EdmMultiplicity multiplicity) throws EdmException {
+
+ EdmEntityType edmEntityType = mockEdmEntityType(JPARelatedTypeMock.ENTITY_NAME, false);
+
+ EdmNavigationProperty navigationProperty = EasyMock.createMock(EdmNavigationProperty.class);
+ EasyMock.expect(navigationProperty.getType()).andReturn(edmEntityType).anyTimes();
+ EasyMock.expect(navigationProperty.getMultiplicity()).andReturn(multiplicity);
+ EasyMock.expect(navigationProperty.getMapping()).andReturn(
+ (EdmMapping) mockEdmMapping(null, null, navigationPropertyName)).anyTimes();
+ EasyMock.expect(navigationProperty.getToRole()).andReturn("TO");
+ EasyMock.expect(navigationProperty.getRelationship()).andReturn(mockEdmAssociation(navigationPropertyName));
+ if (multiplicity.equals(EdmMultiplicity.ONE)) {
+ EasyMock.expect(navigationProperty.getName()).andReturn(JPATypeMock.NAVIGATION_PROPERTY_X).anyTimes();
+ }
+
+ EasyMock.replay(navigationProperty);
+
+ return navigationProperty;
+ }
+
+ public static EdmProperty mockEdmProperty(final String entityName, final String propertyName) throws EdmException {
+ EdmProperty edmProperty = EasyMock.createMock(EdmProperty.class);
+
+ if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT) ||
+ propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING) ||
+ propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME) ||
+ propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT) ||
+ propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT) ||
+ propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID) ||
+ propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG) ||
+ propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE) ||
+ propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE) ||
+ propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) {
+
+ EdmType edmType = EasyMock.createMock(EdmType.class);
+ EasyMock.expect(edmProperty.getType()).andReturn(edmType).anyTimes();
+ EasyMock.expect(edmType.getKind()).andReturn(EdmTypeKind.SIMPLE).anyTimes();
+ EasyMock.replay(edmType);
+ EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes();
+ EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(entityName, propertyName, null))
+ .anyTimes();
+
+ } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE) ||
+ propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) {
+ EdmComplexType complexType = mockComplexType(propertyName);
+
+ EasyMock.expect(edmProperty.getType()).andReturn(complexType).anyTimes();
+ EasyMock.expect(edmProperty.getName()).andReturn(propertyName).anyTimes();
+ EasyMock.expect(edmProperty.getMapping()).andReturn((EdmMapping) mockEdmMapping(null, propertyName, null))
+ .anyTimes();
+
+ }
+
+ EasyMock.replay(edmProperty);
+ return edmProperty;
+ }
+
+ public static EdmComplexType mockComplexType(final String complexPropertyName) throws EdmException {
+
+ String complexTypeName = null;
+ if (complexPropertyName.equals(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) {
+ complexTypeName = JPATypeEmbeddableMock2.ENTITY_NAME;
+ } else if (complexPropertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) {
+ complexTypeName = JPATypeEmbeddableMock.ENTITY_NAME;
+ }
+
+ EdmComplexType edmComplexType = EasyMock.createMock(EdmComplexType.class);
+ EasyMock.expect(edmComplexType.getKind()).andReturn(EdmTypeKind.COMPLEX);
+ EasyMock.expect(edmComplexType.getPropertyNames()).andReturn(mockPropertyNames(complexTypeName)).anyTimes();
+ EasyMock.expect(edmComplexType.getMapping()).andReturn((EdmMapping) mockEdmMapping(complexTypeName, null, null));
+
+ if (complexTypeName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
+ EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).andReturn(
+ mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)).anyTimes();
+ EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).andReturn(
+ mockEdmProperty(complexTypeName, JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)).anyTimes();
+ } else if (complexTypeName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
+ EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).andReturn(
+ mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)).anyTimes();
+ EasyMock.expect(edmComplexType.getProperty(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).andReturn(
+ mockEdmProperty(complexTypeName, JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)).anyTimes();
+ }
+
+ EasyMock.replay(edmComplexType);
+ return edmComplexType;
+ }
+
+ public static JPAEdmMapping mockEdmMapping(final String entityName, final String propertyName,
+ final String navigationPropertyName) {
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+
+ if (propertyName == null && entityName != null) {
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ mapping.setJPAType(JPATypeMock.class);
+ } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
+ mapping.setJPAType(JPARelatedTypeMock.class);
+ } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
+ mapping.setJPAType(JPATypeEmbeddableMock.class);
+ } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
+ mapping.setJPAType(JPATypeEmbeddableMock2.class);
+ }
+ } else if (entityName == null && navigationPropertyName != null) {
+ mapping.setJPAType(JPARelatedTypeMock.class);
+ mapping.setJPAColumnName(JPATypeMock.NAVIGATION_PROPERTY_X);
+ } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MINT)) {
+ mapping.setJPAType(int.class);
+ ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MINT);
+ } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MSTRING)) {
+ mapping.setJPAType(String.class);
+ ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MSTRING);
+ } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MDATETIME)) {
+ mapping.setJPAType(Calendar.class);
+ ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MDATETIME);
+ } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MLONG)) {
+ mapping.setJPAType(long.class);
+ ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MLONG);
+ } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE)) {
+ mapping.setJPAType(double.class);
+ ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE);
+ } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTE)) {
+ mapping.setJPAType(byte.class);
+ ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTE);
+ } else if (propertyName.equals(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY)) {
+ mapping.setJPAType(byte[].class);
+ ((Mapping) mapping).setInternalName(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY);
+ } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT)) {
+ mapping.setJPAType(Short.TYPE);
+ ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT);
+ } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT)) {
+ mapping.setJPAType(Float.TYPE);
+ ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT);
+ } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID)) {
+ mapping.setJPAType(UUID.class);
+ ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID);
+ } else if (propertyName.equals(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE)) {
+ mapping.setJPAType(JPATypeEmbeddableMock2.class);
+ ((Mapping) mapping).setInternalName(JPATypeMock.JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE);
+ } else if (propertyName.equals(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE)) {
+ mapping.setJPAType(JPATypeEmbeddableMock.class);
+ ((Mapping) mapping).setInternalName(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE);
+ }
+ return mapping;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
new file mode 100644
index 0000000..9242df9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/JPATypeMock.java
@@ -0,0 +1,205 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.UUID;
+
+/* ========================================================================= */
+public class JPATypeMock {
+
+ public static final String ENTITY_NAME = "JPATypeMock";
+ public static final String PROPERTY_NAME_MINT = "mInt";
+ public static final String PROPERTY_NAME_MSTRING = "mString";
+ public static final String PROPERTY_NAME_MDATETIME = "mDateTime";
+ public static final String PROPERTY_NAME_MKEY = "key";
+ public static final String PROPERTY_NAME_MCOMPLEXTYPE = "complexType";
+
+ public static final String NAVIGATION_PROPERTY_X = "mRelatedEntity";
+ public static final String NAVIGATION_PROPERTY_XS = "mRelatedEntities";
+
+ private JPATypeEmbeddableMock key;
+ private JPATypeEmbeddableMock complexType;
+ private int mInt;
+ private String mString;
+ private Calendar mDateTime;
+ private JPARelatedTypeMock mRelatedEntity;
+ private List<JPARelatedTypeMock> mRelatedEntities = new ArrayList<JPATypeMock.JPARelatedTypeMock>();
+
+ public String getMString() {
+ return mString;
+ }
+
+ public void setMString(final String mString) {
+ this.mString = mString;
+ }
+
+ public JPATypeEmbeddableMock getKey() {
+ return key;
+ }
+
+ public void setKey(final JPATypeEmbeddableMock key) {
+ this.key = key;
+ }
+
+ public int getMInt() {
+ return mInt;
+ }
+
+ public void setMInt(final int mInt) {
+ this.mInt = mInt;
+ }
+
+ public Calendar getMDateTime() {
+ return mDateTime;
+ }
+
+ public void setMDateTime(final Calendar mDateTime) {
+ this.mDateTime = mDateTime;
+ }
+
+ public JPARelatedTypeMock getMRelatedEntity() {
+ return mRelatedEntity;
+ }
+
+ public void setMRelatedEntity(final JPARelatedTypeMock mRelatedEntity) {
+ this.mRelatedEntity = mRelatedEntity;
+ }
+
+ public List<JPARelatedTypeMock> getMRelatedEntities() {
+ return mRelatedEntities;
+ }
+
+ public void setMRelatedEntities(final List<JPARelatedTypeMock> mRelatedEntities) {
+ this.mRelatedEntities = mRelatedEntities;
+ }
+
+ public JPATypeEmbeddableMock getComplexType() {
+ return complexType;
+ }
+
+ public void setComplexType(final JPATypeEmbeddableMock complexType) {
+ this.complexType = complexType;
+ }
+
+ /* ========================================================================= */
+ public static class JPATypeEmbeddableMock {
+
+ public static final String ENTITY_NAME = "JPATypeEmbeddableMock";
+ public static final String PROPERTY_NAME_MSHORT = "mShort";
+ public static final String PROPERTY_NAME_MEMBEDDABLE = "mEmbeddable";
+
+ private short mShort;
+ private JPATypeEmbeddableMock2 mEmbeddable;
+
+ public short getMShort() {
+ return mShort;
+ }
+
+ public void setMShort(final short mShort) {
+ this.mShort = mShort;
+ }
+
+ public JPATypeEmbeddableMock2 getMEmbeddable() {
+ return mEmbeddable;
+ }
+
+ public void setMEmbeddable(final JPATypeEmbeddableMock2 mEmbeddable) {
+ this.mEmbeddable = mEmbeddable;
+ }
+
+ }
+
+ /* ========================================================================= */
+ public static class JPATypeEmbeddableMock2 {
+
+ public static final String ENTITY_NAME = "JPATypeEmbeddableMock2";
+ public static final String PROPERTY_NAME_MUUID = "mUUID";
+ public static final String PROPERTY_NAME_MFLOAT = "mFloat";
+
+ private UUID mUUID;
+ private float mFloat;
+
+ public UUID getMUUID() {
+ return mUUID;
+ }
+
+ public void setMUUID(final UUID mUUID) {
+ this.mUUID = mUUID;
+ }
+
+ public float getMFloat() {
+ return mFloat;
+ }
+
+ public void setMFloat(final float mFloat) {
+ this.mFloat = mFloat;
+ }
+
+ }
+
+ /* ========================================================================= */
+ public static final class JPARelatedTypeMock {
+ public static final String ENTITY_NAME = "JPARelatedTypeMock";
+ public static final String PROPERTY_NAME_MLONG = "mLong";
+ public static final String PROPERTY_NAME_MDOUBLE = "mDouble";
+ public static final String PROPERTY_NAME_MBYTE = "mByte";
+ public static final String PROPERTY_NAME_MBYTEARRAY = "mByteArray";
+
+ private long mLong;
+ private double mDouble;
+ private byte mByte;
+ private byte mByteArray[];
+
+ public long getMLong() {
+ return mLong;
+ }
+
+ public void setMLong(final long key) {
+ mLong = key;
+ }
+
+ public double getMDouble() {
+ return mDouble;
+ }
+
+ public void setMDouble(final double mDouble) {
+ this.mDouble = mDouble;
+ }
+
+ public byte getMByte() {
+ return mByte;
+ }
+
+ public void setMByte(final byte mByte) {
+ this.mByte = mByte;
+ }
+
+ public byte[] getMByteArray() {
+ return mByteArray;
+ }
+
+ public void setMByteArray(final byte mByteArray[]) {
+ this.mByteArray = mByteArray;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
new file mode 100644
index 0000000..92912cc
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/ODataEntryMockUtil.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.UUID;
+
+import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
+import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPARelatedTypeMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock;
+import org.apache.olingo.odata2.jpa.processor.core.mock.data.JPATypeMock.JPATypeEmbeddableMock2;
+import org.easymock.EasyMock;
+
+public class ODataEntryMockUtil {
+
+ public static final int VALUE_MINT = 20;
+ public static Calendar VALUE_DATE_TIME = null;
+ public static final String VALUE_MSTRING = "Mock";
+ public static final long VALUE_MLONG = 1234567890L;
+ public static final double VALUE_MDOUBLE = 20.12;
+ public static final byte VALUE_MBYTE = 0XA;
+ public static final byte[] VALUE_MBYTEARRAY = { 0XA, 0XB };
+ public static final float VALUE_MFLOAT = 2.00F;
+ public static final UUID VALUE_UUID = UUID.fromString("38400000-8cf0-11bd-b23e-10b96e4ef00d");
+ public static final short VALUE_SHORT = 2;
+
+ public static ODataEntry mockODataEntry(final String entityName) {
+ ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
+ EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryProperties(entityName)).anyTimes();
+
+ EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(false);
+ EasyMock.replay(oDataEntry);
+ return oDataEntry;
+ }
+
+ public static ODataEntry mockODataEntryWithComplexType(final String entityName) {
+ ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
+ EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithComplexType(entityName))
+ .anyTimes();
+
+ EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(false);
+ EasyMock.replay(oDataEntry);
+ return oDataEntry;
+ }
+
+ public static Map<String, Object> mockODataEntryProperties(final String entityName) {
+ Map<String, Object> propertyMap = new HashMap<String, Object>();
+
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ propertyMap.put(JPATypeMock.PROPERTY_NAME_MINT, VALUE_MINT);
+
+ VALUE_DATE_TIME = Calendar.getInstance(TimeZone.getDefault());
+ VALUE_DATE_TIME.set(2013, 1, 1, 1, 1, 1);
+ propertyMap.put(JPATypeMock.PROPERTY_NAME_MDATETIME, VALUE_DATE_TIME);
+
+ propertyMap.put(JPATypeMock.PROPERTY_NAME_MSTRING, VALUE_MSTRING);
+ } else if (entityName.equals(JPARelatedTypeMock.ENTITY_NAME)) {
+ propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MLONG, VALUE_MLONG);
+ propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MDOUBLE, VALUE_MDOUBLE);
+ propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTE, VALUE_MBYTE);
+ propertyMap.put(JPARelatedTypeMock.PROPERTY_NAME_MBYTEARRAY, VALUE_MBYTEARRAY);
+ } else if (entityName.equals(JPATypeEmbeddableMock.ENTITY_NAME)) {
+ propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MSHORT, VALUE_SHORT);
+ propertyMap.put(JPATypeEmbeddableMock.PROPERTY_NAME_MEMBEDDABLE,
+ mockODataEntryProperties(JPATypeEmbeddableMock2.ENTITY_NAME));
+ } else if (entityName.equals(JPATypeEmbeddableMock2.ENTITY_NAME)) {
+ propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MFLOAT, VALUE_MFLOAT);
+ propertyMap.put(JPATypeEmbeddableMock2.PROPERTY_NAME_MUUID, VALUE_UUID);
+ }
+
+ return propertyMap;
+ }
+
+ public static Map<String, Object> mockODataEntryPropertiesWithComplexType(final String entityName) {
+ Map<String, Object> propertyMap = mockODataEntryProperties(entityName);
+ propertyMap
+ .put(JPATypeMock.PROPERTY_NAME_MCOMPLEXTYPE, mockODataEntryProperties(JPATypeEmbeddableMock.ENTITY_NAME));
+ return propertyMap;
+ }
+
+ public static Map<String, Object> mockODataEntryPropertiesWithInline(final String entityName) {
+ Map<String, Object> propertyMap = mockODataEntryProperties(entityName);
+ List<ODataEntry> relatedEntries = new ArrayList<ODataEntry>();
+ relatedEntries.add(mockODataEntry(JPARelatedTypeMock.ENTITY_NAME));
+ ODataFeed feed = EasyMock.createMock(ODataFeed.class);
+ EasyMock.expect(feed.getEntries()).andReturn(relatedEntries);
+ EasyMock.replay(feed);
+ propertyMap.put(JPATypeMock.NAVIGATION_PROPERTY_X, feed);
+
+ return propertyMap;
+
+ }
+
+ public static ODataEntry mockODataEntryWithInline(final String entityName) {
+ ODataEntry oDataEntry = EasyMock.createMock(ODataEntry.class);
+ EasyMock.expect(oDataEntry.getProperties()).andReturn(mockODataEntryPropertiesWithInline(entityName)).anyTimes();
+ if (entityName.equals(JPATypeMock.ENTITY_NAME)) {
+ EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(true);
+ } else {
+ EasyMock.expect(oDataEntry.containsInlineEntry()).andReturn(false);
+ }
+ EasyMock.replay(oDataEntry);
+ return oDataEntry;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderHeader.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderHeader.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderHeader.java
new file mode 100644
index 0000000..1236d96
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderHeader.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class SalesOrderHeader {
+
+ private int id;
+ private String description;
+
+ public SalesOrderHeader() {}
+
+ public SalesOrderHeader(final int id, final String description) {
+ super();
+ this.id = id;
+ this.description = description;
+ }
+
+ private List<SalesOrderLineItem> salesOrderLineItems = new ArrayList<SalesOrderLineItem>();
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(final String description) {
+ this.description = description;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(final int id) {
+ this.id = id;
+ }
+
+ public List<SalesOrderLineItem> getSalesOrderLineItems() {
+ return salesOrderLineItems;
+ }
+
+ public void setSalesOrderLineItems(final List<SalesOrderLineItem> salesOrderLineItems) {
+ this.salesOrderLineItems = salesOrderLineItems;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItem.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItem.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItem.java
new file mode 100644
index 0000000..be28f13
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItem.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+public class SalesOrderLineItem {
+
+ private int price;
+
+ public SalesOrderLineItem(final int price) {
+ super();
+ this.price = price;
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public void setPrice(final int price) {
+ this.price = price;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItemKey.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItemKey.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItemKey.java
new file mode 100644
index 0000000..9f6048b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/data/SalesOrderLineItemKey.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.data;
+
+public class SalesOrderLineItemKey {
+
+ private int soId;
+ private int liId;
+
+ public SalesOrderLineItemKey() {
+
+ }
+
+ public SalesOrderLineItemKey(final int soId, final int liId) {
+ super();
+ this.soId = soId;
+ this.liId = liId;
+ }
+
+ public int getSoId() {
+ return soId;
+ }
+
+ public void setSoId(final int soId) {
+ this.soId = soId;
+ }
+
+ public int getLiId() {
+ return liId;
+ }
+
+ public void setLiId(final int liId) {
+ this.liId = liId;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/EdmSchemaMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/EdmSchemaMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/EdmSchemaMock.java
new file mode 100644
index 0000000..5b927f5
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/EdmSchemaMock.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.Association;
+import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
+import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
+import org.apache.olingo.odata2.api.edm.provider.ComplexType;
+import org.apache.olingo.odata2.api.edm.provider.EntityContainer;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
+import org.apache.olingo.odata2.api.edm.provider.Key;
+import org.apache.olingo.odata2.api.edm.provider.Mapping;
+import org.apache.olingo.odata2.api.edm.provider.Property;
+import org.apache.olingo.odata2.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata2.api.edm.provider.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.jpa.processor.api.model.JPAEdmMapping;
+import org.apache.olingo.odata2.jpa.processor.core.model.JPAEdmMappingImpl;
+
+public class EdmSchemaMock {
+
+ private static final String ASSOCIATION_ROLE_NAME_ONE = "SalesOrderHeader";
+ private static final String ASSOCIATION_NAME = "SalesOrderHeader_SalesOrderItem";
+ private static final String ASSOCIATION_SET_NAME = "SalesOrderHeader_SalesOrderItemSet";
+ private static final String ASSOCIATION_ROLE_NAME_TWO = "SalesOrderItem";
+ private static final String NAMESPACE = "salesorderprocessing";
+ private static final String ENTITY_CONTAINER_NAME = "salesorderprocessingContainer";
+ private static final String ENTITY_NAME_ONE = "SalesOrderHeader";
+ private static final String ENTITY_NAME_TWO = "SalesOrderItem";
+ private static final String ENTITY_SET_NAME_ONE = "SalesOrderHeaders";
+ private static final String FUNCTION_IMPORT_NAME_ONE = "SalesOrder_FunctionImport1";
+ private static final String FUNCTION_IMPORT_NAME_TWO = "SalesOrder_FunctionImport2";
+ private static final String ENTITY_SET_NAME_TWO = "SalesOrderItems";
+ private static final String COMPLEX_TYPE_NAME_ONE = "Address";
+ private static final String COMPLEX_TYPE_NAME_TWO = "SalesOrderItemKey";
+
+ public static Schema createMockEdmSchema() {
+ Schema schema = new Schema();
+ schema.setNamespace(NAMESPACE);
+ schema.setComplexTypes(createComplexTypes());
+ schema.setEntityContainers(createEntityContainer());
+ schema.setEntityTypes(createEntityTypes());
+ schema.setAssociations(createAssociations());
+ return schema;
+ }
+
+ private static List<EntityContainer> createEntityContainer() {
+ List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ EntityContainer entityContainer = new EntityContainer();
+ entityContainer.setDefaultEntityContainer(true);
+ entityContainer.setName(ENTITY_CONTAINER_NAME);
+ entityContainer.setEntitySets(createEntitySets());
+ entityContainer.setAssociationSets(createAssociationSets());
+ entityContainer.setFunctionImports(createFunctionImports());
+ entityContainers.add(entityContainer);
+ return entityContainers;
+ }
+
+ private static List<AssociationSet> createAssociationSets() {
+ List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ AssociationSet associationSet = new AssociationSet();
+ associationSet.setName(ASSOCIATION_SET_NAME);
+ associationSet.setAssociation(new FullQualifiedName(NAMESPACE, ASSOCIATION_NAME));
+ associationSet
+ .setEnd1(new AssociationSetEnd().setEntitySet(ENTITY_SET_NAME_ONE).setRole(ASSOCIATION_ROLE_NAME_ONE));
+ associationSet
+ .setEnd2(new AssociationSetEnd().setEntitySet(ENTITY_SET_NAME_TWO).setRole(ASSOCIATION_ROLE_NAME_TWO));
+ associationSets.add(associationSet);
+ return associationSets;
+ }
+
+ private static List<EntitySet> createEntitySets() {
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ EntitySet entitySet = new EntitySet();
+ entitySet.setName(ENTITY_SET_NAME_ONE);
+ entitySet.setEntityType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_ONE));
+ entitySets.add(entitySet);
+ entitySet = new EntitySet();
+ entitySet.setName(ENTITY_SET_NAME_TWO);
+ entitySet.setEntityType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_TWO));
+ entitySets.add(entitySet);
+ return entitySets;
+ }
+
+ private static List<FunctionImport> createFunctionImports() {
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ FunctionImport functionImport = new FunctionImport();
+ functionImport.setName(FUNCTION_IMPORT_NAME_ONE);
+ functionImports.add(functionImport);
+ functionImport = new FunctionImport();
+ functionImport.setName(FUNCTION_IMPORT_NAME_TWO);
+ functionImports.add(functionImport);
+ return functionImports;
+ }
+
+ private static List<Association> createAssociations() {
+ List<Association> associations = new ArrayList<Association>();
+ Association association = new Association();
+ association.setName(ASSOCIATION_NAME);
+ association.setEnd1(new AssociationEnd().setMultiplicity(EdmMultiplicity.ONE).setRole(ASSOCIATION_ROLE_NAME_ONE)
+ .setType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_ONE)));
+ association.setEnd2(new AssociationEnd().setMultiplicity(EdmMultiplicity.MANY).setRole(ASSOCIATION_ROLE_NAME_TWO)
+ .setType(new FullQualifiedName(NAMESPACE, ENTITY_NAME_TWO)));
+ associations.add(association);
+ return associations;
+ }
+
+ private static List<EntityType> createEntityTypes() {
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ EntityType entityType = new EntityType();
+ entityType.setName(ENTITY_NAME_ONE);
+ String[] keyNamesOne = { "SoId" };
+ entityType.setKey(createKey(keyNamesOne));
+ entityTypes.add(entityType);
+
+ entityType = new EntityType();
+ entityType.setName(ENTITY_NAME_TWO);
+ String[] keyNamesTwo = { "SoId", "LiId" };
+ entityType.setKey(createKey(keyNamesTwo));
+ entityTypes.add(entityType);
+ return entityTypes;
+
+ }
+
+ private static Key createKey(final String[] keyNames) {
+ Key key = new Key();
+ List<PropertyRef> keys = new ArrayList<PropertyRef>();
+ for (String keyName : keyNames) {
+ keys.add(new PropertyRef().setName(keyName));
+ }
+ key.setKeys(keys);
+ return null;
+ }
+
+ private static List<ComplexType> createComplexTypes() {
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ ComplexType complexTypeOne = new ComplexType();
+ complexTypeOne.setName(COMPLEX_TYPE_NAME_ONE);
+ complexTypeOne.setProperties(createComplexTypePropertiesOne());
+ complexTypes.add(complexTypeOne);
+ ComplexType complexTypeTwo = new ComplexType();
+ complexTypeTwo.setName(COMPLEX_TYPE_NAME_TWO);
+ complexTypeTwo.setProperties(createComplexTypePropertiesTwo());
+ complexTypes.add(complexTypeTwo);
+ return complexTypes;
+ }
+
+ private static List<Property> createComplexTypePropertiesTwo() {
+ List<Property> properties = new ArrayList<Property>();
+ SimpleProperty property = new SimpleProperty();
+ property.setName("SoId");
+ property.setType(EdmSimpleTypeKind.Int64);
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ mapping.setJPAColumnName("Sales_Order_Id");
+ ((Mapping) mapping).setInternalName("SalesOrderItemKey.SoId");
+ property.setMapping((Mapping) mapping);
+ properties.add(property);
+ property = new SimpleProperty();
+ property.setName("LiId");
+ property.setType(EdmSimpleTypeKind.Int64);
+ mapping = new JPAEdmMappingImpl();
+ mapping.setJPAColumnName("Sales_Order_Item_Id");
+ property.setMapping((Mapping) mapping);
+ properties.add(property);
+ return properties;
+
+ }
+
+ private static List<Property> createComplexTypePropertiesOne() {
+ List<Property> properties = new ArrayList<Property>();
+ SimpleProperty property = new SimpleProperty();
+ property.setName("StreetName");
+ property.setType(EdmSimpleTypeKind.String);
+ JPAEdmMapping mapping = new JPAEdmMappingImpl();
+ mapping.setJPAColumnName("STREET_NAME");
+ property.setMapping((Mapping) mapping);
+ properties.add(property);
+ property = new SimpleProperty();
+ property.setName("City");
+ property.setType(EdmSimpleTypeKind.String);
+ mapping = new JPAEdmMappingImpl();
+ mapping.setJPAColumnName("CITY");
+ property.setMapping((Mapping) mapping);
+ properties.add(property);
+ return properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAAttributeMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAAttributeMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAAttributeMock.java
new file mode 100644
index 0000000..f21cbae
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAAttributeMock.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.lang.reflect.Member;
+
+import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.ManagedType;
+
+public abstract class JPAAttributeMock<X, Y> implements Attribute<X, Y> {
+
+ @Override
+ public ManagedType<X> getDeclaringType() {
+ return null;
+ }
+
+ @Override
+ public Member getJavaMember() {
+ return null;
+ }
+
+ @Override
+ public Class<Y> getJavaType() {
+ return null;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public javax.persistence.metamodel.Attribute.PersistentAttributeType getPersistentAttributeType() {
+ return null;
+ }
+
+ @Override
+ public boolean isAssociation() {
+ return false;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
new file mode 100644
index 0000000..6f7d16e
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPACustomProcessorMock.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport.ReturnType.Type;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImportParameter;
+
+public class JPACustomProcessorMock {
+
+ public static final String className = "JPACustomProcessorMock";
+ public static final String edmName = "JPACustomProcessor";
+
+ @EdmFunctionImport(name = "Method1", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
+ isCollection = true))
+ public List<JPACustomProcessorMock> method1(@EdmFunctionImportParameter(name = "Param1", facets = @EdmFacets(
+ nullable = true,
+ maxLength = 2)) final String param1, final int param2, @EdmFunctionImportParameter(name = "Param3",
+ facets = @EdmFacets(precision = 10, scale = 2)) final double param3) {
+ return new ArrayList<JPACustomProcessorMock>();
+ }
+
+ @EdmFunctionImport(name = "Method2", entitySet = "MockSet", returnType = @ReturnType(type = Type.ENTITY,
+ isCollection = true))
+ public List<JPACustomProcessorMock> method2(
+ @EdmFunctionImportParameter(facets = @EdmFacets(maxLength = 2), name = "Param2") final String param2) {
+ return new ArrayList<JPACustomProcessorMock>();
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.SIMPLE))
+ public int method3(@EdmFunctionImportParameter(name = "Param3") final String param3) {
+ return 0;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.ENTITY,
+ isCollection = false), entitySet = "MockSet")
+ public JPACustomProcessorMock method7() {
+ return null;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX,
+ isCollection = false))
+ public JPACustomProcessorMock method9() {
+ return null;
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX,
+ isCollection = true))
+ public List<JPACustomProcessorMock> method10() {
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEdmMockData.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEdmMockData.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEdmMockData.java
new file mode 100644
index 0000000..9b692a4
--- /dev/null
+++ b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/jpa/processor/core/mock/model/JPAEdmMockData.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.core.mock.model;
+
+import org.apache.olingo.odata2.jpa.processor.core.mock.model.JPAEdmMockData.EntityType.EntityTypeA;
+
+public interface JPAEdmMockData {
+ /*
+ * Edm Complex Type Mock Data
+ */
+ public interface ComplexType {
+
+ public interface ComplexTypeA {
+ public static final String name = "ComplexTypeA";
+ public static final Class<ComplexTypeA> clazz = ComplexTypeA.class;
+
+ public interface Property {
+ public static final String PROPERTY_A = "A";
+ public static final String PROPERTY_B = "B";
+ public static final String PROPERTY_C = "C";
+ }
+
+ }
+
+ public interface ComplexTypeB {
+ public static final String name = "ComplexTypeB";
+
+ public interface Property {
+ public static final String PROPERTY_D = "D";
+ public static final String PROPERTY_E = "E";
+ }
+
+ }
+ }
+
+ public interface EntityType {
+ public interface EntityTypeA {
+ public static final String name = "SalesOrderHeader";
+ public static final Class<EntityTypeA> entityClazz = EntityTypeA.class;
+
+ public interface Property {
+ public static final String PROPERTY_A = SimpleType.SimpleTypeA.NAME;
+
+ }
+
+ }
+ }
+
+ public interface SimpleType {
+ public interface SimpleTypeA {
+ public static final String NAME = "SOID";
+ public static final Class<String> clazz = String.class;
+ public static final Class<EntityTypeA> declaringClazz = EntityType.EntityTypeA.class;
+ }
+ }
+}
[08/47] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2
Posted by tb...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/9a05b371
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/9a05b371
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/9a05b371
Branch: refs/heads/ODataServlet
Commit: 9a05b3719b542376513db67931e42c11d7a04e59
Parents: 9a69843 1ce2c87
Author: Chandan V A <ch...@sap.com>
Authored: Mon Dec 23 18:03:43 2013 +0530
Committer: Chandan V A <ch...@sap.com>
Committed: Mon Dec 23 18:03:43 2013 +0530
----------------------------------------------------------------------
.../processor/core/util/AnnotationHelper.java | 26 +-
.../datasource/AnnotationsInMemoryDsTest.java | 60 ++++-
.../core/util/AnnotationHelperTest.java | 270 +++++++++++++++++++
.../annotation-processor-webref/pom.xml | 6 +
.../processor/ref/AbstractRefTest.java | 195 ++++++++++++++
.../processor/ref/AbstractRefXmlTest.java | 89 ++++++
.../processor/ref/ServiceJsonTest.java | 71 +++++
.../processor/ref/ServiceXmlTest.java | 123 +++++++++
8 files changed, 832 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
[38/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypesMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypesMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypesMapType.java
new file mode 100644
index 0000000..7a72e08
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAEntityTypesMapType.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ * <p>
+ * Java class for JPAEntityTypesMapType complex type.
+ *
+ * <p>
+ * The following schema fragment specifies the expected content contained within
+ * this class.
+ *
+ * <pre>
+ * <complexType name="JPAEntityTypesMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="JPAEntityType"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAEntityTypeMapType"
+ * maxOccurs="unbounded" minOccurs="0"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPAEntityTypesMapType", propOrder = { "jpaEntityType" })
+public class JPAEntityTypesMapType {
+
+ @XmlElement(name = "JPAEntityType")
+ protected List<JPAEntityTypeMapType> jpaEntityType;
+
+ /**
+ * Gets the value of the jpaEntityType property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list, not a
+ * snapshot. Therefore any modification you make to the returned list will
+ * be present inside the JAXB object. This is why there is not a
+ * <CODE>set</CODE> method for the jpaEntityType property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ *
+ * <pre>
+ * getJPAEntityType().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list {@link JPAEntityTypeMapType }
+ *
+ *
+ */
+ public List<JPAEntityTypeMapType> getJPAEntityType() {
+ if (jpaEntityType == null) {
+ jpaEntityType = new ArrayList<JPAEntityTypeMapType>();
+ }
+ return jpaEntityType;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAPersistenceUnitMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAPersistenceUnitMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAPersistenceUnitMapType.java
new file mode 100644
index 0000000..22260ea
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPAPersistenceUnitMapType.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+/**
+ *
+ * By default Java Persistence Unit name is taken as EDM schema name. This can
+ * be overriden using JPAPersistenceUnitMapType.
+ *
+ *
+ * <p>
+ * Java class for JPAPersistenceUnitMapType complex type.
+ *
+ * <p>
+ * The following schema fragment specifies the expected content contained within
+ * this class.
+ *
+ * <pre>
+ * <complexType name="JPAPersistenceUnitMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="EDMSchemaNamespace" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ * <element name="JPAEntityTypes"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAEntityTypesMapType"/>
+ * <element name="JPAEmbeddableTypes"
+ * type="{http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping}JPAEmbeddableTypesMapType"/>
+ * </sequence>
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPAPersistenceUnitMapType",
+ propOrder = { "edmSchemaNamespace", "jpaEntityTypes", "jpaEmbeddableTypes" })
+public class JPAPersistenceUnitMapType {
+
+ @XmlElement(name = "EDMSchemaNamespace")
+ protected String edmSchemaNamespace;
+ @XmlElement(name = "JPAEntityTypes", required = true)
+ protected JPAEntityTypesMapType jpaEntityTypes;
+ @XmlElement(name = "JPAEmbeddableTypes", required = true)
+ protected JPAEmbeddableTypesMapType jpaEmbeddableTypes;
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+
+ /**
+ * Gets the value of the edmSchemaNamespace property.
+ *
+ * @return possible object is {@link String }
+ *
+ */
+ public String getEDMSchemaNamespace() {
+ return edmSchemaNamespace;
+ }
+
+ /**
+ * Sets the value of the edmSchemaNamespace property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setEDMSchemaNamespace(final String value) {
+ edmSchemaNamespace = value;
+ }
+
+ /**
+ * Gets the value of the jpaEntityTypes property.
+ *
+ * @return possible object is {@link JPAEntityTypesMapType }
+ *
+ */
+ public JPAEntityTypesMapType getJPAEntityTypes() {
+ return jpaEntityTypes;
+ }
+
+ /**
+ * Sets the value of the jpaEntityTypes property.
+ *
+ * @param value
+ * allowed object is {@link JPAEntityTypesMapType }
+ *
+ */
+ public void setJPAEntityTypes(final JPAEntityTypesMapType value) {
+ jpaEntityTypes = value;
+ }
+
+ /**
+ * Gets the value of the jpaEmbeddableTypes property.
+ *
+ * @return possible object is {@link JPAEmbeddableTypesMapType }
+ *
+ */
+ public JPAEmbeddableTypesMapType getJPAEmbeddableTypes() {
+ return jpaEmbeddableTypes;
+ }
+
+ /**
+ * Sets the value of the jpaEmbeddableTypes property.
+ *
+ * @param value
+ * allowed object is {@link JPAEmbeddableTypesMapType }
+ *
+ */
+ public void setJPAEmbeddableTypes(final JPAEmbeddableTypesMapType value) {
+ jpaEmbeddableTypes = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return possible object is {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setName(final String value) {
+ name = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPARelationshipMapType.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPARelationshipMapType.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPARelationshipMapType.java
new file mode 100644
index 0000000..25a2f95
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/JPARelationshipMapType.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * 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.odata2.jpa.processor.api.model.mapping;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+/**
+ *
+ * The default name for EDM navigation property is derived from JPA relationship
+ * name. This can be overriden using JPARelationshipMapType.
+ *
+ *
+ * <p>
+ * Java class for JPARelationshipMapType complex type.
+ *
+ * <p>
+ * The following schema fragment specifies the expected content contained within
+ * this class.
+ *
+ * <pre>
+ * <complexType name="JPARelationshipMapType">
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element name="JPARelationship" maxOccurs="unbounded" minOccurs="0">
+ * <complexType>
+ * <simpleContent>
+ * <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </extension>
+ * </simpleContent>
+ * </complexType>
+ * </element>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "JPARelationshipMapType", propOrder = { "jpaRelationship" })
+public class JPARelationshipMapType {
+
+ @XmlElement(name = "JPARelationship")
+ protected List<JPARelationshipMapType.JPARelationship> jpaRelationship;
+
+ /**
+ * Gets the value of the jpaRelationship property.
+ *
+ * <p>
+ * This accessor method returns a reference to the live list, not a
+ * snapshot. Therefore any modification you make to the returned list will
+ * be present inside the JAXB object. This is why there is not a
+ * <CODE>set</CODE> method for the jpaRelationship property.
+ *
+ * <p>
+ * For example, to add a new item, do as follows:
+ *
+ * <pre>
+ * getJPARelationship().add(newItem);
+ * </pre>
+ *
+ *
+ * <p>
+ * Objects of the following type(s) are allowed in the list {@link JPARelationshipMapType.JPARelationship }
+ *
+ *
+ */
+ public List<JPARelationshipMapType.JPARelationship> getJPARelationship() {
+ if (jpaRelationship == null) {
+ jpaRelationship = new ArrayList<JPARelationshipMapType.JPARelationship>();
+ }
+ return jpaRelationship;
+ }
+
+ /**
+ * <p>
+ * Java class for anonymous complex type.
+ *
+ * <p>
+ * The following schema fragment specifies the expected content contained
+ * within this class.
+ *
+ * <pre>
+ * <complexType>
+ * <simpleContent>
+ * <extension base="<http://www.w3.org/2001/XMLSchema>string">
+ * <attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ * </extension>
+ * </simpleContent>
+ * </complexType>
+ * </pre>
+ *
+ *
+ */
+ @XmlAccessorType(XmlAccessType.FIELD)
+ @XmlType(name = "", propOrder = { "value" })
+ public static class JPARelationship {
+
+ @XmlValue
+ protected String value;
+ @XmlAttribute(name = "name", required = true)
+ protected String name;
+
+ /**
+ * Gets the value of the value property.
+ *
+ * @return possible object is {@link String }
+ *
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Sets the value of the value property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setValue(final String value) {
+ this.value = value;
+ }
+
+ /**
+ * Gets the value of the name property.
+ *
+ * @return possible object is {@link String }
+ *
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the value of the name property.
+ *
+ * @param value
+ * allowed object is {@link String }
+ *
+ */
+ public void setName(final String value) {
+ name = value;
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/package-info.java
new file mode 100644
index 0000000..45a7c3f
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/mapping/package-info.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library - Mapping Model</h3>
+ * The JPA EDM Mapping model (XML document) is represented as JAXB annotated Java Classes.
+ *
+ *
+ */
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping",
+ elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.olingo.odata2.jpa.processor.api.model.mapping;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/package-info.java
new file mode 100644
index 0000000..c519179
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/model/package-info.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library - JPA EDM Model</h3>
+ * The library provides a set of views over the JPA/EDM element containers.
+ * The views can used to access the elements that form EDM.
+ *
+ *
+ */
+package org.apache.olingo.odata2.jpa.processor.api.model;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/package-info.java
new file mode 100644
index 0000000..7cafb84
--- /dev/null
+++ b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/jpa/processor/api/package-info.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.
+ ******************************************************************************/
+/**
+ * <h3>OData JPA Processor API Library</h3>
+ * The library provides a way for the developers to create an OData Service from a Java Persistence Model.
+ * The library supports Java Persistence 2.0 and is dependent on OData library.
+ *
+ * To create an OData service from JPA models
+ * <ol><li>extend the service factory class {@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory}
+ * and implement the methods</li>
+ * <li>define a JAX-RS servlet in web.xml and configure the service factory as servlet init parameter.
+ * <p><b>See Also:</b>{@link org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory}</li></ol>
+ *
+ *
+ */
+package org.apache.olingo.odata2.jpa.processor.api;
+
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAContext.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAContext.java
deleted file mode 100644
index 9974434..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAContext.java
+++ /dev/null
@@ -1,206 +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.odata2.processor.api.jpa;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension;
-
-/**
- * This class does the compilation of context objects required for OData JPA
- * Runtime. The context object should be properly initialized with values else
- * the behavior of processor and EDM provider can result in exception.
- *
- * Following are the mandatory parameter to be set into the context object
- * <ol>
- * <li>Persistence Unit Name</li>
- * <li>An instance of Java Persistence Entity Manager Factory</li>
- * </ol>
- *
- * <br>
- * @org.apache.olingo.odata2.DoNotImplement
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory
- * @see org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAAccessFactory
- *
- */
-public interface ODataJPAContext {
-
- /**
- * The method gets the Java Persistence Unit Name set into the context.
- *
- * @return Java Persistence Unit Name
- */
- public String getPersistenceUnitName();
-
- /**
- * The method sets the Java Persistence Unit Name into the context.
- *
- * @param pUnitName
- * is the Java Persistence Unit Name.
- *
- */
- public void setPersistenceUnitName(String pUnitName);
-
- /**
- * The method gets the OData Processor for JPA from the context.
- *
- * @return OData JPA Processor
- */
- public ODataProcessor getODataProcessor();
-
- /**
- * The method sets the OData Processor for JPA into the context.
- *
- * @param processor
- * is the specific implementation of {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAProcessor} for
- * processing OData service requests.
- */
- public void setODataProcessor(ODataProcessor processor);
-
- /**
- * The method gets the EDM provider for JPA from the context.
- *
- * @return EDM provider
- */
- public EdmProvider getEdmProvider();
-
- /**
- * The method sets EDM provider into the context
- *
- * @param edmProvider
- * is the specific implementation of {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider} for
- * transforming Java persistence models to Entity Data Model
- *
- */
- public void setEdmProvider(EdmProvider edmProvider);
-
- /**
- * The method gets the Java Persistence Entity Manager factory from the
- * context. <br>
- * <b>CAUTION:-</b> Don't use the Entity Manager Factory to instantiate
- * Entity Managers. Instead get reference to Entity Manager using
- * {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext#getEntityManager()}
- *
- * @return an instance of Java Persistence Entity Manager Factory
- */
- public EntityManagerFactory getEntityManagerFactory();
-
- /**
- * The method sets the Java Persistence Entity Manager factory into the
- * context.
- *
- * @param emf
- * is of type {@link javax.persistence.EntityManagerFactory}
- *
- */
- public void setEntityManagerFactory(EntityManagerFactory emf);
-
- /**
- * The method gets OData Context into the context.
- *
- * @return OData Context
- */
- public ODataContext getODataContext();
-
- /**
- * The method sets OData context into the context.
- *
- * @param ctx
- * is an OData context of type {@link org.apache.olingo.odata2.api.processor.ODataContext}
- */
- public void setODataContext(ODataContext ctx);
-
- /**
- * The method sets the JPA EDM mapping model name into the context. JPA EDM
- * mapping model is an XML document based on JPAEDMMappingModel.xsd
- *
- * @param name
- * is the name of JPA EDM mapping model
- */
- public void setJPAEdmMappingModel(String name);
-
- /**
- * The method gets the JPA EDM mapping model name from the context.
- *
- * @return name of JPA EDM mapping model
- */
- public String getJPAEdmMappingModel();
-
- /**
- * The method returns an instance of type entity manager. The entity manager
- * thus returns a single persistence context for the current OData request.
- * Hence all entities that are accessed within JPA processor are managed by
- * single entity manager.
- *
- * @return an instance of type {@link javax.persistence.EntityManager}
- */
- public EntityManager getEntityManager();
-
- /**
- * The method sets the JPA Edm Extension instance into the context. There
- * can be at most only one extension for a context. Invoking the method
- * several times overwrites already set extension instance in the context.
- *
- * @param jpaEdmExtension
- * is an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmExtension}
- *
- */
- public void setJPAEdmExtension(JPAEdmExtension jpaEdmExtension);
-
- /**
- * The method returns the JPA Edm Extension instance set into the context.
- *
- * @return an instance of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEmbeddableTypeMapType}
- */
- public JPAEdmExtension getJPAEdmExtension();
-
- /**
- * The method sets into the context whether the library should consider default naming for
- * <ul><li>EdmProperty</li>
- * <li>EdmComplexProperty</li>
- * <li>EdmNavigationProperty</li></ul>
- *
- * @param defaultNaming is a boolean value that indicates if set to
- * <ul><li>true - default naming is considered in case no mapping is provided.</li>
- * <li>false - default naming is not considered in case no mapping is provided. The
- * name provided in JPA Entity Model is considered.</li>
- * </ul>
- */
- public void setDefaultNaming(boolean defaultNaming);
-
- /**
- * The method returns whether the library should consider default naming for
- * <ul><li>EdmProperty</li>
- * <li>EdmComplexProperty</li>
- * <li>EdmNavigationProperty</li></ul>
- *
- * @return
- * <ul><li>true - default naming is considered in case no mapping is provided.</li>
- * <li>false - default naming is not considered in case no mapping is provided. The
- * name provided in JPA Entity Model is considered.</li>
- * </ul>
- */
- public boolean getDefaultNaming();
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAProcessor.java
deleted file mode 100644
index 441d38e..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAProcessor.java
+++ /dev/null
@@ -1,69 +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.odata2.processor.api.jpa;
-
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-
-/**
- * Extend this class and implement an OData JPA processor if the default
- * behavior of OData JPA Processor library has to be overwritten.
- *
- *
- *
- *
- */
-public abstract class ODataJPAProcessor extends ODataSingleProcessor {
-
- /**
- * An instance of {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext} object
- */
- protected ODataJPAContext oDataJPAContext;
-
- /**
- * An instance of {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor}. The
- * instance is created using {@link org.apache.olingo.odata2.processor.api.jpa.factory.JPAAccessFactory}.
- */
- protected JPAProcessor jpaProcessor;
-
- public ODataJPAContext getOdataJPAContext() {
- return oDataJPAContext;
- }
-
- public void setOdataJPAContext(final ODataJPAContext odataJPAContext) {
- oDataJPAContext = odataJPAContext;
- }
-
- /**
- * Constructor
- *
- * @param oDataJPAContext
- * non null OData JPA Context object
- */
- public ODataJPAProcessor(final ODataJPAContext oDataJPAContext) {
- if (oDataJPAContext == null) {
- throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL);
- }
- this.oDataJPAContext = oDataJPAContext;
- jpaProcessor = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAProcessor(this.oDataJPAContext);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAServiceFactory.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAServiceFactory.java
deleted file mode 100644
index 4968107..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/ODataJPAServiceFactory.java
+++ /dev/null
@@ -1,190 +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.odata2.processor.api.jpa;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAErrorCallback;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAAccessFactory;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-
-/**
- * <p>
- * Extend this factory class and create own instance of {@link org.apache.olingo.odata2.api.ODataService} that
- * transforms Java Persistence
- * Models into an OData Service. The factory class instantiates instances of
- * type {@link org.apache.olingo.odata2.api.edm.provider.EdmProvider} and
- * {@link org.apache.olingo.odata2.api.processor.ODataSingleProcessor}. The OData
- * JPA Processor library provides a default implementation for EdmProvider and
- * OData Single Processor.
- * </p>
- * <p>
- * The factory implementation is passed as servlet init parameter to a JAX-RS
- * runtime which will instantiate a {@link org.apache.olingo.odata2.api.ODataService} implementation using this factory.
- * </p>
- *
- * <p>
- * <b>Mandatory:</b> Implement the abstract method initializeODataJPAContext. Fill
- * {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext} with context
- * values.
- * </p>
- *
- * <b>Sample Configuration:</b>
- *
- * <pre> {@code
- * <servlet>
- * <servlet-name>ReferenceScenarioServlet</servlet-name>
- * <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
- * <init-param>
- * <param-name>javax.ws.rs.Application</param-name>
- * <param-value>org.apache.olingo.odata2.core.rest.ODataApplication</param-value>
- * </init-param>
- * <init-param>
- * <param-name>org.apache.olingo.odata2.processor.factory</param-name>
- * <param-value>foo.bar.sample.processor.SampleProcessorFactory</param-value>
- * </init-param>
- * <init-param>
- * <param-name>org.apache.olingo.odata2.path.split</param-name>
- * <param-value>2</param-value>
- * </init-param>
- * <load-on-startup>1</load-on-startup>
- * </servlet>
- * } </pre>
- */
-
-public abstract class ODataJPAServiceFactory extends ODataServiceFactory {
-
- private ODataJPAContext oDataJPAContext;
- private ODataContext oDataContext;
- private boolean setDetailErrors = false;
-
- /**
- * Creates an OData Service based on the values set in
- * {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext} and
- * {@link org.apache.olingo.odata2.api.processor.ODataContext}.
- */
- @Override
- public final ODataService createService(final ODataContext ctx) throws ODataException {
-
- oDataContext = ctx;
-
- // Initialize OData JPA Context
- oDataJPAContext = initializeODataJPAContext();
-
- validatePreConditions();
-
- ODataJPAFactory factory = ODataJPAFactory.createFactory();
- ODataJPAAccessFactory accessFactory = factory.getODataJPAAccessFactory();
-
- // OData JPA Processor
- if (oDataJPAContext.getODataContext() == null) {
- oDataJPAContext.setODataContext(ctx);
- }
-
- ODataSingleProcessor odataJPAProcessor = accessFactory.createODataProcessor(oDataJPAContext);
-
- // OData Entity Data Model Provider based on JPA
- EdmProvider edmProvider = accessFactory.createJPAEdmProvider(oDataJPAContext);
-
- return createODataSingleProcessorService(edmProvider, odataJPAProcessor);
- }
-
- private void validatePreConditions() throws ODataJPARuntimeException {
-
- if (oDataJPAContext.getEntityManagerFactory() == null) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ENTITY_MANAGER_NOT_INITIALIZED, null);
- }
-
- }
-
- /**
- * Implement this method and initialize OData JPA Context. It is mandatory
- * to set an instance of type {@link javax.persistence.EntityManagerFactory} into the context. An exception of type
- * {@link org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException} is thrown if
- * EntityManagerFactory is not initialized. <br>
- * <br>
- * <b>Sample Code:</b> <code>
- * <p>public class JPAReferenceServiceFactory extends ODataJPAServiceFactory{</p>
- *
- * <blockquote>private static final String PUNIT_NAME = "punit";
- * <br>
- * public ODataJPAContext initializeODataJPAContext() {
- * <blockquote>ODataJPAContext oDataJPAContext = this.getODataJPAContext();
- * <br>
- * EntityManagerFactory emf = Persistence.createEntityManagerFactory(PUNIT_NAME);
- * <br>
- * oDataJPAContext.setEntityManagerFactory(emf);
- * oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
- * <br> return oDataJPAContext;</blockquote>
- * }</blockquote>
- * } </code>
- * <p>
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext}
- * @throws ODataJPARuntimeException
- */
- public abstract ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException;
-
- /**
- * @return an instance of type {@link ODataJPAContext}
- * @throws ODataJPARuntimeException
- */
- public final ODataJPAContext getODataJPAContext() throws ODataJPARuntimeException {
- if (oDataJPAContext == null) {
- oDataJPAContext = ODataJPAFactory.createFactory().getODataJPAAccessFactory().createODataJPAContext();
- }
- if (oDataContext != null) {
- oDataJPAContext.setODataContext(oDataContext);
- }
- return oDataJPAContext;
-
- }
-
- /**
- * The method sets the context whether a detail error message should be thrown
- * or a less detail error message should be thrown by the library.
- * @param setDetailErrors takes
- * <ul><li>true - to indicate that library should throw a detailed error message</li>
- * <li>false - to indicate that library should not throw a detailed error message</li>
- * </ul>
- *
- */
- protected void setDetailErrors(final boolean setDetailErrors) {
- this.setDetailErrors = setDetailErrors;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
- if (setDetailErrors == true) {
- if (callbackInterface.isAssignableFrom(ODataErrorCallback.class)) {
- return (T) new ODataJPAErrorCallback();
- }
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmBuilder.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmBuilder.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmBuilder.java
deleted file mode 100644
index 110a1f1..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmBuilder.java
+++ /dev/null
@@ -1,57 +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.odata2.processor.api.jpa.access;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-
-/**
- * JPAEdmBuilder interface provides methods for building elements of an Entity Data Model (EDM) from
- * a Java Persistence Model.
- *
- *
- *
- */
-public interface JPAEdmBuilder {
- /**
- * The Method builds EDM Elements by transforming JPA MetaModel. The method
- * processes EDM JPA Containers which could be accessed using the following
- * views,
- * <ul>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationSetView} </li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmBaseView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexPropertyView} </li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView} </li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmModelView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmNavigationPropertyView} </li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmPropertyView}</li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintRoleView} </li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView} </li>
- * <li> {@link org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmSchemaView}</li>
- * </ul>
- *
- * @throws ODataJPARuntimeException
- **/
- public void build() throws ODataJPAModelException, ODataJPARuntimeException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmMappingModelAccess.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmMappingModelAccess.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmMappingModelAccess.java
deleted file mode 100644
index 216db55..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAEdmMappingModelAccess.java
+++ /dev/null
@@ -1,191 +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.odata2.processor.api.jpa.access;
-
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEdmMappingModel;
-
-/**
- * Interface provides methods to access JPA EDM mapping model.
- *
- *
- * @see JPAEdmMappingModel
- *
- */
-public interface JPAEdmMappingModelAccess {
-
- /**
- * The method searches and loads the mapping model stored in <file>.xml
- * file into the java object {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEdmMappingModel} . The
- * name of the file is set into ODataJPAContext method.
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext#setJPAEdmMappingModel(String)
- */
- public void loadMappingModel();
-
- /**
- * The method returns if there exists a mapping model.
- *
- * @return true - if there exists a mapping model for the OData service else
- * false
- */
- public boolean isMappingModelExists();
-
- /**
- * The method returns a JPA EDM mapping model Java object. The mapping model
- * in XML files is un-marshaled into the Java object.
- *
- * @return an instance of type {@link org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEdmMappingModel}
- */
- public JPAEdmMappingModel getJPAEdmMappingModel();
-
- /**
- * The method returns EDM Schema namespace for the persistence unit name
- *
- * @param persistenceUnitName
- * is the Java persistence unit name
- * @return EDM schema name space mapped to Java persistence unit name or
- * null if no mapping is available
- */
- public String mapJPAPersistenceUnit(String persistenceUnitName);
-
- /**
- * The method returns EDM entity type name for the Java persistence entity
- * type name
- *
- * @param jpaEntityTypeName
- * is the Java persistence entity type name
- * @return EDM entity type name mapped to Java persistence entity type name
- * or null if no mapping is available
- */
- public String mapJPAEntityType(String jpaEntityTypeName);
-
- /**
- * The method returns EDM entity set name for the Java persistence entity
- * type name
- *
- * @param jpaEntityTypeName
- * is the Java persistence entity type name
- * @return EDM entity set name mapped to Java persistence entity type name
- * or null if no mapping is available
- */
- public String mapJPAEntitySet(String jpaEntityTypeName);
-
- /**
- * The method returns EDM property name for the Java persistence entity
- * attribute name.
- *
- * @param jpaEntityTypeName
- * is the Java persistence entity type name
- * @param jpaAttributeName
- * is the Java persistence attribute name
- * @return EDM property name mapped to Java persistence attribute name or
- * null if no mapping is available
- */
- public String mapJPAAttribute(String jpaEntityTypeName, String jpaAttributeName);
-
- /**
- * The method returns EDM navigation property name for the Java persistence
- * entity relationship name.
- *
- * @param jpaEntityTypeName
- * is the Java persistence entity type name
- * @param jpaRelationshipName
- * is the Java persistence relationship name
- * @return EDM navigation property name mapped to Java persistence entity
- * relationship name or null if no mapping is available
- */
- public String mapJPARelationship(String jpaEntityTypeName, String jpaRelationshipName);
-
- /**
- * The method returns EDM complex type name for the Java embeddable type
- * name.
- *
- * @param jpaEmbeddableTypeName
- * is the Java persistence embeddable type name
- * @return EDM complex type name mapped to Java persistence entity
- * relationship name or null if no mapping is available
- */
- public String mapJPAEmbeddableType(String jpaEmbeddableTypeName);
-
- /**
- * The method returns EDM property name for the Java persistence embeddable
- * type's attribute name.
- *
- * @param jpaEmbeddableTypeName
- * is the Java persistence
- * @param jpaAttributeName
- * is the Java persistence attribute name
- * @return EDM property name mapped to Java persistence attribute name or
- * null if no mapping is available
- */
- public String mapJPAEmbeddableTypeAttribute(String jpaEmbeddableTypeName, String jpaAttributeName);
-
- /**
- * The method returns whether the JPA Entity should be excluded from EDM
- * model
- *
- * @param jpaEntityTypeName
- * is the name of JPA Entity Type
- * @return <b>true</b> - if JPA Entity should be excluded<br>
- * <b>false</b> - if JPA Entity should be not be excluded
- *
- */
- public boolean checkExclusionOfJPAEntityType(String jpaEntityTypeName);
-
- /**
- * The method returns whether the JPA Attribute should be excluded from EDM
- * Entity Type
- *
- * @param jpaEntityTypeName
- * is the name of JPA Entity Type
- * @param jpaAttributeName
- * is the name of JPA attribute
- * @return <b>true</b> - if JPA attribute should be excluded<br>
- * <b>false</b> - if JPA attribute should be not be excluded
- *
- */
- public boolean checkExclusionOfJPAAttributeType(String jpaEntityTypeName, String jpaAttributeName);
-
- /**
- * The method returns whether the JPA Embeddable Type should be excluded
- * from EDM model
- *
- * @param jpaEmbeddableTypeName
- * is the name of JPA Embeddable Type
- * @return <b>true</b> - if JPA Embeddable Type should be excluded<br>
- * <b>false</b> - if JPA Embeddable Type should be not be excluded
- *
- */
- public boolean checkExclusionOfJPAEmbeddableType(String jpaEmbeddableTypeName);
-
- /**
- * The method returns whether the JPA Embeddable Attribute Type should be
- * excluded from EDM model
- *
- * @param jpaEmbeddableTypeName
- * is the name of JPA Embeddable Attribute Type
- * @param jpaAttributeName
- * is the name of JPA Attribute name
- * @return <b>true</b> - if JPA Embeddable Attribute Type should be excluded<br>
- * <b>false</b> - if JPA Embeddable Attribute Type should be not be
- * excluded
- *
- */
- public boolean checkExclusionOfJPAEmbeddableAttributeType(String jpaEmbeddableTypeName, String jpaAttributeName);
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAFunction.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAFunction.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAFunction.java
deleted file mode 100644
index 648a09c..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAFunction.java
+++ /dev/null
@@ -1,85 +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.odata2.processor.api.jpa.access;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-
-/**
- * A container for JPA Functions. A JPA function can be
- * <ol>
- * <li>Property Access method</li>
- * <li>Custom Operation (Annotated with EDM Annotation FunctionImport)</li>
- * </ol>
- *
- *
- *
- */
-public class JPAFunction {
-
- private Method function;
- private Class<?>[] parameterTypes;
- private Type returnType;
- private Object[] args;
-
- public JPAFunction(final Method function, final Class<?>[] parameterTypes, final Type returnType,
- final Object[] args) {
- this.function = function;
- this.parameterTypes = parameterTypes;
- this.returnType = returnType;
- this.args = args;
- }
-
- /**
- * The method returns the Java method.
- *
- * @return an instance of {@link java.lang.reflect.Method}
- */
- public Method getFunction() {
- return function;
- }
-
- /**
- * The method returns the parameter types for the Java method.
- *
- * @return an array of type {@link java.lang.Class}
- */
- public Class<?>[] getParameterTypes() {
- return parameterTypes;
- }
-
- /**
- * The method returns the return type for the Java method.
- *
- * @return an instance of {@link java.lang.reflect.Type}
- */
- public Type getReturnType() {
- return returnType;
- }
-
- /**
- * The method returns an array of arguments for invoking the Java method.
- *
- * @return an array of Objects
- */
- public Object[] getArguments() {
- return args;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAJoinClause.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAJoinClause.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAJoinClause.java
deleted file mode 100644
index f0a4c8d..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAJoinClause.java
+++ /dev/null
@@ -1,148 +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.odata2.processor.api.jpa.access;
-
-/**
- * A container for Java Persistence Join Clause that can be used for building
- * JPQL statements. The container has two main elements <b>
- * <ol>
- * <li>Java Persistence Entity -</li> is the source entity participating in the
- * join. <br>
- * <li>Java Persistence Entity Relationship -</li> is the entity relationship of
- * the source entity participating in the join.
- * </ol>
- * </b>
- *
- *
- *
- */
-public class JPAJoinClause {
-
- /**
- * Enumerated list of possible Joins in JPQL
- * <ol>
- * <li>LEFT - left outer join</li>
- * <li>FETCH - enable fetching of an association as a side effect of the
- * execution of a query</li>
- * <li>INNER - inner join
- * </ol>
- *
- *
- *
- */
- public enum JOIN {
- LEFT, FETCH, INNER
- }
-
- private String entityName;
- private String entityAlias;
- private String entityRelationShip;
- private String entityRelationShipAlias;
- private JOIN joinType;
- private String joinCondition;
-
- /**
- * The method returns Java Persistence Entity participating in the join.
- *
- * @return an entity name
- */
- public String getEntityName() {
- return entityName;
- }
-
- /**
- * The method returns Java Persistence Entity alias name participating in
- * the join.
- *
- * @return a entity alias name
- */
- public String getEntityAlias() {
- return entityAlias;
- }
-
- /**
- * The method returns Java Persistence Entity Relationship name
- * participating in the join.
- *
- * @return entity alias relationship
- */
- public String getEntityRelationShip() {
- return entityRelationShip;
- }
-
- /**
- * The method returns Java Persistence Entity Relationship Alias name
- * participating in the join.
- *
- * @return entity entity relationship alias
- */
- public String getEntityRelationShipAlias() {
- return entityRelationShipAlias;
- }
-
- /**
- * Constructor for creating elements of JPA Join Clause container.
- *
- * @param entityName
- * is the name of the JPA entity participating in the join
- * @param entityAlias
- * is the alias for the JPA entity participating in the join
- * @param entityRelationShip
- * is the name of the JPA entity relationship participating in
- * the join
- * @param entityRelationShipAlias
- * is the alias name of the JPA entity relationship participating
- * in the join
- * @param joinCondition
- * is the condition on which the joins should occur
- * @param joinType
- * is the type of join {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause.JOIN} to execute
- */
- public JPAJoinClause(final String entityName, final String entityAlias, final String entityRelationShip,
- final String entityRelationShipAlias, final String joinCondition, final JOIN joinType) {
-
- this.entityName = entityName;
- this.entityAlias = entityAlias;
- this.entityRelationShip = entityRelationShip;
- this.entityRelationShipAlias = entityRelationShipAlias;
- this.joinCondition = joinCondition;
- this.joinType = joinType;
- }
-
- /**
- * The method returns a join condition that can be used for building JPQL
- * join statements.
- *
- * @return a join condition
- */
- public String getJoinCondition() {
- return joinCondition;
- }
-
- /**
- * The method returns the type of {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAJoinClause.JOIN} that
- * can be used for building JPQL join statements.
- *
- * @return join type
- */
- public JOIN getJoinType() {
- return joinType;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContext.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContext.java
deleted file mode 100644
index fd44200..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContext.java
+++ /dev/null
@@ -1,130 +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.odata2.processor.api.jpa.access;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-
-/**
- * The abstract class is a compilation of objects required for building specific
- * instances of JPA Method Context. Extend this class to implement specific
- * implementations of JPQL context types (Create,Update,Function). A JPA method
- * Context is constructed from an OData request. Depending on OData
- * CUD/FunctionImport operation performed on an Entity, a corresponding JPA
- * method context object is built. The object thus built can be used for
- * executing operations on JPA Entity/Custom processor objects. <br>
- * A default implementation is provided by the library.
- *
- *
- * @see org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContextView
- * @see org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType
- *
- */
-
-public abstract class JPAMethodContext implements JPAMethodContextView {
-
- protected Object enclosingObject;
- protected ArrayList<JPAFunction> jpaFunction;
-
- @Override
- /**
- * The method returns list of JPA functions that can be executed on the
- * enclosing object.
- *
- * @return an instance of list of JPA Function
- */
- public Object getEnclosingObject() {
- return enclosingObject;
- }
-
- @Override
- /**
- * The method returns list of JPA functions that can be executed on the
- * enclosing object.
- *
- * @return an instance of list of JPA Function
- */
- public List<JPAFunction> getJPAFunctionList() {
- return jpaFunction;
- }
-
- protected void setEnclosingObject(final Object enclosingObject) {
- this.enclosingObject = enclosingObject;
- }
-
- protected void setJpaFunction(final List<JPAFunction> jpaFunctionList) {
- jpaFunction = (ArrayList<JPAFunction>) jpaFunctionList;
- }
-
- /**
- * the method instantiates an instance of type JPAMethodContextBuilder.
- *
- * @param contextType
- * indicates the type of JPQLContextBuilder to instantiate.
- * @param resultsView
- * is the OData request view
- * @return {@link org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext.JPAMethodContextBuilder}
- *
- * @throws ODataJPARuntimeException
- */
- public final static JPAMethodContextBuilder
- createBuilder(final JPQLContextType contextType, final Object resultsView) throws ODataJPARuntimeException {
- return JPAMethodContextBuilder.create(contextType, resultsView);
- }
-
- /**
- * The abstract class is extended by specific JPA Method Context Builder to
- * build JPA Method Context types.
- *
- *
- *
- */
- public static abstract class JPAMethodContextBuilder {
-
- /**
- * Implement this method to build JPAMethodContext
- *
- * @return an instance of type JPAMethodContext
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public abstract JPAMethodContext build() throws ODataJPAModelException, ODataJPARuntimeException;
-
- protected JPAMethodContextBuilder() {}
-
- private static JPAMethodContextBuilder create(final JPQLContextType contextType, final Object resultsView)
- throws ODataJPARuntimeException {
- JPAMethodContextBuilder contextBuilder =
- ODataJPAFactory.createFactory().getJPQLBuilderFactory().getJPAMethodContextBuilder(contextType);
-
- if (contextBuilder == null) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.ERROR_JPQLCTXBLDR_CREATE, null);
- }
- contextBuilder.setResultsView(resultsView);
- return contextBuilder;
- }
-
- protected abstract void setResultsView(Object resultsView);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContextView.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContextView.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContextView.java
deleted file mode 100644
index fb057a0..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAMethodContextView.java
+++ /dev/null
@@ -1,46 +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.odata2.processor.api.jpa.access;
-
-import java.util.List;
-
-/**
- * The interface provides view on JPA Method Context. JPA Method context can be
- * used to access custom operations or JPA Entity property access methods.
- *
- *
- *
- */
-public interface JPAMethodContextView {
- /**
- * The method returns an instance of Object on which the methods/custom
- * operations can be executed.
- *
- * @return instance of enclosing object for the method
- */
- public Object getEnclosingObject();
-
- /**
- * The method returns list of JPA functions that can be executed on the
- * enclosing object.
- *
- * @return an instance of list of JPA Function
- */
- public List<JPAFunction> getJPAFunctionList();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAProcessor.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAProcessor.java
deleted file mode 100644
index af9b77d..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/JPAProcessor.java
+++ /dev/null
@@ -1,260 +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.odata2.processor.api.jpa.access;
-
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-
-/**
- * The interface provides methods for processing OData Requests for Create, Read, Update, Delete operations.
- * Pass the OData request or parsed OData request (Map of properties) as request.
- * A JPA entity is returned as a response.
- *
- */
-public interface JPAProcessor {
- /**
- * Processes OData request for querying an Entity Set. The method returns
- * list of Objects of type representing JPA Entity Types.
- *
- * @param <T>
- * Template parameter representing Java Persistence Entity Type.
- * <p>
- * <b>Note:-</b> Default parameter is Object.
- * </p>
- *
- * @param requestView
- * is an OData request for querying an entity set
- * <p>
- * @return list of objects representing JPA entity types
- **/
- public <T> List<T> process(GetEntitySetUriInfo requestView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for reading an Entity. The method returns an
- * Object of type representing JPA Entity Type.
- *
- * @param <T>
- * Template parameter representing Java Persistence Entity Type.
- * <p>
- * <b>Note:-</b> Default parameter is Object.
- * </p>
- *
- * @param requestView
- * OData request for reading an entity
- *
- * <p>
- * @return object representing JPA entity type
- **/
- public <T> Object process(GetEntityUriInfo requestView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for fetching Entity count. The method returns JPA Entity count
- *
- * @param requestView
- * OData request for counting an entity set
- * @return long value representing count of JPA entity set
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
-
- public long process(GetEntitySetCountUriInfo requestView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for fetching Entity count. The method returns count of target entity.
- * This is specific to situation where cardinality is 1:1
- *
- * @param resultsView
- * OData request for counting target entity.
- * @return long value representing count of JPA entity
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public long process(GetEntityCountUriInfo resultsView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for executing custom operations. The method
- * returns a List of Object. The list contains one entry if the the custom
- * operations return type has multiplicity of ONE.
- *
- * @param requestView
- * OData request for executing function import
- * @return result of executing function import
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public List<Object> process(GetFunctionImportUriInfo requestView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for executing $links OData command for N:1 relation.
- * The method returns an Object of type representing OData entity.
- *
- * @param uriParserResultView
- * OData request for Entity Link URI
- * @return an object representing JPA entity
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public Object process(GetEntityLinkUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for executing $links OData command for N:1 relation.
- * The method returns an Object of type representing OData entity.
- *
- * @param uriParserResultView
- * OData request for Entity Set Link URI
- * @return a list of object representing JPA entities
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public <T> List<T> process(GetEntitySetLinksUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for creating Entity. The method returns an Object
- * which is created. A Null reference implies object was not created.
- *
- * @param createView
- * @param content
- * @param requestContentType
- * @return Created Object
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
-
- public <T> List<T> process(PostUriInfo createView, InputStream content,
- String requestContentType) throws ODataJPAModelException,
- ODataJPARuntimeException;
-
- /**
- * Processes OData request for creating Entity. The method expects a parsed OData request which is a Map of
- * properties.
- * The method returns an Object that is created. A Null reference implies object was not created.
- *
- * @param createView
- * @param content
- * @return Created Object
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
-
- public <T> List<T> process(PostUriInfo createView, Map<String, Object> content) throws ODataJPAModelException,
- ODataJPARuntimeException;
-
- /**
- * Processes OData request for updating Entity. The method returns an Object
- * which is updated. A Null reference implies object was not created.
- *
- * @param updateView
- * @param content
- * @param requestContentType
- * @return Deleted Object
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public <T> Object process(PutMergePatchUriInfo updateView,
- InputStream content, String requestContentType)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for updating Entity. The method returns an Object
- * which is updated. A Null reference implies object was not created.
- *
- * @param updateView
- * @param content
- * @return Deleted Object
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public <T> Object process(PutMergePatchUriInfo updateView, Map<String, Object> content)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Processes OData request for deleting Entity. The method returns an Object
- * which is deleted. A Null reference implies object was not created.
- *
- * @param deleteuriInfo
- * @param contentType
- * @return Deleted Object
- *
- * @throws ODataJPAModelException
- * @throws ODataJPARuntimeException
- */
- public Object process(DeleteUriInfo deleteuriInfo, String contentType)
- throws ODataJPAModelException, ODataJPARuntimeException;
-
- /**
- * Process OData request for creating Links. The OData request should contain
- * $links OData command.
- *
- * @param uriParserResultView
- * OData request for creating Links
- * @param content
- * @param requestContentType
- * @param contentType
- *
- * @throws ODataJPARuntimeException
- * @throws ODataJPAModelException
- */
- public void process(PostUriInfo uriParserResultView,
- InputStream content, String requestContentType, String contentType)
- throws ODataJPARuntimeException, ODataJPAModelException;
-
- /**
- * Process OData request for updating Links. The OData request should contain
- * $links OData command.
- *
- * @param uriParserResultView
- * OData request for updating Links
- * @param content
- * @param requestContentType
- * @param contentType
- *
- * @throws ODataJPARuntimeException
- * @throws ODataJPAModelException
- */
- public void process(PutMergePatchUriInfo uriParserResultView,
- InputStream content, String requestContentType, String contentType)
- throws ODataJPARuntimeException, ODataJPAModelException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/package-info.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/package-info.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/package-info.java
deleted file mode 100644
index 38671c1..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/access/package-info.java
+++ /dev/null
@@ -1,26 +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.
- ******************************************************************************/
-/**
- * <h3>OData JPA Processor API Library - Java Persistence Access</h3>
- * The library provides a set of APIs to access Java Persistence Models and Data.
- *
- *
- */
-package org.apache.olingo.odata2.processor.api.jpa.access;
-
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAErrorCallback.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAErrorCallback.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAErrorCallback.java
deleted file mode 100644
index 9f78af0..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAErrorCallback.java
+++ /dev/null
@@ -1,45 +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.odata2.processor.api.jpa.exception;
-
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
-import org.apache.olingo.odata2.api.processor.ODataErrorContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-
-public class ODataJPAErrorCallback implements ODataErrorCallback {
-
- @Override
- public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
-
- final String SEPARATOR = " : ";
-
- Throwable t = context.getException();
- if (t instanceof ODataJPAException) {
- StringBuilder errorBuilder = new StringBuilder();
- errorBuilder.append(t.getCause().getClass().toString());
- errorBuilder.append(SEPARATOR);
- errorBuilder.append(t.getCause().getMessage());
- context.setInnerError(errorBuilder.toString());
- }
- return EntityProvider.writeErrorDocument(context);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAException.java b/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAException.java
deleted file mode 100644
index 3347ee0..0000000
--- a/odata2-jpa-processor/jpa-api/src/main/java/org/apache/olingo/odata2/processor/api/jpa/exception/ODataJPAException.java
+++ /dev/null
@@ -1,68 +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.odata2.processor.api.jpa.exception;
-
-import java.util.Locale;
-
-import org.apache.olingo.odata2.api.exception.MessageReference;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-/**
- * The exception class is the base of OData JPA exceptions. The class also
- * provides non localized error texts that can be used for raising OData JPA
- * exceptions with non localized error texts.
- *
- *
- *
- */
-public abstract class ODataJPAException extends ODataException {
-
- protected MessageReference messageReference;
-
- public static final String ODATA_JPACTX_NULL = "OData JPA Context cannot be null";
-
- private static final long serialVersionUID = -6884673558124441214L;
- protected static final Locale DEFAULT_LOCALE = Locale.ENGLISH;
-
- protected ODataJPAException(final String localizedMessage, final Throwable e, final MessageReference msgRef) {
- super(localizedMessage, e);
- messageReference = msgRef;
- }
-
- /**
- * The method creates a Reference to Message Object {@link org.apache.olingo.odata2.api.exception.MessageReference} .
- * The message
- * text key is derived out of parameters clazz.messageReferenceKey.
- *
- * @param clazz
- * is name of the class extending {@link org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAException}
- * @param messageReferenceKey
- * is the key of the message
- * @return an instance of type {@link org.apache.olingo.odata2.api.exception.MessageReference}
- */
- protected static MessageReference createMessageReference(final Class<? extends ODataJPAException> clazz,
- final String messageReferenceKey) {
- return MessageReference.create(clazz, messageReferenceKey);
- }
-
- public MessageReference getMessageReference() {
- return messageReference;
- }
-
-}
[07/47] git commit: [OLINGO-86] Created all positive tests for DS
Posted by tb...@apache.org.
[OLINGO-86] Created all positive tests for DS
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/1ce2c877
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/1ce2c877
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/1ce2c877
Branch: refs/heads/ODataServlet
Commit: 1ce2c8776a688d056fc35f3096f777041aaa6aa9
Parents: 78da059
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Dec 23 13:29:08 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Dec 23 13:29:08 2013 +0100
----------------------------------------------------------------------
.../processor/core/util/AnnotationHelper.java | 26 +-
.../datasource/AnnotationsInMemoryDsTest.java | 60 ++++-
.../core/util/AnnotationHelperTest.java | 270 +++++++++++++++++++
3 files changed, 348 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1ce2c877/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
index 807b6fe..54ffb49 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelper.java
@@ -63,6 +63,11 @@ public class AnnotationHelper {
Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
+ if(firstKeyFields.isEmpty() && secondKeyFields.isEmpty()) {
+ throw new ODataRuntimeException("Both object instances does not have EdmKey fields defined ["
+ + "firstClass=" + firstInstance.getClass().getName()
+ + " secondClass=" + secondInstance.getClass().getName() + "].");
+ }
return keyValuesMatch(firstKeyFields, secondKeyFields);
}
@@ -82,6 +87,8 @@ public class AnnotationHelper {
private boolean keyValuesMatch(final Map<String, Object> firstKeyValues, final Map<String, Object> secondKeyValues) {
if (firstKeyValues.size() != secondKeyValues.size()) {
return false;
+ } else if(firstKeyValues.isEmpty()) {
+ throw new ODataRuntimeException("No keys given for key value matching.");
} else {
Set<Map.Entry<String, Object>> entries = firstKeyValues.entrySet();
for (Map.Entry<String, Object> entry : entries) {
@@ -498,8 +505,7 @@ public class AnnotationHelper {
for (Field field : fields) {
if (field.getAnnotation(annotation) != null) {
Object value = getFieldValue(instance, field);
- final EdmProperty property = field.getAnnotation(EdmProperty.class);
- final String name = property == null || property.name().isEmpty() ? field.getName() : property.name();
+ final String name = extractPropertyName(field);
fieldName2Value.put(name, value);
}
}
@@ -513,6 +519,15 @@ public class AnnotationHelper {
return fieldName2Value;
}
+ private String extractPropertyName(Field field) {
+ final EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if(property == null || property.name().isEmpty()) {
+ return getCanonicalName(field);
+ } else {
+ return property.name();
+ }
+ }
+
public void setValueForAnnotatedField(final Object instance, final Class<? extends Annotation> annotation,
final Object value)
throws ODataAnnotationException {
@@ -641,7 +656,7 @@ public class AnnotationHelper {
}
}
- public Object convert(final Field field, final String propertyValue) {
+ private Object convert(final Field field, final String propertyValue) {
Class<?> fieldClass = field.getType();
try {
EdmProperty property = field.getAnnotation(EdmProperty.class);
@@ -649,8 +664,9 @@ public class AnnotationHelper {
return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
EdmLiteralKind.DEFAULT, null, fieldClass);
} catch (EdmSimpleTypeException ex) {
- throw new ODataRuntimeException("Conversion failed for string property with error: "
- + ex.getMessage(), ex);
+ throw new ODataRuntimeException("Conversion failed for string property ["
+ + propertyValue + "] on field ["
+ + field + "] with error: " + ex.getMessage(), ex);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1ce2c877/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
index b9ebcb3..cff39b9 100644
--- a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/datasource/AnnotationsInMemoryDsTest.java
@@ -25,9 +25,6 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.AnnotationInMemoryDs;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource;
-import org.apache.olingo.odata2.annotation.processor.core.datasource.DataStore;
import org.apache.olingo.odata2.annotation.processor.core.datasource.DataSource.BinaryData;
import org.apache.olingo.odata2.annotation.processor.core.edm.AnnotationEdmProvider;
import org.apache.olingo.odata2.annotation.processor.core.model.Building;
@@ -307,6 +304,26 @@ public class AnnotationsInMemoryDsTest {
}
}
+ @Test(expected=ODataRuntimeException.class)
+ public void readUnknownEntity() throws Exception {
+ EdmEntitySet unknownEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(unknownEntitySet.getName()).thenReturn("UnknownEntity");
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ // execute
+ datasource.readData(unknownEntitySet, keys);
+ }
+
+ @Test(expected=ODataRuntimeException.class)
+ public void readUnknownEntities() throws Exception {
+ EdmEntitySet unknownEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(unknownEntitySet.getName()).thenReturn("UnknownEntity");
+
+ // execute
+ datasource.readData(unknownEntitySet);
+ }
+
@Test
public void readEntities() throws Exception {
EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
@@ -608,6 +625,43 @@ public class AnnotationsInMemoryDsTest {
}
+ @Test
+ public void writeRelations() throws Exception {
+ DataStore<Building> buildingStore = DataStore.createInMemory(Building.class, true);
+ DataStore<Room> roomStore = DataStore.createInMemory(Room.class, true);
+
+ EdmEntitySet buildingsEntitySet = createMockedEdmEntitySet("Buildings");
+ EdmEntitySet roomsEntitySet = createMockedEdmEntitySet("Rooms");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ Building created = buildingStore.create(building);
+
+ Room room = new Room(42, "Room with Number");
+ room.setSeats(123);;
+ room.setVersion(4711);
+ roomStore.create(room);
+
+ Map<String, Object> targetEntityKeyValues = new HashMap<String, Object>();
+ targetEntityKeyValues.put("Id", 42);
+
+ // execute
+ datasource.writeRelation(buildingsEntitySet, building, roomsEntitySet, targetEntityKeyValues);
+
+ // validate
+ Building readBuilding = buildingStore.read(created);
+ Room readRoom = roomStore.read(new Room(42, ""));
+
+ List<Room> readRooms = readBuilding.getRooms();
+ Assert.assertEquals(1, readRooms.size());
+ Assert.assertEquals(readRoom, readRooms.get(0));
+
+ Assert.assertEquals("42", readRoom.getId());
+ Assert.assertEquals(123, readRoom.getSeats());
+ Assert.assertEquals(4711, readRoom.getVersion());
+ Assert.assertEquals(readBuilding, readRoom.getBuilding());
+ }
+
private EdmEntitySet createMockedEdmEntitySet(final String entitySetName) throws ODataException {
return createMockedEdmEntitySet(edmProvider, entitySetName);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1ce2c877/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
new file mode 100644
index 0000000..2e95f82
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/annotation/processor/core/util/AnnotationHelperTest.java
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed 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.odata2.annotation.processor.core.util;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.olingo.odata2.annotation.processor.core.model.Location;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AnnotationHelperTest {
+
+ private final AnnotationHelper annotationHelper;
+
+ public AnnotationHelperTest() {
+ annotationHelper = new AnnotationHelper();
+ }
+
+ @Test
+ public void keyMatchMapPositive() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity(42l, "Another Name");
+ Map<String, Object> keyName2Value = new HashMap<String, Object>();
+ keyName2Value.put("Id", Long.valueOf(42));
+
+ boolean result = annotationHelper.keyMatch(firstInstance, keyName2Value);
+
+ Assert.assertTrue(result);
+ }
+
+ @Test
+ public void keyMatchMapNegativeWrongClass() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity(42l, "Another Name");
+ Map<String, Object> keyName2Value = new HashMap<String, Object>();
+ keyName2Value.put("Id", 42);
+
+ boolean result = annotationHelper.keyMatch(firstInstance, keyName2Value);
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void keyMatchMapNegativeDifferentValues() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity(99l, "Another Name");
+ Map<String, Object> keyName2Value = new HashMap<String, Object>();
+ keyName2Value.put("Id", 42);
+
+ boolean result = annotationHelper.keyMatch(firstInstance, keyName2Value);
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void keyMatchMapNegativeDifferentValueCount() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity(99l, "Another Name");
+ Map<String, Object> keyName2Value = new HashMap<String, Object>();
+
+ boolean result = annotationHelper.keyMatch(firstInstance, keyName2Value);
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void keyMatchPositive() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity(42l, "A Name");
+ SimpleEntity secondInstance = new SimpleEntity(42l, "Another Name");
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+
+ Assert.assertTrue(result);
+ }
+
+ @Test
+ public void keyMatchPositiveWithNull() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity();
+ SimpleEntity secondInstance = new SimpleEntity();
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+
+ Assert.assertTrue(result);
+ }
+
+ @Test
+ public void keyMatchNegative() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity(99l, "A Name");
+ SimpleEntity secondInstance = new SimpleEntity(42l, "A Name");
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void keyMatchNegativeWithNull() throws ODataException {
+ SimpleEntity firstInstance = new SimpleEntity();
+ SimpleEntity secondInstance = new SimpleEntity(42l, "A Name");
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void keyMatchNegativeWithNullInstance() throws ODataException {
+ SimpleEntity firstInstance = null;
+ SimpleEntity secondInstance = new SimpleEntity(42l, "A Name");
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+ Assert.assertFalse(result);
+
+ result = annotationHelper.keyMatch(secondInstance, firstInstance);
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void keyMatchNegativeOneNotAnnotated() throws ODataException {
+ NotAnnotatedBean firstInstance = new NotAnnotatedBean();
+ SimpleEntity secondInstance = new SimpleEntity(42l, "A Name");
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+ Assert.assertFalse(result);
+
+ boolean result2 = annotationHelper.keyMatch(secondInstance, firstInstance);
+ Assert.assertFalse(result2);
+ }
+
+ @Test(expected = ODataRuntimeException.class)
+ public void keyMatchNegativeNotAnnotated() throws ODataException {
+ NotAnnotatedBean firstInstance = new NotAnnotatedBean();
+ NotAnnotatedBean secondInstance = new NotAnnotatedBean();
+
+ boolean result = annotationHelper.keyMatch(firstInstance, secondInstance);
+
+ Assert.assertFalse(result);
+ }
+
+ @Test
+ public void extractEntitTypeNameViaNavigation() throws Exception {
+ Field field = NavigationAnnotated.class.getDeclaredField("navigationPropertySimpleEntity");
+ EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
+
+ String name = annotationHelper.extractEntitTypeName(enp, SimpleEntity.class);
+
+ Assert.assertEquals("SimpleEntity", name);
+ }
+
+ @Test
+ public void extractEntitTypeNameViaNavigationField() throws Exception {
+ Field field = NavigationAnnotated.class.getDeclaredField("navigationPropertyDefault");
+ EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
+
+ String name = annotationHelper.extractEntitTypeName(enp, field);
+
+ Assert.assertEquals("SimpleEntity", name);
+ }
+
+ @Test
+ public void getFieldTypeForPropertyNullInstance() throws Exception {
+ Object result = annotationHelper.getFieldTypeForProperty(null, "");
+ Assert.assertNull(result);
+ }
+
+ @Test
+ public void getValueForPropertyNullInstance() throws Exception {
+ Object result = annotationHelper.getValueForProperty(null, "");
+ Assert.assertNull(result);
+ }
+
+ @Test
+ public void setValueForPropertyNullInstance() throws Exception {
+ annotationHelper.setValueForProperty(null, "", null);
+ }
+
+ @Test
+ public void extractEntitySetNameObject() {
+ Assert.assertNull(annotationHelper.extractEntitySetName(Object.class));
+ }
+
+ @Test
+ public void extractComplexTypeFqnObject() {
+ Assert.assertNull(annotationHelper.extractComplexTypeFqn(Object.class));
+ }
+
+ @Test
+ public void extractComplexTypeFqn() {
+ FullQualifiedName fqn = annotationHelper.extractComplexTypeFqn(Location.class);
+ Assert.assertEquals("RefScenario", fqn.getNamespace());
+ Assert.assertEquals("c_Location", fqn.getName());
+ }
+
+ @Test
+ public void convert() throws Exception {
+ ConversionProperty cp = new ConversionProperty();
+ annotationHelper.setValueForProperty(cp, "StringProp", "42");
+ annotationHelper.setValueForProperty(cp, "IntegerProp", "420");
+ annotationHelper.setValueForProperty(cp, "LongProp", "4200");
+ annotationHelper.setValueForProperty(cp, "FloatProp", "43");
+ annotationHelper.setValueForProperty(cp, "DoubleProp", "42.00");
+ annotationHelper.setValueForProperty(cp, "ByteProp", "1");
+
+ Assert.assertEquals("42", cp.stringProp);
+ Assert.assertEquals(Integer.valueOf(420), cp.integerProp);
+ Assert.assertEquals(Long.valueOf("4200"), cp.longProp);
+ Assert.assertEquals(new Float(43), cp.floatProp);
+ Assert.assertEquals(new Double(42.00), cp.doubleProp);
+ Assert.assertEquals(Byte.valueOf("1"), cp.byteProp);
+ }
+
+ @EdmEntityType
+ private class SimpleEntity {
+ @EdmKey
+ @EdmProperty
+ Long id;
+ @EdmProperty
+ String name;
+
+ public SimpleEntity() {}
+
+ public SimpleEntity(Long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+ }
+
+ private class NavigationAnnotated {
+ @EdmNavigationProperty(toType = SimpleEntity.class)
+ SimpleEntity navigationPropertySimpleEntity;
+ @EdmNavigationProperty
+ SimpleEntity navigationPropertyDefault;
+ }
+
+ private class ConversionProperty {
+ @EdmProperty(type=EdmType.STRING) String stringProp;
+ @EdmProperty(type=EdmType.INT32) Integer integerProp;
+ @EdmProperty(type=EdmType.INT64) Long longProp;
+ @EdmProperty(type=EdmType.DECIMAL) Float floatProp;
+ @EdmProperty(type=EdmType.DOUBLE) Double doubleProp;
+ @EdmProperty(type=EdmType.BYTE) Byte byteProp;
+ }
+
+ private class NotAnnotatedBean {
+ private String name;
+ }
+}
[12/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSetTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSetTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSetTest.java
deleted file mode 100644
index 965d3d7..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationSetTest.java
+++ /dev/null
@@ -1,184 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSet;
-import org.apache.olingo.odata2.api.edm.provider.AssociationSetEnd;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmAssociationSetTest extends JPAEdmTestModelView {
-
- private JPAEdmAssociationSetTest objJPAEdmAssociationSetTest;
- private JPAEdmAssociationSet objJPAEdmAssociationSet;
-
- @Before
- public void setUp() {
- objJPAEdmAssociationSetTest = new JPAEdmAssociationSetTest();
- objJPAEdmAssociationSet = new JPAEdmAssociationSet(objJPAEdmAssociationSetTest);
- try {
- objJPAEdmAssociationSet.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmAssociationSet.getBuilder());
- }
-
- @Test
- public void testGetConsistentEdmAssociationSetList() {
- assertNotNull(objJPAEdmAssociationSet.getConsistentEdmAssociationSetList());
- }
-
- @Test
- public void testGetEdmAssociationSet() {
- assertNotNull(objJPAEdmAssociationSet.getEdmAssociationSet());
- }
-
- @Test
- public void testGetEdmAssociation() {
- assertNotNull(objJPAEdmAssociationSet.getEdmAssociation());
- }
-
- @Test
- public void testIsConsistent() {
- assertTrue(objJPAEdmAssociationSet.isConsistent());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmAssociationSet.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmAssociationSet.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmAssociationView getJPAEdmAssociationView() {
- return this;
- }
-
- @Override
- public AssociationSet getEdmAssociationSet() {
- AssociationSet associationSet = new AssociationSet();
- associationSet.setEnd1(new AssociationSetEnd());
- associationSet.setEnd2(new AssociationSetEnd());
-
- return associationSet;
- }
-
- @Override
- public List<Association> getConsistentEdmAssociationList() {
- return getEdmAssociationListLocal();
- }
-
- @Override
- public List<AssociationSet> getConsistentEdmAssociationSetList() {
-
- List<AssociationSet> associationSetList = new ArrayList<AssociationSet>();
- associationSetList.add(getEdmAssociationSet());
- associationSetList.add(getEdmAssociationSet());
-
- return associationSetList;
- }
-
- @Override
- public List<EntitySet> getConsistentEdmEntitySetList() {
- return getEntitySetListLocal();
- }
-
- @Override
- public boolean isConsistent() {
- return true;
- }
-
- @Override
- public Schema getEdmSchema() {
- Schema schema = new Schema();
- schema.setNamespace("salesordereprocessing");
- return schema;
- }
-
- private List<EntitySet> getEntitySetListLocal() {
- List<EntitySet> entitySetList = new ArrayList<EntitySet>();
-
- EntitySet entitySet = new EntitySet();
- entitySet.setName("SalesOrderHeader");
- entitySet.setEntityType(new FullQualifiedName("salesorderprocessing", "SOID"));
-
- EntitySet entitySet2 = new EntitySet();
- entitySet2.setName("SalesOrderItem");
- entitySet2.setEntityType(new FullQualifiedName("salesorderprocessing", "SOID"));
-
- entitySetList.add(entitySet);
- entitySetList.add(entitySet2);
- return entitySetList;
- }
-
- private List<Association> getEdmAssociationListLocal() {
- List<Association> associationList = new ArrayList<Association>();
-
- Association association = new Association();
- association.setName("Assoc_SalesOrderHeader_SalesOrderItem");
- association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")).setRole(
- "SalesOrderHeader"));
- association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"))
- .setRole("SalesOrderItem"));
-
- associationList.add(association);
- return associationList;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationTest.java
deleted file mode 100644
index 8c6d1f9..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmAssociationTest.java
+++ /dev/null
@@ -1,423 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.persistence.JoinColumn;
-import javax.persistence.OneToMany;
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.Association;
-import org.apache.olingo.odata2.api.edm.provider.AssociationEnd;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationEndView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmReferentialConstraintView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.SimpleType;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.SimpleType.SimpleTypeA;
-import org.easymock.EasyMock;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmAssociationTest extends JPAEdmTestModelView {
-
- private static JPAEdmAssociation objAssociation = null;
- private static String ASSOCIATION_NAME = "SalesOrderHeader_String";
- private static JPAEdmAssociationTest localView = null;
- private static final String PUNIT_NAME = "salesorderprocessing";
- private int variant;
-
- @BeforeClass
- public static void setup() {
- localView = new JPAEdmAssociationTest();
- objAssociation = new JPAEdmAssociation(localView, localView, localView, 1);
- try {
- objAssociation.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd1() {
- AssociationEnd associationEnd = new AssociationEnd();
- associationEnd.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader"));
- associationEnd.setRole("SalesOrderHeader");
- associationEnd.setMultiplicity(EdmMultiplicity.ONE);
- return associationEnd;
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd2() {
- AssociationEnd associationEnd = new AssociationEnd();
- associationEnd.setType(new FullQualifiedName("salesorderprocessing", "String"));
- associationEnd.setRole("String");
- associationEnd.setMultiplicity(EdmMultiplicity.MANY);
- return associationEnd;
- }
-
- @Override
- public Association getEdmAssociation() {
- Association association = new Association();
- association
- .setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader")));
- association.setEnd2(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing", "String")));
-
- return association;
- }
-
- @Override
- public boolean isExists() {
- return true;
- }
-
- @Override
- public JPAEdmReferentialConstraintView getJPAEdmReferentialConstraintView() {
- JPAEdmReferentialConstraint refConstraintView = new JPAEdmReferentialConstraint(localView, localView, localView);
- return refConstraintView;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return getJPAAttributeLocal();
- }
-
- @Override
- public String getpUnitName() {
- return PUNIT_NAME;
- }
-
- @Override
- public EntityType getEdmEntityType() {
- EntityType entityType = new EntityType();
- entityType.setName(SimpleTypeA.NAME);
- return entityType;
- }
-
- // The inner class which gives us an replica of the jpa attribute
- @SuppressWarnings("hiding")
- private class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) SimpleType.SimpleTypeA.clazz;
- }
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- if (variant == 1) {
- return PersistentAttributeType.ONE_TO_MANY;
- } else if (variant == 2) {
- return PersistentAttributeType.ONE_TO_ONE;
- } else if (variant == 2) {
- return PersistentAttributeType.MANY_TO_ONE;
- } else {
- return PersistentAttributeType.MANY_TO_MANY;
- }
-
- }
- }
-
- private Attribute<?, ?> getJPAAttributeLocal() {
- AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
- return attr;
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objAssociation.getBuilder());
- }
-
- @Test
- public void testGetEdmAssociation() {
- assertNotNull(objAssociation.getEdmAssociation());
- assertEquals(objAssociation.getEdmAssociation().getName(), ASSOCIATION_NAME);
- }
-
- @Test
- public void testGetConsistentEdmAssociationList() {
- assertTrue(objAssociation.getConsistentEdmAssociationList().size() > 0);
- }
-
- @Override
- public String getEdmRelationShipName() {
- return "Association_SalesOrderHeader_String";
- }
-
- @Test
- public void testSearchAssociation1() {
- class TestAssociationEndView extends JPAEdmTestModelView {
- @Override
- public String getEdmRelationShipName() {
- return "SalesOrderHeader_String1";
- }
-
- private Attribute<?, ?> getJPAAttributeLocal() {
- AttributeMock<Object, String> attr = new AttributeMock<Object, String>();
- return attr;
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return getJPAAttributeLocal();
- }
-
- @Override
- public String getJoinColumnName() {
- return "SO_ID";
- }
-
- @Override
- public String getJoinColumnReferenceColumnName() {
- return "DEMO_ID";
- }
-
- @Override
- public String getMappedByName() {
- return "demo";
- }
-
- @Override
- public String getOwningPropertyName() {
- return "salesOrder";
- }
-
- @Override
- public int getNumberOfAssociationsWithSimilarEndPoints(final JPAEdmAssociationEndView view) {
- return 1;
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @Override
- public EntityType getEdmEntityType() {
- EntityType entityType = new EntityType();
- entityType.setName("SalesOrderHeader");
- return entityType;
- }
-
- @SuppressWarnings("hiding")
- class AttributeMock<Object, String> extends JPAAttributeMock<Object, String> {
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) SimpleType.SimpleTypeA.clazz;
- }
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
-
- return PersistentAttributeType.ONE_TO_MANY;
-
- }
-
- @Override
- public Member getJavaMember() {
- return new AnnotatedElementMock();
- }
-
- @Override
- public java.lang.String getName() {
- // TODO Auto-generated method stub
- return super.getName();
- }
-
- class AnnotatedElementMock implements AnnotatedElement, Member {
-
- @Override
- public boolean isAnnotationPresent(final Class<? extends Annotation> annotationClass) {
- return true;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Annotation getAnnotation(@SuppressWarnings("rawtypes") final Class annotationClass) {
- if (annotationClass.equals(JoinColumn.class)) {
- JoinColumn joinColumn = EasyMock.createMock(JoinColumn.class);
- EasyMock.expect(joinColumn.name()).andStubReturn("SO_ID");
- EasyMock.expect(joinColumn.referencedColumnName()).andStubReturn("DEMO_ID");
- EasyMock.replay(joinColumn);
- return joinColumn;
- } else {
- OneToMany oneToMany = EasyMock.createMock(OneToMany.class);
- EasyMock.expect(oneToMany.mappedBy()).andStubReturn("demo");
- EasyMock.replay(oneToMany);
- return oneToMany;
- }
- }
-
- @Override
- public Annotation[] getAnnotations() {
- return null;
- }
-
- @Override
- public Annotation[] getDeclaredAnnotations() {
- return null;
- }
-
- @Override
- public Class<?> getDeclaringClass() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public java.lang.String getName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public int getModifiers() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public boolean isSynthetic() {
- // TODO Auto-generated method stub
- return false;
- }
-
- }
-
- }
- }
- TestAssociationEndView objJPAEdmAssociationEndTest = new TestAssociationEndView();
- JPAEdmAssociationEnd objJPAEdmAssociationEnd =
- new JPAEdmAssociationEnd(objJPAEdmAssociationEndTest, objJPAEdmAssociationEndTest);
- try {
- objJPAEdmAssociationEnd.getBuilder().build();
- Field field = objAssociation.getClass().getDeclaredField("associationEndMap");
- field.setAccessible(true);
- Map<String, JPAEdmAssociationEndView> associationEndMap = new HashMap<String, JPAEdmAssociationEndView>();
- associationEndMap.put("SalesOrderHeader_String", objJPAEdmAssociationEnd);
- field.set(objAssociation, associationEndMap);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (SecurityException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (NoSuchFieldException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalArgumentException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (IllegalAccessException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- assertEquals("SalesOrderHeader_String", objAssociation.searchAssociation(objJPAEdmAssociationEnd).getName());
-
- }
-
- @Test
- public void testAddJPAEdmAssociationView() {
-
- class LocalJPAAssociationView extends JPAEdmTestModelView {
- @Override
- public AssociationEnd getEdmAssociationEnd1() {
- AssociationEnd associationEnd = new AssociationEnd();
- associationEnd.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderHeader"));
- associationEnd.setRole("SalesOrderHeader");
- associationEnd.setMultiplicity(EdmMultiplicity.ONE);
- return associationEnd;
- }
-
- @Override
- public AssociationEnd getEdmAssociationEnd2() {
- AssociationEnd associationEnd = new AssociationEnd();
- associationEnd.setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem"));
- associationEnd.setRole("SalesOrderItem");
- associationEnd.setMultiplicity(EdmMultiplicity.MANY);
- return associationEnd;
- }
-
- @Override
- public Association getEdmAssociation() {
- Association association = new Association();
- association.setEnd1(new AssociationEnd().setType(new FullQualifiedName("salesorderprocessing",
- "SalesOrderHeader")));
- association.setEnd2(new AssociationEnd()
- .setType(new FullQualifiedName("salesorderprocessing", "SalesOrderItem")));
-
- return association;
- }
- }
- LocalJPAAssociationView assocViewObj = new LocalJPAAssociationView();
- JPAEdmAssociation objLocalAssociation = new JPAEdmAssociation(assocViewObj, assocViewObj, assocViewObj, 1);
- try {
- objLocalAssociation.getBuilder().build();
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- objAssociation.addJPAEdmAssociationView(objLocalAssociation, localView);
-
- }
-
- @Test
- public void testAddJPAEdmRefConstraintView() {
-
- localView = new JPAEdmAssociationTest();
- objAssociation = new JPAEdmAssociation(localView, localView, localView, 1);
- try {
- objAssociation.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- objAssociation.addJPAEdmRefConstraintView(localView);
- assertTrue(objAssociation.getConsistentEdmAssociationList().size() > 0);
- }
-
- @Test
- public void testGetJPAEdmReferentialConstraintView() {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImplTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImplTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImplTest.java
deleted file mode 100644
index bdbf104..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmBaseViewImplTest.java
+++ /dev/null
@@ -1,89 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmBaseViewImplTest extends JPAEdmTestModelView {
-
- private JPAEdmBaseViewImplTest objJPAEdmBaseViewImplTest;
- private JPAEdmBaseViewImpl objJPAEdmBaseViewImpl;
-
- @Before
- public void setUp() {
- objJPAEdmBaseViewImplTest = new JPAEdmBaseViewImplTest();
- objJPAEdmBaseViewImpl = new JPAEdmBaseViewImpl(objJPAEdmBaseViewImplTest) {
-
- @Override
- public JPAEdmBuilder getBuilder() {
- return null;
- }
- };
-
- objJPAEdmBaseViewImpl = new JPAEdmBaseViewImpl(getJPAMetaModel(), getpUnitName()) {
-
- @Override
- public JPAEdmBuilder getBuilder() {
- return null;
- }
- };
-
- }
-
- @Test
- public void testGetpUnitName() {
- assertTrue(objJPAEdmBaseViewImpl.getpUnitName().equals("salesorderprocessing"));
- }
-
- @Test
- public void testGetJPAMetaModel() {
- assertNotNull(objJPAEdmBaseViewImpl.getJPAMetaModel());
- }
-
- @Test
- public void testIsConsistent() {
- assertTrue(objJPAEdmBaseViewImpl.isConsistent());
- }
-
- @Test
- public void testClean() {
- objJPAEdmBaseViewImpl.clean();
- assertFalse(objJPAEdmBaseViewImpl.isConsistent());
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAMetaModelMock();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexTypeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexTypeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexTypeTest.java
deleted file mode 100644
index 2fabe8c..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmComplexTypeTest.java
+++ /dev/null
@@ -1,268 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EmbeddableType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEmbeddableMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPASingularAttributeMock;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmComplexTypeTest extends JPAEdmTestModelView {
-
- private static JPAEdmComplexType objComplexType = null;
- private static JPAEdmComplexTypeTest localView = null;
-
- @BeforeClass
- public static void setup() {
- localView = new JPAEdmComplexTypeTest();
- objComplexType = new JPAEdmComplexType(localView);
- try {
- objComplexType.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @SuppressWarnings("rawtypes")
- @Override
- public EmbeddableType<?> getJPAEmbeddableType() {
- @SuppressWarnings("hiding")
- class JPAComplexAttribute<Long> extends JPAEmbeddableMock<Long> {
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<Long> getJavaType() {
-
- return (Class<Long>) java.lang.Long.class;
- }
-
- }
- return new JPAComplexAttribute();
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAEdmMetaModel();
- }
-
- @Test
- public void testGetBuilder() {
-
- assertNotNull(objComplexType.getBuilder());
- }
-
- @Test
- public void testGetEdmComplexType() {
- assertEquals(objComplexType.getEdmComplexType().getName(), "String");
- }
-
- @Test
- public void testSearchComplexTypeString() {
- assertNotNull(objComplexType.searchEdmComplexType("java.lang.String"));
-
- }
-
- @Test
- public void testGetJPAEmbeddableType() {
- assertTrue(objComplexType.getJPAEmbeddableType().getAttributes().size() > 0);
-
- }
-
- @Test
- public void testGetConsistentEdmComplexTypes() {
- assertTrue(objComplexType.getConsistentEdmComplexTypes().size() > 0);
- }
-
- @Test
- public void testSearchComplexTypeFullQualifiedName() {
- assertNotNull(objComplexType.searchEdmComplexType(new FullQualifiedName("salesorderprocessing", "String")));
-
- }
-
- @Test
- public void testSearchComplexTypeFullQualifiedNameNegative() {
- assertNull(objComplexType.searchEdmComplexType(new FullQualifiedName("salesorderprocessing", "lang.String")));
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objComplexType.getBuilder();
- JPAEdmBuilder builder2 = objComplexType.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testAddCompleTypeView() {
- localView = new JPAEdmComplexTypeTest();
- objComplexType = new JPAEdmComplexType(localView);
- try {
- objComplexType.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- objComplexType.addJPAEdmCompleTypeView(localView);
- assertTrue(objComplexType.getConsistentEdmComplexTypes().size() > 1);
- }
-
- @Test
- public void testExpandEdmComplexType() {
- ComplexType complexType = new ComplexType();
- List<Property> properties = new ArrayList<Property>();
- JPAEdmMapping mapping1 = new JPAEdmMappingImpl();
- mapping1.setJPAColumnName("LINEITEMID");
- ((Mapping) mapping1).setInternalName("LineItemKey.LiId");
- JPAEdmMapping mapping2 = new JPAEdmMappingImpl();
- mapping2.setJPAColumnName("LINEITEMNAME");
- ((Mapping) mapping2).setInternalName("LineItemKey.LiName");
- properties.add(new SimpleProperty().setName("LIID").setMapping((Mapping) mapping1));
- properties.add(new SimpleProperty().setName("LINAME").setMapping((Mapping) mapping2));
- complexType.setProperties(properties);
- List<Property> expandedList = null;
- try {
- objComplexType.expandEdmComplexType(complexType, expandedList, "SalesOrderItemKey");
- } catch (ClassCastException e) {
- assertTrue(false);
- }
- assertTrue(true);
-
- }
-
- @Test
- public void testComplexTypeCreation() {
- try {
- objComplexType.getBuilder().build();
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- assertEquals(objComplexType.pUnitName, "salesorderprocessing");
- }
-
- private class JPAEdmMetaModel extends JPAMetaModelMock {
- Set<EmbeddableType<?>> embeddableSet;
-
- public JPAEdmMetaModel() {
- embeddableSet = new HashSet<EmbeddableType<?>>();
- }
-
- @Override
- public Set<EmbeddableType<?>> getEmbeddables() {
- embeddableSet.add(new JPAEdmEmbeddable<String>());
- return embeddableSet;
- }
-
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEmbeddable<String> extends JPAEmbeddableMock<String> {
-
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Class<String> getJavaType() {
- return (Class<String>) java.lang.String.class;
- }
-
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return PersistentAttributeType.BASIC;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return false;
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainerTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainerTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainerTest.java
deleted file mode 100644
index 4e9355b..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityContainerTest.java
+++ /dev/null
@@ -1,234 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmAssociationView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPASingularAttributeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmEntityContainerTest extends JPAEdmTestModelView {
-
- private JPAEdmEntityContainer objJPAEdmEntityContainer;
- private JPAEdmEntityContainerTest objJPAEdmEntityContainerTest;
-
- @Before
- public void setUp() {
- objJPAEdmEntityContainerTest = new JPAEdmEntityContainerTest();
- objJPAEdmEntityContainer = new JPAEdmEntityContainer(objJPAEdmEntityContainerTest);
- try {
- objJPAEdmEntityContainer.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmEntityContainer.getBuilder());
- }
-
- @Test
- public void testGetEdmEntityContainer() {
- assertNotNull(objJPAEdmEntityContainer.getEdmEntityContainer());
- assertTrue(objJPAEdmEntityContainer.getEdmEntityContainer().getEntitySets().size() > 0);
- }
-
- @Test
- public void testGetConsistentEdmEntityContainerList() {
- assertNotNull(objJPAEdmEntityContainer.getConsistentEdmEntityContainerList());
- assertTrue(objJPAEdmEntityContainer.getConsistentEdmEntityContainerList().size() > 0);
-
- }
-
- @Test
- public void testGetJPAEdmEntitySetView() {
- assertNotNull(objJPAEdmEntityContainer.getJPAEdmEntitySetView());
- assertEquals("salesorderprocessing", objJPAEdmEntityContainer.getJPAEdmEntitySetView().getpUnitName());
- }
-
- @Test
- public void testIsConsistent() {
- assertTrue(objJPAEdmEntityContainer.isConsistent());
- objJPAEdmEntityContainer.clean();
- assertFalse(objJPAEdmEntityContainer.isConsistent());
- }
-
- @Test
- public void testGetEdmAssociationSetView() {
- assertNotNull(objJPAEdmEntityContainer.getEdmAssociationSetView());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmEntityContainer.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmEntityContainer.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAEdmMetaModel();
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public EntityType<?> getJPAEntityType() {
- return new JPAEdmEntityType<String>();
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public Schema getEdmSchema() {
- Schema schema = new Schema();
- schema.setNamespace("salesordereprocessing");
- return schema;
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @Override
- public JPAEdmAssociationView getJPAEdmAssociationView() {
- return this;
- }
-
- @Override
- public JPAEdmBuilder getBuilder() {
- return new JPAEdmBuilder() {
-
- @Override
- public void build() {
- // Nothing to do?
- }
- };
- }
-
- private class JPAEdmMetaModel extends JPAMetaModelMock {
- Set<EntityType<?>> entities;
-
- public JPAEdmMetaModel() {
- entities = new HashSet<EntityType<?>>();
- }
-
- @Override
- public Set<EntityType<?>> getEntities() {
- entities.add(new JPAEdmEntityType());
- return entities;
- }
-
- private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
- @Override
- public String getName() {
- return "SalesOrderHeader";
- }
- }
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return PersistentAttributeType.BASIC;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return true;
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySetTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySetTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySetTest.java
deleted file mode 100644
index 74c203e..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntitySetTest.java
+++ /dev/null
@@ -1,224 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.api.edm.provider.Schema;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPASingularAttributeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmEntitySetTest extends JPAEdmTestModelView {
-
- private static JPAEdmEntitySet objJPAEdmEntitySet;
- private static JPAEdmEntitySetTest objJPAEdmEntitySetTest;
-
- @Before
- public void setUp() {
- objJPAEdmEntitySetTest = new JPAEdmEntitySetTest();
- objJPAEdmEntitySet = new JPAEdmEntitySet(objJPAEdmEntitySetTest);
- try {
- objJPAEdmEntitySet.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmEntitySet.getBuilder());
- }
-
- @Test
- public void testGetEdmEntitySet() {
- assertNotNull(objJPAEdmEntitySet.getEdmEntitySet());
- assertNotNull(objJPAEdmEntitySet.getEdmEntitySet().getEntityType());
- }
-
- @Test
- public void testGetConsistentEntitySetList() {
- assertTrue(objJPAEdmEntitySet.getConsistentEdmEntitySetList().size() > 0);
- }
-
- @Test
- public void testGetJPAEdmEntityTypeView() {
- assertNotNull(objJPAEdmEntitySet.getJPAEdmEntityTypeView());
- assertEquals("salesorderprocessing", objJPAEdmEntitySet.getJPAEdmEntityTypeView().getpUnitName());
- }
-
- @Test
- public void testIsConsistent() {
- assertTrue(objJPAEdmEntitySet.isConsistent());
-
- objJPAEdmEntitySet.getJPAEdmEntityTypeView().clean();
- assertFalse(objJPAEdmEntitySet.getJPAEdmEntityTypeView().isConsistent());
-
- objJPAEdmEntitySet.clean();
- assertFalse(objJPAEdmEntitySet.isConsistent());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmEntitySet.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmEntitySet.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAEdmMetaModel();
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public EntityType<?> getJPAEntityType() {
- return new JPAEdmEntityType<String>();
- }
-
- @Override
- public JPAEdmKeyView getJPAEdmKeyView() {
- return this;
- }
-
- @Override
- public Schema getEdmSchema() {
- Schema schema = new Schema();
- schema.setNamespace("salesordereprocessing");
- return schema;
- }
-
- @Override
- public String getpUnitName() {
- return "salesorderprocessing";
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEntityType<String> extends JPAEntityTypeMock<String> {
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- }
-
- @Override
- public java.lang.String getName() {
- return "SalesOrderHeader";
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return PersistentAttributeType.BASIC;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return true;
- }
- }
- }
-
- private class JPAEdmMetaModel extends JPAMetaModelMock {
- Set<EntityType<?>> entities;
-
- public JPAEdmMetaModel() {
- entities = new HashSet<EntityType<?>>();
- }
-
- @Override
- public Set<EntityType<?>> getEntities() {
- entities.add(new JPAEdmEntityType());
- return entities;
- }
-
- private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
- @Override
- public String getName() {
- return "SalesOrderHeader";
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityTypeTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityTypeTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityTypeTest.java
deleted file mode 100644
index dfbe879..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmEntityTypeTest.java
+++ /dev/null
@@ -1,198 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.persistence.metamodel.Attribute;
-import javax.persistence.metamodel.EntityType;
-import javax.persistence.metamodel.Metamodel;
-
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEntityTypeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAMetaModelMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPASingularAttributeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmEntityTypeTest extends JPAEdmTestModelView {
-
- private static JPAEdmEntityTypeTest objJPAEdmEntityTypeTest;
- private static JPAEdmEntityType objJPAEdmEntityType;
-
- @Before
- public void setUp() {
- objJPAEdmEntityTypeTest = new JPAEdmEntityTypeTest();
- objJPAEdmEntityType = new JPAEdmEntityType(objJPAEdmEntityTypeTest);
- try {
- objJPAEdmEntityType.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-
- @Test
- public void testGetBuilder() {
- assertNotNull(objJPAEdmEntityType.getBuilder());
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = objJPAEdmEntityType.getBuilder();
- JPAEdmBuilder builder2 = objJPAEdmEntityType.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Test
- public void testGetEdmEntityType() {
- assertNotNull(objJPAEdmEntityType.getEdmEntityType());
- assertNotNull(objJPAEdmEntityType.getEdmEntityType().getKey());
- }
-
- @Test
- public void testGetJPAEntityType() {
- assertNotNull(objJPAEdmEntityType.getJPAEntityType());
-
- }
-
- @Test
- public void testGetConsistentEdmEntityTypes() {
- assertTrue(objJPAEdmEntityType.getConsistentEdmEntityTypes().size() > 0);
- }
-
- @Test
- public void testSearchEdmEntityType() {
- assertNotNull(objJPAEdmEntityType.searchEdmEntityType("SalesOrderHeader"));
- }
-
- @Test
- public void testIsConsistent() {
- assertTrue(objJPAEdmEntityType.isConsistent());
- }
-
- @Override
- public Metamodel getJPAMetaModel() {
- return new JPAEdmMetaModel();
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public EntityType<?> getJPAEntityType() {
- return new JPAEdmEntityTypeLocal<String>();
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- private class JPAEdmMetaModel extends JPAMetaModelMock {
- Set<EntityType<?>> entities;
-
- public JPAEdmMetaModel() {
- entities = new HashSet<EntityType<?>>();
- }
-
- @Override
- public Set<EntityType<?>> getEntities() {
- entities.add(new JPAEdmEntityType());
- return entities;
- }
-
- private class JPAEdmEntityType extends JPAEntityTypeMock<String> {
- @Override
- public String getName() {
- return "SalesOrderHeader";
- }
- }
- }
-
- @SuppressWarnings("hiding")
- private class JPAEdmEntityTypeLocal<String> extends JPAEntityTypeMock<String> {
- Set<Attribute<? super String, ?>> attributeSet = new HashSet<Attribute<? super String, ?>>();
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private void setValuesToSet() {
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SOID"));
- attributeSet.add((Attribute<? super String, String>) new JPAEdmAttribute(java.lang.String.class, "SONAME"));
- }
-
- @Override
- public Set<Attribute<? super String, ?>> getAttributes() {
- setValuesToSet();
- return attributeSet;
- }
-
- private class JPAEdmAttribute<Object, String> extends JPASingularAttributeMock<Object, String> {
-
- @Override
- public PersistentAttributeType getPersistentAttributeType() {
- return PersistentAttributeType.BASIC;
- }
-
- Class<String> clazz;
- java.lang.String attributeName;
-
- public JPAEdmAttribute(final Class<String> javaType, final java.lang.String name) {
- this.clazz = javaType;
- this.attributeName = name;
-
- }
-
- @Override
- public Class<String> getJavaType() {
- return clazz;
- }
-
- @Override
- public java.lang.String getName() {
- return this.attributeName;
- }
-
- @Override
- public boolean isId() {
- return true;
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImportTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImportTest.java
deleted file mode 100644
index 94665d7..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmFunctionImportTest.java
+++ /dev/null
@@ -1,566 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata2.api.edm.provider.FunctionImportParameter;
-import org.apache.olingo.odata2.api.edm.provider.Mapping;
-import org.apache.olingo.odata2.api.edm.provider.ReturnType;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmComplexTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityContainerView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntitySetView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmEntityTypeView;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPACustomProcessorMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model._JPACustomProcessorNegativeMock;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JPAEdmFunctionImportTest extends JPAEdmTestModelView {
- private static final int METHOD_COUNT = 6;
- private static int VARIANT = 0;
- private JPAEdmFunctionImport jpaEdmfunctionImport;
-
- @Before
- public void setup() {
- jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
- }
-
- /**
- * Test Case - Function Import Basic test - Positive Case
- */
- @Test
- public void testFunctionImportBasic() {
- VARIANT = 0;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
- for (FunctionImport functionImport : functionImportList) {
- assertEquals(functionImport.getName(), "Method1");
- assertNotNull(functionImport.getMapping());
- Mapping mapping = new Mapping();
- mapping.setInternalName("method1");
-
- assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
-
- List<FunctionImportParameter> funcImpList = functionImport.getParameters();
- assertEquals(2, funcImpList.size());
- assertEquals("Param1", funcImpList.get(0).getName());
- assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType());
-
- assertEquals("Param3", funcImpList.get(1).getName());
- assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType());
-
- }
-
- }
-
- /**
- * Test Case - Enable a method that does not exists
- */
- @Test
- public void testFunctionImportNoSuchMethod() {
- VARIANT = 1;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- /**
- * Test Case - Enable all annotated methods in a class as function imports
- */
- @Test
- public void testFunctionImportAllMethods() {
- VARIANT = 2;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(METHOD_COUNT, functionImportList.size());
-
- }
-
- /**
- * Test Case - Function Import with no names. Default name is Java method
- * name.
- */
- @Test
- public void testFunctionImportNoName() {
- VARIANT = 3;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method3");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString());
- }
-
- /**
- * Test Case - Function Import with No return type defined - Negative case
- */
- @Test
- public void testNoReturnType() {
- VARIANT = 4;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- /**
- * Test Case - Function Import with return type as Entity and Multiplicity
- * as Many but no Entity set defined. --> Negative Case
- */
- @Test
- public void testNoEntitySet() {
- VARIANT = 5;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_ENTITYSET_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
- }
-
- /**
- * Test Case - Function Import with return type as Entity Type but method
- * has returns void. --> Negative Case
- */
- @Test
- public void testNoReturnTypeButAnnotated() {
- VARIANT = 6;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
- }
-
- /**
- * Test Case - Function Import that returns an Entity Type with Multiplicity
- * as ONE. -->Positive Case
- */
- @Test
- public void testFunctionImportEntityTypeSingleReturn() {
- VARIANT = 7;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method7");
- assertNotNull(functionImport.getMapping());
- JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping();
- assertEquals(JPACustomProcessorMock.class, mapping.getJPAType());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + JPACustomProcessorMock.edmName);
- }
-
- /**
- * Test Case - Function Import that returns an Entity Type that is not found
- * in JPA Model
- */
- @Test
- public void testFunctionImportEntityTypeInvalid() {
- VARIANT = 8;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that returns a complex Type
- */
- @Test
- public void testFunctionImportComplexType() {
- VARIANT = 9;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method9");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + JPACustomProcessorMock.edmName);
-
- }
-
- /**
- * Test Case - Function Import that returns a complex Type with multiplicity
- * Many
- */
- @Test
- public void testFunctionImportComplexTypeMany() {
- VARIANT = 10;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- FunctionImport functionImport = functionImportList.get(0);
- assertEquals(functionImport.getName(), "method10");
- assertNotNull(functionImport.getMapping());
-
- ReturnType returnType = functionImport.getReturnType();
- assertNotNull(returnType);
- assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity());
- assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "."
- + JPACustomProcessorMock.edmName);
-
- }
-
- /**
- * Test Case - Function Import that returns an Complex Type that is not
- * found in JPA Model
- */
- @Test
- public void testFunctionImportComplexTypeInvalid() {
- VARIANT = 11;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that returns an scalar Type that is not valid
- */
- @Test
- public void testFunctionImportScalarTypeInvalid() {
- VARIANT = 12;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.TYPE_NOT_SUPPORTED.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import that takes a parameter with no name
- */
- @Test
- public void testFunctionImportParamNoName() {
- VARIANT = 13;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_PARAM_NAME_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import test for facets
- */
- @Test
- public void testFunctionImportParamFacets() {
- VARIANT = 14;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
- EdmFacets facets = funcImpParamList.get(0).getFacets();
- assertNotNull(facets);
- assertEquals(2, facets.getMaxLength().intValue());
- assertEquals(true, facets.isNullable());
-
- facets = funcImpParamList.get(1).getFacets();
- assertNotNull(facets);
- assertEquals(false, facets.isNullable());
- assertEquals(10, facets.getPrecision().intValue());
- assertEquals(2, facets.getScale().intValue());
-
- }
-
- /**
- * Test Case - Function Import test for default facets
- */
- @Test
- public void testFunctionImportParamFacetsDefault() {
- VARIANT = 15;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 1);
-
- List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters();
- EdmFacets facets = funcImpParamList.get(0).getFacets();
- assertNotNull(facets);
- assertNull(facets.getMaxLength());
- assertEquals(false, facets.isNullable());
- assertNull(facets.getPrecision());
- assertNull(facets.getScale());
-
- }
-
- /**
- * Test Case - Function Import test for ReturnType.SCALAR but method returns
- * void
- */
- @Test
- public void testWrongReturnTypeScalar() {
- VARIANT = 16;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- /**
- * Test Case - Function Import test for ReturnType.COMPLEX but method returns
- * void
- */
- @Test
- public void testWrongReturnTypeComplex() {
- VARIANT = 17;
-
- try {
- jpaEdmfunctionImport.getBuilder().build();
- fail("Exception Expected");
- } catch (ODataJPAModelException e) {
- assertEquals(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.getKey(), e.getMessageReference().getKey());
- } catch (ODataJPARuntimeException e) {
- fail("Model Exception Expected");
- }
-
- }
-
- @Test
- public void testNoFunctionImport() {
- VARIANT = 99;
-
- build();
-
- List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList();
-
- assertEquals(functionImportList.size(), 0);
-
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmFunctionImport jpaEdmfunctionImport = new JPAEdmFunctionImport(this);
-
- JPAEdmBuilder builder1 = jpaEdmfunctionImport.getBuilder();
- JPAEdmBuilder builder2 = jpaEdmfunctionImport.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public HashMap<Class<?>, String[]> getRegisteredOperations() {
-
- HashMap<Class<?>, String[]> customOperations = new HashMap<Class<?>, String[]>();
-
- if (VARIANT == 0) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method1" });
- } else if (VARIANT == 1) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "XYX" });
- } else if (VARIANT == 2) {
- customOperations.put(JPACustomProcessorMock.class, null);
- } else if (VARIANT == 3) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method3" });
- } else if (VARIANT == 4) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method4" });
- } else if (VARIANT == 5) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method5" });
- } else if (VARIANT == 6) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method6" });
- } else if (VARIANT == 7) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method7" });
- } else if (VARIANT == 8) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method8" });
- } else if (VARIANT == 9) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method9" });
- } else if (VARIANT == 10) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method10" });
- } else if (VARIANT == 11) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method11" });
- } else if (VARIANT == 12) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method12" });
- } else if (VARIANT == 13) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method13" });
- } else if (VARIANT == 14) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method1" });
- } else if (VARIANT == 15) {
- customOperations.put(JPACustomProcessorMock.class, new String[] { "method3" });
- } else if (VARIANT == 16) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method16" });
- } else if (VARIANT == 17) {
- customOperations.put(_JPACustomProcessorNegativeMock.class, new String[] { "method17" });
- } else {
- return null;
- }
-
- return customOperations;
- }
-
- @Override
- public JPAEdmEntityContainerView getJPAEdmEntityContainerView() {
- return this;
- }
-
- @Override
- public JPAEdmEntitySetView getJPAEdmEntitySetView() {
- return this;
- }
-
- @Override
- public JPAEdmEntityTypeView getJPAEdmEntityTypeView() {
- return this;
- }
-
- @Override
- public JPAEdmComplexTypeView getJPAEdmComplexTypeView() {
- return this;
- }
-
- @Override
- public EntityType searchEdmEntityType(final String arg0) {
- if (arg0.equals(JPACustomProcessorMock.class.getSimpleName())) {
- return new EntityType().setName(JPACustomProcessorMock.edmName);
- } else {
- return null;
- }
- }
-
- @Override
- public ComplexType searchEdmComplexType(final String arg0) {
- if (arg0.equals(JPACustomProcessorMock.class.getName())) {
- return new ComplexType().setName(JPACustomProcessorMock.edmName);
- } else {
- return null;
- }
- }
-
- @Override
- public String getpUnitName() {
- return ODataJPAContextMock.PERSISTENCE_UNIT_NAME;
- }
-
- private void build() {
- try {
- jpaEdmfunctionImport.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKeyTest.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKeyTest.java b/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKeyTest.java
deleted file mode 100644
index 0ec45df..0000000
--- a/odata2-jpa-processor/jpa-core/src/test/java/org/apache/olingo/odata2/processor/core/jpa/model/JPAEdmKeyTest.java
+++ /dev/null
@@ -1,176 +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.odata2.processor.core.jpa.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.metamodel.Attribute;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.ComplexProperty;
-import org.apache.olingo.odata2.api.edm.provider.ComplexType;
-import org.apache.olingo.odata2.api.edm.provider.Key;
-import org.apache.olingo.odata2.api.edm.provider.Property;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmBuilder;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmKeyView;
-import org.apache.olingo.odata2.processor.core.jpa.common.ODataJPATestConstants;
-import org.apache.olingo.odata2.processor.core.jpa.mock.ODataJPAContextMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAAttributeMock;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData;
-import org.apache.olingo.odata2.processor.core.jpa.mock.model.JPAEdmMockData.ComplexType.ComplexTypeA;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class JPAEdmKeyTest extends JPAEdmTestModelView {
-
- private static JPAEdmKeyView keyView;
- private static JPAEdmKeyTest objJpaEdmKeyTest;
-
- @BeforeClass
- public static void setup() {
- objJpaEdmKeyTest = new JPAEdmKeyTest();
- keyView = new JPAEdmKey(objJpaEdmKeyTest, objJpaEdmKeyTest);
- }
-
- @SuppressWarnings("hiding")
- private class JPAAttributeA<Object, ComplexTypeA> extends JPAAttributeMock<Object, ComplexTypeA> {
- @SuppressWarnings("unchecked")
- @Override
- public Class<ComplexTypeA> getJavaType() {
- return (Class<ComplexTypeA>) JPAEdmMockData.ComplexType.ComplexTypeA.class;
- }
- }
-
- @Test
- public void testBuildComplexKey() {
- try {
- keyView.getBuilder().build();
- } catch (ODataJPAModelException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- } catch (ODataJPARuntimeException e) {
- fail(ODataJPATestConstants.EXCEPTION_MSG_PART_1 + e.getMessage() + ODataJPATestConstants.EXCEPTION_MSG_PART_2);
- }
-
- Key key = keyView.getEdmKey();
-
- assertEquals(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_A, key.getKeys().get(0).getName());
- assertEquals(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_B, key.getKeys().get(1).getName());
- assertEquals(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_D, key.getKeys().get(2).getName());
- assertEquals(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_E, key.getKeys().get(3).getName());
-
- }
-
- @Test
- public void testGetBuilderIdempotent() {
- JPAEdmBuilder builder1 = keyView.getBuilder();
- JPAEdmBuilder builder2 = keyView.getBuilder();
-
- assertEquals(builder1.hashCode(), builder2.hashCode());
- }
-
- @Override
- public Attribute<?, ?> getJPAAttribute() {
- return new JPAAttributeA<Object, ComplexTypeA>();
-
- }
-
- @Override
- public ComplexType searchEdmComplexType(final FullQualifiedName arg0) {
- return searchEdmComplexType(arg0.getName());
- }
-
- @Override
- public ComplexType searchEdmComplexType(final String arg0) {
- if (arg0.equals(JPAEdmMockData.ComplexType.ComplexTypeA.class.getName())) {
- return buildComplexTypeA();
- } else if (arg0.equals(JPAEdmMockData.ComplexType.ComplexTypeB.class.getSimpleName())) {
- return buildComplexTypeB();
- }
-
- return null;
-
- }
-
- private ComplexType buildComplexTypeB() {
- ComplexType complexType = new ComplexType();
- complexType.setProperties(buildPropertiesB());
-
- return complexType;
- }
-
- private List<Property> buildPropertiesB() {
- List<Property> propertyList = new ArrayList<Property>();
-
- SimpleProperty property = new SimpleProperty();
- property.setName(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_D);
- property.setType(EdmSimpleTypeKind.Int16);
-
- propertyList.add(property);
-
- property = new SimpleProperty();
- property.setName(JPAEdmMockData.ComplexType.ComplexTypeB.Property.PROPERTY_E);
- property.setType(EdmSimpleTypeKind.Int16);
-
- propertyList.add(property);
-
- return propertyList;
- }
-
- private ComplexType buildComplexTypeA() {
- ComplexType complexType = new ComplexType();
- complexType.setProperties(buildPropertiesA());
-
- return complexType;
- }
-
- private List<Property> buildPropertiesA() {
-
- List<Property> propertyList = new ArrayList<Property>();
-
- SimpleProperty property = new SimpleProperty();
- property.setName(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_A);
- property.setType(EdmSimpleTypeKind.Int16);
-
- propertyList.add(property);
-
- property = new SimpleProperty();
- property.setName(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_B);
- property.setType(EdmSimpleTypeKind.Int16);
-
- propertyList.add(property);
-
- ComplexProperty complexProperty = new ComplexProperty();
- complexProperty.setName(JPAEdmMockData.ComplexType.ComplexTypeA.Property.PROPERTY_C);
- complexProperty.setType(new FullQualifiedName(ODataJPAContextMock.NAMESPACE,
- JPAEdmMockData.ComplexType.ComplexTypeB.name));
-
- propertyList.add(complexProperty);
- return propertyList;
-
- }
-
-}
[29/47] [OLINGO-99] Re-factor Package Names. Following are the changes
Posted by tb...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
deleted file mode 100644
index 756e1ca..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAEntityParser.java
+++ /dev/null
@@ -1,453 +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.odata2.processor.core.jpa.access.data;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.edm.EdmAssociationEnd;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-
-public final class JPAEntityParser {
-
- /*
- * List of buffers used by the Parser
- */
- private static short MAX_SIZE = 10;
- public static final String ACCESS_MODIFIER_GET = "get";
- public static final String ACCESS_MODIFIER_SET = "set";
-
- private HashMap<String, HashMap<String, Method>> jpaEntityAccessMap = null;
- private HashMap<String, HashMap<String, String>> jpaEmbeddableKeyMap = null;
-
- public JPAEntityParser() {
- jpaEntityAccessMap = new HashMap<String, HashMap<String, Method>>(
- MAX_SIZE);
- jpaEmbeddableKeyMap = new HashMap<String, HashMap<String, String>>();
- };
-
- public HashMap<String, Method> getJPAEntityAccessMap(final String jpaEntityName) {
- return jpaEntityAccessMap.get(jpaEntityName);
- }
-
- public HashMap<String, String> getJPAEmbeddableKeyMap(final String jpaEntityName) {
- return jpaEmbeddableKeyMap.get(jpaEntityName);
- }
-
- /**
- * The method returns a Hash Map of Properties and values for selected
- * properties of an EdmEntity Type
- *
- * @param jpaEntity
- * @param selectedItems
- * @return a Hash Map of Properties and values for given selected properties
- * of an EdmEntity Type
- * @throws ODataJPARuntimeException
- */
-
- public final HashMap<String, Object> parse2EdmPropertyValueMap(
- final Object jpaEntity, final List<EdmProperty> selectPropertyList)
- throws ODataJPARuntimeException {
- HashMap<String, Object> edmEntity = new HashMap<String, Object>();
- String methodName = null;
- Method method = null;
- for (int i = 0; i < selectPropertyList.size(); i++) {
- String key = null;
- Object propertyValue = null;
- EdmProperty property = null;
- property = selectPropertyList.get(i);
-
- try {
- methodName = getAccessModifierName(property.getName(),
- property.getMapping(), ACCESS_MODIFIER_GET);
- String[] nameParts = methodName.split("\\.");
- if (nameParts.length > 1) {
- Object propertyVal = new Object();
- propertyVal = jpaEntity;
- for (String namePart : nameParts) {
- method = propertyVal.getClass().getMethod(
- namePart, (Class<?>[]) null);
- method.setAccessible(true);
- propertyVal = getProperty(method, propertyVal);
- }
- edmEntity.put(property.getName(), propertyVal);
- } else {
- method = jpaEntity.getClass().getMethod(methodName,
- (Class<?>[]) null);
- method.setAccessible(true);
- propertyValue = getProperty(method, jpaEntity);
- key = property.getName();
- if (property.getType().getKind()
- .equals(EdmTypeKind.COMPLEX)) {
- try {
- propertyValue = parse2EdmPropertyValueMap(
- propertyValue,
- (EdmStructuralType) property.getType());
- } catch (ODataJPARuntimeException e) {
- throw e;
- }
- }
- edmEntity.put(key, propertyValue);
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- }
-
- return edmEntity;
- }
-
- /**
- * The method returns a Hash Map of Properties and values for an EdmEntity
- * Type The method uses reflection on object jpaEntity to get the list of
- * accessModifier method. Then uses the accessModifier method to extract the value from
- * JPAEntity.
- *
- * @param jpaEntity
- * @param structuralType
- * @return a Hash Map of Properties and values for given EdmEntity Type
- * @throws ODataJPARuntimeException
- */
- public final HashMap<String, Object> parse2EdmPropertyValueMap(
- final Object jpaEntity, final EdmStructuralType structuralType)
- throws ODataJPARuntimeException {
-
- if (jpaEntity == null || structuralType == null) {
- return null;
- }
-
- String jpaEntityAccessKey = jpaEntity.getClass().getName();
-
- if (!jpaEntityAccessMap.containsKey(jpaEntityAccessKey)) {
- jpaEntityAccessMap.put(jpaEntityAccessKey,
- getAccessModifiers(jpaEntity, structuralType, ACCESS_MODIFIER_GET));
- }
-
- HashMap<String, Object> edmEntity = new HashMap<String, Object>();
- HashMap<String, Method> getters = jpaEntityAccessMap
- .get(jpaEntityAccessKey);
- HashMap<String, String> embeddableKeys = jpaEmbeddableKeyMap
- .get(jpaEntityAccessKey);
-
- try {
- for (String key : getters.keySet()) {
-
- EdmProperty property = (EdmProperty) structuralType
- .getProperty(key);
-
- Method method = getters.get(key);
- Object propertyValue = null;
-
- if (method != null) {
- getters.get(key).setAccessible(true);
- propertyValue = getProperty(method, jpaEntity);
- }
- if (property.getType().getKind().equals(EdmTypeKind.COMPLEX)) {
- propertyValue = parse2EdmPropertyValueMap(propertyValue,
- (EdmStructuralType) property.getType());
- }
-
- edmEntity.put(key, propertyValue);
-
- }
-
- if (embeddableKeys != null) {
- for (String key : embeddableKeys.keySet()) {
- String name = embeddableKeys.get(key);
- String[] nameParts = name.split("\\.");
- Object propertyValue = jpaEntity;
- Method method = null;
- for (String namePart : nameParts) {
- method = propertyValue.getClass().getMethod(
- namePart, (Class<?>[]) null);
- method.setAccessible(true);
- propertyValue = getProperty(method, propertyValue);
- }
- edmEntity.put(key, propertyValue);
- }
- }
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- return edmEntity;
- }
-
- // This method appends the associated entities as a java list to an expanded
- // map of a source entity
- public final HashMap<String, Object> parse2EdmNavigationValueMap(
- final Object jpaEntity, final List<EdmNavigationProperty> navigationPropertyList)
- throws ODataJPARuntimeException {
- Object result = null;
- String methodName = null;
- HashMap<String, Object> navigationMap = new HashMap<String, Object>();
- if (navigationPropertyList != null
- && navigationPropertyList.size() != 0) {
-
- try {
- for (EdmNavigationProperty navigationProperty : navigationPropertyList) {
- methodName = getAccessModifierName(navigationProperty.getName(),
- navigationProperty.getMapping(), ACCESS_MODIFIER_GET);
- Method getterMethod = jpaEntity.getClass()
- .getDeclaredMethod(methodName, (Class<?>[]) null);
- getterMethod.setAccessible(true);
- result = getProperty(getterMethod, jpaEntity);
- navigationMap.put(navigationProperty.getName(), result);
- }
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- }
- return navigationMap;
- }
-
- public Method getAccessModifierSet(final Object jpaEntity, final String methodName) throws ODataJPARuntimeException {
- Class<?> jpaType = jpaEntity.getClass();
- String methodNameGet = ACCESS_MODIFIER_GET + methodName.substring(3);
- Method method = null;
-
- try {
- method = jpaType.getMethod(methodNameGet, (Class<?>[]) null);
- Class<?> parameterType = method.getReturnType();
- method = jpaType.getMethod(methodName, new Class<?>[] { parameterType });
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- return method;
- }
-
- public HashMap<String, Method> getAccessModifiers(final Object jpaEntity,
- final EdmStructuralType structuralType, final String accessModifier) throws ODataJPARuntimeException {
-
- HashMap<String, Method> accessModifierMap = new HashMap<String, Method>();
- HashMap<String, String> embeddableKey = new HashMap<String, String>();
- try {
- for (String propertyName : structuralType.getPropertyNames()) {
-
- EdmProperty property = (EdmProperty) structuralType
- .getProperty(propertyName);
-
- String name = getAccessModifierName(property.getName(),
- property.getMapping(), accessModifier);
- String[] nameParts = name.split("\\.");
- if (nameParts.length > 1) {
- embeddableKey.put(propertyName, name);
- } else {
- if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
- JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) property.getMapping();
- accessModifierMap.put(
- propertyName,
- jpaEntity.getClass().getMethod(name, new Class<?>[] { jpaEdmMapping.getJPAType() }));
- } else {
- accessModifierMap.put(
- propertyName,
- jpaEntity.getClass().getMethod(name,
- (Class<?>[]) null));
- }
- }
- }
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- if (!embeddableKey.isEmpty()) {
- jpaEmbeddableKeyMap.put(jpaEntity.getClass().getName(),
- embeddableKey);
- }
- return accessModifierMap;
- }
-
- public static Object getProperty(final Method method, final Object entity) throws ODataJPARuntimeException {
- Object propertyValue = null;
- try {
- Class<?> returnType = method.getReturnType();
-
- if (returnType.equals(char[].class)) {
- char[] ch = (char[]) method.invoke(entity);
- if (ch != null) {
- propertyValue = (String) String.valueOf((char[]) method.invoke(entity));
- }
- } else if (returnType.equals(Character[].class)) {
- propertyValue = (String) toString((Character[]) method.invoke(entity));
- } else if (returnType.equals(char.class)) {
- char c = (Character) method.invoke(entity);
- if (c != '\u0000') {
- propertyValue = (String) String.valueOf(c);
- }
- } else if (returnType.equals(Character.class)) {
- Character c = (Character) method.invoke(entity);
- if (c != null) {
- propertyValue = toString(new Character[] { c });
- }
- } else {
- propertyValue = method.invoke(entity);
- }
- } catch (IllegalAccessException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (InvocationTargetException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
- return propertyValue;
- }
-
- public static String toString(final Character[] input) {
- if (input == null) {
- return null;
- }
-
- StringBuilder builder = new StringBuilder();
- for (Character element : input) {
- if (element == null) {
- continue;
- }
- builder.append(element.charValue());
- }
- return builder.toString();
-
- }
-
- public static Character[] toCharacterArray(final String input) {
- if (input == null) {
- return null;
- }
-
- Character[] characters = new Character[input.length()];
- char[] chars = ((String) input).toCharArray();
- for (int i = 0; i < input.length(); i++) {
- characters[i] = new Character(chars[i]);
- }
-
- return characters;
- }
-
- public static String getAccessModifierName(final String propertyName, final EdmMapping mapping,
- final String accessModifier)
- throws ODataJPARuntimeException {
- String name = null;
- StringBuilder builder = new StringBuilder();
- String[] nameParts = {};
- if (mapping == null || mapping.getInternalName() == null) {
- name = propertyName;
- } else {
- name = mapping.getInternalName();
- }
- if (name != null) {
- nameParts = name.split("\\.");
- }
- if (nameParts.length == 1) {
- if (name != null) {
- char c = Character.toUpperCase(name.charAt(0));
-
- builder.append(accessModifier).append(c).append(name.substring(1))
- .toString();
- }
- } else if (nameParts.length > 1) {
-
- for (int i = 0; i < nameParts.length; i++) {
- name = nameParts[i];
- char c = Character.toUpperCase(name.charAt(0));
- if (i == 0) {
- builder.append(accessModifier).append(c).append(name.substring(1));
- } else {
- builder.append(".").append(accessModifier).append(c)
- .append(name.substring(1));
- }
- }
- } else {
- return null;
- }
-
- if (builder.length() > 0) {
- return builder.toString();
- } else {
- return null;
- }
-
- }
-
- public Method getAccessModifier(final Object jpaEntity, final EdmNavigationProperty navigationProperty,
- final String accessModifier)
- throws ODataJPARuntimeException {
-
- try {
-
- JPAEdmMapping navPropMapping = (JPAEdmMapping) navigationProperty.getMapping();
- String name = getAccessModifierName(navigationProperty.getName(), (EdmMapping) navPropMapping, accessModifier);
-
- Class<?>[] params = null;
- if (accessModifier.equals(ACCESS_MODIFIER_SET)) {
- EdmAssociationEnd end = navigationProperty.getRelationship().getEnd(navigationProperty.getToRole());
- switch (end.getMultiplicity()) {
- case MANY:
- params = new Class<?>[] { navPropMapping.getJPAType() };
- break;
- case ONE:
- params = new Class<?>[] { ((JPAEdmMapping) end.getEntityType().getMapping()).getJPAType() };
- default:
- break;
- }
- }
- return jpaEntity.getClass().getMethod(name,
- params);
-
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBack.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBack.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBack.java
deleted file mode 100644
index 78a9ea5..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAExpandCallBack.java
+++ /dev/null
@@ -1,180 +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.odata2.processor.core.jpa.access.data;
-
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties.ODataEntityProviderPropertiesBuilder;
-import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
-import org.apache.olingo.odata2.api.ep.callback.OnWriteFeedContent;
-import org.apache.olingo.odata2.api.ep.callback.WriteCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.NavigationPropertySegment;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-
-public class JPAExpandCallBack implements OnWriteFeedContent, OnWriteEntryContent, ODataCallback {
-
- private URI baseUri;
- private List<ArrayList<NavigationPropertySegment>> expandList;
- private EdmEntitySet nextEntitySet = null;
-
- private JPAExpandCallBack(final URI baseUri, final List<ArrayList<NavigationPropertySegment>> expandList) {
- super();
- this.baseUri = baseUri;
- this.expandList = expandList;
- }
-
- @Override
- public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context) {
- WriteEntryCallbackResult result = new WriteEntryCallbackResult();
- Map<String, Object> entry = context.getEntryData();
- Map<String, Object> edmPropertyValueMap = null;
- List<EdmNavigationProperty> currentNavPropertyList = null;
- Map<String, ExpandSelectTreeNode> navigationLinks = null;
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty();
- try {
- Object inlinedEntry = entry.get(currentNavigationProperty.getName());
- if (nextEntitySet == null) {
- nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty);
- }
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(inlinedEntry, nextEntitySet.getEntityType());
- result.setEntryData(edmPropertyValueMap);
- navigationLinks = context.getCurrentExpandSelectTreeNode().getLinks();
- if (navigationLinks.size() > 0) {
- currentNavPropertyList = new ArrayList<EdmNavigationProperty>();
- EdmNavigationProperty nextNavProperty =
- getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty());
- if (nextNavProperty != null) {
- currentNavPropertyList.add(nextNavProperty);
- }
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(inlinedEntry, currentNavPropertyList);
- edmPropertyValueMap.putAll(navigationMap);
- result.setEntryData(edmPropertyValueMap);
- }
- result.setInlineProperties(getInlineEntityProviderProperties(context));
- } catch (EdmException e) {
-
- } catch (ODataJPARuntimeException e) {
-
- }
-
- return result;
- }
-
- @Override
- public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context) {
- WriteFeedCallbackResult result = new WriteFeedCallbackResult();
- HashMap<String, Object> inlinedEntry = (HashMap<String, Object>) context.getEntryData();
- List<Map<String, Object>> edmEntityList = new ArrayList<Map<String, Object>>();
- Map<String, Object> edmPropertyValueMap = null;
- JPAEntityParser jpaResultParser = new JPAEntityParser();
- List<EdmNavigationProperty> currentNavPropertyList = null;
- EdmNavigationProperty currentNavigationProperty = context.getNavigationProperty();
- try {
- @SuppressWarnings({ "unchecked" })
- Collection<Object> listOfItems = (Collection<Object>) inlinedEntry.get(context.getNavigationProperty().getName());
- if (nextEntitySet == null) {
- nextEntitySet = context.getSourceEntitySet().getRelatedEntitySet(currentNavigationProperty);
- }
- for (Object object : listOfItems) {
- edmPropertyValueMap = jpaResultParser.parse2EdmPropertyValueMap(object, nextEntitySet.getEntityType());
- edmEntityList.add(edmPropertyValueMap);
- }
- result.setFeedData(edmEntityList);
- if (context.getCurrentExpandSelectTreeNode().getLinks().size() > 0) {
- currentNavPropertyList = new ArrayList<EdmNavigationProperty>();
- EdmNavigationProperty nextNavProperty =
- getNextNavigationProperty(context.getSourceEntitySet().getEntityType(), context.getNavigationProperty());
- if (nextNavProperty != null) {
- currentNavPropertyList.add(nextNavProperty);
- }
- int count = 0;
- for (Object object : listOfItems) {
- HashMap<String, Object> navigationMap =
- jpaResultParser.parse2EdmNavigationValueMap(object, currentNavPropertyList);
- edmEntityList.get(count).putAll(navigationMap);
- count++;
- }
- result.setFeedData(edmEntityList);
- }
- result.setInlineProperties(getInlineEntityProviderProperties(context));
- } catch (EdmException e) {
-
- } catch (ODataJPARuntimeException e) {
-
- }
- return result;
- }
-
- private EdmNavigationProperty getNextNavigationProperty(final EdmEntityType sourceEntityType,
- final EdmNavigationProperty navigationProperty) throws EdmException {
- for (ArrayList<NavigationPropertySegment> navPropSegments : expandList) {
- int size = navPropSegments.size();
- for (int i = 0; i < size; i++) {
- EdmNavigationProperty navProperty = navPropSegments.get(i).getNavigationProperty();
- if (navProperty.getFromRole().equalsIgnoreCase(sourceEntityType.getName())
- && navProperty.getName().equals(navigationProperty.getName())) {
- if (i < size - 1) {
- return navPropSegments.get(i + 1).getNavigationProperty();
- }
- }
- }
- }
- return null;
- }
-
- public static <T> Map<String, ODataCallback> getCallbacks(final URI baseUri,
- final ExpandSelectTreeNode expandSelectTreeNode, final List<ArrayList<NavigationPropertySegment>> expandList)
- throws EdmException {
- Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
-
- for (String navigationPropertyName : expandSelectTreeNode.getLinks().keySet()) {
- callbacks.put(navigationPropertyName, new JPAExpandCallBack(baseUri, expandList));
- }
-
- return callbacks;
-
- }
-
- private EntityProviderWriteProperties getInlineEntityProviderProperties(final WriteCallbackContext context)
- throws EdmException {
- ODataEntityProviderPropertiesBuilder propertiesBuilder = EntityProviderWriteProperties.serviceRoot(baseUri);
- propertiesBuilder.callbacks(getCallbacks(baseUri, context.getCurrentExpandSelectTreeNode(), expandList));
- propertiesBuilder.expandSelectTree(context.getCurrentExpandSelectTreeNode());
- return propertiesBuilder.build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContext.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContext.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContext.java
deleted file mode 100644
index 8f79c92..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAFunctionContext.java
+++ /dev/null
@@ -1,170 +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.odata2.processor.core.jpa.access.data;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFacets;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmLiteral;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmParameter;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAFunction;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.model.JPAEdmMapping;
-
-public class JPAFunctionContext extends JPAMethodContext {
-
- public class JPAFunctionContextBuilder extends JPAMethodContextBuilder {
-
- protected GetFunctionImportUriInfo functiontView;
- private EdmFunctionImport functionImport;
- private EdmMapping mapping;
-
- @Override
- public JPAMethodContext build() throws ODataJPAModelException, ODataJPARuntimeException {
- if (functiontView != null) {
-
- functionImport = functiontView.getFunctionImport();
- try {
- mapping = functionImport.getMapping();
-
- List<JPAFunction> jpaFunctionList = new ArrayList<JPAFunction>();
- jpaFunctionList.add(generateJPAFunction());
- setJpaFunction(jpaFunctionList);
- setEnclosingObject(generateEnclosingObject());
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (InstantiationException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (IllegalAccessException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (InvocationTargetException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (NoSuchMethodException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (SecurityException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- }
-
- return JPAFunctionContext.this;
- }
-
- private JPAFunction generateJPAFunction() throws EdmException, NoSuchMethodException, SecurityException,
- ODataJPAModelException, ODataJPARuntimeException {
-
- Class<?>[] parameterTypes = getParameterTypes();
- Method method = getMethod(parameterTypes);
- Type returnType = getReturnType();
- Object[] args = getAruguments();
-
- JPAFunction jpafunction = new JPAFunction(method, parameterTypes, returnType, args);
-
- return jpafunction;
- }
-
- private Object[] getAruguments() throws EdmException {
- Map<String, EdmLiteral> edmArguements = functiontView.getFunctionImportParameters();
-
- if (edmArguements == null) {
- return null;
- } else {
- Object[] args = new Object[edmArguements.size()];
- int i = 0;
- for (String paramName : functionImport.getParameterNames()) {
- EdmLiteral literal = edmArguements.get(paramName);
- EdmParameter parameter = functionImport.getParameter(paramName);
- JPAEdmMapping mapping = (JPAEdmMapping) parameter.getMapping();
- args[i] = convertArguement(literal, parameter.getFacets(), mapping.getJPAType());
- i++;
- }
- return args;
- }
-
- }
-
- private Object convertArguement(final EdmLiteral edmLiteral, final EdmFacets facets, final Class<?> targetType)
- throws EdmSimpleTypeException {
- EdmSimpleType edmType = edmLiteral.getType();
- Object value = edmType.valueOfString(edmLiteral.getLiteral(), EdmLiteralKind.DEFAULT, facets, targetType);
-
- return value;
- }
-
- private Class<?>[] getParameterTypes() throws EdmException {
-
- Class<?>[] parameterTypes = new Class<?>[functionImport.getParameterNames().size()];
- int i = 0;
- for (String parameterName : functionImport.getParameterNames()) {
- EdmParameter parameter = functionImport.getParameter(parameterName);
- parameterTypes[i] = ((JPAEdmMapping) parameter.getMapping()).getJPAType();
- i++;
- }
-
- return parameterTypes;
- }
-
- private Method getMethod(final Class<?>[] parameterTypes) throws NoSuchMethodException, SecurityException {
-
- Class<?> type = ((JPAEdmMapping) mapping).getJPAType();
- Method method;
- method = type.getMethod(mapping.getInternalName(), parameterTypes);
-
- return method;
- }
-
- private Type getReturnType() throws ODataJPAModelException, ODataJPARuntimeException, EdmException {
- return null;
- }
-
- private Object generateEnclosingObject() throws InstantiationException, IllegalAccessException,
- IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
-
- Class<?> type = ((JPAEdmMapping) mapping).getJPAType();
- Object[] params = null;
-
- return type.getConstructor((Class<?>[]) params).newInstance(params);
-
- }
-
- @Override
- protected void setResultsView(final Object resultsView) {
- if (resultsView instanceof GetFunctionImportUriInfo) {
- functiontView = (GetFunctionImportUriInfo) resultsView;
- }
-
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPALink.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPALink.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPALink.java
deleted file mode 100644
index 872a99b..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPALink.java
+++ /dev/null
@@ -1,225 +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.odata2.processor.core.jpa.access.data;
-
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityTransaction;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.factory.ODataJPAFactory;
-import org.apache.olingo.odata2.processor.core.jpa.ODataEntityParser;
-
-public class JPALink {
-
- private ODataJPAContext context;
- private JPAProcessor jpaProcessor;
- private ODataEntityParser parser;
- private Object targetJPAEntity;
- private Object sourceJPAEntity;
-
- public JPALink(final ODataJPAContext context) {
- this.context = context;
- jpaProcessor = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAProcessor(this.context);
- parser = new ODataEntityParser(this.context);
- }
-
- public void setSourceJPAEntity(final Object jpaEntity) {
- sourceJPAEntity = jpaEntity;
- }
-
- public void create(final PostUriInfo uriInfo, final InputStream content, final String requestContentType,
- final String contentType) throws ODataJPARuntimeException, ODataJPAModelException {
-
- EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
- String targerEntitySetName;
- EdmNavigationProperty navigationProperty = null;
- try {
- targerEntitySetName = targetEntitySet.getName();
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- List<UriInfo> uriInfoList = new ArrayList<UriInfo>();
-
- if (((UriInfo) uriInfo).isLinks()) {
- UriInfo getUriInfo = parser.parseLink(targetEntitySet, content, requestContentType);
- uriInfoList = new ArrayList<UriInfo>();
- uriInfoList.add(getUriInfo);
- navigationProperty = uriInfo.getNavigationSegments().get(0).getNavigationProperty();
- } else {
- uriInfoList = parser.parseLinks(targetEntitySet, content, contentType);
- }
-
- if (uriInfoList == null) {
- return;
- }
- try {
- for (UriInfo getUriInfo : uriInfoList) {
-
- if (!getUriInfo.getTargetEntitySet().getName().equals(targerEntitySetName)) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RELATIONSHIP_INVALID, null);
- }
- if (!((UriInfo) uriInfo).isLinks()) {
- navigationProperty = getUriInfo.getNavigationSegments().get(0).getNavigationProperty();
- }
-
- targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
- if (targetJPAEntity != null && ((UriInfo) uriInfo).isLinks()) {
- getUriInfo = parser.parseLinkURI();
- sourceJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
- if (sourceJPAEntity == null) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND
- .addContent(getUriInfo.getTargetEntitySet().getName()), null);
- }
- }
-
- JPAEntityParser entityParser = new JPAEntityParser();
- Method setMethod =
- entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
-
- Method getMethod =
- entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
-
- if (getMethod.getReturnType().getTypeParameters() != null) {
- @SuppressWarnings("unchecked")
- List<Object> relatedEntities = (List<Object>) getMethod.invoke(sourceJPAEntity);
- relatedEntities.add(targetJPAEntity);
- setMethod.invoke(sourceJPAEntity, relatedEntities);
- } else {
- setMethod.invoke(sourceJPAEntity, targetJPAEntity);
- }
- }
- } catch (IllegalAccessException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (InvocationTargetException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
- }
-
- public void delete() {}
-
- public void save() {
- EntityManager em = context.getEntityManager();
- EntityTransaction tx = em.getTransaction();
-
- if (!tx.isActive()) {
- em.getTransaction().begin();
- em.persist(sourceJPAEntity);
- em.getTransaction().commit();
- }
-
- }
-
- public void update(final PutMergePatchUriInfo putUriInfo, final InputStream content, final String requestContentType,
- final String contentType) throws ODataJPARuntimeException, ODataJPAModelException {
- UriInfo uriInfo = (UriInfo) putUriInfo;
-
- EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
- String targerEntitySetName;
- EdmNavigationProperty navigationProperty = null;
- try {
- targerEntitySetName = targetEntitySet.getName();
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- List<UriInfo> uriInfoList = new ArrayList<UriInfo>();
-
- if (((UriInfo) uriInfo).isLinks()) {
- UriInfo getUriInfo = parser.parseLink(targetEntitySet, content, requestContentType);
- uriInfoList = new ArrayList<UriInfo>();
- uriInfoList.add(getUriInfo);
- navigationProperty = uriInfo.getNavigationSegments().get(0).getNavigationProperty();
- } else {
- uriInfoList = parser.parseLinks(targetEntitySet, content, contentType);
- }
-
- if (uriInfoList == null) {
- return;
- }
- try {
- for (UriInfo getUriInfo : uriInfoList) {
-
- if (!getUriInfo.getTargetEntitySet().getName().equals(targerEntitySetName)) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RELATIONSHIP_INVALID, null);
- }
- if (!((UriInfo) uriInfo).isLinks()) {
- navigationProperty = getUriInfo.getNavigationSegments().get(0).getNavigationProperty();
- }
-
- targetJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
- if (targetJPAEntity != null && ((UriInfo) uriInfo).isLinks()) {
- getUriInfo = parser.parseLinkURI();
- sourceJPAEntity = jpaProcessor.process((GetEntityUriInfo) getUriInfo);
- if (sourceJPAEntity == null) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.RESOURCE_X_NOT_FOUND
- .addContent(getUriInfo.getTargetEntitySet().getName()), null);
- }
- }
-
- JPAEntityParser entityParser = new JPAEntityParser();
- Method setMethod =
- entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_SET);
-
- Method getMethod =
- entityParser.getAccessModifier(sourceJPAEntity, navigationProperty, JPAEntityParser.ACCESS_MODIFIER_GET);
-
- if (getMethod.getReturnType().getTypeParameters() != null
- && getMethod.getReturnType().getTypeParameters().length != 0) {
- @SuppressWarnings("unchecked")
- List<Object> relatedEntities = (List<Object>) getMethod.invoke(sourceJPAEntity);
- relatedEntities.add(targetJPAEntity);
- setMethod.invoke(sourceJPAEntity, relatedEntities);
- } else {
- setMethod.invoke(sourceJPAEntity, targetJPAEntity);
- }
- }
- } catch (IllegalAccessException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (InvocationTargetException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- } catch (EdmException e) {
- throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
deleted file mode 100644
index 8501b77..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/data/JPAProcessorImpl.java
+++ /dev/null
@@ -1,491 +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.odata2.processor.core.jpa.access.data;
-
-import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAFunction;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAMethodContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAProcessor;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContext;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLContextType;
-import org.apache.olingo.odata2.processor.api.jpa.jpql.JPQLStatement;
-import org.apache.olingo.odata2.processor.core.jpa.ODataEntityParser;
-
-public class JPAProcessorImpl implements JPAProcessor {
-
- ODataJPAContext oDataJPAContext;
- EntityManager em;
-
- public JPAProcessorImpl(final ODataJPAContext oDataJPAContext) {
- this.oDataJPAContext = oDataJPAContext;
- em = oDataJPAContext.getEntityManager();
- }
-
- /* Process Function Import Request */
- @SuppressWarnings("unchecked")
- @Override
- public List<Object> process(final GetFunctionImportUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException {
-
- JPAMethodContext jpaMethodContext = JPAMethodContext.createBuilder(
- JPQLContextType.FUNCTION, uriParserResultView).build();
-
- List<Object> resultObj = null;
-
- try {
-
- JPAFunction jpaFunction = jpaMethodContext.getJPAFunctionList()
- .get(0);
- Method method = jpaFunction.getFunction();
- Object[] args = jpaFunction.getArguments();
-
- if (uriParserResultView.getFunctionImport().getReturnType()
- .getMultiplicity().equals(EdmMultiplicity.MANY)) {
-
- resultObj = (List<Object>) method.invoke(
- jpaMethodContext.getEnclosingObject(), args);
- } else {
- resultObj = new ArrayList<Object>();
- Object result = method.invoke(
- jpaMethodContext.getEnclosingObject(), args);
- resultObj.add(result);
- }
-
- } catch (EdmException e) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL
- .addContent(e.getMessage()), e);
- } catch (IllegalAccessException e) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL
- .addContent(e.getMessage()), e);
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL
- .addContent(e.getMessage()), e);
- } catch (InvocationTargetException e) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.GENERAL
- .addContent(e.getTargetException().getMessage()), e.getTargetException());
- }
-
- return resultObj;
- }
-
- /* Process Get Entity Set Request (Query) */
- @SuppressWarnings("unchecked")
- @Override
- public <T> List<T> process(final GetEntitySetUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException {
-
- if (uriParserResultView.getFunctionImport() != null) {
- return (List<T>) process((GetFunctionImportUriInfo) uriParserResultView);
- }
- JPQLContextType contextType = null;
- try {
- if (!uriParserResultView.getStartEntitySet().getName()
- .equals(uriParserResultView.getTargetEntitySet().getName())) {
- contextType = JPQLContextType.JOIN;
- } else {
- contextType = JPQLContextType.SELECT;
- }
-
- } catch (EdmException e) {
- ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.GENERAL, e);
- }
-
- JPQLContext jpqlContext = JPQLContext.createBuilder(contextType,
- uriParserResultView).build();
-
- JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext)
- .build();
- Query query = null;
- try {
- query = em.createQuery(jpqlStatement.toString());
- // $top/$skip with $inlinecount case handled in response builder to avoid multiple DB call
- if (uriParserResultView.getSkip() != null && uriParserResultView.getInlineCount() == null) {
- query.setFirstResult(uriParserResultView.getSkip());
- }
-
- if (uriParserResultView.getTop() != null && uriParserResultView.getInlineCount() == null) {
- if (uriParserResultView.getTop() == 0) {
- List<T> resultList = new ArrayList<T>();
- return resultList;
- } else {
- query.setMaxResults(uriParserResultView.getTop());
- }
- }
- return query.getResultList();
- } catch (Exception e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
-
- }
- }
-
- /* Process Get Entity Request (Read) */
- @Override
- public <T> Object process(GetEntityUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException {
-
- JPQLContextType contextType = null;
- try {
- if (uriParserResultView instanceof GetEntityUriInfo) {
- uriParserResultView = ((GetEntityUriInfo) uriParserResultView);
- if (!((GetEntityUriInfo) uriParserResultView).getStartEntitySet().getName()
- .equals(((GetEntityUriInfo) uriParserResultView).getTargetEntitySet().getName())) {
- contextType = JPQLContextType.JOIN_SINGLE;
- } else {
- contextType = JPQLContextType.SELECT_SINGLE;
- }
- }
- } catch (EdmException e) {
- ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.GENERAL, e);
- }
-
- return readEntity(uriParserResultView, contextType);
- }
-
- /* Process $count for Get Entity Set Request */
- @Override
- public long process(final GetEntitySetCountUriInfo resultsView)
- throws ODataJPAModelException, ODataJPARuntimeException {
-
- JPQLContextType contextType = null;
- try {
- if (!resultsView.getStartEntitySet().getName()
- .equals(resultsView.getTargetEntitySet().getName())) {
- contextType = JPQLContextType.JOIN_COUNT;
- } else {
- contextType = JPQLContextType.SELECT_COUNT;
- }
- } catch (EdmException e) {
- ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.GENERAL, e);
- }
-
- JPQLContext jpqlContext = JPQLContext.createBuilder(contextType,
- resultsView).build();
-
- JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext)
- .build();
- Query query = null;
- try {
-
- query = em.createQuery(jpqlStatement.toString());
- List<?> resultList = query.getResultList();
- if (resultList != null && resultList.size() == 1) {
- return Long.valueOf(resultList.get(0).toString());
- }
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
- }
- return 0;
- }
-
- /* Process $count for Get Entity Request */
- @Override
- public long process(final GetEntityCountUriInfo resultsView) throws ODataJPAModelException, ODataJPARuntimeException {
-
- JPQLContextType contextType = null;
- try {
- if (!resultsView.getStartEntitySet().getName()
- .equals(resultsView.getTargetEntitySet().getName())) {
- contextType = JPQLContextType.JOIN_COUNT;
- } else {
- contextType = JPQLContextType.SELECT_COUNT;
- }
- } catch (EdmException e) {
- ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.GENERAL, e);
- }
-
- JPQLContext jpqlContext = JPQLContext.createBuilder(contextType,
- resultsView).build();
-
- JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext)
- .build();
- Query query = null;
- try {
-
- query = em.createQuery(jpqlStatement.toString());
- List<?> resultList = query.getResultList();
- if (resultList != null && resultList.size() == 1) {
- return Long.valueOf(resultList.get(0).toString());
- }
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
- }
-
- return 0;
- }
-
- /* Process Create Entity Request */
- @Override
- public <T> List<T> process(final PostUriInfo createView, final InputStream content,
- final String requestedContentType) throws ODataJPAModelException,
- ODataJPARuntimeException {
- return processCreate(createView, content, null, requestedContentType);
- }
-
- @Override
- public <T> List<T> process(final PostUriInfo createView, final Map<String, Object> content)
- throws ODataJPAModelException, ODataJPARuntimeException {
- return processCreate(createView, null, content, null);
- }
-
- /* Process Update Entity Request */
- @Override
- public <T> Object process(final PutMergePatchUriInfo updateView,
- final InputStream content, final String requestContentType)
- throws ODataJPAModelException, ODataJPARuntimeException {
- return processUpdate(updateView, content, null, requestContentType);
- }
-
- @Override
- public <T> Object process(final PutMergePatchUriInfo updateView, final Map<String, Object> content)
- throws ODataJPAModelException, ODataJPARuntimeException {
- return processUpdate(updateView, null, content, null);
- }
-
- @SuppressWarnings("unchecked")
- private <T> List<T> processCreate(final PostUriInfo createView, final InputStream content,
- final Map<String, Object> properties,
- final String requestedContentType) throws ODataJPAModelException,
- ODataJPARuntimeException {
- try {
-
- final EdmEntitySet oDataEntitySet = createView.getTargetEntitySet();
- final EdmEntityType oDataEntityType = oDataEntitySet.getEntityType();
- final JPAEntity virtualJPAEntity = new JPAEntity(oDataEntityType, oDataEntitySet);
- final List<Object> createList = new ArrayList<Object>();
- Object jpaEntity = null;
-
- if (content != null) {
- final ODataEntityParser oDataEntityParser = new ODataEntityParser(oDataJPAContext);
- final ODataEntry oDataEntry =
- oDataEntityParser.parseEntry(oDataEntitySet, content, requestedContentType, false);
- virtualJPAEntity.create(oDataEntry);
- JPALink link = new JPALink(oDataJPAContext);
- link.setSourceJPAEntity(jpaEntity);
- link.create(createView, content, requestedContentType, requestedContentType);
- } else if (properties != null) {
- virtualJPAEntity.create(properties);
- } else {
- return null;
- }
-
- em.getTransaction().begin();
- jpaEntity = virtualJPAEntity.getJPAEntity();
-
- em.persist(jpaEntity);
- if (em.contains(jpaEntity)) {
- em.getTransaction().commit();
-
- createList.add(virtualJPAEntity.getJPAEntity());
- createList.add(virtualJPAEntity.getInlineJPAEntities());
-
- return (List<T>) createList;
- }
- } catch (Exception e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_CREATE_REQUEST, e);
- }
- return null;
- }
-
- public <T> Object processUpdate(PutMergePatchUriInfo updateView,
- final InputStream content, final Map<String, Object> properties, final String requestContentType)
- throws ODataJPAModelException, ODataJPARuntimeException {
- JPQLContextType contextType = null;
- Object jpaEntity = null;
- try {
- em.getTransaction().begin();
- if (updateView instanceof PutMergePatchUriInfo) {
- updateView = ((PutMergePatchUriInfo) updateView);
- if (!((PutMergePatchUriInfo) updateView).getStartEntitySet().getName()
- .equals(((PutMergePatchUriInfo) updateView).getTargetEntitySet().getName())) {
- contextType = JPQLContextType.JOIN_SINGLE;
- } else {
- contextType = JPQLContextType.SELECT_SINGLE;
- }
- }
-
- jpaEntity = readEntity(updateView, contextType);
-
- if (jpaEntity == null) {
- throw ODataJPARuntimeException
- .throwException(ODataJPARuntimeException.RESOURCE_NOT_FOUND, null);
- }
-
- final EdmEntitySet oDataEntitySet = updateView.getTargetEntitySet();
- final EdmEntityType oDataEntityType = oDataEntitySet.getEntityType();
- final JPAEntity virtualJPAEntity = new JPAEntity(oDataEntityType, oDataEntitySet);
- virtualJPAEntity.setJPAEntity(jpaEntity);
-
- if (content != null) {
- final ODataEntityParser oDataEntityParser = new ODataEntityParser(oDataJPAContext);
- final ODataEntry oDataEntry = oDataEntityParser.parseEntry(oDataEntitySet, content, requestContentType, false);
- virtualJPAEntity.update(oDataEntry);
- } else if (properties != null) {
- virtualJPAEntity.update(properties);
- } else {
- return null;
- }
- em.flush();
- em.getTransaction().commit();
- } catch (Exception e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_UPDATE_REQUEST, e);
- }
-
- return jpaEntity;
- }
-
- /* Process Delete Entity Request */
- @Override
- public Object process(DeleteUriInfo uriParserResultView, final String contentType)
- throws ODataJPAModelException, ODataJPARuntimeException {
- JPQLContextType contextType = null;
- try {
- if (uriParserResultView instanceof DeleteUriInfo) {
- uriParserResultView = ((DeleteUriInfo) uriParserResultView);
- if (!((DeleteUriInfo) uriParserResultView).getStartEntitySet().getName()
- .equals(((DeleteUriInfo) uriParserResultView).getTargetEntitySet().getName())) {
- contextType = JPQLContextType.JOIN_SINGLE;
- } else {
- contextType = JPQLContextType.SELECT_SINGLE;
- }
- }
- } catch (EdmException e) {
- ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.GENERAL, e);
- }
-
- // First read the entity with read operation.
- Object selectedObject = readEntity(uriParserResultView, contextType);
- // Read operation done. This object would be passed on to entity manager for delete
- if (selectedObject != null) {
- try {
- em.getTransaction().begin();
- em.remove(selectedObject);
- em.flush();
- em.getTransaction().commit();
- } catch (Exception e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_DELETE_REQUEST, e);
- }
- }
- return selectedObject;
- }
-
- /* Process Get Entity Link Request */
- @Override
- public Object process(final GetEntityLinkUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException {
-
- return this.process((GetEntityUriInfo) uriParserResultView);
- }
-
- /* Process Get Entity Set Link Request */
- @Override
- public <T> List<T> process(final GetEntitySetLinksUriInfo uriParserResultView)
- throws ODataJPAModelException, ODataJPARuntimeException {
- return this.process((GetEntitySetUriInfo) uriParserResultView);
- }
-
- @Override
- public void process(final PostUriInfo uriInfo,
- final InputStream content, final String requestContentType, final String contentType)
- throws ODataJPARuntimeException, ODataJPAModelException {
- JPALink link = new JPALink(oDataJPAContext);
- link.create(uriInfo, content, requestContentType, contentType);
- link.save();
- }
-
- /* Common method for Read and Delete */
- private Object readEntity(final Object uriParserResultView, final JPQLContextType contextType)
- throws ODataJPAModelException, ODataJPARuntimeException {
-
- Object selectedObject = null;
-
- if (uriParserResultView instanceof DeleteUriInfo || uriParserResultView instanceof GetEntityUriInfo
- || uriParserResultView instanceof PutMergePatchUriInfo) {
-
- JPQLContext selectJPQLContext = JPQLContext.createBuilder(
- contextType, uriParserResultView).build();
-
- JPQLStatement selectJPQLStatement = JPQLStatement.createBuilder(
- selectJPQLContext).build();
- Query query = null;
- try {
- query = em.createQuery(selectJPQLStatement.toString());
- if (!query.getResultList().isEmpty()) {
- selectedObject = query.getResultList().get(0);
- }
- } catch (IllegalArgumentException e) {
- throw ODataJPARuntimeException.throwException(
- ODataJPARuntimeException.ERROR_JPQL_QUERY_CREATE, e);
- }
- }
- return selectedObject;
- }
-
- @Override
- public void process(final PutMergePatchUriInfo putUriInfo,
- final InputStream content, final String requestContentType, final String contentType)
- throws ODataJPARuntimeException, ODataJPAModelException {
-
- JPALink link = new JPALink(oDataJPAContext);
- link.update(putUriInfo, content, requestContentType, contentType);
- link.save();
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/EdmTypeConvertor.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/EdmTypeConvertor.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/EdmTypeConvertor.java
deleted file mode 100644
index f3c3e88..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/EdmTypeConvertor.java
+++ /dev/null
@@ -1,69 +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.odata2.processor.core.jpa.access.model;
-
-import java.math.BigDecimal;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
-
-public class EdmTypeConvertor {
-
- public static Class<?> convertToJavaType(final EdmType edmType) throws ODataJPAModelException,
- ODataJPARuntimeException {
- if (edmType instanceof EdmSimpleType) {
- EdmSimpleType edmSimpleType = (EdmSimpleType) edmType;
- if (edmSimpleType == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()) {
- return String.class;
- } else if (edmSimpleType == EdmSimpleTypeKind.Int64.getEdmSimpleTypeInstance()) {
- return Long.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.Int16.getEdmSimpleTypeInstance()) {
- return Short.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.Int32.getEdmSimpleTypeInstance()) {
- return Integer.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()) {
- return Double.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Float.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()) {
- return BigDecimal.class;
- } else if (edmSimpleType == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) {
- return byte[].class;
- } else if (edmSimpleType == EdmSimpleTypeKind.Byte.getEdmSimpleTypeInstance()) {
- return Byte.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance()) {
- return Boolean.TYPE;
- } else if (edmSimpleType == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()) {
- return Date.class;
- } else if (edmSimpleType == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()) {
- return Calendar.class;
- } else if (edmSimpleType == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()) {
- return UUID.class;
- }
- }
- throw ODataJPAModelException.throwException(ODataJPAModelException.TYPE_NOT_SUPPORTED
- .addContent(edmType.toString()), null);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/63b621a8/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelService.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelService.java b/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelService.java
deleted file mode 100644
index d00638e..0000000
--- a/odata2-jpa-processor/jpa-core/src/main/java/org/apache/olingo/odata2/processor/core/jpa/access/model/JPAEdmMappingModelService.java
+++ /dev/null
@@ -1,247 +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.odata2.processor.core.jpa.access.model;
-
-import java.io.InputStream;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
-
-import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
-import org.apache.olingo.odata2.processor.api.jpa.access.JPAEdmMappingModelAccess;
-import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPAModelException;
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAAttributeMapType.JPAAttribute;
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEdmMappingModel;
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEmbeddableTypeMapType;
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAEntityTypeMapType;
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPAPersistenceUnitMapType;
-import org.apache.olingo.odata2.processor.api.jpa.model.mapping.JPARelationshipMapType.JPARelationship;
-
-public class JPAEdmMappingModelService implements JPAEdmMappingModelAccess {
-
- boolean mappingModelExists = true;
- private JPAEdmMappingModel mappingModel;
- private String mappingModelName;
-
- public JPAEdmMappingModelService(final ODataJPAContext ctx) {
- mappingModelName = ctx.getJPAEdmMappingModel();
- if (mappingModelName == null) {
- mappingModelExists = false;
- }
- }
-
- @Override
- public void loadMappingModel() {
-
- if (mappingModelExists) {
- JAXBContext context;
- try {
- context = JAXBContext.newInstance(JPAEdmMappingModel.class);
-
- Unmarshaller unmarshaller = context.createUnmarshaller();
- InputStream is = loadMappingModelInputStream();
- if (is == null) {
- mappingModelExists = false;
- return;
- }
-
- mappingModel = (JPAEdmMappingModel) unmarshaller.unmarshal(is);
-
- if (mappingModel != null) {
- mappingModelExists = true;
- }
-
- } catch (JAXBException e) {
- mappingModelExists = false;
- ODataJPAModelException.throwException(ODataJPAModelException.GENERAL, e);
- }
- }
- }
-
- @Override
- public boolean isMappingModelExists() {
- return mappingModelExists;
- }
-
- @Override
- public JPAEdmMappingModel getJPAEdmMappingModel() {
- return mappingModel;
- }
-
- @Override
- public String mapJPAPersistenceUnit(final String persistenceUnitName) {
-
- JPAPersistenceUnitMapType persistenceUnit = mappingModel.getPersistenceUnit();
- if (persistenceUnit.getName().equals(persistenceUnitName)) {
- return persistenceUnit.getEDMSchemaNamespace();
- }
-
- return null;
- }
-
- @Override
- public String mapJPAEntityType(final String jpaEntityTypeName) {
-
- JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
- if (jpaEntityTypeMap != null) {
- return jpaEntityTypeMap.getEDMEntityType();
- } else {
- return null;
- }
- }
-
- @Override
- public String mapJPAEntitySet(final String jpaEntityTypeName) {
- JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
- if (jpaEntityTypeMap != null) {
- return jpaEntityTypeMap.getEDMEntitySet();
- } else {
- return null;
- }
- }
-
- @Override
- public String mapJPAAttribute(final String jpaEntityTypeName, final String jpaAttributeName) {
- JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
- if (jpaEntityTypeMap != null && jpaEntityTypeMap.getJPAAttributes() != null) {
- // fixing attributes
- // removal issue
- // from mapping
- for (JPAAttribute jpaAttribute : jpaEntityTypeMap.getJPAAttributes().getJPAAttribute()) {
- if (jpaAttribute.getName().equals(jpaAttributeName)) {
- return jpaAttribute.getValue();
- }
- }
- }
-
- return null;
- }
-
- @Override
- public String mapJPARelationship(final String jpaEntityTypeName, final String jpaRelationshipName) {
- JPAEntityTypeMapType jpaEntityTypeMap = searchJPAEntityTypeMapType(jpaEntityTypeName);
- if (jpaEntityTypeMap != null && jpaEntityTypeMap.getJPARelationships() != null) {
- for (JPARelationship jpaRealtionship : jpaEntityTypeMap.getJPARelationships().getJPARelationship()) {
- if (jpaRealtionship.getName().equals(jpaRelationshipName)) {
- return jpaRealtionship.getValue();
- }
- }
- }
-
- return null;
- }
-
- @Override
- public String mapJPAEmbeddableType(final String jpaEmbeddableTypeName) {
- JPAEmbeddableTypeMapType jpaEmbeddableType = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
- if (jpaEmbeddableType != null) {
- return jpaEmbeddableType.getEDMComplexType();
- } else {
- return null;
- }
- }
-
- @Override
- public String mapJPAEmbeddableTypeAttribute(final String jpaEmbeddableTypeName, final String jpaAttributeName) {
- JPAEmbeddableTypeMapType jpaEmbeddableType = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
- if (jpaEmbeddableType != null && jpaEmbeddableType.getJPAAttributes() != null) {
- for (JPAAttribute jpaAttribute : jpaEmbeddableType.getJPAAttributes().getJPAAttribute()) {
- if (jpaAttribute.getName().equals(jpaAttributeName)) {
- return jpaAttribute.getValue();
- }
- }
- }
- return null;
- }
-
- private JPAEntityTypeMapType searchJPAEntityTypeMapType(final String jpaEntityTypeName) {
- for (JPAEntityTypeMapType jpaEntityType : mappingModel.getPersistenceUnit().getJPAEntityTypes()
- .getJPAEntityType()) {
- if (jpaEntityType.getName().equals(jpaEntityTypeName)) {
- return jpaEntityType;
- }
- }
-
- return null;
- }
-
- private JPAEmbeddableTypeMapType searchJPAEmbeddableTypeMapType(final String jpaEmbeddableTypeName) {
- for (JPAEmbeddableTypeMapType jpaEmbeddableType : mappingModel.getPersistenceUnit().getJPAEmbeddableTypes()
- .getJPAEmbeddableType()) {
- if (jpaEmbeddableType.getName().equals(jpaEmbeddableTypeName)) {
- return jpaEmbeddableType;
- }
- }
-
- return null;
- }
-
- protected InputStream loadMappingModelInputStream() {
- InputStream is = JPAEdmMappingModelService.class.getClassLoader().getResourceAsStream("../../" + mappingModelName);
-
- return is;
-
- }
-
- @Override
- public boolean checkExclusionOfJPAEntityType(final String jpaEntityTypeName) {
- JPAEntityTypeMapType type = searchJPAEntityTypeMapType(jpaEntityTypeName);
- if (type != null) {
- return type.isExclude();
- }
- return false;
- }
-
- @Override
- public boolean checkExclusionOfJPAAttributeType(final String jpaEntityTypeName, final String jpaAttributeName) {
- JPAEntityTypeMapType type = searchJPAEntityTypeMapType(jpaEntityTypeName);
- if (type != null && type.getJPAAttributes() != null) {
- for (JPAAttribute jpaAttribute : type.getJPAAttributes().getJPAAttribute()) {
- if (jpaAttribute.getName().equals(jpaAttributeName)) {
- return jpaAttribute.isExclude();
- }
- }
- }
- return false;
- }
-
- @Override
- public boolean checkExclusionOfJPAEmbeddableType(final String jpaEmbeddableTypeName) {
- JPAEmbeddableTypeMapType type = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
- if (type != null) {
- return type.isExclude();
- }
- return false;
- }
-
- @Override
- public boolean checkExclusionOfJPAEmbeddableAttributeType(final String jpaEmbeddableTypeName,
- final String jpaAttributeName) {
- JPAEmbeddableTypeMapType type = searchJPAEmbeddableTypeMapType(jpaEmbeddableTypeName);
- if (type != null && type.getJPAAttributes() != null) {
- for (JPAAttribute jpaAttribute : type.getJPAAttributes().getJPAAttribute()) {
- if (jpaAttribute.getName().equals(jpaAttributeName)) {
- return jpaAttribute.isExclude();
- }
- }
- }
- return false;
- }
-}