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

Java DatastoreOptions类代码示例

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

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



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

示例1: createEntityManager

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
/**
 * Creates and returns an {@link EntityManager} using the specified connection parameters.
 * 
 * @param parameters
 *          the connection parameters
 * @return a new {@link EntityManager} created using the specified connection parameters.
 * @throws EntityManagerException
 *           if any error occurs while creating the EntityManager.
 */
public EntityManager createEntityManager(ConnectionParameters parameters) {
  try {
    DatastoreOptions.Builder datastoreOptionsBuilder = DatastoreOptions.newBuilder();
    datastoreOptionsBuilder.setHost(parameters.getServiceURL());
    datastoreOptionsBuilder.setTransportOptions(getHttpTransportOptions(parameters));
    String projectId = parameters.getProjectId();
    if (!Utility.isNullOrEmpty(projectId)) {
      datastoreOptionsBuilder.setProjectId(projectId);
    }
    String namespace = parameters.getNamespace();
    if (namespace != null) {
      datastoreOptionsBuilder.setNamespace(namespace);
    }
    datastoreOptionsBuilder.setCredentials(getCredentials(parameters));
    Datastore datastore = datastoreOptionsBuilder.build().getService();
    return new DefaultEntityManager(datastore);
  } catch (Exception exp) {
    throw new EntityManagerFactoryException(exp);
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:30,代码来源:EntityManagerFactory.java


示例2: testCreateLocalEntityManager1

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateLocalEntityManager1() {
  try {
    EntityManagerFactory emf = EntityManagerFactory.getInstance();
    EntityManager em = emf.createLocalEntityManager("localhost:9999");
    DefaultEntityManager dem = (DefaultEntityManager) em;
    DatastoreOptions options = dem.getDatastore().getOptions();
    assertEquals("localhost:9999", options.getHost());
    assertNotNull(options.getProjectId());
    assertEquals("", options.getNamespace());
  } catch (EntityManagerFactoryException exp) {
    if (!TestUtils.isCI()) {
      throw exp;
    }
  }
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:17,代码来源:EntityManagerFactoryTest.java


示例3: testCreateEntityManager_ConnectionParameters3

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateEntityManager_ConnectionParameters3() {
  ConnectionParameters parameters = new ConnectionParameters();
  final String serviceURL = "http://localhost:9999";
  final String projectId = "my-project";
  final String namespace = "my-namespace";
  parameters.setServiceURL(serviceURL);
  parameters.setProjectId(projectId);
  parameters.setNamespace(namespace);
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  DefaultEntityManager em = (DefaultEntityManager) emf.createEntityManager(parameters);
  DatastoreOptions options = em.getDatastore().getOptions();
  assertEquals(serviceURL, options.getHost());
  assertNotNull(options.getProjectId());
  assertTrue(options.getProjectId().length() > 0);
  assertNotNull(options.getCredentials());
  assertEquals(projectId, options.getProjectId());
  assertEquals(namespace, options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:20,代码来源:EntityManagerFactoryTest.java


示例4: testCreateEntityManager_ConnectionParameters4

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateEntityManager_ConnectionParameters4() {
  if (TestUtils.isCI()) {
    // TODO
    return;
  }
  ConnectionParameters parameters = new ConnectionParameters();
  final String projectId = "my-project";
  final String namespace = "my-namespace";
  parameters.setProjectId(projectId);
  parameters.setNamespace(namespace);
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  DefaultEntityManager em = (DefaultEntityManager) emf.createEntityManager(parameters);
  DatastoreOptions options = em.getDatastore().getOptions();
  assertEquals(ConnectionParameters.DEFAULT_SERVICE_URL, options.getHost());
  assertNotNull(options.getProjectId());
  assertTrue(options.getProjectId().length() > 0);
  assertNotNull(options.getCredentials());
  assertEquals(projectId, options.getProjectId());
  assertEquals(namespace, options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:22,代码来源:EntityManagerFactoryTest.java


示例5: testCreateEntityManager_ConnectionParameters5

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateEntityManager_ConnectionParameters5() {
  ConnectionParameters parameters = new ConnectionParameters();
  final String projectId = "my-project";
  final String namespace = "my-namespace";
  final String credentialsFile = System.getenv(TestUtils.ENV_CREDENTIALS);
  if (Utility.isNullOrEmpty(credentialsFile)) {
    System.out.printf("Enviornment variable %s is not set, skipping the test case%n",
        TestUtils.ENV_CREDENTIALS);
    return;
  }
  parameters.setProjectId(projectId);
  parameters.setNamespace(namespace);
  parameters.setJsonCredentialsFile(credentialsFile);
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  DefaultEntityManager em = (DefaultEntityManager) emf.createEntityManager(parameters);
  DatastoreOptions options = em.getDatastore().getOptions();
  assertEquals(ConnectionParameters.DEFAULT_SERVICE_URL, options.getHost());
  assertNotNull(options.getProjectId());
  assertTrue(options.getProjectId().length() > 0);
  assertEquals(ServiceAccountCredentials.class, options.getCredentials().getClass());
  assertEquals(projectId, options.getProjectId());
  assertEquals(namespace, options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:25,代码来源:EntityManagerFactoryTest.java


示例6: testCreateEntityManager_ConnectionParameters6

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateEntityManager_ConnectionParameters6() throws FileNotFoundException {
  ConnectionParameters parameters = new ConnectionParameters();
  final String projectId = "my-project";
  final String namespace = "my-namespace";
  final String credentialsFile = System.getenv(TestUtils.ENV_CREDENTIALS);
  if (Utility.isNullOrEmpty(credentialsFile)) {
    System.out.printf("Enviornment variable %s is not set, skipping the test case%n",
        TestUtils.ENV_CREDENTIALS);
    return;
  }
  parameters.setProjectId(projectId);
  parameters.setNamespace(namespace);
  parameters.setJsonCredentialsStream(new FileInputStream(credentialsFile));
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  DefaultEntityManager em = (DefaultEntityManager) emf.createEntityManager(parameters);
  DatastoreOptions options = em.getDatastore().getOptions();
  assertEquals(ConnectionParameters.DEFAULT_SERVICE_URL, options.getHost());
  assertNotNull(options.getProjectId());
  assertTrue(options.getProjectId().length() > 0);
  assertEquals(ServiceAccountCredentials.class, options.getCredentials().getClass());
  assertEquals(projectId, options.getProjectId());
  assertEquals(namespace, options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:25,代码来源:EntityManagerFactoryTest.java


示例7: testCreateEntityManager_ConnectionParameters7

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateEntityManager_ConnectionParameters7() throws FileNotFoundException {
  ConnectionParameters parameters = new ConnectionParameters();
  final String projectId = "my-project";
  final String namespace = "my-namespace";
  final String credentialsFile = System.getenv(TestUtils.ENV_CREDENTIALS);
  if (Utility.isNullOrEmpty(credentialsFile)) {
    System.out.printf("Enviornment variable %s is not set, skipping the test case%n",
        TestUtils.ENV_CREDENTIALS);
    return;
  }
  parameters.setProjectId(projectId);
  parameters.setNamespace(namespace);
  parameters.setJsonCredentialsStream(new FileInputStream(credentialsFile));
  parameters.setJsonCredentialsFile("nonexistentfile.json");
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  DefaultEntityManager em = (DefaultEntityManager) emf.createEntityManager(parameters);
  DatastoreOptions options = em.getDatastore().getOptions();
  assertEquals(ConnectionParameters.DEFAULT_SERVICE_URL, options.getHost());
  assertNotNull(options.getProjectId());
  assertTrue(options.getProjectId().length() > 0);
  assertEquals(ServiceAccountCredentials.class, options.getCredentials().getClass());
  assertEquals(projectId, options.getProjectId());
  assertEquals(namespace, options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:26,代码来源:EntityManagerFactoryTest.java


示例8: setConfig

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Override
public void setConfig(Map<String, String> config) {
    kind = StringUtils.stripToNull(config.get("prefix"));
    if (kind == null) throw new RuntimeException("Prefix not set in config " + JacksonUtil.formattedJsonFromObject(config));

    if (datastore == null) {
        if (testDatastoreOptions != null) {
            datastore = testDatastoreOptions.getService();
        } else {
            String projectId = StringUtils.trimToNull(config.get("projectid"));
            if (projectId == null) {
                projectId = MultiValueConfigLoader.getConfig("GOOGLE-projectid");
                if (projectId == null) {
                    throw new RuntimeException("Project ID not set in RaptureGOOGLE.cfg or in config " + config);
                }
            }
            datastore = DatastoreOptions.newBuilder().setProjectId(projectId).build().getService();
        }
    }
    this.config = config;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:22,代码来源:GoogleDatastoreKeyStore.java


示例9: init

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Override
public void init(FilterConfig config) throws ServletException {
  // initialize local copy of datastore session variables

  datastore = DatastoreOptions.getDefaultInstance().getService();
  keyFactory = datastore.newKeyFactory().setKind("SessionVariable");
  // Delete all sessions unmodified for over two days
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  Query<Entity> query = Query.newEntityQueryBuilder()
      .setKind("SessionVariable")
      .setFilter(PropertyFilter.le("lastModified", dt.minusDays(2).toString(dtf)))
      .build();
  QueryResults<Entity> resultList = datastore.run(query);
  while (resultList.hasNext()) {
    Entity stateEntity = resultList.next();
    datastore.delete(stateEntity.getKey());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:19,代码来源:DatastoreSessionFilter.java


示例10: tearDownClass

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
  // Clear the datastore
  Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
  Batch batch = datastore.newBatch();
  StructuredQuery<Key> query = Query.newKeyQueryBuilder()
      .setKind("Book3").build();
  for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
    batch.delete(keys.next());
  }
  batch.submit();

  // Delete any objects in the bucket
  Storage storage = StorageOptions.getDefaultInstance().getService();
  Page<Blob> blobs = storage.list(System.getProperty("bookshelf.bucket"));
  List<BlobId> blobIds = new ArrayList<BlobId>();
  for (Blob b : blobs.iterateAll()) {
    blobIds.add(b.getBlobId());
  }
  storage.delete(blobIds);

  service.stop();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:24,代码来源:UserJourneyTestIT.java


示例11: tearDownClass

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
  // Clear the datastore if we're not using the local emulator
  if (!LOCAL_TEST) {
    Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
    Batch batch = datastore.newBatch();
    StructuredQuery<Key> query = Query.newKeyQueryBuilder()
        .setKind("Book5").build();
    for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
      batch.delete(keys.next());
    }
    batch.submit();
  }

  service.stop();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:17,代码来源:UserJourneyTestIT.java


示例12: createAndStopService

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@AfterClass
public static void createAndStopService() {
  service.stop();

  // Clear the datastore if we're not using the local emulator
  if (!LOCAL_TEST) {
    Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
    Batch batch = datastore.newBatch();
    StructuredQuery<Key> query = Query.newKeyQueryBuilder()
        .setKind("Book2").build();
    for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
      batch.delete(keys.next());
    }
    batch.submit();
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:17,代码来源:UserJourneyTestIT.java


示例13: tearDownClass

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
  // Delete any objects in the bucket
  Storage storage = StorageOptions.getDefaultInstance().getService();
  Page<Blob> blobs = storage.list(System.getProperty("bookshelf.bucket"));
  List<BlobId> blobIds = new ArrayList<BlobId>();
  for (Blob b : blobs.iterateAll()) {
    blobIds.add(b.getBlobId());
  }
  storage.delete(blobIds);

  // Clear the datastore if we're not using the local emulator
  if (!LOCAL_TEST) {
    Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
    Batch batch = datastore.newBatch();
    StructuredQuery<Key> query = Query.newKeyQueryBuilder()
        .setKind("Book3").build();
    for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
      batch.delete(keys.next());
    }
    batch.submit();
  }

  service.stop();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:26,代码来源:UserJourneyTestIT.java


示例14: tearDownClass

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@AfterClass
public static void tearDownClass() {
  // Clear the datastore if we're not using the local emulator
  if (!LOCAL_TEST) {
    Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
    Batch batch = datastore.newBatch();
    StructuredQuery<Key> query = Query.newKeyQueryBuilder()
        .setKind("Book4").build();
    for (QueryResults<Key> keys = datastore.run(query); keys.hasNext(); ) {
      batch.delete(keys.next());
    }
    batch.submit();
  }

  service.stop();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:17,代码来源:UserJourneyTestIT.java


示例15: SimpleGcloudDatastoreRepository

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
public SimpleGcloudDatastoreRepository(EntityInformation<T, ID> entityInformation,
		DatastoreOptions datastoreOptions) {

	Assert.notNull(entityInformation, "EntityInformation must not be null!");

	this.entityInformation = entityInformation;
	this.kind = entityInformation.getJavaType().getSimpleName();
	this.datastoreOptions = datastoreOptions;
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:10,代码来源:SimpleGcloudDatastoreRepository.java


示例16: createCreator

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
private GcloudDatastoreQueryCreator createCreator(Class<?> repositoryClass,
		Method method, Object... values) {

	QueryMethod queryMethod = new QueryMethod(method,
			new DefaultRepositoryMetadata(repositoryClass),
			new SpelAwareProxyProjectionFactory());
	return new GcloudDatastoreQueryCreator(
			new PartTree(method.getName(),
					queryMethod.getResultProcessor().getReturnedType()
							.getDomainType()),
			new ParametersParameterAccessor(queryMethod.getParameters(), values),
			DatastoreOptions.getDefaultInstance());
}
 
开发者ID:tkob,项目名称:spring-data-gclouddatastore,代码行数:14,代码来源:GcloudDatastoreQueryCreatorTests.java


示例17: getEntityManager

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
public static EntityManager getEntityManager() throws FileNotFoundException {
  if (isCI()) {
    return getCIEntityManager();
  }
  ConnectionParameters parameters = new ConnectionParameters();
  parameters.setServiceURL(System.getenv(ENV_SERVICE_URL));
  parameters.setProjectId(System.getenv(ENV_PROJECT_ID));
  parameters.setNamespace(System.getenv(ENV_NAMESPACE));
  String jsonCredentialsPath = System.getenv(ENV_CREDENTIALS);
  if (!Utility.isNullOrEmpty(jsonCredentialsPath)) {
    parameters.setJsonCredentialsFile(jsonCredentialsPath);
  }
  String connectionTimeout = System.getenv(ENV_CONNECTION_TIMEOUT);
  if (!Utility.isNullOrEmpty(connectionTimeout)) {
    parameters.setConnectionTimeout(Integer.parseInt(connectionTimeout));
  }
  String readTimeout = System.getenv(ENV_READ_TIMEOUT);
  if (!Utility.isNullOrEmpty(readTimeout)) {
    parameters.setReadTimeout(Integer.parseInt(readTimeout));
  }
  System.out.println(parameters);
  EntityManager em = EntityManagerFactory.getInstance().createEntityManager(parameters);
  Datastore ds = ((DefaultEntityManager) em).getDatastore();
  DatastoreOptions options = ds.getOptions();
  HttpTransportOptions httpTransportOptions = (HttpTransportOptions) options
      .getTransportOptions();
  System.out.println("***************************");
  System.out.println("DATASTORE INFORMATION");
  System.out.printf("Host: %s%n", options.getHost());
  System.out.printf("Project Id: %s%n", options.getProjectId());
  System.out.printf("Namespace: %s%n", options.getNamespace());
  System.out.printf("Credentials: %s%n", options.getCredentials());
  System.out.printf("Connection Timeout: %d%n", httpTransportOptions.getConnectTimeout());
  System.out.printf("Read Timeout: %d%n", httpTransportOptions.getReadTimeout());
  System.out.println("***************************");
  return em;

}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:39,代码来源:TestUtils.java


示例18: testCreateLocalEntityManager2

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateLocalEntityManager2() {
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  EntityManager em = emf.createLocalEntityManager("localhost:9999", "cool-project");
  DefaultEntityManager dem = (DefaultEntityManager) em;
  DatastoreOptions options = dem.getDatastore().getOptions();
  assertEquals("localhost:9999", options.getHost());
  assertEquals("cool-project", options.getProjectId());
  assertEquals("", options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:11,代码来源:EntityManagerFactoryTest.java


示例19: testCreateLocalEntityManager3

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateLocalEntityManager3() {
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  EntityManager em = emf.createLocalEntityManager("localhost:9999", "cool-project",
      "scret-namespace");
  DefaultEntityManager dem = (DefaultEntityManager) em;
  DatastoreOptions options = dem.getDatastore().getOptions();
  assertEquals("localhost:9999", options.getHost());
  assertEquals("cool-project", options.getProjectId());
  assertEquals("scret-namespace", options.getNamespace());
}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:12,代码来源:EntityManagerFactoryTest.java


示例20: testCreateEntityManager_ConnectionParameters1

import com.google.cloud.datastore.DatastoreOptions; //导入依赖的package包/类
@Test
public void testCreateEntityManager_ConnectionParameters1() {
  if (TestUtils.isCI()) {
    // TODO
    return;
  }
  ConnectionParameters parameters = new ConnectionParameters();
  EntityManagerFactory emf = EntityManagerFactory.getInstance();
  DefaultEntityManager em = (DefaultEntityManager) emf.createEntityManager(parameters);
  DatastoreOptions options = em.getDatastore().getOptions();
  assertEquals(ConnectionParameters.DEFAULT_SERVICE_URL, options.getHost());
  assertNotNull(options.getProjectId());
  assertTrue(options.getProjectId().length() > 0);

}
 
开发者ID:sai-pullabhotla,项目名称:catatumbo,代码行数:16,代码来源:EntityManagerFactoryTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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