Changeset 3209


Ignore:
Timestamp:
07/30/13 12:24:35 (11 years ago)
Author:
peterwithers
Message:

Added the constructor defined in the spring configuration file, that provides the mandatory dataSource used by the queries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/dao/impl/JdbcUserDao.java

    r3206 r3209  
    2323import java.sql.SQLException;
    2424import java.util.List;
     25import javax.sql.DataSource;
    2526import org.springframework.jdbc.core.RowMapper;
    2627
     
    2930 * @author olhsha
    3031 */
    31 public class JdbcUserDao extends JdbcResourceDao implements UserDao{
    32    
     32public class JdbcUserDao extends JdbcResourceDao implements UserDao {
     33
     34    public JdbcUserDao(DataSource dataSource) {
     35        setDataSource(dataSource);
     36    }
     37
    3338    @Override
    3439    public Number getInternalID(UserIdentifier userIdentifier) {
     
    3641            return null;
    3742        }
    38        String sql = "SELECT "+principal_id+" FROM "+principalTableName+" WHERE "+external_id  +"= ?";
    39        List<Number> result= getSimpleJdbcTemplate().query(sql, userIDRowMapper, userIdentifier.toString());
    40        
    41        if (result==null){
    42            return null;
    43        }
    44        
    45        if (result.isEmpty()) {
    46            return null;
    47        }
    48        
    49        return result.get(0);
     43        String sql = "SELECT " + principal_id + " FROM " + principalTableName + " WHERE " + external_id + "= ?";
     44        List<Number> result = getSimpleJdbcTemplate().query(sql, userIDRowMapper, userIdentifier.toString());
     45
     46        if (result == null) {
     47            return null;
     48        }
     49
     50        if (result.isEmpty()) {
     51            return null;
     52        }
     53
     54        return result.get(0);
    5055    }
    51    
    52      private final RowMapper<Number> userIDRowMapper = new RowMapper<Number>() {       
     56    private final RowMapper<Number> userIDRowMapper = new RowMapper<Number>() {
    5357        @Override
    5458        public Number mapRow(ResultSet rs, int rowNumber) throws SQLException {
    55            Number result = rs.getInt(principal_id);
    56            return result;
     59            Number result = rs.getInt(principal_id);
     60            return result;
    5761        }
    58      };
     62    };
    5963}
Note: See TracChangeset for help on using the changeset viewer.