KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > jdbc > ColumnNameCache


1 // $Id: ColumnNameCache.java,v 1.6 2005/02/20 23:02:30 oneovthafew Exp $
2
package org.hibernate.jdbc;
3
4 import java.sql.SQLException JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.util.Map JavaDoc;
7
8 /**
9  * Implementation of ColumnNameCache.
10  *
11  * @author Steve Ebersole
12  */

13 public class ColumnNameCache {
14
15     private final Map JavaDoc columnNameToIndexCache;
16
17     public ColumnNameCache(int columnCount) {
18         // should *not* need to grow beyond the size of the total number of columns in the rs
19
this.columnNameToIndexCache = new HashMap JavaDoc( columnCount );
20     }
21
22     public int getIndexForColumnName(String JavaDoc columnName, ResultSetWrapper rs)throws SQLException JavaDoc {
23         Integer JavaDoc cached = ( Integer JavaDoc ) columnNameToIndexCache.get( columnName );
24         if ( cached != null ) {
25             return cached.intValue();
26         }
27         else {
28             int index = rs.getTarget().findColumn( columnName );
29             columnNameToIndexCache.put( columnName, new Integer JavaDoc(index) );
30             return index;
31         }
32     }
33 }
34
Popular Tags