vgritsenko 2003/08/08 15:38:18
Modified: java/src/org/apache/xindice/client/xmldb/embed
DatabaseImpl.java
java/src/org/apache/xindice/core Collection.java
CollectionManager.java
Log:
Tune up logging (i.e. print canonical collection name in debug header).
Guard log calls.
Minor style changes.
Revision Changes Path
1.17 +12 -4
xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java
Index: DatabaseImpl.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/embed/DatabaseImpl.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DatabaseImpl.java 7 Aug 2003 20:13:20 -0000 1.16
+++ DatabaseImpl.java 8 Aug 2003 22:38:18 -0000 1.17
@@ -123,16 +123,23 @@
String configDir = null;
String configFile =
System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
if (configFile != null && !configFile.equals("")) {
- log.info("Specified configuration file: '" + configFile + "'");
+ if (log.isInfoEnabled()) {
+ log.info("Specified configuration file: '" + configFile +
"'");
+ }
FileInputStream configXMLFile = new FileInputStream(configFile);
+
config = new Configuration(DOMParser.toDocument(configXMLFile),
false);
configDir = new File(configFile).getAbsoluteFile().getParent();
} else {
- log.info("No configuration file specified, going with the
default configuration");
+ if (log.isInfoEnabled()) {
+ log.info("No configuration file specified, going with the
default configuration");
+ }
+
config = new
Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
}
config = config.getChild("root-collection", false);
+
String dbRoot = config.getAttribute(Database.DBROOT,
Database.DBROOT_DEFAULT);
if (!new File(dbRoot).isAbsolute()) {
// Let's see if the property was specified.
@@ -149,6 +156,7 @@
config.setAttribute(Database.DBROOT, new
File(".").getAbsolutePath() + File.separator + dbRoot);
}
}
+
return config;
}
1.29 +126 -72
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.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- Collection.java 8 Aug 2003 13:17:29 -0000 1.28
+++ Collection.java 8 Aug 2003 22:38:18 -0000 1.29
@@ -221,10 +221,11 @@
public Document getNextDocument() throws DBException {
Container c = getNextContainer();
- if (c != null)
+ if (c != null) {
return c.getDocument();
- else
+ } else {
return null;
+ }
}
public boolean hasMoreDocuments() throws DBException {
@@ -250,6 +251,7 @@
private Collection parent = null;
private SymbolTable symbols = null;
+
protected Collection() {
}
@@ -263,8 +265,10 @@
}
private void checkFiler(int faultCode) throws DBException {
- if (filer == null)
- throw new DBException(faultCode, "This Collection '" + name + "'
cannot store Documents");
+ if (filer == null) {
+ throw new DBException(faultCode,
+ "This Collection '" + name + "' cannot
store Documents");
+ }
}
/**
@@ -316,12 +320,15 @@
* @return The newly generated Key
*/
protected final Key createNewKey(Object key) {
- if (key == null)
+ if (key == null) {
return createNewOID();
- if (key instanceof Key)
+ }
+
+ if (key instanceof Key) {
return (Key) key;
- else
+ } else {
return new Key(key.toString());
+ }
}
/**
@@ -334,8 +341,9 @@
long ct = System.currentTimeMillis();
synchronized (oidMutex) {
- if (ct <= document_id)
+ if (ct <= document_id) {
ct = document_id + 1;
+ }
document_id = ct;
}
@@ -350,14 +358,11 @@
private String debugHeader() {
return "["
+ Thread.currentThread().getName()
- + "] Collection:"
- + " name="
+ + "] '"
+ + (parent != null ? parent.getCanonicalName() : "")
+ + "/"
+ name
- + " compressed="
- + compressed
- + " inline-metadata="
- + (inlineMetaService != null)
- + " ";
+ + "' ";
}
/**
@@ -375,12 +380,14 @@
* @see org.apache.xindice.core.DBObject#drop()
*/
public boolean drop() throws DBException {
- if (this == getDatabase())
- throw new DBException(FaultCodes.DBE_CANNOT_DROP, "You Cannot
Drop The Database");
+ if (this == getDatabase()) {
+ throw new DBException(FaultCodes.DBE_CANNOT_DROP,
+ "You Cannot Drop The Database");
+ }
DBObserver.getInstance().dropCollection(this);
- // drop the meta if necessary
+ // Drop the meta if necessary
if (isMetaEnabled()) {
MetaSystemCollection metacol = getMetaSystemCollection();
metacol.dropCollectionMeta(this);
@@ -388,14 +395,16 @@
// Drop Child Collections
String[] cols = listCollections();
- for (int i = 0; i < cols.length; i++)
+ for (int i = 0; i < cols.length; i++) {
dropCollection(getCollection(cols[i]));
+ }
if (filer != null) {
// Drop Indexers
String[] idx = indexManager.list();
- for (int i = 0; i < idx.length; i++)
+ for (int i = 0; i < idx.length; i++) {
dropIndexer(getIndexer(idx[i]));
+ }
// Now Drop The Filer
filer.drop();
@@ -403,7 +412,6 @@
getCollectionRoot().delete();
getDatabase().flushConfig();
-
return true;
}
@@ -426,8 +434,9 @@
public final boolean dropIndexer(Indexer index) throws DBException {
checkFiler(FaultCodes.COL_NO_INDEXMANAGER);
- if (index == null)
+ if (index == null) {
throw new DBException(FaultCodes.IDX_INDEX_NOT_FOUND, "Index
Value Null");
+ }
boolean success = indexManager.drop(index.getName());
getDatabase().flushConfig();
@@ -445,8 +454,9 @@
* @throws DBException
*/
public final void flushSymbolTable() throws DBException {
- if (symbols.isDirty() && !internalSymbols)
+ if (symbols.isDirty() && !internalSymbols) {
getSystemCollection().saveSymbols(this, symbols);
+ }
}
/**
@@ -466,7 +476,8 @@
log.debug(debugHeader() + "getBinary: docKey=<" + docKey.toString()
+ ">");
if (inlineMetaService != null) {
- throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND, "There
are no binary resources in collection" + name + ": inline-metadata is not
enabled.");
+ throw new DBException(FaultCodes.COL_DOCUMENT_NOT_FOUND,
+ "There are no binary resources in
collection" + name + ": inline-metadata is not enabled.");
}
Object entry = getEntry(docKey);
@@ -475,7 +486,8 @@
}
if (!(entry instanceof byte[])) {
- throw new DBException(FaultCodes.COL_INVALID_RESULT, "The
resource associated with key '" + docKey.toString() + "' in collection '" +
name + "'is not binary");
+ throw new DBException(FaultCodes.COL_INVALID_RESULT,
+ "The resource associated with key '" +
docKey.toString() + "' in collection '" + name + "'is not binary");
}
return (byte[]) entry;
@@ -522,6 +534,7 @@
*
* If metadata is not enabled in the configuration, the MetaData object
* returned will be null.
+ *
* @return MetaData this collection's metadata.
*/
public MetaData getCollectionMeta() throws DBException {
@@ -580,7 +593,9 @@
*/
public final Document getDocument(Object docKey) throws DBException {
- log.debug(debugHeader() + "getDocument: docKey=<" +
docKey.toString() + ">");
+ if (log.isTraceEnabled()) {
+ log.trace(debugHeader() + "getDocument: docKey=<" +
docKey.toString() + ">");
+ }
Object entry = getEntry(docKey);
if (entry == null) {
@@ -588,7 +603,8 @@
}
if (!(entry instanceof Document)) {
- throw new DBException(FaultCodes.COL_INVALID_RESULT, "The
resource associated with key '" + docKey.toString() + "' in collection '" +
name + "'is not XML");
+ throw new DBException(FaultCodes.COL_INVALID_RESULT,
+ "The resource associated with key '" +
docKey.toString() + "' in collection '" + name + "'is not XML");
}
return (Document) entry;
@@ -668,9 +684,11 @@
/**
* Retrieve a database entry by key.
+ *
* If no matching entry is found, null is returned; if
* an XML entry is found, a Document is returned; if a
* binary entryis found, byte[] is returned.
+ *
* This low-level method will not update non-inline metadata.
*
* @param docKey identifying the desired database entry
@@ -689,9 +707,8 @@
return null;
}
- String localDebugHeader = debugHeader() + "getEntry: docKey=<" +
docKey.toString() + ">: ";
-
- log.debug(localDebugHeader);
+ final String localDebugHeader = debugHeader() + "getEntry: docKey=<"
+ docKey.toString() + ">: ";
+ log.trace(localDebugHeader);
checkFiler(FaultCodes.COL_NO_FILER);
@@ -707,7 +724,9 @@
*/
if (documentCache != null) {
Document document = documentCache.getDocument(this, key);
- log.debug(localDebugHeader + "cache search returned: " +
document);
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Cache search returned: " +
document);
+ }
if (document != null) {
return document;
}
@@ -718,40 +737,55 @@
return null;
}
- log.debug(localDebugHeader + "record value: length=" +
record.getValue().getLength());
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Record value length=" +
record.getValue().getLength());
+ }
Value value;
InlineMetaMap metaMap = null;
if (inlineMetaService == null) {
- log.debug(localDebugHeader + "type not available");
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Type is not available");
+ }
+
value = record.getValue();
} else {
- log.debug(localDebugHeader + "decomposing header...");
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "Decomposing header...");
+ }
+
InlineMetaService.DatabaseEntry databaseEntry =
inlineMetaService.readDatabaseEntry(record.getValue());
metaMap = databaseEntry.map;
value = databaseEntry.value;
- log.debug(localDebugHeader + "type=" + metaMap.get("type") + "
length=" + value.getLength());
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Type=" + metaMap.get("type") +
", Length=" + value.getLength());
+ }
}
if (inlineMetaService == null ||
metaMap.get("type").equals(ResourceTypeReader.XML)) {
-
- log.debug(localDebugHeader + "XML document");
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "XML document");
+ }
Document document;
if (compressed) {
-
document = new DocumentImpl(value.getData(), symbols, new
NodeSource(this, key));
-
flushSymbolTable();
- log.debug(localDebugHeader + "compressed XML document:
document=<" + TextWriter.toString(document) + ">");
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader
+ + "Compressed XML document=<" +
TextWriter.toString(document) + ">");
+ }
if (documentCache != null) {
documentCache.putDocument(this, key, value.getData());
}
} else {
- log.debug(localDebugHeader + "pre parseDocument(): value=<"
+ value.toString() + ">");
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "Pre parseDocument():
value=<" + value.toString() + ">");
+ }
+
document = parseDocument(key, value.toString());
}
@@ -899,7 +933,8 @@
public Key insertBinary(byte[] bytes) throws DBException {
if (inlineMetaService == null) {
- throw new DBException(FaultCodes.COL_CANNOT_STORE, "Cannot
insert a binary resource in collection " + name + ": inline-metadata is not
enabled.");
+ throw new DBException(FaultCodes.COL_CANNOT_STORE,
+ "Cannot insert a binary resource in
collection " + name + ": inline-metadata is not enabled.");
}
Key key = createNewOID();
@@ -922,7 +957,8 @@
public void insertBinary(Object docKey, byte[] bytes) throws DBException
{
if (inlineMetaService == null) {
- throw new DBException(FaultCodes.COL_CANNOT_STORE, "Cannot
insert a binary resource in collection " + name + ": inline-metadata is not
enabled.");
+ throw new DBException(FaultCodes.COL_CANNOT_STORE,
+ "Cannot insert a binary resource in
collection " + name + ": inline-metadata is not enabled.");
}
putBinary(createNewKey(docKey), bytes, true);
@@ -966,8 +1002,7 @@
* @param obj The Object to insert
*/
public final void insertObject(String key, XMLSerializable obj) throws
DBException {
- putObject(createNewKey(key), obj /*, true */
- );
+ putObject(createNewKey(key), obj /*, true */);
}
/**
@@ -980,8 +1015,7 @@
*/
public final Key insertObject(XMLSerializable obj) throws DBException {
Key key = createNewOID();
- putObject(key, obj /*, true */
- );
+ putObject(key, obj /*, true */);
return key;
}
@@ -1076,7 +1110,8 @@
private void putBinary(Key key, byte[] bytes, boolean create) throws
DBException {
if (inlineMetaService == null) {
- throw new DBException(FaultCodes.COL_CANNOT_STORE, "Cannot store
a binary resource in collection " + name + ": inline-metadata is not enabled");
+ throw new DBException(FaultCodes.COL_CANNOT_STORE,
+ "Cannot store a binary resource in
collection " + name + ": inline-metadata is not enabled");
}
if (!create) {
@@ -1321,8 +1356,9 @@
protected final void setCollectionRoot(File collectionRoot) {
this.collectionRoot = collectionRoot;
- if (!collectionRoot.exists())
+ if (!collectionRoot.exists()) {
collectionRoot.mkdirs();
+ }
}
public void setConfig(Configuration config) throws XindiceException {
@@ -1340,19 +1376,22 @@
* Wait to set up the local debug header until everything needed
* by debugHeader() is complete!
*/
- String localDebugHeader = debugHeader() + "setConfig: ";
-
- if (inlineMetaService == null) {
- log.debug(localDebugHeader + "inline metadata DISABLED");
- } else {
- log.debug(localDebugHeader + "inline metadata ENABLED");
- }
+ final String localDebugHeader = debugHeader() + "setConfig: ";
+ // Set parent
if (parent != null) {
setCanonicalName(parent.getCanonicalName() + '/' + name);
- log.debug(localDebugHeader + "canonical name=<" +
getCanonicalName() + ">");
+ log.debug(localDebugHeader + "Canonical name=<" +
getCanonicalName() + ">");
setCollectionRoot(new File(parent.getCollectionRoot(), name));
- log.debug(localDebugHeader + "collection root=<" +
getCollectionRoot().toString() + ">");
+ log.debug(localDebugHeader + "Root=<" +
getCollectionRoot().toString() + ">");
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader
+ + (compressed ? "Compressed" : "NOT Compressed")
+ + ", "
+ + (inlineMetaService == null ? "Inline metadata
DISABLED" : "Inline metadata ENABLED")
+ );
}
// Init super now, when collectionRoot is known. Otherwise child
collections
@@ -1366,45 +1405,60 @@
// If no Filer is defined, skip Symbols and Indexes
Configuration filerConfig = config.getChild(FILER);
if (filerConfig != null) {
- log.debug(localDebugHeader + "have filer config...");
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "Have filer config...");
+ }
// Symbol Table Setup
Configuration symConfig = config.getChild(SYMBOLS);
internalSymbols = (symConfig != null);
if (internalSymbols) {
- log.debug(localDebugHeader + "have internal symbols <" +
TextWriter.toString(symConfig.getElement()) + ">");
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader
+ + "Internal symbols=<" +
TextWriter.toString(symConfig.getElement()) + ">");
+ }
+
try {
symbols = new SymbolTable(symConfig.getElement());
} catch (Exception e) {
- if (log.isDebugEnabled()) {
- log.debug("Error building symbol table from internal
symbols", e);
+ if (log.isWarnEnabled()) {
+ log.warn("Error building symbol table from internal
symbols", e);
}
}
} else {
- log.debug(localDebugHeader + "no internal symbols...");
+ if (log.isTraceEnabled()) {
+ log.trace(localDebugHeader + "No internal symbols...");
+ }
+
try {
symbols = getSystemCollection().loadSymbols(this);
- log.debug(localDebugHeader + "loaded symbols from system
collection <" + TextWriter.toString(symbols.streamToXML(new DocumentImpl())) +
">");
- } catch (Exception e) {
if (log.isDebugEnabled()) {
- log.debug("Error building symbol table from system
collection...", e);
+ log.debug(localDebugHeader
+ + "Loaded symbols=<" +
TextWriter.toString(symbols.streamToXML(new DocumentImpl())) + ">");
+ }
+ } catch (Exception e) {
+ if (log.isWarnEnabled()) {
+ log.warn("Error building symbol table from system
collection", e);
}
}
}
String className = filerConfig.getAttribute(CLASS);
- log.debug(localDebugHeader + "file class=<" + className + ">");
+ if (log.isDebugEnabled()) {
+ log.debug(localDebugHeader + "Filer class=<" + className +
">");
+ }
try {
filer = (Filer) Class.forName(className).newInstance();
// filer.setCollection(this);
filer.setLocation(getCollectionRoot(), getName());
filer.setConfig(filerConfig);
- if (!filer.exists())
+ if (!filer.exists()) {
filer.create();
+ }
filer.open();
} catch (Exception e) {
if (log.isWarnEnabled()) {
- log.warn("Filer '" + className + "' not available", e);
+ log.warn("Filer '" + className + "' is not available",
e);
}
}
@@ -1513,7 +1567,7 @@
metacol.setCollectionMeta(this, meta);
} catch (DBException e) {
if (log.isWarnEnabled()) {
- log.warn("Error setting the collection meta. " + e);
+ log.warn("Error setting the collection meta", e);
}
return;
}
1.16 +33 -20
xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java
Index: CollectionManager.java
===================================================================
RCS file:
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/CollectionManager.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- CollectionManager.java 7 Aug 2003 20:13:21 -0000 1.15
+++ CollectionManager.java 8 Aug 2003 22:38:18 -0000 1.16
@@ -124,31 +124,39 @@
StringTokenizer st = new StringTokenizer(path, "/");
while (cm != null && st.hasMoreTokens()) {
path = st.nextToken().trim();
- if (path.length() == 0)
+ if (path.length() == 0) {
continue;
- if (st.hasMoreTokens())
+ }
+
+ if (st.hasMoreTokens()) {
cm = (CollectionManager) cm.collections.get(path);
- else
+ } else {
return cm.createCollection(path, cfg);
+ }
}
- throw new DBException(FaultCodes.COL_COLLECTION_NOT_FOUND,
"Parent Collection '" + path + "' doesn't exist");
+
+ throw new DBException(FaultCodes.COL_COLLECTION_NOT_FOUND,
+ "Parent Collection '" + path + "' doesn't
exist");
}
Collection collection = null;
-
- if (CollectionManager.this instanceof Database)
+ if (CollectionManager.this instanceof Database) {
collection = new Collection((Database) CollectionManager.this);
- else
+ } else {
collection = new Collection((Collection) CollectionManager.this);
+ }
try {
// Do a name check to see if all is well
String n = cfg.getAttribute(NAME);
- if (n == null || n.trim().equals(""))
+ if (n == null || n.trim().equals("")) {
throw new DBException(FaultCodes.COL_CANNOT_CREATE, "No name
specified");
+ }
- if (getCollection(n) != null)
- throw new DBException(FaultCodes.COL_DUPLICATE_COLLECTION,
"Duplicate Collection '" + n + "'");
+ if (getCollection(n) != null) {
+ throw new DBException(FaultCodes.COL_DUPLICATE_COLLECTION,
+ "Duplicate Collection '" + n + "'");
+ }
Configuration colConfig = this.config.getChild(COLLECTIONS,
true);
colConfig.add(cfg);
@@ -158,9 +166,11 @@
collections.put(n, collection);
log.info("Created a new collection named '" + n + "'");
} catch (DBException e) {
+ // Do not wrap DBException
throw e;
} catch (Exception e) {
- throw new DBException(FaultCodes.COL_CANNOT_CREATE, "Error
Creating Collection '" + path + "'", e);
+ throw new DBException(FaultCodes.COL_CANNOT_CREATE,
+ "Error Creating Collection '" + path +
"'", e);
}
return collection;
}
@@ -179,17 +189,20 @@
* @return Whether or not the Collection was dropped
*/
public boolean dropCollection(Collection collection) throws DBException {
- if (collection == null)
- throw new DBException(FaultCodes.COL_COLLECTION_NOT_FOUND,
"Collection Value Null");
+ if (collection == null) {
+ throw new DBException(FaultCodes.COL_COLLECTION_NOT_FOUND,
+ "Collection Value Null");
+ }
Collection cm = collection.getParentCollection();
+ if (cm == null) {
+ throw new DBException(FaultCodes.DBE_CANNOT_DROP,
+ "You Cannot Drop The Database");
+ }
- if (cm == null)
- throw new DBException(FaultCodes.DBE_CANNOT_DROP, "You Cannot
Drop The Database");
-
- if (cm != this)
+ if (cm != this) {
return cm.dropCollection(collection);
- else {
+ } else {
final String name = collection.getName();
boolean dropped = collection.drop();
if (dropped) {