Index: oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>/*\n * Licensed to the Apache Software Foundation (ASF) under one or more\n * contributor license agreements.  See the NOTICE file distributed with\n * this work for additional information regarding copyright ownership.\n * The ASF licenses this file to You under the Apache License, Version 2.0\n * (the \"License\"); you may not use this file except in compliance with\n * the License.  You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\npackage org.apache.jackrabbit.mk.persistence;\n\nimport org.apache.jackrabbit.mk.model.ChildNodeEntries;\nimport org.apache.jackrabbit.mk.model.ChildNodeEntriesMap;\nimport org.apache.jackrabbit.mk.model.Commit;\nimport org.apache.jackrabbit.mk.model.Id;\nimport org.apache.jackrabbit.mk.model.Node;\nimport org.apache.jackrabbit.mk.model.StoredCommit;\nimport org.apache.jackrabbit.mk.model.StoredNode;\nimport org.apache.jackrabbit.mk.store.BinaryBinding;\nimport org.apache.jackrabbit.mk.store.IdFactory;\nimport org.apache.jackrabbit.mk.store.NotFoundException;\nimport org.h2.jdbcx.JdbcConnectionPool;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.ByteArrayOutputStream;\nimport java.io.File;\nimport java.sql.Connection;\nimport java.sql.PreparedStatement;\nimport java.sql.ResultSet;\nimport java.sql.Statement;\nimport java.sql.Timestamp;\n\n/**\n *\n */\npublic class H2Persistence implements GCPersistence {\n\n    private static final boolean FAST = Boolean.getBoolean(\"mk.fastDb\");\n\n    private JdbcConnectionPool cp;\n    private long gcStart;\n    \n    // TODO: make this configurable\n    private IdFactory idFactory = IdFactory.getDigestFactory();\n\n    //---------------------------------------------------< Persistence >\n\n    public void initialize(File homeDir) throws Exception {\n        File dbDir = new File(homeDir, \"db\");\n        if (!dbDir.exists()) {\n            dbDir.mkdirs();\n        }\n\n        Class.forName(\"org.h2.Driver\");\n        String url = \"jdbc:h2:\" + dbDir.getCanonicalPath() + \"/revs\";\n        if (FAST) {\n            url += \";log=0;undo_log=0\";\n        }\n        cp = JdbcConnectionPool.create(url, \"sa\", \"\");\n        cp.setMaxConnections(40);\n        Connection con = cp.getConnection();\n        try {\n            Statement stmt = con.createStatement();\n            stmt.execute(\"create table if not exists REVS(ID binary primary key, DATA binary, TIME timestamp)\");\n            stmt.execute(\"create table if not exists HEAD(ID binary) as select null\");\n            stmt.execute(\"create sequence if not exists DATASTORE_ID\");\n/*\n            DbBlobStore store = new DbBlobStore();\n            store.setConnectionPool(cp);\n            blobStore = store;\n*/\n        } finally {\n            con.close();\n        }\n    }\n\n    public void close() {\n        cp.dispose();\n    }\n\n    public Id readHead() throws Exception {\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con.prepareStatement(\"select * from HEAD\");\n            ResultSet rs = stmt.executeQuery();\n            byte[] rawId = null;\n            if (rs.next()) {\n                rawId = rs.getBytes(1);\n            }\n            stmt.close();\n            return rawId == null ? null : new Id(rawId); \n        } finally {\n            con.close();\n        }\n    }\n\n    public void writeHead(Id id) throws Exception {\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con.prepareStatement(\"update HEAD set ID=?\");\n            stmt.setBytes(1, id.getBytes());\n            stmt.execute();\n            stmt.close();\n        } finally {\n            con.close();\n        }\n    }\n\n    public void readNode(StoredNode node) throws NotFoundException, Exception {\n        Id id = node.getId();\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con.prepareStatement(\"select DATA from REVS where ID = ?\");\n            try {\n                stmt.setBytes(1, id.getBytes());\n                ResultSet rs = stmt.executeQuery();\n                if (rs.next()) {\n                    ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));\n                    node.deserialize(new BinaryBinding(in));\n                } else {\n                    throw new NotFoundException(id.toString());\n                }\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n    }\n\n    public Id writeNode(Node node) throws Exception {\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        node.serialize(new BinaryBinding(out));\n        byte[] bytes = out.toByteArray();\n        byte[] rawId = idFactory.createContentId(bytes);\n        //String id = StringUtils.convertBytesToHex(rawId);\n\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con\n                    .prepareStatement(\n                            \"insert into REVS (ID, DATA, TIME) select ?, ?, CURRENT_TIMESTAMP() where not exists (select 1 from REVS where ID = ?)\");\n            try {\n                stmt.setBytes(1, rawId);\n                stmt.setBytes(2, bytes);\n                stmt.setBytes(3, rawId);\n                stmt.executeUpdate();\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n        return new Id(rawId);\n    }\n\n    public StoredCommit readCommit(Id id) throws NotFoundException, Exception {\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con.prepareStatement(\"select DATA from REVS where ID = ?\");\n            try {\n                stmt.setBytes(1, id.getBytes());\n                ResultSet rs = stmt.executeQuery();\n                if (rs.next()) {\n                    ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));\n                    return StoredCommit.deserialize(id, new BinaryBinding(in));\n                } else {\n                    throw new NotFoundException(id.toString());\n                }\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n    }\n    \n    public void writeCommit(Id id, Commit commit) throws Exception {\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        commit.serialize(new BinaryBinding(out));\n        byte[] bytes = out.toByteArray();\n\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con\n                    .prepareStatement(\n                            \"insert into REVS (ID, DATA, TIME) select ?, ?, CURRENT_TIMESTAMP() where not exists (select 1 from REVS where ID = ?)\");\n            try {\n                stmt.setBytes(1, id.getBytes());\n                stmt.setBytes(2, bytes);\n                stmt.setBytes(3, id.getBytes());\n                stmt.executeUpdate();\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n    }\n\n    public ChildNodeEntriesMap readCNEMap(Id id) throws NotFoundException, Exception {\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con.prepareStatement(\"select DATA from REVS where ID = ?\");\n            try {\n                stmt.setBytes(1, id.getBytes());\n                ResultSet rs = stmt.executeQuery();\n                if (rs.next()) {\n                    ByteArrayInputStream in = new ByteArrayInputStream(rs.getBytes(1));\n                    return ChildNodeEntriesMap.deserialize(new BinaryBinding(in));\n                } else {\n                    throw new NotFoundException(id.toString());\n                }\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n    }\n\n    public Id writeCNEMap(ChildNodeEntries map) throws Exception {\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        map.serialize(new BinaryBinding(out));\n        byte[] bytes = out.toByteArray();\n        byte[] rawId = idFactory.createContentId(bytes);\n\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con\n                    .prepareStatement(\n                            \"insert into REVS (ID, DATA, TIME) select ?, ?, CURRENT_TIMESTAMP() where not exists (select 1 from REVS where ID = ?)\");\n            try {\n                stmt.setBytes(1, rawId);\n                stmt.setBytes(2, bytes);\n                stmt.setBytes(3, rawId);\n                stmt.executeUpdate();\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n        return new Id(rawId);\n    }\n\n    @Override\n    public void start() {\n        gcStart = System.currentTimeMillis();\n    }\n    \n    @Override\n    public boolean markCommit(Id id) throws Exception {\n        return touch(id, gcStart);\n    }\n\n    @Override\n    public void replaceCommit(Id id, Commit commit) throws Exception {\n        ByteArrayOutputStream out = new ByteArrayOutputStream();\n        commit.serialize(new BinaryBinding(out));\n        byte[] bytes = out.toByteArray();\n\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con\n                    .prepareStatement(\n                            \"update REVS set DATA = ?, TIME = CURRENT_TIMESTAMP() where ID = ?\");\n            try {\n                stmt.setBytes(1, bytes);\n                stmt.setBytes(2, id.getBytes());\n                stmt.executeUpdate();\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n    }\n    \n    @Override\n    public boolean markNode(Id id) throws Exception {\n        return touch(id, gcStart);\n    }\n\n    @Override\n    public boolean markCNEMap(Id id) throws Exception {\n        return touch(id, gcStart);\n    }\n    \n    private boolean touch(Id id, long timeMillis) throws Exception {\n        Timestamp ts = new Timestamp(timeMillis);\n\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con\n                    .prepareStatement(\n                            \"update REVS set TIME = ? where ID = ? and TIME < ?\");\n            try {\n                stmt.setTimestamp(1, ts);\n                stmt.setBytes(2, id.getBytes());\n                stmt.setTimestamp(3, ts);\n                return stmt.executeUpdate() == 1;\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n    }\n    \n    @Override\n    public void sweep() throws Exception {\n        Timestamp ts = new Timestamp(gcStart);\n\n        Connection con = cp.getConnection();\n        try {\n            PreparedStatement stmt = con\n                    .prepareStatement(\n                            \"delete REVS where TIME < ?\");\n            try {\n                stmt.setTimestamp(1, ts);\n                stmt.executeUpdate();\n            } finally {\n                stmt.close();\n            }\n        } finally {\n            con.close();\n        }\n     }\n}
===================================================================
--- oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java	(date 1344613995000)
+++ oak-mk/src/main/java/org/apache/jackrabbit/mk/persistence/H2Persistence.java	(revision )
@@ -26,6 +26,7 @@
 import org.apache.jackrabbit.mk.store.BinaryBinding;
 import org.apache.jackrabbit.mk.store.IdFactory;
 import org.apache.jackrabbit.mk.store.NotFoundException;
+import org.h2.Driver;
 import org.h2.jdbcx.JdbcConnectionPool;
 
 import java.io.ByteArrayInputStream;
@@ -58,7 +59,7 @@
             dbDir.mkdirs();
         }
 
-        Class.forName("org.h2.Driver");
+        Driver.load();
         String url = "jdbc:h2:" + dbDir.getCanonicalPath() + "/revs";
         if (FAST) {
             url += ";log=0;undo_log=0";
\ No newline at end of file
