• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DesignDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: should_import_design_doc

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void should_import_design_doc() {
    // Given a Design Doc
    String name = "user";
    String design_doc = "{\n" +
            "  \"views\": {\n" +
            "    \"findUser\": {\n" +
            "      \"map\": \"function (doc, meta) {\\n  if (doc.type == \\\"user\\\") {\\n    emit(doc.username, null);\\n  } \\n}\"\n" +
            "    }\n" +
            "  }\n" +
            "}";

    // When we import it
    repository.importDesignDoc(name, design_doc);

    // Then it should be saved
    DesignDocument designDocument = AbstractCouchbaseTest.getBucket().bucketManager().getDesignDocument(name);
    Assert.assertNotNull(designDocument);
}
 
开发者ID:differentway,项目名称:couchmove,代码行数:20,代码来源:CouchbaseRepositoryTest.java


示例2: shouldNotDeleteAll

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void shouldNotDeleteAll() throws IOException {
  final BucketManager bucketManager = bucket.bucketManager();
  final View view =
      DefaultView.create("all", IOUtils.toString(getClass().getResourceAsStream("/all.js")));
  final DesignDocument document = DesignDocument.create("person", ImmutableList.of(view));
  try {
    bucketManager.upsertDesignDocument(document);

    repository.deleteAll();
    final Iterable<Person> found = repository.findAll();
    assertEquals(ImmutableList.of(), found);
  } finally {
    bucketManager.removeDesignDocument(document.name());
  }
}
 
开发者ID:jloisel,项目名称:reactive-couchbase,代码行数:17,代码来源:SyncRepositoryTest.java


示例3: shouldDeleteAll

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void shouldDeleteAll() throws IOException {
  final BucketManager bucketManager = bucket.bucketManager();
  final View view =
      DefaultView.create("all", IOUtils.toString(getClass().getResourceAsStream("/all.js")));
  final DesignDocument document = DesignDocument.create("person", ImmutableList.of(view));
  try {
    bucketManager.upsertDesignDocument(document);

    repository.save(person);
    repository.deleteAll();
    final Iterable<Person> found = repository.findAll();
    assertEquals(ImmutableList.of(), found);
  } finally {
    bucketManager.removeDesignDocument(document.name());
  }
}
 
开发者ID:jloisel,项目名称:reactive-couchbase,代码行数:18,代码来源:SyncRepositoryTest.java


示例4: shouldFindAll

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void shouldFindAll() throws IOException {
  final BucketManager bucketManager = bucket.bucketManager();
  final View view =
      DefaultView.create("all", IOUtils.toString(getClass().getResourceAsStream("/all.js")));
  final DesignDocument document = DesignDocument.create("person", ImmutableList.of(view));
  try {
    bucketManager.upsertDesignDocument(document);

    repository.save(person);
    final Iterable<Person> found = repository.findAll();
    assertEquals(ImmutableList.of(person), found);
  } finally {
    bucketManager.removeDesignDocument(document.name());
  }
}
 
开发者ID:jloisel,项目名称:reactive-couchbase,代码行数:17,代码来源:SyncRepositoryTest.java


示例5: shouldQueryView

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void shouldQueryView() throws IOException {
  final BucketManager bucketManager = bucket.bucketManager();
  final View view =
      DefaultView.create("byFirstname",
          IOUtils.toString(getClass().getResourceAsStream("/byfirstname.js")));
  final DesignDocument document = DesignDocument.create("person", ImmutableList.of(view));
  try {
    bucketManager.upsertDesignDocument(document);

    repository.save(person);
    final ViewQuery query = ViewQuery.from(document.name(), view.name());
    query.stale(Stale.FALSE);
    query.debug();
    query.key(person.getFirstname());

    final Iterable<Person> found = repository.queryView(query);
    assertEquals(ImmutableList.of(person), found);
  } finally {
    bucketManager.removeDesignDocument(document.name());
  }
}
 
开发者ID:jloisel,项目名称:reactive-couchbase,代码行数:23,代码来源:SyncRepositoryTest.java


示例6: checkAndGetViewInfo

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
/**
 * Checks for existence of a view adapted for iteration on all this cache's values.
 *
 * @return a pair of the view's designDoc and name if it exists, throws a {@link CacheException} otherwise.
 * @throws CacheException when a suitable view could not be found.
 * @see CouchbaseConfiguration#getAllViewDesignDoc()
 * @see CouchbaseConfiguration#getAllViewName()
 * @see CouchbaseConfiguration.Builder#viewAll(String, String)
 */
