replaced Commons Collections dependency with Spring-provided LinkedCaseInsensitiveMap; revised CollectionFactory and Spring Map implementations for consistency

This commit is contained in:
Juergen Hoeller
2009-05-12 23:37:43 +00:00
parent da71f266ae
commit 59101c096f
16 changed files with 227 additions and 141 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2009 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.
@@ -21,8 +21,8 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;
import org.springframework.core.CollectionFactory;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.util.LinkedCaseInsensitiveMap;
/**
* {@link RowMapper} implementation that creates a <code>java.util.Map</code>
@@ -61,16 +61,15 @@ public class ColumnMapRowMapper implements RowMapper<Map<String, Object>> {
/**
* Create a Map instance to be used as column map.
* <p>By default, a linked case-insensitive Map will be created if possible,
* else a plain HashMap (see Spring's CollectionFactory).
* <p>By default, a linked case-insensitive Map will be created.
* @param columnCount the column count, to be used as initial
* capacity for the Map
* @return the new Map instance
* @see org.springframework.core.CollectionFactory#createLinkedCaseInsensitiveMapIfPossible
* @see org.springframework.util.LinkedCaseInsensitiveMap
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> createColumnMap(int columnCount) {
return CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(columnCount);
return new LinkedCaseInsensitiveMap<Object>(columnCount);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -35,7 +35,6 @@ import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.core.CollectionFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.support.DataAccessUtils;
@@ -48,6 +47,7 @@ import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
/**
* <b>This is the central class in the JDBC core package.</b>
@@ -1161,16 +1161,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
/**
* Create a Map instance to be used as results map.
* <p>If "isResultsMapCaseInsensitive" has been set to true, a linked case-insensitive Map
* will be created if possible, else a plain HashMap (see Spring's CollectionFactory).
* <p>If "isResultsMapCaseInsensitive" has been set to true,
* a linked case-insensitive Map will be created.
* @return the results Map instance
* @see #setResultsMapCaseInsensitive
* @see org.springframework.core.CollectionFactory#createLinkedCaseInsensitiveMapIfPossible
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> createResultsMap() {
if (isResultsMapCaseInsensitive()) {
return CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(16);
return new LinkedCaseInsensitiveMap<Object>();
}
else {
return new LinkedHashMap<String, Object>();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -29,11 +29,10 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.easymock.MockControl;
import org.apache.commons.logging.LogFactory;
import org.easymock.MockControl;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -49,6 +48,7 @@ import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter;
import org.springframework.util.LinkedCaseInsensitiveMap;
/**
* Mock object based tests for JdbcTemplate.
@@ -1954,8 +1954,7 @@ public class JdbcTemplateTests extends AbstractJdbcTests {
JdbcTemplate template = new JdbcTemplate(mockDataSource);
try {
template.call(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection conn)
throws SQLException {
public CallableStatement createCallableStatement(Connection conn) throws SQLException {
return conn.prepareCall("my query");
}
}, params);
@@ -2005,13 +2004,11 @@ public class JdbcTemplateTests extends AbstractJdbcTests {
params.add(new SqlOutParameter("a", 12));
Map out = template.call(new CallableStatementCreator() {
public CallableStatement createCallableStatement(Connection conn)
throws SQLException {
public CallableStatement createCallableStatement(Connection conn) throws SQLException {
return conn.prepareCall("my query");
}
}, params);
assertTrue("this should have been an Apache Commons Collections class",
out.getClass().getName().startsWith("org.apache.commons.collections.map"));
assertTrue("this should have been a LinkedCaseInsensitiveMap", out instanceof LinkedCaseInsensitiveMap);
assertNotNull("we should have gotten the result with upper case", out.get("A"));
assertNotNull("we should have gotten the result with lower case", out.get("a"));