*/
private Object obtainKey(DbChangeEntry dbChangeEntry)
throws DatabusException
{
if (null == dbChangeEntry) {
throw new DatabusException("DBUpdateImage is null");
}
List<KeyPair> pairs = dbChangeEntry.getPkeys();
if (null == pairs || pairs.size() == 0) {
throw new DatabusException("There do not seem to be any keys");
}
if (pairs.size() == 1) {
Object key = pairs.get(0).getKey();
Schema.Type pKeyType = pairs.get(0).getKeyType();
Object keyObj = null;
if (pKeyType == Schema.Type.INT)
{
if (key instanceof Integer)
{
keyObj = key;
}
else
{
throw new DatabusException(
"Schema.Type does not match actual key type (INT) "
+ key.getClass().getName());
}
} else if (pKeyType == Schema.Type.LONG)
{
if (key instanceof Long)
{
keyObj = key;
}
else
{
throw new DatabusException(
"Schema.Type does not match actual key type (LONG) "
+ key.getClass().getName());
}
keyObj = key;
}
else
{
keyObj = key;
}
return keyObj;
} else {
// Treat multiple keys as a separate case to avoid unnecessary casts
Iterator<KeyPair> li = pairs.iterator();
StringBuilder compositeKey = new StringBuilder();
while (li.hasNext())
{
KeyPair kp = li.next();
Schema.Type pKeyType = kp.getKeyType();
Object key = kp.getKey();
if (pKeyType == Schema.Type.INT)
{
if (key instanceof Integer)
compositeKey.append(kp.getKey().toString());
else
throw new DatabusException(
"Schema.Type does not match actual key type (INT) "
+ key.getClass().getName());
}
else if (pKeyType == Schema.Type.LONG)
{
if (key instanceof Long)
compositeKey.append(key.toString());
else
throw new DatabusException(
"Schema.Type does not match actual key type (LONG) "
+ key.getClass().getName());
}
else
{