Package com.sleepycat.db

Examples of com.sleepycat.db.Transaction


        dbConfig.setAllowCreate(true);
        dbConfig.setType(DatabaseType.BTREE);

        env = new Environment(dbHome, envConfig);

        Transaction txn = null;

        try {
            txn = env.beginTransaction(null, null);
            index = env.openDatabase(txn, "__index__", null, dbConfig);
            blocks = env.openDatabase(txn, "__blocks__", null, dbConfig);
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            index = null;
            blocks = null;
            throw e;
        } finally {
            if (txn != null)
                txn.commit();
            txn = null;
        }
    }
View Full Code Here


        int duration;
        Date end;
   
        Date veryStart = new Date();
        Date start = new Date();
        Transaction txn = null;
        Directory store = null;

        System.out.println("Writing files byte by byte");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexOutput file = store.createOutput(name);

                totalLength += length;

                for (int j = 0; j < length; j++) {
                    byte b = (byte)(gen.nextInt() & 0x7F);
                    file.writeByte(b);
                }
     
                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to create, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(seed);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexInput file = store.openInput(name);

                if (file.length() != length)
                    throw new Exception("length incorrect");

                for (int j = 0; j < length; j++) {
                    byte b = (byte)(gen.nextInt() & 0x7F);

                    if (file.readByte() != b)
                        throw new Exception("contents incorrect");
                }

                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to read, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(seed);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                store.deleteFile(name);
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();
View Full Code Here

        int duration;
        Date end;
   
        Date veryStart = new Date();
        Date start = new Date();
        Transaction txn = null;
        Directory store = null;

        System.out.println("Writing files as one byte array");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexOutput file = store.createOutput(name);
                byte[] data = new byte[length];

                totalLength += length;
                gen.nextBytes(data);
                file.writeBytes(data, length);
     
                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to create, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(seed);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexInput file = store.openInput(name);
               
                if (file.length() != length)
                    throw new Exception("length incorrect");

                byte[] data = new byte[length];
                byte[] read = new byte[length];
                gen.nextBytes(data);
                file.readBytes(read, 0, length);

                if (!Arrays.equals(data, read))
                    throw new Exception("contents incorrect");

                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to read, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(seed);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                store.deleteFile(name);
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();
View Full Code Here

        dbConfig.setAllowCreate(true);
        dbConfig.setType(DatabaseType.BTREE);

        env = new Environment(dbHome, envConfig);

        Transaction txn = null;

        try {
            txn = env.beginTransaction(null, null);
            index = env.openDatabase(txn, "__index__", null, dbConfig);
            blocks = env.openDatabase(txn, "__blocks__", null, dbConfig);
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            index = null;
            blocks = null;
            throw e;
        } finally {
            if (txn != null)
                txn.commit();
            txn = null;
        }
    }
View Full Code Here

        int duration;
        Date end;
   
        Date veryStart = new Date();
        Date start = new Date();
        Transaction txn = null;
        Directory store = null;

        System.out.println("Writing files byte by byte");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexOutput file = store.createOutput(name);

                totalLength += length;

                for (int j = 0; j < length; j++) {
                    byte b = (byte)(gen.nextInt() & 0x7F);
                    file.writeByte(b);
                }
     
                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to create, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexInput file = store.openInput(name);

                if (file.length() != length)
                    throw new Exception("length incorrect");

                for (int j = 0; j < length; j++) {
                    byte b = (byte)(gen.nextInt() & 0x7F);

                    if (file.readByte() != b)
                        throw new Exception("contents incorrect");
                }

                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to read, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                store.deleteFile(name);
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();
View Full Code Here

        int duration;
        Date end;
   
        Date veryStart = new Date();
        Date start = new Date();
        Transaction txn = null;
        Directory store = null;

        System.out.println("Writing files as one byte array");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexOutput file = store.createOutput(name);
                byte[] data = new byte[length];

                totalLength += length;
                gen.nextBytes(data);
                file.writeBytes(data, length);
     
                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to create, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexInput file = store.openInput(name);
               
                if (file.length() != length)
                    throw new Exception("length incorrect");

                byte[] data = new byte[length];
                byte[] read = new byte[length];
                gen.nextBytes(data);
                file.readBytes(read, 0, length);

                if (!Arrays.equals(data, read))
                    throw new Exception("contents incorrect");

                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to read, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                store.deleteFile(name);
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();
View Full Code Here

        dbConfig.setAllowCreate(true);
        dbConfig.setType(DatabaseType.BTREE);

        env = new Environment(dbHome, envConfig);

        Transaction txn = null;

        try {
            txn = env.beginTransaction(null, null);
            index = env.openDatabase(txn, "__index__", null, dbConfig);
            blocks = env.openDatabase(txn, "__blocks__", null, dbConfig);
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            index = null;
            blocks = null;
            throw e;
        } finally {
            if (txn != null)
                txn.commit();
            txn = null;
        }
    }
View Full Code Here

        int duration;
        Date end;
   
        Date veryStart = new Date();
        Date start = new Date();
        Transaction txn = null;
        Directory store = null;

        System.out.println("Writing files byte by byte");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexOutput file = store.createOutput(name);

                totalLength += length;

                for (int j = 0; j < length; j++) {
                    byte b = (byte)(gen.nextInt() & 0x7F);
                    file.writeByte(b);
                }
     
                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to create, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexInput file = store.openInput(name);

                if (file.length() != length)
                    throw new Exception("length incorrect");

                for (int j = 0; j < length; j++) {
                    byte b = (byte)(gen.nextInt() & 0x7F);

                    if (file.readByte() != b)
                        throw new Exception("contents incorrect");
                }

                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to read, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                store.deleteFile(name);
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();
View Full Code Here

        int duration;
        Date end;
   
        Date veryStart = new Date();
        Date start = new Date();
        Transaction txn = null;
        Directory store = null;

        System.out.println("Writing files as one byte array");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexOutput file = store.createOutput(name);
                byte[] data = new byte[length];

                totalLength += length;
                gen.nextBytes(data);
                file.writeBytes(data, length);
     
                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to create, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                int length = gen.nextInt() & LENGTH_MASK;
                IndexInput file = store.openInput(name);
               
                if (file.length() != length)
                    throw new Exception("length incorrect");

                byte[] data = new byte[length];
                byte[] read = new byte[length];
                gen.nextBytes(data);
                file.readBytes(read, 0, length);

                if (!Arrays.equals(data, read))
                    throw new Exception("contents incorrect");

                file.close();
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();

        duration = (int) (end.getTime() - start.getTime());
        System.out.print(duration);
        System.out.print(" total milliseconds to read, ");
        System.out.print(totalLength / duration);
        System.out.println(" kb/s");

        try {
            txn = env.beginTransaction(null, null);
            store = new DbDirectory(txn, index, blocks);

            gen = new Random(1251971);
            start = new Date();

            for (int i = 0; i < count; i++) {
                String name = i + ".dat";
                store.deleteFile(name);
            }
        } catch (IOException e) {
            txn.abort();
            txn = null;
            throw e;
        } catch (DatabaseException e) {
            if (txn != null)
            {
                txn.abort();
                txn = null;
            }
            throw e;
        } finally {
            if (txn != null)
                txn.commit();

            store.close();
        }

        end = new Date();
View Full Code Here

    public void testForeignKeys()
        throws Exception {

        open();
        Transaction txn = txnBegin();

        Entity1 o1 = new Entity1("pk1", "sk1");
        assertNull(pri1.put(txn, o1));

        assertEquals(o1, pri1.get(txn, "pk1", null));
View Full Code Here

TOP

Related Classes of com.sleepycat.db.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.