Skip to content

Commit bac1443

Browse files
committed
Initial import
1 parent a86c694 commit bac1443

12 files changed

Lines changed: 356 additions & 0 deletions

File tree

‎apache-olingo/olingo2/.gitignore‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
HELP.md
2+
/target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
5+
### STS ###
6+
.apt_generated
7+
.classpath
8+
.factorypath
9+
.project
10+
.settings
11+
.springBeans
12+
.sts4-cache
13+
14+
### IntelliJ IDEA ###
15+
.idea
16+
*.iws
17+
*.iml
18+
*.ipr
19+
20+
### NetBeans ###
21+
/nbproject/private/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/
26+
/build/
27+
28+
### VS Code ###
29+
.vscode/

‎apache-olingo/olingo2/pom.xml‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
<version>2.1.3.RELEASE</version>
10+
<relativePath /> <!-- lookup parent from repository -->
11+
</parent>
12+
<groupId>org.baeldung.examples.olingo2</groupId>
13+
<artifactId>olingo2-sample</artifactId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<name>olingo2-sample</name>
16+
<description>Sample Olingo 2 Project</description>
17+
18+
<properties>
19+
<java.version>1.8</java.version>
20+
<olingo2.version>2.0.11</olingo2.version>
21+
</properties>
22+
23+
<dependencies>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-jersey</artifactId>
28+
</dependency>
29+
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-data-jpa</artifactId>
34+
</dependency>
35+
36+
37+
<dependency>
38+
<groupId>com.h2database</groupId>
39+
<artifactId>h2</artifactId>
40+
<scope>runtime</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.springframework.boot</groupId>
44+
<artifactId>spring-boot-configuration-processor</artifactId>
45+
<optional>true</optional>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.projectlombok</groupId>
49+
<artifactId>lombok</artifactId>
50+
<optional>true</optional>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-test</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
58+
<!-- Olingo 2 Dependencies -->
59+
<dependency>
60+
<groupId>org.apache.olingo</groupId>
61+
<artifactId>olingo-odata2-core</artifactId>
62+
<version>${olingo2.version}</version>
63+
<!-- Avoid jax-rs version conflict by excluding Olingo's version -->
64+
<exclusions>
65+
<exclusion>
66+
<groupId>javax.ws.rs</groupId>
67+
<artifactId>javax.ws.rs-api</artifactId>
68+
</exclusion>
69+
</exclusions>
70+
</dependency>
71+
<dependency>
72+
<groupId>org.apache.olingo</groupId>
73+
<artifactId>olingo-odata2-api</artifactId>
74+
<version>${olingo2.version}</version>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.apache.olingo</groupId>
78+
<artifactId>olingo-odata2-jpa-processor-api</artifactId>
79+
<version>${olingo2.version}</version>
80+
</dependency>
81+
<dependency>
82+
<groupId>org.apache.olingo</groupId>
83+
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
84+
<version>${olingo2.version}</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.apache.olingo</groupId>
88+
<artifactId>olingo-odata2-jpa-processor-ref</artifactId>
89+
<version>${olingo2.version}</version>
90+
<exclusions>
91+
<exclusion>
92+
<groupId>org.eclipse.persistence</groupId>
93+
<artifactId>eclipselink</artifactId>
94+
</exclusion>
95+
</exclusions>
96+
</dependency>
97+
</dependencies>
98+
99+
<build>
100+
<plugins>
101+
<plugin>
102+
<groupId>org.springframework.boot</groupId>
103+
<artifactId>spring-boot-maven-plugin</artifactId>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
108+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.baeldung.examples.olingo2;
2+
3+
4+
import java.util.Set;
5+
6+
import javax.ws.rs.ApplicationPath;
7+
8+
import org.apache.olingo.odata2.core.rest.ODataRootLocator;
9+
import org.apache.olingo.odata2.core.rest.app.ODataApplication;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
import org.springframework.stereotype.Component;
13+
14+
@Component
15+
public class CarsODataApplication extends ODataApplication {
16+
17+
private static final Logger log = LoggerFactory.getLogger(CarsODataApplication.class);
18+
19+
public CarsODataApplication() {
20+
super();
21+
log.info("[I17] Creating CarsODataApplication...");
22+
}
23+
24+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.baeldung.examples.olingo2;
2+
3+
import javax.persistence.EntityManager;
4+
5+
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
6+
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;
7+
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
import org.springframework.stereotype.Component;
11+
12+
/**
13+
* OData ServiceFactory that
14+
* @author Philippe
15+
*
16+
*/
17+
@Component
18+
public class CarsODataJPAServiceFactory extends ODataJPAServiceFactory {
19+
20+
private EntityManager em;
21+
private static final Logger log = LoggerFactory.getLogger(CarsODataJPAServiceFactory.class);
22+
23+
public CarsODataJPAServiceFactory(EntityManager em) {
24+
this.em = em;
25+
}
26+
27+
@Override
28+
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
29+
30+
ODataJPAContext oDataJPAContext = getODataJPAContext();
31+
oDataJPAContext.setEntityManagerFactory(em.getEntityManagerFactory());
32+
oDataJPAContext.setPersistenceUnitName("default");
33+
34+
return oDataJPAContext;
35+
36+
}
37+
38+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.baeldung.examples.olingo2;
2+
3+
import javax.servlet.ServletContext;
4+
import javax.ws.rs.ApplicationPath;
5+
import javax.ws.rs.Path;
6+
7+
import org.apache.olingo.odata2.api.ODataServiceFactory;
8+
import org.apache.olingo.odata2.core.rest.ODataRootLocator;
9+
import org.glassfish.jersey.server.ResourceConfig;
10+
import org.springframework.stereotype.Component;
11+
12+
@Component
13+
@ApplicationPath("/odata")
14+
public class JerseyConfig extends ResourceConfig {
15+
16+
17+
public JerseyConfig(CarsODataApplication delegate,ServletContext servletContext,CarsODataJPAServiceFactory serviceFactory) {
18+
19+
delegate
20+
.getClasses()
21+
.forEach( c -> {
22+
// Avoid using the default Locator
23+
if ( !ODataRootLocator.class.isAssignableFrom(c)) {
24+
register(c);
25+
}
26+
});
27+
28+
register(new CustomLocator(serviceFactory));
29+
30+
}
31+
32+
33+
@Path("/")
34+
public static class CustomLocator extends ODataRootLocator {
35+
36+
private CarsODataJPAServiceFactory serviceFactory;
37+
38+
public CustomLocator(CarsODataJPAServiceFactory serviceFactory) {
39+
this.serviceFactory = serviceFactory;
40+
}
41+
42+
@Override
43+
public ODataServiceFactory getServiceFactory() {
44+
return this.serviceFactory;
45+
}
46+
47+
}
48+
49+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.baeldung.examples.olingo2;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.builder.SpringApplicationBuilder;
5+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
6+
7+
@SpringBootApplication
8+
public class Olingo2SampleApplication extends SpringBootServletInitializer {
9+
10+
public static void main(String[] args) {
11+
new Olingo2SampleApplication()
12+
.configure(new SpringApplicationBuilder(Olingo2SampleApplication.class))
13+
.run(args);
14+
}
15+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.baeldung.examples.olingo2.domain;
2+
3+
import java.util.List;
4+
5+
import javax.persistence.CascadeType;
6+
import javax.persistence.Column;
7+
import javax.persistence.Entity;
8+
import javax.persistence.Id;
9+
import javax.persistence.OneToMany;
10+
import javax.persistence.Table;
11+
import javax.validation.constraints.NotNull;
12+
13+
import lombok.Data;
14+
15+
@Entity
16+
@Data
17+
@Table(name="car_maker")
18+
public class CarMaker {
19+
20+
@Id
21+
private Long id;
22+
23+
@NotNull
24+
@Column(name="name")
25+
private String name;
26+
27+
@OneToMany(mappedBy="maker",cascade=CascadeType.ALL)
28+
private List<CarModel> models;
29+
30+
31+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.baeldung.examples.olingo2.domain;
2+
3+
4+
import javax.persistence.Entity;
5+
import javax.persistence.Id;
6+
import javax.persistence.ManyToOne;
7+
import javax.validation.constraints.NotNull;
8+
9+
import lombok.Data;
10+
11+
@Entity
12+
@Data
13+
public class CarModel {
14+
15+
@Id
16+
private Long id;
17+
18+
@NotNull
19+
private String name;
20+
21+
@NotNull
22+
private Integer year;
23+
24+
@NotNull
25+
private String sku;
26+
27+
@ManyToOne
28+
private CarMaker maker;
29+
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
spring:
3+
jersey:
4+
application-path: /odata
5+
6+
jpa:
7+
show-sql: true
8+
hibernate:
9+
ddl-auto: update
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
insert into car_maker(id,name) values (1,'Special Motors');
2+
insert into car_maker(id,name) values (2,'BWM');
3+
insert into car_maker(id,name) values (3,'Dolores');

0 commit comments

Comments
 (0)