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


Java PartitionKey类代码示例

本文整理汇总了Java中com.microsoft.azure.documentdb.PartitionKey的典型用法代码示例。如果您正苦于以下问题:Java PartitionKey类的具体用法?Java PartitionKey怎么用?Java PartitionKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: readDocument

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test(groups = { "simple" }, timeOut = TIMEOUT)
public void readDocument() throws Exception {
    Document docDefinition = getDocumentDefinition();

    Document document = client
            .createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource();


    RequestOptions options = new RequestOptions();
    options.setPartitionKey(new PartitionKey(document.get("mypk")));
    Observable<ResourceResponse<Document>> readObservable = client.readDocument(document.getSelfLink(), options);

    ResourceResponseValidator<Document> validator = new ResourceResponseValidator.Builder<Document>()
            .withId(document.getId())
            .build();
    validateSuccess(readObservable, validator);
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:18,代码来源:DocumentCrudTest.java

示例2: readDocument_DoesntExist

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test(groups = { "simple" }, timeOut = TIMEOUT)
public void readDocument_DoesntExist() throws Exception {
    Document docDefinition = getDocumentDefinition();

    Document document = client
            .createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource();

    RequestOptions options = new RequestOptions();
    options.setPartitionKey(new PartitionKey(document.get("mypk")));
    client.deleteDocument(document.getSelfLink(), options).toBlocking().first();

    options.setPartitionKey(new PartitionKey("looloo"));
    Observable<ResourceResponse<Document>> readObservable = client.readDocument(document.getSelfLink(), options);

    FailureValidator validator = new FailureValidator.Builder().instanceOf(DocumentClientException.class)
            .statusCode(404).build();
    validateFailure(readObservable, validator);
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:19,代码来源:DocumentCrudTest.java

示例3: deleteDocument

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test(groups = { "simple" }, timeOut = TIMEOUT)
public void deleteDocument() throws Exception {
    Document docDefinition = getDocumentDefinition();

    Document document = client
            .createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource();

    RequestOptions options = new RequestOptions();
    options.setPartitionKey(new PartitionKey(document.get("mypk")));
    Observable<ResourceResponse<Document>> deleteObservable = client.deleteDocument(document.getSelfLink(), options);


    ResourceResponseValidator<Document> validator = new ResourceResponseValidator.Builder<Document>()
            .nullResource().build();
    validateSuccess(deleteObservable, validator);

    //TODO validate after deletion the resource is actually deleted (not found)
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:19,代码来源:DocumentCrudTest.java

示例4: deleteDocument_DoesntExist

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test(groups = { "simple" }, timeOut = TIMEOUT)
public void deleteDocument_DoesntExist() throws Exception {
    Document docDefinition = getDocumentDefinition();

    Document document = client
            .createDocument(getCollectionLink(), docDefinition, null, false).toBlocking().single().getResource();

    RequestOptions options = new RequestOptions();
    options.setPartitionKey(new PartitionKey(document.get("mypk")));
    client.deleteDocument(document.getSelfLink(), options).toBlocking().single();

    // delete again
    Observable<ResourceResponse<Document>> deleteObservable = client.deleteDocument(document.getSelfLink(), options);

    FailureValidator validator = new FailureValidator.Builder().resourceNotFound().build();
    validateFailure(deleteObservable, validator);
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:18,代码来源:DocumentCrudTest.java

示例5: executeStoredProcWithArgs

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test
public void executeStoredProcWithArgs() throws DocumentClientException {
    // create stored procedure
    StoredProcedure storedProcedure = new StoredProcedure(
            "{" +
                    "  'id': 'multiplySample'," +
                    "  'body':" +
                    "    'function (value, num) {" +
                    "      getContext().getResponse().setBody(" +
                    "          \"2*\" + value + \" is \" + num * 2 );" +
                    "    }'" +
            "}");

    client.createStoredProcedure(collection.getSelfLink(), storedProcedure, null).getResource();

    // execute stored procedure
    RequestOptions requestOptions = new RequestOptions();
    requestOptions.setPartitionKey(new PartitionKey("Seattle"));

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

    Object[] storedProcedureArgs = new Object[] {"a", 123};
    String storedProcResultAsString = client.executeStoredProcedure(storedProcLink, requestOptions, storedProcedureArgs).getResponseAsString();
    assertThat(storedProcResultAsString, equalTo("\"2*a is 246\""));
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:26,代码来源:StoredProcedureSamples.java

示例6: scriptConsoleLogEnabled

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test
public void scriptConsoleLogEnabled() throws DocumentClientException {
    // create a stored procedure
    String storeProcedureStr = "{" +
            "  'id':'storedProcedureSample'," +
            "  'body':" +
            "    'function() {" +
            "        var mytext = \"x\";" +
            "        var myval = 1;" +
            "        try {" +
            "            console.log(\"The value of %s is %s.\", mytext, myval);" +
            "            getContext().getResponse().setBody(\"Success!\");" +
            "        }" +
            "        catch(err) {" +
            "            getContext().getResponse().setBody(\"inline err: [\" + err.number + \"] \" + err);" +
            "        }" +
            "    }'" +
            "}";
    StoredProcedure storedProcedure = new StoredProcedure(storeProcedureStr);
    client.createStoredProcedure(collection.getSelfLink(), storedProcedure, null);

    // execute stored procedure
    String storedProcLink = String.format("/dbs/%s/colls/%s/sprocs/%s", databaseId, collectionId, "storedProcedureSample");

    RequestOptions requestOptions = new RequestOptions();
    requestOptions.setScriptLoggingEnabled(true);
    requestOptions.setPartitionKey(new PartitionKey("Seattle"));

    StoredProcedureResponse response = client.executeStoredProcedure(storedProcLink,
            requestOptions, new Object[]{});

    String logResult = "The value of x is 1.";
    assertThat(response.getScriptLog(), is(logResult));
    assertThat(response.getResponseHeaders().get(HttpConstants.HttpHeaders.SCRIPT_LOG_RESULTS), is(logResult));
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:36,代码来源:StoredProcedureSamples.java

示例7: executeStoredProcWithPojoArgs

import com.microsoft.azure.documentdb.PartitionKey; //导入依赖的package包/类
@Test
public void executeStoredProcWithPojoArgs() throws DocumentClientException {
    // create stored procedure
    StoredProcedure storedProcedure = new StoredProcedure(
            "{" +
                    "  'id': 'storedProcedurePojoSample'," +
                    "  'body':" +
                    "    'function (value) {" +
                    "      getContext().getResponse().setBody(" +
                    "          \"a is \" + value.temp);" +
                    "    }'" +
            "}");

    client.createStoredProcedure(collection.getSelfLink(), storedProcedure, null).getResource();

    // execute stored procedure
    String storedProcLink = String.format("/dbs/%s/colls/%s/sprocs/%s", databaseId, collectionId, "storedProcedurePojoSample");

    RequestOptions requestOptions = new RequestOptions();
    requestOptions.setPartitionKey(new PartitionKey("Seattle"));

    // POJO
    class SamplePojo {
        public String temp = "my temp value";
    }
    SamplePojo samplePojo = new SamplePojo();

    Object[] storedProcedureArgs = new Object[] { samplePojo };

    String storedProcResultAsString = client.executeStoredProcedure(storedProcLink, requestOptions, storedProcedureArgs).getResponseAsString();
    assertThat(storedProcResultAsString, equalTo("\"a is my temp value\""));
}
 
开发者ID:Azure,项目名称:azure-documentdb-java,代码行数:33,代码来源:StoredProcedureSamples.java


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