Skip to content

Commit b3ea4b1

Browse files
authored
Merge pull request #427 from kolea2/repo-migration
feat: migrate google-cloud-datastore/java into java-datastore
2 parents 586709b + a655613 commit b3ea4b1

24 files changed

+4094
-1
lines changed

datastore-v1-proto-client/pom.xml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (C) 2015 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
use this file except in compliance with the License. You may obtain a copy of
7+
the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
License for the specific language governing permissions and limitations under
15+
the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
18+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<groupId>com.google.cloud.datastore</groupId>
21+
<artifactId>datastore-v1-proto-client</artifactId>
22+
<version>1.6.4-SNAPSHOT</version><!-- {x-version-update:datastore-v1-proto-client:current} -->
23+
24+
<parent>
25+
<groupId>com.google.cloud</groupId>
26+
<artifactId>google-cloud-datastore-parent</artifactId>
27+
<version>1.106.5-SNAPSHOT</version><!-- {x-version-update:google-cloud-datastore-parent:current} -->
28+
</parent>
29+
30+
<packaging>jar</packaging>
31+
<description>
32+
Low level client for accessing Google Cloud Datastore v1.
33+
</description>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>com.google.api.grpc</groupId>
38+
<artifactId>proto-google-cloud-datastore-v1</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>com.google.http-client</groupId>
43+
<artifactId>google-http-client</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>com.google.http-client</groupId>
48+
<artifactId>google-http-client-protobuf</artifactId>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>com.google.http-client</groupId>
53+
<artifactId>google-http-client-jackson2</artifactId>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>com.google.oauth-client</groupId>
58+
<artifactId>google-oauth-client</artifactId>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>com.google.api-client</groupId>
63+
<artifactId>google-api-client</artifactId>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>com.google.guava</groupId>
68+
<artifactId>guava</artifactId>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>com.google.code.findbugs</groupId>
73+
<artifactId>jsr305</artifactId>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>com.google.api.grpc</groupId>
78+
<artifactId>proto-google-common-protos</artifactId>
79+
</dependency>
80+
81+
<dependency>
82+
<groupId>com.google.protobuf</groupId>
83+
<artifactId>protobuf-java</artifactId>
84+
</dependency>
85+
86+
<!-- Test dependencies. -->
87+
<dependency>
88+
<groupId>junit</groupId>
89+
<artifactId>junit</artifactId>
90+
<scope>test</scope>
91+
</dependency>
92+
93+
<dependency>
94+
<groupId>com.google.truth</groupId>
95+
<artifactId>truth</artifactId>
96+
<version>1.1.2</version>
97+
<scope>test</scope>
98+
</dependency>
99+
</dependencies>
100+
101+
<build>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-surefire-plugin</artifactId>
106+
<version>3.0.0-M5</version>
107+
<configuration>
108+
<!-- Excludes integration tests and smoke tests when unit tests are run -->
109+
<excludes>
110+
<exclude>**/*SmokeTest.java</exclude>
111+
<exclude>**/IT*.java</exclude>
112+
</excludes>
113+
<reportNameSuffix>sponge_log</reportNameSuffix>
114+
<argLine>-Xmx2048m</argLine>
115+
</configuration>
116+
<dependencies>
117+
<dependency>
118+
<groupId>org.apache.maven.surefire</groupId>
119+
<artifactId>surefire-junit47</artifactId>
120+
<version>3.0.0-M5</version>
121+
</dependency>
122+
</dependencies>
123+
</plugin>
124+
</plugins>
125+
</build>
126+
</project>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.datastore.v1.client;
17+
18+
import com.google.api.client.http.HttpResponse;
19+
import com.google.common.annotations.VisibleForTesting;
20+
import java.io.IOException;
21+
import java.io.InputStream;
22+
import java.security.MessageDigest;
23+
24+
/** This class provides End-to-End Checksum API for http protocol. */
25+
class ChecksumEnforcingInputStream extends InputStream {
26+
private final InputStream delegate;
27+
private final MessageDigest messageDigest;
28+
private final String expectedChecksum;
29+
30+
ChecksumEnforcingInputStream(
31+
InputStream originalInputStream, HttpResponse response, MessageDigest digest) {
32+
this(originalInputStream, EndToEndChecksumHandler.getChecksumHeader(response), digest);
33+
}
34+
35+
@VisibleForTesting
36+
ChecksumEnforcingInputStream(
37+
InputStream originalInputStream, String checksum, MessageDigest digest) {
38+
delegate = originalInputStream;
39+
expectedChecksum = checksum;
40+
messageDigest = digest;
41+
}
42+
43+
@Override
44+
public int available() throws IOException {
45+
return delegate.available();
46+
}
47+
48+
@Override
49+
public void close() throws IOException {
50+
delegate.close();
51+
}
52+
53+
@Override
54+
public void mark(int readlimit) {
55+
throw new RuntimeException("mark(int) Not Supported");
56+
}
57+
58+
@Override
59+
public boolean markSupported() {
60+
// This class doesn't support mark, reset methods!
61+
return false;
62+
}
63+
64+
@Override
65+
public int read() throws IOException {
66+
throw new RuntimeException("read() Not Supported");
67+
}
68+
69+
@Override
70+
public int read(byte[] b) throws IOException {
71+
throw new RuntimeException("read(byte[]) Not Supported");
72+
}
73+
74+
@Override
75+
public int read(byte[] b, int off, int len) throws IOException {
76+
if (len <= 0) return 0;
77+
int i = delegate.read(b, off, len);
78+
if (i > 0) {
79+
messageDigest.update(b, off, i);
80+
} else {
81+
// no more payload to read. compute checksum and verify
82+
if (!expectedChecksum.equalsIgnoreCase(
83+
com.google.common.io.BaseEncoding.base16().encode(messageDigest.digest()))) {
84+
throw new IOException("possible memory corruption on payload detected");
85+
}
86+
}
87+
return i;
88+
}
89+
90+
@Override
91+
public void reset() throws IOException {
92+
throw new RuntimeException("reset() Not Supported");
93+
}
94+
95+
@Override
96+
public long skip(long n) throws IOException {
97+
if (n <= 0) return 0;
98+
// TODO: handle the case of n > Integer.MAX_VALUE ( that is, n > (2GB - 1). It is highly
99+
// unlikely that callers will want to skip that many bytes. That is the entire payload
100+
if (n > Integer.MAX_VALUE) {
101+
throw new IOException("can't skip more than Integer.MAX bytes");
102+
}
103+
int intSkip = (int) n;
104+
byte[] b = new byte[intSkip];
105+
return read(b, 0, intSkip);
106+
}
107+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.datastore.v1.client;
17+
18+
import com.google.datastore.v1.AllocateIdsRequest;
19+
import com.google.datastore.v1.AllocateIdsResponse;
20+
import com.google.datastore.v1.BeginTransactionRequest;
21+
import com.google.datastore.v1.BeginTransactionResponse;
22+
import com.google.datastore.v1.CommitRequest;
23+
import com.google.datastore.v1.CommitResponse;
24+
import com.google.datastore.v1.LookupRequest;
25+
import com.google.datastore.v1.LookupResponse;
26+
import com.google.datastore.v1.ReserveIdsRequest;
27+
import com.google.datastore.v1.ReserveIdsResponse;
28+
import com.google.datastore.v1.RollbackRequest;
29+
import com.google.datastore.v1.RollbackResponse;
30+
import com.google.datastore.v1.RunQueryRequest;
31+
import com.google.datastore.v1.RunQueryResponse;
32+
import com.google.rpc.Code;
33+
import java.io.IOException;
34+
import java.io.InputStream;
35+
36+
/**
37+
* Provides access to Cloud Datastore.
38+
*
39+
* <p>This class is thread-safe.
40+
*/
41+
public class Datastore {
42+
43+
final RemoteRpc remoteRpc;
44+
45+
Datastore(RemoteRpc remoteRpc) {
46+
this.remoteRpc = remoteRpc;
47+
}
48+
49+
/** Reset the RPC count. */
50+
public void resetRpcCount() {
51+
remoteRpc.resetRpcCount();
52+
}
53+
54+
/**
55+
* Returns the number of RPC calls made since the client was created or {@link #resetRpcCount} was
56+
* called.
57+
*/
58+
public int getRpcCount() {
59+
return remoteRpc.getRpcCount();
60+
}
61+
62+
private DatastoreException invalidResponseException(String method, IOException exception) {
63+
return RemoteRpc.makeException(
64+
remoteRpc.getUrl(), method, Code.UNAVAILABLE, "Invalid response", exception);
65+
}
66+
67+
public AllocateIdsResponse allocateIds(AllocateIdsRequest request) throws DatastoreException {
68+
try (InputStream is = remoteRpc.call("allocateIds", request)) {
69+
return AllocateIdsResponse.parseFrom(is);
70+
} catch (IOException exception) {
71+
throw invalidResponseException("allocateIds", exception);
72+
}
73+
}
74+
75+
public BeginTransactionResponse beginTransaction(BeginTransactionRequest request)
76+
throws DatastoreException {
77+
try (InputStream is = remoteRpc.call("beginTransaction", request)) {
78+
return BeginTransactionResponse.parseFrom(is);
79+
} catch (IOException exception) {
80+
throw invalidResponseException("beginTransaction", exception);
81+
}
82+
}
83+
84+
public CommitResponse commit(CommitRequest request) throws DatastoreException {
85+
try (InputStream is = remoteRpc.call("commit", request)) {
86+
return CommitResponse.parseFrom(is);
87+
} catch (IOException exception) {
88+
throw invalidResponseException("commit", exception);
89+
}
90+
}
91+
92+
public LookupResponse lookup(LookupRequest request) throws DatastoreException {
93+
try (InputStream is = remoteRpc.call("lookup", request)) {
94+
return LookupResponse.parseFrom(is);
95+
} catch (IOException exception) {
96+
throw invalidResponseException("lookup", exception);
97+
}
98+
}
99+
100+
public ReserveIdsResponse reserveIds(ReserveIdsRequest request) throws DatastoreException {
101+
try (InputStream is = remoteRpc.call("reserveIds", request)) {
102+
return ReserveIdsResponse.parseFrom(is);
103+
} catch (IOException exception) {
104+
throw invalidResponseException("reserveIds", exception);
105+
}
106+
}
107+
108+
public RollbackResponse rollback(RollbackRequest request) throws DatastoreException {
109+
try (InputStream is = remoteRpc.call("rollback", request)) {
110+
return RollbackResponse.parseFrom(is);
111+
} catch (IOException exception) {
112+
throw invalidResponseException("rollback", exception);
113+
}
114+
}
115+
116+
public RunQueryResponse runQuery(RunQueryRequest request) throws DatastoreException {
117+
try (InputStream is = remoteRpc.call("runQuery", request)) {
118+
return RunQueryResponse.parseFrom(is);
119+
} catch (IOException exception) {
120+
throw invalidResponseException("runQuery", exception);
121+
}
122+
}
123+
}

0 commit comments

Comments
 (0)