ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1857244 - in /ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc: field/ i2b2/ row/ table/
Date Wed, 10 Apr 2019 12:57:21 GMT
Author: seanfinan
Date: Wed Apr 10 12:57:21 2019
New Revision: 1857244

URL: http://svn.apache.org/viewvc?rev=1857244&view=rev
Log:
Jdbc checkin : simplified interfaces, use PreparedStatement

Modified:
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/AbstractJdbcField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/BooleanField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/DoubleField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/FloatField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/IntField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/JdbcField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/LongField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TextField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TimeField.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/i2b2/ObservationFactRow.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/row/JdbcRow.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractJdbcTable.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractUmlsTable.java
    ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/JdbcTable.java

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/AbstractJdbcField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/AbstractJdbcField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/AbstractJdbcField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/AbstractJdbcField.java
Wed Apr 10 12:57:21 2019
@@ -20,7 +20,7 @@ abstract public class AbstractJdbcField<
     * {@inheritDoc}
     */
    @Override
-   public String getFieldName() {
+   public String getName() {
       return _name;
    }
 
@@ -28,16 +28,8 @@ abstract public class AbstractJdbcField<
     * {@inheritDoc}
     */
    @Override
-   public int getFieldIndex() {
+   public int getIndex() {
       return _index;
    }
 
-   /**
-    * {@inheritDoc}
-    */
-   @Override
-   public void setFieldIndex( final int index ) {
-      _index = index;
-   }
-
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/BooleanField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/BooleanField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/BooleanField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/BooleanField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -11,16 +11,12 @@ import java.sql.SQLException;
  */
 final public class BooleanField extends AbstractJdbcField<Boolean> {
 
-   public BooleanField( final String name ) {
-      super( name, NO_INDEX );
+   public BooleanField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final Boolean value ) throws
SQLException {
-      statement.setBoolean( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final Boolean value
) throws SQLException {
-      statement.setBoolean( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final Boolean value ) throws
SQLException {
+      statement.setBoolean( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/DoubleField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/DoubleField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/DoubleField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/DoubleField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -11,16 +11,12 @@ import java.sql.SQLException;
  */
 final public class DoubleField extends AbstractJdbcField<Double> {
 
-   public DoubleField( final String name ) {
-      super( name, NO_INDEX );
+   public DoubleField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final Double value ) throws
SQLException {
-      statement.setDouble( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final Double value )
throws SQLException {
-      statement.setDouble( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final Double value ) throws
SQLException {
+      statement.setDouble( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/FloatField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/FloatField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/FloatField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/FloatField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -11,16 +11,12 @@ import java.sql.SQLException;
  */
 final public class FloatField extends AbstractJdbcField<Float> {
 
-   public FloatField( final String name ) {
-      super( name, NO_INDEX );
+   public FloatField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final Float value ) throws
SQLException {
-      statement.setFloat( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final Float value )
throws SQLException {
-      statement.setFloat( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final Float value ) throws
SQLException {
+      statement.setFloat( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/IntField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/IntField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/IntField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/IntField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -11,16 +11,12 @@ import java.sql.SQLException;
  */
 final public class IntField extends AbstractJdbcField<Integer> {
 
-   public IntField( final String name ) {
-      super( name, NO_INDEX );
+   public IntField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final Integer value ) throws
SQLException {
-      statement.setInt( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final Integer value
) throws SQLException {
-      statement.setInt( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final Integer value ) throws
SQLException {
+      statement.setInt( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/JdbcField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/JdbcField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/JdbcField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/JdbcField.java
Wed Apr 10 12:57:21 2019
@@ -1,6 +1,6 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -10,18 +10,10 @@ import java.sql.SQLException;
  */
 public interface JdbcField<T> {
 
-   int NO_INDEX = -1;
+   String getName();
 
-   String getFieldName();
+   int getIndex();
 
-   default int getFieldIndex() {
-      return NO_INDEX;
-   }
-
-   void setFieldIndex( final int index );
-
-   void addToStatement( final CallableStatement statement, final T value ) throws SQLException;
-
-   void insertInStatement( final CallableStatement statement, final T value ) throws SQLException;
+   void addToStatement( final PreparedStatement statement, final T value ) throws SQLException;
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/LongField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/LongField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/LongField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/LongField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -11,16 +11,12 @@ import java.sql.SQLException;
  */
 final public class LongField extends AbstractJdbcField<Long> {
 
-   public LongField( final String name ) {
-      super( name, NO_INDEX );
+   public LongField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final Long value ) throws
SQLException {
-      statement.setLong( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final Long value ) throws
SQLException {
-      statement.setLong( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final Long value ) throws
SQLException {
+      statement.setLong( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TextField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TextField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TextField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TextField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -11,16 +11,12 @@ import java.sql.SQLException;
  */
 final public class TextField extends AbstractJdbcField<String> {
 
-   public TextField( final String name ) {
-      super( name, NO_INDEX );
+   public TextField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final String value ) throws
SQLException {
-      statement.setString( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final String value )
throws SQLException {
-      statement.setString( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final String value ) throws
SQLException {
+      statement.setString( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TimeField.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TimeField.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TimeField.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/field/TimeField.java
Wed Apr 10 12:57:21 2019
@@ -1,7 +1,7 @@
 package org.apache.ctakes.core.cc.jdbc.field;
 
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 
@@ -12,16 +12,12 @@ import java.sql.Timestamp;
  */
 final public class TimeField extends AbstractJdbcField<Timestamp> {
 
-   public TimeField( final String name ) {
-      super( name, NO_INDEX );
+   public TimeField( final String name, final int index ) {
+      super( name, index );
    }
 
-   public void addToStatement( final CallableStatement statement, final Timestamp value )
throws SQLException {
-      statement.setTimestamp( getFieldName(), value );
-   }
-
-   public void insertInStatement( final CallableStatement statement, final Timestamp value
) throws SQLException {
-      statement.setTimestamp( getFieldIndex(), value );
+   public void addToStatement( final PreparedStatement statement, final Timestamp value )
throws SQLException {
+      statement.setTimestamp( getIndex(), value );
    }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/i2b2/ObservationFactRow.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/i2b2/ObservationFactRow.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/i2b2/ObservationFactRow.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/i2b2/ObservationFactRow.java
Wed Apr 10 12:57:21 2019
@@ -11,7 +11,7 @@ import org.apache.log4j.Logger;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.resource.ResourceProcessException;
 
-import java.sql.CallableStatement;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.sql.Timestamp;
 import java.time.LocalDateTime;
@@ -54,20 +54,20 @@ final public class ObservationFactRow
 
 
    // Per Patient
-   private final LongField _patientNum = new LongField( PATIENT_NUM );
+   private final LongField _patientNum = new LongField( PATIENT_NUM, 1 );
 
    // Per Document
-   private final TextField _providerId = new TextField( PROVIDER_ID );
-   private final IntField _encounterNum = new IntField( ENCOUNTER_NUM );
-   private final TimeField _startDate = new TimeField( START_DATE );
+   private final TextField _providerId = new TextField( PROVIDER_ID, 2 );
+   private final IntField _encounterNum = new IntField( ENCOUNTER_NUM, 3 );
+   private final TimeField _startDate = new TimeField( START_DATE, 4 );
 
    // Per Row
-   private final LongField _instanceNum = new LongField( INSTANCE_NUM );
-   private final TextField _conceptCd = new TextField( CONCEPT_CD );
-   private final TextField _modifierCd = new TextField( MODIFIER_CD );
-   private final TextField _valtypeCd = new TextField( VALTYPE_CD );
-   private final TextField _tvalChar = new TextField( TVAL_CHAR );
-   private final TextField _observationBlob = new TextField( OBSERVATION_BLOB );
+   private final LongField _instanceNum = new LongField( INSTANCE_NUM, 5 );
+   private final TextField _conceptCd = new TextField( CONCEPT_CD, 6 );
+   private final TextField _modifierCd = new TextField( MODIFIER_CD, 7 );
+   private final TextField _valtypeCd = new TextField( VALTYPE_CD, 8 );
+   private final TextField _tvalChar = new TextField( TVAL_CHAR, 9 );
+   private final TextField _observationBlob = new TextField( OBSERVATION_BLOB, 10 );
 
    // Per Patient
    private long _patient;
@@ -154,23 +154,23 @@ final public class ObservationFactRow
     * Set the concept_cd, modifier_cd, instance_num, valtype_cd, tval_char, observation_blob.
     */
    @Override
-   public void addToStatement( final CallableStatement statement,
+   public void addToStatement( final PreparedStatement statement,
                                final UmlsConcept value ) throws SQLException {
       // Per Patient
-      _patientNum.insertInStatement( statement, _patient );
+      _patientNum.addToStatement( statement, _patient );
 
       // Per Document
-      _providerId.insertInStatement( statement, _provider );
-      _encounterNum.insertInStatement( statement, _encounter );
-      _startDate.insertInStatement( statement, _start );
+      _providerId.addToStatement( statement, _provider );
+      _encounterNum.addToStatement( statement, _encounter );
+      _startDate.addToStatement( statement, _start );
 
       // Per Row
-      _instanceNum.insertInStatement( statement, _instance );
-      _conceptCd.insertInStatement( statement, getConceptCode( value ) );
-      _modifierCd.insertInStatement( statement, getModifierCd( value ) );
-      _valtypeCd.insertInStatement( statement, getValtypeCd( value ) );
-      _tvalChar.insertInStatement( statement, getTvalChar( value ) );
-      _observationBlob.insertInStatement( statement, getObservationBlob( value ) );
+      _instanceNum.addToStatement( statement, _instance );
+      _conceptCd.addToStatement( statement, getConceptCode( value ) );
+      _modifierCd.addToStatement( statement, getModifierCd( value ) );
+      _valtypeCd.addToStatement( statement, getValtypeCd( value ) );
+      _tvalChar.addToStatement( statement, getTvalChar( value ) );
+      _observationBlob.addToStatement( statement, getObservationBlob( value ) );
       _instance++;
    }
 

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/row/JdbcRow.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/row/JdbcRow.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/row/JdbcRow.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/row/JdbcRow.java
Wed Apr 10 12:57:21 2019
@@ -2,13 +2,9 @@ package org.apache.ctakes.core.cc.jdbc.r
 
 import org.apache.ctakes.core.cc.jdbc.field.JdbcField;
 
-import java.sql.*;
-import java.util.ArrayList;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.util.Collection;
-import java.util.Comparator;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
 
 /**
  * @author SPF , chip-nlp
@@ -19,53 +15,6 @@ public interface JdbcRow<C, P, D, E, T>
 
    Collection<JdbcField<?>> getFields();
 
-   default Collection<String> getFieldNames() {
-      return getFields().stream()
-                        .sorted( Comparator.comparingInt( JdbcField::getFieldIndex ) )
-                        .map( JdbcField::getFieldName )
-                        .collect( Collectors.toList() );
-   }
-
-   /**
-    * Attempt to get field indices using database metadata
-    *
-    * @param connection -
-    * @param tableName  -
-    * @throws SQLException if something went wrong or some required fields did not exist
-    */
-   default void initializeFieldIndices( final Connection connection, final String tableName
) throws SQLException {
-      final Collection<JdbcField<?>> fields = getFields();
-      if ( fields == null ) {
-         throw new SQLException( "No Fields defined for table " + tableName );
-      }
-      final Map<String, JdbcField<?>> fieldMap
-            = fields.stream().collect( Collectors.toMap( JdbcField::getFieldName, Function.identity()
) );
-      final Collection<String> assigned = new ArrayList<>( fieldMap.size() );
-      final DatabaseMetaData metadata = connection.getMetaData();
-      final ResultSet resultSet = metadata.getColumns( null, null, tableName, null );
-      int index = 0;
-      while ( resultSet.next() ) {
-         index++;
-         final String name = resultSet.getString( "COLUMN_NAME" );
-         final JdbcField<?> field = fieldMap.get( name );
-         if ( field != null ) {
-            field.setFieldIndex( index );
-            assigned.add( name );
-         }
-      }
-      resultSet.close();
-      if ( assigned.isEmpty() ) {
-         // some drivers don't fully populate the db metadata.  Try a series of statement
resultset metadata.
-         SELECT_1.initializeFieldIndices( connection, tableName, fieldMap );
-      } else {
-         fieldMap.keySet().removeAll( assigned );
-      }
-      if ( !fieldMap.isEmpty() ) {
-         throw new SQLException( "No field indices for "
-                                 + tableName + " : " + String.join( " , ", fieldMap.keySet()
) );
-      }
-   }
-
    default void initializeCorpus( final C corpusValue ) {
    }
 
@@ -78,66 +27,7 @@ public interface JdbcRow<C, P, D, E, T>
    default void initializeEntity( final E entityValue ) {
    }
 
-   void addToStatement( final CallableStatement statement, final T value ) throws SQLException;
+   void addToStatement( final PreparedStatement statement, final T value ) throws SQLException;
 
-   enum SELECT_1 {
-      TOP( "SELECT TOP 1 * FROM ", "" ),
-      FIRST( "SELECT FIRST 1 * FROM ", "" ),
-      LIMIT( "SELECT * FROM ", " LIMIT 1" ),
-      SAMPLE( "SELECT * FROM ", " SAMPLE 1" ),
-      ROWNUM( "SELECT * FROM ", " WHERE ROWNUM <=1" );
-      final private String _prefix;
-      final private String _suffix;
-
-      SELECT_1( final String prefix, final String suffix ) {
-         _prefix = prefix;
-         _suffix = suffix;
-      }
-
-      private boolean runStatement( final Connection connection,
-                                    final String tableName,
-                                    final Map<String, JdbcField<?>> fieldMap
) {
-         final Collection<String> assigned = new ArrayList<>( fieldMap.size()
);
-         try {
-            final Statement statement = connection.createStatement();
-            final ResultSet resultSet = statement.executeQuery( _prefix + tableName + _suffix
);
-            final ResultSetMetaData metaData = resultSet.getMetaData();
-            int index = 0;
-            while ( resultSet.next() ) {
-               index++;
-               final String name = metaData.getColumnName( index );
-               final JdbcField<?> field = fieldMap.get( name );
-               if ( field != null ) {
-                  field.setFieldIndex( index );
-                  assigned.add( name );
-               }
-            }
-            resultSet.close();
-            statement.close();
-         } catch ( SQLException sqlE ) {
-            return false;
-         }
-         if ( assigned.isEmpty() ) {
-            return false;
-         }
-         fieldMap.keySet().removeAll( assigned );
-         return true;
-      }
-
-      static private boolean initializeFieldIndices( final Connection connection,
-                                                     final String tableName,
-                                                     final Map<String, JdbcField<?>>
fieldMap ) {
-         if ( fieldMap == null || fieldMap.isEmpty() ) {
-            return true;
-         }
-         for ( SELECT_1 select1 : SELECT_1.values() ) {
-            final boolean success = select1.runStatement( connection, tableName, fieldMap
);
-            if ( success ) {
-               return true;
-            }
-         }
-         return false;
-      }
-   }
 
 }

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractJdbcTable.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractJdbcTable.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractJdbcTable.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractJdbcTable.java
Wed Apr 10 12:57:21 2019
@@ -2,8 +2,8 @@ package org.apache.ctakes.core.cc.jdbc.t
 
 
 import javax.annotation.concurrent.NotThreadSafe;
-import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 /**
@@ -17,15 +17,14 @@ abstract public class AbstractJdbcTable<
    static private final int DEFAULT_BATCH_LIMIT = 100;
 
    private final String _tableName;
-   private final CallableStatement _callableStatement;
+   private final PreparedStatement _preparedStatement;
    private int _batchLimit = DEFAULT_BATCH_LIMIT;
    private int _batchIndex = 0;
 
    public AbstractJdbcTable( final Connection connection, final String tableName ) throws
SQLException {
       _tableName = tableName;
-      initializeFieldIndices( connection, tableName );
       final String sql = createRowInsertSql();
-      _callableStatement = connection.prepareCall( sql );
+      _preparedStatement = connection.prepareCall( sql );
    }
 
    /**
@@ -40,8 +39,8 @@ abstract public class AbstractJdbcTable<
     * {@inheritDoc}
     */
    @Override
-   final public CallableStatement getCallableStatement() {
-      return _callableStatement;
+   final public PreparedStatement getPreparedStatement() {
+      return _preparedStatement;
    }
 
    /**
@@ -68,7 +67,7 @@ abstract public class AbstractJdbcTable<
       _batchIndex++;
       if ( _batchIndex >= _batchLimit ) {
          _batchIndex = 0;
-         getCallableStatement().executeBatch();
+         getPreparedStatement().executeBatch();
          return true;
       }
       return false;

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractUmlsTable.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractUmlsTable.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractUmlsTable.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/AbstractUmlsTable.java
Wed Apr 10 12:57:21 2019
@@ -8,8 +8,8 @@ import org.apache.ctakes.typesystem.type
 import org.apache.uima.fit.util.JCasUtil;
 import org.apache.uima.jcas.JCas;
 
-import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -68,7 +68,7 @@ abstract public class AbstractUmlsTable<
     */
    @Override
    final public void writeValue( final JCas value ) throws SQLException {
-      final CallableStatement statement = getCallableStatement();
+      final PreparedStatement statement = getPreparedStatement();
       final C corpusInitializer = getCorpusInitializer( value );
       final JdbcRow<C, JCas, JCas, IdentifiedAnnotation, UmlsConcept> row = getJdbcRow();
 
@@ -98,7 +98,7 @@ abstract public class AbstractUmlsTable<
       }
       if ( !batchWritten ) {
          // The current batch has not been written to db.  Do so now.
-         getCallableStatement().executeBatch();
+         getPreparedStatement().executeBatch();
       }
    }
 

Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/JdbcTable.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/JdbcTable.java?rev=1857244&r1=1857243&r2=1857244&view=diff
==============================================================================
--- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/JdbcTable.java
(original)
+++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/cc/jdbc/table/JdbcTable.java
Wed Apr 10 12:57:21 2019
@@ -1,13 +1,16 @@
 package org.apache.ctakes.core.cc.jdbc.table;
 
 
+import org.apache.ctakes.core.cc.jdbc.field.JdbcField;
 import org.apache.ctakes.core.cc.jdbc.row.JdbcRow;
 
-import java.sql.CallableStatement;
-import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.SQLDataException;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
 
 /**
  * @author SPF , chip-nlp
@@ -22,21 +25,10 @@ public interface JdbcTable<T> {
 
    JdbcRow<?, ?, ?, ?, ?> getJdbcRow();
 
-   CallableStatement getCallableStatement();
+   PreparedStatement getPreparedStatement();
 
-   default Collection<String> getFieldNames() {
-      return getJdbcRow().getFieldNames();
-   }
-
-   /**
-    * Attempt to get field indices
-    *
-    * @param connection -
-    * @param tableName  -
-    * @throws SQLException if something went wrong or some required fields did not exist
-    */
-   default void initializeFieldIndices( final Connection connection, final String tableName
) throws SQLException {
-      getJdbcRow().initializeFieldIndices( connection, tableName );
+   default Collection<JdbcField<?>> getFields() {
+      return getJdbcRow().getFields();
    }
 
    void writeValue( final T value ) throws SQLException;
@@ -46,15 +38,17 @@ public interface JdbcTable<T> {
     * @throws SQLDataException -
     */
    default String createRowInsertSql() throws SQLDataException {
-      if ( getFieldNames().isEmpty() ) {
+      final List<JdbcField<?>> fields = new ArrayList<>( getFields() );
+      if ( fields.isEmpty() ) {
          throw new SQLDataException( "Must set at least one Field to create an sql insert
Statement" );
       }
+      fields.sort( Comparator.comparingInt( JdbcField::getIndex ) );
       final StringBuilder statement = new StringBuilder( "insert into" );
       final StringBuilder queries = new StringBuilder();
       statement.append( " " ).append( getTableName() );
       statement.append( " (" );
-      for ( String fieldName : getFieldNames() ) {
-         statement.append( fieldName ).append( "," );
+      for ( JdbcField<?> field : fields ) {
+         statement.append( field.getName() ).append( "," );
          queries.append( "?," );
       }
       // remove the last comma
@@ -65,7 +59,7 @@ public interface JdbcTable<T> {
    }
 
    default void close() throws SQLException {
-      getCallableStatement().close();
+      getPreparedStatement().close();
    }
 
 }



Mime
View raw message