+ public DatastoreContextFactory newContextFactory() {
+ return new DatastoreContextFactory(this);
+ }
+
+ public synchronized DatastoreContext getShardDatastoreContext(String forShardName) {
+ if(currentProperties == null) {
+ return context;
+ }
+
+ Builder builder = DatastoreContext.newBuilderFrom(context);
+ String dataStoreTypePrefix = context.getDataStoreName() + '.';
+ final String shardNamePrefix = forShardName + '.';
+
+ List<String> keys = getSortedKeysByDatastoreType(currentProperties.keySet(), dataStoreTypePrefix);
+
+ for(String key: keys) {
+ Object value = currentProperties.get(key);
+ if(key.startsWith(dataStoreTypePrefix)) {
+ key = key.replaceFirst(dataStoreTypePrefix, "");
+ }
+
+ if(key.startsWith(shardNamePrefix)) {
+ key = key.replaceFirst(shardNamePrefix, "");
+ convertValueAndInvokeSetter(key, value, builder);
+ }
+ }
+
+ return builder.build();
+ }
+