-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Elide JPA datastore initial commit * Fix CheckStyle errors * Passing the bulk of the integration tests for the jpa data store. Fixing a number of bugs with tests and also a few with the data store * Passing the bulk of the integration tests for the jpa data store. Fixing a number of bugs with tests and also a few with the data store * Fixed GraphQL Bug * Resolve conflicts * Change build order * Enable UserType test * Cleanup warnings * merge master * Bind entity model beans * Include missing tests
- Loading branch information
Showing
37 changed files
with
1,164 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<!-- | ||
~ Copyright 2016, Yahoo Inc. | ||
~ Licensed under the Apache License, Version 2.0 | ||
~ See LICENSE file in project root for terms. | ||
--> | ||
|
||
<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> | ||
<artifactId>elide-datastore-jpa</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Elide Data Store: JPA</name> | ||
<description>Elide Data Store for JPA support</description> | ||
<url>https://github.com/yahoo/elide</url> | ||
<parent> | ||
<groupId>com.yahoo.elide</groupId> | ||
<artifactId>elide-datastore-parent-pom</artifactId> | ||
<version>4.3.4-SNAPSHOT</version> | ||
</parent> | ||
|
||
<licenses> | ||
<license> | ||
<name>The Apache Software License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<name>Belov Aleksandr</name> | ||
<url>https://github.com/belovaf</url> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<developerConnection>scm:git:ssh://[email protected]/yahoo/elide.git</developerConnection> | ||
<url>https://github.com/yahoo/elide.git</url> | ||
<tag>HEAD</tag> | ||
</scm> | ||
|
||
<properties> | ||
<dataStoreSupplier>com.yahoo.elide.datastores.jpa.JpaDataStoreSupplier</dataStoreSupplier> | ||
</properties> | ||
|
||
<dependencies> | ||
<!-- Elide --> | ||
<dependency> | ||
<groupId>com.yahoo.elide</groupId> | ||
<artifactId>elide-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.yahoo.elide</groupId> | ||
<artifactId>elide-datastore-hibernate</artifactId> | ||
<version>4.3.4-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- JPA --> | ||
<dependency> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<artifactId>javax.persistence</artifactId> | ||
<version>2.1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- JTA (Optional) --> | ||
<dependency> | ||
<groupId>javax.transaction</groupId> | ||
<artifactId>javax.transaction-api</artifactId> | ||
<version>1.2</version> | ||
<scope>provided</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.yahoo.elide</groupId> | ||
<artifactId>elide-integration-tests</artifactId> | ||
<version>4.3.4-SNAPSHOT</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
|
||
|
||
<!-- Hibernate 5 --> | ||
<!-- Integration test --> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.jayway.restassured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-servlet</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-validator</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-webapp</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-core</artifactId> | ||
<version>${hibernate5.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>slf4j-api</artifactId> | ||
<groupId>org.slf4j</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>xml-apis</artifactId> | ||
<groupId>xml-apis</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>jasper-runtime</artifactId> | ||
<groupId>tomcat</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>xerces</artifactId> | ||
<groupId>xerces</groupId> | ||
</exclusion> | ||
<exclusion> | ||
<artifactId>jasper-compiler</artifactId> | ||
<groupId>tomcat</groupId> | ||
</exclusion> | ||
</exclusions> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Envers testing --> | ||
<dependency> | ||
<groupId>org.hibernate</groupId> | ||
<artifactId>hibernate-envers</artifactId> | ||
<version>${hibernate5.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
71 changes: 71 additions & 0 deletions
71
...astore/elide-datastore-jpa/src/main/java/com/yahoo/elide/datastores/jpa/JpaDataStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2018, Oath Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.datastores.jpa; | ||
|
||
import com.yahoo.elide.core.DataStore; | ||
import com.yahoo.elide.core.DataStoreTransaction; | ||
import com.yahoo.elide.core.EntityDictionary; | ||
import com.yahoo.elide.datastores.jpa.transaction.JpaTransaction; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.metamodel.EntityType; | ||
|
||
/** | ||
* Implementation for JPA EntityManager data store. | ||
*/ | ||
public class JpaDataStore implements DataStore { | ||
protected final EntityManagerSupplier entityManagerSupplier; | ||
protected final JpaTransactionSupplier transactionSupplier; | ||
|
||
public JpaDataStore(EntityManagerSupplier entityManagerSupplier, | ||
JpaTransactionSupplier transactionSupplier) { | ||
this.entityManagerSupplier = entityManagerSupplier; | ||
this.transactionSupplier = transactionSupplier; | ||
} | ||
|
||
@Override | ||
public void populateEntityDictionary(EntityDictionary dictionary) { | ||
for (EntityType type : entityManagerSupplier.get().getMetamodel().getEntities()) { | ||
try { | ||
Class<?> mappedClass = type.getJavaType(); | ||
// Ignore this result. We are just checking to see if it throws an exception meaning that | ||
// provided class was _not_ an entity. | ||
dictionary.lookupEntityClass(mappedClass); | ||
|
||
// Bind if successful | ||
dictionary.bindEntity(mappedClass); | ||
} catch (IllegalArgumentException e) { | ||
// Ignore this entity. | ||
// Turns out that JPA may include non-entity types in this list when using things like envers. | ||
// Since they are not entities, we do not want to bind them into the entity dictionary. | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public DataStoreTransaction beginTransaction() { | ||
EntityManager entityManager = entityManagerSupplier.get(); | ||
JpaTransaction transaction = transactionSupplier.get(entityManager); | ||
transaction.begin(); | ||
return transaction; | ||
} | ||
|
||
/** | ||
* Functional interface for describing a method to supply EntityManager. | ||
*/ | ||
@FunctionalInterface | ||
public interface EntityManagerSupplier { | ||
EntityManager get(); | ||
} | ||
|
||
/** | ||
* Functional interface for describing a method to supply JpaTransaction. | ||
*/ | ||
@FunctionalInterface | ||
public interface JpaTransactionSupplier { | ||
JpaTransaction get(EntityManager entityManager); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...astore-jpa/src/main/java/com/yahoo/elide/datastores/jpa/porting/EntityManagerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2018, Oath Inc. | ||
* Licensed under the Apache License, Version 2.0 | ||
* See LICENSE file in project root for terms. | ||
*/ | ||
package com.yahoo.elide.datastores.jpa.porting; | ||
|
||
import com.yahoo.elide.core.hibernate.Query; | ||
import com.yahoo.elide.core.hibernate.Session; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.persistence.EntityManager; | ||
|
||
/** | ||
* Wraps a JPA EntityManager allowing most data store logic | ||
* to not directly depend on a specific version of JPA. | ||
*/ | ||
@Slf4j | ||
public class EntityManagerWrapper implements Session { | ||
private EntityManager entityManager; | ||
|
||
public EntityManagerWrapper(EntityManager entityManager) { | ||
this.entityManager = entityManager; | ||
} | ||
|
||
private static void logQuery(String queryText) { | ||
log.debug("HQL Query: {}", queryText); | ||
} | ||
|
||
@Override | ||
public Query createQuery(String queryText) { | ||
logQuery(queryText); | ||
return new QueryWrapper(entityManager.createQuery(queryText)); | ||
} | ||
} |
Oops, something went wrong.