From: <sha...@us...> - 2010-10-30 09:24:34
|
Revision: 13058 http://exist.svn.sourceforge.net/exist/?rev=13058&view=rev Author: shabanovd Date: 2010-10-30 09:24:27 +0000 (Sat, 30 Oct 2010) Log Message: ----------- [ignore] fix compilation error & fire right event on creation Modified Paths: -------------- trunk/eXist/extensions/fluent/src/org/exist/fluent/ListenerManager.java trunk/eXist/extensions/synchro/src/org/exist/synchro/WatchCollection.java trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistCollection.java trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistDocument.java trunk/eXist/src/org/exist/collections/triggers/CollectionTrigger.java trunk/eXist/src/org/exist/collections/triggers/XQueryTrigger.java trunk/eXist/src/org/exist/storage/NativeBroker.java trunk/eXist/test/src/org/exist/collections/triggers/XQueryTriggerTest.java Modified: trunk/eXist/extensions/fluent/src/org/exist/fluent/ListenerManager.java =================================================================== --- trunk/eXist/extensions/fluent/src/org/exist/fluent/ListenerManager.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/extensions/fluent/src/org/exist/fluent/ListenerManager.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -254,12 +254,12 @@ EventKey key = new EventKey(documentPath.getCollectionPath(), event, false); INSTANCE.fire(key, key.trigger == Trigger.AFTER_DELETE ? null : document); } - public void prepare(int event, DBBroker broker, Txn txn, org.exist.collections.Collection collection, String newName) throws TriggerException { - EventKey key = new EventKey(newName, event, true); + public void prepare(int event, DBBroker broker, Txn txn, org.exist.collections.Collection collection, org.exist.collections.Collection newCollection) throws TriggerException { + EventKey key = new EventKey(newCollection.getURI().lastSegment().toString(), event, true); INSTANCE.fire(key, collection); } - public void finish(int event, DBBroker broker, Txn txn, org.exist.collections.Collection collection, String newName) { - EventKey key = new EventKey(newName, event, false); + public void finish(int event, DBBroker broker, Txn txn, org.exist.collections.Collection collection, org.exist.collections.Collection newCollection) { + EventKey key = new EventKey(newCollection.getURI().lastSegment().toString(), event, false); INSTANCE.fire(key, key.trigger == Trigger.AFTER_DELETE ? null : collection); } public boolean isValidating() { Modified: trunk/eXist/extensions/synchro/src/org/exist/synchro/WatchCollection.java =================================================================== --- trunk/eXist/extensions/synchro/src/org/exist/synchro/WatchCollection.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/extensions/synchro/src/org/exist/synchro/WatchCollection.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -63,7 +63,7 @@ * @see org.exist.collections.triggers.CollectionTrigger#prepare(int, org.exist.storage.DBBroker, org.exist.storage.txn.Txn, org.exist.collections.Collection, java.lang.String) */ @Override - public void prepare(int event, DBBroker broker, Txn transaction, Collection collection, String newName) throws TriggerException { + public void prepare(int event, DBBroker broker, Txn transaction, Collection collection, Collection newCollection) throws TriggerException { if (comm == null) return; } @@ -71,7 +71,7 @@ * @see org.exist.collections.triggers.CollectionTrigger#finish(int, org.exist.storage.DBBroker, org.exist.storage.txn.Txn, org.exist.collections.Collection, java.lang.String) */ @Override - public void finish(int event, DBBroker broker, Txn transaction, Collection collection, String newName) { + public void finish(int event, DBBroker broker, Txn transaction, Collection collection, Collection newCollection) { if (comm == null) return; switch (event) { Modified: trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistCollection.java =================================================================== --- trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistCollection.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistCollection.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -251,8 +251,12 @@ LOG.error(e); transact.abort(txn); - } finally { + } catch (TriggerException e) { + LOG.error(e); + transact.abort(txn); + } finally { + // TODO: check if can be done earlier if (collection != null) { collection.release(Lock.WRITE_LOCK); @@ -542,8 +546,13 @@ txnManager.abort(txn); throw new EXistException(e.getMessage()); - } finally { + } catch (TriggerException e) { + LOG.error(e); + txnManager.abort(txn); + throw new EXistException(e.getMessage()); + } finally { + if (destCollection != null) { destCollection.release(Lock.WRITE_LOCK); } Modified: trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistDocument.java =================================================================== --- trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistDocument.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/extensions/webdav/src/org/exist/webdav/ExistDocument.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -596,8 +596,13 @@ txnManager.abort(txn); throw new EXistException(e.getMessage()); - } finally { + } catch (TriggerException e) { + LOG.error(e); + txnManager.abort(txn); + throw new EXistException(e.getMessage()); + } finally { + // TODO: check if can be done earlier if (destCollection != null) { destCollection.release(Lock.WRITE_LOCK); Modified: trunk/eXist/src/org/exist/collections/triggers/CollectionTrigger.java =================================================================== --- trunk/eXist/src/org/exist/collections/triggers/CollectionTrigger.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/src/org/exist/collections/triggers/CollectionTrigger.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -48,7 +48,7 @@ DBBroker broker, Txn transaction, Collection collection, - String newName) + Collection newCollection) throws TriggerException; /** @@ -60,5 +60,5 @@ DBBroker broker, Txn transaction, Collection collection, - String newName); + Collection newCollection); } Modified: trunk/eXist/src/org/exist/collections/triggers/XQueryTrigger.java =================================================================== --- trunk/eXist/src/org/exist/collections/triggers/XQueryTrigger.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/src/org/exist/collections/triggers/XQueryTrigger.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -450,7 +450,7 @@ //Collection's methods @Override - public void prepare(int event, DBBroker broker, Txn transaction, Collection collection, String newName) throws TriggerException { + public void prepare(int event, DBBroker broker, Txn transaction, Collection collection, Collection newCollection) throws TriggerException { LOG.debug("Preparing " + eventToString(event) + "XQuery trigger for collection: '" + collection.getURI() + "'"); //get the query @@ -520,7 +520,7 @@ } @Override - public void finish(int event, DBBroker broker, Txn transaction, Collection collection, String newName) { + public void finish(int event, DBBroker broker, Txn transaction, Collection collection, Collection newCollection) { LOG.debug("Finishing " + eventToString(event) + " XQuery trigger for collection : '" + collection.getURI() + "'"); //get the query Modified: trunk/eXist/src/org/exist/storage/NativeBroker.java =================================================================== --- trunk/eXist/src/org/exist/storage/NativeBroker.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/src/org/exist/storage/NativeBroker.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -650,9 +650,36 @@ sub.setId(getNextCollectionId(transaction)); if (transaction != null) transaction.acquireLock(sub.getLock(), Lock.WRITE_LOCK); + + //trigger prepare part + CollectionTrigger trigger = null; + int event = 0; + + CollectionConfiguration config = current.getConfiguration(this); + if (config != null) { + event = Trigger.CREATE_COLLECTION_EVENT; + + try { + trigger = (CollectionTrigger)config.newTrigger(event, this, current); + } catch (CollectionConfigurationException e) { + LOG.debug("An error occurred while initializing a trigger for collection " + current.getURI() + ": " + e.getMessage(), e); + } + if (trigger != null) { + trigger.prepare(event, this, transaction, current, sub); + } + } + + //store collection //TODO : acquire lock manually if transaction is null ? current.addCollection(this, sub, true); saveCollection(transaction, current); + + //trigger finish part + if (trigger != null) { + trigger.finish(event, this, transaction, current, sub); + } + + current = sub; } } @@ -1200,38 +1227,10 @@ // don't cache the collection during initialization: SecurityManager is not yet online pool.getCollectionsCache().add(collection); - CollectionTrigger trigger = null; - int event = 0; - Lock lock = collectionsDb.getLock(); try { lock.acquire(Lock.WRITE_LOCK); - Collection parent; - - XmldbURI parentURI = collection.getParentURI(); - if (parentURI != null) - parent = getCollection(parentURI); - else - parent = collection; - - CollectionConfiguration config = parent.getConfiguration(this); - if (config != null) { - if (collection.getId() == Collection.UNKNOWN_COLLECTION_ID) - event = Trigger.CREATE_COLLECTION_EVENT; - else - event = Trigger.UPDATE_COLLECTION_EVENT; - - try { - trigger = (CollectionTrigger)config.newTrigger(event, this, parent); - } catch (CollectionConfigurationException e) { - LOG.debug("An error occurred while initializing a trigger for collection " + collection.getURI() + ": " + e.getMessage(), e); - } - if (trigger != null) { - trigger.prepare(event, this, transaction, collection, null); - } - } - if (collection.getId() == Collection.UNKNOWN_COLLECTION_ID) collection.setId(getNextCollectionId(transaction)); Value name = new CollectionStore.CollectionKey(collection.getURI().toString()); @@ -1246,10 +1245,6 @@ collection.setAddress(addr); ostream.close(); - if (trigger != null) { - trigger.finish(event, this, transaction, collection, null); - } - } catch (ReadOnlyException e) { LOG.warn(DATABASE_IS_READ_ONLY); } catch (LockException e) { Modified: trunk/eXist/test/src/org/exist/collections/triggers/XQueryTriggerTest.java =================================================================== --- trunk/eXist/test/src/org/exist/collections/triggers/XQueryTriggerTest.java 2010-10-30 08:14:35 UTC (rev 13057) +++ trunk/eXist/test/src/org/exist/collections/triggers/XQueryTriggerTest.java 2010-10-30 09:24:27 UTC (rev 13058) @@ -539,9 +539,8 @@ XPathQueryService query = (XPathQueryService) root.getService("XPathQueryService", "1.0"); - //TODO: wrong - it should be 'trigger4' (create) - ResourceSet result = query.query("/events/event[@id = 'trigger5']"); - assertEquals(4, result.getSize()); + ResourceSet result = query.query("/events/event[@id = 'trigger4']"); + assertEquals(2, result.getSize()); } catch (XMLDBException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |