|
From: <rga...@us...> - 2002-12-30 23:55:17
|
Update of /cvsroot/csms/csms-core/src/java/org/fanfoot/db
In directory sc8-pr-cvs1:/tmp/cvs-serv18223
Modified Files:
Players.java ID.java
Log Message:
Add basic support for XML:DB databases
Index: Players.java
===================================================================
RCS file: /cvsroot/csms/csms-core/src/java/org/fanfoot/db/Players.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Players.java 21 Nov 2002 21:59:37 -0000 1.2
--- Players.java 30 Dec 2002 23:55:14 -0000 1.3
***************
*** 37,44 ****
--- 37,48 ----
import java.util.logging.Level;
import java.util.logging.Logger;
+ import javax.xml.transform.TransformerConfigurationException;
+ import javax.xml.transform.TransformerException;
+ import org.apache.commons.jxpath.JXPathContext;
import org.saafe.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+ import org.xmldb.api.base.ResourceIterator;
import org.xmldb.api.base.ResourceSet;
import org.xmldb.api.base.XMLDBException;
***************
*** 135,164 ****
/**
! * Get the scoring events associated with the given game and the
! * given player.
*
! *@param playerID the ID of the player
! *@param gameID the ID of the game
! *@return the Element representing the scoring events from the
! * indicated game. Returns null if no events for that game are
! * recorded
! *@throws DBException if the player cannot be found
*/
! public Element getPlayerScoringEvents( String playerID, String gameID )
throws DBException {
! Element player = getPlayer( playerID );
! NodeList ndl = player.getElementsByTagName( "scoringEvents" );
! Element scoringEvents = (Element) ndl.item( 0 );
! ndl = scoringEvents.getElementsByTagName( "game" );
! Element elem = null;
! for ( int i = 0; i < ndl.getLength(); i++ ) {
! elem = (Element) ndl.item( i );
! if ( elem.getAttribute( "id" ).equals( gameID ) ) {
! break;
! } else {
! elem = null;
! }
! }
! return elem;
}
--- 139,172 ----
/**
! * Get the total score of a player.
*
! *@param id id of player
! *@return total score in the database for the indicated player
! *@throws DBException if there is an error accessing the DB
! *@throws UnknownPlayerException if the player is not found
*/
! public Integer getTotalScore( String id )
! throws DBException, UnknownPlayerException {
! String strScore;
! JXPathContext context;
! context = JXPathContext.newContext( getPlayer( id ) );
! Double dblScore = (Double) context.getValue( "sum(//event/points)" );
!
! return new Integer( dblScore.intValue() );
! }
!
!
! /**
! * Add a scoring event to a player.
! *
! *@param strPlayerID ide of player to add event to
! *@param event an element representing the event
! *@exception DBException Description of the Exception
! *@throws DBExeption if there is a problem updating the DB
! *@fixme ensure that we are not duplicating events
! */
! public void addScoringEvents( String strPlayerID, Element event )
throws DBException {
! addInfo( strPlayerID, event );
}
***************
*** 199,206 ****
--- 207,242 ----
sb.append( position );
sb.append( "</position>" );
+ sb.append( "<scoringEvents/>" );
sb.append( "</player>" );
db.addResource( strID, sb.toString(), COLLECTION_NAME );
}
+
+ /**
+ * Add some info to a pl;ayer record. .
+ *
+ *@param elemInfo the info to be added
+ *@param strPlayerID The feature to be added to the Info attribute
+ *@exception DBException Description of the Exception
+ */
+ public void addInfo( String strPlayerID, Element elemInfo )
+ throws DBException {
+ String update = "//player[@id='" + strPlayerID + "']/scoringEvents";
+ String strInfo;
+ StringBuffer sb = new StringBuffer();
+ try {
+ strInfo = XMLUtils.xmlToString( elemInfo );
+ } catch ( TransformerConfigurationException tce ) {
+ throw new DBException( "Unable to process even element", tce );
+ } catch ( TransformerException te ) {
+ throw new DBException( "Unable to process even element", te );
+ }
+ sb.append( "<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" );
+ sb.append( "<xupdate:append select=\"" + update + "\" >" );
+ sb.append( strInfo );
+ sb.append( "</xupdate:append>" );
+ sb.append( "</xupdate:modifications>" );
+ db.runXUpdateQuery( COLLECTION_NAME, sb.toString() );
+ }
}
Index: ID.java
===================================================================
RCS file: /cvsroot/csms/csms-core/src/java/org/fanfoot/db/ID.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ID.java 21 Nov 2002 21:59:38 -0000 1.1
--- ID.java 30 Dec 2002 23:55:14 -0000 1.2
***************
*** 51,54 ****
--- 51,64 ----
/**
+ * Set the player ID to the supplied value
+ *
+ *@param id The new playerID value
+ */
+ public static void setPlayerID( int id ) {
+ intPlayerID = id;
+ }
+
+
+ /**
* Create an ID number for a player in the indicated postion
*
|