Example usage for java.sql SQLException fillInStackTrace

List of usage examples for java.sql SQLException fillInStackTrace

Introduction

In this page you can find the example usage for java.sql SQLException fillInStackTrace.

Prototype

public synchronized Throwable fillInStackTrace() 

Source Link

Document

Fills in the execution stack trace.

Usage

From source file:uk.nhs.cfh.dsp.srth.query.transform.sql.impl.AbstractSQLQueryEngineService.java

/**
 * Adds the index on column on table./*from  ww w.j  a  v  a2 s  .c  o  m*/
 *
 * @param tableName the table name
 * @param st the st
 * @param columnName the column name
 * @param collection the collection
 */
private void addIndexOnColumnOnTable(String tableName, Statement st, String columnName,
        QueryStatisticsCollection collection) {
    // create index creation statements
    String createIndexStatement = "ALTER TABLE " + tableName + " ADD INDEX IDX_" + columnName.toUpperCase()
            + "(" + columnName + ")";
    try {
        st.execute(createIndexStatement);
        collection.getCommentedSteps().add("Created index on " + tableName + " using statement : ");
        collection.getCommentedSteps().add(createIndexStatement);
        collection.getSqlSteps().add(createIndexStatement);
    } catch (SQLException e) {
        logger.warn(e.fillInStackTrace());
    }
}

From source file:uk.nhs.cfh.dsp.srth.query.transform.sql.impl.AbstractSQLQueryEngineService.java

/**
 * Gets the table name for reporting query.
 *
 * @param query the query// w  ww  . ja  v  a 2  s.co m
 *
 * @return the table name for reporting query
 *
 */
public String getTableNameForReportingQuery(QueryStatement query) {

    String tableName = null;
    // clear existing table names in table names map
    statsMap.clear();
    tableColumnsMap.clear();
    // reset counters
    resetCounters();
    long startTime = Calendar.getInstance().getTimeInMillis();
    /*
       * we know any query will only ever have one clinical expression inside it.
       * This can be a union object, intersection object or a sub query object.
       */
    List<QueryExpression> expressions = new ArrayList<QueryExpression>(query.getContainedExpressions());
    if (expressions.size() == 1) {
        try {
            tableName = getTableNameForExpression(expressions.get(0));
            if (logger.isDebugEnabled()) {
                logger.debug("Obtained tableName for query in getTableNameForReportingQuery : " + tableName);
            }

            QueryStatisticsCollection collection = new QueryStatisticsCollection(query,
                    queryExpressionXMLRenderer);
            checkAndPopulateQueryStatistics(startTime, tableName, collection, query);

        } catch (SQLException e) {
            logger.warn("SQL error encountered executing query. Nested exception is : "
                    + e.fillInStackTrace().getMessage());
        }
    } else {
        throw new IllegalExpressionsNumberException("\nNumber of expressions in query : " + expressions.size());
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Value of tableName in getTableNameForReportingQuery : " + tableName);
    }

    return tableName;
}

From source file:uk.nhs.cfh.dsp.srth.query.transform.sql.impl.AbstractSQLQueryEngineService.java

/**
 * Gets the result set for reporting query.
 *
 * @param query the query/*w  w w. jav  a  2 s  .  c  om*/
 *
 * @return the result set for reporting query
 *
 */
public ResultSet getResultSetForReportinQuery(QueryStatement query) {

    // get the table name for query
    String tableName = null;

    long startTime = Calendar.getInstance().getTimeInMillis();
    tableName = getTableNameForReportingQuery(query);

    if (tableName != null) {
        // get contents of table
        try {
            Statement st = connection.createStatement();
            ResultSet rs = st.executeQuery("SELECT * FROM " + tableName);
            long queryTime = Calendar.getInstance().getTimeInMillis() - startTime;
            logger.info("Finished generating result set for query statement in : " + queryTime);

            logger.info("Making result set available in service");
            // update result set in service
            resultSetAvailable(rs);
            logger.info("Making query time available in service");
            // update query time
            queryTimeUpdated(queryTime);
            logger.info("Making query statistics available in service");
            // update collection map in service
            queryStatisticsCollectionAvailable(getQueryStatisticsCollectionMap());

            return rs;

        } catch (SQLException e) {
            logger.warn(e.fillInStackTrace());
            throw new NullResultSetForQueryException(
                    "Null result returned for query. " + "Error caused by : \n", e);
        }
    } else {
        throw new NullResultSetForQueryException();
    }
}

