org.apache.ctakes.ytex.uima.DBCollectionReader Maven / Gradle / Ivy
The newest version!
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ctakes.ytex.uima;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ctakes.core.pipeline.PipeBitInfo;
import org.apache.ctakes.ytex.uima.types.DocKey;
import org.apache.ctakes.ytex.uima.types.KeyValuePair;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASException;
import org.apache.uima.collection.CollectionException;
import org.apache.uima.collection.CollectionReader_ImplBase;
import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.cas.FSArray;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
import org.apache.uima.util.Progress;
import org.apache.uima.util.ProgressImpl;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Driver;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* Read documents from db. Config parameters:
*
* - queryGetDocumentKeys the query to get the document keys
* - queryGetDocument the query to get a document given a key. should have
* named parameters that match the columns of the result set returned by
* queryGetDocumentKeys
* - keyTypeName the uima type of the document key to be added to the cas.
* defaults to org.apache.ctakes.ytex.uima.types.DocKey.
*
- keyNameToLowerCase convert the column names returned by
* queryGetDocumentKeys to lower case, default true
*
*
* @TODO more doc
* @author vijay
*
*/
@PipeBitInfo(
name = "Database Reader",
description = "Read documents from a database.",
role = PipeBitInfo.Role.READER )
public class DBCollectionReader extends CollectionReader_ImplBase {
private static final Log log = LogFactory.getLog(DBCollectionReader.class);
/**
* the query to get the document keys set in config file
*/
protected String queryGetDocumentKeys;
/**
* the queyr to get a document given a key. set in config file
*/
protected String queryGetDocument;
/**
* the key type. if not set, will default to
* org.apache.ctakes.ytex.uima.types.DocKey
*/
protected String keyTypeName = "org.apache.ctakes.ytex.uima.types.DocKey";
protected DataSource dataSource;
protected JdbcTemplate jdbcTemplate;
protected NamedParameterJdbcTemplate namedJdbcTemplate;
protected TransactionTemplate txTemplate;
protected boolean keyNameToLowerCase = true;
public boolean isKeyNameToLowerCase() {
return keyNameToLowerCase;
}
public void setKeyNameToLowerCase(boolean keyNameToLowerCase) {
this.keyNameToLowerCase = keyNameToLowerCase;
}
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy