91 lines
3.1 KiB
Plaintext
91 lines
3.1 KiB
Plaintext
/**
|
|
* Auto-generated from apibuilder.io service specification.
|
|
* apidoc-version : {{service.apidoc.version}}
|
|
* organisation : {{service.organization.key}}
|
|
* service-version : {{service.version}}
|
|
*
|
|
* Documentation at:
|
|
* <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}</a>
|
|
*
|
|
**/
|
|
package {{package}};
|
|
|
|
import javax.persistence.*;
|
|
import org.hibernate.annotations.CreationTimestamp;
|
|
import org.hibernate.annotations.GenericGenerator;
|
|
import org.hibernate.annotations.Type;
|
|
import org.hibernate.annotations.UpdateTimestamp;
|
|
import lombok.Data;
|
|
{{#imports}}
|
|
import {{{.}}};
|
|
{{/imports}}
|
|
|
|
import java.util.Collections;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* {{description}}
|
|
* See <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}#model-{{model.name}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}#model-{{model.name}}</a>
|
|
*
|
|
**/
|
|
@Entity
|
|
@Data
|
|
@Table(
|
|
name = "{{table}}",
|
|
indexes = {
|
|
{{#indexes}}
|
|
@Index(columnList = "{{.}}"),
|
|
{{/indexes}}
|
|
}
|
|
)
|
|
public class {{name}} {
|
|
|
|
{{#fields}}
|
|
{{#description}}/** {{.}} **/{{/description}}{{#isPkey}}
|
|
@Id{{#id_generator}}
|
|
@GeneratedValue({{#name}}generator = "{{.}}"{{/name}}){{#strategy}}
|
|
@GenericGenerator(name = "{{name}}", strategy = "{{.}}"){{/strategy}}{{#id_type}}
|
|
@Type(type = "{{.}}"){{/id_type}}{{/id_generator}}{{/isPkey}}{{#type.isCollection}}
|
|
@ManyToMany{{/type.isCollection}}
|
|
{{^oneToOne}}{{^isRecord}}{{^type.isCollection}}
|
|
@Column(
|
|
nullable = {{nullable}},
|
|
unique = {{unique}},
|
|
columnDefinition = "{{columnType}}"
|
|
){{/type.isCollection}}{{/isRecord}}{{/oneToOne}}{{#isEnum}}
|
|
@Enumerated(EnumType.STRING){{/isEnum}}{{#updateTimestamp}}
|
|
@UpdateTimestamp{{/updateTimestamp}}{{#creationTimestamp}}
|
|
@CreationTimestamp{{/creationTimestamp}}{{#oneToMany}}
|
|
@OneToMany{{/oneToMany}}{{#oneToOne}}
|
|
@OneToOne{{/oneToOne}}{{#isRecord}}{{^isCollection}}
|
|
@ManyToOne{{/isCollection}}{{/isRecord}}
|
|
private {{{type.name}}} {{name}}{{#default}} = {{{.}}}{{/default}};
|
|
|
|
{{/fields}}
|
|
|
|
public {{modelType}} toModel() {
|
|
{{modelType}} {{modelName}} = new {{modelType}}();
|
|
|
|
{{#fields}}
|
|
{{#isRecord}}{{#type.isCollection}}
|
|
{{modelName}}.set{{namePascalCase}}(
|
|
this.{{name}} != null
|
|
? this.{{name}}.stream()
|
|
.map({{type.baseType}}::toModel)
|
|
.collect(Collectors.toList())
|
|
: Collections.emptyList()
|
|
);
|
|
{{/type.isCollection}}{{^type.isCollection}}
|
|
{{modelName}}.set{{namePascalCase}}(this.{{name}} != null ? this.{{name}}.toModel() : null);
|
|
{{/type.isCollection}}
|
|
{{/isRecord}}
|
|
{{^isRecord}}
|
|
{{modelName}}.set{{namePascalCase}}(this.{{name}});
|
|
{{/isRecord}}
|
|
{{/fields}}
|
|
|
|
return {{modelName}};
|
|
}
|
|
|
|
|
|
} |