|
From: <rga...@us...> - 2002-12-30 23:55:30
|
Update of /cvsroot/csms/csms-core/src/test/src/org/fanfoot
In directory sc8-pr-cvs1:/tmp/cvs-serv18327
Modified Files:
Data4Tests.java
Log Message:
Add basic support for XML:DB databases
Index: Data4Tests.java
===================================================================
RCS file: /cvsroot/csms/csms-core/src/test/src/org/fanfoot/Data4Tests.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Data4Tests.java 21 Nov 2002 21:57:02 -0000 1.1
--- Data4Tests.java 30 Dec 2002 23:55:27 -0000 1.2
***************
*** 87,111 ****
public void createPlayerCollection() throws DBException {
deletePlayerCollection();
! Collection col = null;
! try {
! String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
! Database database = null;
! try {
! Class c = Class.forName( driver );
! database = (Database) c.newInstance();
! } catch ( ClassNotFoundException cnfe ) {
! throw new DBException( "Cannot find class to connect to DB", cnfe );
! } catch ( InstantiationException ie ) {
! throw new DBException( "Cannot instantiate class to connect to DB", ie );
! } catch ( IllegalAccessException iae ) {
! throw new DBException( "Cannot access class to connect to DB", iae );
! }
! DatabaseManager.registerDatabase( database );
!
! col = DatabaseManager.getCollection( DB_URI );
! if ( col == null ) {
! throw new DBException( "Cannot find the DB collection" );
! }
String strColName = Players.COLLECTION_NAME;
CollectionManager service =
--- 87,93 ----
public void createPlayerCollection() throws DBException {
deletePlayerCollection();
! Collection col = getDBCollection();
+ try {
String strColName = Players.COLLECTION_NAME;
CollectionManager service =
***************
*** 141,165 ****
*/
public void deletePlayerCollection() throws DBException {
! Collection col = null;
! Database database = null;
! try {
! String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
! try {
! Class c = Class.forName( driver );
! database = (Database) c.newInstance();
! } catch ( ClassNotFoundException cnfe ) {
! throw new DBException( "Cannot find class to connect to DB", cnfe );
! } catch ( InstantiationException ie ) {
! throw new DBException( "Cannot instantiate class to connect to DB", ie );
! } catch ( IllegalAccessException iae ) {
! throw new DBException( "Cannot access class to connect to DB", iae );
! }
! DatabaseManager.registerDatabase( database );
!
! col = DatabaseManager.getCollection( DB_URI );
! if ( col == null ) {
! throw new DBException( "Cannot find the db collection" );
! }
CollectionManager service =
(CollectionManager) col.getService( "CollectionManager", "1.0" );
--- 123,129 ----
*/
public void deletePlayerCollection() throws DBException {
! Collection col = getDBCollection();
+ try {
CollectionManager service =
(CollectionManager) col.getService( "CollectionManager", "1.0" );
***************
*** 183,186 ****
--- 147,183 ----
}
+
+
+ private Collection getDBCollection() throws DBException {
+ Collection col = null;
+ String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
+ Database database = null;
+ try {
+ Class c = Class.forName( driver );
+ database = (Database) c.newInstance();
+ } catch ( ClassNotFoundException cnfe ) {
+ throw new DBException( "Cannot find class to connect to DB", cnfe );
+ } catch ( InstantiationException ie ) {
+ throw new DBException( "Cannot instantiate class to connect to DB", ie );
+ } catch ( IllegalAccessException iae ) {
+ throw new DBException( "Cannot access class to connect to DB", iae );
+ }
+ try {
+ DatabaseManager.registerDatabase( database );
+
+ col = DatabaseManager.getCollection( DB_URI );
+ if ( col == null ) {
+ throw new DBException( "Cannot find the DB collection" );
+ }
+ } catch ( XMLDBException e ) {
+ if ( e.errorCode == 201 ) {
+ // collection doesn't exist to delete
+ } else {
+ throw new DBException( "XML:DB Exception occured " + e.errorCode, e );
+ }
+ }
+ return col;
+ }
+
|