Adapter Development Kit 6.5 | webMethods Adapter Development Kit Documentation | webMethods Adapter Development Kit Installation and User’s Documentation | Adapter Services | Adapter Service Implementation | Code Example 2: WmManagedConnection Implementation Class Updates
 
Code Example 2: WmManagedConnection Implementation Class Updates
1. private String[] mockTableNames ={ "CUSTOMERS","ORDERS","LINE_ITEMS"};
2. private String[][] mockColumnNames ={
3. {"name","id", "ssn"},
4. {"id","date","customer_id"},
5. {"order_id","item_number","quantity","description"}
6. };
7.
8. private String [][] mockDataTypes = {
9. {"java.lang.String","java.lang.Integer", "java.lang.String"},
10. {"java.lang.Integer", "java.util.Date", "java.lang.Integer"},
11. {"java.lang.Integer", "java.lang.Integer", "java.lang.Integer",
12. "java.lang.String"}
13. };
14.
15.
16. public Boolean adapterCheckValue(String serviceName,
17. String resourceDomainName,
18. String[][] values,
19. String testValue) throws AdapterException
20. {
21. Boolean result = new Boolean(false);
22. if(resourceDomainName.equals(MockDbUpdate.OVERRIDE_TYPES_RD))
23. {
24. try
25. {
26. Object o = Class.forName(testValue).getConstructor(
27. new Class[] {String.class}).newInstance(new Object[]{"0"});
28. result = new Boolean(true);
29. }
30. catch (Throwable t){}
31. }
32. return result;
33. }
34.
35. public ResourceDomainValues[] adapterResourceDomainLookup(String
serviceName,
36. String resourceDomainName, String[][] values) throws AdapterException
37. {
38. ResourceDomainValues[] results = null;
39. if(resourceDomainName.equals(MockDbUpdate.COLUMN_NAMES_RD)||
40. resourceDomainName.equals(MockDbUpdate.COLUMN_TYPES_RD))
41. {
42. String tableName = values[0][0];
43. for(int x = 0; x < this.mockTableNames.length;x++)
44. {
45. if(this.mockTableNames[x].equals(tableName))
46. {
47. ResourceDomainValues columnsRdvs = new ResourceDomainValues(
48. MockDbUpdate.COLUMN_NAMES_RD,this.mockColumnNames[x]);
49. columnsRdvs.setComplete(true);
50. ResourceDomainValues typesRdvs = new ResourceDomainValues(
51. MockDbUpdate.COLUMN_TYPES_RD, this.mockDataTypes[x]);
52. typesRdvs.setComplete(true);
53. results = new ResourceDomainValues[] {columnsRdvs,typesRdvs};
54. break;
55. }
56. }
57. }
58. else if (resourceDomainName.equals(MockDbUpdate.FIELD_NAMES_RD)||
59. resourceDomainName.equals(MockDbUpdate.FIELD_TYPES_RD))
60. {
61. String tableName = values[0][0];
62. boolean repeating = Boolean.valueOf(values[1][0]).booleanValue();
63. String[] columnNames = values[2];
64. String[] columnTypes = values[3];
65. String[] overrideTypes = values[4];
66.
67. String[] fieldNames = new String[columnNames.length];
68. String[] fieldTypes = new String[columnTypes.length];
69. String optBrackets;
70.
71. if(repeating)
72. optBrackets ="[]";
73. else
74. optBrackets = "";
75.
76.
77. for (int i = 0; i< fieldNames.length;i++)
78. {
79. fieldNames[i] = tableName + optBrackets + "." + columnNames[i];
80. fieldTypes[i] = columnTypes[i] + optBrackets;
81.
82. if(overrideTypes.length > i)
83. {
84. if (!overrideTypes[i].equals(""))
85. {
86. fieldTypes[i] = overrideTypes[i] + optBrackets;
87. }
88.
89. }
90.
91. }
92. results = new ResourceDomainValues[]{
93. new ResourceDomainValues(MockDbUpdate.FIELD_NAMES_RD,fieldNames),
94. new ResourceDomainValues(MockDbUpdate.FIELD_TYPES_RD,fieldTypes)};
95.
96. }
97.
98. return results;
99. }
100.
101. public void registerResourceDomain(WmAdapterAccess access)
102. throws AdapterException
103. {
104. ResourceDomainValues tableRdvs = new ResourceDomainValues(
105. MockDbUpdate.TABLES_RD,mockTableNames);
106. tableRdvs.setComplete(true);
107. access.addResourceDomain(tableRdvs);
108.
109. access.addResourceDomainLookup(MockDbUpdate.COLUMN_NAMES_RD,this);
110. access.addResourceDomainLookup(MockDbUpdate.COLUMN_TYPES_RD,this);
111.
112. ResourceDomainValues rdvs = new ResourceDomainValues(
113. MockDbUpdate.OVERRIDE_TYPES_RD, new String[] {""});
114. rdvs.setComplete(false);
115. rdvs.setCanValidate(true);
116. access.addResourceDomain(rdvs);
117. access.addCheckValue(MockDbUpdate.OVERRIDE_TYPES_RD,this);
118.
119. access.addResourceDomainLookup(MockDbUpdate.FIELD_NAMES_RD,this);
120. access.addResourceDomainLookup(MockDbUpdate.FIELD_TYPES_RD,this);
121. }