Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this file,
   * You can obtain one at http://mozilla.org/MPL/2.0/. */
  
  package pt.webdetails.cda;
  
  import java.io.File;
  
 import  org.apache.commons.logging.Log;
 import  org.apache.commons.logging.LogFactory;
 import  org.dom4j.DocumentException;
Main class to test and execute the CDA in standalone mode User: pedro Date: Feb 1, 2010 Time: 12:30:41 PM
 
 public class CdaExecutor
 {
 
   private static final Log logger = LogFactory.getLog(CdaExecutor.class);
   private static CdaExecutor _instance;
 
 
   protected CdaExecutor()
   {
 
     .debug("Initializing CdaExecutor");
 
 
   }
 
   public static void main(final String[] args)
   {
 
 
     final CdaExecutor cdaExecutor = CdaExecutor.getInstance();
 
     cdaExecutor.doQuery();
 
   }
 
   private void doQuery()
   {
 
 
     try
     {
 
       // Init CDA      
       CdaBoot.getInstance().start();
 
 
       // Define an outputStream
       OutputStream out = .;
 
       // This will test standard query execution
       //testQueryExecution(out);
 
 
       // This will test the block creation
       testBlocks(out);
 
 
     }
     catch (DocumentException e)
     {
       .fatal("Unable to parse settings dom: " + Util.getExceptionDescription(e));
     }
     catch (UnsupportedConnectionException e)
     {
       .fatal("ConnectionException " + Util.getExceptionDescription(e));
     }
     catch (UnsupportedDataAccessException e)
     {
       .fatal("DataAccessException " + Util.getExceptionDescription(e));
     }
     catch (UnknownDataAccessException e)
     {
       .fatal("DataAccess id not found " + Util.getExceptionDescription(e));
     }
     catch (QueryException e)
     {
       .fatal("QueryException " + Util.getExceptionDescription(e));
     }
     catch (UnsupportedExporterException e)
     {
      .fatal("UnsupportedExporterException " + Util.getExceptionDescription(e));
    }
    catch (ExporterException e)
    {
      .fatal("ExporterException " + Util.getExceptionDescription(e));
    }
  }
  private void testBlocks(final OutputStream out)
  {
    .info("Testing CDA file interaction through blocks");
    final SettingsManager settingsManager = SettingsManager.getInstance();
    final File settingsFile = new File("samples/sample-gen.cda");
    final CdaSettings cdaSettings = settingsManager.parseSettingsFile(settingsFile.getAbsolutePath());
    testSingleSqlQuery(outcdaSettings);
  }
//  private void testQueryExecution(final OutputStream out)
//      throws DocumentException, UnsupportedConnectionException, UnsupportedDataAccessException, UnknownDataAccessException, QueryException, UnsupportedExporterException, ExporterException
//  {
//
//    logger.info("Building CDA settings from sample file");
//
//    final SettingsManager settingsManager = SettingsManager.getInstance();
//
//    final File settingsFile = new File("samples/sample.cda");
//    final CdaSettings cdaSettings = settingsManager.parseSettingsFile(settingsFile.getAbsolutePath());
//
//    testSqlQuery(out, cdaSettings);
//
//    //testMondrianQuery(out, cdaSettings);
//
//  }
//  private void testSqlQuery(final OutputStream out, final CdaSettings cdaSettings)
//      throws UnknownDataAccessException, QueryException, UnsupportedExporterException, ExporterException
//  {
//    logger.debug("Doing query on Cda - Initializing CdaEngine");
//    final CdaEngine engine = CdaEngine.getInstance();
//
//    QueryOptions queryOptions = new QueryOptions();
//    queryOptions.setDataAccessId("1");
//    queryOptions.addParameter("orderDate", "2003-04-01");
//    queryOptions.setOutputType("csv");
//    // queryOptions.addParameter("status","In Process");
//
//    logger.info("Doing first query");
//    engine.doQuery(out, cdaSettings, queryOptions);
//
//    logger.info("Doing query with different parameters");
//    queryOptions = new QueryOptions();
//    queryOptions.setDataAccessId("1");
//    queryOptions.addParameter("orderDate", "2004-01-01");
//    engine.doQuery(out, cdaSettings, queryOptions);
//
//    // Querying 2nd time to test cache
//    logger.info("Doing query using the initial parameters - Cache should be used");
//    queryOptions = new QueryOptions();
//    queryOptions.setDataAccessId("1");
//    queryOptions.addParameter("orderDate", "2003-04-01");
//    engine.doQuery(out, cdaSettings, queryOptions);
//
//    // Querying 2nd time to test cache
//    logger.info("Doing query again to see if cache expires");
//    try
//    {
//      Thread.sleep(6000);
//    }
//    catch (InterruptedException e)
//    {
//      e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
//    }
//    engine.doQuery(out, cdaSettings, queryOptions);
//  }
  private void testSingleSqlQuery(final OutputStream outfinal CdaSettings cdaSettings)
  {
    .debug("Doing query on Cda - Initializing CdaEngine");
    final CdaEngine engine = CdaEngine.getInstance();
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.setDataAccessId("1");
    queryOptions.addParameter("orderDate""2003-04-01");
    queryOptions.setOutputType("csv");
    engine.doQuery(outcdaSettingsqueryOptions);
  }
//  private void testMondrianQuery(final OutputStream out, final CdaSettings cdaSettings)
//      throws UnknownDataAccessException, QueryException, UnsupportedExporterException, ExporterException
//  {
//    logger.debug("Doing query on Cda - Initializing CdaEngine");
//    final CdaEngine engine = CdaEngine.getInstance();
//
//    QueryOptions queryOptions = new QueryOptions();
//    queryOptions.setDataAccessId("2");
//    queryOptions.setOutputType("json");
//    queryOptions.addParameter("status", "Shipped");
//
//    logger.info("Doing query");
//    engine.doQuery(out, cdaSettings, queryOptions);
//
//  }
  public static synchronized CdaExecutor getInstance()
  {
    if ( == null)
    {
       = new CdaExecutor();
    }
    return ;
  }
New to GrepCode? Check out our FAQ X