From source file:uk.nhs.cfh.dsp.srth.query.transform.sql.impl.AbstractSQLQueryEngineService.java

/**
 * Gets the total records number./*  www. j  a v a2s .c om*/
 *
 * @param tableName the table numbe to return the record count for.
 * @param isDistinct boolean to return only distinct patient ids.
 * @return the total records number
 */
public int getTotalRecordsNumberInTable(String tableName, boolean isDistinct) {

    int count = 0;
    String selectString = "SELECT COUNT(PATIENT_ID) FROM ";

    // add distinct operator if distinct patient ids are to be returned
    if (isDistinct) {
        selectString = "SELECT COUNT(DISTINCT PATIENT_ID) FROM ";
    }
    // create statement
    try {
        Statement st = connection.createStatement();
        ResultSet rs = st.executeQuery(selectString + getSchemaName() + "." + tableName);
        // this will return only one value
        while (rs.next()) {
            count = rs.getInt(1);
            logger.debug("count = " + count);
        }

        rs.close();
        st.close();

    } catch (SQLException e) {
        logger.warn(e.fillInStackTrace());
    }

    return count;
}

From source file:uk.nhs.cfh.dsp.srth.query.transform.sql.impl.AbstractSQLQueryEngineService.java

public synchronized void setDataSource(DataSource dataSource) {
    this.dataSource = dataSource;
    try {//from  w w  w  .j  ava  2  s.  c  o  m
        this.connection = dataSource.getConnection();
    } catch (SQLException e) {
        logger.warn("Error creating connection from datasource. " + "Nested exception is : "
                + e.fillInStackTrace().getMessage());
    }
}

From source file:uk.nhs.cfh.dsp.srth.query.transform.utils.QueryStatisticsCollection.java

/**
 * Gets the result set size./*  w w  w  .  jav  a  2  s  . c o m*/
 * 
 * @param connection the connection
 * 
 * @return the result set size
 */
public int getResultSetSize(Connection connection) {

    int count = 0;
    // create statement
    try {
        Statement st = connection.createStatement();
        ResultSet rs = st.executeQuery("" + "SELECT COUNT(PATIENT_ID) FROM " + tableName);
        // this will return only one value
        while (rs.next()) {
            count = rs.getInt(1);
            resultSetSize = count;
        }

        rs.close();

    } catch (SQLException e) {
        logger.warn(e.fillInStackTrace());
    }

    return count;
}

From source file:uk.nhs.cfh.dsp.yasb.indexgenerator.engine.SnomedSynonymEngine.java

/**
 * Instantiates a new snomed synonym engine.
 *
 * @param terminologyConceptDAO the terminology concept dao
 * @param dataSource the data source/*from w w  w.  java 2s  . c  o m*/
 */
public SnomedSynonymEngine(TerminologyConceptDAO terminologyConceptDAO, DataSource dataSource) {

    try {
        connection = dataSource.getConnection();
        this.terminologyConceptDAO = terminologyConceptDAO;
        // create dao object
        try {
            // create snynonyms map
            synonymsMap = new HashMap<String, Collection<String>>();
            // populate map
            populateSynonymsMap();

        } catch (SQLException e) {
            logger.warn(e.fillInStackTrace());
        }
    } catch (SQLException e) {
        logger.warn("Error obtaining connection from datasource.\n" + "Nested exception is : "
                + e.fillInStackTrace());
    }

}

From source file:uk.nhs.cfh.dsp.yasb.indexgenerator.SnomedLuceneDescriptionIndexer.java

/**
 * Index concepts./*w ww. ja v  a2s .co m*/
 */
