20
20
21
21
import com .google .common .base .MoreObjects ;
22
22
import com .google .common .collect .ImmutableSet ;
23
- import com .google .common .collect .Iterables ;
24
23
import com .google .gcloud .ServiceOptions ;
25
24
import com .google .gcloud .datastore .spi .DatastoreRpc ;
26
25
import com .google .gcloud .datastore .spi .DatastoreRpcFactory ;
27
26
import com .google .gcloud .datastore .spi .DefaultDatastoreRpc ;
28
27
29
28
import java .lang .reflect .Method ;
30
- import java .util .Iterator ;
31
29
import java .util .Objects ;
32
30
import java .util .Set ;
33
31
@@ -38,7 +36,6 @@ public class DatastoreOptions extends ServiceOptions<Datastore, DatastoreRpc, Da
38
36
private static final Set <String > SCOPES = ImmutableSet .of (DATASTORE_SCOPE );
39
37
40
38
private final String namespace ;
41
- private final boolean normalizeDataset ;
42
39
43
40
public static class DefaultDatastoreFactory implements DatastoreFactory {
44
41
@@ -64,67 +61,31 @@ public static class Builder extends
64
61
ServiceOptions .Builder <Datastore , DatastoreRpc , DatastoreOptions , Builder > {
65
62
66
63
private String namespace ;
67
- private boolean normalizeDataset = true ;
68
64
69
65
private Builder () {
70
66
}
71
67
72
68
private Builder (DatastoreOptions options ) {
73
69
super (options );
74
70
namespace = options .namespace ;
75
- normalizeDataset = options .normalizeDataset ;
76
71
}
77
72
78
73
@ Override
79
74
public DatastoreOptions build () {
80
- DatastoreOptions options = new DatastoreOptions (this );
81
- return normalizeDataset ? options .normalize () : options ;
75
+ return new DatastoreOptions (this );
82
76
}
83
77
84
78
public Builder namespace (String namespace ) {
85
79
this .namespace = validateNamespace (namespace );
86
80
return this ;
87
81
}
88
-
89
- Builder normalizeDataset (boolean normalizeDataset ) {
90
- this .normalizeDataset = normalizeDataset ;
91
- return this ;
92
- }
93
82
}
94
83
95
84
private DatastoreOptions (Builder builder ) {
96
85
super (DatastoreFactory .class , DatastoreRpcFactory .class , builder );
97
- normalizeDataset = builder .normalizeDataset ;
98
86
namespace = builder .namespace != null ? builder .namespace : defaultNamespace ();
99
87
}
100
88
101
- private DatastoreOptions normalize () {
102
- if (!normalizeDataset ) {
103
- return this ;
104
- }
105
-
106
- Builder builder = toBuilder ();
107
- builder .normalizeDataset (false );
108
- // Replace provided project-id with full project-id (s~xxx, e~xxx,...)
109
- com .google .datastore .v1beta3 .LookupRequest .Builder requestPb =
110
- com .google .datastore .v1beta3 .LookupRequest .newBuilder ();
111
- com .google .datastore .v1beta3 .Key key = com .google .datastore .v1beta3 .Key .newBuilder ()
112
- .addPath (com .google .datastore .v1beta3 .Key .PathElement .newBuilder ()
113
- .setKind ("__foo__" ).setName ("bar" ))
114
- .build ();
115
- requestPb .addKeys (key );
116
- com .google .datastore .v1beta3 .LookupResponse responsePb = rpc ().lookup (requestPb .build ());
117
- if (responsePb .getDeferredCount () > 0 ) {
118
- key = responsePb .getDeferred (0 );
119
- } else {
120
- Iterator <com .google .datastore .v1beta3 .EntityResult > combinedIter =
121
- Iterables .concat (responsePb .getMissingList (), responsePb .getFoundList ()).iterator ();
122
- key = combinedIter .next ().getEntity ().getKey ();
123
- }
124
- builder .projectId (key .getPartitionId ().getProjectId ());
125
- return new DatastoreOptions (builder );
126
- }
127
-
128
89
@ Override
129
90
protected String defaultHost () {
130
91
String host = System .getProperty (
@@ -138,9 +99,6 @@ protected String defaultProject() {
138
99
String projectId = System .getProperty (
139
100
com .google .datastore .v1beta3 .client .DatastoreHelper .PROJECT_ID_ENV_VAR ,
140
101
System .getenv (com .google .datastore .v1beta3 .client .DatastoreHelper .PROJECT_ID_ENV_VAR ));
141
- if (projectId == null ) {
142
- projectId = appEngineAppId ();
143
- }
144
102
return projectId != null ? projectId : super .defaultProject ();
145
103
}
146
104
@@ -192,7 +150,7 @@ public Builder toBuilder() {
192
150
193
151
@ Override
194
152
public int hashCode () {
195
- return baseHashCode () ^ Objects .hash (namespace , normalizeDataset );
153
+ return Objects .hash (baseHashCode (), namespace );
196
154
}
197
155
198
156
@ Override
@@ -201,8 +159,7 @@ public boolean equals(Object obj) {
201
159
return false ;
202
160
}
203
161
DatastoreOptions other = (DatastoreOptions ) obj ;
204
- return baseEquals (other ) && Objects .equals (namespace , other .namespace )
205
- && Objects .equals (normalizeDataset , other .normalizeDataset );
162
+ return baseEquals (other ) && Objects .equals (namespace , other .namespace );
206
163
}
207
164
208
165
public static Builder builder () {
0 commit comments