Java Code Examples for com.google.cloud.spanner.SpannerExceptionFactory#newSpannerException()

The following examples show how to use com.google.cloud.spanner.SpannerExceptionFactory#newSpannerException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudSpannerDriver.java    From spanner-jdbc with MIT License 6 votes vote down vote up
/**
 * Closes all connections to Google Cloud Spanner that have been opened by this driver during the
 * lifetime of this application. You should call this method when you want to shutdown your
 * application, as this frees up all connections and sessions to Google Cloud Spanner. Failure to
 * do so, will keep sessions open server side and can eventually lead to resource exhaustion. Any
 * open JDBC connection to Cloud Spanner opened by this driver will also be closed by this method.
 * This method is also called automatically in a shutdown hook when the JVM is stopped orderly.
 */
public synchronized void closeSpanner() {
  try {
    for (Entry<Spanner, List<CloudSpannerConnection>> entry : connections.entrySet()) {
      List<CloudSpannerConnection> list = entry.getValue();
      for (CloudSpannerConnection con : list) {
        if (!con.isClosed()) {
          con.rollback();
          con.markClosed();
        }
      }
      entry.getKey().close();
    }
    connections.clear();
    spanners.clear();
  } catch (SQLException e) {
    throw SpannerExceptionFactory.newSpannerException(e);
  }
}
 
Example 2
Source File: SpannerTransactionManagerTests.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoCommitDupeException() {

	this.expectedEx.expect(DuplicateKeyException.class);
	this.expectedEx.expectMessage("ALREADY_EXISTS; nested exception is " +
			"com.google.cloud.spanner.SpannerException: ALREADY_EXISTS: this is from a test");

	SpannerException exception = SpannerExceptionFactory.newSpannerException(
			ErrorCode.ALREADY_EXISTS, "this is from a test");

	when(transactionManager.getState()).thenReturn(TransactionState.STARTED);
	Mockito.doThrow(exception).when(transactionManager).commit();

	tx.transactionManager = transactionManager;

	manager.doCommit(status);
}
 
Example 3
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public List<Partition> partitionReadUsingIndex(PartitionOptions partitionOptions, String table,
    String index, KeySet keys, Iterable<String> columns, ReadOption... options)
    throws SpannerException {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}
 
Example 4
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public List<Partition> partitionQuery(PartitionOptions partitionOptions, Statement statement,
    QueryOption... options) throws SpannerException {
  checkTransaction();
  if (batchReadOnlyTransaction != null) {
    return batchReadOnlyTransaction.partitionQuery(partitionOptions, statement, options);
  }
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.FAILED_PRECONDITION,
      METHOD_ONLY_IN_BATCH_READONLY);
}
 
Example 5
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public ResultSet execute(Partition partition) throws SpannerException {
  checkTransaction();
  if (batchReadOnlyTransaction != null) {
    return batchReadOnlyTransaction.execute(partition);
  }
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.FAILED_PRECONDITION,
      METHOD_ONLY_IN_BATCH_READONLY);
}
 
Example 6
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 5 votes vote down vote up
@Override
public BatchTransactionId getBatchTransactionId() {
  checkTransaction();
  if (batchReadOnlyTransaction != null) {
    return batchReadOnlyTransaction.getBatchTransactionId();
  }
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.FAILED_PRECONDITION,
      METHOD_ONLY_IN_BATCH_READONLY);
}
 
Example 7
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public ResultSet read(String table, KeySet keys, Iterable<String> columns,
    ReadOption... options) {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}
 
Example 8
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public ResultSet readUsingIndex(String table, String index, KeySet keys, Iterable<String> columns,
    ReadOption... options) {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}
 
Example 9
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public Struct readRow(String table, Key key, Iterable<String> columns) {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}
 
Example 10
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public Struct readRowUsingIndex(String table, String index, Key key, Iterable<String> columns) {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}
 
Example 11
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public ResultSet analyzeQuery(Statement statement, QueryAnalyzeMode queryMode) {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}
 
Example 12
Source File: CloudSpannerTransaction.java    From spanner-jdbc with MIT License 4 votes vote down vote up
@Override
public List<Partition> partitionRead(PartitionOptions partitionOptions, String table, KeySet keys,
    Iterable<String> columns, ReadOption... options) throws SpannerException {
  throw SpannerExceptionFactory.newSpannerException(ErrorCode.UNIMPLEMENTED,
      METHOD_NOT_IMPLEMENTED);
}