[Webfunds-commits] java/webfunds/store Store.java

Ian Grigg iang@cypherpunks.ai
Mon, 26 Mar 2001 21:43:38 -0400 (AST)


iang        01/03/26 21:43:38

  Modified:    webfunds/store Store.java
  Log:
  lots more comments, added optional existsStore(), more to come

Revision  Changes    Path
1.24      +63 -4     java/webfunds/store/Store.java

Index: Store.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/store/Store.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Store.java	2000/10/07 01:16:35	1.23
+++ Store.java	2001/03/27 01:43:37	1.24
@@ -1,4 +1,4 @@
-/* $Id: Store.java,v 1.23 2000/10/07 01:16:35 iang Exp $
+/* $Id: Store.java,v 1.24 2001/03/27 01:43:37 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-2000 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -51,9 +51,14 @@
     }
 
     /**
-     * Bug.  If this fails because of corruption, there
-     * is no way to recover it, nor any way to remove
-     * (can only remove by Object, not string).
+     *  Get a store.
+     *  If the store did not exist previously, it is created.
+     *
+     *  Bug.  If this fails because of corruption, there
+     *  is no way to recover it, nor any way to remove
+     *  (can only remove by Object, not string).
+     *
+     *  @return an open store, never null
      */
     public Store getStore(String storename)
         throws StoreException
@@ -61,12 +66,66 @@
         return getStore(storename, 0);
     }
 
+    /**
+     *  Get a store.  With some flags set.
+     *  If the store did not exist previously, it is created.
+     *
+     *  Bug.  If this fails because of corruption, there
+     *  is no way to recover it, nor any way to remove
+     *  (can only remove by Object, not string).
+     *
+     *  @return an open store, never null
+     */
     public abstract Store getStore(String storename, int flags)
         throws StoreException;
 
+    /**
+     *  Get all stores within the current store, opened.
+     *
+     *  (Not recursive, the returned list does not return stores
+     *  within stores.)
+     *
+     *  @return a list of all stores, may be empty, never null
+     */
     public abstract Store[] getStores()
         throws StoreException;
 
+    /**
+     *  Does a store exist?  It is hard to know without opening them
+     *  all up with getStores() above.
+     *
+     *  Neither is it relevant, as a getStore() can open it without
+     *  any meaning being attached.  Another signal should be used.
+     *
+     *  (Not recursive, the returned list does not return stores
+     *  within stores.)
+     *
+     *  This should be abstract, but whilst it is being migrated,
+     *  a kludge implementation is provided.
+     *
+     *  @return true of the store is already opened within
+     */
+    public /* abstract */ boolean existsStore(String storename)
+        throws StoreException
+    {
+         Store[] stores = getStores();
+         int i;
+         for (i = 0; i < stores.length; i++)
+         {
+              String name = stores[i].getName();
+              if (name.equals(storename))
+                  return true;
+         }
+         return false;
+    }
+
+    /**
+     *  The name of the store, may also be used for the name of a
+     *  directory or file for storage purposes.  Should be unique
+     *  within the current parent store.
+     *
+     *  @return a name, not empty nor null
+     */
     public String getName()
     {
         return name;