Initial import
This commit is contained in:
parent
a86c69429b
commit
bac1443897
29
apache-olingo/olingo2/.gitignore
vendored
Normal file
29
apache-olingo/olingo2/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
HELP.md
|
||||||
|
/target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
108
apache-olingo/olingo2/pom.xml
Normal file
108
apache-olingo/olingo2/pom.xml
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
|
<version>2.1.3.RELEASE</version>
|
||||||
|
<relativePath /> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>org.baeldung.examples.olingo2</groupId>
|
||||||
|
<artifactId>olingo2-sample</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>olingo2-sample</name>
|
||||||
|
<description>Sample Olingo 2 Project</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<olingo2.version>2.0.11</olingo2.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jersey</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Olingo 2 Dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>olingo-odata2-core</artifactId>
|
||||||
|
<version>${olingo2.version}</version>
|
||||||
|
<!-- Avoid jax-rs version conflict by excluding Olingo's version -->
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>olingo-odata2-api</artifactId>
|
||||||
|
<version>${olingo2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>olingo-odata2-jpa-processor-api</artifactId>
|
||||||
|
<version>${olingo2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>olingo-odata2-jpa-processor-core</artifactId>
|
||||||
|
<version>${olingo2.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.olingo</groupId>
|
||||||
|
<artifactId>olingo-odata2-jpa-processor-ref</artifactId>
|
||||||
|
<version>${olingo2.version}</version>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.eclipse.persistence</groupId>
|
||||||
|
<artifactId>eclipselink</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.baeldung.examples.olingo2;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.ws.rs.ApplicationPath;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata2.core.rest.ODataRootLocator;
|
||||||
|
import org.apache.olingo.odata2.core.rest.app.ODataApplication;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class CarsODataApplication extends ODataApplication {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(CarsODataApplication.class);
|
||||||
|
|
||||||
|
public CarsODataApplication() {
|
||||||
|
super();
|
||||||
|
log.info("[I17] Creating CarsODataApplication...");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package org.baeldung.examples.olingo2;
|
||||||
|
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
|
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.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OData ServiceFactory that
|
||||||
|
* @author Philippe
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class CarsODataJPAServiceFactory extends ODataJPAServiceFactory {
|
||||||
|
|
||||||
|
private EntityManager em;
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(CarsODataJPAServiceFactory.class);
|
||||||
|
|
||||||
|
public CarsODataJPAServiceFactory(EntityManager em) {
|
||||||
|
this.em = em;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException {
|
||||||
|
|
||||||
|
ODataJPAContext oDataJPAContext = getODataJPAContext();
|
||||||
|
oDataJPAContext.setEntityManagerFactory(em.getEntityManagerFactory());
|
||||||
|
oDataJPAContext.setPersistenceUnitName("default");
|
||||||
|
|
||||||
|
return oDataJPAContext;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package org.baeldung.examples.olingo2;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.ws.rs.ApplicationPath;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata2.api.ODataServiceFactory;
|
||||||
|
import org.apache.olingo.odata2.core.rest.ODataRootLocator;
|
||||||
|
import org.glassfish.jersey.server.ResourceConfig;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ApplicationPath("/odata")
|
||||||
|
public class JerseyConfig extends ResourceConfig {
|
||||||
|
|
||||||
|
|
||||||
|
public JerseyConfig(CarsODataApplication delegate,ServletContext servletContext,CarsODataJPAServiceFactory serviceFactory) {
|
||||||
|
|
||||||
|
delegate
|
||||||
|
.getClasses()
|
||||||
|
.forEach( c -> {
|
||||||
|
// Avoid using the default Locator
|
||||||
|
if ( !ODataRootLocator.class.isAssignableFrom(c)) {
|
||||||
|
register(c);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
register(new CustomLocator(serviceFactory));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Path("/")
|
||||||
|
public static class CustomLocator extends ODataRootLocator {
|
||||||
|
|
||||||
|
private CarsODataJPAServiceFactory serviceFactory;
|
||||||
|
|
||||||
|
public CustomLocator(CarsODataJPAServiceFactory serviceFactory) {
|
||||||
|
this.serviceFactory = serviceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ODataServiceFactory getServiceFactory() {
|
||||||
|
return this.serviceFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package org.baeldung.examples.olingo2;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Olingo2SampleApplication extends SpringBootServletInitializer {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new Olingo2SampleApplication()
|
||||||
|
.configure(new SpringApplicationBuilder(Olingo2SampleApplication.class))
|
||||||
|
.run(args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.baeldung.examples.olingo2.domain;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
@Table(name="car_maker")
|
||||||
|
public class CarMaker {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Column(name="name")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy="maker",cascade=CascadeType.ALL)
|
||||||
|
private List<CarModel> models;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package org.baeldung.examples.olingo2.domain;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Data
|
||||||
|
public class CarModel {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Integer year;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String sku;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private CarMaker maker;
|
||||||
|
|
||||||
|
}
|
9
apache-olingo/olingo2/src/main/resources/application.yml
Normal file
9
apache-olingo/olingo2/src/main/resources/application.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
spring:
|
||||||
|
jersey:
|
||||||
|
application-path: /odata
|
||||||
|
|
||||||
|
jpa:
|
||||||
|
show-sql: true
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: update
|
3
apache-olingo/olingo2/src/main/resources/data.sql
Normal file
3
apache-olingo/olingo2/src/main/resources/data.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
insert into car_maker(id,name) values (1,'Special Motors');
|
||||||
|
insert into car_maker(id,name) values (2,'BWM');
|
||||||
|
insert into car_maker(id,name) values (3,'Dolores');
|
@ -0,0 +1,16 @@
|
|||||||
|
package org.baeldung.examples.olingo2;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class Olingo2SampleApplicationTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void contextLoads() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -55,6 +55,10 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user