Example 2: WmManagedConnection Implementation Class Updates
package com.wm.MyAdapter.connections;
import com.wm.adk.connection.WmManagedConnection;
import com.wm.adk.metadata.*;
import com.wm.adk.error.AdapterException;
import com.wm.MyAdapter.MyAdapter;
import com.wm.MyAdapter.services.MockDbUpdate;
public class SimpleConnection extends WmManagedConnection {
String hostName;
int port;
//Adapter Services variables
private String[] mockTableNames ={ "CUSTOMERS","ORDERS","LINE_ITEMS"};
private String[][] mockColumnNames ={
{"name","id", "ssn"},
{"id","date","customer_id"},
{"order_id","item_number","quantity","description"}
};
private String [][] mockDataTypes = {
{"java.lang.String","java.lang.Integer", "java.lang.String"},
{"java.lang.Integer", "java.util.Date", "java.lang.Integer"},
{"java.lang.Integer", "java.lang.Integer", "java.lang.Integer",
"java.lang.String"}
};
public SimpleConnection(String hostNameValue, int portValue)
{
super();
hostName = hostNameValue;
port = portValue;
MyAdapter.getInstance().getLogger().logDebug(9999,
"Simple Connection created with hostName = "
+ hostName + "and port = " + Integer.toString(port));
}
public void destroyConnection()
{
MyAdapter.getInstance().getLogger().logDebug(9999,"Simple Connection Destroyed");
}
// The remaining methods support metadata for related services, etc.
// Implement content as needed.
public Boolean adapterCheckValue(String serviceName,
String resourceDomainName,
String[][] values,
String testValue) throws AdapterException
{
Boolean result = new Boolean(false);
if(resourceDomainName.equals(MockDbUpdate.OVERRIDE_TYPES_RD))
{
try
{
Object o = Class.forName(testValue).getConstructor(
new Class[] {String.class}).newInstance(new Object[]{"0"});
result = new Boolean(true);
}
catch (Throwable t){}
}
return result;
}
public ResourceDomainValues[] adapterResourceDomainLookup(String serviceName,
String resourceDomainName, String[][] values) throws AdapterException
{
ResourceDomainValues[] results = null;
//MockDB Group Lookup
if(resourceDomainName.equals(MockDbUpdate.COLUMN_NAMES_RD)||
resourceDomainName.equals(MockDbUpdate.COLUMN_TYPES_RD))
{
String tableName = values[0][0];
for(int x = 0; x < this.mockTableNames.length;x++)
{
if(this.mockTableNames[x].equals(tableName))
{
ResourceDomainValues columnsRdvs = new ResourceDomainValues(
MockDbUpdate.COLUMN_NAMES_RD,this.mockColumnNames[x]);
columnsRdvs.setComplete(true);
ResourceDomainValues typesRdvs = new ResourceDomainValues(
MockDbUpdate.COLUMN_TYPES_RD, this.mockDataTypes[x]);
typesRdvs.setComplete(true);
results = new ResourceDomainValues[] {columnsRdvs,typesRdvs};
break;
}
}
}
//MockDB Signature Group Lookup
else if (resourceDomainName.equals(MockDbUpdate.FIELD_NAMES_RD)||
resourceDomainName.equals(MockDbUpdate.FIELD_TYPES_RD))
{
String tableName = values[0][0];
boolean repeating = Boolean.valueOf(values[1][0]).booleanValue();
String[] columnNames = values[2];
String[] columnTypes = values[3];
String[] overrideTypes = values[4];
String[] fieldNames = new String[columnNames.length];
String[] fieldTypes = new String[columnTypes.length];
String optBrackets;
if(repeating)
optBrackets ="[]";
else
optBrackets = "";
for (int i = 0; i< fieldNames.length;i++)
{
fieldNames[i] = tableName + optBrackets + "." + columnNames[i];
fieldTypes[i] = columnTypes[i] + optBrackets;
if(overrideTypes.length > i)
{
if (!overrideTypes[i].equals(""))
{
fieldTypes[i] = overrideTypes[i] + optBrackets;
}
}
}
results = new ResourceDomainValues[]{
new ResourceDomainValues(MockDbUpdate.FIELD_NAMES_RD,fieldNames),
new ResourceDomainValues(MockDbUpdate.FIELD_TYPES_RD,fieldTypes)};
}
return results;
}
public void registerResourceDomain(WmAdapterAccess access)
throws AdapterException
{
//MockDB Group Registering Resource Domain
ResourceDomainValues tableRdvs = new ResourceDomainValues(
MockDbUpdate.TABLES_RD,mockTableNames);
tableRdvs.setComplete(true);
access.addResourceDomain(tableRdvs);
access.addResourceDomainLookup(MockDbUpdate.COLUMN_NAMES_RD,this);
access.addResourceDomainLookup(MockDbUpdate.COLUMN_TYPES_RD,this);
ResourceDomainValues rdvs = new ResourceDomainValues(
MockDbUpdate.OVERRIDE_TYPES_RD, new String[] {""});
rdvs.setComplete(false);
rdvs.setCanValidate(true);
access.addResourceDomain(rdvs);
access.addCheckValue(MockDbUpdate.OVERRIDE_TYPES_RD,this);
//MockDB Signature Group Registering Resource Domain
access.addResourceDomainLookup(MockDbUpdate.FIELD_NAMES_RD,this);
access.addResourceDomainLookup(MockDbUpdate.FIELD_TYPES_RD,this);
}
}