-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EntityManagerFactory.withTransaction() as default implementation. (#1884
) Signed-off-by: Tomáš Kraus <[email protected]>
- Loading branch information
1 parent
191dccd
commit eea7f20
Showing
8 changed files
with
689 additions
and
1 deletion.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
jpa/eclipselink.jpa.testapps/jpa.test.persistence32/pom.xml
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,86 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0, | ||
or the Eclipse Distribution License v. 1.0 which is available at | ||
http://www.eclipse.org/org/documents/edl-v10.php. | ||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
--> | ||
|
||
<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"> | ||
<parent> | ||
<artifactId>org.eclipse.persistence.jpa.testapps</artifactId> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<version>4.1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>org.eclipse.persistence.jpa.testapps.persistence32</artifactId> | ||
|
||
<name>Test - Jakarta Persistence 3.2</name> | ||
|
||
<properties> | ||
<argLine/> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<!--Resolve dependencies into Maven properties like ${org.eclipse.persistence:org.eclipse.persistence.jpa:jar} for JPA module--> | ||
<execution> | ||
<id>get-test-classpath-to-properties</id> | ||
<phase>process-test-classes</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.carlspring.maven</groupId> | ||
<artifactId>derby-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>start-derby</id> | ||
<phase>process-test-classes</phase> | ||
</execution> | ||
<execution> | ||
<id>stop-derby</id> | ||
<phase>prepare-package</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-test</id> | ||
<configuration> | ||
<argLine>-javaagent:${org.eclipse.persistence:org.eclipse.persistence.jpa:jar} @{argLine}</argLine> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>package-model</id> | ||
<phase>package</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
51 changes: 51 additions & 0 deletions
51
...a/org/eclipse/persistence/testing/models/jpa/persistence32/Persistence32TableCreator.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,51 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
package org.eclipse.persistence.testing.models.jpa.persistence32; | ||
|
||
import org.eclipse.persistence.testing.framework.TogglingFastTableCreator; | ||
import org.eclipse.persistence.tools.schemaframework.TableDefinition; | ||
|
||
public class Persistence32TableCreator extends TogglingFastTableCreator { | ||
|
||
public Persistence32TableCreator() { | ||
setName("Persistence32Project"); | ||
addTableDefinition(buildTypeTable()); | ||
addTableDefinition(buildPokemonTable()); | ||
addTableDefinition(buildPokemonTypeTable()); | ||
} | ||
|
||
public static TableDefinition buildTypeTable() { | ||
TableDefinition table = new TableDefinition(); | ||
table.setName("PERSISTENCE32_TYPE"); | ||
table.addField(createNumericPk("ID")); | ||
table.addField(createStringColumn("NAME", 64, false)); | ||
return table; | ||
} | ||
|
||
public static TableDefinition buildPokemonTable() { | ||
TableDefinition table = new TableDefinition(); | ||
table.setName("PERSISTENCE32_POKEMON"); | ||
table.addField(createNumericPk("ID")); | ||
table.addField(createStringColumn("NAME", 64, false)); | ||
return table; | ||
} | ||
|
||
public static TableDefinition buildPokemonTypeTable() { | ||
TableDefinition table = new TableDefinition(); | ||
table.setName("PERSISTENCE32_POKEMON_TYPE"); | ||
table.addField(createNumericFk("POKEMON_ID", "PERSISTENCE32_POKEMON.ID")); | ||
table.addField(createNumericFk("TYPE_ID", "PERSISTENCE32_TYPE.ID")); | ||
return table; | ||
} | ||
|
||
} |
128 changes: 128 additions & 0 deletions
128
...nce32/src/main/java/org/eclipse/persistence/testing/models/jpa/persistence32/Pokemon.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,128 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
package org.eclipse.persistence.testing.models.jpa.persistence32; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.JoinTable; | ||
import jakarta.persistence.ManyToMany; | ||
import jakarta.persistence.NamedQuery; | ||
import jakarta.persistence.Table; | ||
|
||
@Entity | ||
@Table(name="PERSISTENCE32_POKEMON") | ||
@NamedQuery(name="Pokemon.get", query="SELECT p FROM Pokemon p WHERE p.id = :id") | ||
public class Pokemon { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private int id; | ||
|
||
private String name; | ||
|
||
@ManyToMany | ||
@JoinTable(name = "PERSISTENCE32_POKEMON_TYPE", | ||
joinColumns = @JoinColumn( | ||
name = "POKEMON_ID", | ||
referencedColumnName = "ID" | ||
), | ||
inverseJoinColumns = @JoinColumn( | ||
name = "TYPE_ID", | ||
referencedColumnName = "ID" | ||
)) | ||
private Collection<Type> types; | ||
|
||
public Pokemon() { | ||
} | ||
|
||
public Pokemon(String name, Collection<Type> types) { | ||
this.name = name; | ||
this.types = types; | ||
} | ||
|
||
public Pokemon(int id, String name, Collection<Type> types) { | ||
this(name, types); | ||
this.id = id; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Collection<Type> getTypes() { | ||
return types; | ||
} | ||
|
||
public void setTypes(Collection<Type> types) { | ||
this.types = types; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || obj.getClass() != this.getClass()) { | ||
return false; | ||
} | ||
return id == ((Pokemon) obj).id | ||
&& Objects.equals(name, ((Pokemon) obj).name) | ||
&& Objects.deepEquals(types, ((Pokemon) obj).types); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = Objects.hash(id, name); | ||
for (Type type : types) { | ||
result = 31 * result + type.hashCode(); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Pokemon {id="); | ||
sb.append(id); | ||
sb.append(", name="); | ||
sb.append(name); | ||
sb.append(", types=["); | ||
boolean first = true; | ||
for (Type type : types) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
sb.append(", "); | ||
} | ||
sb.append(type.toString()); | ||
} | ||
sb.append("]}"); | ||
return sb.toString(); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
...stence32/src/main/java/org/eclipse/persistence/testing/models/jpa/persistence32/Type.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,81 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, | ||
* or the Eclipse Distribution License v. 1.0 which is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
*/ | ||
|
||
package org.eclipse.persistence.testing.models.jpa.persistence32; | ||
|
||
import java.util.Objects; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.NamedQuery; | ||
import jakarta.persistence.Table; | ||
|
||
@Entity | ||
@Table(name="PERSISTENCE32_TYPE") | ||
@NamedQuery(name="Type.all", query="SELECT t FROM Type t") | ||
public class Type { | ||
|
||
@Id | ||
private int id; | ||
|
||
private String name; | ||
|
||
public Type() { | ||
} | ||
|
||
public Type(int id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null || obj.getClass() != this.getClass()) { | ||
return false; | ||
} | ||
return id == ((Type) obj).id | ||
&& Objects.equals(name, ((Type) obj).name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Type {id="); | ||
sb.append(id); | ||
sb.append(", name="); | ||
sb.append(name); | ||
sb.append("}"); | ||
return sb.toString(); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...lipselink.jpa.testapps/jpa.test.persistence32/src/main/resources/META-INF/persistence.xml
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,35 @@ | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0 which is available at | ||
http://www.eclipse.org/legal/epl-2.0, | ||
or the Eclipse Distribution License v. 1.0 which is available at | ||
http://www.eclipse.org/org/documents/edl-v10.php. | ||
SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause | ||
--> | ||
|
||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence | ||
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" | ||
version="2.1"> | ||
|
||
<!-- This is the default persistence unit --> | ||
<persistence-unit name="persistence32" transaction-type="RESOURCE_LOCAL"> | ||
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> | ||
<class>org.eclipse.persistence.testing.models.jpa.persistence32.Pokemon</class> | ||
<class>org.eclipse.persistence.testing.models.jpa.persistence32.Type</class> | ||
<exclude-unlisted-classes>true</exclude-unlisted-classes> | ||
<properties> | ||
<property name="jakarta.persistence.schema-generation.scripts.action" value="none"/> | ||
<property name="eclipselink.logging.level" value="${eclipselink.logging.level}"/> | ||
<property name="eclipselink.logging.level.sql" value="${eclipselink.logging.sql.level}"/> | ||
<property name="eclipselink.logging.parameters" value="${eclipselink.logging.parameters}"/> | ||
</properties> | ||
</persistence-unit> | ||
|
||
</persistence> |
Oops, something went wrong.