From: <one...@us...> - 2003-01-04 11:23:56
|
Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/ps In directory sc8-pr-cvs1:/tmp/cvs-serv14211/src/net/sf/hibernate/ps Modified Files: PreparedStatementCache.java Log Message: reformatted code with beautiful, shiny, happy TABS! improved an exception Index: PreparedStatementCache.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/ps/PreparedStatementCache.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PreparedStatementCache.java 3 Jan 2003 22:47:24 -0000 1.2 --- PreparedStatementCache.java 4 Jan 2003 11:15:30 -0000 1.3 *************** *** 14,23 **** */ public final class PreparedStatementCache { ! Log log = LogFactory.getLog(PreparedStatementCache.class); private final int maxSize; private final ArrayList open = new ArrayList(); ! static final class Entry { --- 14,23 ---- */ public final class PreparedStatementCache { ! Log log = LogFactory.getLog(PreparedStatementCache.class); private final int maxSize; private final ArrayList open = new ArrayList(); ! static final class Entry { *************** *** 38,42 **** return sql.hashCode(); } ! } private final Map cache = new HashMap(); --- 38,42 ---- return sql.hashCode(); } ! } private final Map cache = new HashMap(); *************** *** 49,57 **** log.info("prepared statement cache size: " + maxSize); } ! public PreparedStatement getPreparedStatement(String sql, Connection connection, boolean scrollable) throws SQLException { Entry e = new Entry(sql, connection, scrollable); ! PreparedStatement ps; synchronized(this) { --- 49,57 ---- log.info("prepared statement cache size: " + maxSize); } ! public PreparedStatement getPreparedStatement(String sql, Connection connection, boolean scrollable) throws SQLException { Entry e = new Entry(sql, connection, scrollable); ! PreparedStatement ps; synchronized(this) { *************** *** 62,66 **** if (ps!=null) entries.remove( entryMap.get(ps) ); } ! if (ps==null) { --- 62,66 ---- if (ps!=null) entries.remove( entryMap.get(ps) ); } ! if (ps==null) { *************** *** 68,73 **** try { ps = scrollable ? ! connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY) : ! connection.prepareStatement(sql); } catch (SQLException sqle) { --- 68,73 ---- try { ps = scrollable ? ! connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY) : ! connection.prepareStatement(sql); } catch (SQLException sqle) { *************** *** 83,94 **** if ( log.isTraceEnabled() ) log.trace("returning cached statement: " + sql); } ! return ps; } ! public void closePreparedStatement(PreparedStatement ps) { log.trace("recaching"); ! PreparedStatement old=null; synchronized(this) { --- 83,94 ---- if ( log.isTraceEnabled() ) log.trace("returning cached statement: " + sql); } ! return ps; } ! public void closePreparedStatement(PreparedStatement ps) { log.trace("recaching"); ! PreparedStatement old=null; synchronized(this) { *************** *** 99,103 **** old = (PreparedStatement) cache.put(e, ps); ! if (old==null) { reapCounter++; --- 99,103 ---- old = (PreparedStatement) cache.put(e, ps); ! if (old==null) { reapCounter++; *************** *** 108,114 **** entries.add(e); ! } ! if (old!=null) { try { --- 108,114 ---- entries.add(e); ! } ! if (old!=null) { try { *************** *** 119,123 **** } } ! reap(); --- 119,123 ---- } } ! reap(); *************** *** 130,140 **** } ! public void closeAll(Connection connection) { log.trace("closing all statements for connection"); ! ArrayList templist = new ArrayList(25); ! synchronized(this) { Iterator iter = entries.iterator(); //slowish --- 130,140 ---- } ! public void closeAll(Connection connection) { log.trace("closing all statements for connection"); ! ArrayList templist = new ArrayList(25); ! synchronized(this) { Iterator iter = entries.iterator(); //slowish *************** *** 145,157 **** } } ! close(templist); ! } ! private void reap() { ArrayList templist = new ArrayList(25); ! synchronized(this) { if (reapCounter<20) return; --- 145,157 ---- } } ! close(templist); ! } ! private void reap() { ArrayList templist = new ArrayList(25); ! synchronized(this) { if (reapCounter<20) return; *************** *** 162,172 **** reapCounter = 0; } ! if ( log.isTraceEnabled() ) log.trace( "reaping: " + templist.size() + " statements" ); ! close(templist); ! } ! private void close(List templist) { Iterator iter = templist.iterator(); --- 162,172 ---- reapCounter = 0; } ! if ( log.isTraceEnabled() ) log.trace( "reaping: " + templist.size() + " statements" ); ! close(templist); ! } ! private void close(List templist) { Iterator iter = templist.iterator(); *************** *** 182,186 **** } } ! protected void finalize() { --- 182,186 ---- } } ! protected void finalize() { *************** *** 197,200 **** } } - } \ No newline at end of file --- 197,202 ---- } } + + } + |