当前位置: 首页>>代码示例>>Java>>正文


Java DocumentCollection.setPartitionKey方法代码示例

本文整理汇总了Java中com.microsoft.azure.documentdb.DocumentCollection.setPartitionKey方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentCollection.setPartitionKey方法的具体用法?Java DocumentCollection.setPartitionKey怎么用?Java DocumentCollection.setPartitionKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.microsoft.azure.documentdb.DocumentCollection的用法示例。


在下文中一共展示了DocumentCollection.setPartitionKey方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createMultiPartitionCollection

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
private DocumentCollection createMultiPartitionCollection(String databaseLink, String collectionId,
        String partitionKeyPath) throws DocumentClientException {
    PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition();
    ArrayList<String> paths = new ArrayList<String>();
    paths.add(partitionKeyPath);
    partitionKeyDef.setPaths(paths);

    RequestOptions options = new RequestOptions();
    options.setOfferThroughput(10100);
    DocumentCollection collectionDefinition = new DocumentCollection();
    collectionDefinition.setId(collectionId);
    collectionDefinition.setPartitionKey(partitionKeyDef);
    DocumentCollection createdCollection = asyncClient
            .createCollection(databaseLink, collectionDefinition, options).toBlocking().single().getResource();

    return createdCollection;
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:18,代码来源:DocumentQueryAsyncAPITest.java

示例2: setup

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
public void setup(DocumentClient client) throws Exception {
    logger.debug("setting up ...");
    cleanUpDatabase(client);

    Thread.sleep(5000);
    Database d = new Database();
    d.setId(databaseId);
    Database database = client.createDatabase(d, null).getResource();


    PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition();
    ArrayList<String> paths = new ArrayList<String>();
    paths.add("/mypk");
    partitionKeyDef.setPaths(paths);

    pCollection = new DocumentCollection();
    pCollection.setId(collectionId);
    pCollection.setPartitionKey(partitionKeyDef);

    RequestOptions options = new RequestOptions();
    options.setOfferThroughput(10100);
    pCollection = client.createCollection(database.getSelfLink(), pCollection, options).getResource();
    logger.debug("setting up done.");
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:25,代码来源:EndToEndTestBase.java

示例3: getCollectionDefinition

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
static protected DocumentCollection getCollectionDefinition() {
    PartitionKeyDefinition partitionKeyDef = new PartitionKeyDefinition();
    ArrayList<String> paths = new ArrayList<String>();
    paths.add("/mypk");
    partitionKeyDef.setPaths(paths);

    RequestOptions options = new RequestOptions();
    options.setOfferThroughput(10100);
    DocumentCollection collectionDefinition = new DocumentCollection();
    collectionDefinition.setId(UUID.randomUUID().toString());
    collectionDefinition.setPartitionKey(partitionKeyDef);

    return collectionDefinition;
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:15,代码来源:DocumentQueryTest.java

示例4: createMultiPartitionCollection

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
private void createMultiPartitionCollection() throws DocumentClientException {

        String databaseLink = String.format("/dbs/%s", databaseId);

        DocumentCollection collectionDefinition = new DocumentCollection();
        collectionDefinition.setId(collectionId);

        // set /city as the partition key path
        PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
        Collection<String> paths = new ArrayList<String>();
        paths.add(partitionKeyPath);
        partitionKeyDefinition.setPaths(paths);
        collectionDefinition.setPartitionKey(partitionKeyDefinition);

        // set the throughput to be 10,200
        RequestOptions options = new RequestOptions();
        options.setOfferThroughput(10200);

        // set indexing policy to be range range for string and number
        IndexingPolicy indexingPolicy = new IndexingPolicy();
        Collection<IncludedPath> includedPaths = new ArrayList<IncludedPath>();
        IncludedPath includedPath = new IncludedPath();
        includedPath.setPath("/*");
        Collection<Index> indexes = new ArrayList<Index>();
        Index stringIndex = Index.Range(DataType.String);
        stringIndex.set("precision", -1);
        indexes.add(stringIndex);

        Index numberIndex = Index.Range(DataType.Number);
        numberIndex.set("precision", -1);
        indexes.add(numberIndex);
        includedPath.setIndexes(indexes);
        includedPaths.add(includedPath);
        indexingPolicy.setIncludedPaths(includedPaths);
        collectionDefinition.setIndexingPolicy(indexingPolicy);

        // create a collection
        client.createCollection(databaseLink, collectionDefinition, options);
    }
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:40,代码来源:DocumentQuerySamples.java

示例5: createMultiPartitionCollection

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
private void createMultiPartitionCollection() throws DocumentClientException {

        String databaseLink = String.format("/dbs/%s", databaseId);

        DocumentCollection collectionDefinition = new DocumentCollection();
        collectionDefinition.setId(collectionId);

        // set /city as the partition key path
        PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
        Collection<String> paths = new ArrayList<String>();
        paths.add(partitionKeyPath);
        partitionKeyDefinition.setPaths(paths);
        collectionDefinition.setPartitionKey(partitionKeyDefinition);

        // set the throughput to be 10,200
        RequestOptions options = new RequestOptions();
        options.setOfferThroughput(10200);

        // set indexing policy to be range range for string and number
        IndexingPolicy indexingPolicy = new IndexingPolicy();
        Collection<IncludedPath> includedPaths = new ArrayList<IncludedPath>();
        IncludedPath includedPath = new IncludedPath();
        includedPath.setPath("/*");
        Collection<Index> indexes = new ArrayList<Index>();
        Index stringIndex = Index.Range(DataType.String);
        stringIndex.set("precision", -1);
        indexes.add(stringIndex);

        Index numberIndex = Index.Range(DataType.Number);
        numberIndex.set("precision", -1);
        indexes.add(numberIndex);
        includedPath.setIndexes(indexes);
        includedPaths.add(includedPath);
        indexingPolicy.setIncludedPaths(includedPaths);
        collectionDefinition.setIndexingPolicy(indexingPolicy);

        // create a collection
        this.collection = client.createCollection(databaseLink, collectionDefinition, options).getResource();
    }
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:40,代码来源:StoredProcedureSamples.java

示例6: createCustomMultiPartitionCollection

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
@Test
public void createCustomMultiPartitionCollection() throws DocumentClientException {

    String databaseLink = String.format("/dbs/%s", databaseId);
    String collectionId = "testCollection";

    DocumentCollection collectionDefinition = new DocumentCollection();
    collectionDefinition.setId(collectionId);

    // set /city as the partition key path
    PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
    Collection<String> paths = new ArrayList<String>();
    paths.add("/city");
    partitionKeyDefinition.setPaths(paths);
    collectionDefinition.setPartitionKey(partitionKeyDefinition);

    // set the throughput to be 20,000
    RequestOptions options = new RequestOptions();
    options.setOfferThroughput(20000);

    // set ttl to 100 seconds
    collectionDefinition.setDefaultTimeToLive(100);

    // set indexing policy to be range range for string and number
    IndexingPolicy indexingPolicy = new IndexingPolicy();
    Collection<IncludedPath> includedPaths = new ArrayList<IncludedPath>();
    IncludedPath includedPath = new IncludedPath();
    includedPath.setPath("/*");
    Collection<Index> indexes = new ArrayList<Index>();
    Index stringIndex = Index.Range(DataType.String);
    stringIndex.set("precision", -1);
    indexes.add(stringIndex);

    Index numberIndex = Index.Range(DataType.Number);
    numberIndex.set("precision", -1);
    indexes.add(numberIndex);
    includedPath.setIndexes(indexes);
    includedPaths.add(includedPath);
    indexingPolicy.setIncludedPaths(includedPaths);
    collectionDefinition.setIndexingPolicy(indexingPolicy);

    // create a collection
    client.createCollection(databaseLink, collectionDefinition, options);

    // create a document in the collection
    String collectionLink = String.format("/dbs/%s/colls/%s", databaseId, collectionId);
    Document documentDefinition = new Document(
            "{" +
                    "   \"id\": \"test-document\"," +
                    "   \"city\" : \"Seattle\"" +
            "} ") ;

    client.createDocument(collectionLink, documentDefinition, options, false);
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:55,代码来源:CollectionCrudSamples.java

示例7: updateOffer

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
@Test
public void updateOffer() throws DocumentClientException {

    ////////////////////////////////////////////////////////////////////////////
    // create a collection
    ////////////////////////////////////////////////////////////////////////////

    String databaseLink = String.format("/dbs/%s", databaseId);

    DocumentCollection collectionDefinition = new DocumentCollection();
    collectionDefinition.setId(collectionId);

    // set /city as the partition key path
    PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
    Collection<String> paths = new ArrayList<String>();
    paths.add(partitionKeyPath);
    partitionKeyDefinition.setPaths(paths);
    collectionDefinition.setPartitionKey(partitionKeyDefinition);

    int throughput = 10200;
    // set the throughput to be 10,200
    RequestOptions options = new RequestOptions();
    options.setOfferThroughput(throughput);

    // create a collection
    client.createCollection(databaseLink, collectionDefinition, options);

    String collectionLink = String.format("/dbs/%s/colls/%s", databaseId, collectionId);

    ////////////////////////////////////////////////////////////////////////////
    // find the offer associated with the created collection
    ////////////////////////////////////////////////////////////////////////////

    // read the collection
    String collectionResourceId = client.readCollection(collectionLink, options).getResource().getResourceId();

    // find offer associated with this collection
    Iterator<Offer> it = client.queryOffers(
            String.format("SELECT * FROM r where r.offerResourceId = '%s'", collectionResourceId), null).getQueryIterator();
    assertThat(it.hasNext(), equalTo(true));

    Offer offer = it.next();
    assertThat(offer.getString("offerResourceId"), equalTo(collectionResourceId));
    assertThat(offer.getContent().getInt("offerThroughput"), equalTo(throughput));

    // update the offer
    int newThroughput = 10300;
    offer.getContent().put("offerThroughput", newThroughput);
    client.replaceOffer(offer);

    // validate the updated offer
    it = client.queryOffers(String.format("SELECT * FROM r where r.offerResourceId = '%s'", collectionResourceId), null).getQueryIterator();
    assertThat(it.hasNext(), equalTo(true));

    offer = it.next();
    assertThat(offer.getString("offerResourceId"), equalTo(collectionResourceId));
    assertThat(offer.getContent().getInt("offerThroughput"), equalTo(newThroughput));
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:59,代码来源:OfferCrudSamples.java

示例8: createSinglePartitionCollection

import com.microsoft.azure.documentdb.DocumentCollection; //导入方法依赖的package包/类
private void createSinglePartitionCollection(String partitionKeyPath) throws DocumentClientException {
    String databaseLink = String.format("/dbs/%s", databaseId);

    DocumentCollection collectionDefinition = new DocumentCollection();
    collectionDefinition.setId(collectionId);

    // set /city as the partition key path
    PartitionKeyDefinition partitionKeyDefinition = new PartitionKeyDefinition();
    Collection<String> paths = new ArrayList<String>();
    paths.add(partitionKeyPath);
    partitionKeyDefinition.setPaths(paths);
    collectionDefinition.setPartitionKey(partitionKeyDefinition);

    // if you want a single partition collection with 10,000 throughput
    // the only way to do so is to create a single partition collection with lower throughput (400)
    // and then increase the throughput to 10,000
    RequestOptions options = new RequestOptions();
    options.setOfferThroughput(400);

    // set indexing policy to be range range for string and number
    IndexingPolicy indexingPolicy = new IndexingPolicy();
    Collection<IncludedPath> includedPaths = new ArrayList<IncludedPath>();
    IncludedPath includedPath = new IncludedPath();
    includedPath.setPath("/*");
    Collection<Index> indexes = new ArrayList<Index>();
    Index stringIndex = Index.Range(DataType.String);
    stringIndex.set("precision", -1);
    indexes.add(stringIndex);

    Index numberIndex = Index.Range(DataType.Number);
    numberIndex.set("precision", -1);
    indexes.add(numberIndex);
    includedPath.setIndexes(indexes);
    includedPaths.add(includedPath);
    indexingPolicy.setIncludedPaths(includedPaths);
    collectionDefinition.setIndexingPolicy(indexingPolicy);

    // create a collection
    DocumentCollection createdDollection = 
            client.createCollection(databaseLink, collectionDefinition, options).getResource();
    
    // increase throughput from 400 to 10,000
    replaceOffer(createdDollection, 10000);
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:45,代码来源:SinglePartitionCollectionDocumentCrudSample.java


注:本文中的com.microsoft.azure.documentdb.DocumentCollection.setPartitionKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。