}
final String finalUpsertName = upsertName;
EventType eventType = engineSPI.getEventAdapterService().getExistsTypeByName(upsert.getStream());
if (eventType == null) {
throw new ConfigurationException("Event type by name '" + upsert.getStream() + "' not found");
}
try {
DatabaseConnectionFactory connectionFactory = databaseConfigSvc.getConnectionFactory(upsert.getConnection());
String[] keys = new String[upsert.getKeys().size()];
int[] keyTypes = new int[upsert.getKeys().size()];
EventPropertyGetter[] keyGetters = new EventPropertyGetter[upsert.getKeys().size()];
int index = 0;
for (Column key : upsert.getKeys()) {
keys[index] = key.getColumn();
keyTypes[index] = SQLTypeMapUtil.getSQLTypeByName(key.getType());
keyGetters[index] = eventType.getGetter(key.getProperty());
if (keyGetters[index] == null) {
throw new ConfigurationException("Property name '" + key.getProperty() + "' not found for type '" + eventType + "'");
}
index++;
}
String[] values = new String[upsert.getValues().size()];
int[] valueTypes = new int[upsert.getValues().size()];
EventPropertyGetter[] valueGetters = new EventPropertyGetter[upsert.getValues().size()];
index = 0;
for (Column value : upsert.getValues()) {
values[index] = value.getColumn();
valueTypes[index] = SQLTypeMapUtil.getSQLTypeByName(value.getType());
valueGetters[index] = eventType.getGetter(value.getProperty());
if (valueGetters[index] == null) {
throw new ConfigurationException("Property name '" + value.getProperty() + "' not found for type '" + eventType + "'");
}
index++;
}
StoreExceptionHandler handler = new StoreExceptionHandler() {
public void handle(String message, SQLException ex)
{
log.error("Error executing '" + finalUpsertName + "'");
}
};
MultiKeyMultiValueTable table = new MultiKeyMultiValueTable(upsert.getTableName(), keys, keyTypes,
values, valueTypes, handler);
RunnableUpsertContext context = new RunnableUpsertContext(upsertName, connectionFactory, table, keyGetters, valueGetters, upsert.getRetry(), upsert.getRetryIntervalSec());
return new RunnableUpsertFactory(context);
}
catch (ConfigurationException ex) {
throw ex;
}
catch (Throwable t) {
throw new ConfigurationException("Error configuring " + upsertName + " :" + t.getMessage());
}
}