nl.topicus.jdbc

## Class CloudSpannerConnection

- java.lang.Object
- - nl.topicus.jdbc.metadata.AbstractCloudSpannerWrapper
  - - nl.topicus.jdbc.AbstractCloudSpannerConnection
    - - nl.topicus.jdbc.CloudSpannerConnection

All Implemented Interfaces:
  AutoCloseable, Connection, Wrapper, ICloudSpannerConnection

    public class CloudSpannerConnection
    extends AbstractCloudSpannerConnection

JDBC Driver for Google Cloud Spanner.

Author:
  loite

### Nested Class Summary

Nested Classes
`static class` `CloudSpannerConnection.CloudSpannerDatabaseSpecification`

### Field Summary

### Fields inherited from interface java.sql.Connection

`TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addAutoBatchedDdlOperation(String sql)`
`void` `clearAutoBatchedDdlOperations()`
`int` `clearFinishedDDLOperations()` Clears the asynchronous DDL-operations that have finished.
`void` `close()`
`void` `commit()`
`void` `commitPreparedTransaction(String xid)` Commit a previously prepared transaction.
`CloudSpannerArray` `createArrayOf(String typeName, Object[] elements)`
`CloudSpannerConnection` `createCopyConnection()`
`CloudSpannerStatement` `createStatement()`
`Statement` `createStatement(int resultSetType, int resultSetConcurrency)`
`Statement` `createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`Void` `executeDDL(List<String> inputSql)` Execute one or more DDL-statements on the database and wait for it to finish or return after syntax check (when running in async mode).
`List<String>` `getAutoBatchedDdlOperations()`
`boolean` `getAutoCommit()`
`String` `getClientId()`
`static com.google.auth.oauth2.GoogleCredentials` `getCredentialsFromFile(String credentialsPath)`
`static com.google.auth.oauth2.GoogleCredentials` `getCredentialsFromOAuthToken(String oauthToken)`
`ResultSet` `getDynamicConnectionProperties(Statement statement)`
`ResultSet` `getDynamicConnectionProperty(Statement statement, String propertyName)`
`com.google.cloud.Timestamp` `getLastCommitTimestamp()`
`Logger` `getLogger()`
`CloudSpannerDatabaseMetaData` `getMetaData()`
`int` `getNodeCount()`
`String` `getProductName()`
`ResultSet` `getRunningDDLOperations(Statement statement)` Returns a ResultSet containing all asynchronous DDL-operations started by this connection.
`static String` `getServiceAccountProjectId(String credentialsPath)`
`Integer` `getSimulateMajorVersion()`
`Integer` `getSimulateMinorVersion()`
`String` `getSimulateProductName()`
`Properties` `getSuppliedProperties()`
`MetaDataStore.TableKeyMetaData` `getTable(String name)`
`CloudSpannerTransaction` `getTransaction()`
`int` `getTransactionIsolation()`
`Map<String,Class<?>>` `getTypeMap()`
`String` `getUrl()`
`boolean` `isAllowExtendedMode()`
`boolean` `isAsyncDdlOperations()`
`boolean` `isAutoBatchDdlOperations()`
`boolean` `isClosed()`
`boolean` `isReadOnly()`
`boolean` `isReportDefaultSchemaAsNull()`
`boolean` `isValid(int timeout)`
`String` `nativeSQL(String sql)`
`CallableStatement` `prepareCall(String sql)`
`CloudSpannerPreparedStatement` `prepareStatement(String sql)`
`PreparedStatement` `prepareStatement(String sql, int autoGeneratedKeys)`
`PreparedStatement` `prepareStatement(String sql, int[] columnIndexes)`
`PreparedStatement` `prepareStatement(String sql, int resultSetType, int resultSetConcurrency)`
`PreparedStatement` `prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)`
`PreparedStatement` `prepareStatement(String sql, String[] columnNames)`
`void` `prepareTransaction(String xid)` Prepare the current transaction by writing the mutations to the XA_TRANSACTIONS table instead of persisting them in the actual tables.
`int` `resetDynamicConnectionProperty(String propertyName)` Reset a dynamic connection property to its original value, such as AsyncDdlOperations
`void` `rollback()`
`void` `rollbackPreparedTransaction(String xid)` Rollback a previously prepared transaction.
`int` `setAllowExtendedMode(boolean allowExtendedMode)`
`int` `setAsyncDdlOperations(boolean asyncDdlOperations)`
`int` `setAutoBatchDdlOperations(boolean autoBatchDdlOperations)`
`void` `setAutoCommit(boolean autoCommit)`
`int` `setDynamicConnectionProperty(String propertyName, String propertyValue)` Set a dynamic connection property, such as AsyncDdlOperations
`void` `setReadOnly(boolean readOnly)`
`int` `setReportDefaultSchemaAsNull(boolean reportDefaultSchemaAsNull)`
`void` `setSimulateMajorVersion(Integer majorVersion)`
`void` `setSimulateMinorVersion(Integer minorVersion)`
`void` `setSimulateProductName(String productName)`
`void` `setTransactionIsolation(int level)`
`void` `setTypeMap(Map<String,Class<?>> map)`
`void` `waitForDdlOperations()` Waits for all asynchronous DDL-operations that have been issued by this connection to finish.

### Methods inherited from class nl.topicus.jdbc.AbstractCloudSpannerConnection

`abort, checkClosed, clearWarnings, createBlob, createClob, createNClob, createSQLXML, createStruct, getCatalog, getClientInfo, getClientInfo, getHoldability, getNetworkTimeout, getSchema, getWarnings, prepareCall, prepareCall, releaseSavepoint, rollback, setCatalog, setClientInfo, setClientInfo, setHoldability, setNetworkTimeout, setSavepoint, setSavepoint, setSchema`

### Methods inherited from class nl.topicus.jdbc.metadata.AbstractCloudSpannerWrapper

`extractColumnType, getClassName, getGoogleTypeName, isWrapperFor, unwrap`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.sql.Wrapper

`isWrapperFor, unwrap`

### Method Detail

#### getCredentialsFromOAuthToken

    public static com.google.auth.oauth2.GoogleCredentials getCredentialsFromOAuthToken(String oauthToken)

#### getCredentialsFromFile

    public static com.google.auth.oauth2.GoogleCredentials getCredentialsFromFile(String credentialsPath)
                                                                           throws IOException

Throws:
  `IOException`

#### getServiceAccountProjectId

    public static String getServiceAccountProjectId(String credentialsPath)

#### getSimulateProductName

    public String getSimulateProductName()

#### setSimulateProductName

    public void setSimulateProductName(String productName)

#### getSimulateMajorVersion

    public Integer getSimulateMajorVersion()

#### setSimulateMajorVersion

    public void setSimulateMajorVersion(Integer majorVersion)

#### getSimulateMinorVersion

    public Integer getSimulateMinorVersion()

#### setSimulateMinorVersion

    public void setSimulateMinorVersion(Integer minorVersion)

#### executeDDL

    public Void executeDDL(List<String> inputSql)
                    throws SQLException

Execute one or more DDL-statements on the database and wait for it to finish or return after syntax check (when running in async mode). Calling this method will also automatically commit the currently running transaction.

Parameters:
  `inputSql` - The DDL-statement(s) to execute. Some statements may end up not being sent to Cloud Spanner if they contain IF [NOT] EXISTS clauses. The driver will check whether the condition is met, and only then will it be sent to Cloud Spanner.
Returns:
  Nothing
Throws:
  `SQLException` - If an error occurs during the execution of the statement.

#### clearFinishedDDLOperations

    public int clearFinishedDDLOperations()

Clears the asynchronous DDL-operations that have finished.

Returns:
  The number of operations that were cleared

#### waitForDdlOperations

    public void waitForDdlOperations()
                              throws SQLException

Waits for all asynchronous DDL-operations that have been issued by this connection to finish.

Throws:
  `SQLException` - If a database exception occurs while waiting for the operations to finish

#### getRunningDDLOperations

    public ResultSet getRunningDDLOperations(Statement statement)

Returns a ResultSet containing all asynchronous DDL-operations started by this connection. It does not contain DDL-operations that have been started by other connections or by other means.

Parameters:
  `statement` - The statement that requested the operations
Returns:
  A ResultSet with the DDL-operations

#### getProductName

    public String getProductName()

#### createStatement

    public CloudSpannerStatement createStatement()
                                          throws SQLException

Throws:
  `SQLException`

#### prepareStatement

    public CloudSpannerPreparedStatement prepareStatement(String sql)
                                                   throws SQLException

Throws:
  `SQLException`

#### prepareCall

    public CallableStatement prepareCall(String sql)
                                  throws SQLException

Throws:
  `SQLException`

#### nativeSQL

    public String nativeSQL(String sql)
                     throws SQLException

Throws:
  `SQLException`

#### setAutoCommit

    public void setAutoCommit(boolean autoCommit)
                       throws SQLException

Throws:
  `SQLException`

#### getAutoCommit

    public boolean getAutoCommit()
                          throws SQLException

Throws:
  `SQLException`

#### commit

    public void commit()
                throws SQLException

Throws:
  `SQLException`

#### rollback

    public void rollback()
                  throws SQLException

Throws:
  `SQLException`

#### getTransaction

    public CloudSpannerTransaction getTransaction()

#### close

    public void close()
               throws SQLException

Throws:
  `SQLException`

#### isClosed

    public boolean isClosed()
                     throws SQLException

Throws:
  `SQLException`

#### getMetaData

    public CloudSpannerDatabaseMetaData getMetaData()
                                             throws SQLException

Throws:
  `SQLException`

#### setReadOnly

    public void setReadOnly(boolean readOnly)
                     throws SQLException

Throws:
  `SQLException`

#### isReadOnly

    public boolean isReadOnly()
                       throws SQLException

Throws:
  `SQLException`

#### setTransactionIsolation

    public void setTransactionIsolation(int level)
                                 throws SQLException

Throws:
  `SQLException`

#### getTransactionIsolation

    public int getTransactionIsolation()
                                throws SQLException

Throws:
  `SQLException`

#### createStatement

    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency)
                              throws SQLException

Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int resultSetType,
                                              int resultSetConcurrency)
                                       throws SQLException

Throws:
  `SQLException`

#### createStatement

    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency,
                                     int resultSetHoldability)
                              throws SQLException

Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int resultSetType,
                                              int resultSetConcurrency,
                                              int resultSetHoldability)
                                       throws SQLException

Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int autoGeneratedKeys)
                                       throws SQLException

Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              int[] columnIndexes)
                                       throws SQLException

Throws:
  `SQLException`

#### prepareStatement

    public PreparedStatement prepareStatement(String sql,
                                              String[] columnNames)
                                       throws SQLException

Throws:
  `SQLException`

#### getUrl

    public String getUrl()

#### getClientId

    public String getClientId()

#### isValid

    public boolean isValid(int timeout)
                    throws SQLException

Throws:
  `SQLException`

#### createArrayOf

    public CloudSpannerArray createArrayOf(String typeName,
                                           Object[] elements)
                                    throws SQLException

Throws:
  `SQLException`

#### getTable

    public MetaDataStore.TableKeyMetaData getTable(String name)
                                            throws SQLException

Throws:
  `SQLException`

#### getSuppliedProperties

    public Properties getSuppliedProperties()

#### isAllowExtendedMode

    public boolean isAllowExtendedMode()

#### setAllowExtendedMode

    public int setAllowExtendedMode(boolean allowExtendedMode)

#### isAsyncDdlOperations

    public boolean isAsyncDdlOperations()

#### setAsyncDdlOperations

    public int setAsyncDdlOperations(boolean asyncDdlOperations)

#### isAutoBatchDdlOperations

    public boolean isAutoBatchDdlOperations()

#### setAutoBatchDdlOperations

    public int setAutoBatchDdlOperations(boolean autoBatchDdlOperations)

#### isReportDefaultSchemaAsNull

    public boolean isReportDefaultSchemaAsNull()

#### setReportDefaultSchemaAsNull

    public int setReportDefaultSchemaAsNull(boolean reportDefaultSchemaAsNull)

#### setDynamicConnectionProperty

    public int setDynamicConnectionProperty(String propertyName,
                                            String propertyValue)

Set a dynamic connection property, such as AsyncDdlOperations

Parameters:
  `propertyName` - The name of the dynamic connection property
  `propertyValue` - The value to set
Returns:
  1 if the property was set, 0 if not (this complies with the normal behaviour of executeUpdate(...) methods)

#### resetDynamicConnectionProperty

    public int resetDynamicConnectionProperty(String propertyName)

Reset a dynamic connection property to its original value, such as AsyncDdlOperations

Parameters:
  `propertyName` - The name of the dynamic connection property
Returns:
  1 if the property was reset, 0 if not (this complies with the normal behaviour of executeUpdate(...) methods)

#### getDynamicConnectionProperties

    public ResultSet getDynamicConnectionProperties(Statement statement)

#### getDynamicConnectionProperty

    public ResultSet getDynamicConnectionProperty(Statement statement,
                                                  String propertyName)

#### getLastCommitTimestamp

    public com.google.cloud.Timestamp getLastCommitTimestamp()

Returns:
  The commit timestamp of the last transaction that committed succesfully

#### createCopyConnection

    public CloudSpannerConnection createCopyConnection()
                                                throws SQLException

Returns:
  A new connection with the same URL and properties as this connection. You can use this method if you want to open a new connection to the same database, for example to run a number of statements in a different transaction than the transaction you are currently using on this connection.
Throws:
  `SQLException` - If an error occurs while opening the new connection

#### getLogger

    public Logger getLogger()

#### getTypeMap

    public Map<String,Class<?>> getTypeMap()
                                    throws SQLException

Throws:
  `SQLException`

#### setTypeMap

    public void setTypeMap(Map<String,Class<?>> map)
                    throws SQLException

Throws:
  `SQLException`

#### getNodeCount

    public int getNodeCount()
                     throws SQLException

Returns:
  The number of nodes of this Cloud Spanner instance
Throws:
  `SQLException` - If an exception occurs when trying to get the number of nodes

#### prepareTransaction

    public void prepareTransaction(String xid)
                            throws SQLException

Prepare the current transaction by writing the mutations to the XA_TRANSACTIONS table instead of persisting them in the actual tables.

Parameters:
  `xid` - The id of the prepared transaction
Throws:
  `SQLException` - If an exception occurs while saving the mutations to the database for later commit

#### commitPreparedTransaction

    public void commitPreparedTransaction(String xid)
                                   throws SQLException

Commit a previously prepared transaction.

Parameters:
  `xid` - The id of the prepared transaction
Throws:
  `SQLException` - If an error occurs when writing the mutations to the database

#### rollbackPreparedTransaction

    public void rollbackPreparedTransaction(String xid)
                                     throws SQLException

Rollback a previously prepared transaction.

Parameters:
  `xid` - The id of the prepared transaction to rollback
Throws:
  `SQLException` - If an error occurs while rolling back the prepared transaction

#### getAutoBatchedDdlOperations

    public List<String> getAutoBatchedDdlOperations()

#### clearAutoBatchedDdlOperations

    public void clearAutoBatchedDdlOperations()

#### addAutoBatchedDdlOperation

    public void addAutoBatchedDdlOperation(String sql)