Tony CHEMIT pushed to branch develop at ultreiaio / ird-observe
Commits:
-
a6757019
by Tony Chemit at 2020-08-15T12:19:54+02:00
2 changed files:
- − persistence/src/main/java/fr/ird/observe/entities/EntityImpl.java
- templates/src/main/java/fr/ird/observe/toolkit/templates/entity/EntityTransformer.java
Changes:
| 1 |
-package fr.ird.observe.entities;
|
|
| 2 |
- |
|
| 3 |
-/*-
|
|
| 4 |
- * #%L
|
|
| 5 |
- * ObServe :: Persistence
|
|
| 6 |
- * %%
|
|
| 7 |
- * Copyright (C) 2008 - 2020 IRD, Code Lutin, Ultreia.io
|
|
| 8 |
- * %%
|
|
| 9 |
- * This program is free software: you can redistribute it and/or modify
|
|
| 10 |
- * it under the terms of the GNU General Public License as
|
|
| 11 |
- * published by the Free Software Foundation, either version 3 of the
|
|
| 12 |
- * License, or (at your option) any later version.
|
|
| 13 |
- *
|
|
| 14 |
- * This program is distributed in the hope that it will be useful,
|
|
| 15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 17 |
- * GNU General Public License for more details.
|
|
| 18 |
- *
|
|
| 19 |
- * You should have received a copy of the GNU General Public
|
|
| 20 |
- * License along with this program. If not, see
|
|
| 21 |
- * <http://www.gnu.org/licenses/gpl-3.0.html>.
|
|
| 22 |
- * #L%
|
|
| 23 |
- */
|
|
| 24 |
- |
|
| 25 |
- |
|
| 26 |
-import io.ultreia.java4all.bean.definition.JavaBeanDefinition;
|
|
| 27 |
-import io.ultreia.java4all.bean.definition.JavaBeanDefinitionStore;
|
|
| 28 |
-import org.apache.logging.log4j.LogManager;
|
|
| 29 |
-import org.apache.logging.log4j.Logger;
|
|
| 30 |
- |
|
| 31 |
-public abstract class EntityImpl extends EntityAbstract {
|
|
| 32 |
- |
|
| 33 |
- private static final long serialVersionUID = 1L;
|
|
| 34 |
- private static final Logger log = LogManager.getLogger(EntityImpl.class);
|
|
| 35 |
- private JavaBeanDefinition javaBeanDefinition;
|
|
| 36 |
- |
|
| 37 |
- @Override
|
|
| 38 |
- public JavaBeanDefinition javaBeanDefinition() {
|
|
| 39 |
- if (javaBeanDefinition == null) {
|
|
| 40 |
- Class<? extends Entity> contractClass = ObserveEntityEnum.getContractClass(getClass());
|
|
| 41 |
- javaBeanDefinition = JavaBeanDefinitionStore.getDefinition(contractClass).orElseThrow(IllegalStateException::new);
|
|
| 42 |
- log.info(String.format("Loaded javaBean definition for: %s → %s", contractClass.getName(), javaBeanDefinition));
|
|
| 43 |
- }
|
|
| 44 |
- return javaBeanDefinition;
|
|
| 45 |
- }
|
|
| 46 |
-}
|
| ... | ... | @@ -40,6 +40,7 @@ import fr.ird.observe.spi.context.ReferentialDtoEntityContext; |
| 40 | 40 |
import fr.ird.observe.spi.mapping.DtoToEntityContextMapping;
|
| 41 | 41 |
import fr.ird.observe.spi.mapping.EntityToDtoClassMapping;
|
| 42 | 42 |
import fr.ird.observe.toolkit.templates.TemplateContract;
|
| 43 |
+import io.ultreia.java4all.bean.definition.JavaBeanDefinitionStore;
|
|
| 43 | 44 |
import io.ultreia.java4all.bean.spi.GenerateJavaBeanDefinition;
|
| 44 | 45 |
import io.ultreia.java4all.classmapping.ImmutableClassMapping;
|
| 45 | 46 |
import io.ultreia.java4all.lang.Strings;
|
| ... | ... | @@ -369,6 +370,9 @@ public class EntityTransformer extends TopiaEntityTransformer implements Templat |
| 369 | 370 |
}
|
| 370 | 371 |
}
|
| 371 | 372 |
}
|
| 373 |
+ if (!input.isAbstract()) {
|
|
| 374 |
+ generateJavaBeanMethods();
|
|
| 375 |
+ }
|
|
| 372 | 376 |
generateInterfaceUsageConstant(input);
|
| 373 | 377 |
}
|
| 374 | 378 |
|
| ... | ... | @@ -668,6 +672,21 @@ public class EntityTransformer extends TopiaEntityTransformer implements Templat |
| 668 | 672 |
return result.toString();
|
| 669 | 673 |
}
|
| 670 | 674 |
|
| 675 |
+ private void generateJavaBeanMethods() {
|
|
| 676 |
+ |
|
| 677 |
+ // add JavaBeanDefinition constant
|
|
| 678 |
+ String javaBeanDefinition = outputInterface.getName()+"JavaBeanDefinition";
|
|
| 679 |
+ addImport(outputInterface, JavaBeanDefinitionStore.class);
|
|
| 680 |
+ addConstant(outputInterface, "JAVA_BEAN_DEFINITION", javaBeanDefinition, "JavaBeanDefinitionStore.definition("+javaBeanDefinition+".class)",ObjectModelJavaModifier.PUBLIC);
|
|
| 681 |
+ |
|
| 682 |
+ // add JavaBean method
|
|
| 683 |
+ ObjectModelOperation operation = addOperation(outputInterface, "javaBeanDefinition", javaBeanDefinition, ObjectModelJavaModifier.DEFAULT);
|
|
| 684 |
+ setOperationBody(operation, ""/*{
|
|
| 685 |
+ return JAVA_BEAN_DEFINITION;
|
|
| 686 |
+ }*/);
|
|
| 687 |
+ addAnnotation(outputInterface, operation, Override.class);
|
|
| 688 |
+ }
|
|
| 689 |
+ |
|
| 671 | 690 |
private void generateSpiDelegateMethods(boolean referential, String daoName) {
|
| 672 | 691 |
|
| 673 | 692 |
List<Method> methods = Arrays.stream((referential ? ReferentialDtoEntityContext.class : DataDtoEntityContext.class).getMethods()).filter(method -> {
|