package com.lgc.dsl.client.ppdmdefect.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Statement; public class ReadTeiidWithJDBCDriverWorker implements Runnable { /** The current thread number. */ private int currentThreadNumber; public ReadTeiidWithJDBCDriverWorker(int threadNumber) { this.currentThreadNumber = threadNumber; } @Override public void run() { Connection connection = null; try { long startTime = System.currentTimeMillis(); String connectionUrl = "jdbc:teiid:dspm@mm://localhost:31000;version=1;ApplicationName=Example"; // String connectionUrl = // "jdbc:teiid:OpenWorks@mm://localhost:31000;version=1;"; Class.forName("org.teiid.jdbc.TeiidDriver"); connection = DriverManager.getConnection(connectionUrl, "user", "user"); connection.setAutoCommit(false); this.readEntitiesFromPPDM(connection); System.out .println(String .format("The time taken to run the query for iteration [%d] is [%s] seconds", this.currentThreadNumber, ((System.currentTimeMillis() - startTime) / 1000))); // Thread.sleep(1000 * 60 * 5); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } /* * catch (InterruptedException e) { e.printStackTrace(); } */finally { try { if (connection != null && !connection.isClosed()) { connection.close(); connection = null; } } catch (SQLException e) { e.printStackTrace(); connection = null; } } } /** * Read entities from ppdm. * * @param connection * the connection * @throws ClassNotFoundException * the class not found exception * @throws SQLException * the sQL exception */ private void readEntitiesFromPPDM(Connection connection) throws ClassNotFoundException, SQLException { String sql = "SELECT " + "ACTIVE_IND,ACTIVITY_TYPE,ALLOWABLE_VOLUME,ALLOWABLE_VOLUME_OUOM,CUM_VOLUME,DATE_FORMAT_DESC," + "EFFECTIVE_DATE,END_DATE,EXPIRY_DATE,MMBTU_VOLUME,PDEN_ID,PDEN_VOL_SUMMARY_ALLOCATED_ID,PERIOD_TYPE,POTENTIAL_VOLUME,POTENTIAL_VOLUME_OUOM,PRODUCT_NAME,PUBLISHED_VERSION,REMARK,REPORT_IND," + "ROW_CHANGED_BY,ROW_CHANGED_DATE,ROW_CREATED_BY,ROW_CREATED_DATE,ROW_QUALITY_NAME,START_DATE,VOLUME,VOLUME_DATE,VOLUME_OUOM,VOLUME_QUALITY,VOLUME_QUALITY_OUOM,VOLUME_UOM,YTD_VOLUME " + "FROM " + "PDEN_VOL_SUMMARY_ALLOCATED"; Statement stmt = connection.createStatement(); ResultSet resultSet = stmt.executeQuery(sql); ResultSetMetaData rsMetadata = resultSet.getMetaData(); StringBuilder sb = new StringBuilder(); try { int count = 1; // Display the actual data while (resultSet.next() && count <= 1000) { for (int i = 1; i <= rsMetadata.getColumnCount(); i++) { if (i > 1) { sb.append(","); } sb.append(resultSet.getString(i)); } sb.append("\n"); count++; } System.out.println(sb.length() + "=>" + sb.toString().substring(0, 1000)); connection.commit(); } catch (Exception exception) { connection.rollback(); } finally { if (resultSet != null && !resultSet.isClosed()) { resultSet.close(); } if (stmt != null && !stmt.isClosed()) { stmt.close(); } } } /** * Read entities from open works. * * @param connection * the connection * @throws ClassNotFoundException * the class not found exception * @throws SQLException * the sQL exception */ @SuppressWarnings("unused") private void readEntitiesFromOpenWorks(Connection connection) throws ClassNotFoundException, SQLException { String sql = "SELECT " + "base_depth,base_depth_dsdsunit,create_date,create_user_id,data_source,dip_angle,dip_angle_dsdsunit,dip_azimuth,dip_azimuth_dsdsunit,dip_conf_fact,dip_intrp,dip_numeric_conf," + "dip_numeric_conf_dsdsunit,dipmeter_type,original_data_source,pattern_type,remark,top_depth,top_depth_dsdsunit,update_date,update_user_id,wellid " + "FROM " + "Dipmeter"; Statement stmt = connection.createStatement(); ResultSet resultSet = stmt.executeQuery(sql); ResultSetMetaData rsMetadata = resultSet.getMetaData(); StringBuilder sb = new StringBuilder(); try { int count = 1; // Display the actual data while (resultSet.next() && count <= 1000) { for (int i = 1; i <= rsMetadata.getColumnCount(); i++) { if (i > 1) { sb.append(","); } sb.append(resultSet.getString(i)); } sb.append("\n"); count++; } System.out.println(sb.length() + "=>" + sb.toString().substring(0, 1000)); } finally { if (resultSet != null && !resultSet.isClosed()) { resultSet.close(); } if (stmt != null && !stmt.isClosed()) { stmt.close(); } } } }