Skip to content

Commit

Permalink
Added metadata for org.hibernate.orm:hibernate-core:6.2.0.Final (#263)
Browse files Browse the repository at this point in the history
* Adding metadata for hibernate 6.2.0.Final

* Adding metadata for hibernate 6.2.0.Final

* Adding metadata for hibernate 6.2.0.Final

* Adding metadata for hibernate 6.2.0.Final

* Adding metadata for hibernate 6.2.0.Final

* Adding metadata for hibernate 6.2.0.Final

* Adding metadata for hibernate 6.2.0.Final

* Modified hibernate-core index.json file
  • Loading branch information
msupic authored Apr 4, 2023
1 parent 32c16d8 commit 8cf24c9
Show file tree
Hide file tree
Showing 33 changed files with 2,073 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"reflect-config.json",
"resource-config.json"
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"resources":{
"includes":[
{
"condition":{"typeReachable":"org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl"},
"pattern":"\\QMETA-INF/persistence.xml\\E"
},
{
"condition":{"typeReachable":"org.hibernate.internal.util.ConfigHelper"},
"pattern":"\\Qhibernate.properties\\E"
},
{
"condition":{"typeReachable":"org.hibernate.boot.jaxb.internal.stax.LocalSchemaLocator"},
"pattern":"\\Qorg/hibernate/hibernate-configuration-3.0.dtd\\E"
},
{
"condition":{"typeReachable":"org.hibernate.boot.jaxb.internal.stax.LocalSchemaLocator"},
"pattern":"\\Qorg/hibernate/hibernate-mapping-3.0.dtd\\E"
},
{
"condition":{"typeReachable":"org.hibernate.boot.xsd.LocalXsdResolver"},
"pattern":"\\Qorg/hibernate/jpa/persistence_2_0.xsd\\E"
}
]}
}
7 changes: 7 additions & 0 deletions metadata/org.hibernate.orm/hibernate-core/index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[
{
"latest": true,
"metadata-version": "6.2.0.Final",
"module": "org.hibernate.orm:hibernate-core",
"tested-versions": [
"6.2.0.Final"
]
},
{
"metadata-version": "6.1.1.Final",
"module": "org.hibernate.orm:hibernate-core",
"tested-versions": [
Expand Down
11 changes: 11 additions & 0 deletions tests/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
}
]
},
{
"test-project-path": "org.hibernate.orm/hibernate-core/6.2.0.Final",
"libraries": [
{
"name": "org.hibernate.orm:hibernate-core",
"versions": [
"6.2.0.Final"
]
}
]
},
{
"test-project-path": "org.hibernate.orm/hibernate-envers/6.1.1.Final",
"libraries": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
gradlew.bat
gradlew
gradle/
build/
generated-metadata/
10 changes: 10 additions & 0 deletions tests/src/org.hibernate.orm/hibernate-core/6.2.0.Final/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Hibernate ORM

The metadata has been generated by executing the following script:

```bash
./generate-metadata.sh
```

The generated metadata can be found in the `generated-metadata` directory.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

plugins {
id "org.graalvm.internal.tck"
}

String libraryVersion = tck.testedLibraryVersion.get()

dependencies {
testImplementation "org.hibernate.orm:hibernate-core:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'com.h2database:h2:2.1.214'
testImplementation 'jakarta.validation:jakarta.validation-api:3.0.2'
testImplementation 'org.postgresql:postgresql:42.6.0'
testImplementation 'com.oracle.database.jdbc:ojdbc11:21.9.0.0'

testImplementation 'ch.qos.logback:logback-classic:1.4.5'
}

task updateGeneratedMetadata {
doLast {
final ant = new groovy.ant.AntBuilder()
final metadataDir = project.projectDir.toString() + "/generated-metadata"

// replace typeReachable value for entries generated by IdentifierGeneratorTest test class
ant.replace(file: metadataDir + "/reflect-config.json",
token: "org_hibernate_orm.hibernate_core.IdentifierGeneratorTest",
value: "org.hibernate.id.factory.internal.StandardIdentifierGeneratorFactory")
}
}

task deleteGeneratedMetadata(type: Delete) {
delete files(project.projectDir.toString() + "/generated-metadata")
}

graalvmNative {
agent {
defaultMode = "conditional"
modes {
conditional {
userCodeFilterPath = "metadata-conditions-filter.json"
extraFilterPath = "metadata-extra-filter.json"
}
}
metadataCopy {
inputTaskNames.add("test")
outputDirectories.add("generated-metadata")
mergeWithExisting = true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

./gradlew deleteGeneratedMetadata
./gradlew test --tests "org_hibernate_orm.hibernate_core.H2DialectHibernateTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.MariaDBDialectHibernateTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.MSSQLDialectHibernateTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.MySQLDialectHibernateTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.OracleDialectHibernateTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.PostgresDialectHibernateTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.HibernateDialectTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.UrlMessageBundleTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.IdentifierGeneratorTest" -Pagent metadataCopy
./gradlew test --tests "org_hibernate_orm.hibernate_core.OptimizerTest" -Pagent metadataCopy
./gradlew updateGeneratedMetadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 6.2.0.Final
metadata.dir = org.hibernate.orm/hibernate-core/6.2.0.Final/
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": [
{"includeClasses": "org.hibernate.**"},
{"includeClasses": "org_hibernate_orm.hibernate_core.IdentifierGeneratorTest"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"rules": [
{"excludeClasses": "**"},
{"includeClasses": "org.hibernate.**"},
{"includeClasses": "[Lorg.hibernate.**"},
{"includeClasses": "org_hibernate_orm.hibernate_core.IdentifierGeneratorTest"}
],
"regexRules": [
{"excludeClasses": "org\\.hibernate.*_\\$logger_en.*"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
def tckPath = Objects.requireNonNullElse(
System.getenv("GVM_TCK_TCKDIR"),
"../../../../tck-build-logic"
)
includeBuild(tckPath)
}

plugins {
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
}

rootProject.name = 'org.hibernate.orm.hibernate-core_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_hibernate_orm.hibernate_core;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org_hibernate_orm.hibernate_core.entity.Course;
import org_hibernate_orm.hibernate_core.entity.CourseMaterial;
import org_hibernate_orm.hibernate_core.entity.Gender;
import org_hibernate_orm.hibernate_core.entity.Student;
import org_hibernate_orm.hibernate_core.entity.Teacher;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
abstract class AbstractHibernateTest {

private EntityManagerFactory entityManagerFactory;
private EntityManager entityManager;

private Map<String, Long> studentIds = new HashMap<>();

private Map<String, Long> teacherIds = new HashMap<>();

private Map<String, Long> courseIds = new HashMap<>();

@BeforeAll
public void init() {
Map<String, String> properties = new HashMap<>();
properties.put("jakarta.persistence.jdbc.url", getJdbcUrl());
properties.put("hibernate.dialect", getHibernateDialect());
entityManagerFactory = Persistence.createEntityManagerFactory("StudentPU", properties);
entityManager = entityManagerFactory.createEntityManager();
prepareTestData();
}

@AfterAll
public void close() {
entityManager.close();
entityManagerFactory.close();
}

@AfterEach
public void cleanup() {
entityManager.clear();
}

protected abstract String getJdbcUrl();

protected abstract String getHibernateDialect();

@Test
public void testLoadStudent() {
Student student = entityManager.find(Student.class, studentIds.get("John Smith"));
assertThat(student).isNotNull();
assertThat(student.getFirstName()).isEqualTo("John");
assertThat(student.getLastName()).isEqualTo("Smith");
assertThat(student.getGender()).isEqualTo(Gender.MALE);
assertThat(student.getAge()).isEqualTo(25);
}

@Test
public void testLoadTeacher() {
Teacher teacher = entityManager.find(Teacher.class, teacherIds.get("Jennifer Brown"));
assertThat(teacher).isNotNull();
assertThat(teacher.getFirstName()).isEqualTo("Jennifer");
assertThat(teacher.getLastName()).isEqualTo("Brown");
assertThat(teacher.getCourses())
.hasSize(2)
.extracting(Course::getTitle)
.containsExactly("Statistics", "Math");
}

@Test
public void testLoadCourse() {
Course course = entityManager.find(Course.class, courseIds.get("Statistics"));
assertThat(course).isNotNull();
assertThat(course.getTitle()).isEqualTo("Statistics");
assertThat(course.getTeacher())
.extracting(Teacher::getFirstName)
.isEqualTo("Jennifer");
assertThat(course.getStudents())
.hasSize(3)
.extracting(Student::getId)
.containsExactly(studentIds.get("John Smith"), studentIds.get("Robert Smith"), studentIds.get("Mary Smith"));
}

@Test
public void testFindStudentsUsingHql() {
List<Student> studentsResult1 = entityManager.createQuery(
"from Student where lastName = :lastName order by firstName",
Student.class
)
.setParameter("lastName", "Smith")
.getResultList();

assertThat(studentsResult1)
.hasSize(3)
.extracting(Student::getId)
.containsExactly(studentIds.get("John Smith"), studentIds.get("Mary Smith"), studentIds.get("Robert Smith"));

List<Student> studentsResult2 = entityManager.createQuery(
"select s from Course as c inner join c.students as s where c.title = :courseTitle",
Student.class
)
.setParameter("courseTitle", "Math")
.getResultList();

assertThat(studentsResult2)
.hasSize(4)
.extracting(Student::getId)
.containsExactly(studentIds.get("John Smith"), studentIds.get("Robert Smith"), studentIds.get("Mary Smith"), studentIds.get("Patricia Miller"));
}

@Test
public void testFindCoursesUsingHql() {
List<Course> coursesResult = entityManager.createQuery(
"from Course where teacher.firstName = :teacherFirstName",
Course.class)
.setParameter("teacherFirstName", "Jennifer")
.getResultList();

assertThat(coursesResult)
.hasSize(2)
.extracting(Course::getId)
.containsExactly(courseIds.get("Statistics"), courseIds.get("Math"));
}

private void prepareTestData() {
entityManager.getTransaction().begin();

Student student1 = createStudent("John", "Smith", Gender.MALE, 25);
Student student2 = createStudent("Robert", "Smith", Gender.MALE, 24);
Student student3 = createStudent("John", "Miller", Gender.MALE, 21);
Student student4 = createStudent("Mary", "Smith", Gender.FEMALE, 26);
Student student5 = createStudent("Patricia", "Miller", Gender.FEMALE, 21);

Teacher teacher1 = createTeacher("Jennifer", "Brown");
Teacher teacher2 = createTeacher("Richard", "Davis");

createCourse("Statistics", teacher1, Arrays.asList(student1, student2, student4));
createCourse("Math", teacher1, Arrays.asList(student1, student2, student4, student5));
createCourse("Design", teacher2, Arrays.asList(student3, student4, student5));

entityManager.getTransaction().commit();
}

private Student createStudent(String firstName, String lastName, Gender gender, int age) {
Student student = new Student();
student.setFirstName(firstName);
student.setLastName(lastName);
student.setGender(gender);
student.setAge(age);
student.setBirthDate(new Date());
entityManager.persist(student);
studentIds.put(firstName + " " + lastName, student.getId());
return student;
}

private Teacher createTeacher(String firstName, String lastName) {
Teacher teacher = new Teacher();
teacher.setFirstName(firstName);
teacher.setLastName(lastName);
entityManager.persist(teacher);
teacherIds.put(firstName + " " + lastName, teacher.getId());
return teacher;
}

private Course createCourse(String title, Teacher teacher, List<Student> students) {
Course course = new Course();
course.setTitle(title);
course.setTeacher(teacher);
course.setStudents(students);
entityManager.persist(course);
courseIds.put(title, course.getId());

CourseMaterial courseMaterial = new CourseMaterial();
courseMaterial.setUrl(title + "Url");
courseMaterial.setCourse(course);
entityManager.persist(courseMaterial);
return course;
}
}
Loading

0 comments on commit 8cf24c9

Please sign in to comment.