public String[] checkAndGetViewInfo() {
    String expectedDesignDoc = configuration.getAllViewDesignDoc();
    String expectedViewName = configuration.getAllViewName();
    Exception cause = null;

    try {
        DesignDocument designDoc = bucket.bucketManager().getDesignDocument(expectedDesignDoc);
        if (designDoc == null) {
            cause = new NullPointerException("Design document " + expectedDesignDoc + " does not exist");
        } else {
            for (View view : designDoc.views()) {
                if (expectedViewName.equalsIgnoreCase(view.name())) {
                    return new String[] { designDoc.name(), view.name() };
                }
            }
        }
    } catch (Exception e) {
        cause = e;
    }
    throw new CacheException("Cannot find view " + expectedDesignDoc + "/" + expectedViewName
            + " for cache " + getName() + ",did you create it?", cause);
}
 
开发者ID:couchbaselabs,项目名称:couchbase-java-cache,代码行数:32,代码来源:CouchbaseCache.java


示例7: doEnsureIndexes

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
/**
 * Ensures that all views exists in the database.
 *
 * @param documentName the name of the design document.
 * @param views the views to ensure exists in the database.
 */
private void doEnsureIndexes(final String documentName, final List<View> views) {
    logger.debug("Ensure that indexes exist in bucket {}.", bucket.name());
    final DesignDocument newDocument = DesignDocument.create(documentName, views);
    if (!newDocument.equals(bucket.bucketManager().getDesignDocument(documentName))) {
        logger.warn("Missing indexes in bucket {} for document {}, creating new.", bucket.name(), documentName);
        bucket.bucketManager().upsertDesignDocument(newDocument);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:15,代码来源:CouchbaseClientFactory.java


示例8: doEnsureIndexes

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
/**
 * Ensures that all views exists in the database.
 *
 * @param documentName the name of the design document.
 * @param views the views to ensure exists in the database.
 */
private void doEnsureIndexes(final String documentName, final List<View> views) {
    LOGGER.debug("Ensure that indexes exist in bucket [{}]", this.bucket.name());
    final DesignDocument newDocument = DesignDocument.create(documentName, views);
    if (!newDocument.equals(this.bucket.bucketManager().getDesignDocument(documentName))) {
        LOGGER.warn("Missing indexes in bucket [{}] for document [{}]", this.bucket.name(), documentName);
        this.bucket.bucketManager().upsertDesignDocument(newDocument);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:CouchbaseClientFactory.java


示例9: importDesignDoc

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Override
public void importDesignDoc(String name, String jsonContent) {
    logger.trace("Import document : \n'{}'", jsonContent);
    bucket.bucketManager().upsertDesignDocument(DesignDocument.from(name, JsonObject.fromJson(jsonContent)));
}
 
开发者ID:differentway,项目名称:couchmove,代码行数:6,代码来源:CouchbaseRepositoryImpl.java


示例10: should_migrate_successfully

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void should_migrate_successfully() {
    // Given a Couchmove instance configured for success migration folder
    Couchmove couchmove = new Couchmove(getBucket(), DB_MIGRATION + "success");

    // When we launch migration
    couchmove.migrate();

    // Then all changeLogs should be inserted in DB
    List<ChangeLog> changeLogs = Stream.of("1", "1.1", "2")
            .map(version -> PREFIX_ID + version)
            .map(changeLogRepository::findOne)
            .collect(Collectors.toList());

    assertEquals(3, changeLogs.size());
    assertLike(changeLogs.get(0),
            "1", 1, "create index", N1QL, "V1__create_index.n1ql",
            "1a417b9f5787e52a46bc65bcd801e8f3f096e63ebcf4b0a17410b16458124af3",
            EXECUTED);
    assertLike(changeLogs.get(1),
            "1.1", 2, "insert users", DOCUMENTS, "V1.1__insert_users",
            "99a4aaf12e7505286afe2a5b074f7ebabd496f3ea8c4093116efd3d096c430a8",
            EXECUTED);
    assertLike(changeLogs.get(2),
            "2", 3, "user", Type.DESIGN_DOC, "V2__user.json",
            "22df7f8496c21a3e1f3fbd241592628ad6a07797ea5d501df8ab6c65c94dbb79",
            EXECUTED);

    // And successfully executed

    // Users inserted
    assertEquals(new User("user", "titi", "01/09/1998"), userRepository.findOne("user::titi"));
    assertEquals(new User("user", "toto", "10/01/1991"), userRepository.findOne("user::toto"));

    // Index inserted
    Optional<IndexInfo> userIndexInfo = getBucket().bucketManager().listN1qlIndexes().stream()
            .filter(i -> i.name().equals("user_index"))
            .findFirst();
    assertTrue(userIndexInfo.isPresent());
    assertEquals("`username`", userIndexInfo.get().indexKey().get(0));

    // Design Document inserted
    DesignDocument designDocument = getBucket().bucketManager().getDesignDocument("user");
    assertNotNull(designDocument);
}
 
开发者ID:differentway,项目名称:couchmove,代码行数:46,代码来源:CouchmoveIntegrationTest.java


示例11: testRepository

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Test
public void testRepository() {
	List<DesignDocument> designDocuments = bucket.bucketManager().getDesignDocuments();
	Assert.assertNotNull(designDocuments);
}
 
开发者ID:ldoguin,项目名称:testcontainers-spring-boot-couchbase,代码行数:6,代码来源:TestcontainerSpringBootCouchbaseApplicationTests.java


示例12: eval

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {

    final CouchbaseClusterManager cmm = CouchbaseClusterManager.getInstance();

    // Get connection details
    final String clusterId = args[0].itemAt(0).getStringValue();

    // Get reference to cluster
    final CouchbaseCluster cluster = cmm.validate(clusterId);

    // Retrieve other parameters             
    final String bucketName = (args[1].isEmpty()) ? Constants.DEFAULT_BUCKET : args[1].itemAt(0).getStringValue();
    final String bucketPassword = cmm.getBucketPassword(clusterId);


    try {
        // Get access to bucketmanager
        final BucketManager bucketManager = cluster.openBucket(bucketName, bucketPassword).bucketManager();

        // Retrieve all design documents
        final java.util.List<DesignDocument> designDocuments = bucketManager.getDesignDocuments();

        if (designDocuments.isEmpty()) {
            // No values ....
            return Sequence.EMPTY_SEQUENCE;

        } else {

            // Report all documents names
            final Sequence retVal = new ValueSequence();
            for (final DesignDocument doc : designDocuments) {
                retVal.add(new StringValue(doc.name()));
            }
            return retVal;
        }


    } catch (final Throwable ex) {
        return GenericExceptionHandler.handleException(this, ex);
    }

}
 
开发者ID:weXsol,项目名称:Couchbase,代码行数:44,代码来源:ListDesignDocuments.java


示例13: eval

import com.couchbase.client.java.view.DesignDocument; //导入依赖的package包/类
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {

    final CouchbaseClusterManager cmm = CouchbaseClusterManager.getInstance();

    // Get connection details
    final String clusterId = args[0].itemAt(0).getStringValue();

    // Get reference to cluster
    final CouchbaseCluster cluster = cmm.validate(clusterId);

    // Retrieve other parameters             
    final String bucketName = (args[1].isEmpty()) ? Constants.DEFAULT_BUCKET : args[1].itemAt(0).getStringValue();
    final String designName = args[2].itemAt(0).getStringValue();

    final String bucketPassword = cmm.getBucketPassword(clusterId);

    try {
        // Get access to bucketmanager
        final BucketManager bucketManager = cluster.openBucket(bucketName, bucketPassword).bucketManager();

        // Convert to JSonObject
        final JsonObject jsonObject = (JsonObject) MapToJson.convert(args[3]);

        // Convert JSON to design document
        final DesignDocument input = DesignDocument.from(designName, jsonObject);

        // Retrieve all design documents
        final DesignDocument designDocument = (isCalledAs("upsert-design-document"))
                ? bucketManager.upsertDesignDocument(input)
                : bucketManager.insertDesignDocument(input);

        if (designDocument == null) {
            return Sequence.EMPTY_SEQUENCE;
        } else {
            return JsonToMap.convert(designDocument.toJsonObject(), context);
        }

    } catch (final Throwable ex) {
        return GenericExceptionHandler.handleException(this, ex);
    }

}
 
开发者ID:weXsol,项目名称:Couchbase,代码行数:44,代码来源:InsertUpsertDesignDocument.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ManagedAttribute类代码示例发布时间:2022-05-23
下一篇:
Java ModelExtent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap