Examples of NdbTransaction


Examples of com.mysql.cluster.ndbj.NdbTransaction

      new ArrayList<AttributeType>();

    boolean extensibleObject = false;

    // Update ocs tables.
    NdbTransaction ndbDATxn = null;
    for (Map.Entry<ObjectClass, String> ocEntry : ocMap.entrySet()) {
      ObjectClass oc = ocEntry.getKey();
      String ocName = oc.getNameOrOID();

      Map<Integer, NdbOperation> mvOpMap =
        new HashMap<Integer, NdbOperation>();

      if (nClasses > 0) {
        ocBuffer.append(" ");
      }
      ocBuffer.append(ocName);
      nClasses++;

      if (oc.getObjectClassType() == ObjectClassType.ABSTRACT) {
        continue;
      }

      if (ocName.equalsIgnoreCase(OC_EXTENSIBLEOBJECT)) {
        extensibleObject = true;
      }

      if (ndbDATxn == null) {
        ndbDATxn = txn.getNdbDATransaction(ocName, id);
      }
      if (overwrite) {
        op = ndbDATxn.getWriteOperation(ocName);
      } else {
        op = ndbDATxn.getInsertOperation(ocName);
      }
      op.equalLong(BackendImpl.EID, id);
      op.equalInt(BackendImpl.MID, MIN_MID);
      mvOpMap.put(MIN_MID, op);

      for (AttributeType reqAttr : oc.getRequiredAttributes()) {
        if (userAttributes.contains(reqAttr)) {
          continue;
        }
        if (reqAttr.isOperational()) {
          userAttrMap.put(reqAttr, entry.getOperationalAttribute(reqAttr));
        }
        String attrName = reqAttr.getNameOrOID();
        if (entry.hasAttribute(reqAttr)) {
          boolean indexed = BackendImpl.indexes.contains(attrName);
          List<Attribute> attrList = userAttrMap.get(reqAttr);
          int mid = MIN_MID;
          for (Attribute attr : attrList) {
            if (attr.isVirtual() || attr.isEmpty()) {
              continue;
            }
            // Attribute options.
            Set<String> attrOptionsSet = attr.getOptions();
            if (!attrOptionsSet.isEmpty()) {
              if (overwrite) {
                tagOp =
                  ndbDATxn.getWriteOperation(BackendImpl.TAGS_TABLE);
              } else {
                tagOp =
                  ndbDATxn.getInsertOperation(BackendImpl.TAGS_TABLE);
              }
              tagOp.equalLong(BackendImpl.EID, id);
              tagOp.equalString(BackendImpl.TAG_ATTR, attrName);
              tagOp.equalInt(BackendImpl.MID, mid);
              StringBuilder buffer = new StringBuilder();
              for (String option : attrOptionsSet) {
                buffer.append(';');
                buffer.append(option);
              }
              tagOp.setString(BackendImpl.TAG_TAGS, buffer.toString());
            }
            for (AttributeValue attrVal : attr) {
              String attrStringVal = attrVal.toString();
              NdbOperation attrOp = mvOpMap.get(mid);
              if (attrOp == null) {
                if (overwrite) {
                  attrOp = ndbDATxn.getWriteOperation(ocName);
                } else {
                  attrOp = ndbDATxn.getInsertOperation(ocName);
                }
                attrOp.equalLong(BackendImpl.EID, id);
                attrOp.equalInt(BackendImpl.MID, mid);
                mvOpMap.put(mid, attrOp);
              }
              if (BackendImpl.blobAttributes.contains(attrName)) {
                NdbBlob blob = attrOp.getBlobHandle(attrName);
                blob.setValue(new byte[0]);
                byte[] blobBytes = attrVal.getValue().toByteArray();
                blobMap.put(blob, blobBytes);
              } else {
                attrOp.setString(attrName, attrStringVal);
              }
              // Update Indexes.
              if (indexed) {
                NdbOperation idxOp = null;
                if (overwrite) {
                  idxOp = ndbDATxn.getWriteOperation(
                    BackendImpl.IDX_TABLE_PREFIX + attrName);
                } else {
                  idxOp = ndbDATxn.getInsertOperation(
                    BackendImpl.IDX_TABLE_PREFIX + attrName);
                }
                idxOp.equalLong(BackendImpl.EID, id);
                idxOp.equalInt(BackendImpl.MID, mid);
                idxOp.setString(BackendImpl.IDX_VAL, attrStringVal);
              }
              mid++;
            }
          }
          userAttributes.add(reqAttr);
        }
      }

      for (AttributeType optAttr : oc.getOptionalAttributes()) {
        if (userAttributes.contains(optAttr)) {
          continue;
        }
        if (optAttr.isOperational()) {
          userAttrMap.put(optAttr, entry.getOperationalAttribute(optAttr));
        }
        String attrName = optAttr.getNameOrOID();
        if (entry.hasAttribute(optAttr)) {
          boolean indexed = BackendImpl.indexes.contains(attrName);
          List<Attribute> attrList = userAttrMap.get(optAttr);
          int mid = MIN_MID;
          for (Attribute attr : attrList) {
            if (attr.isVirtual() || attr.isEmpty()) {
              continue;
            }
            // Attribute options.
            Set<String> attrOptionsSet = attr.getOptions();
            if (!attrOptionsSet.isEmpty()) {
              if (overwrite) {
                tagOp =
                  ndbDATxn.getWriteOperation(BackendImpl.TAGS_TABLE);
              } else {
                tagOp =
                  ndbDATxn.getInsertOperation(BackendImpl.TAGS_TABLE);
              }
              tagOp.equalLong(BackendImpl.EID, id);
              tagOp.equalString(BackendImpl.TAG_ATTR, attrName);
              tagOp.equalInt(BackendImpl.MID, mid);
              StringBuilder buffer = new StringBuilder();
              for (String option : attrOptionsSet) {
                buffer.append(';');
                buffer.append(option);
              }
              tagOp.setString(BackendImpl.TAG_TAGS, buffer.toString());
            }
            for (AttributeValue attrVal : attr) {
              String attrStringVal = attrVal.toString();
              NdbOperation attrOp = mvOpMap.get(mid);
              if (attrOp == null) {
                if (overwrite) {
                  attrOp = ndbDATxn.getWriteOperation(ocName);
                } else {
                  attrOp = ndbDATxn.getInsertOperation(ocName);
                }
                attrOp.equalLong(BackendImpl.EID, id);
                attrOp.equalInt(BackendImpl.MID, mid);
                mvOpMap.put(mid, attrOp);
              }
              if (BackendImpl.blobAttributes.contains(attrName)) {
                NdbBlob blob = attrOp.getBlobHandle(attrName);
                blob.setValue(new byte[0]);
                byte[] blobBytes = attrVal.getValue().toByteArray();
                blobMap.put(blob, blobBytes);
              } else {
                attrOp.setString(attrName, attrStringVal);
              }
              // Update Indexes.
              if (indexed) {
                NdbOperation idxOp = null;
                if (overwrite) {
                  idxOp = ndbDATxn.getWriteOperation(
                    BackendImpl.IDX_TABLE_PREFIX + attrName);
                } else {
                  idxOp = ndbDATxn.getInsertOperation(
                    BackendImpl.IDX_TABLE_PREFIX + attrName);
                }
                idxOp.equalLong(BackendImpl.EID, id);
                idxOp.equalInt(BackendImpl.MID, mid);
                idxOp.setString(BackendImpl.IDX_VAL, attrStringVal);
              }
              mid++;
            }
          }
          userAttributes.add(optAttr);
        }
      }
    }

    // Extensible object.
    if (extensibleObject) {
      int xnClasses = 0;
      for (Map.Entry<AttributeType, List<Attribute>> attrEntry :
           userAttrMap.entrySet())
      {
        AttributeType attrType = attrEntry.getKey();
        if (!userAttributes.contains(attrType)) {
          String attrName = attrType.getNameOrOID();
          String ocName = BackendImpl.attr2Oc.get(attrName);
          Map<Integer, NdbOperation> mvOpMap =
            new HashMap<Integer, NdbOperation>();
          boolean indexed = BackendImpl.indexes.contains(attrName);

          if (ndbDATxn == null) {
            ndbDATxn = txn.getNdbDATransaction(ocName, id);
          }
          if (overwrite) {
            op = ndbDATxn.getWriteOperation(ocName);
          } else {
            op = ndbDATxn.getInsertOperation(ocName);
          }
          op.equalLong(BackendImpl.EID, id);
          op.equalInt(BackendImpl.MID, MIN_MID);
          mvOpMap.put(MIN_MID, op);

          List<Attribute> attrList = userAttrMap.get(attrType);
          int mid = MIN_MID;
          for (Attribute attr : attrList) {
            if (attr.isVirtual() || attr.isEmpty()) {
              continue;
            }
            // Attribute options.
            Set<String> attrOptionsSet = attr.getOptions();
            if (!attrOptionsSet.isEmpty()) {
              if (overwrite) {
                tagOp =
                  ndbDATxn.getWriteOperation(BackendImpl.TAGS_TABLE);
              } else {
                tagOp =
                  ndbDATxn.getInsertOperation(BackendImpl.TAGS_TABLE);
              }
              tagOp.equalLong(BackendImpl.EID, id);
              tagOp.equalString(BackendImpl.TAG_ATTR, attrName);
              tagOp.equalInt(BackendImpl.MID, mid);
              StringBuilder buffer = new StringBuilder();
              for (String option : attrOptionsSet) {
                buffer.append(';');
                buffer.append(option);
              }
              tagOp.setString(BackendImpl.TAG_TAGS, buffer.toString());
            }
            for (AttributeValue attrVal : attr) {
              String attrStringVal = attrVal.toString();
              NdbOperation attrOp = mvOpMap.get(mid);
              if (attrOp == null) {
                if (overwrite) {
                  attrOp = ndbDATxn.getWriteOperation(ocName);
                } else {
                  attrOp = ndbDATxn.getInsertOperation(ocName);
                }
                attrOp.equalLong(BackendImpl.EID, id);
                attrOp.equalInt(BackendImpl.MID, mid);
                mvOpMap.put(mid, attrOp);
              }
              if (BackendImpl.blobAttributes.contains(attrName)) {
                NdbBlob blob = attrOp.getBlobHandle(attrName);
                blob.setValue(new byte[0]);
                byte[] blobBytes = attrVal.getValue().toByteArray();
                blobMap.put(blob, blobBytes);
              } else {
                attrOp.setString(attrName, attrStringVal);
              }
              // Update Indexes.
              if (indexed) {
                NdbOperation idxOp = null;
                if (overwrite) {
                  idxOp = ndbDATxn.getWriteOperation(
                    BackendImpl.IDX_TABLE_PREFIX + attrName);
                } else {
                  idxOp = ndbDATxn.getInsertOperation(
                    BackendImpl.IDX_TABLE_PREFIX + attrName);
                }
                idxOp.equalLong(BackendImpl.EID, id);
                idxOp.equalInt(BackendImpl.MID, mid);
                idxOp.setString(BackendImpl.IDX_VAL, attrStringVal);
              }
              mid++;
            }
          }
          userAttributes.add(attrType);

          if (xnClasses > 0) {
            xocBuffer.append(" ");
          }
          xocBuffer.append(ocName);
          xnClasses++;
        }
      }
    }

    // Update operational attributes table.
    if (overwrite) {
      op = ndbDATxn.getWriteOperation(BackendImpl.OPATTRS_TABLE);
    } else {
      op = ndbDATxn.getInsertOperation(BackendImpl.OPATTRS_TABLE);
    }
    op.equalLong(BackendImpl.EID, id);
    for (List<Attribute> attrList :
         entry.getOperationalAttributes().values())
    {
      for (Attribute attr : attrList) {
        if (attr.isVirtual() || attr.isEmpty()) {
          continue;
        }
        if (userAttrMap.containsKey(attr.getAttributeType())) {
          continue;
        }
        String attrName = attr.getAttributeType().getNameOrOID();
        for (AttributeValue attrVal : attr) {
          op.setString(attrName, attrVal.toString());
        }
      }
    }

    // Move this txn into the active state and write blob data if any.
    if (!blobMap.isEmpty()) {
      ndbDATxn.execute(ExecType.NoCommit, AbortOption.AbortOnError, true);
      Set<Map.Entry<NdbBlob, byte[]>> blobEntrySet = blobMap.entrySet();
      for (Map.Entry blobEntry : blobEntrySet) {
        NdbBlob blob = (NdbBlob) blobEntry.getKey();
        byte[] blobBytes = (byte[]) blobEntry.getValue();
        blob.writeData(blobBytes);
      }
    }

    // Update dn2id table.
    NdbTransaction ndbTxn = txn.getNdbTransaction();
    if (overwrite) {
      op = ndbTxn.getWriteOperation(name);
    } else {
      op = ndbTxn.getInsertOperation(name);
    }

    int componentIndex = dn.getNumComponents() - 1;
    for (int i=0; i < BackendImpl.DN2ID_DN_NC; i++) {
      while (componentIndex >= 0) {
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

  private void deleteNDBEntry(AbstractTransaction txn,
    Entry originalEntry, long id) throws NdbApiException
  {
    NdbOperation op = null;
    NdbOperation tagOp = null;
    NdbTransaction ndbDATxn = null;
    boolean extensibleObject = false;

    // Delete attributes.
    Map<ObjectClass, String> originalOcMap =
      originalEntry.getObjectClasses();
    ArrayList<AttributeType> originalUserAttributes =
      new ArrayList<AttributeType>();
    Map<AttributeType, List<Attribute>> originalUserAttrMap =
      originalEntry.getUserAttributes();

    for (Map.Entry<ObjectClass, String> ocEntry : originalOcMap.entrySet()) {
      ObjectClass oc = ocEntry.getKey();
      String ocName = oc.getNameOrOID();
      Map<Integer, NdbOperation> mvOpMap =
        new HashMap<Integer, NdbOperation>();

      if (oc.getObjectClassType() == ObjectClassType.ABSTRACT) {
        continue;
      }

      if (ocName.equalsIgnoreCase(OC_EXTENSIBLEOBJECT)) {
        extensibleObject = true;
      }

      if (ndbDATxn == null) {
        ndbDATxn = txn.getNdbDATransaction(ocName, id);
      }
      op = ndbDATxn.getDeleteOperation(ocName);
      op.equalLong(BackendImpl.EID, id);
      op.equalInt(BackendImpl.MID, MIN_MID);
      mvOpMap.put(MIN_MID, op);

      for (AttributeType reqAttr : oc.getRequiredAttributes()) {
        String attrName = reqAttr.getNameOrOID();
        if (originalUserAttributes.contains(reqAttr)) {
          continue;
        }
        if (originalEntry.hasUserAttribute(reqAttr)) {
          boolean indexed = BackendImpl.indexes.contains(attrName);
          List<Attribute> attrList = originalUserAttrMap.get(reqAttr);
          int mid = MIN_MID;
          for (Attribute attr : attrList) {
            if (attr.isVirtual() || attr.isEmpty()) {
              continue;
            }
            // Attribute options.
            Set<String> attrOptionsSet = attr.getOptions();
            if (!attrOptionsSet.isEmpty()) {
              tagOp =
                ndbDATxn.getDeleteOperation(BackendImpl.TAGS_TABLE);
              tagOp.equalLong(BackendImpl.EID, id);
              tagOp.equalString(BackendImpl.TAG_ATTR, attrName);
              tagOp.equalInt(BackendImpl.MID, mid);
            }
            for (AttributeValue attrVal : attr) {
              NdbOperation attrOp = mvOpMap.get(mid);
              if (attrOp == null) {
                attrOp = ndbDATxn.getDeleteOperation(ocName);
                attrOp.equalLong(BackendImpl.EID, id);
                attrOp.equalInt(BackendImpl.MID, mid);
                mvOpMap.put(mid, attrOp);
              }
              // Update Indexes.
              if (indexed) {
                NdbOperation idxOp = ndbDATxn.getDeleteOperation(
                  BackendImpl.IDX_TABLE_PREFIX + attrName);
                idxOp.equalLong(BackendImpl.EID, id);
                idxOp.equalInt(BackendImpl.MID, mid);
              }
              mid++;
            }
          }
          originalUserAttributes.add(reqAttr);
        }
      }

      for (AttributeType optAttr : oc.getOptionalAttributes()) {
        String attrName = optAttr.getNameOrOID();
        if (originalUserAttributes.contains(optAttr)) {
          continue;
        }
        if (originalEntry.hasUserAttribute(optAttr)) {
          boolean indexed = BackendImpl.indexes.contains(attrName);
          List<Attribute> attrList = originalUserAttrMap.get(optAttr);
          int mid = MIN_MID;
          for (Attribute attr : attrList) {
            if (attr.isVirtual() || attr.isEmpty()) {
              continue;
            }
            // Attribute options.
            Set<String> attrOptionsSet = attr.getOptions();
            if (!attrOptionsSet.isEmpty()) {
              tagOp =
                ndbDATxn.getDeleteOperation(BackendImpl.TAGS_TABLE);
              tagOp.equalLong(BackendImpl.EID, id);
              tagOp.equalString(BackendImpl.TAG_ATTR, attrName);
              tagOp.equalInt(BackendImpl.MID, mid);
            }
            for (AttributeValue attrVal : attr) {
              NdbOperation attrOp = mvOpMap.get(mid);
              if (attrOp == null) {
                attrOp = ndbDATxn.getDeleteOperation(ocName);
                attrOp.equalLong(BackendImpl.EID, id);
                attrOp.equalInt(BackendImpl.MID, mid);
                mvOpMap.put(mid, attrOp);
              }
              // Update Indexes.
              if (indexed) {
                NdbOperation idxOp = ndbDATxn.getDeleteOperation(
                  BackendImpl.IDX_TABLE_PREFIX + attrName);
                idxOp.equalLong(BackendImpl.EID, id);
                idxOp.equalInt(BackendImpl.MID, mid);
              }
              mid++;
            }
          }
          originalUserAttributes.add(optAttr);
        }
      }
    }

    // Extensible object.
    if (extensibleObject) {
      for (Map.Entry<AttributeType, List<Attribute>> attrEntry :
           originalUserAttrMap.entrySet())
      {
        AttributeType attrType = attrEntry.getKey();
        if (!originalUserAttributes.contains(attrType)) {
          String attrName = attrType.getNameOrOID();
          String ocName = BackendImpl.attr2Oc.get(attrName);
          Map<Integer, NdbOperation> mvOpMap =
            new HashMap<Integer, NdbOperation>();
          boolean indexed = BackendImpl.indexes.contains(attrName);

          if (ndbDATxn == null) {
            ndbDATxn = txn.getNdbDATransaction(ocName, id);
          }
          op = ndbDATxn.getDeleteOperation(ocName);
          op.equalLong(BackendImpl.EID, id);
          op.equalInt(BackendImpl.MID, MIN_MID);
          mvOpMap.put(MIN_MID, op);

          List<Attribute> attrList = originalUserAttrMap.get(attrType);
          int mid = MIN_MID;
          for (Attribute attr : attrList) {
            if (attr.isVirtual() || attr.isEmpty()) {
              continue;
            }
            // Attribute options.
            Set<String> attrOptionsSet = attr.getOptions();
            if (!attrOptionsSet.isEmpty()) {
              tagOp =
                ndbDATxn.getDeleteOperation(BackendImpl.TAGS_TABLE);
              tagOp.equalLong(BackendImpl.EID, id);
              tagOp.equalString(BackendImpl.TAG_ATTR, attrName);
              tagOp.equalInt(BackendImpl.MID, mid);
            }
            for (AttributeValue attrVal : attr) {
              NdbOperation attrOp = mvOpMap.get(mid);
              if (attrOp == null) {
                attrOp = ndbDATxn.getDeleteOperation(ocName);
                attrOp.equalLong(BackendImpl.EID, id);
                attrOp.equalInt(BackendImpl.MID, mid);
                mvOpMap.put(mid, attrOp);
              }
              // Update Indexes.
              if (indexed) {
                NdbOperation idxOp = ndbDATxn.getDeleteOperation(
                  BackendImpl.IDX_TABLE_PREFIX + attrName);
                idxOp.equalLong(BackendImpl.EID, id);
                idxOp.equalInt(BackendImpl.MID, mid);
              }
              mid++;
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

  {
    DN dn = entry.getDN();

    NdbResultSet rs = null;

    NdbTransaction ndbTxn = txn.getNdbTransaction();

    NdbOperation op = ndbTxn.getSelectOperation(name,
      NdbOperation.LockMode.LM_CommittedRead);

    boolean extensibleObject = false;

    int componentIndex = dn.getNumComponents() - 1;
    for (int i=0; i < BackendImpl.DN2ID_DN_NC; i++) {
      while (componentIndex >= 0) {
        op.equalString(BackendImpl.DN2ID_DN + Integer.toString(i),
          dn.getRDN(componentIndex).toNormalizedString());
        componentIndex--;
        i++;
      }
      op.equalString(BackendImpl.DN2ID_DN +
        Integer.toString(i), "");
    }
    op.getValue(BackendImpl.EID);
    op.getValue(BackendImpl.DN2ID_OC);
    op.getValue(BackendImpl.DN2ID_XOC);

    rs = op.resultData();
    ndbTxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    long eid = 0;
    NdbTransaction ndbDATxn = null;
    String[] ocsStringArray = null;
    String[] xocsStringArray = null;
    List<NdbResultSet> ocRsList = new ArrayList<NdbResultSet>();
    NdbIndexScanOperation indexScanOp = null;

    if (rs.next()) {
      eid = rs.getLong(BackendImpl.EID);
      String ocsString = rs.getString(BackendImpl.DN2ID_OC);
      ocsStringArray = ocsString.split(" ");

      String xocsString = rs.getString(BackendImpl.DN2ID_XOC);
      xocsStringArray = xocsString.split(" ");
      if (xocsString.length() > 0) {
        extensibleObject = true;
      }

      for (String ocName : ocsStringArray) {
        ObjectClass oc =
          DirectoryServer.getObjectClass(ocName, true);
        if (oc.getObjectClassType() == ObjectClassType.ABSTRACT) {
          continue;
        }
        if (ndbDATxn == null) {
          ndbDATxn = txn.getNdbDATransaction(ocName, eid);
        }
        indexScanOp =
          ndbDATxn.getSelectIndexScanOperation(PRIMARY_INDEX_NAME, ocName);
        indexScanOp.setBoundLong(BackendImpl.EID,
            NdbIndexScanOperation.BoundType.BoundEQ, eid);
        indexScanOp.getValue(BackendImpl.MID);
        ocRsList.add(indexScanOp.resultData());
      }

      // Extensible object.
      if (extensibleObject) {
        for (String xocName : xocsStringArray) {
          ObjectClass xoc =
            DirectoryServer.getObjectClass(xocName, true);
          if (xoc.getObjectClassType() == ObjectClassType.ABSTRACT) {
            continue;
          }
          if (ndbDATxn == null) {
            ndbDATxn = txn.getNdbDATransaction(xocName, eid);
          }
          indexScanOp =
            ndbDATxn.getSelectIndexScanOperation(PRIMARY_INDEX_NAME, xocName);
          indexScanOp.setBoundLong(BackendImpl.EID,
            NdbIndexScanOperation.BoundType.BoundEQ, eid);
          indexScanOp.getValue(BackendImpl.MID);
          ocRsList.add(indexScanOp.resultData());
        }
      }
    }

    // Attribute options.
    if (ndbDATxn == null) {
      ndbDATxn = txn.getNdbDATransaction(BackendImpl.TAGS_TABLE, eid);
    }
    indexScanOp = ndbDATxn.getSelectIndexScanOperation(PRIMARY_INDEX_NAME,
      BackendImpl.TAGS_TABLE);
    indexScanOp.setBoundLong(BackendImpl.EID,
      NdbIndexScanOperation.BoundType.BoundEQ, eid);
    indexScanOp.getValue(BackendImpl.TAG_ATTR);
    indexScanOp.getValue(BackendImpl.MID);
    NdbResultSet tagRs = indexScanOp.resultData();

    ndbDATxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    Iterator<NdbResultSet> rsIterator = ocRsList.iterator();
    for (String ocName : ocsStringArray) {
      ObjectClass oc =
        DirectoryServer.getObjectClass(ocName, true);
      if (oc.getObjectClassType() == ObjectClassType.ABSTRACT) {
        continue;
      }
      NdbResultSet ocRs = rsIterator.next();
      while (ocRs.next()) {
        int mid = ocRs.getInt(BackendImpl.MID);
        op = ndbDATxn.getDeleteOperation(ocName);
        op.equalLong(BackendImpl.EID, eid);
        op.equalInt(BackendImpl.MID, mid);
      }
    }

    // Extensible object.
    if (extensibleObject) {
      for (String xocName : xocsStringArray) {
        ObjectClass xoc =
          DirectoryServer.getObjectClass(xocName, true);
        if (xoc.getObjectClassType() == ObjectClassType.ABSTRACT) {
          continue;
        }
        NdbResultSet ocRs = rsIterator.next();
        while (ocRs.next()) {
          int mid = ocRs.getInt(BackendImpl.MID);
          op = ndbDATxn.getDeleteOperation(xocName);
          op.equalLong(BackendImpl.EID, eid);
          op.equalInt(BackendImpl.MID, mid);
        }
      }
    }

    // Operational attributes.
    op = ndbDATxn.getDeleteOperation(BackendImpl.OPATTRS_TABLE);
    op.equalLong(BackendImpl.EID, eid);

    // Attribute options.
    while (tagRs.next()) {
      String attrName = tagRs.getString(BackendImpl.TAG_ATTR);
      int mid = tagRs.getInt(BackendImpl.MID);
      op = ndbDATxn.getDeleteOperation(BackendImpl.TAGS_TABLE);
      op.equalLong(BackendImpl.EID, eid);
      op.equalString(BackendImpl.TAG_ATTR, attrName);
      op.equalInt(BackendImpl.MID, mid);
    }

    // Indexes.
    for (String attrName : BackendImpl.indexes) {
      AttributeType attributeType =
              DirectoryServer.getAttributeType(
              attrName.toLowerCase(), true);
      if (entry.hasAttribute(attributeType)) {
        List<Attribute> attrList =
          entry.getAttribute(attributeType);
        int mid = MIN_MID;
        for (Attribute attr : attrList) {
          for (AttributeValue attrVal : attr) {
            NdbOperation idxOp = ndbDATxn.getDeleteOperation(
              BackendImpl.IDX_TABLE_PREFIX + attrName);
            idxOp.equalLong(BackendImpl.EID, eid);
            idxOp.equalInt(BackendImpl.MID, mid);
            mid++;
          }
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

  {
    NdbIndexScanOperation indexScanOp = null;
    NdbResultSet rs = null;
    DN dn = null;

    NdbTransaction ndbTxn = txn.getNdbTransaction();

    indexScanOp = ndbTxn.getSelectIndexScanOperation(
      BackendImpl.EID, name, lockMode);
    indexScanOp.setBoundLong(BackendImpl.EID,
            NdbIndexScanOperation.BoundType.BoundEQ, eid);
    for (int i = 0; i < BackendImpl.DN2ID_DN_NC; i++) {
      indexScanOp.getValue(BackendImpl.DN2ID_DN +
        Integer.toString(i));
    }
    indexScanOp.getValue(BackendImpl.DN2ID_OC);
    indexScanOp.getValue(BackendImpl.DN2ID_XOC);

    rs = indexScanOp.resultData();
    ndbTxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    if (rs.next()) {
      StringBuilder dnBuffer = new StringBuilder();
      int dnColumnIndex = BackendImpl.DN2ID_DN_NC - 1;
      while (dnColumnIndex >= 0) {
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

    NdbOperation.LockMode lockMode) throws NdbApiException
  {
    NdbOperation op = null;
    NdbResultSet rs = null;

    NdbTransaction ndbTxn = txn.getNdbTransaction();

    op = ndbTxn.getSelectOperation(name, lockMode);

    int componentIndex = dn.getNumComponents() - 1;
    for (int i=0; i < BackendImpl.DN2ID_DN_NC; i++) {
      while (componentIndex >= 0) {
        op.equalString(BackendImpl.DN2ID_DN + Integer.toString(i),
          dn.getRDN(componentIndex).toNormalizedString());
        componentIndex--;
        i++;
      }
      op.equalString(BackendImpl.DN2ID_DN +
        Integer.toString(i), "");
    }
    op.getValue(BackendImpl.EID);
    op.getValue(BackendImpl.DN2ID_OC);
    op.getValue(BackendImpl.DN2ID_XOC);

    rs = op.resultData();
    ndbTxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    if (rs.next()) {
      long eid = rs.getLong(BackendImpl.EID);
      if (eid == 0) {
        return null;
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

    Map<String, Map<String, NdbBlob>> blobMap =
      new HashMap<String, Map<String, NdbBlob>>();
    LinkedHashMap<ObjectClass, String> objectClasses =
      new LinkedHashMap<ObjectClass, String>(ocsStringArray.length);

    NdbTransaction ndbDATxn = null;
    NdbIndexScanOperation tagScanOp = null;

    for (String ocName : ocsStringArray) {
      ObjectClass oc =
        DirectoryServer.getObjectClass(ocName, true);
      objectClasses.put(oc, ocName);
      if (oc.getObjectClassType() == ObjectClassType.ABSTRACT) {
        continue;
      }

      if (ndbDATxn == null) {
        ndbDATxn = txn.getNdbDATransaction(ocName, eid);
      }

      indexScanOp =
        ndbDATxn.getSelectIndexScanOperation(
        PRIMARY_INDEX_NAME, ocName,
        NdbOperation.LockMode.LM_CommittedRead);
      indexScanOp.setBoundLong(BackendImpl.EID,
        NdbIndexScanOperation.BoundType.BoundEQ, eid);
      indexScanOp.getValue(BackendImpl.MID);

      for (AttributeType reqAttr : oc.getRequiredAttributes()) {
        String attrName = reqAttr.getNameOrOID();
        if (BackendImpl.blobAttributes.contains(attrName)) {
          NdbBlob blob = indexScanOp.getBlobHandle(attrName);
          Map<String, NdbBlob> attr2Blob = blobMap.get(ocName);
          if (attr2Blob == null) {
            attr2Blob = new HashMap<String, NdbBlob>();
          }
          attr2Blob.put(attrName, blob);
          blobMap.put(ocName, attr2Blob);
        } else {
          indexScanOp.getValue(attrName);
        }
      }
      for (AttributeType optAttr : oc.getOptionalAttributes()) {
        String attrName = optAttr.getNameOrOID();
        if (BackendImpl.blobAttributes.contains(attrName)) {
          NdbBlob blob = indexScanOp.getBlobHandle(attrName);
          Map<String, NdbBlob> attr2Blob = blobMap.get(ocName);
          if (attr2Blob == null) {
            attr2Blob = new HashMap<String, NdbBlob>();
          }
          attr2Blob.put(attrName, blob);
          blobMap.put(ocName, attr2Blob);
        } else {
          indexScanOp.getValue(attrName);
        }
      }
      ocRsList.add(indexScanOp.resultData());
    }

    // Extensible object.
    if (extensibleObject) {
      for (String xocName : xocsStringArray) {
        ObjectClass xoc =
          DirectoryServer.getObjectClass(xocName, true);
        objectClasses.put(xoc, xocName);
        xObjectClasses.put(xoc, xocName);
        if (xoc.getObjectClassType() == ObjectClassType.ABSTRACT) {
          continue;
        }

        if (ndbDATxn == null) {
          ndbDATxn = txn.getNdbDATransaction(xocName, eid);
        }

        indexScanOp =
          ndbDATxn.getSelectIndexScanOperation(
          PRIMARY_INDEX_NAME, xocName,
          NdbOperation.LockMode.LM_CommittedRead);
        indexScanOp.setBoundLong(BackendImpl.EID,
          NdbIndexScanOperation.BoundType.BoundEQ, eid);
        indexScanOp.getValue(BackendImpl.MID);

        for (AttributeType reqAttr : xoc.getRequiredAttributes()) {
          String attrName = reqAttr.getNameOrOID();
          if (BackendImpl.blobAttributes.contains(attrName)) {
            NdbBlob blob = indexScanOp.getBlobHandle(attrName);
            Map<String, NdbBlob> attr2Blob = blobMap.get(xocName);
            if (attr2Blob == null) {
              attr2Blob = new HashMap<String, NdbBlob>();
            }
            attr2Blob.put(attrName, blob);
            blobMap.put(xocName, attr2Blob);
          } else {
            indexScanOp.getValue(attrName);
          }
        }
        for (AttributeType optAttr : xoc.getOptionalAttributes()) {
          String attrName = optAttr.getNameOrOID();
          if (BackendImpl.blobAttributes.contains(attrName)) {
            NdbBlob blob = indexScanOp.getBlobHandle(attrName);
            Map<String, NdbBlob> attr2Blob = blobMap.get(xocName);
            if (attr2Blob == null) {
              attr2Blob = new HashMap<String, NdbBlob>();
            }
            attr2Blob.put(attrName, blob);
            blobMap.put(xocName, attr2Blob);
          } else {
            indexScanOp.getValue(attrName);
          }
        }
        ocRsList.add(indexScanOp.resultData());
      }
    }

    // Operational attributes.
    op = ndbDATxn.getSelectOperation(BackendImpl.OPATTRS_TABLE,
      NdbOperation.LockMode.LM_CommittedRead);
    op.equalLong(BackendImpl.EID, eid);

    for (String attrName : BackendImpl.operationalAttributes) {
      op.getValue(attrName);
    }
    ocRsList.add(op.resultData());

    // Attribute options.
    tagScanOp = ndbDATxn.getSelectIndexScanOperation(
      PRIMARY_INDEX_NAME,
      BackendImpl.TAGS_TABLE,
      NdbOperation.LockMode.LM_CommittedRead);
    tagScanOp.setBoundLong(BackendImpl.EID,
      NdbIndexScanOperation.BoundType.BoundEQ, eid);
    tagScanOp.getValue(BackendImpl.TAG_ATTR);
    tagScanOp.getValue(BackendImpl.MID);
    tagScanOp.getValue(BackendImpl.TAG_TAGS);
    NdbResultSet tagRs = tagScanOp.resultData();

    ndbDATxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    return decodeNDBEntry(dn, ocRsList, tagRs, objectClasses,
      xObjectClasses, blobMap, extensibleObject);
  }
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

  {
    NdbOperation op = null;
    NdbResultSet rs = null;
    long eid = 0;

    NdbTransaction ndbTxn = txn.getNdbTransaction();

    op = ndbTxn.getSelectOperation(name, lockMode);

    int componentIndex = dn.getNumComponents() - 1;
    for (int i=0; i < BackendImpl.DN2ID_DN_NC; i++) {
      while (componentIndex >= 0) {
        op.equalString(BackendImpl.DN2ID_DN + Integer.toString(i),
          dn.getRDN(componentIndex).toNormalizedString());
        componentIndex--;
        i++;
      }
      op.equalString(BackendImpl.DN2ID_DN +
        Integer.toString(i), "");
    }

    op.getValue(BackendImpl.EID);

    rs = op.resultData();
    ndbTxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    if (rs.next()) {
      eid = rs.getLong(BackendImpl.EID);
    }
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

  {
    NdbIndexScanOperation op = null;
    NdbResultSet rs = null;
    Set<String> referrals = new HashSet<String>();

    NdbTransaction ndbDATxn =
      txn.getNdbDATransaction(BackendImpl.REFERRALS_TABLE, id);

    op = ndbDATxn.getSelectIndexScanOperation(
      PRIMARY_INDEX_NAME, BackendImpl.REFERRALS_TABLE,
      NdbOperation.LockMode.LM_CommittedRead);
    op.setBoundLong(BackendImpl.EID,
            NdbIndexScanOperation.BoundType.BoundEQ, id);

    op.getValue(ATTR_REFERRAL_URL);
    rs = op.resultData();

    ndbDATxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    while (rs.next()) {
      String referral = rs.getString(ATTR_REFERRAL_URL);
      if (rs.wasNull() || (referral.length() == 0)) {
        break;
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

    throws NdbApiException
  {
    NdbIndexScanOperation op;
    NdbResultSet rs;

    NdbTransaction ndbTxn = txn.getNdbTransaction();

    // Set batch size and parallel scans to
    // their minimum values to reduce churn.
    op = ndbTxn.getSelectIndexScanOperation(
      PRIMARY_INDEX_NAME, name,
      NdbOperation.LockMode.LM_CommittedRead,
      NdbScanOperation.ScanFlag.NO_FLAG, 1, 1);

    int numComponents = dn.getNumComponents();
    int componentIndex = numComponents - 1;
    for (int i=0; i < numComponents; i++) {
      op.setBoundString(BackendImpl.DN2ID_DN +
        Integer.toString(i),
        NdbIndexScanOperation.BoundType.BoundEQ,
        dn.getRDN(componentIndex).toNormalizedString());
      componentIndex--;
    }

    if (dn.getNumComponents() < BackendImpl.DN2ID_DN_NC) {
      String nextRDNColumn =
        BackendImpl.DN2ID_DN + Integer.toString(numComponents);
      op.setBoundString(nextRDNColumn,
        NdbIndexScanOperation.BoundType.BoundLT, "");
    }

    // FIXME: Need NDB/J API like native interpretExitLastRow
    // to do this more efficiently without additional hops.
    op.getValue(BackendImpl.EID);

    rs = op.resultData();
    ndbTxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    if (rs.next()) {
      return true;
    }
View Full Code Here

Examples of com.mysql.cluster.ndbj.NdbTransaction

  {
    long numSubordinates = 0;
    NdbIndexScanOperation op;
    NdbResultSet rs;

    NdbTransaction ndbTxn = txn.getNdbTransaction();

    op = ndbTxn.getSelectIndexScanOperation(
      PRIMARY_INDEX_NAME, name,
      NdbOperation.LockMode.LM_CommittedRead);

    int numComponents = dn.getNumComponents();
    int componentIndex = numComponents - 1;
    for (int i=0; i < numComponents; i++) {
      op.setBoundString(BackendImpl.DN2ID_DN +
        Integer.toString(i),
        NdbIndexScanOperation.BoundType.BoundEQ,
        dn.getRDN(componentIndex).toNormalizedString());
      componentIndex--;
    }

    // FIXME: Need multi range bound here to optimize in
    // NOT subtree case which would prevent subtree walk
    // when it is not needed. need NDB/J API to do that.
    // native API: NdbIndexScanOperation::end_of_bound()
    if (dn.getNumComponents() < BackendImpl.DN2ID_DN_NC) {
      String nextRDNColumn =
        BackendImpl.DN2ID_DN + Integer.toString(numComponents);
      op.setBoundString(nextRDNColumn,
        NdbIndexScanOperation.BoundType.BoundLT, "");
    }

    // FIXME: Need NDB/J API like native interpretExitLastRow
    // to do this more efficiently without additional hops.
    op.getValue(BackendImpl.EID);

    String subtreeColumn = BackendImpl.DN2ID_DN +
      Integer.toString(dn.getNumComponents() + 1);
    if (!subtree &&
        (dn.getNumComponents() < BackendImpl.DN2ID_DN_NC))
    {
      op.getValue(subtreeColumn);
    }

    rs = op.resultData();
    ndbTxn.execute(ExecType.NoCommit, AbortOption.AO_IgnoreError, true);

    while (rs.next()) {
      if (!subtree &&
          (dn.getNumComponents() < BackendImpl.DN2ID_DN_NC))
      {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.