コード例 #1
0
  protected void onDisconnectAllSequences() {
    RuntimeException exception = null;

    // defaultSequence has to disconnect the last
    for (int i = connectedSequences.size() - 1; i >= 0; i--) {
      try {
        Sequence sequenceToDisconnect = (Sequence) connectedSequences.elementAt(i);
        sequenceToDisconnect.onDisconnect(getOwnerSession().getDatasourcePlatform());
      } catch (RuntimeException ex) {
        if (exception == null) {
          exception = ex;
        }
      }
    }
    connectedSequences = null;
    whenShouldAcquireValueForAll = UNDEFINED;
    atLeastOneSequenceShouldUseTransaction = false;
    atLeastOneSequenceShouldUsePreallocation = false;
    if (exception != null) {
      throw exception;
    }
  }
コード例 #2
0
  protected void onConnectAllSequences() {
    connectedSequences = new Vector();
    boolean shouldUseTransaction = false;
    boolean shouldUsePreallocation = false;
    boolean shouldAcquireValueAfterInsert = false;
    Iterator descriptors = getOwnerSession().getDescriptors().values().iterator();
    while (descriptors.hasNext()) {
      ClassDescriptor descriptor = (ClassDescriptor) descriptors.next();
      // Find root sequence, because inheritance needs to be resolved here.
      // TODO: The way we initialize sequencing needs to be in line with descriptor init.
      ClassDescriptor parentDescriptor = descriptor;
      while (!parentDescriptor.usesSequenceNumbers() && parentDescriptor.isChildDescriptor()) {
        ClassDescriptor newDescriptor =
            getOwnerSession()
                .getDescriptor(parentDescriptor.getInheritancePolicy().getParentClass());
        // Avoid issue with error cases of self parent, or null parent.
        if ((newDescriptor == null) || (newDescriptor == parentDescriptor)) {
          break;
        }
        parentDescriptor = newDescriptor;
      }
      if (!parentDescriptor.usesSequenceNumbers()) {
        continue;
      }
      String seqName = parentDescriptor.getSequenceNumberName();
      Sequence sequence = getSequence(seqName);
      if (sequence == null) {
        sequence = new DefaultSequence(seqName);
        getOwnerSession().getDatasourcePlatform().addSequence(sequence);
      }
      // PERF: Initialize the sequence, this avoid having to look it up every time.
      descriptor.setSequence(sequence);
      if (connectedSequences.contains(sequence)) {
        continue;
      }
      try {
        if (sequence instanceof DefaultSequence
            && !connectedSequences.contains(getDefaultSequence())) {
          getDefaultSequence().onConnect(getOwnerSession().getDatasourcePlatform());
          connectedSequences.add(0, getDefaultSequence());
          shouldUseTransaction |= getDefaultSequence().shouldUseTransaction();
          shouldUsePreallocation |= getDefaultSequence().shouldUsePreallocation();
          shouldAcquireValueAfterInsert |= getDefaultSequence().shouldAcquireValueAfterInsert();
        }
        sequence.onConnect(getOwnerSession().getDatasourcePlatform());
        connectedSequences.addElement(sequence);
        shouldUseTransaction |= sequence.shouldUseTransaction();
        shouldUsePreallocation |= sequence.shouldUsePreallocation();
        shouldAcquireValueAfterInsert |= sequence.shouldAcquireValueAfterInsert();
      } catch (RuntimeException ex) {
        // defaultSequence has to disconnect the last
        for (int i = connectedSequences.size() - 1; i >= 0; i--) {
          try {
            Sequence sequenceToDisconnect = (Sequence) connectedSequences.elementAt(i);
            sequenceToDisconnect.onDisconnect(getOwnerSession().getDatasourcePlatform());
          } catch (RuntimeException ex2) {
            // ignore
          }
        }
        connectedSequences = null;
        throw ex;
      }
    }

    if (shouldAcquireValueAfterInsert && !shouldUsePreallocation) {
      whenShouldAcquireValueForAll = AFTER_INSERT;
    } else if (!shouldAcquireValueAfterInsert && shouldUsePreallocation) {
      whenShouldAcquireValueForAll = BEFORE_INSERT;
    }
    atLeastOneSequenceShouldUseTransaction = shouldUseTransaction;
    atLeastOneSequenceShouldUsePreallocation = shouldUsePreallocation;
  }