001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.mlm.plugin.ldm;
028:
029: import org.cougaar.glm.ldm.oplan.Oplan;
030:
031: /** Reads oplan info from a database table. Assumes it's being invoked on
032: * behalf of SQLOplanPlugin. Updates oplan maintained by SQLOplanPlugin.
033: */
034:
035: public class OplanQueryHandler extends SQLOplanQueryHandler {
036: private static final String QUERY_NAME = "OplanInfoQuery";
037:
038: private String myOperationName;
039: private String myPriority;
040:
041: //private Date myCday;
042:
043: /** this method is called before a query is started,
044: * before even getQuery. The default method is empty
045: * but may be overridden.
046: **/
047: public void startQuery() {
048: }
049:
050: /** Construct and return an SQL query to be used by the Database engine.
051: * Subclasses are required to implement this method.
052: **/
053: public String getQuery() {
054: return (String) getParameter(QUERY_NAME);
055: }
056:
057: /** Process a single row in a result set,
058: * doing whatever is required.
059: **/
060: public void processRow(Object[] rowData) {
061: if (rowData.length != 2) {
062: System.err
063: .println("OplanQueryHandler.processRow()- expected 2 columns of data, "
064: + " got " + rowData.length);
065: }
066: try {
067: if (rowData[0] instanceof String)
068: myOperationName = (String) rowData[0];
069: else
070: myOperationName = new String((byte[]) rowData[0],
071: "US-ASCII");
072:
073: if (rowData[1] instanceof String)
074: myPriority = (String) rowData[1];
075: else
076: myPriority = new String((byte[]) rowData[1], "US-ASCII");
077:
078: } catch (Exception usee) {
079: System.err
080: .println("Caught exception while executing a query: "
081: + usee);
082: usee.printStackTrace();
083: }
084:
085: }
086:
087: /** this method is called when a query is complete,
088: * afer the last call to processRow. The default method is empty
089: * but may be overridden by subclasses.
090: **/
091: public void endQuery() {
092: String oplanID = getParameter(OplanReaderPlugin.OPLAN_ID_PARAMETER);
093: //should already have this oplan
094: Oplan oplan = (Oplan) myPlugin.getOplan(oplanID).clone();
095: oplan.setOperationName(myOperationName);
096: oplan.setPriority(myPriority);
097:
098: myPlugin.updateOplanInfo(oplan);
099: }
100: }
|