Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding jakarta package support for JPA Annotation. #140

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ Currently implemented JPA Annotations are
*** javax.persistence.Table,
*** javax.persistence.MappedSuperclass,
*** javax.persistence.Index and
*** javax.persistence.UniqueConstraint
*** javax.persistence.UniqueConstraint
*** jakarta.persistence.Column,
*** jakarta.persistence.Id,
*** jakarta.persistence.Transient,
*** jakarta.persistence.OneToOne,
*** jakarta.persistence.OneToMany,
*** jakarta.persistence.ManyToMany,
*** jakarta.persistence.ManyToOne,
*** jakarta.persistence.Entity,
*** jakarta.persistence.Table,
*** jakarta.persistence.MappedSuperclass,
*** jakarta.persistence.Index and
*** jakarta.persistence.UniqueConstraint
--
+
Index, UniqueConstraint, Tablename and Tableschema are show as tagged values in a separate compartment
Expand Down
6 changes: 6 additions & 0 deletions plantuml-generator-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,27 @@ the following JPA Annotations:
** javax.persistence.Entity
** javax.persistence.Table
** javax.persistence.MappedSuperclass
** jakarta.persistence.Index
** jakarta.persistence.UniqueConstraint
** jakarta.persistence.Entity
** jakarta.persistence.Table
** jakarta.persistence.MappedSuperclass
* field annotations
** javax.persistence.Column
** javax.persistence.Id
** javax.persistence.Transient
** jakarta.persistence.Column
** jakarta.persistence.Id
** jakarta.persistence.Transient
* relationship annotations
** javax.persistence.OneToOne
** javax.persistence.OneToMany
** javax.persistence.ManyToMany
** javax.persistence.ManyToOne
** jakarta.persistence.OneToOne
** jakarta.persistence.OneToMany
** jakarta.persistence.ManyToMany
** jakarta.persistence.ManyToOne

If class annotations are found the generator adds a separate compartment
to the head of the PlantUML class with all informations found in these
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ List<String> addJPAFieldAnnotationsToList(final java.lang.reflect.Field field, M
ClassLoader destinationClassloader) {
List<String> annotationStringList = new LinkedList<>();
if (destinationClassloader != null) {
// javax.persistance
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"javax.persistence.Column");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
Expand All @@ -40,6 +41,22 @@ List<String> addJPAFieldAnnotationsToList(final java.lang.reflect.Field field, M
"javax.persistence.ManyToMany");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"javax.persistence.ManyToOne");

