提交 6391467e authored 作者: Thomas Mueller's avatar Thomas Mueller

--no commit message

--no commit message
上级 0a8384cb
......@@ -414,12 +414,12 @@ public abstract class DataPage {
}
public Value readValue() throws SQLException {
int type = data[pos++];
if (type == '-') {
int dataType = data[pos++];
if (dataType == '-') {
return ValueNull.INSTANCE;
}
type = (type - 'a');
switch (type) {
dataType = (dataType - 'a');
switch (dataType) {
case Value.BOOLEAN:
return ValueBoolean.get(readInt() == 1);
case Value.BYTE:
......@@ -472,7 +472,7 @@ public abstract class DataPage {
if (smallLen >= 0) {
byte[] small = new byte[smallLen];
read(small, 0, smallLen);
return ValueLob.createSmallLob(type, small);
return ValueLob.createSmallLob(dataType, small);
} else {
int tableId = readInt();
int objectId = readInt();
......@@ -483,7 +483,7 @@ public abstract class DataPage {
precision = readLong();
compression = readByte() == 1;
}
ValueLob lob = ValueLob.open(type, handler, tableId, objectId, precision, compression);
ValueLob lob = ValueLob.open(dataType, handler, tableId, objectId, precision, compression);
if (smallLen == -3) {
lob.setFileName(readString());
}
......@@ -499,7 +499,7 @@ public abstract class DataPage {
return ValueArray.get(list);
}
default:
throw Message.getInternalError("type=" + type);
throw Message.getInternalError("type=" + dataType);
}
}
......
......@@ -938,6 +938,14 @@ public class DiskFile implements CacheWriter {
}
}
/**
* Add a redo-log entry to the redo buffer.
*
* @param storage the storage
* @param recordId the record id of the entry
* @param blockCount the number of blocks
* @param rec the record
*/
public void addRedoLog(Storage storage, int recordId, int blockCount, DataPage rec) throws SQLException {
synchronized (database) {
byte[] data = null;
......
......@@ -40,14 +40,46 @@ public class FileStore {
private boolean synchronousMode;
private String mode;
/**
* Open a non encrypted file store with the given settings.
*
* @param handler the data handler
* @param name the file name
* @param mode the access mode (r, rw, rws, rwd)
* @param magic the file header magic bytes
* @return the created object
*/
public static FileStore open(DataHandler handler, String name, String mode, byte[] magic) throws SQLException {
return open(handler, name, mode, magic, null, null, 0);
}
/**
* Open an encrypted file store with the given settings.
*
* @param handler the data handler
* @param name the file name
* @param mode the access mode (r, rw, rws, rwd)
* @param magic the file header magic bytes
* @param cipher the name of the cipher algorithm
* @param key the encryption key
* @return the created object
*/
public static FileStore open(DataHandler handler, String name, String mode, byte[] magic, String cipher, byte[] key) throws SQLException {
return open(handler, name, mode, magic, cipher, key, Constants.ENCRYPTION_KEY_HASH_ITERATIONS);
}
/**
* Open an encrypted file store with the given settings.
*
* @param handler the data handler
* @param name the file name
* @param mode the access mode (r, rw, rws, rwd)
* @param magic the file header magic bytes
* @param cipher the name of the cipher algorithm
* @param key the encryption key
* @param keyIterations the number of iterations the key should be hashed
* @return the created object
*/
public static FileStore open(DataHandler handler, String name, String mode, byte[] magic, String cipher,
byte[] key, int keyIterations) throws SQLException {
FileStore store;
......
......@@ -271,6 +271,14 @@ public class Column {
}
}
/**
* Convert the auto-increment flag to a sequence that is linked with this table.
*
* @param session the session
* @param schema the schema where the sequence should be generated
* @param id the object id
* @param temporary true if the sequence is temporary and does not need to be stored
*/
public void convertAutoIncrementToSequence(Session session, Schema schema, int id, boolean temporary)
throws SQLException {
if (!autoIncrement) {
......
......@@ -19,6 +19,19 @@ import org.h2.util.StringUtils;
* A utility class to create table links for a whole schema.
*/
public class LinkSchema {
/**
* Link all tables of a schema to the database.
*
* @param conn the connection to the database where the links are to be created
* @param targetSchema the schema name where the objects should be created
* @param driver the driver class name of the linked database
* @param url the database URL of the linked database
* @param user the user name
* @param password the password
* @param sourceSchema the schema where the existing tables are
* @return a result set with the created tables
*/
public static ResultSet linkSchema(Connection conn, String targetSchema, String driver, String url, String user,
String password, String sourceSchema) throws SQLException {
Connection c2 = null;
......
......@@ -124,6 +124,17 @@ public class FileUtils {
return FileSystem.getInstance(fileName).length(fileName);
}
/**
* Create a new temporary file.
*
* @param prefix the prefix of the file name (including directory name if
* required)
* @param suffix the suffix
* @param deleteOnExit if the file should be deleted when the virtual
* machine exists
* @param inTempDir if the file should be stored in the temporary directory
* @return the name of the created file
*/
public static String createTempFile(String prefix, String suffix, boolean deleteOnExit, boolean inTempDir)
throws IOException, SQLException {
return FileSystem.getInstance(prefix).createTempFile(prefix, suffix, deleteOnExit, inTempDir);
......
......@@ -190,6 +190,15 @@ public class IOUtils {
}
}
/**
* Read the given number of bytes to the buffer.
*
* @param in the input stream
* @param buffer the output buffer
* @param off the offset in the buffer
* @param max the number of bytes to read at most
* @return the number of bytes read
*/
public static int readFully(InputStream in, byte[] buffer, int off, int max) throws IOException {
int len = Math.min(max, buffer.length);
int result = 0;
......
......@@ -77,6 +77,15 @@ public class JdbcUtils {
}
//#endif
/**
* Create a new database connection with the given settings.
*
* @param driver the driver class name
* @param url the database URL
* @param user the user name
* @param password the password
* @return the database connection
*/
public static Connection getConnection(String driver, String url, String user, String password) throws SQLException {
Properties prop = new Properties();
prop.setProperty("user", user);
......
......@@ -38,6 +38,16 @@ public class MathUtils {
return (int) i;
}
/**
* Increase the value by about 50%. The method is used to increase the file size
* in larger steps.
*
* @param start the smallest possible returned value
* @param min the current value
* @param blockSize the block size
* @param maxIncrease the maximum increment
* @return the new value
*/
public static long scaleUp50Percent(long start, long min, long blockSize, long maxIncrease) {
long len;
if (min > maxIncrease * 2) {
......
......@@ -636,6 +636,15 @@ public class StringUtils {
return sql;
}
/**
* Pad a string. This method is used for the SQL function RPAD and LPAD.
*
* @param string the original string
* @param n the target length
* @param padding the padding string
* @param right true if the padding should be appended at the end
* @return the padded string
*/
public static String pad(String string, int n, String padding, boolean right) {
if (n < 0) {
n = 0;
......
......@@ -326,6 +326,15 @@ public class DataType {
return types;
}
/**
* Read a value from the given result set.
*
* @param session the session
* @param rs the result set
* @param columnIndex the column index (1 based)
* @param type the data type
* @return the value
*/
public static Value readValue(SessionInterface session, ResultSet rs, int columnIndex, int type) throws SQLException {
Value v;
switch(type) {
......@@ -746,6 +755,15 @@ public class DataType {
}
}
/**
* Convert a value to the specified class.
*
* @param session the session
* @param conn the database connection
* @param v the value
* @param paramClass the target class
* @return the converted object
*/
public static Object convertTo(SessionInterface session, JdbcConnection conn, Value v, Class paramClass)
throws SQLException {
if (paramClass == java.sql.Blob.class) {
......
......@@ -104,6 +104,17 @@ public class ValueLob extends Value {
}
}
/**
* Create a LOB value with the given parameters.
*
* @param type the data type
* @param handler the file handler
* @param tableId the table object id
* @param objectId the object id
* @param precision the precision (length in elements)
* @param compression if compression is used
* @return the value object
*/
public static ValueLob open(int type, DataHandler handler, int tableId, int objectId, long precision, boolean compression) {
String fileName = getFileName(handler, tableId, objectId);
return new ValueLob(type, handler, fileName, tableId, objectId, true, precision, compression);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论