use of io.vertigo.dynamo.domain.metamodel.association.AssociationNode in project vertigo by KleeGroup.
the class AnnotationWriter method writeSimpleAssociationAnnotation.
/**
* Ectiture des annotations sur un DT_FIELD gérant une association.
*
* @param associationSimple Definition de l'association
* @return Liste des lignes de code java à ajouter.
*/
List<String> writeSimpleAssociationAnnotation(final AssociationSimpleDefinition associationSimple) {
final AssociationNode primaryNode = associationSimple.getPrimaryAssociationNode();
final AssociationNode foreignNode = associationSimple.getForeignAssociationNode();
final String primaryMultiplicity = AssociationUtil.getMultiplicity(primaryNode.isNotNull(), primaryNode.isMultiple());
final String foreignMultiplipicity = AssociationUtil.getMultiplicity(foreignNode.isNotNull(), foreignNode.isMultiple());
return new ListBuilder<String>().add("@" + Association.class.getCanonicalName() + "(").add(INDENT + "name = \"" + associationSimple.getName() + "\",").add(INDENT + "fkFieldName = \"" + associationSimple.getFKField().getName() + "\",").add(INDENT + "primaryDtDefinitionName = \"" + primaryNode.getDtDefinition().getName() + "\",").add(INDENT + "primaryIsNavigable = " + primaryNode.isNavigable() + ',').add(INDENT + "primaryRole = \"" + primaryNode.getRole() + "\",").add(INDENT + "primaryLabel = \"" + primaryNode.getLabel() + "\",").add(INDENT + "primaryMultiplicity = \"" + primaryMultiplicity + "\",").add(INDENT + "foreignDtDefinitionName = \"" + foreignNode.getDtDefinition().getName() + "\",").add(INDENT + "foreignIsNavigable = " + foreignNode.isNavigable() + ',').add(INDENT + "foreignRole = \"" + foreignNode.getRole() + "\",").add(INDENT + "foreignLabel = \"" + foreignNode.getLabel() + "\",").add(INDENT + "foreignMultiplicity = \"" + foreignMultiplipicity + "\")").build();
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNode in project vertigo by KleeGroup.
the class AnnotationWriter method writeNNAssociationAnnotation.
/**
* Ectiture des annotations sur un DT_FIELD gérant une association.
*
* @param associationNN Definition de l'association
* @return Liste des lignes de code java à ajouter.
*/
List<String> writeNNAssociationAnnotation(final AssociationNNDefinition associationNN) {
final AssociationNode nodeA = associationNN.getAssociationNodeA();
final AssociationNode nodeB = associationNN.getAssociationNodeB();
return new ListBuilder<String>().add("@" + AssociationNN.class.getCanonicalName() + "(").add(INDENT + "name = \"" + associationNN.getName() + "\",").add(INDENT + "tableName = \"" + associationNN.getTableName() + "\",").add(INDENT + "dtDefinitionA = \"" + nodeA.getDtDefinition().getName() + "\",").add(INDENT + "dtDefinitionB = \"" + nodeB.getDtDefinition().getName() + "\",").add(INDENT + "navigabilityA = " + nodeA.isNavigable() + ',').add(INDENT + "navigabilityB = " + nodeB.isNavigable() + ',').add(INDENT + "roleA = \"" + nodeA.getRole() + "\",").add(INDENT + "roleB = \"" + nodeB.getRole() + "\",").add(INDENT + "labelA = \"" + nodeA.getLabel() + "\",").add(INDENT + "labelB = \"" + nodeB.getLabel() + "\")").build();
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNode in project vertigo by KleeGroup.
the class JpaDataStorePlugin method doFindAll.
private <E extends Entity> DtList<E> doFindAll(final ProcessAnalyticsTracer tracer, final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
final Class<E> resultClass = (Class<E>) ClassUtil.classForName(dtDefinition.getClassCanonicalName());
// PK de la DtList recherchée
final String idFieldName = dtDefinition.getIdField().get().getName();
// FK dans la table nn correspondant à la collection recherchée. (clé de jointure ).
final AssociationNNDefinition associationNNDefinition = dtcUri.getAssociationDefinition();
final String joinTableName = associationNNDefinition.getTableName();
final DtDefinition joinDtDefinition = AssociationUtil.getAssociationNode(associationNNDefinition, dtcUri.getRoleName()).getDtDefinition();
final DtField joinDtField = joinDtDefinition.getIdField().get();
// La condition s'applique sur l'autre noeud de la relation (par rapport à la collection attendue)
final AssociationNode associationNode = AssociationUtil.getAssociationNodeTarget(associationNNDefinition, dtcUri.getRoleName());
final DtField fkField = associationNode.getDtDefinition().getIdField().get();
final String fkFieldName = fkField.getName();
final String request = new StringBuilder(" select t.* from ").append(dtDefinition.getLocalName()).append(" t").append(" join ").append(joinTableName).append(" j on j.").append(joinDtField.getName()).append(" = t.").append(idFieldName).append(" where j.").append(fkFieldName).append(" = :").append(fkFieldName).toString();
final URI uri = dtcUri.getSource();
final Query q = getEntityManager().createNativeQuery(request, resultClass);
q.setParameter(fkFieldName, uri.getId());
final List<E> results = q.getResultList();
final DtList<E> dtc = new DtList<>(dtDefinition);
dtc.addAll(results);
tracer.setMeasure("nbSelectedRow", dtc.size());
return dtc;
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNode in project vertigo by KleeGroup.
the class DomainDynamicRegistry method createAssociationSimpleDefinition.
private AssociationSimpleDefinition createAssociationSimpleDefinition(final DefinitionSpace definitionSpace, final DslDefinition xassociation) {
final String multiplicityA = (String) xassociation.getPropertyValue(KspProperty.MULTIPLICITY_A);
final String multiplicityB = (String) xassociation.getPropertyValue(KspProperty.MULTIPLICITY_B);
// Vérification que l'on est bien dans le cas d'une association simple de type 1-n
if (AssociationUtil.isMultiple(multiplicityB) && AssociationUtil.isMultiple(multiplicityA)) {
// Relation n-n
throw new IllegalArgumentException("Utiliser la déclaration AssociationNN");
}
if (!AssociationUtil.isMultiple(multiplicityB) && !AssociationUtil.isMultiple(multiplicityA)) {
// Relation 1-1
throw new IllegalArgumentException("Les associations 1-1 sont interdites");
}
final String fkFieldName = (String) xassociation.getPropertyValue(KspProperty.FK_FIELD_NAME);
final DtDefinition dtDefinitionA = definitionSpace.resolve(xassociation.getDefinitionLinkName("dtDefinitionA"), DtDefinition.class);
final boolean navigabilityA = (Boolean) xassociation.getPropertyValue(KspProperty.NAVIGABILITY_A);
final String roleA = (String) xassociation.getPropertyValue(KspProperty.ROLE_A);
final String labelA = (String) xassociation.getPropertyValue(KspProperty.LABEL_A);
final DtDefinition dtDefinitionB = definitionSpace.resolve(xassociation.getDefinitionLinkName("dtDefinitionB"), DtDefinition.class);
final boolean navigabilityB = (Boolean) xassociation.getPropertyValue(KspProperty.NAVIGABILITY_B);
final String roleB = (String) xassociation.getPropertyValue(KspProperty.ROLE_B);
final String labelB = (String) xassociation.getPropertyValue(KspProperty.LABEL_B);
// Relation 1-n ou 1-1
final String urn = fixAssociationName(ASSOCIATION_SIMPLE_DEFINITION_PREFIX, xassociation.getName());
final AssociationNode associationNodeA = new AssociationNode(dtDefinitionA, navigabilityA, roleA, labelA, AssociationUtil.isMultiple(multiplicityA), AssociationUtil.isNotNull(multiplicityA));
final AssociationNode associationNodeB = new AssociationNode(dtDefinitionB, navigabilityB, roleB, labelB, AssociationUtil.isMultiple(multiplicityB), AssociationUtil.isNotNull(multiplicityB));
final AssociationSimpleDefinition associationSimpleDefinition = new AssociationSimpleDefinition(urn, fkFieldName, associationNodeA, associationNodeB);
final AssociationNode primaryAssociationNode = associationSimpleDefinition.getPrimaryAssociationNode();
final AssociationNode foreignAssociationNode = associationSimpleDefinition.getForeignAssociationNode();
final DtDefinition fkDefinition = primaryAssociationNode.getDtDefinition();
LOGGER.trace("" + xassociation.getName() + " : ajout d'une FK [" + fkFieldName + "] sur la table '" + foreignAssociationNode.getDtDefinition().getName() + "'");
final String label = primaryAssociationNode.getLabel();
dtDefinitionBuilders.get(foreignAssociationNode.getDtDefinition().getName()).addForeignKey(fkFieldName, label, fkDefinition.getIdField().get().getDomain(), primaryAssociationNode.isNotNull(), fkDefinition.getName());
return associationSimpleDefinition;
}
use of io.vertigo.dynamo.domain.metamodel.association.AssociationNode in project vertigo by KleeGroup.
the class SqlDataStorePlugin method findAll.
/**
* {@inheritDoc}
*/
@Override
public <E extends Entity> DtList<E> findAll(final DtDefinition dtDefinition, final DtListURIForNNAssociation dtcUri) {
Assertion.checkNotNull(dtDefinition);
Assertion.checkNotNull(dtcUri);
// -----
final String tableName = getTableName(dtDefinition);
final String taskName = TASK.TK_SELECT + "_N_N_LIST_" + tableName + "_BY_URI";
// PK de la DtList recherchée
final String idFieldName = getIdField(dtDefinition).getName();
// FK dans la table nn correspondant à la collection recherchée. (clé de jointure ).
final AssociationNNDefinition associationNNDefinition = dtcUri.getAssociationDefinition();
final String joinTableName = associationNNDefinition.getTableName();
final DtDefinition joinDtDefinition = AssociationUtil.getAssociationNode(associationNNDefinition, dtcUri.getRoleName()).getDtDefinition();
final DtField joinDtField = getIdField(joinDtDefinition);
// La condition s'applique sur l'autre noeud de la relation (par rapport à la collection attendue)
final AssociationNode associationNode = AssociationUtil.getAssociationNodeTarget(associationNNDefinition, dtcUri.getRoleName());
final DtField fkField = getIdField(associationNode.getDtDefinition());
final String fkFieldName = fkField.getName();
final String request = new StringBuilder(" select t.* from ").append(tableName).append(" t").append(" join ").append(joinTableName).append(" j on j.").append(joinDtField.getName()).append(" = t.").append(idFieldName).append(" where j.").append(fkFieldName).append(" = #").append(fkFieldName).append('#').toString();
final TaskDefinition taskDefinition = TaskDefinition.builder(taskName).withEngine(TaskEngineSelect.class).withDataSpace(dataSpace).withRequest(request).addInRequired(fkFieldName, fkField.getDomain()).withOutRequired("dtc", Home.getApp().getDefinitionSpace().resolve(DOMAIN_PREFIX + SEPARATOR + dtDefinition.getName() + "_DTC", Domain.class)).build();
final URI uri = dtcUri.getSource();
final Task task = Task.builder(taskDefinition).addValue(fkFieldName, uri.getId()).build();
return taskManager.execute(task).getResult();
}
Aggregations