Search in sources :

Example 91 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class TestAll method addTest.

private void addTest(TestBase test) {
    // tests.add(test);
    // run directly for now, because concurrently running tests
    // fails on Raspberry Pi quite often (seems to be a JVM problem)
    // event queue watchdog for tests that get stuck when running in Jenkins
    final java.util.Timer watchdog = new java.util.Timer();
    // 5 minutes
    watchdog.schedule(new TimerTask() {

        @Override
        public void run() {
            ThreadDeadlockDetector.dumpAllThreadsAndLocks("test watchdog timed out");
        }
    }, 5 * 60 * 1000);
    try {
        test.runTest(this);
    } finally {
        watchdog.cancel();
    }
}
Also used : TestTimer(org.h2.test.synth.TestTimer) TimerTask(java.util.TimerTask)

Example 92 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class TestAll method testEverything.

/**
 * Run all tests in all possible combinations.
 */
private void testEverything() throws SQLException {
    for (int c = 0; c < 2; c++) {
        if (c == 0) {
            cipher = null;
        } else {
            cipher = "AES";
        }
        for (int a = 0; a < 64; a++) {
            smallLog = (a & 1) != 0;
            big = (a & 2) != 0;
            networked = (a & 4) != 0;
            memory = (a & 8) != 0;
            ssl = (a & 16) != 0;
            diskResult = (a & 32) != 0;
            for (int trace = 0; trace < 3; trace++) {
                traceLevelFile = trace;
                test();
            }
        }
    }
}
Also used : TestCheckpoint(org.h2.test.db.TestCheckpoint)

Example 93 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class CreateScriptFile method openScriptReader.

/**
 * Open a script reader.
 *
 * @param fileName the file name (the file will be overwritten)
 * @param compressionAlgorithm the compression algorithm (uppercase)
 * @param cipher the encryption algorithm or null
 * @param password the encryption password
 * @param charset the character set (for example UTF-8)
 * @return the script reader
 */
public static LineNumberReader openScriptReader(String fileName, String compressionAlgorithm, String cipher, String password, String charset) throws IOException {
    try {
        InputStream in;
        if (cipher != null) {
            byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
            FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
            store.init();
            in = new FileStoreInputStream(store, null, compressionAlgorithm != null, false);
            in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE_COMPRESS);
        } else {
            in = FileUtils.newInputStream(fileName);
            in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
            in = CompressTool.wrapInputStream(in, compressionAlgorithm, "script.sql");
            if (in == null) {
                throw new IOException("Entry not found: script.sql in " + fileName);
            }
        }
        return new LineNumberReader(new InputStreamReader(in, charset));
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : FileStore(org.h2.store.FileStore) InputStreamReader(java.io.InputStreamReader) FileStoreInputStream(org.h2.store.FileStoreInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 94 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class ValueLobDb method createTempClob.

/**
 * Create a temporary CLOB value from a stream.
 *
 * @param in the reader
 * @param length the number of characters to read, or -1 for no limit
 * @param handler the data handler
 * @return the lob value
 */
public static ValueLobDb createTempClob(Reader in, long length, DataHandler handler) {
    if (length >= 0) {
        // blocks the network level
        try {
            in = new RangeReader(in, 0, length);
        } catch (IOException e) {
            throw DbException.convert(e);
        }
    }
    BufferedReader reader;
    if (in instanceof BufferedReader) {
        reader = (BufferedReader) in;
    } else {
        reader = new BufferedReader(in, Constants.IO_BUFFER_SIZE);
    }
    try {
        boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
        long remaining = Long.MAX_VALUE;
        if (length >= 0 && length < remaining) {
            remaining = length;
        }
        int len = getBufferSize(handler, compress, remaining);
        char[] buff;
        if (len >= Integer.MAX_VALUE) {
            String data = IOUtils.readStringAndClose(reader, -1);
            buff = data.toCharArray();
            len = buff.length;
        } else {
            buff = new char[len];
            reader.mark(len);
            len = IOUtils.readFully(reader, buff, len);
        }
        if (len <= handler.getMaxLengthInplaceLob()) {
            byte[] small = new String(buff, 0, len).getBytes(StandardCharsets.UTF_8);
            return ValueLobDb.createSmallLob(Value.CLOB, small, len);
        }
        reader.reset();
        return new ValueLobDb(handler, reader, remaining);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    }
}
Also used : RangeReader(org.h2.store.RangeReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 95 with In

use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.

the class TestMVRTree method testExample.

private void testExample() {
    // create an in-memory store
    MVStore s = MVStore.open(null);
    // open an R-tree map
    MVRTreeMap<String> r = s.openMap("data", new MVRTreeMap.Builder<String>());
    // add two key-value pairs
    // the first value is the key id (to make the key unique)
    // then the min x, max x, min y, max y
    r.add(new SpatialKey(0, -3f, -2f, 2f, 3f), "left");
    r.add(new SpatialKey(1, 3f, 4f, 4f, 5f), "right");
    // iterate over the intersecting keys
    Iterator<SpatialKey> it = r.findIntersectingKeys(new SpatialKey(0, 0f, 9f, 3f, 6f));
    for (SpatialKey k; it.hasNext(); ) {
        k = it.next();
        // System.out.println(k + ": " + r.get(k));
        assertNotNull(k);
    }
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) SpatialKey(org.h2.mvstore.rtree.SpatialKey) MVRTreeMap(org.h2.mvstore.rtree.MVRTreeMap)

Aggregations

SQLException (java.sql.SQLException)63 Connection (java.sql.Connection)59 DbException (org.h2.message.DbException)56 PreparedStatement (java.sql.PreparedStatement)54 ResultSet (java.sql.ResultSet)47 Statement (java.sql.Statement)44 Value (org.h2.value.Value)40 IOException (java.io.IOException)39 ByteArrayInputStream (java.io.ByteArrayInputStream)30 InputStream (java.io.InputStream)29 Column (org.h2.table.Column)24 ArrayList (java.util.ArrayList)23 SimpleResultSet (org.h2.tools.SimpleResultSet)23 Random (java.util.Random)19 Expression (org.h2.expression.Expression)18 JdbcConnection (org.h2.jdbc.JdbcConnection)18 Index (org.h2.index.Index)16 ValueString (org.h2.value.ValueString)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 IgniteSQLException (org.apache.ignite.internal.processors.query.IgniteSQLException)15