本文整理汇总了Java中com.google.cloud.datastore.DatastoreOptions类的典型用法代码示例。如果您正苦于以下问题:Java DatastoreOptions类的具体用法?Java DatastoreOptions怎么用?Java DatastoreOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DatastoreOptions类属于com.google.cloud.datastore包,在下文中一共展示了DatastoreOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
}
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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;
}
示例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());
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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;
}