Table of Contents

Search

  1. Preface
  2. Introduction to Informatica Connector Toolkit
  3. Before you begin
  4. Develop a connector for Cloud Data Integration
  5. Develop a connector for Data Loader
  6. Import a connector
  7. Connection attributes
  8. Type system
  9. Connector metadata
  10. Partitioning capability
  11. Pushdown capability
  12. Mappings in advanced mode
  13. Manual changes to Informatica Connector Toolkit source code
  14. Runtime behavior
  15. Connector example: MySQL_Cloud
  16. Version control integration
  17. Appendix A: Metadata models
  18. Appendix B: ASO model
  19. Appendix C: Connector project migration
  20. Appendix D: Frequently used generic APIs in Informatica Connector Toolkit
  21. Appendix E: Frequently asked questions

Cloud Data Integration Connector Toolkit Developer Guide

Cloud Data Integration Connector Toolkit Developer Guide

Code changes for custom query

Code changes for custom query

When you enable the custom query capability for the connector, you must manually modify the Informatica Connector Toolkit classes and methods to implement the custom query logic.
Add the following code changes to implement the custom query capability for the connector:
  1. In the populateObjectCatalog() method of the MetadataAdapter class, validate if a custom query is used to import the data object:
    //Sample code to check if custom query is enabled public String getCustomQuery(List<Option> options) { try{ for (Option opt : options) { int optionID = opt.getDescription().getEffectiveDefinition().getOptionID(); if (optionID == CCatalogImportOpts.QUERY) return opt.getValue().toString(); } //returns empty string or null if custom query is not enabled }
  2. If custom query is enabled, then import the data object by executing the query. Call the following method from populateObjectCatalog() method:
    //Sample code to import data object by executing the query public boolean populateCatalogForCustomQuery(Connection connection, Catalog catalog, String customQuery){ Factory sdkFactory = catalog.getFactory(); FlatRecord record = null; Package pack = sdkFactory.newPackage(catalog); pack.setName("CUSTOM_CATALOG"); pack.setNativeName("CUSTOM_CATALOG"); catalog.addRootPackage(pack); record=sdkFactory.newFlatRecord(catalog); try { // sample code to execute the custom query Connection nativeConn = conn.getNativeConnection(); stmt = nativeConn.createStatement(); rs = stmt.executeQuery(customQuery); rsMetaData = rs.getMetaData(); String tableName = rsMetaData.getTableName(1); int numberOfColumns = rsMetaData.getColumnCount(); // Sample code to populate the object details record.setName(tableName); record.setNativeName(tableName); for (int i = 1; i <= numberOfColumns; i++) { int scale=rsMetaData.getScale(i); int precision=rsMetaData.getPrecision(i); String columnName = rsMetaData.getColumnLabel(i); String colType = rsMetaData.getColumnTypeName(i); Field field=null; field = sdkFactry.newField(catalog); field.setNativeName(columnName); field.setScale(scale); field.setDataType(colType); field.setPrecision(precision); record.addField(field); } } catch (SQLException e) { ExceptionManager.createNonNlsAdapterSDKException( "An error occured while executing custom query:[" + e.getMessage() + "]"); return false; } return true; }
  3. Validate the custom query specified by the user. The validate() method is executed when the user validates the custom query in the
    Add Native Metadata Definition
    dialog box.
    The following code snippet shows an example of validating the custom query for MySQL_Cloud Connector:
    @Override public boolean validate(Connection sdkConnection, List<Option> options) { String customQuery = getCustomQuery(options); java.sql.Connection mySQLConnection = ((MySQL_CloudConnection) sdkConnection).getMySQLConnection(); try (Statement ps = mySQLConnection.createStatement()) { String dbForCustomQuery=((MySQL_CloudConnection) sdkConnection).getCatalog(); ps.executeQuery("USE "+dbForCustomQuery); ps.executeQuery(customQuery); } catch (SQLException e) { // TODO Auto-generated catch block ExceptionManager.createNonNlsAdapterSDKException( "An error occured while executing custom query for validation:[" + e.getMessage() + "]"); return false; } return true; }

0 COMMENTS

We’d like to hear from you!