package org.mbari.seepsearch.db;

/**
 * Title:        Seep Search Project
 * Description:  The Seep Search project is a sub-project of the Continental Margin Fluids and Gases project (200010). It involves the analysis of archived ROV data to obtain understanding of seep distritution in Monterey Bay.
 * The Purpose of this Java package is to intercompare ROV Navigation files, VIMS data on seep community observations and the EM-300 bathymetry. We are looking for locations where the ROV navigation files and the EM-300 data have similar depths between the 2 data sets, which implies that the ROV is observing the sea floor.
 * Copyright:    Copyright (c) 2001
 * Company:      Monterey Bay Aquarium Research Institute
 * @author Brian Schlining
 * @version 1.0
 */

import java.sql.*;

public class TestVimsConnection {

    public TestVimsConnection() throws ClassNotFoundException,
     SQLException, IllegalAccessException, InstantiationException  {
        this.vc = new VimsConnection();
    }

    public void execute() throws ClassNotFoundException,
     SQLException, IllegalAccessException, InstantiationException  {

        // executeQuery returns a ResultSet
        String query = "SELECT DISTINCT RecordedEpoch, InSequence , " +
         "ISNULL(RTRIM(TapeTimeCode),' ') AS TapeTimeCode1, " +
         "ISNULL(RTRIM(CONVERT(VARCHAR(2),Annotation_TapeNumber)),' ') " +
         "AS TapeNumber1, ISNULL(RTRIM(ConceptName),' ') AS ConceptName1, " +
         "ISNULL(RTRIM(Observer),' ') AS Intpertor1, ObservationID , BLANK AS " +
         "Direction1, BLANK AS Zoom1, BLANK AS Focus1, BLANK AS Iris1, BLANK " +
         "AS FieldWidth1, BLANK AS StillImage1, " +
         "ISNULL(RTRIM(CONVERT(VARCHAR(12),Latitude)),' ') AS Latitude1, " +
         "ISNULL(RTRIM(CONVERT(VARCHAR(13),Longitude)),' ') AS Longitude1, " +
         "ISNULL(RTRIM(CONVERT(VARCHAR(10),Depth)),' ') AS Depth1, " +
         "ISNULL(RTRIM(CONVERT(VARCHAR(10),Temperature)),' ') AS " +
         "Temperature1, ISNULL(RTRIM(CONVERT(VARCHAR(10),Salinity)),' ') " +
         "AS Salinity1, ISNULL(RTRIM(CONVERT(VARCHAR(10),Oxygen)),' ') " +
         "AS Oxygen1, ISNULL(RTRIM(CONVERT(VARCHAR(10),Light)),' ') AS " +
         "Light1, ISNULL(CONVERT(CHAR(4),ShipName),' ') AS ShipName1, " +
         "ISNULL(CONVERT(CHAR(4),PlatformName),' ') AS PlatformName1, " +
         "ISNULL(RTRIM(CONVERT(VARCHAR(6),SeqNumber)),' ') AS DiveNumber1, " +
         "ISNULL(RTRIM(ChiefScientist),' ') AS ChiefScientist1 FROM " +
         "BasicAnnotations  JOIN AncillaryData  ON (AncillaryDataID = " +
         "Annotation_AncillaryDataID) LEFT OUTER JOIN PlatformUsage  ON " +
         "(PlatformUsage_TapeSetID = TapeSetID) AND (UsageStartDTG " +
         "<= RecordedDtg) AND (UsageEndDTG >= RecordedDtg) WHERE " +
         "(TapeSetID > 0)  AND AnnotationID IN (SELECT " +
         "AnnoObserv_AnnotationID FROM AnnoObserv WHERE (LookupName = " +
         "'benthos') )  ORDER BY RecordedEpoch";

        ResultSet rs = vc.executeQuery(query);

        /*
          next moves the cursor to the next row and makes that
          row (called the current row) the one upon which we can operate.

          The cursor is initially positioned just above the first row of a
          ResultSet  object, the first call to the method next  moves the cursor
          to the first row and makes it the current row
         */

         String[] buffer = new String[5]; // Buffer for holding the info
         int[] index = {1, 5, 14, 15, 16}; // The fields that we want
         int[] order = {0, 2, 3, 4, 1};    // The order we wnat to print

         while (rs.next()) {


             for (int i = 0;i < index.length; i++ ) {
                 buffer[i] = rs.getString(index[i]); //or use: String s = rs.getString(1);
             }

             for (int i = 0; i < order.length; i++) {
                 System.out.print(buffer[order[i]] + "\t");
             }

             System.out.println();

         }


    }

    public static void main(String[] args) {

        try {
            TestVimsConnection vims = new TestVimsConnection();
            vims.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private VimsConnection vc;

}