}
private int getKey(String id, final Object parameterObject) throws SQLException {
int key = Integer.MIN_VALUE;
String selectKeyId = selectKeyIdFor(id);
final MappedStatement keyStatement;
if (configuration.getMappedStatementNames().contains(selectKeyId)) {
keyStatement = configuration.getMappedStatement(selectKeyId);
} else {
keyStatement = null;
}
if (keyStatement != null) {
List results = (List) transactionManager.doInTransaction(new TransactionScope() {
public Object execute(Transaction transaction) throws SQLException {
transaction.setCommitRequired(true);
Executor executor = transaction.getExecutor();
return executor.query(keyStatement, parameterObject, RowBounds.DEFAULT, null);
}
});
try {
key = (Integer) ((Map) results.get(0)).values().iterator().next();
} catch (Exception e) {
//Ignore...sometimes code sucks. This is a good example.
}
}
try {
String property = keyStatement.getResultMaps().get(0).getResultMappings().get(0).getProperty();
MetaObject.forObject(parameterObject).setValue(property, key);
} catch (Exception e) {
//Ignore...sometimes code sucks. This is a good example.
}
return key;