-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JPA] Implémentation des compositions sur les classes persistées
- Loading branch information
1 parent
d9d51ec
commit ea971f2
Showing
15 changed files
with
116 additions
and
40 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
|
@@ -72,9 +72,18 @@ public void WriteCompositePrimaryKeyClass(JavaWriter fw, Class classe, string ta | |
fw.WriteLine(1, "}"); | ||
} | ||
|
||
public void WriteCompositionProperty(JavaWriter fw, CompositionProperty property) | ||
public void WriteCompositionProperty(JavaWriter fw, CompositionProperty property, string tag) | ||
{ | ||
fw.WriteDocEnd(1); | ||
if (property.Class.IsPersistent) | ||
{ | ||
var javaOrJakarta = _config.PersistenceMode.ToString().ToLower(); | ||
fw.AddImport($"{javaOrJakarta}.persistence.Convert"); | ||
fw.AddImport(_config.CompositionConverterCanonicalName.Replace("{class}", property.Class.Name).Replace("{package}", _config.GetPackageName(property.Class, tag))); | ||
fw.WriteLine(1, $"@Convert(converter = {_config.CompositionConverterSimpleName.Replace("{class}", property.Class.Name)}.class)"); | ||
WriteColumnAnnotation(fw, property, 1); | ||
} | ||
|
||
fw.WriteLine(1, $"private {_config.GetType(property)} {property.NameCamel};"); | ||
} | ||
|
||
|
@@ -127,7 +136,7 @@ public void WriteProperty(JavaWriter fw, Class classe, IProperty property, strin | |
switch (property) | ||
{ | ||
case CompositionProperty cp: | ||
WriteCompositionProperty(fw, cp); | ||
WriteCompositionProperty(fw, cp, tag); | ||
break; | ||
case AssociationProperty { Association.IsPersistent: true } ap: | ||
WriteAssociationProperty(fw, classe, ap, tag); | ||
|
@@ -328,31 +337,41 @@ private void WriteAutogeneratedAnnotations(JavaWriter fw, Class classe, string j | |
} | ||
} | ||
|
||
private void WriteColumnAnnotation(JavaWriter fw, IFieldProperty property, int indentLevel) | ||
private void WriteColumnAnnotation(JavaWriter fw, IProperty property, int indentLevel) | ||
{ | ||
var javaOrJakarta = _config.PersistenceMode.ToString().ToLower(); | ||
string column; | ||
if (!_config.UseJdbc) | ||
{ | ||
column = @$"@Column(name = ""{property.SqlName}"", nullable = {(!property.Required).ToString().ToFirstLower()}"; | ||
if (property.Domain.Length != null) | ||
if (property.Domain != null) | ||
{ | ||
Check warning on line 348 in TopModel.Generator.Jpa/JpaModelPropertyGenerator.cs GitHub Actions / build
|
||
if (_config.GetImplementation(property.Domain)?.Type?.ToUpper() == "STRING") | ||
|
||
if (property.Domain.Length != null) | ||
{ | ||
column += $", length = {property.Domain.Length}"; | ||
if (_config.GetImplementation(property.Domain)?.Type?.ToUpper() == "STRING") | ||
{ | ||
column += $", length = {property.Domain.Length}"; | ||
} | ||
else | ||
{ | ||
column += $", precision = {property.Domain.Length}"; | ||
} | ||
} | ||
else | ||
|
||
if (property.Domain.Scale != null) | ||
{ | ||
column += $", precision = {property.Domain.Length}"; | ||
column += $", scale = {property.Domain.Scale}"; | ||
} | ||
|
||
column += @$", columnDefinition = ""{property.Domain.Implementations["sql"].Type}"""; | ||
} | ||
|
||
if (property.Domain.Scale != null) | ||
if (property is CompositionProperty && property.Domain is null) | ||
{ | ||
column += $", scale = {property.Domain.Scale}"; | ||
column += @$", columnDefinition = ""jsonb"""; | ||
} | ||
|
||
column += @$", columnDefinition = ""{property.Domain.Implementations["sql"].Type}"""; | ||
column += ")"; | ||
fw.AddImport($"{javaOrJakarta}.persistence.Column"); | ||
} | ||
|
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
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
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
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
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
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
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
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
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
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
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