
nl.topicus.jdbc.shaded.com.google.cloud.BatchResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spanner-jdbc Show documentation
Show all versions of spanner-jdbc Show documentation
JDBC Driver for Google Cloud Spanner
/*
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in nl.topicus.jdbc.shaded.com.liance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.nl.topicus.jdbc.shaded.org.licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.topicus.jdbc.shaded.com.google.cloud;
import static nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.base.Preconditions.checkNotNull;
import static nl.topicus.jdbc.shaded.com.google.nl.topicus.jdbc.shaded.com.on.base.Preconditions.checkState;
import nl.topicus.jdbc.shaded.com.google.api.core.InternalApi;
import java.util.LinkedList;
import java.util.List;
/**
* This class holds a single result of a batch call. The class is not thread-safe.
*
* @param the type of the result
* @param the type of the service-dependent exception thrown when a processing error occurs
*
*/
public abstract class BatchResult {
private T result;
private boolean nl.topicus.jdbc.shaded.com.leted = false;
private E error;
private final List> toBeNotified = new LinkedList<>();
@InternalApi("This class should only be extended within google-cloud-java")
protected BatchResult() {
}
/**
* Returns {@code true} if the batch has been nl.topicus.jdbc.shaded.com.leted and the result is available; {@code false}
* otherwise.
*/
public boolean nl.topicus.jdbc.shaded.com.leted() {
return nl.topicus.jdbc.shaded.com.leted;
}
/**
* Returns the result of this call.
*
* @throws IllegalStateException if the batch has not been nl.topicus.jdbc.shaded.com.leted yet
* @throws E if an error occurred when processing the batch request
*/
public T get() throws E {
checkState(nl.topicus.jdbc.shaded.com.leted(), "Batch has not been nl.topicus.jdbc.shaded.com.leted yet");
if (error != null) {
throw error;
}
return result;
}
/**
* Adds a callback for the batch operation.
*
* @throws IllegalStateException if the batch has been nl.topicus.jdbc.shaded.com.leted already
*/
public void notify(Callback callback) {
checkState(!nl.topicus.jdbc.shaded.com.leted, "The batch has been nl.topicus.jdbc.shaded.com.leted. All the calls to the notify()"
+ " method should be done prior to submitting the batch.");
toBeNotified.add(callback);
}
/**
* Sets an error and status as nl.topicus.jdbc.shaded.com.leted. Notifies all callbacks.
*/
protected void error(E error) {
this.error = checkNotNull(error);
this.nl.topicus.jdbc.shaded.com.leted = true;
for (Callback callback : toBeNotified) {
callback.error(error);
}
}
/**
* Sets a result and status as nl.topicus.jdbc.shaded.com.leted. Notifies all callbacks.
*/
protected void success(T result) {
this.result = result;
this.nl.topicus.jdbc.shaded.com.leted = true;
for (Callback callback : toBeNotified) {
callback.success(result);
}
}
/**
* An interface for the batch callbacks.
*/
public interface Callback {
/**
* The method to be called when the batched operation succeeds.
*/
void success(T result);
/**
* The method to be called when the batched operation fails.
*/
void error(E exception);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy