Skip to content

Commit 9ae82d5

Browse files
committed
---
yaml --- r: 25 b: refs/heads/master c: aa237dc h: refs/heads/master i: 23: 756fa2e v: v3
1 parent e72ec31 commit 9ae82d5

19 files changed

Lines changed: 434 additions & 257 deletions

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 65a9f121fbe37a34b1f855e4505853dba26d7a1d
2+
refs/heads/master: aa237dcf201e5865535d68689092cb6e6b220326
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.google.gcloud.datastore;
2+
3+
import java.io.Serializable;
4+
5+
public abstract class BatchWriteOption implements Serializable {
6+
7+
private static final long serialVersionUID = -3932758377282659839L;
8+
9+
BatchWriteOption() {
10+
// package protected
11+
}
12+
13+
public static final class ForceWrites extends BatchWriteOption {
14+
15+
private static final long serialVersionUID = 2555054296046232799L;
16+
17+
private final boolean force;
18+
19+
public ForceWrites(boolean force) {
20+
this.force = force;
21+
}
22+
23+
public boolean isForce() {
24+
return force;
25+
}
26+
}
27+
28+
public static ForceWrites forceWrites() {
29+
return new ForceWrites(true);
30+
}
31+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.google.gcloud.datastore;
2+
3+
public interface BatchWriter extends DatastoreWriter {
4+
5+
void submit();
6+
}

trunk/src/main/java/com/google/gcloud/datastore/DatastoreService.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,48 @@
44

55
public interface DatastoreService extends DatastoreReader, DatastoreWriter {
66

7-
interface Query {
8-
// TODO
9-
// consider 2 types of queries regualr and Gql
7+
enum QueryType {
8+
PROJECTION,
9+
FULL;
1010
}
1111

12+
/*
13+
interface QueryResult<T> {
1214
13-
public interface Transaction extends DatastoreReader, DatastoreWriter {
14-
15-
void commit();
16-
17-
void rollback();
1815
}
1916
20-
public interface TransactionOptions {
21-
22-
enum IsolationLevel {
23-
SERIALIZABLE, SNAPSHOT;
24-
}
25-
26-
27-
IsolationLevel getIsolationLevel();
28-
29-
boolean force();
30-
}
31-
32-
public interface BatchWriter extends DatastoreWriter {
33-
34-
void submit();
17+
// consider 2 types of queries regualr and Gql
18+
interface Query {
19+
QueryResult<T> keysOnly(QueryType query);
3520
}
21+
*/
3622

37-
public interface BatchOptions {
38-
}
3923

4024
DatastoreServiceOptions getOptions();
4125

42-
Transaction newTransaction(TransactionOptions transactionOptions);
43-
44-
BatchWriter newBatchWriter(BatchOptions batchOptions);
45-
46-
Key allocateId(IncompleteKey key);
47-
26+
KeyBuilder newKeyBuilder(String kind);
27+
28+
/**
29+
* Returns a new Datastore transaction.
30+
*
31+
* @throws DatastoreServiceExcepiton upon failure
32+
*/
33+
Transaction newTransaction(TransactionOption... transactionOption);
34+
35+
BatchWriter newBatchWriter(BatchWriteOption... batchWriteOption);
36+
37+
/**
38+
* Returns a key with a newly allocated id.
39+
*
40+
* @throws DatastoreServiceExcepiton upon failure
41+
*/
42+
Key allocateId(PartialKey key);
43+
44+
/**
45+
* Returns a list of keys using the allocated ids ordered by the input.
46+
*
47+
* @throws DatastoreServiceExcepiton upon failure
48+
*/
4849
// results are returned using request order
49-
Iterator<Key> allocateIds(IncompleteKey... key);
50+
Iterator<Key> allocateIds(PartialKey... key);
5051
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.google.gcloud.datastore;
2+
3+
public class DatastoreServiceException extends RuntimeException {
4+
5+
private static final long serialVersionUID = 8170357898917041899L;
6+
7+
private final boolean isTransient;
8+
9+
public DatastoreServiceException(boolean isTransient, String msg, Exception cause) {
10+
super(msg, cause);
11+
this.isTransient = isTransient;
12+
}
13+
14+
/**
15+
* @return {@code true} if this exception is transient and could be safely retried.
16+
*/
17+
public boolean isTransient() {
18+
return isTransient;
19+
}
20+
}

trunk/src/main/java/com/google/gcloud/datastore/DatastoreServiceImpl.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ public DatastoreServiceOptions getOptions() {
1717
}
1818

1919
@Override
20-
public Transaction newTransaction(TransactionOptions transactionOptions) {
20+
public Transaction newTransaction(TransactionOption... transactionOption) {
2121
// TODO Auto-generated method stub
2222
return null;
2323
}
2424

2525
@Override
26-
public BatchWriter newBatchWriter(BatchOptions batchOptions) {
26+
public BatchWriter newBatchWriter(BatchWriteOption... batchWriteOption) {
2727
// TODO Auto-generated method stub
2828
return null;
2929
}
3030

3131
@Override
32-
public Key allocateId(IncompleteKey key) {
32+
public Key allocateId(PartialKey key) {
3333
// TODO Auto-generated method stub
3434
return null;
3535
}
3636

3737
@Override
38-
public Iterator<Key> allocateIds(IncompleteKey... key) {
38+
public Iterator<Key> allocateIds(PartialKey... key) {
3939
// TODO Auto-generated method stub
4040
return null;
4141
}
@@ -75,4 +75,9 @@ public void delete(Key... key) {
7575
// TODO Auto-generated method stub
7676

7777
}
78+
79+
@Override
80+
public KeyBuilder newKeyBuilder(String kind) {
81+
return new KeyBuilder(kind, options.getDefaultNamespace(), kind);
82+
}
7883
}

trunk/src/main/java/com/google/gcloud/datastore/DatastoreServiceOptions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.google.common.collect.ImmutableSet;
88
import com.google.gcloud.ServiceOptions;
99

10+
import java.lang.reflect.Method;
1011
import java.util.Set;
1112
import java.util.regex.Pattern;
1213

@@ -72,6 +73,18 @@ public String getDataset() {
7273
return dataset;
7374
}
7475

76+
public String getDefaultNamespace() {
77+
// TODO(ozarov): An alternative to reflection would be to depend on AE api jar:
78+
// http://mvnrepository.com/artifact/com.google.appengine/appengine-api-1.0-sdk/1.2.0
79+
try {
80+
Class<?> clazz = Class.forName("com.google.appengine.api.NamespaceManager");
81+
Method method = clazz.getMethod("get");
82+
return (String) method.invoke(null);
83+
} catch (Exception ex) {
84+
return "";
85+
}
86+
}
87+
7588
public boolean getForce() {
7689
return force;
7790
}

trunk/src/main/java/com/google/gcloud/datastore/EmbeddedEntityValue.java

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)