public void indexConcepts() {

    try {
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery(
                "" + "SELECT DISTINCT DESCRIPTIONID, CONCEPTID, TERM, DESCRIPTIONTYPE FROM SNOMED.TERM");
        int counter = 1;
        while (rs.next()) {
            String conceptID = rs.getString(2);
            String descId = rs.getString(1);
            String term = rs.getString(3);
            String descType = rs.getString(4);

            SnomedConcept concept = (SnomedConcept) terminologyConceptDAO.getTerminologyConcept(conceptID);

            // get attributes of concept and add to lucene document
            Document document = new Document();
            String source = concept.getSource();
            String status = concept.getStatus().name();
            String conceptType = concept.getType().name();
            // replace all spaces in concept type with underscores
            conceptType = conceptType.replaceAll(" ", "_");

            document.add(new Field("CONCEPTID", conceptID, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("DESCRIPTIONID", descId, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("SOURCE", source, Store.NO, Index.ANALYZED));
            document.add(new Field("STATUS", status, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("TERM", term, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("CONCEPTTYPE", conceptType, Store.NO, Index.ANALYZED));
            document.add(new Field("DESCRIPTIONTYPE", descType, Store.NO, Index.ANALYZED));

            // add document to index
            indexWriter.addDocument(document);

            // debuggin messages
            if (logger.isDebugEnabled() && counter % 1000 == 0) {
                logger.debug("Concepts indexed : " + counter);
            }
            // increment counter
            counter++;
        }

        // close result set and statement
        rs.close();
        statement.close();

        // optimise index
        indexWriter.optimize();
        indexWriter.commit();

    } catch (SQLException e) {
        logger.warn(e.fillInStackTrace());
    } catch (ConceptNotFoundException e) {
        logger.warn(e.fillInStackTrace());
    } catch (CorruptIndexException e) {
        logger.warn(e.fillInStackTrace());
    } catch (IOException e) {
        logger.warn(e.fillInStackTrace());
    }
}

From source file:uk.nhs.cfh.dsp.yasb.indexgenerator.SnomedLuceneIndexer.java

/**
 * Index concepts.//from   w  ww.j av  a  2s  .com
 */
private void indexConcepts() {

    try {
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("" + "SELECT DISTINCT CONCEPTID FROM SNOMED.CONCEPT");
        int counter = 1;
        while (rs.next()) {
            String conceptID = rs.getString("CONCEPTID");
            SnomedConcept concept = (SnomedConcept) terminologyConceptDAO.getTerminologyConcept(conceptID);

            // get attributes of concept and add to lucene document
            Document document = new Document();
            String preferredTerm = concept.getPreferredLabel();
            String fullySpecName = concept.getFullySpecifiedName();
            String isPrimitive = String.valueOf(concept.isPrimitive());
            String source = concept.getSource();
            String status = concept.getStatus().name();
            String conceptType = concept.getType().name();
            // replace all spaces in concept type with underscores
            conceptType = conceptType.replaceAll(" ", "_");

            document.add(new Field("ID", conceptID, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("FSN", fullySpecName, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("TERM", fullySpecName, Store.NO, Index.ANALYZED));
            document.add(new Field("PT", preferredTerm, Store.NO, Index.ANALYZED));
            document.add(new Field("TERM", preferredTerm, Store.NO, Index.ANALYZED));
            document.add(new Field("SOURCE", source, Store.NO, Index.ANALYZED));
            document.add(new Field("STATUS", status, Store.COMPRESS, Index.ANALYZED));
            document.add(new Field("ISPRIMTIVE", isPrimitive, Store.NO, Index.NOT_ANALYZED));
            document.add(new Field("TYPE", conceptType, Store.NO, Index.ANALYZED));

            Collection<String> synonyms = concept.getSynonyms();
            for (String synonym : synonyms) {
                document.add(new Field("SYN", synonym, Store.NO, Index.ANALYZED));
                // add synonym as a general term to be indexed
                document.add(new Field("TERM", synonym, Store.NO, Index.ANALYZED));
            }

            // add document to index
            indexWriter.addDocument(document);

            // debuggin messages
            if (logger.isDebugEnabled() && counter % 1000 == 0) {
                logger.debug("Concepts indexed : " + counter);
            }
            // increment counter
            counter++;
        }

        // close result set and statement
        rs.close();
        statement.close();

        // optimise index
        indexWriter.optimize();
        indexWriter.commit();

    } catch (SQLException e) {
        logger.warn(e.fillInStackTrace());
    } catch (ConceptNotFoundException e) {
        logger.warn(e.fillInStackTrace());
    } catch (CorruptIndexException e) {
        logger.warn(e.fillInStackTrace());
    } catch (IOException e) {
        logger.warn(e.fillInStackTrace());
    }
}