001: /*
002: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003: * (http://h2database.com/html/license.html).
004: * Initial Developer: H2 Group
005: */
006: package org.h2.store;
007:
008: import java.sql.SQLException;
009:
010: import org.h2.util.SmallLRUCache;
011: import org.h2.value.Value;
012:
013: /**
014: * A data handler contains a number of callback methods.
015: * The most important implementing class is a database.
016: */
017: public interface DataHandler {
018:
019: /**
020: * Check if text storage is used.
021: *
022: * @return if text storage is used.
023: */
024: boolean getTextStorage();
025:
026: /**
027: * Get the database path.
028: *
029: * @return the database path
030: */
031: String getDatabasePath();
032:
033: /**
034: * Open a file at the given location.
035: *
036: * @param name the file name
037: * @param mode the mode
038: * @param mustExist whether the file must already exist
039: * @return the file
040: */
041: FileStore openFile(String name, String mode, boolean mustExist)
042: throws SQLException;
043:
044: /**
045: * Calculate the checksum for the byte array.
046: *
047: * @param data the byte array
048: * @param start the starting offset
049: * @param end the end offset
050: * @return the checksum
051: */
052: int getChecksum(byte[] data, int start, int end);
053:
054: /**
055: * Check if the simulated power failure occured.
056: * This call will decrement the countdown.
057: *
058: * @throws SQLException if the simulated power failure occured
059: */
060: void checkPowerOff() throws SQLException;
061:
062: /**
063: * Check if writing is allowed.
064: *
065: * @throws SQLException if it is not allowed
066: */
067: void checkWritingAllowed() throws SQLException;
068:
069: /**
070: * Free up disk space if possible.
071: * This method is called if more space is needed.
072: *
073: * @throws SQLException if no more space could be freed
074: */
075: void freeUpDiskSpace() throws SQLException;
076:
077: /**
078: * Called when the checksum was invalid.
079: *
080: * @throws SQLException if this should not be ignored
081: */
082: void handleInvalidChecksum() throws SQLException;
083:
084: /**
085: * Compare two values.
086: *
087: * @param a the first value
088: * @param b the second value
089: * @return 0 for equal, 1 if a is larger than b, and -1 otherwise
090: */
091: int compareTypeSave(Value a, Value b) throws SQLException;
092:
093: /**
094: * Get the maximum length of a in-place large object
095: *
096: * @return the maximum size
097: */
098: int getMaxLengthInplaceLob();
099:
100: /**
101: * Get the compression algorithm used for large objects.
102: *
103: * @param type the data type (CLOB or BLOB)
104: * @return the compression algorithm, or null
105: */
106: String getLobCompressionAlgorithm(int type);
107:
108: /**
109: * Get the next object id.
110: * This method is not required if LOB_FILES_IN_DIRECTORIES is enabled.
111: *
112: * @param needFresh if a fresh id is required
113: * @param dataFile true if the id is for the data file
114: * @return the new id
115: */
116: int allocateObjectId(boolean needFresh, boolean dataFile);
117:
118: /**
119: * Create a temporary file and return the file name.
120: *
121: * @return the file name
122: */
123: String createTempFile() throws SQLException;
124:
125: /**
126: * Get the synchronization object for lob operations.
127: *
128: * @return the synchronization object
129: */
130: Object getLobSyncObject();
131:
132: /**
133: * Checks if the lob files stored in directories.
134: *
135: * @return true if lob files are stored in directories.
136: */
137: boolean getLobFilesInDirectories();
138:
139: /**
140: * Get the lob file list cache if it is used.
141: *
142: * @return the cache or null
143: */
144: SmallLRUCache getLobFileListCache();
145:
146: }
|