package com.dbxml.db.enterprise.sync;
/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: SyncTrigger.java,v 1.3 2006/02/02 19:04:15 bradford Exp $
*/
import java.util.Date;
import com.dbxml.db.core.Collection;
import com.dbxml.db.core.DBException;
import com.dbxml.db.core.SystemCollection;
import com.dbxml.db.core.data.Key;
import com.dbxml.db.core.transaction.Transaction;
import com.dbxml.db.core.trigger.SimpleTrigger;
/**
* SyncTrigger
*/
public final class SyncTrigger extends SimpleTrigger {
private static final String SYNCMGR_OBJ = "syncmanager";
private SyncManager mgr;
public void setCollection(Collection collection) {
super.setCollection(collection);
try {
SystemCollection sysCol = getCollection().getSystemCollection();
mgr = (SyncManager)sysCol.getExtensionManager().get(SYNCMGR_OBJ);
}
catch ( DBException e ) {
System.err.println("ERROR: Can't retrieve SyncManager Extension");
e.printStackTrace(System.err);
}
}
public void afterDelete(Transaction tx, Key key, Object oldObj) throws DBException {
Content c = mgr.getContent(collection.getCanonicalDocumentName(key), true);
c.setStatus(Constants.STATUS_DELETED);
mgr.storeContent(c);
}
public void afterUpdate(Transaction tx, Key key, Object oldObj, Object newObj) throws DBException {
Content c = mgr.getContent(collection.getCanonicalDocumentName(key), true);
c.setModified(new Date());
mgr.storeContent(c);
}
public void afterInsert(Transaction tx, Key key, Object newObj) throws DBException {
Content c = new Content(collection.getCanonicalDocumentName(key));
mgr.storeContent(c);
}
}