diff --git a/xflaim/util/java/XFlaimTester/src/XFlaimTester.java b/xflaim/util/java/XFlaimTester/src/XFlaimTester.java new file mode 100644 index 0000000..9f62cf7 --- /dev/null +++ b/xflaim/util/java/XFlaimTester/src/XFlaimTester.java @@ -0,0 +1,179 @@ +//------------------------------------------------------------------------------ +// Desc: +// +// Tabs: 3 +// +// Copyright (c) 2003-2006 Novell, Inc. All Rights Reserved. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, contact Novell, Inc. +// +// To contact Novell about this file by physical or electronic mail, +// you may find current contact information at www.novell.com +// +// $Id: $ +//------------------------------------------------------------------------------ + +import java.util.Collections; +import xflaim.*; + +public class XFlaimTester +{ + + public static void main(String[] args) throws XFlaimException + { + DbSystem dbSystem = null; + CREATEOPTS createOpts = null; + Db jDb = null; + PosIStream jIStream = null; + boolean bDone = false; + int iCount = 0; + int iBufferSize; + boolean bCreate = false; + DOMNode jDoc = null; + + try + { + // Initialize the dbSystem so we can do a few things. + + if (dbSystem == null) + { + dbSystem = new DbSystem(); + } + } + catch (XFlaimException e) + { + System.out.println( "Couldn't create the DbSystem. Exception message: " + + e.getMessage()); + System.exit( 0); + } + + while (!bDone) + { + try + { + jDb = dbSystem.dbOpen("tst.db", "", ""); + bDone = true; + System.out.println("Database successfully opened!"); + } + catch (XFlaimException e) + { + bCreate = true; + } + + try + { + // Try to create it. + + if (bCreate) + { + + jDb = dbSystem.dbCreate( "tst.db", "", "", "", "", null); + bDone = true; + System.out.println("Database successfully created!"); + } + } + catch (XFlaimException e) + { + System.out.println( "Database could not be created. Attempting to remove."); + if (iCount < 5) + { + dbSystem.dbRemove("tst.db", "", "", true); + iCount++; + } + else + { + e.printStackTrace(); + System.exit( 0); + } + } + } + + jDb.close(); + jDb = dbSystem.dbOpen("tst.db", "", ""); + + System.out.println("Database successfully re-opened!"); + + // Open a BufferIstream (just for fun) + + String str = "" + + "" + + " 7004df09" + + " 1249" + + " Last of the Juanitas / Time's Up" + + " cddb/rock" + + " Of Course - Nowadays - They Call It Stalking" + + " Make You Cry" + + " Look Bolt the Door" + + " Here It Comes" + + " Time's Up" + + " Big Eyed Space Girl" + + ""; + + try + { + jIStream = dbSystem.openBufferIStream( str); + System.out.println("Created a BufferedIStream"); + } + catch (XFlaimException e) + { + // Can't go any farther. + System.out.println( "Caught openBufferIStream exception: " + e.getMessage()); + e.printStackTrace(); + } + + // Now import a document. + + try + { + // Begin a transaction + + jDb.transBegin( TransactionType.UPDATE_TRANS, 0, 0); + + System.out.println("Began an UPDATE transaction"); + +// jDb.Import(jIStream, 65535); +// +// System.out.println("Imported the document"); + + jDb.transCommit(); + + System.out.println("Committed the transaction"); + } + catch (XFlaimException e) + { + System.out.println( "Caught XFlaim exception: " + e.getMessage()); + e.printStackTrace(); + } + + // Get the first document. + +// try +// { +// jDb.transBegin( TransactionType.READ_TRANS, 0, 0); +// jDoc = jDb.getFirstDocument( Collections.DATA, null); +// jDb.transCommit(); + System.out.println("Got the first document."); +// } +// catch (XFlaimException e) +// { +// System.out.println("Caught getFirstDocument exception: " + e.getMessage()); +// e.printStackTrace(); +// } + + // Now shut down. + + System.out.println("Shutting down"); + jDb.close(); + dbSystem.dbClose(); + } +}