One case I came across when working on integrating spring social into my current application is that I wanted to extend the UserConnection table by adding a column with a foreign key constraint to our main customer table that would associate user records by their primary key.
In order for this to work cleanly, I was going to modify the addConnection sql statement to include the right subquery to populate this column.
Code:
@Transactional
public void addConnection(Connection<?> connection) {
try {
ConnectionData data = connection.createData();
int rank = jdbcTemplate.queryForInt("select coalesce(max(rank) + 1, 1) as rank from " + tablePrefix + "UserConnection where userId = ? and providerId = ?", userId, data.getProviderId());
jdbcTemplate.update("insert into " + tablePrefix + "UserConnection (userId, providerId, providerUserId, rank, displayName, profileUrl, imageUrl, accessToken, secret, refreshToken, expireTime) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
userId, data.getProviderId(), data.getProviderUserId(), rank, data.getDisplayName(), data.getProfileUrl(), data.getImageUrl(), encrypt(data.getAccessToken()), encrypt(data.getSecret()), encrypt(data.getRefreshToken()), data.getExpireTime());
} catch (DuplicateKeyException e) {
throw new DuplicateConnectionException(connection.getKey());
}
}
Would it be feasible to be able to override the sql statements themselves instead of exposing the class as public?
I thought about doing something after the fact to update the record, but, would prefer to avoid multiple calls to the db.
..and thank you for the quick reply and the great work you're doing on spring social.. much appreciated..