src/org/ohmage/cache/KeyValueCache.java
protected synchronized void refreshMap() {
		// Only one thread should be updating this information at a time. Once
		// other threads enter, they should check to see if an update was just
		// done and, if so, should abort a second update.
		if((getLastUpdateTimestamp() + getUpdateFrequency()) > System
			.currentTimeMillis()) {
			return;
		}

		// This is the JdbcTemplate we will use for our query. If there is an
		// issue report it and abort the update.
		JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());

		// Get all the keys and their corresponding values.
		List<KeyAndValue> keyAndValue;
		try {
			keyAndValue =
				jdbcTemplate.query(
					sqlForRetrievingValues,
					new RowMapper<KeyAndValue>() {
						@Override
						public KeyAndValue mapRow(ResultSet rs, int row)
							throws SQLException {
							return new KeyAndValue(rs.getString(keyColumn), rs
								.getString(valueColumn));
						}
					});
		}
		catch(org.springframework.dao.DataAccessException e) {
			LOGGER
				.error(
					"Error executing SQL '" +
						sqlForRetrievingValues +
						"'. Aborting cache refresh.",
					e);
			return;
		}

		// Create a new Map, populate it, and replace the old one. This allows
		// for concurrent readying while the new Map is being created.
		Map<String, String> keyValueMap = new HashMap<String, String>();
		for(KeyAndValue currStateAndId : keyAndValue) {
			keyValueMap.put(currStateAndId.key, currStateAndId.value);
		}
		this.keyValueMap = keyValueMap;

		setLastUpdateTimestamp(System.currentTimeMillis());
	}
/**
	 * Reads the database for the information in the lookup table and populates
	 * its map with the gathered information. If there is an issue reading the
	 * database, it will just remain with the current lookup table it has.
	 * 
	 * @complexity O(n) where n is the number of keys in the database.
	 */
Reads the database for the information in the lookup table and populates
its map with the gathered information. If there is an issue reading the
database, it will just remain with the current lookup table it has.

@complexity O(n) where n is the number of keys in the database.
Reads the database for the information in the lookup table and populates its map with the gathered information . If there is an issue reading the database it will just remain with the current lookup table it has . @complexity O ( n ) where n is the number of keys in the database .
protected synchronized void refreshMap() {
		if((getLastUpdateTimestamp() + getUpdateFrequency()) > System
			.currentTimeMillis()) {
			return;
		}
		JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSource());
		List<KeyAndValue> keyAndValue;
		try {
			keyAndValue =
				jdbcTemplate.query(
					sqlForRetrievingValues,
					new RowMapper<KeyAndValue>() {
						@Override
						public KeyAndValue mapRow(ResultSet rs, int row)
							throws SQLException {
							return new KeyAndValue(rs.getString(keyColumn), rs
								.getString(valueColumn));
						}
					});
		}
		catch(org.springframework.dao.DataAccessException e) {
			LOGGER
				.error(
					"Error executing SQL '" +
						sqlForRetrievingValues +
						"'. Aborting cache refresh.",
					e);
			return;
		}
		Map<String, String> keyValueMap = new HashMap<String, String>();
		for(KeyAndValue currStateAndId : keyAndValue) {
			keyValueMap.put(currStateAndId.key, currStateAndId.value);
		}
		this.keyValueMap = keyValueMap;
		setLastUpdateTimestamp(System.currentTimeMillis());
	}
protected synchronized void refreshMap ( ) { if ( ( getLastUpdateTimestamp ( ) + getUpdateFrequency ( ) ) > System . currentTimeMillis ( ) ) { return ; } JdbcTemplate jdbcTemplate = new JdbcTemplate ( getDataSource ( ) ) ; List < KeyAndValue > keyAndValue ; try { keyAndValue = jdbcTemplate . query ( sqlForRetrievingValues , new RowMapper < KeyAndValue > ( ) { @ Override public KeyAndValue mapRow ( ResultSet rs , int row ) throws SQLException { return new KeyAndValue ( rs . getString ( keyColumn ) , rs . getString ( valueColumn ) ) ; } } ) ; } catch ( org . springframework . dao . DataAccessException e ) { LOGGER . error ( "Error executing SQL '" + sqlForRetrievingValues + "'. Aborting cache refresh." , e ) ; return ; } Map < String , String > keyValueMap = new HashMap < String , String > ( ) ; for ( KeyAndValue currStateAndId : keyAndValue ) { keyValueMap . put ( currStateAndId . key , currStateAndId . value ) ; } this . keyValueMap = keyValueMap ; setLastUpdateTimestamp ( System . currentTimeMillis ( ) ) ; }
Reads the database for the information in the lookup table and populates
 its map with the gathered information.
Reads the database for the information in the lookup table and populates its map with the gathered information .
// Only one thread should be updating this information at a time. Once // other threads enter, they should check to see if an update was just // done and, if so, should abort a second update. // This is the JdbcTemplate we will use for our query. If there is an // issue report it and abort the update. // Get all the keys and their corresponding values. // Create a new Map, populate it, and replace the old one. This allows // for concurrent readying while the new Map is being created.