Data Integration Connector Toolkit
- Data Integration Connector Toolkit
- All Products
@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()); }
/** * 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; }
/** * 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; }