Skip to content

Commit

Permalink
Merge pull request #30 from ZenWave360/develop
Browse files Browse the repository at this point in the history
Preparing next release
  • Loading branch information
ivangsa authored May 12, 2024
2 parents 22c7777 + c97d317 commit 4aa06ae
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public enum TransactionalOutboxType {
handlebarsEngine.getHandlebars().registerHelper("methodSuffix", (context, options) -> {
boolean doExposeMessage = "true".equals(String.valueOf(options.hash.get("exposeMessage")));
boolean isProducer = "true".equals(String.valueOf(options.hash.get("producer")));;
if (isProducer || doExposeMessage || exposeMessage || style == ProgrammingStyle.reactive) {
if (doExposeMessage || exposeMessage || style == ProgrammingStyle.reactive) {
int messagesCount = JSONPath.get(options.param(0), "$.x--messages.length()", 0);
if (messagesCount > 1) {
String messageJavaType = JSONPath.get(context, "$.x--javaTypeSimpleName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}}
@Column(name = "{{snakeCase relationship.fieldName}}_id")
private {{idJavaType}} {{relationship.fieldName}}Id;
{{~/if}}
{{> (partial 'partials/' relationship.type)}}
{{#unless (addRelationshipById relationship entity=entity)}}{{#if relationship.required}}@NotNull{{/if}}{{/unless}}
{{> (partial 'partials/' relationship.type)}}
private {{{relationshipFieldType relationship}}} {{relationship.fieldName}} {{{relationshipFieldTypeInitializer relationship}}};
{{/if~}}
{{/each}}
Expand All @@ -104,6 +104,38 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}}
protected LocalDateTime lastModifiedDate;
{{~/if}}

{{~#each (jsonPath entity '$.relationships[*][?(@.ownerSide == true)]') as |relationship|}}
// manage relationships
{{~#if (eq relationship.type 'OneToOne')}}
public {{entity.className}} set{{capitalize relationship.fieldName}}({{{relationshipFieldType relationship}}} {{relationship.fieldName}}) {
this.{{relationship.fieldName}} = {{relationship.fieldName}};
{{relationship.fieldName}}.set{{capitalize relationship.otherEntityFieldName}}(this);
return this;
}
{{~/if}}
{{~#if (eq relationship.type 'OneToMany')}}
public {{entity.className}} add{{capitalize relationship.fieldName}}({{relationship.otherEntityName}} {{relationship.fieldName}}) {
this.{{relationship.fieldName}}.add({{relationship.fieldName}});
{{relationship.fieldName}}.set{{capitalize relationship.otherEntityFieldName}}(this);
return this;
}
{{~/if}}
{{~#if (eq relationship.type 'ManyToMany')}}
public {{entity.className}} add{{capitalize relationship.fieldName}}({{relationship.otherEntityName}} {{relationship.fieldName}}) {
this.{{relationship.fieldName}}.add({{relationship.fieldName}});
{{relationship.fieldName}}.get{{capitalize relationship.otherEntityFieldName}}().add(this);
return this;
}
{{~/if}}
{{~#if (and (eq relationship.type 'ManyToOne') relationship.otherEntityFieldName)}}
public {{entity.className}} set{{capitalize relationship.fieldName}}({{{relationshipFieldType relationship}}} {{relationship.fieldName}}) {
this.{{relationship.fieldName}} = {{relationship.fieldName}};
{{relationship.fieldName}}.get{{capitalize relationship.otherEntityFieldName}}().add(this);
return this;
}
{{~/if}}
{{/each}}

{{#unless useLombok~}}
{{#unless (skipEntityId entity)~}}
public {{idJavaType}} getId() {
Expand Down Expand Up @@ -147,10 +179,12 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}}
public {{{relationshipFieldType relationship}}} get{{capitalize relationship.fieldName}}() {
return {{relationship.fieldName}};
}
{{~#unless (and (endsWith relationship.type 'ToOne') relationship.ownerSide relationship.otherEntityFieldName)}}
public {{entity.className}} set{{capitalize relationship.fieldName}}({{{relationshipFieldType relationship}}} {{relationship.fieldName}}) {
this.{{relationship.fieldName}} = {{relationship.fieldName}};
return this;
}
{{~/unless}}
{{/if~}}
{{/each}}

Expand Down Expand Up @@ -191,7 +225,7 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}}
return this;
}
{{/if}}
{{/unless~}}
{{/unless~}}{{!-- ends no lombok --}}

{{#unless (skipEntityId entity)~}}
/* https://vladmihalcea.com/the-best-way-to-implement-equals-hashcode-and-tostring-with-jpa-and-hibernate/ */
Expand All @@ -204,7 +238,7 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}}
return false;
}
{{entity.className}} other = ({{entity.className}}) o;
return id != null && id.equals(other.id);
return getId() != null && getId().equals(other.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@ManyToMany{{#if relationship.ownerSide}}(cascade = CascadeType.ALL){{else}}(mappedBy = "{{relationship.otherEntityFieldName}}"){{/if}}
{{~#if relationship.ownerSide}}
{{~#if relationship.required}}
@NotNull
{{~/if}}
@JoinTable(name = "{{snakeCase (concat entity.name relationship.otherEntityName)}}",
joinColumns = @JoinColumn(name = "{{snakeCase (concat entity.name '_id')}}", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "{{snakeCase (concat relationship.otherEntityName '_id')}}", referencedColumnName = "id"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{{#if relationship.ownerSide}}
@ManyToOne({{#if (addRelationshipById relationship entity=entity)}}fetch = FetchType.LAZY{{else}}cascade = CascadeType.ALL{{/if}})
@ManyToOne(fetch = FetchType.LAZY {{#unless (addRelationshipById relationship entity=entity)}}, cascade = CascadeType.ALL{{/unless}})
@JoinColumn(name = "{{snakeCase relationship.fieldName}}_id"{{#if (addRelationshipById relationship entity=entity)}}, updatable = false, insertable = false{{/if}})
{{else}}
{{~#if relationship.required}}
@NotNull
{{~/if}}
@OneToMany(mappedBy="{{relationship.otherEntityFieldName}}", fetch = FetchType.LAZY)
{{/if}}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{{#if relationship.ownerSide}}
{{~#if relationship.required}}
@NotNull
{{~/if}}
@OneToMany(mappedBy = "{{relationship.otherEntityFieldName}}"{{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
@OneToMany({{#if relationship.otherEntityFieldName}}mappedBy = "{{relationship.otherEntityFieldName}}",{{/if}} fetch = FetchType.LAZY{{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
{{else}}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "{{snakeCase relationship.fieldName}}_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{{#if relationship.ownerSide }}
@OneToOne(fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
{{~#if relationship.required}}
@NotNull
{{~/if}}
{{#if relationship.otherEntityFieldName ~}}
{{!-- bidirectional --}}
{{#if relationship.ownerSide }}
@OneToOne(mappedBy = "{{relationship.otherEntityFieldName}}", fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
{{~else~}}
{{~#if relationship.mapsId}}
@MapsId
@JoinColumn(name = "id")
{{~else}}
@JoinColumn(unique = true)
{{/if~}}
@OneToOne(fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
{{/if~}}
{{~else~}}
{{~#if relationship.mapsId}}
@MapsId
@JoinColumn(name = "id")
{{~else}}
@JoinColumn(unique = true)
{{!-- unidirectional --}}
{{#if relationship.ownerSide }}
@JoinColumn(unique = true)
@OneToOne(fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
{{/if~}}
@OneToOne(mappedBy = "{{relationship.otherEntityFieldName}}", fetch = FetchType.LAZY {{#if entity.options.aggregate}}, cascade = CascadeType.ALL, orphanRemoval = true{{/if}})
{{/if~}}
{{~/if~}}

Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}}
return false;
}
{{entity.className}} other = ({{entity.className}}) o;
return id != null && id.equals(other.id);
return getId() != null && getId().equals(other.getId());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{infrastructurePackage}}.jpa;
package {{infrastructureRepositoryPackage}};

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{infrastructurePackage}}.jpa;
package {{infrastructureRepositoryPackage}};

import java.util.HashSet;
import java.time.*;
Expand Down Expand Up @@ -75,7 +75,9 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor
// Persist aggregate root
var created = {{entity.instanceName}}Repository.save({{entity.instanceName}});

entityManager.refresh(created); // reloading to get relationships persisted by id
// reloading to get relationships persisted by id
entityManager.flush();
entityManager.refresh(created);
Assertions.assertTrue(created.getId() != null);
Assertions.assertTrue(created.getVersion() != null);
{{~#if (or entity.options.auditing entity.options.extendsAuditing)}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{infrastructurePackage}}.mongodb;
package {{infrastructureRepositoryPackage}};

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package {{infrastructurePackage}}.mongodb;
package {{infrastructureRepositoryPackage}};

import {{entitiesPackage}}.*;
import {{outboundRepositoryPackage}}.{{entity.className}}Repository;
Expand Down

0 comments on commit 4aa06ae

Please sign in to comment.