コード例 #1
0
  public void performBatch(DataSyncOperation[] operations) {
    List<BatchUnit> rows = new LinkedList<BatchUnit>();

    for (DataSyncOperation operation : operations) {

      BatchUnit bu = new BatchUnit();
      cacheTypeDescriptor(operation.getTypeDescriptor());
      bu.setSpaceDocument(operation.getDataAsDocument());
      bu.setDataSyncOperationType(operation.getDataSyncOperationType());
      rows.add(bu);
    }

    performBatch(rows);
  }
コード例 #2
0
  public void performBatch(List<BatchUnit> rows) {
    if (logger.isTraceEnabled()) {
      logger.trace("MongoClientWrapper.performBatch(" + rows + ")");
      logger.trace("Batch size to be performed is " + rows.size());
    }
    // List<Future<? extends Number>> pending = new ArrayList<Future<? extends Number>>();

    for (BatchUnit row : rows) {
      SpaceDocument spaceDoc = row.getSpaceDocument();
      SpaceTypeDescriptor typeDescriptor = types.get(row.getTypeName()).getTypeDescriptor();
      SpaceDocumentMapper<DBObject> mapper = getMapper(typeDescriptor);

      DBObject obj = mapper.toDBObject(spaceDoc);

      DBCollection col = getCollection(row.getTypeName());
      switch (row.getDataSyncOperationType()) {
        case WRITE:
        case UPDATE:
          col.save(obj);
          break;
        case PARTIAL_UPDATE:
          DBObject query =
              BasicDBObjectBuilder.start()
                  .add(Constants.ID_PROPERTY, obj.get(Constants.ID_PROPERTY))
                  .get();

          DBObject update = normalize(obj);
          col.update(query, update);
          break;
          // case REMOVE_BY_UID: // Not supported by this implementation
        case REMOVE:
          col.remove(obj);
          break;
        default:
          throw new IllegalStateException(
              "Unsupported data sync operation type: " + row.getDataSyncOperationType());
      }
    }

    /*long totalCount = waitFor(pending);

    if (logger.isTraceEnabled()) {
    	logger.trace("total accepted replies is: " + totalCount);
    }*/
  }