1616
1717package com .google .cloud .datastore ;
1818
19+ import static com .google .cloud .datastore .RequestOptionsHelper .createRequestOptions ;
1920import static com .google .cloud .datastore .telemetry .TelemetryConstants .ATTRIBUTES_KEY_DEFERRED ;
2021import static com .google .cloud .datastore .telemetry .TelemetryConstants .ATTRIBUTES_KEY_DOCUMENT_COUNT ;
2122import static com .google .cloud .datastore .telemetry .TelemetryConstants .ATTRIBUTES_KEY_MISSING ;
@@ -111,7 +112,7 @@ final class DatastoreImpl extends BaseService<DatastoreOptions> implements Datas
111112 private static final ExceptionHandler TRANSACTION_OPERATION_EXCEPTION_HANDLER =
112113 TransactionOperationExceptionHandler .build ();
113114
114- private final com . google . cloud . datastore . telemetry . TraceUtil otelTraceUtil =
115+ private final TraceUtil otelTraceUtil =
115116 getOptions ().getTraceUtil ();
116117 private final DatastoreMetricsRecorder metricsRecorder ;
117118 private final OpenTelemetry builtInOpenTelemetry ;
@@ -180,7 +181,7 @@ static class TracedReadWriteTransactionCallable<T> implements Callable<T> {
180181
181182 TracedReadWriteTransactionCallable (
182183 ReadWriteTransactionCallable <T > delegate ,
183- @ Nullable com . google . cloud . datastore . telemetry . TraceUtil .Span parentSpan ) {
184+ @ Nullable TraceUtil .Span parentSpan ) {
184185 this .delegate = delegate ;
185186 this .parentSpan = parentSpan ;
186187 }
@@ -362,13 +363,16 @@ public <T> QueryResults<T> run(
362363 @ Override
363364 @ BetaApi
364365 public <T > QueryResults <T > run (Query <T > query , DatastoreExecutionOptions executionOptions ) {
366+ Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
365367 com .google .cloud .datastore .models .ExplainOptions explainOptions =
366368 executionOptions .getExplainOptions ();
367369 return run (
368370 toReadOptionsPb (executionOptions .getReadOptions ().toArray (new ReadOption [0 ])),
369371 query ,
370372 explainOptions != null ? explainOptions .toPb () : null ,
371- executionOptions .getRequestOptions ());
373+ executionOptions .getRequestOptions () != null
374+ ? executionOptions .getRequestOptions ().toPb ()
375+ : null );
372376 }
373377
374378 @ SuppressWarnings ("unchecked" )
@@ -435,7 +439,7 @@ RunQueryResponse runQuery(final RunQueryRequest requestPb) {
435439 return runWithObservability (
436440 () -> {
437441 RunQueryResponse response = datastoreRpc .runQuery (requestPb );
438- com . google . cloud . datastore . telemetry . TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
442+ TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
439443 if (span != null ) {
440444 span .addEvent (
441445 spanName + " complete." ,
@@ -488,7 +492,6 @@ public List<Key> allocateId(IncompleteKey... keys) {
488492 @ Override
489493 @ BetaApi
490494 public List <Key > allocateId (List <IncompleteKey > keys , DatastoreExecutionOptions executionOptions ) {
491- Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
492495 Preconditions .checkArgument (
493496 verifyIncompleteKeyType (keys ), "keys must be IncompleteKey instances" );
494497 if (keys .isEmpty ()) {
@@ -501,7 +504,7 @@ public List<Key> allocateId(List<IncompleteKey> keys, DatastoreExecutionOptions
501504 requestPb .setProjectId (getOptions ().getProjectId ());
502505 requestPb .setDatabaseId (getOptions ().getDatabaseId ());
503506 requestPb .setRequestOptions (
504- RequestOptionsHelper . createRequestOptions (getOptions (), executionOptions ));
507+ createRequestOptions (getOptions (), executionOptions ));
505508 AllocateIdsResponse responsePb = allocateIds (requestPb .build ());
506509 ImmutableList .Builder <Key > keyList = ImmutableList .builder ();
507510 for (com .google .datastore .v1 .Key keyPb : responsePb .getKeysList ()) {
@@ -546,7 +549,6 @@ public List<Entity> add(FullEntity<?>... entities) {
546549 @ Override
547550 @ BetaApi
548551 public List <Entity > add (List <FullEntity <?>> entities , DatastoreExecutionOptions executionOptions ) {
549- Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
550552 if (entities .isEmpty ()) {
551553 return Collections .emptyList ();
552554 }
@@ -663,7 +665,7 @@ Iterator<Entity> get(
663665 requestPb .setProjectId (getOptions ().getProjectId ());
664666 requestPb .setDatabaseId (getOptions ().getDatabaseId ());
665667 requestPb .setRequestOptions (
666- RequestOptionsHelper . createRequestOptions (getOptions (), executionOptions ));
668+ createRequestOptions (getOptions (), executionOptions ));
667669 return new ResultsIterator (requestPb );
668670 }
669671
@@ -707,7 +709,7 @@ LookupResponse lookup(final LookupRequest requestPb) {
707709 return runWithObservability (
708710 () -> {
709711 LookupResponse response = datastoreRpc .lookup (requestPb );
710- com . google . cloud . datastore . telemetry . TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
712+ TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
711713 if (span != null ) {
712714 span .addEvent (
713715 spanName + " complete." ,
@@ -738,15 +740,14 @@ public List<Key> reserveIds(Key... keys) {
738740 @ Override
739741 @ BetaApi
740742 public List <Key > reserveIds (List <Key > keys , DatastoreExecutionOptions executionOptions ) {
741- Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
742743 ReserveIdsRequest .Builder requestPb = ReserveIdsRequest .newBuilder ();
743744 for (Key key : keys ) {
744745 requestPb .addKeys (key .toPb ());
745746 }
746747 requestPb .setProjectId (getOptions ().getProjectId ());
747748 requestPb .setDatabaseId (getOptions ().getDatabaseId ());
748749 requestPb .setRequestOptions (
749- RequestOptionsHelper . createRequestOptions (getOptions (), executionOptions ));
750+ createRequestOptions (getOptions (), executionOptions ));
750751 ReserveIdsResponse responsePb = reserveIds (requestPb .build ());
751752 ImmutableList .Builder <Key > keyList = ImmutableList .builder ();
752753 if (responsePb .isInitialized ()) {
@@ -773,7 +774,6 @@ public void update(Entity... entities) {
773774 @ Override
774775 @ BetaApi
775776 public void update (List <Entity > entities , DatastoreExecutionOptions executionOptions ) {
776- Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
777777 if (!entities .isEmpty ()) {
778778 ImmutableList .Builder <Mutation > mutationsPb = ImmutableList .builder ();
779779 Map <Key , Entity > dedupEntities = new LinkedHashMap <>();
@@ -801,7 +801,6 @@ public List<Entity> put(FullEntity<?>... entities) {
801801 @ Override
802802 @ BetaApi
803803 public List <Entity > put (List <FullEntity <?>> entities , DatastoreExecutionOptions executionOptions ) {
804- Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
805804 if (entities .isEmpty ()) {
806805 return Collections .emptyList ();
807806 }
@@ -842,7 +841,6 @@ public void delete(Key... keys) {
842841 @ Override
843842 @ BetaApi
844843 public void delete (List <Key > keys , DatastoreExecutionOptions executionOptions ) {
845- Preconditions .checkNotNull (executionOptions , "executionOptions cannot be null" );
846844 if (!keys .isEmpty ()) {
847845 ImmutableList .Builder <Mutation > mutationsPb = ImmutableList .builder ();
848846 Set <Key > dedupKeys = new LinkedHashSet <>(keys );
@@ -858,20 +856,15 @@ public KeyFactory newKeyFactory() {
858856 return DatastoreHelper .newKeyFactory (getOptions ());
859857 }
860858
861- private CommitResponse commitMutation (ImmutableList <Mutation > mutationsPb ) {
862- return commitMutation (mutationsPb , DatastoreExecutionOptions .getDefaultInstance ());
863- }
864-
865859 private CommitResponse commitMutation (
866860 ImmutableList <Mutation > mutationsPb , DatastoreExecutionOptions executionOptions ) {
867861 CommitRequest .Builder requestPb =
868862 CommitRequest .newBuilder ()
869863 .setMode (CommitRequest .Mode .NON_TRANSACTIONAL )
870864 .setProjectId (getOptions ().getProjectId ())
871865 .setDatabaseId (getOptions ().getDatabaseId ())
872- .addAllMutations (mutationsPb );
873- requestPb .setRequestOptions (
874- RequestOptionsHelper .createRequestOptions (getOptions (), executionOptions ));
866+ .addAllMutations (mutationsPb )
867+ .setRequestOptions (createRequestOptions (getOptions (), executionOptions ));
875868 return commit (requestPb .build ());
876869 }
877870
@@ -883,7 +876,7 @@ CommitResponse commit(final CommitRequest requestPb) {
883876 return runWithObservability (
884877 () -> {
885878 CommitResponse response = datastoreRpc .commit (requestPb );
886- com . google . cloud . datastore . telemetry . TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
879+ TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
887880 if (span != null ) {
888881 span .addEvent (
889882 spanName + " complete." ,
@@ -925,16 +918,15 @@ void rollbackTransaction(ByteString transaction, DatastoreExecutionOptions execu
925918 requestPb .setTransaction (transaction );
926919 requestPb .setProjectId (getOptions ().getProjectId ());
927920 requestPb .setDatabaseId (getOptions ().getDatabaseId ());
928- requestPb .setRequestOptions (
929- RequestOptionsHelper .createRequestOptions (getOptions (), executionOptions ));
921+ requestPb .setRequestOptions (createRequestOptions (getOptions (), executionOptions ));
930922 rollback (requestPb .build ());
931923 }
932924
933925 void rollback (final RollbackRequest requestPb ) {
934926 runWithObservability (
935927 () -> {
936928 datastoreRpc .rollback (requestPb );
937- com . google . cloud . datastore . telemetry . TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
929+ TraceUtil .Span span = otelTraceUtil .getCurrentSpan ();
938930 if (span != null ) {
939931 span .addEvent (
940932 SPAN_NAME_ROLLBACK ,
@@ -954,7 +946,7 @@ private <T> T runWithObservability(
954946 String methodName ,
955947 String spanName ,
956948 ResultRetryAlgorithm <?> exceptionHandler ) {
957- com . google . cloud . datastore . telemetry . TraceUtil .Span span = otelTraceUtil .startSpan (spanName );
949+ TraceUtil .Span span = otelTraceUtil .startSpan (spanName );
958950
959951 Stopwatch operationStopwatch = Stopwatch .createStarted ();
960952 String operationStatus = StatusCode .Code .OK .toString ();
0 commit comments