Skip to content

Commit

Permalink
ClassWeaver refresh - code generated by weaving (#2049)
Browse files Browse the repository at this point in the history
Contains following main changes:
- Replacement of deprecated e.g. new Integer(...) by Integer.valueOf(...)
- Generated _persistence_shallow_clone content is wrapped by try/catch
- Remove dependency to JPA module (org.eclipse.persistence.internal.jpa.EntityManagerImpl class) in generated _persistence_checkFetched and _persistence_checkFetchedForSet

There are some extensions in weaving test to more deeply check methods/logic generated by ClassWeaver.

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Jan 30, 2024
1 parent a5cdf1d commit 7dd60fd
Show file tree
Hide file tree
Showing 7 changed files with 473 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ public static StaticWeaveException exceptionPerformWeaving(Exception cause, Obje
return loadingException;
}


public String getResourceName(){
return resourceName;
}
Expand Down
25 changes: 24 additions & 1 deletion jpa/eclipselink.jpa.testapps/jpa.test.weaving/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2023, 2024 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
Expand Down Expand Up @@ -33,9 +33,20 @@

<build>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<filtering>true</filtering>
<includes>
<include>persistence.xml</include>
</includes>
<targetPath>META-INF</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
<plugins>
Expand Down Expand Up @@ -99,6 +110,12 @@
</classpathDependencyExcludes>
<systemPropertyVariables>
<eclipselink.asm.service>eclipselink</eclipselink.asm.service>
<!--Following system properties must be initialized again as systemPropertyVariables reset environment.-->
<db.driver>${db.driver}</db.driver>
<db.url>${db.url}</db.url>
<db.user>${db.user}</db.user>
<db.pwd>${db.pwd}</db.pwd>
<db.platform>${db.platform}</db.platform>
</systemPropertyVariables>
</configuration>
</execution>
Expand All @@ -110,6 +127,12 @@
<configuration>
<systemPropertyVariables>
<eclipselink.asm.service>ow2</eclipselink.asm.service>
<!--Following system properties must be initialized again as systemPropertyVariables reset environment.-->
<db.driver>${db.driver}</db.driver>
<db.url>${db.url}</db.url>
<db.user>${db.user}</db.user>
<db.pwd>${db.pwd}</db.pwd>
<db.platform>${db.platform}</db.platform>
</systemPropertyVariables>
<classpathDependencyExcludes>
<classpathDependencyExclude>org.eclipse.persistence.asm</classpathDependencyExclude>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024 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 version="3.0" xmlns="https://jakarta.ee/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">

<persistence-unit name="weaving-dir-test-pu" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.eclipse.persistence.testing.models.jpa.weaving.WeavingEntityInDir</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
<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}"/>
<property name="eclipse.weaving" value="static"/>
</properties>
</persistence-unit>
</persistence>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 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
*/

// Contributors:
// Oracle - initial API and implementation
package org.eclipse.persistence.testing.models.jpa.weaving;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

public class WeavingChangeListener implements PropertyChangeListener {

private boolean listenerInvoked = false;

@Override
public void propertyChange(PropertyChangeEvent evt) {
listenerInvoked = true;
}

public boolean isListenerInvoked() {
return listenerInvoked;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2024 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
*/

// Contributors:
// Oracle - initial API and implementation
package org.eclipse.persistence.testing.models.jpa.weaving;

import jakarta.persistence.Basic;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import org.eclipse.persistence.annotations.FetchAttribute;
import org.eclipse.persistence.annotations.FetchGroup;

@Entity
@FetchGroup(name="FloatingPointFieldsOnly",
attributes={
@FetchAttribute(name="floatField"),
@FetchAttribute(name="doubleField")})
@Cacheable(false)
public class WeavingEntityInDir {
private int id;
private boolean booleanField;
private byte byteField;
private short shortField;
private int intField;
private long longField;
private float floatField;
private double doubleField;
private String stringField;
private byte[] blobField;

public WeavingEntityInDir() {
}

public WeavingEntityInDir(int id) {
this.id = id;
}

@Id
public int getId() {
return this.id;
}

public void setId(int id) {
this.id = id;
}

public boolean isBooleanField() {
return booleanField;
}

public void setBooleanField(boolean booleanField) {
this.booleanField = booleanField;
}

public byte getByteField() {
return byteField;
}

public void setByteField(byte byteField) {
this.byteField = byteField;
}

public short getShortField() {
return shortField;
}

public void setShortField(short shortFiled) {
this.shortField = shortFiled;
}

public int getIntField() {
return intField;
}

public void setIntField(int intField) {
this.intField = intField;
}

public long getLongField() {
return longField;
}

public void setLongField(long longField) {
this.longField = longField;
}

public float getFloatField() {
return floatField;
}

public void setFloatField(float floatField) {
this.floatField = floatField;
}

public double getDoubleField() {
return doubleField;
}

public void setDoubleField(double doubleField) {
this.doubleField = doubleField;
}

public String getStringField() {
return stringField;
}

public void setStringField(String stringField) {
this.stringField = stringField;
}

@Lob
@Column(length=4800)
@Basic(fetch= FetchType.LAZY)
public byte[] getBlobField() {
return blobField;
}

public void setBlobField(byte[] blobField) {
this.blobField = blobField;
}
}

0 comments on commit 7dd60fd

Please sign in to comment.