vgritsenko 2003/08/08 15:53:30
Modified: java/src/org/apache/xindice/core MetaSystemCollection.java Log: Two changes: * Bootstrap meta collection with all system collections. This is done in order to avoid StackOverflowException during startup: to create meta collection, you have to update system collection, to update system collection you have to update meta data, to update meta data you have to create meta collection, go to beginning. * When dropping collection, use super.dropCollection instead of coll.drop() to avoid FilerClosedException due to stale collection in memory. Revision Changes Path 1.8 +40 -32 xml-xindice/java/src/org/apache/xindice/core/MetaSystemCollection.java Index: MetaSystemCollection.java =================================================================== RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/core/MetaSystemCollection.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- MetaSystemCollection.java 8 Aug 2003 13:29:24 -0000 1.7 +++ MetaSystemCollection.java 8 Aug 2003 22:53:30 -0000 1.8 @@ -84,32 +84,35 @@ public static final String METAS = "Metas"; public static final String COLLECTION_META_DATA = "_META_DATA_"; + private static String METACOL_DEFINITION + = "<collection name=\"" + METACOL + "\">" + // Meta System Collections + + " <collections>" + // Meta Collections + + " <collection name=\"" + METAS + "\" compressed=\"true\">" + + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" + + " <collections>" + // Add Meta collections for System collections to avoid eternal loop during initialization + + SystemCollection.getDefinition() + + " </collections>" + + " </collection>" + + " </collections>" + + "</collection>"; + private String dbCanonicalName; - private String metaCanonicalName; public MetaSystemCollection(Database db) { super(db); + + // Set the canonical names + dbCanonicalName = db.getCanonicalName(); } public void init() throws DBException { - // Bootstrap the System Collection - - String MetaCol - = "<collection name=\"" + METACOL + "\">" -// Meta System Collections - + " <collections>" -// Meta Collections - + " <collection name=\"" - + METAS - + "\" compressed=\"true\">" - + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" - + " </collection>" - + " </collections>" - + "</collection>"; - + // Bootstrap the Meta Collection try { - Document metaDoc = DOMParser.toDocument(MetaCol); + Document metaDoc = DOMParser.toDocument(METACOL_DEFINITION); Configuration metaCfg = new Configuration(metaDoc, false); setConfig(metaCfg); } catch (Exception e) { @@ -118,10 +121,6 @@ } System.exit(1); } - - // set the canonical names - dbCanonicalName = getParentCollection().getCanonicalName(); - metaCanonicalName = getCanonicalName(); } /** @@ -136,28 +135,34 @@ String path = collection.getCanonicalName(); // different database - if (!path.startsWith(dbCanonicalName)) + if (!path.startsWith(dbCanonicalName)) { return null; + } // this is a meta collection - if (path.startsWith(metaCanonicalName)) + if (path.startsWith(getCanonicalName())) { return null; + } Collection current = getCollection(METAS); StringTokenizer st = new StringTokenizer(path.substring(dbCanonicalName.length()), "/"); while (current != null && st.hasMoreTokens()) { String segment = st.nextToken().trim(); - if (segment.length() == 0) + if (segment.length() == 0) { continue; + } Collection childcol = current.getCollection(segment); if (null == childcol) { - if (!create) + if (!create) { return null; + } - String cfgText = - "<collection name=\"" + segment + "\" compressed=\"true\">" + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" + "</collection>"; + String cfgText + = "<collection name=\"" + segment + "\" compressed=\"true\">" + + " <filer class=\"org.apache.xindice.core.filer.BTreeFiler\" />" + + "</collection>"; try { Document cfgDoc = DOMParser.toDocument(cfgText); @@ -185,7 +190,7 @@ Collection mcol = getMetaCollection(collection, false); if (null != mcol) { try { - mcol.drop(); + dropCollection(mcol); } catch (DBException e) { // fail silently } @@ -224,8 +229,9 @@ * @param meta The MetaData */ public void setCollectionMeta(Collection collection, MetaData meta) throws DBException { - if (null == meta) + if (null == meta) { return; + } Collection mcol = getMetaCollection(collection, true); if (null != mcol) { @@ -264,6 +270,7 @@ Collection mcol = getMetaCollection(collection, true); if (null != mcol) { MetaData meta = (MetaData) mcol.getObject(id); + if (meta == null) { meta = new MetaData(); } @@ -286,8 +293,9 @@ * @param meta The MetaData */ public void setDocumentMeta(Collection collection, String id, MetaData meta) throws DBException { - if (null == meta) + if (null == meta) { return; + } Collection mcol = getMetaCollection(collection, true); if (null != mcol) {