Results 1 to 3 of 3

Thread: Implementing custom JdbcConnectionRepository (Q about default access level modifier)

  1. #1
    Join Date
    Nov 2012
    Posts
    29

    Default Implementing custom JdbcConnectionRepository (Q about default access level modifier)

    Hello,

    I'd like to implement my own version of org.springframework.social.connect.jdbc.JdbcConnec tionRepository , basically just overriding a couple of methods.

    I noticed the package level access is set to default (protected), so, I can't subclass it in my code.

    Is this by design?

    Is the preferred approach to implement the ConnectionRepository interface and all the methods ourselves?

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Posts
    1,074

    Default

    The reason for making it package protected is because it's only intended to be instantiated by JdbcUsersConnectionRepository. And, in general, the thinking is that unless there is an immediate and compelling need to make it public, it should remain private/protected because it's always easier to open it up later, but much harder to lock it down later.

    I could consider making it public, but before I do I would want to better understand what it is that you're planning on overriding to see if there's a way to help you with minimal or no changes to the existing design.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Nov 2012
    Posts
    29

    Default

    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..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •