Top Description Fields Constructors Methods
org.h2.tools

public Class Recover

extends Tool
implements DataHandler
Class Inheritance
All Implemented Interfaces
org.h2.store.DataHandler
Imports
java.io.BufferedReader, .ByteArrayInputStream, .IOException, .InputStream, .InputStreamReader, .PrintWriter, .Reader, .SequenceInputStream, java.nio.charset.StandardCharsets, java.sql.Connection, .PreparedStatement, .ResultSet, .SQLException, java.util.ArrayList, .Collections, .Enumeration, .HashMap, .HashSet, .Iterator, .Map, .Map.Entry, org.h2.engine.Constants, .DbObject, .MetaRecord, org.h2.message.DbException, org.h2.mvstore.MVMap, .MVStore, .MVStoreTool, .StreamStore, org.h2.mvstore.db.LobStorageMap, .ValueDataType, org.h2.mvstore.tx.TransactionMap, .TransactionStore, org.h2.mvstore.type.DataType, .MetaType, .StringDataType, org.h2.result.Row, org.h2.store.DataHandler, .FileLister, .FileStore, .LobStorageFrontend, .LobStorageInterface, org.h2.store.fs.FileUtils, org.h2.util.HasSQL, .IOUtils, .SmallLRUCache, .StringUtils, .TempFileDeleter, .Tool, org.h2.value.CompareMode, .Value, .ValueCollectionBase, .ValueLob, org.h2.value.lob.LobData, .LobDataDatabase

Helps recovering a corrupted database.

Field Summary

Modifier and TypeField and Description
private HashMap<String, String>
private String
private boolean
private HashSet<Integer>
private int
private ArrayList<MetaRecord>
private int
private String
private HashMap<Integer, String>
private boolean
private int
Inherited from org.h2.util.Tool:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
private void
private static void
private void
private static void
private void
private static void
public static void
execute(String
the directory
dir
,
String
the database name (null for all databases)
db
)

Dumps the contents of a database to a SQL script file.

private static String
public CompareMode
getCompareMode()

Implements org.h2.store.DataHandler.getCompareMode.

Return compare mode.

public String
public SmallLRUCache<String, String[]>
public LobStorageInterface
public Object
public int
private void
getSQL(StringBuilder builder, String column, Value v)

public TempFileDeleter
private PrintWriter
getWriter(String fileName, String suffix)

private static boolean
private static boolean
public static void
main(String...
the command line arguments
args
)

Options are case sensitive.

public FileStore
openFile(String
the file name
name
,
String
the mode
mode
,
boolean
whether the file must already exist
mustExist
)

Implements org.h2.store.DataHandler.openFile.

INTERNAL

private void
public static InputStream

Returns:

InputStream to read LOB content from
readBlobMap
(Connection
to use
conn
,
long
id of the LOB stream
lobId
,
long
not used
precision
)

INTERNAL

public static Reader

Returns:

Reader to read LOB content from
readClobMap
(Connection
to use
conn
,
long
id of the LOB stream
lobId
,
long
not used
precision
)

INTERNAL

public int
readLob(long
the lob id
lobId
,
byte[]
the message authentication code
hmac
,
long
the offset within the lob
offset
,
byte[]
the target buffer
buff
,
int
the offset within the target buffer
off
,
int
the number of bytes to read
length
)

Implements org.h2.store.DataHandler.readLob.

INTERNAL

private void
public void
runTool(String...
the command line arguments
args
)

Implements abstract org.h2.util.Tool.runTool.

Dumps the contents of a database file to a human readable text file.

private void
private String
setStorage(int storageId)

private void
trace(String message)

private void
private void
private void
private void
private void
Inherited from org.h2.util.Tool:
getMainClassNameisOptionprintNoDatabaseFilesFoundsetOutshowUsageshowUsageAndThrowUnsupportedOptionthrowUnsupportedOption

Field Detail

