kstaken 2002/07/18 20:38:42
Modified: java/src/org/apache/xindice/core Collection.java
Database.java
java/src/org/apache/xindice/core/system Sequencer.java
java/src/org/apache/xindice/server/services
XindiceService.java
Added: java/src/org/apache/xindice/core DBObserver.java
Log:
Adding patches to add observable to collection and some additional facilities
to sequencer
Submitted by: David Viner / David Ku
Reviewed by: Kimbro Staken
Revision Changes Path
1.3 +13 -1
xml-xindice/java/src/org/apache/xindice/core/Collection.java
Index: Collection.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/Collection.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Collection.java 14 Jul 2002 09:35:53 -0000 1.2
+++ Collection.java 19 Jul 2002 03:38:42 -0000 1.3
@@ -214,6 +214,9 @@
}
super.setConfig(config);
+
+ // observer
+ DBObserver.getInstance().setCollectionConfig(this, config);
}
public final String getName() {
@@ -520,6 +523,8 @@
if ( this == getDatabase() )
throw new DBException(FaultCodes.DBE_CANNOT_DROP, "You Cannot Drop
The Database");
+ DBObserver.getInstance().dropCollection(this);
+
// Drop Child Collections
String[] cols = listCollections();
for ( int i = 0; i < cols.length; i++ )
@@ -635,6 +640,9 @@
else
documentCache.putDocument(this, key, document);
}
+
+ DBObserver.getInstance().putDocument(this, key, document,
+ oldDoc == null);
}
/**
@@ -690,6 +698,8 @@
if ( !filer.deleteRecord(objKey) )
throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND, "Document
Does Not Exist");
+
+ DBObserver.getInstance().dropDocument(this, objKey);
}
/**
@@ -724,6 +734,8 @@
doc = parseDocument(key, value.toString());
flushSymbolTable();
+
+ DBObserver.getInstance().loadDocument(this, record, doc);
}
return doc;
}
1.5 +6 -1
xml-xindice/java/src/org/apache/xindice/core/Database.java
Index: Database.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/Database.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Database.java 14 Jul 2002 09:35:53 -0000 1.4
+++ Database.java 19 Jul 2002 03:38:42 -0000 1.5
@@ -170,6 +170,9 @@
// Register the Database with the VM
databases.put(getName(), this);
+
+ // observer
+ DBObserver.getInstance().setDatabaseConfig(this, collections, config);
}
public SystemCollection getSystemCollection() {
@@ -192,6 +195,8 @@
catch ( Exception e ) {
org.apache.xindice.Debug.println(this, "Error Writing Configuration
'"+name+"'");
}
+ // observer
+ DBObserver.getInstance().flushDatabaseConfig(this, config);
}
public boolean close() throws DBException {
1.1
xml-xindice/java/src/org/apache/xindice/core/DBObserver.java
Index: DBObserver.java
===================================================================
package org.apache.xindice.core;
import java.io.File;
import java.io.File;
import java.util.Map;
import org.w3c.dom.Document;
import org.apache.xindice.core.DBException;
import org.apache.xindice.core.Collection;
import org.apache.xindice.core.Database;
import org.apache.xindice.core.data.Key;
import org.apache.xindice.core.data.Record;
import org.apache.xindice.util.Configuration;
/**
* Observer for Xindice DB activities
*/
public abstract class DBObserver
{
private static final DBObserver NOOP = new DBObserver()
{
public void setDatabaseConfig(
Database db, Map collections, Configuration cfg ) {}
public void setCollectionConfig(
Collection col, Configuration cfg ) {}
public void flushDatabaseConfig(
Database db, Configuration cfg ) {}
public void dropCollection( Collection col )
throws DBException {}
public void putDocument(
Collection col, Key key, Document document, boolean create )
throws DBException {}
public void loadDocument(
Collection col, Record record, Document document )
throws DBException {}
public void dropDocument( Collection col, Key key )
throws DBException {}
};
private static DBObserver instance = NOOP;
/**
* Sets the default observer instance
*/
public static void setInstance( DBObserver obs )
{
instance = (null == obs) ? NOOP : obs;
}
/**
* Returns the observer instance, must be non-null
*/
public static DBObserver getInstance()
{
return instance;
}
/**
* Called after Database.setConfig()
*/
public abstract void setDatabaseConfig(
Database db, Map collections, Configuration cfg );
/**
* Called after Collection.setConfig()
*/
public abstract void setCollectionConfig(
Collection col, Configuration cfg );
/**
* Called after Database.flushConfig()
*/
public abstract void flushDatabaseConfig(
Database db, Configuration cfg );
/**
* Called before Collection.drop()
*/
public abstract void dropCollection( Collection col )
throws DBException;
/**
* Called after Collection.putDocument()
*/
public abstract void putDocument(
Collection col, Key key, Document document, boolean create )
throws DBException;
/**
* Called after Collection.getDocument()
*/
public abstract void loadDocument(
Collection col, Record record, Document document )
throws DBException;
/**
* Called before Collection.remove(key)
*/
public abstract void dropDocument( Collection col, Key key )
throws DBException;
}
1.2 +26 -1
xml-xindice/java/src/org/apache/xindice/core/system/Sequencer.java
Index: Sequencer.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/system/Sequencer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Sequencer.java 6 Dec 2001 21:00:15 -0000 1.1
+++ Sequencer.java 19 Jul 2002 03:38:42 -0000 1.2
@@ -124,6 +124,21 @@
}
}
+ public static final String[] PARAMS_list = {};
+ public String list() {
+ checkLoaded();
+
+ Set keys = values.keySet();
+ StringBuffer buffer = new StringBuffer();
+ for( Iterator it = keys.iterator(); it.hasNext(); ) {
+ String key = (String)it.next();
+ buffer.append(key);
+ if( it.hasNext() )
+ buffer.append(",");
+ }
+ return buffer.toString();
+ }
+
public static final String[] PARAMS_create = {"name"};
public void create(String name) {
checkLoaded();
@@ -179,6 +194,16 @@
return sv.next();
else
return -1;
+ }
+
+ public static final String[] PARAMS_contains = {"name", };
+ public boolean contains(String name) {
+ checkLoaded();
+ SequenceValue sv = (SequenceValue)values.get(name);
+ if ( sv != null )
+ return true;
+ else
+ return false;
}
private void write() {
1.2 +16 -1
xml-xindice/java/src/org/apache/xindice/server/services/XindiceService.java
Index: XindiceService.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/server/services/XindiceService.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XindiceService.java 6 Dec 2001 19:33:56 -0000 1.1
+++ XindiceService.java 19 Jul 2002 03:38:42 -0000 1.2
@@ -65,6 +65,7 @@
import org.apache.xindice.util.SimpleConfigurable;
import org.apache.xindice.util.XindiceException;
import org.apache.xindice.core.Database;
+import org.apache.xindice.core.DBObserver;
/**
* XindiceService controls the Xindice server instance.
@@ -74,7 +75,9 @@
public class XindiceService extends SimpleConfigurable
implements Service, KernelAccess {
private static final String ROOT_COLLECTION = "root-collection";
+ private static final String OBSERVER = "db-observer";
private static final String NAME = "name";
+ private static final String CLASS = "class";
protected Kernel kernel;
protected Configuration config;
@@ -90,6 +93,18 @@
try {
this.config = config.getChild(ROOT_COLLECTION);
serviceName = this.config.getAttribute(NAME);
+
+ Configuration obsConfig = config.getChild(OBSERVER);
+ if( null != obsConfig )
+ {
+ String obsClassName = obsConfig.getAttribute(CLASS);
+
+ Class obsClass = Class.forName(obsClassName);
+ DBObserver obs = (DBObserver)obsClass.newInstance();
+ DBObserver.setInstance(obs);
+
+ System.out.println("Register DB Observer: '" + obsClassName +
"'");
+ }
} catch (Exception e) {
org.apache.xindice.Debug.println(this, e);
}