protected RemoteRpc newRemoteRpc(DatastoreOptions options) { checkNotNull(options); HttpRequestFactory client = makeClient(options); return new RemoteRpc(client, options.getInitializer(), buildProjectEndpoint(options)); }
/** * Provides access to a datastore using the provided options. Logs * into the application using the credentials available via these * options. * * @throws IllegalArgumentException if the server or credentials weren't provided. */ public Datastore create(DatastoreOptions options) throws IllegalArgumentException { return new Datastore(newRemoteRpc(options)); }
/** * Starts logging datastore method calls to the console. (Useful within tests.) */ public static void logMethodCalls() { Logger logger = Logger.getLogger(Datastore.class.getName()); logger.setLevel(Level.FINE); if (!Arrays.asList(logger.getHandlers()).contains(getStreamHandler())) { logger.addHandler(getStreamHandler()); } }
protected RemoteRpc newRemoteRpc(DatastoreOptions options) { checkNotNull(options); HttpRequestFactory client = makeClient(options); return new RemoteRpc(client, options.getInitializer(), buildProjectEndpoint(options)); }
/** * Provides access to a datastore using the provided options. Logs * into the application using the credentials available via these * options. * * @throws IllegalArgumentException if the server or credentials weren't provided. */ public Datastore create(DatastoreOptions options) throws IllegalArgumentException { return new Datastore(newRemoteRpc(options)); }
/** * Starts logging datastore method calls to the console. (Useful within tests.) */ public static void logMethodCalls() { Logger logger = Logger.getLogger(Datastore.class.getName()); logger.setLevel(Level.FINE); if (!Arrays.asList(logger.getHandlers()).contains(getStreamHandler())) { logger.addHandler(getStreamHandler()); } }
public HttpDatastoreRpc(DatastoreOptions options) { HttpTransportOptions httpTransportOptions = (HttpTransportOptions) options.getTransportOptions(); HttpTransport transport = httpTransportOptions.getHttpTransportFactory().create(); com.google.datastore.v1.client.DatastoreOptions.Builder clientBuilder = new com.google.datastore.v1.client.DatastoreOptions.Builder() .projectId(options.getProjectId()) .initializer(getHttpRequestInitializer(options, httpTransportOptions)) .transport(transport); String normalizedHost = options.getHost() != null ? options.getHost().toLowerCase() : ""; if (isLocalHost(normalizedHost)) { clientBuilder = clientBuilder.localHost(removeScheme(normalizedHost)); } else if (!removeScheme(com.google.datastore.v1.client.DatastoreFactory.DEFAULT_HOST) .equals(removeScheme(normalizedHost)) && !normalizedHost.isEmpty()) { String fullUrl = normalizedHost; if (fullUrl.charAt(fullUrl.length() - 1) != '/') { fullUrl = fullUrl + '/'; } fullUrl = fullUrl + com.google.datastore.v1.client.DatastoreFactory.VERSION + "/projects/" + options.getProjectId(); clientBuilder = clientBuilder.projectId(null).projectEndpoint(fullUrl); } client = com.google.datastore.v1.client.DatastoreFactory.get().create(clientBuilder.build()); }
/** * Builds a Cloud Datastore client for the given pipeline options, project and an optional * locahost. */ public Datastore getDatastore( PipelineOptions pipelineOptions, String projectId, @Nullable String localhost) { Credentials credential = pipelineOptions.as(GcpOptions.class).getGcpCredential(); HttpRequestInitializer initializer; if (credential != null) { initializer = new ChainingHttpRequestInitializer( new HttpCredentialsAdapter(credential), new RetryHttpRequestInitializer()); } else { initializer = new RetryHttpRequestInitializer(); } DatastoreOptions.Builder builder = new DatastoreOptions.Builder().projectId(projectId).initializer(initializer); if (localhost != null) { builder.localHost(localhost); } else { builder.host("batch-datastore.googleapis.com"); } return DatastoreFactory.get().create(builder.build()); }
public HttpDatastoreRpc(DatastoreOptions options) { HttpTransportOptions httpTransportOptions = (HttpTransportOptions) options.getTransportOptions(); HttpTransport transport = httpTransportOptions.getHttpTransportFactory().create(); com.google.datastore.v1.client.DatastoreOptions.Builder clientBuilder = new com.google.datastore.v1.client.DatastoreOptions.Builder() .projectId(options.getProjectId()) .initializer(getHttpRequestInitializer(options, httpTransportOptions)) .transport(transport); String normalizedHost = options.getHost() != null ? options.getHost().toLowerCase() : ""; if (isLocalHost(normalizedHost)) { clientBuilder = clientBuilder.localHost(removeScheme(normalizedHost)); } else if (!removeScheme(com.google.datastore.v1.client.DatastoreFactory.DEFAULT_HOST) .equals(removeScheme(normalizedHost)) && !normalizedHost.isEmpty()) { String fullUrl = normalizedHost; if (fullUrl.charAt(fullUrl.length() - 1) != '/') { fullUrl = fullUrl + '/'; } fullUrl = fullUrl + com.google.datastore.v1.client.DatastoreFactory.VERSION + "/projects/" + options.getProjectId(); clientBuilder = clientBuilder.projectId(null).projectEndpoint(fullUrl); } client = com.google.datastore.v1.client.DatastoreFactory.get().create(clientBuilder.build()); }
/** Build a new datastore client. */ static Datastore getDatastore(PipelineOptions pipelineOptions, String projectId) { Credentials credential = pipelineOptions.as(GcpOptions.class).getGcpCredential(); HttpRequestInitializer initializer; if (credential != null) { initializer = new ChainingHttpRequestInitializer( new HttpCredentialsAdapter(credential), new RetryHttpRequestInitializer()); } else { initializer = new RetryHttpRequestInitializer(); } DatastoreOptions.Builder builder = new DatastoreOptions.Builder().projectId(projectId).initializer(initializer); return DatastoreFactory.get().create(builder.build()); }