org.h2.mvstore
Class MVStore.Builder

java.lang.Object
  extended by org.h2.mvstore.MVStore.Builder
Enclosing class:
MVStore

public static class MVStore.Builder
extends java.lang.Object

A builder for an MVStore.


Constructor Summary
MVStore.Builder()
           
 
Method Summary
 MVStore.Builder backgroundExceptionHandler(java.lang.Thread.UncaughtExceptionHandler exceptionHandler)
          Set the listener to be used for exceptions that occur in the background thread.
 MVStore.Builder cacheSize(int mb)
          Set the read cache size in MB.
 MVStore.Builder compressData()
          Compress data before writing using the LZF algorithm.
 MVStore.Builder encryptionKey(char[] password)
          Encrypt / decrypt the file using the given password.
 MVStore.Builder fileName(java.lang.String fileName)
          Use the following file name.
 MVStore.Builder fileStore(FileStore store)
          Use the provided file store instead of the default one.
static MVStore.Builder fromString(java.lang.String s)
          Read the configuration from a string.
 MVStore open()
          Open the store.
 MVStore.Builder pageSplitSize(int pageSplitSize)
          Set the amount of memory a page should contain at most, in bytes, before it is split.
 MVStore.Builder readOnly()
          Open the file in read-only mode.
 java.lang.String toString()
           
 MVStore.Builder writeBufferSize(int mb)
          Set the size of the write buffer, in MB (for file-based stores).
 MVStore.Builder writeDelay(int writeDelay)
          Set the initial write delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MVStore.Builder

public MVStore.Builder()
Method Detail

fileName

public MVStore.Builder fileName(java.lang.String fileName)
Use the following file name. If the file does not exist, it is automatically created. The parent directory already must exist.

Parameters:
fileName - the file name
Returns:
this

encryptionKey

public MVStore.Builder encryptionKey(char[] password)
Encrypt / decrypt the file using the given password. This method has no effect for in-memory stores. The password is passed as a char array so that it can be cleared as soon as possible. Please note there is still a small risk that password stays in memory (due to Java garbage collection). Also, the hashed encryption key is kept in memory as long as the file is open.

Parameters:
password - the password
Returns:
this

readOnly

public MVStore.Builder readOnly()
Open the file in read-only mode. In this case, a shared lock will be acquired to ensure the file is not concurrently opened in write mode.

If this option is not used, the file is locked exclusively.

Please note a store may only be opened once in every JVM (no matter whether it is opened in read-only or read-write mode), because each file may be locked only once in a process.

Returns:
this

cacheSize

public MVStore.Builder cacheSize(int mb)
Set the read cache size in MB. The default is 16 MB.

Parameters:
mb - the cache size in megabytes
Returns:
this

compressData

public MVStore.Builder compressData()
Compress data before writing using the LZF algorithm. This will save about 50% of the disk space, but will slow down read and write operations slightly.

This setting only affects writes; it is not necessary to enable compression when reading, even if compression was enabled when writing.

Returns:
this

writeBufferSize

public MVStore.Builder writeBufferSize(int mb)
Set the size of the write buffer, in MB (for file-based stores). Changes are automatically stored if the buffer grows larger than this. However, unless the changes are committed later on, they are rolled back when opening the store.

The default is 4 MB.

When the value is set to 0 or lower, data is never automatically stored.

Parameters:
mb - the write buffer size, in megabytes
Returns:
this

pageSplitSize

public MVStore.Builder pageSplitSize(int pageSplitSize)
Set the amount of memory a page should contain at most, in bytes, before it is split. The default is 6 KB. This is not a limit in the page size, as pages with one entry can get larger. It is just the point where pages that contain more than one entry are split.

Parameters:
pageSplitSize - the page size
Returns:
this

backgroundExceptionHandler

public MVStore.Builder backgroundExceptionHandler(java.lang.Thread.UncaughtExceptionHandler exceptionHandler)
Set the listener to be used for exceptions that occur in the background thread.

Parameters:
exceptionHandler - the handler
Returns:
this

fileStore

public MVStore.Builder fileStore(FileStore store)
Use the provided file store instead of the default one.

Parameters:
store - the file store
Returns:
this

writeDelay

public MVStore.Builder writeDelay(int writeDelay)
Set the initial write delay.

Parameters:
writeDelay - the write delay
Returns:
this

open

public MVStore open()
Open the store.

Returns:
the opened store

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromString

public static MVStore.Builder fromString(java.lang.String s)
Read the configuration from a string.

Parameters:
s - the string representation
Returns:
the builder