示例#1
0
    /*
     * Performs join of the tables corresponding to the association and to the target type
     * Returns the local name of the target type of the association
     */
    private String leftJoin(String associationName_) {
      AssociationDefinition associationDefinition =
          dictionaryService.getAssociation(QName.createQName(namespaceURI, associationName_));
      if (associationDefinition == null) {
        throw new InvalidAssociationException(associationName_);
      }

      QName sourceClassQName = associationDefinition.getSourceClass().getName();
      QName targetClassQName = associationDefinition.getTargetClass().getName();

      String sourceTableName =
          databaseDictionary.resolveClassAsTableName(sourceClassQName.getLocalName());
      String targetTableName =
          databaseDictionary.resolveClassAsTableName(targetClassQName.getLocalName());
      String associationTableName =
          databaseDictionary.resolveAssociationAsTableName(associationName_);

      // Check whether the association table was already taken into account
      if (!joinedTables.containsKey(associationTableName)) {
        // Check whether the join has been previously made on source or target tables
        if (!typeName.equals(sourceClassQName.getLocalName())
            && !joinedTables.containsKey(sourceTableName)) {
          // There is a problem, an association can be added only if the source type was previously
          // joined (as a table)
          throw new AlfrescoRuntimeException(
              "Cannot join the association \""
                  + associationName_
                  + "\" since source type \""
                  + sourceClassQName.getLocalName()
                  + "\" has not yet been joined.");
        } else {
          if (logger.isDebugEnabled())
            logger.debug(
                "Join condition is made explicitely on column with name \""
                    + TYPE_TABLE_ID_COLUMN_NAME
                    + "\"");

          // the source type name is the "master" type name or has already been defined previously
          // as a left join
          join(
              associationTableName,
              databaseDictionary.getSourceAlias(associationName_),
              sourceTableName,
              TYPE_TABLE_ID_COLUMN_NAME,
              JoinType.LEFT_JOIN);
          join(
              targetTableName,
              TYPE_TABLE_ID_COLUMN_NAME,
              associationTableName,
              databaseDictionary.getTargetAlias(associationName_),
              JoinType.LEFT_JOIN);
        }
      }

      return targetClassQName.getLocalName();
    }
  public boolean generateArcsInstances(IStructure structure) throws Exception {
    List<IArc> arcsInstances = new ArrayList<IArc>();

    Collection<AssociationDefinition> associations =
        ((AlfrescoModelStructure) structure).getAssociations();

    for (AssociationDefinition associationDefinition : associations) {

      List<IArc> arcsInstancesByAssociation = new ArrayList<IArc>();

      ClassDefinition sourceType = associationDefinition.getSourceClass();
      Collection<INode> sourcesNodes = generatorServices.getGeneratedNodesByType(sourceType);

      boolean sourceMultiplicity = associationDefinition.isSourceMany();

      ClassDefinition targetType = associationDefinition.getTargetClass();
      Collection<INode> targetsNodes = generatorServices.getGeneratedNodesByType(targetType);

      boolean targetMultiplicity = associationDefinition.isTargetMany();

      if (!sourcesNodes.isEmpty() && !targetsNodes.isEmpty()) {
        if (!sourceMultiplicity && !targetMultiplicity) {
          arcsInstancesByAssociation =
              generateArcsInstancesCase11(
                  sourcesNodes, targetsNodes, associationDefinition, associations, arcsInstances);
        } else if (!sourceMultiplicity && targetMultiplicity) {
          arcsInstancesByAssociation =
              generateArcsInstancesCase1N(
                  sourcesNodes, targetsNodes, associationDefinition, associations, arcsInstances);
        } else if (sourceMultiplicity && !targetMultiplicity) {
          arcsInstancesByAssociation =
              generateArcsInstancesCaseN1(
                  sourcesNodes, targetsNodes, associationDefinition, associations, arcsInstances);
        } else if (sourceMultiplicity && targetMultiplicity) {
          arcsInstancesByAssociation =
              generateArcsInstancesCaseNN(sourcesNodes, targetsNodes, associationDefinition);
        }
        arcsInstances.addAll(arcsInstancesByAssociation);
      }
    }
    ((AlfrescoModelData) alfrescoModelDatas).setGeneratedAssociationsInstances(arcsInstances);
    return true;
  }