froehlich 01/12/13 05:21:04 Modified: scratchpad/src/org/apache/cocoon/jispstore JispKey.java JispFilesystemStore.java Log: hold,store,get and remove are working now alpha. Revision Changes Path 1.2 +18 -24 xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispKey.java Index: JispKey.java =================================================================== RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispKey.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JispKey.java 2001/12/13 00:04:34 1.1 +++ JispKey.java 2001/12/13 13:21:04 1.2 @@ -13,10 +13,11 @@ import java.io.ObjectOutput; final class JispKey extends KeyObject{ + static final long serialVersionUID = -6894793231339165076L; private String mKey; public JispKey() { - mKey = null; + mKey = new String(""); } public JispKey(String keyValue) { @@ -24,43 +25,36 @@ } public int compareTo(KeyObject key) { - int code = -1; - if (key instanceof JispKey) { - code = System.identityHashCode(this) - - System.identityHashCode(key); - - if(code < 0) { - code = KEY_LESS; - } else if(code > 0) { - code = KEY_MORE; + int comp = mKey.trim().compareTo(((JispKey)key).mKey.trim()); + + if (comp == 0) { + return KEY_EQUAL; } else { - code = KEY_EQUAL; + if (comp < 0) { + return KEY_LESS; + } else { + return KEY_MORE; + } } + } else { + return KEY_ERROR; } - return code; } public KeyObject makeNullKey() { - JispKey nullKey = new JispKey(); - return nullKey; + return new JispKey();; } public void writeExternal(ObjectOutput out) throws IOException { - out.writeObject(mKey); + String outKey; + outKey = new String(mKey); + out.writeUTF(outKey); } public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - mKey = (String)in.readObject(); - } - - public boolean equals(Object obj) - { - if ((obj != null) && (obj instanceof JispKey)) - return (mKey.equals(((JispKey)obj).mKey)); - else - return false; + mKey = in.readUTF(); } public String toString() { 1.2 +43 -35 xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispFilesystemStore.java Index: JispFilesystemStore.java =================================================================== RCS file: /home/cvs/xml-cocoon2/scratchpad/src/org/apache/cocoon/jispstore/JispFilesystemStore.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JispFilesystemStore.java 2001/12/13 00:04:34 1.1 +++ JispFilesystemStore.java 2001/12/13 13:21:04 1.2 @@ -20,7 +20,7 @@ import com.coyotegulch.jisp.IndexedObjectDatabase; import com.coyotegulch.jisp.BTreeIndex; -import com.coyotegulch.jisp.KeyObject; +import com.coyotegulch.jisp.StringKey32; import java.io.File; import java.io.IOException; @@ -35,17 +35,17 @@ Initializable { /** The directory repository */ - protected File directoryFile; - protected volatile String directoryPath; + protected File mDirectoryFile; + protected volatile String mDirectoryPath; /** some statics for the moment */ private static String DATABASE_NAME = "cocoon.data"; private static String INDEX_NAME = "cocoon.idx"; - private static int ORDER = 33; + private static int ORDER = 1001; /** The database */ - private IndexedObjectDatabase database; - private BTreeIndex index; + private IndexedObjectDatabase mDatabase; + private BTreeIndex mIndex; /** * Sets the repository's location @@ -76,17 +76,17 @@ if (myFile.exists()) { this.getLogger().debug("Data file exists"); - database = new IndexedObjectDatabase(getDirectoryPath() + DATABASE_NAME,false); - index = new BTreeIndex(this.getDirectoryPath() + INDEX_NAME); - database.attachIndex(index); - index.dumpTree(); + mDatabase = new IndexedObjectDatabase(getDirectoryPath() + DATABASE_NAME,false); + mIndex = new BTreeIndex(this.getDirectoryPath() + INDEX_NAME); + mDatabase.attachIndex(mIndex); + mIndex.dumpTree(); } else { this.getLogger().debug("Data file not exists"); - database = new IndexedObjectDatabase(getDirectoryPath() + DATABASE_NAME,false); - index = new BTreeIndex(this.getDirectoryPath() + INDEX_NAME, + mDatabase = new IndexedObjectDatabase(getDirectoryPath() + DATABASE_NAME,false); + mIndex = new BTreeIndex(this.getDirectoryPath() + INDEX_NAME, ORDER, new JispKey(),false); - database.attachIndex(index); - index.dumpTree(); + mDatabase.attachIndex(mIndex); + mIndex.dumpTree(); } } catch (Exception e) { getLogger().error("initialize(..) Exception",e); @@ -98,30 +98,30 @@ */ public void setDirectory(final File directory) throws IOException { - this.directoryFile = directory; + this.mDirectoryFile = directory; /* Save directory path prefix */ - this.directoryPath = IOUtils.getFullFilename(this.directoryFile); - this.directoryPath += File.separator; + this.mDirectoryPath = IOUtils.getFullFilename(this.mDirectoryFile); + this.mDirectoryPath += File.separator; /* Does directory exist? */ - if (!this.directoryFile.exists()) { + if (!this.mDirectoryFile.exists()) { /* Create it anew */ - if (!this.directoryFile.mkdir()) { + if (!this.mDirectoryFile.mkdir()) { throw new IOException( - "Error creating store directory '" + this.directoryPath + "': "); + "Error creating store directory '" + this.mDirectoryPath + "': "); } } /* Is given file actually a directory? */ - if (!this.directoryFile.isDirectory()) { - throw new IOException("'" + this.directoryPath + "' is not a directory"); + if (!this.mDirectoryFile.isDirectory()) { + throw new IOException("'" + this.mDirectoryPath + "' is not a directory"); } /* Is directory readable and writable? */ - if (!(this.directoryFile.canRead() && this.directoryFile.canWrite())) { + if (!(this.mDirectoryFile.canRead() && this.mDirectoryFile.canWrite())) { throw new IOException( - "Directory '" + this.directoryPath + "' is not readable/writable" + "Directory '" + this.mDirectoryPath + "' is not readable/writable" ); } } @@ -130,7 +130,7 @@ * Returns the repository's full pathname */ public String getDirectoryPath() { - return this.directoryPath; + return this.mDirectoryPath; } public Object get(Object key) { @@ -138,7 +138,7 @@ Object readObj = null; try { - readObj = database.read(new JispKey(key.toString()),index); + readObj = mDatabase.read(new JispKey(key.toString()),mIndex); if(readObj != null) { this.getLogger().debug("get(): FOUND!!= " + readObj); } else { @@ -156,12 +156,10 @@ //this.remove(key); try { - KeyObject[] keyArray = new JispKey[3]; + JispKey[] keyArray = new JispKey[1]; keyArray[0] = new JispKey(key.toString()); - keyArray[1] = new JispKey(key.toString()); - keyArray[2] = new JispKey(key.toString()); - database.write(keyArray,(Serializable)value); + mDatabase.write(keyArray,(Serializable)value); } catch (Exception e) { this.getLogger().error("store(..): Exception",e); } @@ -179,19 +177,29 @@ this.getLogger().debug("remove(..) Remove item"); try { - KeyObject[] keyArray = new JispKey[3]; + JispKey[] keyArray = new JispKey[1]; keyArray[0] = new JispKey(key.toString()); - keyArray[1] = new JispKey(key.toString()); - keyArray[2] = new JispKey(key.toString()); - database.remove(keyArray); + mDatabase.remove(keyArray); } catch (Exception e) { this.getLogger().error("remove(..): Exception",e); } } public boolean containsKey(Object key) { - return false; + long res = -1; + + try { + res = mIndex.findKey(new JispKey(key.toString())); + this.getLogger().debug("containsKey(..): res=" + res); + } catch (Exception e) { + this.getLogger().error("containsKey(..) Exception",e); + } + if(res > 0) { + return true; + } else { + return false; + } } public Enumeration keys() {
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]