columnTypeMapback to summary
private HashMap<String, String> columnTypeMap
databaseNameback to summary
private String databaseName
lobMapsback to summary
private boolean lobMaps
objectIdSetback to summary
private HashSet<Integer> objectIdSet
recordLengthback to summary
private int recordLength
schemaback to summary
private ArrayList<MetaRecord> schema
storageIdback to summary
private int storageId
storageNameback to summary
private String storageName
tableMapback to summary
private HashMap<Integer, String> tableMap
traceback to summary
private boolean trace
valueIdback to summary
private int valueId

Constructor Detail

Recoverback to summary
public Recover()

Method Detail

checkPowerOffback to summary
public void checkPowerOff()

Implements org.h2.store.DataHandler.checkPowerOff.

INTERNAL

Annotations
@Override
checkWritingAllowedback to summary
public void checkWritingAllowed()

Implements org.h2.store.DataHandler.checkWritingAllowed.

INTERNAL

Annotations
@Override
createTemporaryTableback to summary
private void createTemporaryTable(PrintWriter writer)
dumpLayoutback to summary
private static void dumpLayout(PrintWriter writer, MVStore mv)
dumpLobMapsback to summary
private void dumpLobMaps(PrintWriter writer, MVStore mv)
dumpMetaback to summary
private static void dumpMeta(PrintWriter writer, MVStore mv)
dumpMVStoreFileback to summary
private void dumpMVStoreFile(PrintWriter writer, String fileName)
dumpTypesback to summary
private static void dumpTypes(PrintWriter writer, MVStore mv)
executeback to summary
public static void execute(String dir, String db) throws SQLException

Dumps the contents of a database to a SQL script file.

Parameters
dir:String

the directory

db:String

the database name (null for all databases)

Exceptions
SQLException:
on failure
extractTableOrViewNameback to summary
private static String extractTableOrViewName(String sql)
getCompareModeback to summary
public CompareMode getCompareMode()

Implements org.h2.store.DataHandler.getCompareMode.

Doc from org.h2.store.DataHandler.getCompareMode.

Return compare mode.

Returns:CompareMode

Compare mode.

Annotations
@Override
getDatabasePathback to summary
public String getDatabasePath()

Implements org.h2.store.DataHandler.getDatabasePath.

INTERNAL

Returns:String

Doc from org.h2.store.DataHandler.getDatabasePath.

the database path

Annotations
@Override
getLobFileListCacheback to summary
public SmallLRUCache<String, String[]> getLobFileListCache()

Implements org.h2.store.DataHandler.getLobFileListCache.

INTERNAL

Returns:SmallLRUCache<String, String[]>

Doc from org.h2.store.DataHandler.getLobFileListCache.

the cache or null

Annotations
@Override
getLobStorageback to summary
public LobStorageInterface getLobStorage()

Implements org.h2.store.DataHandler.getLobStorage.

INTERNAL

Returns:LobStorageInterface

Doc from org.h2.store.DataHandler.getLobStorage.

the lob storage mechanism

Annotations
@Override
getLobSyncObjectback to summary
public Object getLobSyncObject()

Implements org.h2.store.DataHandler.getLobSyncObject.

INTERNAL

Returns:Object

Doc from org.h2.store.DataHandler.getLobSyncObject.

the synchronization object

Annotations
@Override
getMaxLengthInplaceLobback to summary
public int getMaxLengthInplaceLob()

Implements org.h2.store.DataHandler.getMaxLengthInplaceLob.

INTERNAL

Returns:int

Doc from org.h2.store.DataHandler.getMaxLengthInplaceLob.

the maximum size

Annotations
@Override
getSQLback to summary
private void getSQL(StringBuilder builder, String column, Value v)
getTempFileDeleterback to summary
public TempFileDeleter getTempFileDeleter()

Implements org.h2.store.DataHandler.getTempFileDeleter.

INTERNAL

Returns:TempFileDeleter

