<commit_before>/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 

package org.springframework.jdbc.core.support;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.JdbcTemplate;

/** 
 * An implementation of the KeyRetriever interface.
 * 
 * @author <NAME>
 * @see KeyHolder
 * @see JdbcTemplate
 * @see org.springframework.jdbc.object.SqlUpdate
 */
public class GeneratedKeyHolder implements KeyHolder {
	private List keyList = new LinkedList();

	/* Return single key value
	 * @see org.springframework.jdbc.core.support.KeyRetriever#getKey()
	 */
	public Object getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException {
		if (keyList.size() == 0)
			return null;
		if (keyList.size() > 1 || ((Map)keyList.get(0)).size() > 1)
			throw new 
				InvalidDataAccessApiUsageException("The getKey method should only be used when a single key is returned.  " +
						"The current key entry contains multiple keys: " + 
						keyList);
		Iterator keyIter = ((Map)keyList.get(0)).values().iterator();
		if (keyIter.hasNext()) {
			return keyIter.next();
		}
		else {
			throw new DataRetrievalFailureException("Unable to retrieve the generated key.  Check that the table has the an identity column enabled");
		}
	}
	/* Return the Map of keys
	 * @see org.springframework.jdbc.core.support.KeyRetriever#getKeys()
	 */
	public Map getKeys() throws InvalidDataAccessApiUsageException {
		if (keyList.size() == 0)
			return null;
		if (keyList.size() > 1)
			throw new 
				InvalidDataAccessApiUsageException("The getKeys method should only be used when keys for a single row are returned.  " + 
						"The current key list contains keys for multiple rows: " +
						keyList);
		return (Map)keyList.get(0);
	}
	/* Return the List containing the keys
	 * @see org.springframework.jdbc.core.support.KeyRetriever#getKeyList()
	 */
	public List getKeyList() {
		return keyList;
	}
}<commit_msg>fixed java doc reference<commit_after>/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 

package org.springframework.jdbc.core.support;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.JdbcTemplate;

/** 
 * An implementation of the KeyRetriever interface.
 * 
 * @author <NAME>
 * @see KeyHolder
 * @see JdbcTemplate
 * @see org.springframework.jdbc.object.SqlUpdate
 */
public class GeneratedKeyHolder implements KeyHolder {
	private List keyList = new LinkedList();

	/* Return single key value
	 * @see org.springframework.jdbc.core.support.KeyHolder#getKey()
	 */
	public Object getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException {
		if (keyList.size() == 0)
			return null;
		if (keyList.size() > 1 || ((Map)keyList.get(0)).size() > 1)
			throw new 
				InvalidDataAccessApiUsageException("The getKey method should only be used when a single key is returned.  " +
						"The current key entry contains multiple keys: " + 
						keyList);
		Iterator keyIter = ((Map)keyList.get(0)).values().iterator();
		if (keyIter.hasNext()) {
			return keyIter.next();
		}
		else {
			throw new DataRetrievalFailureException("Unable to retrieve the generated key.  Check that the table has the an identity column enabled");
		}
	}
	/* Return the Map of keys
	 * @see org.springframework.jdbc.core.support.KeyHolder#getKeys()
	 */
	public Map getKeys() throws InvalidDataAccessApiUsageException {
		if (keyList.size() == 0)
			return null;
		if (keyList.size() > 1)
			throw new 
				InvalidDataAccessApiUsageException("The getKeys method should only be used when keys for a single row are returned.  " + 
						"The current key list contains keys for multiple rows: " +
						keyList);
		return (Map)keyList.get(0);
	}
	/* Return the List containing the keys
	 * @see org.springframework.jdbc.core.support.KeyHolder#getKeyList()
	 */
	public List getKeyList() {
		return keyList;
	}
}
{'fraction_non_alphanumeric': 0.09737134394668641, 'fraction_numerical': 0.0074046649389115145, 'mean_word_length': 4.021375464684015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6987448', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1502, 'n_words': 521}