1 package org.sapia.regis.prevayler; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.rmi.RemoteException ; 6 import java.util.Properties ; 7 8 import org.prevayler.Prevayler; 9 import org.prevayler.PrevaylerFactory; 10 import org.sapia.regis.Configurable; 11 import org.sapia.regis.Node; 12 import org.sapia.regis.Path; 13 import org.sapia.regis.RegisSession; 14 import org.sapia.regis.Registry; 15 import org.sapia.regis.impl.NodeImpl; 16 import org.sapia.regis.util.Utils; 17 18 public class PrevaylerRegistry implements Registry, Configurable{ 19 20 private NodeImpl _root = new NodeImpl(null, Node.ROOT_NAME); 21 private Prevayler _prevayler; 22 23 private static RegisSession SESSION = new PrevaylerSession(); 24 25 PrevaylerRegistry(String prevalenceBase, boolean deleteOnStartup) throws Exception { 26 if(deleteOnStartup){ 27 File f = new File (prevalenceBase); 28 if(f.exists()){ 29 Utils.deleteRecurse(f); 30 } 31 f.mkdirs(); 32 } 33 _prevayler = PrevaylerFactory.createPrevayler(_root, prevalenceBase); 34 } 35 36 public Node getRoot() { 37 try{ 38 return (Node)_prevayler.execute(new QueryGetRoot()); 39 }catch(Exception e){ 40 throw new RuntimeException ("Could not get root", e); 41 } 42 } 43 44 public RegisSession open() { 45 return SESSION; 46 } 47 48 public void close() { 49 try{ 50 _prevayler.close(); 51 }catch(IOException e){ 52 } 54 } 55 56 public void load(Path nodePath, String username, String password, String xmlConf, Properties props) throws RemoteException , Exception { 57 TxLoad load = new TxLoad(nodePath, xmlConf, props); 58 _prevayler.execute(load); 59 } 60 61 public void syncLoad(Path nodePath, String username, String password, String xmlConf, Properties props) throws RemoteException , Exception { 62 } 63 64 } 65 | Popular Tags |