/*
@see android.content.ContentProvider#bulkInsert(android.net.Uri,
android.content.ContentValues[])
@since 1.0.1
193665
@Override
    public int bulkInsert(Uri uri, ContentValues[] values) {
        int result = 0;

        if (!controller.hasPreinitialized()) {
            throw new IllegalStateException("Controller has not been initialized.");
        }

        int patternCode = controller.getUriMatcher().match(uri);
        MatcherPattern pattern = controller.findMatcherPattern(patternCode);
        if (pattern == null) {
            throw new IllegalArgumentException("unknown uri : " + uri.toString());
        }

        SQLiteDatabase db = this.getHelper().getWritableDatabase();

        db.beginTransaction();
        try {
            for (ContentValues value : values) {
                Parameter parameter = new Parameter(uri, value);

                Uri resultBulkInsert = this.onBulkInsert(this.getHelper(), db, pattern, parameter);
                if (resultBulkInsert != null) {
                    result++;
                    // this.getContext().getContentResolver().notifyChange(resultBulkInsert, null);
                }
            }
            db.setTransactionSuccessful();

            if (result >= 1) {
                this.onBulkInsertCompleted(result, uri);
            }
        } finally {
            db.endTransaction();
        }
        return result;
    }
1145423
public List<Response> bulk(List<?> objects, boolean allOrNothing) {
        assertNotEmpty(objects, "objects");
        InputStream responseStream = null;
        HttpConnection connection;
        try {
            final JsonObject jsonObject = new JsonObject();
            if(allOrNothing) {
                jsonObject.addProperty("all_or_nothing", true);
            }
            final URI uri = new DatabaseURIHelper(dbUri).bulkDocsUri();
            jsonObject.add("docs", getGson().toJsonTree(objects));
            connection = Http.POST(uri, "application/json");
            if (jsonObject.toString().length() != 0) {
                connection.setRequestBody(jsonObject.toString());
            }
            couchDbClient.execute(connection);
            responseStream = connection.responseAsInputStream();
            List<Response> bulkResponses = getResponseList(responseStream, getGson(),
                    DeserializationTypes.LC_RESPONSES);
            for(Response response : bulkResponses) {
                response.setStatusCode(connection.getConnection().getResponseCode());
            }
            return bulkResponses;
        }
        catch (IOException e) {
            throw new CouchDbException("Error retrieving response input stream.", e);
        } finally {
            close(responseStream);
        }
    }
632701
public static byte[] insert (byte[] values, byte value, int index)
    {
        byte[] nvalues = new byte[values.length+1];
        if (index > 0) {
            System.arraycopy(values, 0, nvalues, 0, index);
        }
        nvalues[index] = value;
        if (index < values.length) {
            System.arraycopy(values, index, nvalues, index+1, values.length-index);
        }
        return nvalues;
    }
660686
@Override
	public int update(Uri uri, ContentValues contentvalues, String s,
										String[] as) {
		return 0;
	}
9050
@Override
  protected void bulkLoad(List<E> spatialObjects) {
    if(!initialized) {
      initialize(spatialObjects.get(0));
    }

    StringBuilder msg = getLogger().isDebuggingFine() ? new StringBuilder() : null;

    // Tiny tree that fits into a single page
    if(spatialObjects.size() <= leafCapacity) {
      N root = createNewLeafNode();
      root.setPageID(getRootID());
      writeNode(root);
      createRoot(root, spatialObjects);
      setHeight(1);
      if(msg != null) {
        msg.append("\n  numNodes = 1");
      }
    }
    // root is directory node
    else {
      N root = createNewDirectoryNode();
      root.setPageID(getRootID());
      writeNode(root);

      // create leaf nodes
      List<E> nodes = createBulkLeafNodes(spatialObjects);

      int numNodes = nodes.size();
      if(msg != null) {
        msg.append("\n  numLeafNodes = ").append(numNodes);
      }
      setHeight(1);

      // create directory nodes
      while(nodes.size() > (dirCapacity - 1)) {
        nodes = createBulkDirectoryNodes(nodes);
        numNodes += nodes.size();
        setHeight(getHeight() + 1);
      }

      // create root
      createRoot(root, nodes);
      numNodes++;
      setHeight(getHeight() + 1);
      if(msg != null) {
        msg.append("\n  numNodes = ").append(numNodes);
      }
    }
    if(msg != null) {
      msg.append("\n  height = ").append(getHeight());
      msg.append("\n  root ").append(getRoot());
      getLogger().debugFine(msg.toString());
    }
  }
1131842
@PUT
    public Response putContent(@PathParam("spaceID") String spaceID,
                               @PathParam("contentID") String contentID,
                               @QueryParam("storeID") String storeID,
                               @HeaderParam(COPY_SOURCE_HEADER) String copySource,
                               @HeaderParam(COPY_SOURCE_STORE_HEADER) String sourceStoreID) {
        if (null != copySource) {
            return copyContent(spaceID, contentID, storeID, sourceStoreID, copySource);

        } else {
            return addContent(spaceID, contentID, storeID);
        }
    }
645661
@NonNull
    @Override
    public MutableArray insertString(int index, String value) {
        return insertValue(index, value);
    }
574213
public void add(ByteArrayList values) {
        ensureCapacity(size + values.size);
        for (int i=0; i<values.size; i++) {
            this.add(values.elements[i]);
        }
    }
575832
@SafeVarargs
	public final void addInsert(Map<String, Object>... maps) throws SQLException {
		if (insertNps != null) {
			addAction(insertNps, insertKeysToColumns, maps);
			noOfInserts++;
		} else {
			throw new RuntimeException("No insert for importer: " + tableName);
		}
	}
1004418
@Override
    public void write(List<? extends ContentProperties> items) throws Exception {
        for (final ContentProperties props : items) {
            new Retrier().execute(new Retriable() {

                @Override
                public Object retry() throws Exception {
                    try {
                        contentStore.setContentProperties(destinationSpaceId,
                                                          props.getContentId(),
                                                          props.getProperties());
                        log.debug("wrote content properties ({}) to space ({}) on store ({}/{}):",
                                  props, destinationSpaceId, storeId, storageProviderType);
                        return null;
                    } catch (ContentStoreException ex) {
                        log.warn("failed to update content properties ({}) to space({}); on store({}/{}). " +
                                 "Trying with chunk manifest extension.",
                                 props, destinationSpaceId, storeId, storageProviderType);

                        //make sure the chunk manifest's properties are layed on top of the stitched file
                        //properties to ensure that mutable "system-ish" properties such as content type are not
                        //overwritten.
                        String manifestId = props.getContentId() + ChunksManifest.manifestSuffix;
                        Map<String, String> properties = new HashMap<>(props.getProperties());
                        Map<String, String> chunkManifestProperties =
                            contentStore.getContentProperties(destinationSpaceId, manifestId);
                        properties.putAll(chunkManifestProperties);
                        contentStore.setContentProperties(destinationSpaceId, manifestId, properties);
                        return null;
                    }
                }
            });
        }
    }
1176756
public void setBulkDeployments(java.util.Collection<BulkDeployment> bulkDeployments) {
        if (bulkDeployments == null) {
            this.bulkDeployments = null;
            return;
        }

        this.bulkDeployments = new java.util.ArrayList<BulkDeployment>(bulkDeployments);
    }
1238408
public void addContents(final List<JingleContent> contentList) {
        if (contentList != null) {
            synchronized (contents) {
                contents.addAll(contentList);
            }
        }
    }
219073
@Override
    public void updateContentRepository(final Iterable<Content> content) {
        Content oldContent = contentColumn.getSelectedItem();
        Content newContent = null;

        if (oldContent != null) {
            for (Content c : content) {
                if (c.getName().equals(oldContent.getName())) {
                    newContent = c;
                }
            }
        }
        contentColumn.updateFrom(Lists.newArrayList(content), newContent);
        setPreview(PreviewContent.INSTANCE.content_repository());
    }
32142
public static void cursorStringToContentValues(Cursor cursor, String field,
            ContentValues values) {
        cursorStringToContentValues(cursor, field, values, field);
    }
1361870
@NonNull
    @Override
    public MutableArray insertBlob(int index, Blob value) {
        return insertValue(index, value);
    }
734150
@Override
  protected void bulkLoad(List<RdKNNEntry> entries) {
    super.bulkLoad(entries);

    // adjust all knn distances
    ArrayModifiableDBIDs ids = DBIDUtil.newArray(entries.size());
    for(RdKNNEntry entry : entries) {
      DBID id = ((RdKNNLeafEntry) entry).getDBID();
      ids.add(id);
    }
    ids.sort();
    List<? extends KNNList> knnLists = knnQuery.getKNNForBulkDBIDs(ids, settings.k_max);
    adjustKNNDistance(getRootEntry(), ids, knnLists);

    // test
    doExtraIntegrityChecks();
  }
648570
@Override
    public String addContent(String spaceID,
                             String contentID,
                             InputStream content,
                             String contentMimeType,
                             Map<String, String> userProperties,
                             long contentSize,
                             String checksum,
                             String storeID)
        throws ResourceException, InvalidIdException, ResourcePropertiesInvalidException {

        IdUtil.validateContentId(contentID);
        validateProperties(userProperties, "add content", spaceID, contentID);

        try {
            StorageProvider storage =
                storageProviderFactory.getStorageProvider(storeID);

            try {
                // overlay new properties on top of older extended properties
                // so that old tags and custom properties are preserved.
                // c.f. https://jira.duraspace.org/browse/DURACLOUD-757
                Map<String, String> oldUserProperties =
                    storage.getContentProperties(spaceID, contentID);
                //remove all non extended properties
                if (userProperties != null) {
                    oldUserProperties.putAll(userProperties);
                    //use old mimetype if none specified.
                    String oldMimetype =
                        oldUserProperties.remove(StorageProvider.PROPERTIES_CONTENT_MIMETYPE);
                    if (contentMimeType == null || contentMimeType.trim() == "") {
                        contentMimeType = oldMimetype;
                    }

                    oldUserProperties = StorageProviderUtil.removeCalculatedProperties(oldUserProperties);
                }

                userProperties = oldUserProperties;
            } catch (NotFoundException ex) {
                // do nothing - no properties to update
                // since file did not previous exist.
            }

            return storage.addContent(spaceID,
                                      contentID,
                                      contentMimeType,
                                      userProperties,
                                      contentSize,
                                      checksum,
                                      content);
        } catch (NotFoundException e) {
            throw new ResourceNotFoundException("add content",
                                                spaceID,
                                                contentID,
                                                e);
        } catch (ChecksumMismatchException e) {
            throw new ResourceChecksumException("add content",
                                                spaceID,
                                                contentID,
                                                e);
        } catch (Exception e) {
            storageProviderFactory.expireStorageProvider(storeID);
            throw new ResourceException("add content", spaceID, contentID, e);
        }
    }