// jakarta.persistance
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.Column");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.Id");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.Transient");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.OneToOne");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.OneToMany");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.ManyToMany");
addJPAFieldAnnotationClassToList(field, paramDeclaredMethods, annotationStringList, destinationClassloader,
"jakarta.persistence.ManyToOne");
}
return annotationStringList;
}
Expand Down Expand Up @@ -119,12 +136,21 @@ private String getColumnAnnotationString(Annotation annotation, String annotatio
protected void addJPAStereotype(final Class<?> paramClassObject, List<UMLStereotype> stereotypes, ClassLoader destinationClassloader) {
if (destinationClassloader != null) {
try {
// javax.persistance
addStereoTypesForAnnotationClass(paramClassObject, stereotypes, destinationClassloader,
"javax.persistence.Entity", "Entity");
addStereoTypesForAnnotationClass(paramClassObject, stereotypes, destinationClassloader,
"javax.persistence.Table", "Table");
addStereoTypesForAnnotationClass(paramClassObject, stereotypes, destinationClassloader,
"javax.persistence.MappedSuperclass", "MappedSuperclass");

// jakarta.persistance
addStereoTypesForAnnotationClass(paramClassObject, stereotypes, destinationClassloader,
"jakarta.persistence.Entity", "Entity");
addStereoTypesForAnnotationClass(paramClassObject, stereotypes, destinationClassloader,
"jakarta.persistence.Table", "Table");
addStereoTypesForAnnotationClass(paramClassObject, stereotypes, destinationClassloader,
"jakarta.persistence.MappedSuperclass", "MappedSuperclass");
} catch (ClassNotFoundException | SecurityException | IllegalArgumentException e) {
// ignore all exceptions
}
Expand Down Expand Up @@ -168,10 +194,18 @@ private void addAnnotationStereotype(List<UMLStereotype> stereotypes, Annotation
if ("Table".equals(annotationName)) {
addAttributeIfExists(annotation, attributes, "name");
addAttributeIfExists(annotation, attributes, "schema");

// javax.persistance
addAttributeObjectListIfExists(annotation, attributes, "javax.persistence.Index", "indexes",
destinationClassloader);
addAttributeObjectListIfExists(annotation, attributes, "javax.persistence.UniqueConstraint",
"uniqueConstraints", destinationClassloader);

// jakarta.persistance
addAttributeObjectListIfExists(annotation, attributes, "jakarta.persistence.Index", "indexes",
destinationClassloader);
addAttributeObjectListIfExists(annotation, attributes, "jakarta.persistence.UniqueConstraint",
"uniqueConstraints", destinationClassloader);
}
UMLStereotype stereotype = new UMLStereotype(annotationName, attributes);
stereotypes.add(stereotype);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ private CtMethod findStartingMethodInClassPool(ClassPool cp) throws javassist.No
private boolean isIgnoreCall(CtClass calleeClass, CtMethod calleeMethod) {
boolean ignoreCall = config.isIgnoreStandardClasses() && isJavaStandardClass(calleeClass);
// handle all ignore cases
if (config.isIgnoreJPAEntities() && calleeClass.hasAnnotation("javax.persistence.Entity")) ignoreCall = true;
if (config.isIgnoreJPAEntities()
&& (calleeClass.hasAnnotation("javax.persistence.Entity")
|| calleeClass.hasAnnotation("jakarta.persistence.Entity"))
) {
ignoreCall = true;
}
if (config.getClassBlacklistRegexp() != null && isClassBlacklisted(calleeClass)) ignoreCall = true;
if (config.getMethodBlacklistRegexp() != null && isMethodBlacklisted(calleeMethod)) ignoreCall = true;
return ignoreCall;
Expand Down Expand Up @@ -163,4 +168,4 @@ public ICallerMethod analyzeCallSequence() throws NotFoundException, CannotCompi
CtMethod method = findStartingMethodInClassPool(cp);
return getCallerMethod(method, null, null);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.elnarion.test.domain.t0021jakarta;

import jakarta.persistence.Entity;

@Entity
public class Address {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.elnarion.test.domain.t0021jakarta;

import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Version;

@MappedSuperclass
public class Employee {

@Id
protected Integer empId;
@Version
protected Integer version;
@ManyToOne
@JoinColumn(name = "ADDR")
protected Address address;

public Integer getEmpId() {
return empId;
}

public void setEmpId(Integer paramId) {
empId = paramId;
}

public Address getAddress() {
return address;
}

public void setAddress(Address paramAddress) {
address = paramAddress;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.elnarion.test.domain.t0021jakarta;

import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

@Entity
@Table(name = "FTEmployee", indexes = { @Index(columnList = "salaray,empId", unique = true),
@Index(columnList = "version") }, uniqueConstraints = { @UniqueConstraint(columnNames = "empId"),
@UniqueConstraint(columnNames = "empId,version") })
public class FTEmployee extends Employee {

// Inherited empId field mapped to FTEMPLOYEE.EMPID
// Inherited version field mapped to FTEMPLOYEE.VERSION
// Inherited address field mapped to FTEMPLOYEE.ADDR fk

// Defaults to FTEMPLOYEE.SALARY
protected Integer salary;

public FTEmployee() {
}

public Integer getSalary() {
return salary;
}

public void setSalary(Integer paramSalary) {
this.salary = paramSalary;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package de.elnarion.test.domain.t0021jakarta;

import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;

@Entity
public class Family {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String description;

@OneToMany(mappedBy = "family")
private final List<Person> members = new ArrayList<Person>();

public int getId() {
return id;
}

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

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public List<Person> getMembers() {
return members;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.elnarion.test.domain.t0021jakarta;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;

@Entity
public class Job {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private double salery;
private String jobDescr;

public int getId() {
return id;
}

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

public double getSalery() {
return salery;
}

public void setSalery(double salery) {
this.salery = salery;
}

public String getJobDescr() {
return jobDescr;
}

public void setJobDescr(String jobDescr) {
this.jobDescr = jobDescr;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package de.elnarion.test.domain.t0021jakarta;

import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Transient;

@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private String id;
private String firstName;
private String lastName;

private Family family;

private String nonsenseField = "";

private List<Job> jobList = new ArrayList<Job>();

public String getId() {
return id;
}

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

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

// Leave the standard column name of the table
public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

@ManyToOne
public Family getFamily() {
return family;
}

public void setFamily(Family family) {
this.family = family;
}

@Transient
public String getNonsenseField() {
return nonsenseField;
}

public void setNonsenseField(String nonsenseField) {
this.nonsenseField = nonsenseField;
}

@OneToMany
public List<Job> getJobList() {
return this.jobList;
}

public void setJobList(List<Job> nickName) {
this.jobList = nickName;
}

}
Loading