Jump to content
McObject Forums

Search the Community

Showing results for tags 'Index'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • McObject Embedded Databases
    • Perst
  • Root2


  • Steven Graves' Blog

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL







Found 2 results

  1. 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
  2. gjshannon

    Indexing and Inheritance 101

    I have what is probably a simple question but cannot find an answer in the tutorial or help topics herein. (Or did I miss the obvious?) It is in regards indexing and inheritance. This is regarding the C# version, although I assume it is a generic question and applies to any platform. I have two classes, A and B. B inherits A (i.e., public class B : A). I also have a random unique identifier for each (string uid;). Right now, to be conservative since I don't really understand inheritance for Perst, I arbitrarily ignore inheritance and treat each class as separate. This includes creating two separate indexes, one for each class, using the unique uid (i.e., public FieldIndex<string, A> classAUidIdx; and public FieldIndex<string, B> classBUidIdx;). It appears that I'm not using an appropriate approach but I don't want to refactor code until I know the consequences/opportunities using one UID unique index for both classes. To whit: If I use one unique uid index for both classes, I assume I first retrieve the base class (class A) using the unique UID index, and then cast it to class B. Is this correct? How do I know whether or not it is class A or B? (Do I need a flag in the base class A identifying what class type it is or will Perst automatically create class B when its really an instance of class B and all I need to do is check its Type (i.e., baseClassAInstance.GetType().Equals(typeof()?). Any info is most appreciated.......if not in the tutorial something on this topic might be a nice enhancement (nothing complex, just simple stuff). Thanks, Regards, George