Author: vgritsenko
Date: Mon Nov 12 09:47:53 2007
New Revision: 594230
URL: http://svn.apache.org/viewvc?rev=594230&view=rev
Log:
rearrange methods
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
Modified: xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java
URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java?rev=594230&r1=594229&r2=594230&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java (original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/Collection.java Mon Nov 12 09:47:53 2007
@@ -243,6 +243,9 @@
this.parent = parent;
}
+
+ // -- Internal Implementation Methods -----------------------------------
+
private void checkFiler(int faultCode) throws DBException {
if (filer == null) {
throw new DBException(faultCode,
@@ -254,19 +257,90 @@
}
}
+ private Key getIdentityKey(Key key) {
+ synchronized (identityMap) {
+ Key id = null;
+ WeakReference ref = (WeakReference) identityMap.get(key);
+ if (ref != null) {
+ id = (Key) ref.get();
+ }
+ if (id == null) {
+ id = key;
+ identityMap.put(id, new WeakReference(id));
+ }
+
+ return id;
+ }
+ }
+
+ private String debugHeader() {
+ return "["
+ + Thread.currentThread().getName()
+ + "] '"
+ + (parent != null ? parent.getCanonicalName() : "")
+ + "/"
+ + name
+ + "' ";
+ }
+
/**
- * @see org.apache.xindice.core.DBObject#close()
+ * @throws DBException if operation failed
*/
- public boolean close() throws DBException {
- // Close children collections first
- super.close();
+ private void flushSymbolTable() throws DBException {
+ if (symbols.isDirty()) {
+ getSystemCollection().saveSymbols(this, symbols);
+ }
+ }
- // Close its own filer
- if (filer != null) {
- indexManager.close();
- filer.close();
+ /**
+ * @param name collection name
+ */
+ protected void setName(String name) {
+ this.name = name;
+ }
+
+ protected final void setCanonicalName(String canonicalName) {
+ this.canonicalName = canonicalName;
+
+ // Calculate The OID Template
+ StringBuffer sb = new StringBuffer("00000000000000000000000000000000");
+ String host = Integer.toString(host_id, 16);
+ sb.insert(8 - host.length(), host);
+
+ String collection = Integer.toString(Math.abs(canonicalName.hashCode()), 16);
+ sb.insert(16 - collection.length(), collection);
+
+ sb.setLength(32);
+ oidTemplate = sb.toString();
+ }
+
+ protected final void setCollectionRoot(File collectionRoot) {
+ this.collectionRoot = collectionRoot;
+ if (!collectionRoot.exists()) {
+ if (log.isTraceEnabled()) {
+ log.trace("Creating directories: " + collectionRoot);
+ }
+ collectionRoot.mkdirs();
}
+ }
+
+
+ // -- Database Object Methods -------------------------------------------
+ public boolean isOpened() {
+ // Collection without filer is always open ... for now.
+ //noinspection SimplifiableIfStatement
+ if (filer == null) {
+ return true;
+ }
+
+ return filer.isOpened();
+ }
+
+ /**
+ * @see org.apache.xindice.core.DBObject#exists()
+ */
+ public boolean exists() throws DBException {
return true;
}
@@ -281,6 +355,178 @@
return true;
}
+ public final boolean open() throws DBException {
+ return true;
+ }
+
+ /**
+ * @see org.apache.xindice.core.DBObject#drop()
+ */
+ public boolean drop() throws DBException {
+ DBObserver.getInstance().dropCollection(this);
+
+ // Drop the meta if necessary
+ if (isMetaEnabled()) {
+ getMetaSystemCollection().dropCollectionMeta(this);
+ }
+
+ // Drop Child Collections
+ String[] cols = listCollections();
+ for (int i = 0; i < cols.length; i++) {
+ dropCollection(getCollection(cols[i]));
+ }
+
+ if (filer != null) {
+ // Drop Indexers and Filer
+ indexManager.drop();
+ filer.drop();
+ }
+
+ getCollectionRoot().delete();
+
+ // Drop symbols
+ if (!symbols.isReadOnly()) {
+ getSystemCollection().dropSymbols(this);
+ }
+
+ getDatabase().flushConfig();
+ return true;
+ }
+
+ /**
+ * @see org.apache.xindice.core.DBObject#close()
+ */
+ public boolean close() throws DBException {
+ // Close children collections first
+ super.close();
+
+ // Close its own filer
+ if (filer != null) {
+ indexManager.close();
+ filer.close();
+ }
+
+ return true;
+ }
+
+
+ // -- CollectionManager methods -----------------------------------------
+
+ public void setConfig(Configuration config) throws XindiceException {
+ name = config.getAttribute(NAME);
+ compressed = config.getBooleanAttribute(COMPRESSED, true);
+
+ /*
+ * If inline metadata is desired, get an InlineMetaService object.
+ */
+ if (config.getBooleanAttribute(INLINE_METADATA, false)) {
+ inlineMetaService = new InlineMetaService();
+ }
+
+ /*
+ * Wait to set up the local debug header until everything needed
+ * by debugHeader() is complete!
+ */
+ final String localDebugHeader = debugHeader() + "setConfig: ";
+
+ // Set parent
+ if (parent != null) {
+ setCanonicalName(parent.getCanonicalName() + '/' + name);
+ setCollectionRoot(new File(parent.getCollectionRoot(), name));
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Root=<" + getCollectionRoot() + ">");
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader
+ + (compressed ? "Compressed" : "NOT Compressed")
+ + ", "
+ + (inlineMetaService == null ? "Inline metadata DISABLED" : "Inline metadata ENABLED")
+ );
+ }
+
+ if (config.getBooleanAttribute(CACHE, true)) {
+ documentCache = getDatabase().getDocumentCache();
+ }
+
+ // If no Filer is defined, skip Symbols and Indexes
+ Configuration filerConfig = config.getChild(FILER);
+ if (filerConfig != null) {
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "Have filer config...");
+ }
+
+ // Symbol Table Setup
+ Configuration symConfig = config.getChild(SYMBOLS);
+ if (symConfig != null) {
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader +
+ "Internal symbols=<" + TextWriter.toString(symConfig.getElement()) + ">");
+ }
+
+ try {
+ symbols = new SymbolTable(symConfig.getElement(), true);
+ } catch (Exception e) {
+ if (log.isWarnEnabled()) {
+ log.warn(localDebugHeader + "Error building symbol table from internal symbols", e);
+ }
+ }
+ } else {
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "No internal symbols...");
+ }
+
+ try {
+ symbols = getSystemCollection().loadSymbols(this);
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Loaded symbols=<" +
+ TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
+ }
+ } catch (Exception e) {
+ if (log.isWarnEnabled()) {
+ log.warn(localDebugHeader + "Error loading symbol table from system collection", e);
+ }
+ }
+ }
+
+ String className = filerConfig.getAttribute(CLASS);
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Filer class=<" + className + ">");
+ }
+ try {
+ filer = (Filer) Class.forName(className).newInstance();
+ filer.setLocation(getCollectionRoot(), getName());
+ filer.setConfig(filerConfig);
+ if (!filer.exists()) {
+ filer.create();
+ }
+ filer.open();
+ } catch (Exception e) {
+ if (log.isWarnEnabled()) {
+ log.warn("Filer '" + className + "' is not available", e);
+ }
+ }
+
+ // Index Manager
+ try {
+ indexManager = new IndexManager(this, getDatabase().getTimer());
+ Configuration idxConfig = config.getChild(INDEXES, true);
+ indexManager.setConfig(idxConfig);
+ } catch (Exception e) {
+ if (log.isWarnEnabled()) {
+ log.warn("Failed to initialize indexer", e);
+ }
+ }
+ }
+
+ // Last thing to do is to init child collections
+ super.setConfig(config);
+
+ // observer
+ DBObserver.getInstance().setCollectionConfig(this, config);
+ }
+
/**
* @see CollectionManager#createCollection(String, Configuration)
*/
@@ -291,6 +537,136 @@
}
/**
+ * @see CollectionManager#dropCollection(Collection)
+ */
+ public final boolean dropCollection(Collection collection) throws DBException {
+ boolean success = super.dropCollection(collection);
+ getDatabase().flushConfig();
+ return success;
+ }
+
+ // -- Core Collection API Public Methods --------------------------------
+
+ /**
+ * getDatabase returns the Database owner for this Collection.
+ *
+ * @return The Database
+ */
+ public Database getDatabase() {
+ return parent.getDatabase();
+ }
+
+ /**
+ * getParentCollection returns the parent Collection of this
+ * Collection.
+ *
+ * @return The parent Collection (or null)
+ * @throws DBException if operation failed
+ */
+ public final Collection getParentCollection() throws DBException {
+ return parent;
+ }
+
+
+ /**
+ * getSystemCollection returns the System Collection.
+ *
+ * @return The System Collection
+ */
+ public SystemCollection getSystemCollection() {
+ return getDatabase().getSystemCollection();
+ }
+
+ /**
+ * Return the MetaSystemCollection for the database containing this
+ * collection.
+ *
+ * @return MetaSystemCollection
+ */
+ private MetaSystemCollection getMetaSystemCollection() {
+ return getDatabase().getMetaSystemCollection();
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * getCanonicalName returns the canonical name of this Collection.
+ * <br>
+ * ex: /local/test/ocs
+ *
+ * @return The canonical name of the Collection
+ */
+ public final String getCanonicalName() {
+ return canonicalName;
+ }
+
+ /**
+ * getCanonicalDocumentName returns the canonical name for the specified
+ * Key in relation to this Collection.
+ * <br>
+ * ex: /local/test/ocs/ytd
+ *
+ * @param key The Key
+ * @return The canonical name
+ */
+ public final String getCanonicalDocumentName(Key key) {
+ return getCanonicalDocumentName(key.toString());
+ }
+
+ /**
+ * From the document key and this collection canonical name,
+ * composes canonical document name.
+ *
+ * @param key document key
+ * @return The canonical document name
+ */
+ public final String getCanonicalDocumentName(String key) {
+ return canonicalName + '/' + key;
+ }
+
+ /**
+ * @return The collection root
+ */
+ public final File getCollectionRoot() {
+ return collectionRoot;
+ }
+
+ /**
+ * getSymbols returns the SymbolTable in use by this
+ * Collection.
+ *
+ * @return The Symbol Table
+ */
+ public final SymbolTable getSymbols() {
+ return symbols;
+ }
+
+ /**
+ * getFiler returns the low-level Filer instance underlying the
+ * Collection instance.
+ *
+ * @return The requested Filer
+ */
+ public final Filer getFiler() {
+ return filer;
+ }
+
+ /**
+ * getQueryEngine returns the Database's Query Engine
+ *
+ * @return The Query Engine
+ * @throws DBException if operation failed
+ */
+ public QueryEngine getQueryEngine() throws DBException {
+ return getDatabase().getQueryEngine();
+ }
+
+
+ // ----------------------------------------------------------------------
+
+ /**
* createIndexer creates a new Indexer object and any associated
* system resources that the Indexer will need.
*
@@ -345,59 +721,6 @@
return new Key(sb.toString());
}
- private String debugHeader() {
- return "["
- + Thread.currentThread().getName()
- + "] '"
- + (parent != null ? parent.getCanonicalName() : "")
- + "/"
- + name
- + "' ";
- }
-
- /**
- * @see org.apache.xindice.core.DBObject#drop()
- */
- public boolean drop() throws DBException {
- DBObserver.getInstance().dropCollection(this);
-
- // Drop the meta if necessary
- if (isMetaEnabled()) {
- getMetaSystemCollection().dropCollectionMeta(this);
- }
-
- // Drop Child Collections
- String[] cols = listCollections();
- for (int i = 0; i < cols.length; i++) {
- dropCollection(getCollection(cols[i]));
- }
-
- if (filer != null) {
- // Drop Indexers and Filer
- indexManager.drop();
- filer.drop();
- }
-
- getCollectionRoot().delete();
-
- // Drop symbols
- if (!symbols.isReadOnly()) {
- getSystemCollection().dropSymbols(this);
- }
-
- getDatabase().flushConfig();
- return true;
- }
-
- /**
- * @see CollectionManager#dropCollection(Collection)
- */
- public final boolean dropCollection(Collection collection) throws DBException {
- boolean success = super.dropCollection(collection);
- getDatabase().flushConfig();
- return success;
- }
-
/**
* dropIndexer physically removes the specified Indexer and any
* associated system resources that the Indexer uses.
@@ -420,22 +743,6 @@
}
/**
- * @see org.apache.xindice.core.DBObject#exists()
- */
- public boolean exists() throws DBException {
- return true;
- }
-
- /**
- * @throws DBException if operation failed
- */
- public final void flushSymbolTable() throws DBException {
- if (symbols.isDirty()) {
- getSystemCollection().saveSymbols(this, symbols);
- }
- }
-
- /**
* Retrieve a binary database entry by key.
* This low-level method will not update non-inline metadata.
*
@@ -473,45 +780,6 @@
}
/**
- * getCanonicalDocumentName returns the canonical name for the specified
- * Key in relation to this Collection.
- * <br>
- * ex: /local/test/ocs/ytd
- *
- * @param key The Key
- * @return The canonical name
- */
- public final String getCanonicalDocumentName(Key key) {
- return getCanonicalDocumentName(key.toString());
- }
-
- /**
- * From the document key and this collection canonical name,
- * composes canonical document name.
- *
- * @param key document key
- * @return The canonical document name
- */
- public final String getCanonicalDocumentName(String key) {
- StringBuffer sb = new StringBuffer();
- sb.append(canonicalName);
- sb.append('/');
- sb.append(key);
- return sb.toString();
- }
-
- /**
- * getCanonicalName returns the canonical name for this Object.
- * <br>
- * ex: /local/test/ocs
- *
- * @return The canonical name
- */
- public final String getCanonicalName() {
- return canonicalName;
- }
-
- /**
* Return the MetaData for this collection.
*
* If metadata is not enabled in the configuration, the MetaData object
@@ -536,14 +804,7 @@
metacol.setCollectionMeta(this, meta);
}
- return meta;
- }
-
- /**
- * @return The collection root
- */
- public final File getCollectionRoot() {
- return collectionRoot;
+ return meta;
}
/**
@@ -562,15 +823,6 @@
}
/**
- * getDatabase returns the Database owner for this Collection.
- *
- * @return The Database
- */
- public Database getDatabase() {
- return parent.getDatabase();
- }
-
- /**
* getDocument retrieves a Document by Key.
*
* @param key The Document Key
@@ -628,7 +880,7 @@
Key key = getIdentityKey(createNewKey(id));
synchronized (key) {
- if (null == getEntry(id)) {
+ if (getEntry(id) == null) {
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
"Resource '" + id + "' does not exist in '" + getCanonicalName() + "'");
}
@@ -653,7 +905,7 @@
// this is wrong.. but it should work for now...
long now = System.currentTimeMillis();
- if (null == meta) {
+ if (meta == null) {
meta = new MetaData(MetaData.DOCUMENT, getCanonicalDocumentName(id), now, now);
metacol.setDocumentMeta(this, id, meta);
} else if (!meta.hasContext()) {
@@ -836,16 +1088,6 @@
}
/**
- * getFiler returns the low-level Filer instances underlying the
- * Collection instance.
- *
- * @return The requested Filer
- */
- public final Filer getFiler() {
- return filer;
- }
-
- /**
* getIndexer retrieves an Indexer by name.
*
* @param name The Indexer name
@@ -869,20 +1111,6 @@
}
/**
- * Return the MetaSystemCollection for the database containing this
- * collection.
- *
- * @return MetaSystemCollection
- */
- private MetaSystemCollection getMetaSystemCollection() {
- return getDatabase().getMetaSystemCollection();
- }
-
- public final String getName() {
- return name;
- }
-
- /**
* getObject instantiates and returns an XMLSerializable object based on the
* provided Key. Xindice takes care of instantiating the correct class, but
* only if a class was registered with the Document in the first place.
@@ -926,46 +1154,6 @@
}
/**
- * getParentCollection returns the parent Collection of this
- * Collection.
- *
- * @return The parent Collection (or null)
- * @throws DBException if operation failed
- */
- public final Collection getParentCollection() throws DBException {
- return parent;
- }
-
- /**
- * getQueryEngine returns the Database's Query Engine
- *
- * @return The Query Engine
- * @throws DBException if operation failed
- */
- public QueryEngine getQueryEngine() throws DBException {
- return getDatabase().getQueryEngine();
- }
-
- /**
- * getSymbols returns the SymbolTable in use by this
- * Collection.
- *
- * @return The Symbol Table
- */
- public final SymbolTable getSymbols() {
- return symbols;
- }
-
- /**
- * getSystemCollection returns the System Collection.
- *
- * @return The System Collection
- */
- public SystemCollection getSystemCollection() {
- return getDatabase().getSystemCollection();
- }
-
- /**
* Insert a binary object into a Xindice Collection. A unique key
* is automatically generated. by which the binary object can be
* retrieved in the future. Note: because the key is automatically
@@ -1083,16 +1271,6 @@
return getDatabase().isMetaEnabled();
}
- public boolean isOpened() {
- // Collection without filer is always open ... for now.
- //noinspection SimplifiableIfStatement
- if (filer == null) {
- return true;
- }
-
- return filer.isOpened();
- }
-
/**
* listDocuments returns a list of all entry keys stored by this
* collection.
@@ -1134,10 +1312,6 @@
return indexManager.list();
}
- public final boolean open() throws DBException {
- return true;
- }
-
/**
* Turns an XML string into a parsed document retrieved
* from the uncompressed collection.
@@ -1455,21 +1629,6 @@
DBObserver.getInstance().dropDocument(this, objKey);
}
- protected final void setCanonicalName(String canonicalName) {
- this.canonicalName = canonicalName;
-
- // Calculate The OID Template
- StringBuffer sb = new StringBuffer("00000000000000000000000000000000");
- String host = Integer.toString(host_id, 16);
- sb.insert(8 - host.length(), host);
-
- String collection = Integer.toString(Math.abs(canonicalName.hashCode()), 16);
- sb.insert(16 - collection.length(), collection);
-
- sb.setLength(32);
- oidTemplate = sb.toString();
- }
-
/**
* Reset the metadata object for this collection.
*
@@ -1497,131 +1656,6 @@
}
}
- protected final void setCollectionRoot(File collectionRoot) {
- this.collectionRoot = collectionRoot;
- if (!collectionRoot.exists()) {
- if (log.isTraceEnabled()) {
- log.trace("Creating directories: " + collectionRoot);
- }
- collectionRoot.mkdirs();
- }
- }
-
- public void setConfig(Configuration config) throws XindiceException {
- name = config.getAttribute(NAME);
- compressed = config.getBooleanAttribute(COMPRESSED, true);
-
- /*
- * If inline metadata is desired, get an InlineMetaService object.
- */
- if (config.getBooleanAttribute(INLINE_METADATA, false)) {
- inlineMetaService = new InlineMetaService();
- }
-
- /*
- * Wait to set up the local debug header until everything needed
- * by debugHeader() is complete!
- */
- final String localDebugHeader = debugHeader() + "setConfig: ";
-
- // Set parent
- if (parent != null) {
- setCanonicalName(parent.getCanonicalName() + '/' + name);
- setCollectionRoot(new File(parent.getCollectionRoot(), name));
- if (log.isDebugEnabled()) {
- log.debug(localDebugHeader + "Root=<" + getCollectionRoot() + ">");
- }
- }
-
- if (log.isDebugEnabled()) {
- log.debug(localDebugHeader
- + (compressed ? "Compressed" : "NOT Compressed")
- + ", "
- + (inlineMetaService == null ? "Inline metadata DISABLED" : "Inline metadata ENABLED")
- );
- }
-
- if (config.getBooleanAttribute(CACHE, true)) {
- documentCache = getDatabase().getDocumentCache();
- }
-
- // If no Filer is defined, skip Symbols and Indexes
- Configuration filerConfig = config.getChild(FILER);
- if (filerConfig != null) {
- if (log.isTraceEnabled()) {
- log.trace(localDebugHeader + "Have filer config...");
- }
-
- // Symbol Table Setup
- Configuration symConfig = config.getChild(SYMBOLS);
- if (symConfig != null) {
- if (log.isTraceEnabled()) {
- log.trace(localDebugHeader +
- "Internal symbols=<" + TextWriter.toString(symConfig.getElement()) + ">");
- }
-
- try {
- symbols = new SymbolTable(symConfig.getElement(), true);
- } catch (Exception e) {
- if (log.isWarnEnabled()) {
- log.warn(localDebugHeader + "Error building symbol table from internal symbols", e);
- }
- }
- } else {
- if (log.isTraceEnabled()) {
- log.trace(localDebugHeader + "No internal symbols...");
- }
-
- try {
- symbols = getSystemCollection().loadSymbols(this);
- if (log.isDebugEnabled()) {
- log.debug(localDebugHeader + "Loaded symbols=<" +
- TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
- }
- } catch (Exception e) {
- if (log.isWarnEnabled()) {
- log.warn(localDebugHeader + "Error loading symbol table from system collection", e);
- }
- }
- }
-
- String className = filerConfig.getAttribute(CLASS);
- if (log.isDebugEnabled()) {
- log.debug(localDebugHeader + "Filer class=<" + className + ">");
- }
- try {
- filer = (Filer) Class.forName(className).newInstance();
- filer.setLocation(getCollectionRoot(), getName());
- filer.setConfig(filerConfig);
- if (!filer.exists()) {
- filer.create();
- }
- filer.open();
- } catch (Exception e) {
- if (log.isWarnEnabled()) {
- log.warn("Filer '" + className + "' is not available", e);
- }
- }
-
- // Index Manager
- try {
- indexManager = new IndexManager(this, getDatabase().getTimer());
- Configuration idxConfig = config.getChild(INDEXES, true);
- indexManager.setConfig(idxConfig);
- } catch (Exception e) {
- if (log.isWarnEnabled()) {
- log.warn("Failed to initialize indexer", e);
- }
- }
- }
-
- // Last thing to do is to init child collections
- super.setConfig(config);
-
- // observer
- DBObserver.getInstance().setCollectionConfig(this, config);
- }
-
/**
* setDocument inserts or updates an existing Document in a
* Xindice Collection.
@@ -1712,13 +1746,6 @@
}
/**
- * @param name collection name
- */
- protected void setName(String name) {
- this.name = name;
- }
-
- /**
* setObject sets an XMLSerializable object in the Collection based on the
* provided Key. Xindice takes care of associating the implementation class
* with the XMLSerializable object.
@@ -1816,21 +1843,5 @@
}
metacol.setDocumentMeta(this, id, meta);
- }
-
- private Key getIdentityKey(Key key) {
- synchronized (identityMap) {
- Key id = null;
- WeakReference ref = (WeakReference) identityMap.get(key);
- if (ref != null) {
- id = (Key) ref.get();
- }
- if (id == null) {
- id = key;
- identityMap.put(id, new WeakReference(id));
- }
-
- return id;
- }
}
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.