Jump to content
McObject Forums
Sign in to follow this  
tsichevski

Reading XML with multi-key index: StorageError: Incompatible key type

Recommended Posts

tsichevski    0

Hi support,

I have a problem reading back XML created by Perst. My root object contains an index with two string keys. The database seems to operate Ok, I can successfully export it as XML. The resulting XML looks Ok either. But I got the following exception when I try to read it back:

org.garret.perst.StorageError: Incompatible key type
at org.garret.perst.impl.Btree.checkKey(Btree.java:109)
at org.garret.perst.impl.Btree.insert(Btree.java:180)
at org.garret.perst.impl.XMLImporter.createIndex(XMLImporter.java:509)
at org.garret.perst.impl.XMLImporter.importDatabase(XMLImporter.java:60)
at org.garret.perst.impl.StorageImpl.importXML(StorageImpl.java:2643)
at testperst.TestRepository.testXmlImport(TestRepository.java:43)
...


I use perst-436.jar.

My root class is as follows:

package testperst;

import org.eclipse.jdt.annotation.NonNull;
import org.garret.perst.IPersistent;
import org.garret.perst.Index;
import org.garret.perst.Key;
import org.garret.perst.Persistent;
import org.garret.perst.Storage;

public class MyRoot extends Persistent {
  public MyRoot() {
  }

  public MyRoot(@NonNull Storage storage) {
    super(storage);
    rootIndex = storage.createIndex(new @NonNull Class [] {String.class, String.class}, true);
  }
  
  public void put(@NonNull IPersistent o, @NonNull String a, @NonNull String  {
    @NonNull Key key = new Key(new Object[]{a, b});
    rootIndex.put(key, o);
  }

  private Index rootIndex;
}

The test class is:

package testperst;

import java.io.BufferedReader;

public class TestRepository {
  @Test public void testInitDB() throws Exception {
    Storage db = getStorage();
    getRootIndex(db);
    db.close();
  }

  @Test public void testXmlExport() throws Exception {
    Storage db = getStorage();
    assert db != null;
    try {
      Writer writer = new BufferedWriter(new FileWriter("/tmp/testPerst.xml"));
      db.exportXML(writer);
      writer.close();
    } catch (IOException x) {
      System.err.println("Export failed: " + x);
    }
    db.close();
  }

  @Test public void testXmlImport() throws Exception {
    Storage db = getStorage();
    assert db != null;
    try {
      Reader reader
      = new BufferedReader(new FileReader("/tmp/testPerst.xml"));
      db.importXML(reader);
      reader.close();
    } catch (IOException x) {
      System.err.println("Import failed: " + x);
      throw x;
    }
    db.close();
  }
  
  private @NonNull Storage getStorage() {
    Storage db = StorageFactory.getInstance().createStorage();
    db.open("test.dbs", Storage.DEFAULT_PAGE_POOL_SIZE);
    getRootIndex(db);
    return db;
  }

  private @NonNull MyRoot getRootIndex(@NonNull Storage db) {
    MyRoot o = (MyRoot) db.getRoot();
    if(o == null) {
      o = new MyRoot(db);
      o.put(new Persistent(), "key1", "key2");
      db.setRoot(o);
    }
    return o;
  }

}


The XML is:

<?xml version="1.0" encoding="UTF-8"?>
<database root="4100">
 <testperst.MyRoot id="4100">
  <rootIndex><ref id="4103"/></rootIndex>
 </testperst.MyRoot>
 <org.garret.perst.impl.BtreeCompoundIndex id="4103" unique="1" type0="String" type1="String">
  <ref id="4097" key0="key1" key1="key2"/>
 </org.garret.perst.impl.BtreeCompoundIndex>
 <org.garret.perst.Persistent id="4097">
 </org.garret.perst.Persistent>
</database>

Regards,

Vladimir

Share this post


Link to post
Share on other sites
perstmco    0

Sorry, it is bug in Perst. Here is a patch, which will be incorporated into the next release of Perst.


Index: src/org/garret/perst/impl/BtreeCompoundIndex.java
===================================================================
--- src/org/garret/perst/impl/BtreeCompoundIndex.java (revision 15844)
+++ src/org/garret/perst/impl/BtreeCompoundIndex.java (working copy)
@@ -19,6 +19,7 @@
}

BtreeCompoundIndex(int[] types, boolean unique) {
+ type = ClassDescriptor.tpArrayOfByte;
this.types = types;
this.unique = unique;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×