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 connection pooling

Code changes for connection pooling

When you enable connection pooling for the connector, you must manually modify the Informatica Connector Toolkit classes and methods to implement the connection pooling logic.
  1. Override the validateConnection() method in the connection class of metadata connector.
    The method executes a simple query to validate whether the connection is open or closed. Use this method if testOnBorrow, testOnReturn, or testOnCreate is enabled for connection pooling.
    @Override public Status validateConnection() { // This is just a sample logic for testing, actual logic might be different String validateConnectionQuery = "select 1 from dual"; Statement stmt = null; StatusEnum status = StatusEnum.SUCCESS; StringBuilder errMsgBuilder = new StringBuilder(""); try { stmt = conn.createStatement(); stmt.executeQuery(validateConnectionQuery); } catch (SQLException e) { status = StatusEnum.FAILURE; errMsgBuilder.append( "Following error occurred while executing query : [" + validateConnectionQuery + "]\n[" + e.getMessage() + "].\n"); } finally { try { if (stmt != null) { stmt.close(); } } catch (SQLException sqlException) { status = StatusEnum.FAILURE; errMsgBuilder.append( "Error occurred while closing JDBC statement due to : [" + sqlException.getMessage() + "]"); } } return new Status(status, errMsgBuilder.toString()); }
  2. Override the isEqual() method in the connection class of metadata connector. The method compares the connection attributes of the connection objects as shown below:
    /** * This api is used if customComparison is enabled for connection pooling for comparing two connection objects */ @Override public boolean isEqual(Map<String, Object> connAttrs) { if(connAttrs != null) { if(this.connAttrs.containsKey("username") && connAttrs.containsKey("username")) { if(!(this.connAttrs.get("username").equals(connAttrs.get("username")))) return false; } if(this.connAttrs.containsKey("password") && connAttrs.containsKey("password")) { if(!(this.connAttrs.get("password").equals(connAttrs.get("password")))) return false; } if(this.connAttrs.containsKey("host") && connAttrs.containsKey("host")) { if(!(this.connAttrs.get("host").equals(connAttrs.get("host")))) return false; } if(this.connAttrs.containsKey("port") && connAttrs.containsKey("port")) { int port1 = (int)this.connAttrs.get("port"); int port2 = (int)connAttrs.get("port"); if(port1 != port2) return false; } } return true; }
  3. Override the generateHashCode() method in the connection class of metadata connector.
    This pool uses this method to generate the hash code for the key in the pool if the connector supports custom comparison of the connection attributes.
    /** * This API is used to generate the hashCode for the connection object. It is used only when custom comparison is enabled in Design time connection pooling */ @Override public int generateHashCode() { final int prime = 31; int result = 1; // use only those connection attribute to generate hashcode which you are using in isEqual method to compare 2 Connection objects ArrayList<String> supportedConnAttr = new ArrayList<String>() {{ add("username"); add("password"); add("host"); add("port");}}; if(connAttrs != null) { for(Map.Entry<String,Object> mapElement : connAttrs.entrySet()) { Object val = mapElement.getValue(); String key = mapElement.getKey(); if(val != null && supportedConnAttr.contains(key)) { result = prime * result + val.hashCode(); } } } return result; }

0 COMMENTS

We’d like to hear from you!