Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
20dc759
Initial commit
May 14, 2013
ce63aab
v1beta1-rev2-1.0.1
eddavisson Aug 7, 2013
45831c2
v1beta2-rev1-2.0.0
eddavisson Sep 24, 2013
4c28630
python: fix #23
proppy Oct 2, 2013
118b49d
v1beta2-rev1-2.1.0
eddavisson Dec 16, 2013
49a43b9
changed class usage in comment to match code
bmenasha May 5, 2015
f4f606f
Corrects error message on exceptions
skim1420 May 26, 2015
229dc4c
v1beta2-rev1-3.0.0
eddavisson Aug 31, 2015
3a74434
v1beta2-rev1-3.0.1
eddavisson Sep 11, 2015
35cdd30
Fix bug in LocalDevelopmentDatastore
PieterDM Sep 23, 2015
34bfe3c
Update to v1beta3.
pcostell Mar 29, 2016
4dbc919
Merge remote-tracking branch 'github/master' into v1beta3
pcostell Mar 29, 2016
6b53466
Update RemoteRpc to use correct version of proto library.
pcostell Mar 30, 2016
17d14c7
Add a helper for ancestor filters.
pcostell Apr 6, 2016
a4a4247
Remove log that credentials aren't provided.
Apr 7, 2016
1bfd8bb
Datastore.java closes InputStreams
eddavisson Apr 7, 2016
54cc831
Do all URL validation in DatastoreFactory
eddavisson May 9, 2016
a315247
s/prom-qa/localhost:1234/
eddavisson May 9, 2016
29249d4
Update to use the v1 API
eddavisson Aug 15, 2016
aef3e35
Remove 'datatore' from path and prepare for release (#135)
eddavisson Aug 17, 2016
e1c8dc8
Rename Java testing harness
eddavisson Sep 13, 2016
8d62ff4
Update test harnesses to use the emulator.
eddavisson Sep 12, 2016
c77c3cd
Add a host() option to DatastoreOptions
eddavisson Jan 10, 2017
6f1ffea
Sync from CL 170707635.
wsh Oct 10, 2017
3caba37
Remove V1 ID reservation flag guarding in low-level Java proto client…
wsh Oct 12, 2017
b48b091
🚑 fix http connection leak on Datastore errors
cmaan Oct 25, 2017
cff0e2e
Also use GzipFixingInputStream for error response content.
eddavisson Dec 14, 2017
09ce8df
Cache project ID information retrieved from Compute Engine.
wsh Jan 2, 2018
3f6b85f
update to jackson2
elharo Oct 29, 2019
058ca50
fix assorted warnings
elharo Oct 29, 2019
42bca4c
Merge pull request #238 from elharo/warnings
elharo Oct 30, 2019
f2aa3dd
update http client (#239)
elharo Nov 1, 2019
f55449c
feat: add optional end-to-end checksum support for http 1.1 requests …
vnorigoog Mar 30, 2021
449ea88
delete .gitignore
kolea2 May 14, 2021
5aa175e
move pom
kolea2 May 14, 2021
9f115b7
move pom
kolea2 May 14, 2021
b9af31f
Merge remote-tracking branch 'dpe/master' into repo-migration
kolea2 May 14, 2021
62411b9
add module, run formatter, fix any failing builds
kolea2 May 14, 2021
5fd6621
have dependencies use snapshot version
kolea2 May 17, 2021
156e3df
close input stream after each run
kolea2 May 17, 2021
32ee220
use try with resources
kolea2 May 17, 2021
756784b
use try with resources
kolea2 May 17, 2021
320dc12
add test config
kolea2 May 17, 2021
a655613
adjust xmx value
kolea2 May 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions datastore-v1-proto-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1-proto-client</artifactId>
<version>1.6.4-SNAPSHOT</version><!-- {x-version-update:datastore-v1-proto-client:current} -->

<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-datastore-parent</artifactId>
<version>1.106.5-SNAPSHOT</version><!-- {x-version-update:google-cloud-datastore-parent:current} -->
</parent>

<packaging>jar</packaging>
<description>
Low level client for accessing Google Cloud Datastore v1.
</description>

<dependencies>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-datastore-v1</artifactId>
</dependency>

<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
</dependency>

<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-protobuf</artifactId>
</dependency>

<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
</dependency>

<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client</artifactId>
</dependency>

<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>

<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>

<!-- Test dependencies. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!-- Excludes integration tests and smoke tests when unit tests are run -->
<excludes>
<exclude>**/*SmokeTest.java</exclude>
<exclude>**/IT*.java</exclude>
</excludes>
<reportNameSuffix>sponge_log</reportNameSuffix>
<argLine>-Xmx2048m</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.datastore.v1.client;

import com.google.api.client.http.HttpResponse;
import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;

/** This class provides End-to-End Checksum API for http protocol. */
class ChecksumEnforcingInputStream extends InputStream {
private final InputStream delegate;
private final MessageDigest messageDigest;
private final String expectedChecksum;

ChecksumEnforcingInputStream(
InputStream originalInputStream, HttpResponse response, MessageDigest digest) {
this(originalInputStream, EndToEndChecksumHandler.getChecksumHeader(response), digest);
}

@VisibleForTesting
ChecksumEnforcingInputStream(
InputStream originalInputStream, String checksum, MessageDigest digest) {
delegate = originalInputStream;
expectedChecksum = checksum;
messageDigest = digest;
}

@Override
public int available() throws IOException {
return delegate.available();
}

@Override
public void close() throws IOException {
delegate.close();
}

@Override
public void mark(int readlimit) {
throw new RuntimeException("mark(int) Not Supported");
}

@Override
public boolean markSupported() {
// This class doesn't support mark, reset methods!
return false;
}

@Override
public int read() throws IOException {
throw new RuntimeException("read() Not Supported");
}

@Override
public int read(byte[] b) throws IOException {
throw new RuntimeException("read(byte[]) Not Supported");
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
if (len <= 0) return 0;
int i = delegate.read(b, off, len);
if (i > 0) {
messageDigest.update(b, off, i);
} else {
// no more payload to read. compute checksum and verify
if (!expectedChecksum.equalsIgnoreCase(
com.google.common.io.BaseEncoding.base16().encode(messageDigest.digest()))) {
throw new IOException("possible memory corruption on payload detected");
}
}
return i;
}

@Override
public void reset() throws IOException {
throw new RuntimeException("reset() Not Supported");
}

@Override
public long skip(long n) throws IOException {
if (n <= 0) return 0;
// TODO: handle the case of n > Integer.MAX_VALUE ( that is, n > (2GB - 1). It is highly
// unlikely that callers will want to skip that many bytes. That is the entire payload
if (n > Integer.MAX_VALUE) {
throw new IOException("can't skip more than Integer.MAX bytes");
}
int intSkip = (int) n;
byte[] b = new byte[intSkip];
return read(b, 0, intSkip);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.datastore.v1.client;

import com.google.datastore.v1.AllocateIdsRequest;
import com.google.datastore.v1.AllocateIdsResponse;
import com.google.datastore.v1.BeginTransactionRequest;
import com.google.datastore.v1.BeginTransactionResponse;
import com.google.datastore.v1.CommitRequest;
import com.google.datastore.v1.CommitResponse;
import com.google.datastore.v1.LookupRequest;
import com.google.datastore.v1.LookupResponse;
import com.google.datastore.v1.ReserveIdsRequest;
import com.google.datastore.v1.ReserveIdsResponse;
import com.google.datastore.v1.RollbackRequest;
import com.google.datastore.v1.RollbackResponse;
import com.google.datastore.v1.RunQueryRequest;
import com.google.datastore.v1.RunQueryResponse;
import com.google.rpc.Code;
import java.io.IOException;
import java.io.InputStream;

/**
* Provides access to Cloud Datastore.
*
* <p>This class is thread-safe.
*/
public class Datastore {

final RemoteRpc remoteRpc;

Datastore(RemoteRpc remoteRpc) {
this.remoteRpc = remoteRpc;
}

/** Reset the RPC count. */
public void resetRpcCount() {
remoteRpc.resetRpcCount();
}

/**
* Returns the number of RPC calls made since the client was created or {@link #resetRpcCount} was
* called.
*/
public int getRpcCount() {
return remoteRpc.getRpcCount();
}

private DatastoreException invalidResponseException(String method, IOException exception) {
return RemoteRpc.makeException(
remoteRpc.getUrl(), method, Code.UNAVAILABLE, "Invalid response", exception);
}

public AllocateIdsResponse allocateIds(AllocateIdsRequest request) throws DatastoreException {
try (InputStream is = remoteRpc.call("allocateIds", request)) {
return AllocateIdsResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("allocateIds", exception);
}
}

public BeginTransactionResponse beginTransaction(BeginTransactionRequest request)
throws DatastoreException {
try (InputStream is = remoteRpc.call("beginTransaction", request)) {
return BeginTransactionResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("beginTransaction", exception);
}
}

public CommitResponse commit(CommitRequest request) throws DatastoreException {
try (InputStream is = remoteRpc.call("commit", request)) {
return CommitResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("commit", exception);
}
}

public LookupResponse lookup(LookupRequest request) throws DatastoreException {
try (InputStream is = remoteRpc.call("lookup", request)) {
return LookupResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("lookup", exception);
}
}

public ReserveIdsResponse reserveIds(ReserveIdsRequest request) throws DatastoreException {
try (InputStream is = remoteRpc.call("reserveIds", request)) {
return ReserveIdsResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("reserveIds", exception);
}
}

public RollbackResponse rollback(RollbackRequest request) throws DatastoreException {
try (InputStream is = remoteRpc.call("rollback", request)) {
return RollbackResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("rollback", exception);
}
}

public RunQueryResponse runQuery(RunQueryRequest request) throws DatastoreException {
try (InputStream is = remoteRpc.call("runQuery", request)) {
return RunQueryResponse.parseFrom(is);
} catch (IOException exception) {
throw invalidResponseException("runQuery", exception);
}
}
}
Loading