@Override public AllocateIdsResponse allocateIds(AllocateIdsRequest request) { try { return client.allocateIds(request); } catch (com.google.datastore.v1.client.DatastoreException ex) { throw translate(ex); } }
@Override public RollbackResponse rollback(RollbackRequest request) { try { return client.rollback(request); } catch (com.google.datastore.v1.client.DatastoreException ex) { throw translate(ex); } }
@Override public LookupResponse lookup(LookupRequest request) { try { return client.lookup(request); } catch (com.google.datastore.v1.client.DatastoreException ex) { throw translate(ex); } }
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()); }
DatastoreOptions.Builder options = new DatastoreOptions.Builder(); Credential credential = GoogleCredential.getApplicationDefault(); if (serviceAccountEmail != null && privateKeyFile != null) { credential = DatastoreHelper.getServiceAccountCredential( serviceAccountEmail, privateKeyFile); logger.info("Using JWT Service Account credential."); datastore = DatastoreFactory.get().create( options.credential(credential).projectId(datasetId).build());
/** * @see #getOptionsFromEnv() */ public static Datastore getDatastoreFromEnv() throws GeneralSecurityException, IOException { return DatastoreFactory.get().create(getOptionsFromEnv().build()); }
datastore.commit(commitRequest.build()); logger.debug("successfully committed."); exception.getMessage(), exception.getMethodName(), exception.getCode())); return new Status("ERROR-" + exception.getCode(), exception.getMessage());
response = datastore.lookup(lookupRequest.build()); exception.getMessage(), exception.getMethodName(), exception.getCode())); return new Status("ERROR-" + exception.getCode(), exception.getMessage());
private static DatastoreException translate( com.google.datastore.v1.client.DatastoreException exception, boolean idempotent) { String reason = ""; if (exception.getCode() != null) { reason = exception.getCode().name(); } if (reason.isEmpty()) { if (exception.getCause() instanceof IOException) { return new DatastoreException((IOException) exception.getCause()); } } return new DatastoreException( exception.getCode().getNumber(), exception.getMessage(), reason, idempotent, exception); }
@Override public RunQueryResponse runQuery(RunQueryRequest request) { try { return client.runQuery(request); } catch (com.google.datastore.v1.client.DatastoreException ex) { throw translate(ex); } } }
@Override public CommitResponse commit(CommitRequest request) { try { return client.commit(request); } catch (com.google.datastore.v1.client.DatastoreException ex) { throw translate(ex, request.getMode() == CommitRequest.Mode.NON_TRANSACTIONAL); } }
public DatastoreEmulator create( DatastoreOptions options, DatastoreEmulatorOptions localDevelopmentOptions) { RemoteRpc rpc = newRemoteRpc(options); return new DatastoreEmulator(rpc, options.getLocalHost(), localDevelopmentOptions); } }
/** * 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)); }
@Override public DatastoreEmulator create(DatastoreOptions options) throws IllegalArgumentException { return create(options, new DatastoreEmulatorOptions.Builder().build()); }
protected RemoteRpc newRemoteRpc(DatastoreOptions options) { checkNotNull(options); HttpRequestFactory client = makeClient(options); return new RemoteRpc(client, options.getInitializer(), buildProjectEndpoint(options)); }
@Override public BeginTransactionResponse beginTransaction(BeginTransactionRequest request) { try { return client.beginTransaction(request); } catch (com.google.datastore.v1.client.DatastoreException ex) { throw translate(ex); } }
/** * @see #getOptionsFromEnv() */ public static Datastore getDatastoreFromEnv() throws GeneralSecurityException, IOException { return DatastoreFactory.get().create(getOptionsFromEnv().build()); }
public DatastoreEmulator create( DatastoreOptions options, DatastoreEmulatorOptions localDevelopmentOptions) { RemoteRpc rpc = newRemoteRpc(options); return new DatastoreEmulator(rpc, options.getLocalHost(), localDevelopmentOptions); } }
/** * 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)); }
@Override public DatastoreEmulator create(DatastoreOptions options) throws IllegalArgumentException { return create(options, new DatastoreEmulatorOptions.Builder().build()); }