Class MySQLKVDatabase
- All Implemented Interfaces:
KVDatabase
SQLKVDatabase
.
Automatically creates the key/value table on startup if it doesn't already exist.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
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
configureConnection
(Connection connection) Configure a newly createdConnection
.protected SQLKVTransaction
createSQLKVTransaction
(Connection connection) Create a newSQLKVTransaction
for a new transaction given the specifiedConnection
.int
Get the lock timeout with which to configure new transactions.protected void
initializeDatabaseIfNecessary
(Connection connection) Perform any required database initialization.limitSingleRow
(String sql) AppendsLIMIT 1
to the statement.Encloses the givenname
in backticks.void
setInnodbLargePrefix
(boolean innodbLargePrefix) Configure the use of InnoDB large prefixes.void
setLockTimeout
(int lockTimeout) Wrap the givenSQLException
in the appropriateKVTransactionException
.Methods inherited from class io.permazen.kv.sql.SQLKVDatabase
beginTransaction, createGetAllStatement, createGetAtLeastStatement, createGetAtMostStatement, createGetRangeStatement, createGetStatement, createPutStatement, createRemoveAllStatement, createRemoveAtLeastStatement, createRemoveAtMostStatement, createRemoveRangeStatement, createRemoveStatement, createTransaction, createTransaction, createTransactionConnection, getDataSource, getIsolationLevel, getIsolationLevel, getKeyColumnName, getTableName, getValueColumnName, isRollbackForReadOnly, postBeginTransaction, preBeginTransaction, setDataSource, setIsolationLevel, setKeyColumnName, setRollbackForReadOnly, setTableName, setValueColumnName, start, stop
-
Field Details
-
INNODB_NORMAL_INDEX_SIZE
public static final int INNODB_NORMAL_INDEX_SIZE- See Also:
-
INNODB_LARGE_INDEX_SIZE
public static final int INNODB_LARGE_INDEX_SIZE- See Also:
-
-
Constructor Details
-
MySQLKVDatabase
public MySQLKVDatabase()
-
-
Method Details
-
setInnodbLargePrefix
public void setInnodbLargePrefix(boolean innodbLargePrefix) Configure the use of InnoDB large prefixes.MySQL InnoDB indexes are normally limited to 767 bytes, but you can go up to 3072 bytes if you set these parameters in
/etc/my.cnf
:[mysqld] innodb_large_prefix = true innodb_file_per_table = true innodb_file_format = barracuda
Setting this property to true increases the maximum key length from 767 to 3072 bytes and adds
ROW_FORMAT=DYNAMIC
to the table creation statement ininitializeDatabaseIfNecessary()
. This property has no effect if the table already exists at startup.Default is false.
- Parameters:
innodbLargePrefix
- true for InnoDB large prefixes- See Also:
-
getLockTimeout
public int getLockTimeout()Get the lock timeout with which to configure new transactions.Default is 3.
- Returns:
- lock timeout for new transactions
-
setLockTimeout
public void setLockTimeout(int lockTimeout) -
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
-
configureConnection
Description copied from class:SQLKVDatabase
Configure a newly createdConnection
.The implementation in
SQLKVDatabase
does nothing.- Overrides:
configureConnection
in classSQLKVDatabase
- Parameters:
connection
- newly createdConnection
- Throws:
SQLException
- if an error occurs
-
createSQLKVTransaction
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
-
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
-