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 2013/12/19 16:31:38 UTC
[27/50] [abbrv] [OLINGO-82] Renamed the project folder name to
odata2-jpa-processor
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/pom.xml b/odata2-jpa-processor/jpa-ref/pom.xml
new file mode 100644
index 0000000..bdf3ee6
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/pom.xml
@@ -0,0 +1,109 @@
+<?xml version="1.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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-jpa-processor-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>olingo-odata2-jpa-processor-ref-incubating</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>bundle-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ *
+ </Import-Package>
+ <Export-Package>
+ org.apache.olingo.odata2.jpa.processor.ref.factory;version=${project.version},
+ </Export-Package>
+ <Bundle-DocURL>${project.url}</Bundle-DocURL>
+ <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- JPA Support -->
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>eclipselink</artifactId>
+ <version>${version.eclipselink}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>javax.persistence</artifactId>
+ <version>2.0.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <version>1.8.0.10</version>
+ </dependency>
+
+ <!-- OData Annotation Support -->
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- JUnits -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/exception/InvalidPartyRoleException.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/exception/InvalidPartyRoleException.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/exception/InvalidPartyRoleException.java
new file mode 100644
index 0000000..3eb7d5a
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/exception/InvalidPartyRoleException.java
@@ -0,0 +1,10 @@
+package org.apache.olingo.odata2.jpa.processor.ref.exception;
+
+public class InvalidPartyRoleException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/factory/JPAEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/factory/JPAEntityManagerFactory.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/factory/JPAEntityManagerFactory.java
new file mode 100644
index 0000000..1f4a7a8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/factory/JPAEntityManagerFactory.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.ref.factory;
+
+import java.util.HashMap;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+public class JPAEntityManagerFactory {
+ private static HashMap<String, EntityManagerFactory> emfMap;
+
+ public static EntityManagerFactory getEntityManagerFactory(final String pUnit) {
+ if (pUnit == null) {
+ return null;
+ }
+ if (emfMap == null) {
+ emfMap = new HashMap<String, EntityManagerFactory>();
+ }
+
+ if (emfMap.containsKey(pUnit)) {
+ return emfMap.get(pUnit);
+ } else {
+ EntityManagerFactory emf = Persistence.createEntityManagerFactory(pUnit);
+ emfMap.put(pUnit, emf);
+ return emf;
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Activity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Activity.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Activity.java
new file mode 100644
index 0000000..c20e5b8
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Activity.java
@@ -0,0 +1,59 @@
+package org.apache.olingo.odata2.jpa.processor.ref.model;
+
+import java.util.Calendar;
+
+import javax.persistence.Column;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@MappedSuperclass
+public abstract class Activity {
+
+ @Column(name = "ACTIVITY_ID")
+ @Id
+ protected long id;
+
+ @Column
+ protected String subject;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ protected Calendar creationDate;
+
+ @Column
+ protected String note;
+
+ public Calendar getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(final Calendar creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public String getNote() {
+ return note;
+ }
+
+ public void setNote(final String note) {
+ this.note = note;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(final long id) {
+ this.id = id;
+ }
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(final String subject) {
+ this.subject = subject;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/ActivityParty.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/ActivityParty.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/ActivityParty.java
new file mode 100644
index 0000000..c92908c
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/ActivityParty.java
@@ -0,0 +1,46 @@
+package org.apache.olingo.odata2.jpa.processor.ref.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+@Entity
+public class ActivityParty {
+
+ @Id
+ @Column(name = "PARTY_ID")
+ private long id;
+
+ @Column(name = "ACTIVITY_ID")
+ private long activityId;
+
+ @Column
+ private String name;
+ @Column
+ private short role;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public short getRole() {
+ return role;
+ }
+
+ public void setRole(final short role) {
+ this.role = role;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(final long id) {
+ this.id = id;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Address.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Address.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Address.java
new file mode 100644
index 0000000..a0aabcb
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Address.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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.model;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Address {
+
+ public Address() {
+ super();
+ }
+
+ public Address(final short houseNumber, final String streetName, final String city,
+ final String country) {
+ this();
+ this.houseNumber = houseNumber;
+ this.streetName = streetName;
+ this.city = city;
+ this.country = country;
+ }
+
+ @Column(name = "HOUSE_NUMBER")
+ private short houseNumber;
+
+ @Column(name = "STREET_NAME")
+ private String streetName;
+
+ @Column(name = "CITY")
+ private String city;
+
+ @Column(name = "COUNTRY")
+ private String country;
+
+ public short getHouseNumber() {
+ return houseNumber;
+ }
+
+ public void setHouseNumber(final short houseNumber) {
+ this.houseNumber = houseNumber;
+ }
+
+ public String getStreetName() {
+ return streetName;
+ }
+
+ public void setStreetName(final String streetName) {
+ this.streetName = streetName;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(final String city) {
+ this.city = city;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/AppointmentActivity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/AppointmentActivity.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/AppointmentActivity.java
new file mode 100644
index 0000000..aafedb2
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/AppointmentActivity.java
@@ -0,0 +1,44 @@
+package org.apache.olingo.odata2.jpa.processor.ref.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.PrePersist;
+
+import org.apache.olingo.odata2.jpa.processor.ref.exception.InvalidPartyRoleException;
+
+@Entity
+public class AppointmentActivity extends Activity {
+
+ @OneToMany(cascade = CascadeType.ALL)
+ private List<ActivityParty> parties = new ArrayList<ActivityParty>();
+
+ public List<ActivityParty> getParties() {
+ return parties;
+ }
+
+ public void setParties(final List<ActivityParty> parties) {
+ this.parties = parties;
+ }
+
+ @PrePersist
+ public void validatePartyRoles() throws InvalidPartyRoleException {
+ boolean maxOrganizer = false;
+ for (ActivityParty party : getParties()) {
+ Short role = party.getRole();
+ if (role != PartyRole.ATTENDEE.ordinal() ||
+ role != PartyRole.ORGANIZER.ordinal()) {
+ throw new InvalidPartyRoleException();
+ }
+ if (role == PartyRole.ORGANIZER.ordinal() && maxOrganizer == false) {
+ maxOrganizer = true;
+ } else if (role == PartyRole.ORGANIZER.ordinal() && maxOrganizer == true) {
+ throw new InvalidPartyRoleException();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/EmailActivity.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/EmailActivity.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/EmailActivity.java
new file mode 100644
index 0000000..521d124
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/EmailActivity.java
@@ -0,0 +1,46 @@
+package org.apache.olingo.odata2.jpa.processor.ref.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.OneToMany;
+import javax.persistence.PrePersist;
+
+import org.apache.olingo.odata2.jpa.processor.ref.exception.InvalidPartyRoleException;
+
+@Entity
+public class EmailActivity extends Activity {
+
+ @OneToMany(cascade = CascadeType.ALL)
+ private List<ActivityParty> parties = new ArrayList<ActivityParty>();
+
+ public List<ActivityParty> getParties() {
+ return parties;
+ }
+
+ public void setParties(final List<ActivityParty> parties) {
+ this.parties = parties;
+ }
+
+ @PrePersist
+ public void validatePartyRoles() throws InvalidPartyRoleException {
+ boolean maxFrom = false;
+ for (ActivityParty party : getParties()) {
+ Short role = party.getRole();
+ if (role != PartyRole.FROM.ordinal() ||
+ role != PartyRole.TO.ordinal() ||
+ role != PartyRole.CC.ordinal() ||
+ role != PartyRole.BCC.ordinal()) {
+ throw new InvalidPartyRoleException();
+ }
+ if (role == PartyRole.FROM.ordinal() && maxFrom == false) {
+ maxFrom = true;
+ } else if (role == PartyRole.FROM.ordinal() && maxFrom == true) {
+ throw new InvalidPartyRoleException();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Material.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Material.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Material.java
new file mode 100644
index 0000000..6f08119
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Material.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "T_MATERIAL")
+public class Material {
+
+ public Material() {}
+
+ public Material(final String materialName, final String typeCode, final double price,
+ final String measurementUnit) {
+ super();
+ this.materialName = materialName;
+ this.typeCode = typeCode;
+ this.price = price;
+ this.measurementUnit = measurementUnit;
+ }
+
+ @Id
+ @Column(name = "MATERIAL_ID")
+ private long materialId;
+
+ @Column(name = "MATERIAL_NAME")
+ private String materialName;
+
+ @Column(name = "TYPE_CODE")
+ private String typeCode;
+
+ @Column(name = "PRICE")
+ private double price;
+
+ @Column(name = "MEASUREMENT_UNIT")
+ private String measurementUnit;
+
+ @ManyToMany
+ private List<Store> stores = new ArrayList<Store>();
+
+ public long getMaterialId() {
+ return materialId;
+ }
+
+ public void setMaterialId(final long materialId) {
+ this.materialId = materialId;
+ }
+
+ public String getMaterialName() {
+ return materialName;
+ }
+
+ public void setMaterialName(final String materialName) {
+ this.materialName = materialName;
+ }
+
+ public String getTypeCode() {
+ return typeCode;
+ }
+
+ public void setTypeCode(final String typeCode) {
+ this.typeCode = typeCode;
+ }
+
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(final double price) {
+ this.price = price;
+ }
+
+ public String getMeasurementUnit() {
+ return measurementUnit;
+ }
+
+ public void setMeasurementUnit(final String measurementUnit) {
+ this.measurementUnit = measurementUnit;
+ }
+
+ public List<Store> getStores() {
+ return stores;
+ }
+
+ public void setStores(final List<Store> stores) {
+ this.stores = stores;
+ Iterator<Store> itr = stores.iterator();
+ while (itr.hasNext()) {
+ itr.next().getMaterials().add(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Note.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Note.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Note.java
new file mode 100644
index 0000000..4a93509
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Note.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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.model;
+
+import java.util.Calendar;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name = "T_NOTE")
+public class Note {
+
+ public Note() {}
+
+ public Note(final Calendar creationTime, final Calendar creationDate, final String createdBy,
+ final String text) {
+ super();
+ this.creationTime = creationTime;
+ this.creationDate = creationDate;
+ this.createdBy = createdBy;
+ this.text = text;
+ }
+
+ @Id
+ @Temporal(TemporalType.TIME)
+ private Calendar creationTime;
+
+ @Id
+ @Temporal(TemporalType.DATE)
+ private Calendar creationDate;
+
+ @Id
+ private String createdBy;
+
+ @Column
+ private String text;
+
+ @Column(name = "SO_ID")
+ private long soId;
+
+ @JoinColumn(name = "SO_ID", referencedColumnName = "SO_ID", insertable = false, updatable = false)
+ @ManyToOne
+ private SalesOrderHeader salesOrderHeader;
+
+ public Calendar getCreationTime() {
+ return creationTime;
+ }
+
+ public void setCreationTime(final Calendar creationTime) {
+ this.creationTime = creationTime;
+ }
+
+ public Calendar getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(final Calendar creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public String getCreatedBy() {
+ return createdBy;
+ }
+
+ public void setCreatedBy(final String createdBy) {
+ this.createdBy = createdBy;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(final String text) {
+ this.text = text;
+ }
+
+ public long getSoId() {
+ return soId;
+ }
+
+ public void setSoId(final long soId) {
+ this.soId = soId;
+ }
+
+ public SalesOrderHeader getSalesOrderHeader() {
+ return salesOrderHeader;
+ }
+
+ public void setSalesOrderHeader(final SalesOrderHeader salesOrderHeader) {
+ this.salesOrderHeader = salesOrderHeader;
+ this.salesOrderHeader.getNotes().add(this);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/PartyRole.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/PartyRole.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/PartyRole.java
new file mode 100644
index 0000000..c1adaf9
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/PartyRole.java
@@ -0,0 +1,5 @@
+package org.apache.olingo.odata2.jpa.processor.ref.model;
+
+public enum PartyRole {
+ FROM, TO, CC, BCC, ORGANIZER, ATTENDEE
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderHeader.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderHeader.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderHeader.java
new file mode 100644
index 0000000..9af23f3
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderHeader.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TimeZone;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.PostPersist;
+import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+@Entity
+@Table(name = "T_SALESORDERHEADER")
+public class SalesOrderHeader {
+
+ public SalesOrderHeader() {}
+
+ public SalesOrderHeader(final Calendar creationDate, final int buyerId, final String buyerName,
+ final Address buyerAddress, final String currencyCode, final double netAmount,
+ final String deliveryStatus, final char[] shortText, final Character[] longText) {
+ super();
+ this.creationDate = creationDate;
+ this.buyerId = buyerId;
+ this.buyerName = buyerName;
+ this.buyerAddress = buyerAddress;
+ this.currencyCode = currencyCode;
+ this.deliveryStatus = deliveryStatus;
+ this.shortText = shortText;
+ this.longText = longText;
+ }
+
+ @Id
+ @Column(name = "SO_ID")
+ private long soId;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Calendar creationDate;
+
+ @Column
+ private Character status;
+
+ public Character getStatus() {
+ return status;
+ }
+
+ public void setStatus(final Character status) {
+ this.status = status;
+ }
+
+ @Column(name = "SHORT_TEXT", length = 20)
+ private char[] shortText;
+
+ @Column(name = "LONG_TEXT", length = 40)
+ private Character[] longText;
+
+ @Column(name = "BUYER_ID")
+ private int buyerId;
+
+ @Column(name = "BUYER_NAME", length = 255)
+ private String buyerName;
+
+ @Embedded
+ private Address buyerAddress;
+
+ @Column(name = "CURRENCY_CODE", length = 3)
+ private String currencyCode;
+
+ @Column(name = "DELIVERY_STATUS", length = 2)
+ private String deliveryStatus;
+
+ @Column(precision = 5)
+ private double grossAmount;
+
+ @Column(precision = 8)
+ private double netAmount;
+
+ @OneToMany(mappedBy = "salesOrderHeader", cascade = CascadeType.ALL)
+ private Set<SalesOrderItem> salesOrderItem = new HashSet<SalesOrderItem>();
+
+ @OneToMany(mappedBy = "salesOrderHeader", cascade = CascadeType.ALL)
+ private List<Note> notes = new ArrayList<Note>();
+
+ public long getSoId() {
+ return soId;
+ }
+
+ public void setSoId(final long soId) {
+ this.soId = soId;
+ }
+
+ public Date getCreationDate() {
+ if (creationDate == null) {
+ return null;
+ }
+ long dbTime = creationDate.getTime().getTime();
+ Date originalDate = new Date(dbTime + TimeZone.getDefault().getOffset(dbTime));
+ return originalDate;
+ }
+
+ public void setCreationDate(final Calendar creationDate) {
+ long originalTime;
+ if (creationDate != null) {
+ originalTime = creationDate.getTime().getTime();
+ } else {
+ originalTime = Calendar.getInstance(TimeZone.getDefault()).getTime().getTime();
+ }
+ Date newDate = new Date(originalTime - TimeZone.getDefault().getOffset(originalTime));
+ Calendar newCalendar = Calendar.getInstance();
+ newCalendar.setTime(newDate);
+ this.creationDate = newCalendar;
+ }
+
+ public int getBuyerId() {
+ return buyerId;
+ }
+
+ public void setBuyerId(final int buyerId) {
+ this.buyerId = buyerId;
+ }
+
+ public String getBuyerName() {
+ return buyerName;
+ }
+
+ public void setBuyerName(final String buyerName) {
+ this.buyerName = buyerName;
+ }
+
+ public Address getBuyerAddress() {
+ return buyerAddress;
+ }
+
+ public void setBuyerAddress(final Address buyerAddress) {
+ this.buyerAddress = buyerAddress;
+ }
+
+ public String getCurrencyCode() {
+ return currencyCode;
+ }
+
+ public void setCurrencyCode(final String currencyCode) {
+ this.currencyCode = currencyCode;
+ }
+
+ public String getDeliveryStatus() {
+ return deliveryStatus;
+ }
+
+ public void setDeliveryStatus(final String deliveryStatus) {
+ this.deliveryStatus = deliveryStatus;
+ }
+
+ public double getGrossAmount() {
+ return grossAmount;
+ }
+
+ public void setGrossAmount(final double grossAmount) {
+ this.grossAmount = grossAmount;
+ }
+
+ public double getNetAmount() {
+ return netAmount;
+ }
+
+ public void setNetAmount(final double netAmount) {
+ this.netAmount = netAmount;
+ }
+
+ public Set<SalesOrderItem> getSalesOrderItem() {
+ return salesOrderItem;
+ }
+
+ public void setSalesOrderItem(final Set<SalesOrderItem> salesOrderItem) {
+ this.salesOrderItem = salesOrderItem;
+ }
+
+ public List<Note> getNotes() {
+ return notes;
+ }
+
+ public void setNotes(final List<Note> notes) {
+ this.notes = notes;
+ }
+
+ public char[] getShortText() {
+ return shortText;
+ }
+
+ public void setShortText(final char[] shortText) {
+ this.shortText = shortText;
+ }
+
+ public Character[] getLongText() {
+ return longText;
+ }
+
+ public void setLongText(final Character[] longText) {
+ this.longText = longText;
+ }
+
+ @PostPersist
+ public void defaultValues() {
+ if (creationDate == null) {
+ setCreationDate(creationDate);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java
new file mode 100644
index 0000000..fa20b47
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItem.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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.model;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+import javax.persistence.Transient;
+
+@Entity
+@Table(name = "T_SALESORDERITEM")
+public class SalesOrderItem {
+
+ public SalesOrderItem() {}
+
+ public SalesOrderItem(final int quantity, final double amount, final double discount,
+ final Material material) {
+ super();
+ this.quantity = quantity;
+ this.amount = amount;
+ this.discount = discount;
+ this.material = material;
+ }
+
+ @EmbeddedId
+ private SalesOrderItemKey salesOrderItemKey;
+
+ @Column(name = "Material_Id", nullable = false)
+ private long matId;
+
+ @Column
+ private int quantity;
+
+ @Column
+ private double amount;
+
+ @Column
+ private double discount;
+
+ @Transient
+ private double netAmount;
+
+ @JoinColumn(name = "Material_Id", referencedColumnName = "MATERIAL_ID", insertable = false, updatable = false)
+ @ManyToOne
+ private Material material;
+
+ @JoinColumn(name = "Sales_Order_Id", referencedColumnName = "SO_ID", insertable = false, updatable = false)
+ @ManyToOne
+ private SalesOrderHeader salesOrderHeader;
+
+ public SalesOrderItemKey getSalesOrderItemKey() {
+ return salesOrderItemKey;
+ }
+
+ public void setSalesOrderItemKey(final SalesOrderItemKey salesOrderItemKey) {
+ this.salesOrderItemKey = salesOrderItemKey;
+ }
+
+ public long getMatId() {
+ return matId;
+ }
+
+ public void setMatId(final long matId) {
+ this.matId = matId;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(final int quantity) {
+ this.quantity = quantity;
+ }
+
+ public double getAmount() {
+ return amount;
+ }
+
+ public void setAmount(final double amount) {
+ this.amount = amount;
+ }
+
+ public double getDiscount() {
+ return discount;
+ }
+
+ public void setDiscount(final double discount) {
+ this.discount = discount;
+ }
+
+ public double getNetAmount() {
+ return netAmount;
+ }
+
+ public void setNetAmount(final double netAmount) {
+ this.netAmount = netAmount;
+ }
+
+ public Material getMaterial() {
+ return material;
+ }
+
+ public void setMaterial(final Material material) {
+ this.material = material;
+ }
+
+ public SalesOrderHeader getSalesOrderHeader() {
+ return salesOrderHeader;
+ }
+
+ public void setSalesOrderHeader(final SalesOrderHeader salesOrderHeader) {
+ this.salesOrderHeader = salesOrderHeader;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItemKey.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItemKey.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItemKey.java
new file mode 100644
index 0000000..efc09d2
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/SalesOrderItemKey.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.ref.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class SalesOrderItemKey implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public SalesOrderItemKey() {}
+
+ public SalesOrderItemKey(final long liId) {
+ super();
+ this.liId = liId;
+ }
+
+ @Column(name = "Sales_Order_Id", nullable = false)
+ private long soId;
+
+ @Column(name = "Sales_Order_Item_Id", unique = true)
+ private long liId;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (int) (liId ^ (liId >>> 32));
+ result = prime * result + (int) (soId ^ (soId >>> 32));
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ SalesOrderItemKey other = (SalesOrderItemKey) obj;
+ if (liId != other.liId) {
+ return false;
+ }
+ if (soId != other.soId) {
+ return false;
+ }
+ return true;
+ }
+
+ public long getSoId() {
+ return soId;
+ }
+
+ public void setSoId(final long soId) {
+ this.soId = soId;
+ }
+
+ public long getLiId() {
+ return liId;
+ }
+
+ public void setLiId(final long liId) {
+ this.liId = liId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Store.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Store.java b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Store.java
new file mode 100644
index 0000000..b88bc3a
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/model/Store.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.ref.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "T_STORE")
+public class Store {
+
+ public Store() {}
+
+ public Store(final String storeName, final Address storeAddress) {
+ super();
+ this.storeName = storeName;
+ this.storeAddress = storeAddress;
+ }
+
+ @Id
+ @Column(name = "STORE_ID")
+ private long storeId;
+
+ @Column(name = "STORE_NAME", unique = true)
+ private String storeName;
+
+ @Embedded
+ private Address storeAddress;
+
+ @ManyToMany(mappedBy = "stores")
+ private List<Material> materials = new ArrayList<Material>();
+
+ public long getStoreId() {
+ return storeId;
+ }
+
+ public void setStoreId(final long storeId) {
+ this.storeId = storeId;
+ }
+
+ public String getStoreName() {
+ return storeName;
+ }
+
+ public void setStoreName(final String storeName) {
+ this.storeName = storeName;
+ }
+
+ public Address getStoreAddress() {
+ return storeAddress;
+ }
+
+ public void setStoreAddress(final Address storeAddress) {
+ this.storeAddress = storeAddress;
+ }
+
+ public List<Material> getMaterials() {
+ return materials;
+ }
+
+ public void setMaterials(final List<Material> materials) {
+ this.materials = materials;
+ Iterator<Material> itr = materials.iterator();
+ while (itr.hasNext()) {
+ itr.next().getStores().add(this);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml b/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..d85fa46
--- /dev/null
+++ b/odata2-jpa-processor/jpa-ref/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<persistence version="2.0"
+ xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+ <persistence-unit name="salesorderprocessing"
+ transaction-type="RESOURCE_LOCAL">
+ <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderHeader</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderItem</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.Note</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.Material</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.Store</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.EmailActivity</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.ActivityParty</class>
+ <class>org.apache.olingo.odata2.jpa.processor.ref.model.AppointmentActivity</class>
+ <properties>
+ <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
+ <property name="javax.persistence.jdbc.url"
+ value="jdbc:hsqldb:mem:org.apache.olingo.jpa.sample" />
+ <property name="javax.persistence.jdbc.user" value="sa" />
+ <property name="javax.persistence.jdbc.password" value="" />
+ <property name="eclipselink.target-database"
+ value="org.eclipse.persistence.platform.database.HSQLPlatform" />
+ <property name="eclipselink.logging.level" value="ALL" />
+ <property name="eclipselink.orm.throw.exceptions" value="true" />
+ <property name="eclipselink.ddl-generation" value="create-tables" />
+ <property name="eclipselink.ddl-generation.output-mode"
+ value="database" />
+ </properties>
+ </persistence-unit>
+</persistence>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-web/.gitignore
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/.gitignore b/odata2-jpa-processor/jpa-web/.gitignore
new file mode 100644
index 0000000..fe5d89b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/.gitignore
@@ -0,0 +1,8 @@
+.project
+.classpath
+.settings
+target
+bin
+*.bak
+classes
+.DS_Store
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-web/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/pom.xml b/odata2-jpa-processor/jpa-web/pom.xml
new file mode 100644
index 0000000..18302cb
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/pom.xml
@@ -0,0 +1,123 @@
+<?xml version="1.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. -->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>olingo-odata2-jpa-processor-ref-web-incubating</artifactId>
+ <packaging>war</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-jpa-processor-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/version</directory>
+ <filtering>true</filtering>
+ <targetPath>../${project.build.finalName}/gen</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>com.sap.research</groupId>
+ <artifactId>nwcloud-maven-plugin</artifactId>
+ <version>1.0.0.RELEASE</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+
+ </build>
+
+ <dependencies>
+ <dependency>
+ <!-- required because of auto detection of web facet 2.5 -->
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-jpa-processor-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-jpa-processor-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-jpa-processor-ref-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dev</id>
+ <build>
+ <defaultGoal>cargo:run</defaultGoal>
+
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <version>1.4.2</version>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/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
new file mode 100644
index 0000000..0ff659b
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderHeaderProcessor.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+
+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.HttpMethod;
+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;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.jpa.processor.ref.model.Address;
+import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderHeader;
+import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderItem;
+
+public class SalesOrderHeaderProcessor {
+
+ private EntityManager em;
+
+ public SalesOrderHeaderProcessor() {
+ em = Persistence.createEntityManagerFactory("salesorderprocessing")
+ .createEntityManager();
+ }
+
+ @SuppressWarnings("unchecked")
+ @EdmFunctionImport(name = "FindAllSalesOrders", entitySet = "SalesOrders", returnType = @ReturnType(
+ type = Type.ENTITY, isCollection = true))
+ public List<SalesOrderHeader> findAllSalesOrders(
+ @EdmFunctionImportParameter(name = "DeliveryStatusCode",
+ facets = @EdmFacets(maxLength = 2)) final String status) {
+
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.deliveryStatus = '"
+ + status + "'");
+ List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
+ .getResultList();
+ return soList;
+ }
+
+ @EdmFunctionImport(name = "CheckATP", returnType = @ReturnType(type = Type.SIMPLE, isCollection = false),
+ httpMethod = HttpMethod.GET)
+ public boolean checkATP(
+ @EdmFunctionImportParameter(name = "SoID", facets = @EdmFacets(nullable = false)) final Long soID,
+ @EdmFunctionImportParameter(name = "LiId", facets = @EdmFacets(nullable = false)) final Long lineItemID) {
+ if (soID == 2L) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.ENTITY, isCollection = true), entitySet = "SalesOrders")
+ public SalesOrderHeader calculateNetAmount(
+ @EdmFunctionImportParameter(name = "SoID", facets = @EdmFacets(nullable = false)) final Long soID)
+ throws ODataException {
+
+ if (soID <= 0L) {
+ throw new ODataException("Invalid SoID");
+ }
+
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ + soID + "l");
+ 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());
+ }
+ so.setNetAmount(amount);
+ return so;
+ }
+
+ @SuppressWarnings("unchecked")
+ @EdmFunctionImport(returnType = @ReturnType(type = Type.COMPLEX))
+ public Address getAddress(
+ @EdmFunctionImportParameter(name = "SoID", facets = @EdmFacets(nullable = false)) final Long soID) {
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ + soID + "l");
+ List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
+ .getResultList();
+ if (!soList.isEmpty()) {
+ return soList.get(0).getBuyerAddress();
+ } else {
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/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
new file mode 100644
index 0000000..6b82899
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/SalesOrderProcessingExtension.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.ref.extension;
+
+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
+
+ }
+
+ @Override
+ public void extendWithOperation(final JPAEdmSchemaView view) {
+ view.registerOperations(SalesOrderHeaderProcessor.class, null);
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/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
new file mode 100644
index 0000000..4bc0a29
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/extension/_SalesOrderHeaderProcessor.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.ref.extension;
+
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+
+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;
+import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod;
+import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod.Name;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.jpa.processor.ref.model.Address;
+import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderHeader;
+import org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderItem;
+
+@Deprecated
+public class _SalesOrderHeaderProcessor {
+
+ private EntityManager em;
+
+ public _SalesOrderHeaderProcessor() {
+ em = Persistence.createEntityManagerFactory("salesorderprocessing")
+ .createEntityManager();
+ }
+
+ @SuppressWarnings("unchecked")
+ @FunctionImport(name = "FindAllSalesOrders", entitySet = "SalesOrders", returnType = ReturnType.ENTITY_TYPE,
+ multiplicity = Multiplicity.MANY)
+ public List<SalesOrderHeader> findAllSalesOrders(
+ @Parameter(name = "DeliveryStatusCode", facets = @Facets(maxLength = 2)) final String status) {
+
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.deliveryStatus = '"
+ + status + "'");
+ List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
+ .getResultList();
+ return soList;
+ }
+
+ @FunctionImport(name = "CheckATP", returnType = ReturnType.SCALAR, multiplicity = Multiplicity.ONE,
+ httpMethod = @HttpMethod(name = Name.GET))
+ public boolean checkATP(
+ @Parameter(name = "SoID", facets = @Facets(nullable = false), mode = Mode.IN) final Long soID,
+ @Parameter(name = "LiId", facets = @Facets(nullable = false), mode = Mode.IN) final Long lineItemID) {
+ if (soID == 2L) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ @FunctionImport(returnType = ReturnType.ENTITY_TYPE, entitySet = "SalesOrders")
+ public SalesOrderHeader calculateNetAmount(
+ @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID)
+ throws ODataException {
+
+ if (soID <= 0L) {
+ throw new ODataException("Invalid SoID");
+ }
+
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ + soID + "l");
+ 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());
+ }
+ so.setNetAmount(amount);
+ return so;
+ }
+
+ @SuppressWarnings("unchecked")
+ @FunctionImport(returnType = ReturnType.COMPLEX_TYPE)
+ public Address getAddress(
+ @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) {
+ Query q = em
+ .createQuery("SELECT E1 from SalesOrderHeader E1 WHERE E1.soId = "
+ + soID + "l");
+ List<SalesOrderHeader> soList = (List<SalesOrderHeader>) q
+ .getResultList();
+ if (!soList.isEmpty()) {
+ return soList.get(0).getBuyerAddress();
+ } else {
+ return null;
+ }
+ }
+
+ /*
+ * This method will not be transformed into Function Import Function Import
+ * with return type as void is not supported yet.
+ */
+ @FunctionImport(returnType = ReturnType.NONE)
+ public void process(
+ @Parameter(name = "SoID", facets = @Facets(nullable = false)) final Long soID) {
+ return;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/DataGenerator.java
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/DataGenerator.java b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/DataGenerator.java
new file mode 100644
index 0000000..55eb876
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/util/DataGenerator.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.ref.util;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+
+import org.apache.olingo.odata2.jpa.processor.ref.model.Material;
+import org.apache.olingo.odata2.jpa.processor.ref.model.Store;
+import org.eclipse.persistence.internal.jpa.EntityManagerImpl;
+import org.eclipse.persistence.queries.DataModifyQuery;
+import org.eclipse.persistence.queries.SQLCall;
+import org.eclipse.persistence.sessions.Session;
+
+/**
+ * This is a utility class for generating and cleaning data. The generated data would be used by the application.
+ *
+ *
+ */
+public class DataGenerator {
+
+ private EntityManager entityManager;
+
+ /**
+ * This is configuration property to hold comma separated names of Insert Files
+ */
+ private static final String SQL_INSERT_CONFIG = "SQLInsertConfig";
+
+ /**
+ * This is key which will be used to fetch file names from SQL Insert Config File.
+ */
+ private static final String SQL_INSERT_FILE_NAMES_KEY = "insert_file_names";
+
+ private static final String SQL_DELETE_CONFIG = "DataDeleteSQLs";
+ private static final String SQL_DELETE_STATEMENTS_KEY = "delete_queries";
+
+ public DataGenerator(final EntityManager entityManager) {
+ this.entityManager = entityManager;
+ }
+
+ /**
+ * This method generates data to be used in the application. It does so by
+ * reading properties file. Currently it iterates through comma separated
+ * file names in file SQLInsertConfig and gets the insert statements from
+ * those files in the order provided in the file.
+ */
+ public void generate() {
+ String[] resourceSQLPropFileNames = getSQLInsertFileNames();
+ if (resourceSQLPropFileNames.length > 0) { // If configuration is proper with at least one file
+ Session session = ((EntityManagerImpl) entityManager).getActiveSession();
+ ResourceBundle[] resourceBundleArr = new ResourceBundle[resourceSQLPropFileNames.length];
+ entityManager.getTransaction().begin();
+
+ for (int i = 0; i < resourceSQLPropFileNames.length; i++) { // For each Entity SQL property file,
+ System.out.println("Reading from File - " + resourceSQLPropFileNames[i]);
+ resourceBundleArr[i] = ResourceBundle.getBundle(resourceSQLPropFileNames[i]);// Get SQL statements as properties
+
+ Set<String> keySet = resourceBundleArr[i].keySet();
+
+ for (String string : keySet) {
+ String currentSQL = (String) string;
+ String sqlQuery = resourceBundleArr[i].getString(currentSQL);
+ System.out.println("Executing Query - " + sqlQuery);
+ SQLCall sqlCall = new SQLCall(sqlQuery);
+
+ DataModifyQuery query = new DataModifyQuery();
+ query.setCall(sqlCall);
+ session.executeQuery(query);
+ }
+ }
+ setMaterialInStore();
+ entityManager.flush();
+ entityManager.getTransaction().commit();
+ }
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private void setMaterialInStore() {
+ Query query = entityManager.createQuery("SELECT e FROM Material e");
+ List<Material> materials = (List<Material>) query.getResultList();
+
+ query = entityManager.createQuery("SELECT e FROM Store e");
+ List<Store> stores = (List<Store>) query.getResultList();
+
+ int storeSize = stores.size();
+ int i = 0;
+ for (Material material : materials) {
+ List<Store> storesA = Arrays.asList(stores.get(i), stores.get(i + 1));
+ material.setStores(storesA);
+ i++;
+ if (i > storeSize - 2) {
+ i = 0;
+ }
+ entityManager.persist(material);
+ }
+ entityManager.flush();
+ }
+
+ private String[] getSQLInsertFileNames() {
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(SQL_INSERT_CONFIG);// File names from properties
+ String namesStr = resourceBundle.getString(SQL_INSERT_FILE_NAMES_KEY);
+ return namesStr.split(",");
+ }
+
+ private String[] getSQLDeleteStatements() {
+ ResourceBundle resourceBundle = ResourceBundle.getBundle(SQL_DELETE_CONFIG);// File names from properties
+ String deleteStatements = resourceBundle.getString(SQL_DELETE_STATEMENTS_KEY);
+ return deleteStatements.split(",");
+ }
+
+ /**
+ * This method deletes data from JPA tables created. This method reads comma
+ * separated SQL delete statements from DataDeleteSQLs properties files and
+ * executes them in order.
+ */
+ public void clean() {
+ // Delete using SQLs
+ String[] deleteStatements = getSQLDeleteStatements();
+ if (deleteStatements.length > 0) { // If configuration is proper with at least one delete Statements
+ Session session = ((EntityManagerImpl) entityManager).getActiveSession();
+ entityManager.getTransaction().begin();
+ for (String deleteStatement : deleteStatements) {
+ System.out.println("Cleaning - " + deleteStatement);
+ SQLCall sqlCall = new SQLCall(deleteStatement);
+
+ DataModifyQuery query = new DataModifyQuery();
+ query.setCall(sqlCall);
+ session.executeQuery(query);
+ }
+ entityManager.getTransaction().commit();
+ } else {
+ System.err.println("Delete configuration file doesn't have any delete statements.");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/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
new file mode 100644
index 0000000..fe4e618
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/java/org/apache/olingo/odata2/jpa/processor/ref/web/JPAReferenceServiceFactory.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * 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.web;
+
+import java.util.ResourceBundle;
+
+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";
+ private static final String MAPPING_MODEL = "SalesOrderProcessingMappingModel.xml";
+ private static final String CONFIG = "serviceConfig";
+ private static final String SHOW_DETAIL_ERROR = "showDetailError";
+
+ @Override
+ public ODataJPAContext initializeODataJPAContext()
+ throws ODataJPARuntimeException {
+ ODataJPAContext oDataJPAContext = getODataJPAContext();
+ oDataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory.getEntityManagerFactory(PUNIT_NAME));
+ oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
+ oDataJPAContext.setJPAEdmMappingModel(MAPPING_MODEL);
+ oDataJPAContext
+ .setJPAEdmExtension((JPAEdmExtension) new SalesOrderProcessingExtension());
+
+ setErrorLevel();
+
+ return oDataJPAContext;
+ }
+
+ private void setErrorLevel() {
+ ResourceBundle config = ResourceBundle.getBundle(CONFIG);
+ boolean error = Boolean.parseBoolean((String) config.getObject(SHOW_DETAIL_ERROR));
+ setDetailErrors(error);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/1b479e6c/odata2-jpa-processor/jpa-web/src/main/resources/DataDeleteSQLs.properties
----------------------------------------------------------------------
diff --git a/odata2-jpa-processor/jpa-web/src/main/resources/DataDeleteSQLs.properties b/odata2-jpa-processor/jpa-web/src/main/resources/DataDeleteSQLs.properties
new file mode 100644
index 0000000..19f859d
--- /dev/null
+++ b/odata2-jpa-processor/jpa-web/src/main/resources/DataDeleteSQLs.properties
@@ -0,0 +1,22 @@
+#-------------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#-------------------------------------------------------------------------------
+
+#Config file for deleting the entities. They are deleted in the order provided in the below comma-separated string.
+#It is mandatory due to referential constaints.
+delete_queries = DELETE FROM T_NOTE,DELETE FROM T_SALESORDERITEM,DELETE FROM T_MATERIAL_T_STORE,DELETE FROM T_MATERIAL,DELETE FROM T_STORE,DELETE FROM T_SALESORDERHEADER
\ No newline at end of file