Author: thomasm
Date: Tue May 31 10:01:05 2011
New Revision: 1129595
URL: http://svn.apache.org/viewvc?rev=1129595&view=rev
Log:
Store the head revision id in the database.
Modified:
jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java?rev=1129595&r1=1129594&r2=1129595&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/store/H2RevisionStore.java
Tue May 31 10:01:05 2011
@@ -49,7 +49,6 @@ public class H2RevisionStore extends Sim
if (!homeDir.exists()) {
homeDir.mkdirs();
}
- headRev = new PersistentId(new File(homeDir, "HEAD"));
dataDir = new File(homeDir, "db");
if (!dataDir.exists()) {
dataDir.mkdir();
@@ -60,12 +59,9 @@ public class H2RevisionStore extends Sim
cp.setMaxConnections(40);
Connection con = cp.getConnection();
try {
- ResultSet rs = con.getMetaData().getTables(null, null, "REVS", null);
- if (!rs.next()) {
- Statement stmt = con.createStatement();
- stmt.execute("create table REVS (ID binary primary key, DATA binary)");
- stmt.close();
- }
+ Statement stmt = con.createStatement();
+ stmt.execute("create table if not exists REVS (ID binary primary key, DATA binary)");
+ stmt.execute("create table if not exists head(id varchar) as select ''");
} finally {
con.close();
}
@@ -83,6 +79,40 @@ public class H2RevisionStore extends Sim
initialized = false;
}
+ public String getHeadRevision() throws Exception {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ Connection con = cp.getConnection();
+ try {
+ PreparedStatement stmt = con.prepareStatement("select * from head");
+ ResultSet rs = stmt.executeQuery();
+ rs.next();
+ String head = rs.getString(1);
+ stmt.close();
+ return head;
+ } finally {
+ con.close();
+ }
+ }
+
+ public void setHeadRevision(String revId) throws Exception {
+ if (!initialized) {
+ throw new IllegalStateException("not initialized");
+ }
+
+ Connection con = cp.getConnection();
+ try {
+ PreparedStatement stmt = con.prepareStatement("update head set id=?");
+ stmt.setString(1, revId);
+ stmt.execute();
+ stmt.close();
+ } finally {
+ con.close();
+ }
+ }
+
public InputStream get(String id) throws Exception {
if (!initialized) {
throw new IllegalStateException("not initialized");
|