001: /**
002: * Redistribution and use of this software and associated documentation
003: * ("Software"), with or without modification, are permitted provided
004: * that the following conditions are met:
005: *
006: * 1. Redistributions of source code must retain copyright
007: * statements and notices. Redistributions must also contain a
008: * copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the
011: * above copyright notice, this list of conditions and the
012: * following disclaimer in the documentation and/or other
013: * materials provided with the distribution.
014: *
015: * 3. The name "Exolab" must not be used to endorse or promote
016: * products derived from this Software without prior written
017: * permission of Intalio, Inc. For written permission,
018: * please contact info@exolab.org.
019: *
020: * 4. Products derived from this Software may not be called "Exolab"
021: * nor may "Exolab" appear in their names without prior written
022: * permission of Intalio, Inc. Exolab is a registered
023: * trademark of Intalio, Inc.
024: *
025: * 5. Due credit should be given to the Exolab Project
026: * (http://www.exolab.org/).
027: *
028: * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
029: * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
030: * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
031: * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
032: * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
033: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
034: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
035: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
036: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
037: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
038: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
039: * OF THE POSSIBILITY OF SUCH DAMAGE.
040: *
041: * Copyright 2000 (C) Intalio, Inc. All Rights Reserved.
042: *
043: * $Id: Test.java 6963 2007-04-23 22:08:53Z rjoachim $
044: */package dtx;
045:
046: import org.apache.commons.logging.Log;
047: import org.apache.commons.logging.LogFactory;
048: import org.exolab.castor.dtx.*;
049:
050: public class Test {
051:
052: /** The <a href="http://jakarta.apache.org/commons/logging/">Jakarta Commons
053: * Logging </a> instance used for all logging. */
054: private static final Log LOG = LogFactory.getLog(Test.class);
055:
056: static String DATABASE = "database.xml";
057: static String SCHEMA = "product.xsd";
058: static int MAX_ID = 10;
059:
060: public static void main(String[] argv) {
061:
062: Test test = new Test();
063: test.run();
064: }
065:
066: public Test() {
067: }
068:
069: public void run() {
070:
071: try {
072: DTXEngine engine = new DTXEngine();
073:
074: String schemaURL = getClass().getResource(SCHEMA)
075: .toString();
076: LOG.info("Schema URL: " + schemaURL);
077: engine.setSchema(schemaURL);
078: String dbURL = getClass().getResource(DATABASE).toString();
079: LOG.info("DB URL: " + dbURL);
080: engine.setDatabase(dbURL);
081:
082: LOG.info("Setting document handler...");
083:
084: engine.setDocumentHandler(new DemoHandler());
085:
086: LOG.info("Preparing query...");
087:
088: DTXQuery qry = engine
089: .prepareQuery("SELECT p FROM myapp.Product p "
090: + "WHERE p.id = $1 ");
091:
092: LOG.info("Beginning bind-and-execute loop.");
093:
094: for (int i = 0; i < MAX_ID; i++) {
095: LOG.info("Binding id " + i);
096: qry.bind(1, i);
097: LOG.info("Executing for id " + i);
098: qry.execute();
099: LOG.info("Done executing " + i);
100: }
101:
102: DTXQuery multiQuery = engine
103: .prepareQuery("SELECT p FROM myapp.Product p "
104: + "WHERE p.id <= $1 AND p.id >= $2 ");
105:
106: multiQuery.bind(1, 6);
107: multiQuery.bind(2, 4);
108:
109: multiQuery.execute();
110:
111: } catch (DTXException dtxe) {
112: dtxe.printStackTrace();
113: } catch (Exception e) {
114: e.printStackTrace();
115: }
116: }
117: }
|