Doc from org.h2.store.DataHandler.getTempFileDeleter.

the temp file deleter

Annotations
@Override
getWriterback to summary
private PrintWriter getWriter(String fileName, String suffix)
isLobTableback to summary
private static boolean isLobTable(String name)
isSchemaObjectTypeDelayedback to summary
private static boolean isSchemaObjectTypeDelayed(MetaRecord m)
mainback to summary
public static void main(String... args) throws SQLException

Options are case sensitive.

Supported options
[-help] or [-?] Print the list of options
[-dir <dir>] The directory (default: .)
[-db <database>] The database name (all databases if not set)
[-trace] Print additional trace information
[-transactionLog] Print the transaction log
Encrypted databases need to be decrypted first.
Parameters
args:String[]

the command line arguments

Exceptions
SQLException:
on failure
openFileback to summary
public FileStore openFile(String name, String mode, boolean mustExist)

Implements org.h2.store.DataHandler.openFile.

INTERNAL

Parameters
name:String

Doc from org.h2.store.DataHandler.openFile.

the file name

mode:String

Doc from org.h2.store.DataHandler.openFile.

the mode

mustExist:boolean

Doc from org.h2.store.DataHandler.openFile.

whether the file must already exist

Returns:FileStore

Doc from org.h2.store.DataHandler.openFile.

the file

Annotations
@Override
processback to summary
private void process(String dir, String db)
readBlobMapback to summary
public static InputStream readBlobMap(Connection conn, long lobId, long precision) throws SQLException

INTERNAL

Parameters
conn:Connection

to use

lobId:long

id of the LOB stream

precision:long

not used

Returns:InputStream

InputStream to read LOB content from

Exceptions
SQLException:
on failure
readClobMapback to summary
public static Reader readClobMap(Connection conn, long lobId, long precision) throws Exception

INTERNAL

Parameters
conn:Connection

to use

lobId:long

id of the LOB stream

precision:long

not used

Returns:Reader

Reader to read LOB content from

Exceptions
SQLException:
on failure
readLobback to summary
public int readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)

Implements org.h2.store.DataHandler.readLob.

INTERNAL

Parameters
lobId:long

Doc from org.h2.store.DataHandler.readLob.

the lob id

hmac:byte[]

Doc from org.h2.store.DataHandler.readLob.

the message authentication code

offset:long

Doc from org.h2.store.DataHandler.readLob.

the offset within the lob

buff:byte[]

Doc from org.h2.store.DataHandler.readLob.

the target buffer

off:int

Doc from org.h2.store.DataHandler.readLob.

the offset within the target buffer

length:int

Doc from org.h2.store.DataHandler.readLob.

the number of bytes to read

Returns:int

Doc from org.h2.store.DataHandler.readLob.

the number of bytes read

Annotations
@Override
resetSchemaback to summary
private void resetSchema()
runToolback to summary
public void runTool(String... args) throws SQLException

Implements abstract org.h2.util.Tool.runTool.

Dumps the contents of a database file to a human readable text file. This text file can be used to recover most of the data. This tool does not open the database and can be used even if the database files are corrupted. A database can get corrupted if there is a bug in the database engine or file system software, or if an application writes into the database file that doesn't understand the file format, or if there is a hardware problem.

Parameters
args:String[]

the command line arguments

Annotations
@Override
Exceptions
SQLException:
on failure
setDatabaseNameback to summary
private void setDatabaseName(String name)
setStorageback to summary
private String setStorage(int storageId)
traceback to summary
private void trace(String message)
traceErrorback to summary
private void traceError(String message, Throwable t)
writeErrorback to summary
private void writeError(PrintWriter writer, Throwable e)
writeMetaRowback to summary
private void writeMetaRow(Row r)
writeSchemaback to summary
private void writeSchema(PrintWriter writer)
writeSchemaSETback to summary
private void writeSchemaSET(PrintWriter writer)