Package io.permazen.kv.cockroach
Class CockroachKVDatabase
java.lang.Object
io.permazen.kv.sql.SQLKVDatabase
io.permazen.kv.cockroach.CockroachKVDatabase
- All Implemented Interfaces:
KVDatabase
KVDatabase
implementation based on CockroachDB.
Automatically creates the key/value table on startup if it doesn't already exist.
-
Field Summary
Fields inherited from class io.permazen.kv.sql.SQLKVDatabase
dataSource, DEFAULT_KEY_COLUMN_NAME, DEFAULT_TABLE_NAME, DEFAULT_VALUE_COLUMN_NAME, isolationLevel, keyColumnName, log, OPTION_ISOLATION, tableName, valueColumnName
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
beginTransaction
(Connection connection) Open a new SQL transaction on the givenConnection
.Create an SQL statement that inserts the key/value pair with key?1
and value?2
A row with key?1
may already exist; if so, the value should be updated to?2
(if syntax requires it, the value may be updated to?3
instead;?3
, if it exists, will be set to the same value as?2
).protected io.permazen.kv.cockroach.CockroachKVTransaction
createSQLKVTransaction
(Connection connection) Create a newSQLKVTransaction
for a new transaction given the specifiedConnection
.protected void
initializeDatabaseIfNecessary
(Connection connection) Perform any required database initialization.limitSingleRow
(String sql) AppendsLIMIT 1
to the statement.protected void
postBeginTransaction
(Connection connection) Subclass hook invoked just after opening a new SQL transaction.Encloses the givenname
in backticks.Wrap the givenSQLException
in the appropriateKVTransactionException
.Methods inherited from class io.permazen.kv.sql.SQLKVDatabase
configureConnection, createGetAllStatement, createGetAtLeastStatement, createGetAtMostStatement, createGetRangeStatement, createGetStatement, createRemoveAllStatement, createRemoveAtLeastStatement, createRemoveAtMostStatement, createRemoveRangeStatement, createRemoveStatement, createTransaction, createTransaction, createTransactionConnection, getDataSource, getIsolationLevel, getIsolationLevel, getKeyColumnName, getTableName, getValueColumnName, isRollbackForReadOnly, preBeginTransaction, setDataSource, setIsolationLevel, setKeyColumnName, setRollbackForReadOnly, setTableName, setValueColumnName, start, stop
-
Constructor Details
-
CockroachKVDatabase
public CockroachKVDatabase()
-
-
Method Details
-
initializeDatabaseIfNecessary
Description copied from class:SQLKVDatabase
Perform any required database initialization.The implementation in
SQLKVDatabase
does nothing. Subclasses will typically invokeCREATE TABLE ... IF NOT EXISTS
here, etc.- Overrides:
initializeDatabaseIfNecessary
in classSQLKVDatabase
- Parameters:
connection
- open database connection (will be closed by the caller of this method)- Throws:
SQLException
- if an error occurs
-
beginTransaction
Description copied from class:SQLKVDatabase
Open a new SQL transaction on the givenConnection
.The implementation in
SQLKVDatabase
invokesConnection.setAutoCommit(false)
.- Overrides:
beginTransaction
in classSQLKVDatabase
- Parameters:
connection
- theConnection
for a new transaction- Throws:
SQLException
- if an error occurs- See Also:
-
postBeginTransaction
Description copied from class:SQLKVDatabase
Subclass hook invoked just after opening a new SQL transaction.The implementation in
SQLKVDatabase
does nothing. Note: subclasses must ensure the transaction is configured for theIsolationLevel
configured on this instance.- Overrides:
postBeginTransaction
in classSQLKVDatabase
- Parameters:
connection
- theConnection
for a new transaction- Throws:
SQLException
- if an error occurs- See Also:
-
createSQLKVTransaction
protected io.permazen.kv.cockroach.CockroachKVTransaction createSQLKVTransaction(Connection connection) throws SQLException Description copied from class:SQLKVDatabase
Create a newSQLKVTransaction
for a new transaction given the specifiedConnection
. There will already be an SQL transaction open onconnection
.The implementation in
SQLKVDatabase
just invokesnew SQLKVTransaction(this, connection)
.- Overrides:
createSQLKVTransaction
in classSQLKVDatabase
- Parameters:
connection
- theConnection
for a new transaction- Returns:
- newly created transaction
- Throws:
SQLException
- if an error occurs
-
createPutStatement
Description copied from class:SQLKVDatabase
Create an SQL statement that inserts the key/value pair with key?1
and value?2
A row with key?1
may already exist; if so, the value should be updated to?2
(if syntax requires it, the value may be updated to?3
instead;?3
, if it exists, will be set to the same value as?2
).- Overrides:
createPutStatement
in classSQLKVDatabase
- Returns:
- SQL insertion statement
-
quote
Encloses the givenname
in backticks.- Overrides:
quote
in classSQLKVDatabase
- Parameters:
name
- table or column name- Returns:
name
enquoted as necessary for this database type
-
limitSingleRow
AppendsLIMIT 1
to the statement.- Overrides:
limitSingleRow
in classSQLKVDatabase
- Parameters:
sql
- SQL statement- Returns:
- SQL statement
-
wrapException
Description copied from class:SQLKVDatabase
Wrap the givenSQLException
in the appropriateKVTransactionException
.- Overrides:
wrapException
in classSQLKVDatabase
- Parameters:
tx
- theSQLKVTransaction
in which the exception occurede
- SQL exception- Returns:
- appropriate
KVTransactionException
with chained exceptione
-