Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl In directory sc8-pr-cvs1:/tmp/cvs-serv20166/cirrus/hibernate/impl Modified Files: BatcherImpl.java BatchingBatcher.java CacheEntry.java CollectionPersister.java FilterImpl.java NonBatchingBatcher.java ScrollableResultsImpl.java Log Message: fixed broken line-endings and added a test Index: BatcherImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/BatcherImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BatcherImpl.java 25 Nov 2002 10:42:54 -0000 1.2 --- BatcherImpl.java 26 Nov 2002 03:35:42 -0000 1.3 *************** *** 1,117 **** ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.sql.PreparedStatement; ! import java.sql.SQLException; ! import java.util.HashSet; ! import java.util.Iterator; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.engine.Batcher; ! import cirrus.hibernate.engine.SessionFactoryImplementor; ! import cirrus.hibernate.engine.SessionImplementor; ! ! /** ! * Manages prepared statements and batching. Class exists to enforce seperation of concerns. ! */ ! public abstract class BatcherImpl implements Batcher { ! ! public static int open; ! ! protected static final Log log = LogFactory.getLog(BatcherImpl.class); ! ! protected final SessionImplementor session; ! protected final SessionFactoryImplementor factory; ! ! private PreparedStatement batchUpdate; ! private String batchUpdateSQL; ! ! private HashSet statementsToClose = new HashSet(); ! ! public BatcherImpl(SessionImplementor session) { ! this.session = session; ! this.factory = session.getFactory(); ! } ! ! protected PreparedStatement getStatement() { ! return batchUpdate; ! } ! ! public PreparedStatement prepareStatement(String sql) throws SQLException, HibernateException { ! executeBatch(); ! logOpen(); ! return factory.getPreparedStatement( session.connection(), sql, false ); ! } ! public PreparedStatement prepareQueryStatement(String sql, boolean scrollable) throws SQLException, HibernateException { ! logOpen(); ! PreparedStatement ps = factory.getPreparedStatement( session.connection(), sql, scrollable ); ! factory.setFetchSize(ps); ! statementsToClose.add(ps); ! return ps; ! } ! ! public void closeQueryStatement(PreparedStatement ps) throws SQLException { ! statementsToClose.remove(ps); ! logClose(); ! factory.closePreparedStatement(ps); ! } ! ! public void closeStatement(PreparedStatement ps) throws SQLException { ! logClose(); ! factory.closePreparedStatement(ps); ! } ! ! public PreparedStatement prepareBatchStatement(String sql) throws SQLException, HibernateException { ! if ( !sql.equals(batchUpdateSQL) ) { ! batchUpdate=prepareStatement(sql); // calls executeBatch() ! batchUpdateSQL=sql; ! } ! return batchUpdate; ! } ! ! public void executeBatch() throws SQLException, HibernateException { ! if (batchUpdate!=null) { ! final PreparedStatement ps = batchUpdate; ! batchUpdate=null; ! batchUpdateSQL=null; ! try { ! doExecuteBatch(ps); ! } ! finally { ! closeStatement(ps); ! } ! } ! } ! ! public void closeStatements() { ! Iterator iter = statementsToClose.iterator(); ! while ( iter.hasNext() ) { ! try { ! closeStatement( (PreparedStatement) iter.next() ); ! } ! catch (SQLException e) { ! // no big deal ! log.warn("Could not close a JDBC statement", e); ! } ! iter.remove(); ! } ! statementsToClose.clear(); ! } ! ! protected abstract void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException; ! ! private static void logOpen() { ! if ( log.isTraceEnabled() ) { ! open++; ! log.trace( open + " open PreparedStatements" ); ! } ! } ! ! private static void logClose() { ! if ( log.isTraceEnabled() ) ! open--; ! } ! } --- 1,117 ---- ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.sql.PreparedStatement; ! import java.sql.SQLException; ! import java.util.HashSet; ! import java.util.Iterator; ! ! import org.apache.commons.logging.Log; ! import org.apache.commons.logging.LogFactory; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.engine.Batcher; ! import cirrus.hibernate.engine.SessionFactoryImplementor; ! import cirrus.hibernate.engine.SessionImplementor; ! ! /** ! * Manages prepared statements and batching. Class exists to enforce seperation of concerns. ! */ ! public abstract class BatcherImpl implements Batcher { ! ! public static int open; ! ! protected static final Log log = LogFactory.getLog(BatcherImpl.class); ! ! protected final SessionImplementor session; ! protected final SessionFactoryImplementor factory; ! ! private PreparedStatement batchUpdate; ! private String batchUpdateSQL; ! ! private HashSet statementsToClose = new HashSet(); ! ! public BatcherImpl(SessionImplementor session) { ! this.session = session; ! this.factory = session.getFactory(); ! } ! ! protected PreparedStatement getStatement() { ! return batchUpdate; ! } ! ! public PreparedStatement prepareStatement(String sql) throws SQLException, HibernateException { ! executeBatch(); ! logOpen(); ! return factory.getPreparedStatement( session.connection(), sql, false ); ! } ! public PreparedStatement prepareQueryStatement(String sql, boolean scrollable) throws SQLException, HibernateException { ! logOpen(); ! PreparedStatement ps = factory.getPreparedStatement( session.connection(), sql, scrollable ); ! factory.setFetchSize(ps); ! statementsToClose.add(ps); ! return ps; ! } ! ! public void closeQueryStatement(PreparedStatement ps) throws SQLException { ! statementsToClose.remove(ps); ! logClose(); ! factory.closePreparedStatement(ps); ! } ! ! public void closeStatement(PreparedStatement ps) throws SQLException { ! logClose(); ! factory.closePreparedStatement(ps); ! } ! ! public PreparedStatement prepareBatchStatement(String sql) throws SQLException, HibernateException { ! if ( !sql.equals(batchUpdateSQL) ) { ! batchUpdate=prepareStatement(sql); // calls executeBatch() ! batchUpdateSQL=sql; ! } ! return batchUpdate; ! } ! ! public void executeBatch() throws SQLException, HibernateException { ! if (batchUpdate!=null) { ! final PreparedStatement ps = batchUpdate; ! batchUpdate=null; ! batchUpdateSQL=null; ! try { ! doExecuteBatch(ps); ! } ! finally { ! closeStatement(ps); ! } ! } ! } ! ! public void closeStatements() { ! Iterator iter = statementsToClose.iterator(); ! while ( iter.hasNext() ) { ! try { ! closeStatement( (PreparedStatement) iter.next() ); ! } ! catch (SQLException e) { ! // no big deal ! log.warn("Could not close a JDBC statement", e); ! } ! iter.remove(); ! } ! statementsToClose.clear(); ! } ! ! protected abstract void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException; ! ! private static void logOpen() { ! if ( log.isTraceEnabled() ) { ! open++; ! log.trace( open + " open PreparedStatements" ); ! } ! } ! ! private static void logClose() { ! if ( log.isTraceEnabled() ) ! open--; ! } ! } Index: BatchingBatcher.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/BatchingBatcher.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BatchingBatcher.java 31 Oct 2002 16:58:14 -0000 1.1 --- BatchingBatcher.java 26 Nov 2002 03:35:42 -0000 1.2 *************** *** 1,73 **** ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.sql.PreparedStatement; ! import java.sql.SQLException; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.engine.SessionImplementor; ! import cirrus.hibernate.helpers.JDBCExceptionReporter; ! ! /** ! * An implementation of the <tt>Batcher</tt> interface that actually uses batching ! */ ! public class BatchingBatcher extends BatcherImpl { ! ! private int batchSize; ! ! public BatchingBatcher(SessionImplementor session) { ! super(session); ! } ! ! public void addToBatch(int expectedRowCount) throws SQLException, HibernateException { ! ! log.trace("Adding to batch"); ! PreparedStatement batchUpdate = getStatement(); ! batchUpdate.addBatch(); ! batchSize++; ! if ( batchSize==factory.getJdbcBatchSize() ) { ! try { ! doExecuteBatch(batchUpdate); ! } ! catch (SQLException sqle) { ! closeStatement(batchUpdate); ! throw sqle; ! } ! catch (HibernateException he) { ! closeStatement(batchUpdate); ! throw he; ! } ! } ! ! } ! ! protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException { ! if ( log.isDebugEnabled() ) ! log.debug("Executing batch size: " + batchSize ); ! ! try { ! if (batchSize!=0) { ! final int[] results = ps.executeBatch(); ! // check return codes ! for ( int i=0; i<batchSize; i++ ) { ! if ( results[i]==-3 ) throw new HibernateException("Batch update failed"); ! } ! } ! } ! catch(SQLException sqle) { ! JDBCExceptionReporter.logExceptions(sqle); ! throw sqle; ! } ! catch(RuntimeException re) { ! log.error("Exception executing batch: ", re); ! throw re; ! } ! finally { ! batchSize=0; ! //ps.clearBatch(); ! } ! } ! ! ! ! } --- 1,73 ---- ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.sql.PreparedStatement; ! import java.sql.SQLException; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.engine.SessionImplementor; ! import cirrus.hibernate.helpers.JDBCExceptionReporter; ! ! /** ! * An implementation of the <tt>Batcher</tt> interface that actually uses batching ! */ ! public class BatchingBatcher extends BatcherImpl { ! ! private int batchSize; ! ! public BatchingBatcher(SessionImplementor session) { ! super(session); ! } ! ! public void addToBatch(int expectedRowCount) throws SQLException, HibernateException { ! ! log.trace("Adding to batch"); ! PreparedStatement batchUpdate = getStatement(); ! batchUpdate.addBatch(); ! batchSize++; ! if ( batchSize==factory.getJdbcBatchSize() ) { ! try { ! doExecuteBatch(batchUpdate); ! } ! catch (SQLException sqle) { ! closeStatement(batchUpdate); ! throw sqle; ! } ! catch (HibernateException he) { ! closeStatement(batchUpdate); ! throw he; ! } ! } ! ! } ! ! protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException { ! if ( log.isDebugEnabled() ) ! log.debug("Executing batch size: " + batchSize ); ! ! try { ! if (batchSize!=0) { ! final int[] results = ps.executeBatch(); ! // check return codes ! for ( int i=0; i<batchSize; i++ ) { ! if ( results[i]==-3 ) throw new HibernateException("Batch update failed"); ! } ! } ! } ! catch(SQLException sqle) { ! JDBCExceptionReporter.logExceptions(sqle); ! throw sqle; ! } ! catch(RuntimeException re) { ! log.error("Exception executing batch: ", re); ! throw re; ! } ! finally { ! batchSize=0; ! //ps.clearBatch(); ! } ! } ! ! ! ! } Index: CacheEntry.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/CacheEntry.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CacheEntry.java 1 Oct 2002 16:42:40 -0000 1.4 --- CacheEntry.java 26 Nov 2002 03:35:42 -0000 1.5 *************** *** 1,65 **** ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.io.Serializable; ! import java.sql.SQLException; ! ! import cirrus.hibernate.AssertionFailure; ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.Lifecycle; ! import cirrus.hibernate.engine.*; ! import cirrus.hibernate.persister.ClassPersister; ! import cirrus.hibernate.type.Type; ! ! /** ! * A cached instance of a persistent class ! */ ! public final class CacheEntry implements Serializable { ! ! Object[] state; ! Class subclass; ! public Class getSubclass() { ! return subclass; ! } ! public CacheEntry(Object object, ClassPersister persister, SessionImplementor session) throws HibernateException, SQLException { ! state = disassemble(object, persister, session); ! subclass = object.getClass(); ! } ! ! ! private Object[] disassemble(Object object, ClassPersister persister, SessionImplementor session) throws HibernateException { ! Object[] values = persister.getPropertyValues(object); ! Type[] propertyTypes = persister.getPropertyTypes(); ! for ( int i=0; i<values.length; i++ ) { ! values[i] = propertyTypes[i].disassemble(values[i], session); ! } ! return values; ! } ! ! ! public Object[] assemble(Object instance, Serializable id, ClassPersister persister, SessionImplementor session) throws SQLException, HibernateException { ! ! if ( subclass!=persister.getMappedClass() ) throw new AssertionFailure("Tried to assemble a different subclass instance"); ! ! return assemble(state, instance, id, persister, session); ! ! } ! ! private Object[] assemble(Object[] values, Object result, Serializable id, ClassPersister persister, SessionImplementor session) throws HibernateException, SQLException { ! Type[] propertyTypes = persister.getPropertyTypes(); ! Object[] assembledProps = new Object[propertyTypes.length]; ! for ( int i=0; i<values.length; i++ ) { ! assembledProps[i] = propertyTypes[i].assemble( (Serializable) values[i], session, result ); ! } ! persister.setPropertyValues(result, assembledProps); ! persister.setIdentifier(result, id); ! ! if ( persister.implementsLifecycle() ) { ! ( (Lifecycle) result ).onLoad(session, id); ! } ! ! return assembledProps; ! } ! ! ! } --- 1,65 ---- ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.io.Serializable; ! import java.sql.SQLException; ! ! import cirrus.hibernate.AssertionFailure; ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.Lifecycle; ! import cirrus.hibernate.engine.*; ! import cirrus.hibernate.persister.ClassPersister; ! import cirrus.hibernate.type.Type; ! ! /** ! * A cached instance of a persistent class ! */ ! public final class CacheEntry implements Serializable { ! ! Object[] state; ! Class subclass; ! public Class getSubclass() { ! return subclass; ! } ! public CacheEntry(Object object, ClassPersister persister, SessionImplementor session) throws HibernateException, SQLException { ! state = disassemble(object, persister, session); ! subclass = object.getClass(); ! } ! ! ! private Object[] disassemble(Object object, ClassPersister persister, SessionImplementor session) throws HibernateException { ! Object[] values = persister.getPropertyValues(object); ! Type[] propertyTypes = persister.getPropertyTypes(); ! for ( int i=0; i<values.length; i++ ) { ! values[i] = propertyTypes[i].disassemble(values[i], session); ! } ! return values; ! } ! ! ! public Object[] assemble(Object instance, Serializable id, ClassPersister persister, SessionImplementor session) throws SQLException, HibernateException { ! ! if ( subclass!=persister.getMappedClass() ) throw new AssertionFailure("Tried to assemble a different subclass instance"); ! ! return assemble(state, instance, id, persister, session); ! ! } ! ! private Object[] assemble(Object[] values, Object result, Serializable id, ClassPersister persister, SessionImplementor session) throws HibernateException, SQLException { ! Type[] propertyTypes = persister.getPropertyTypes(); ! Object[] assembledProps = new Object[propertyTypes.length]; ! for ( int i=0; i<values.length; i++ ) { ! assembledProps[i] = propertyTypes[i].assemble( (Serializable) values[i], session, result ); ! } ! persister.setPropertyValues(result, assembledProps); ! persister.setIdentifier(result, id); ! ! if ( persister.implementsLifecycle() ) { ! ( (Lifecycle) result ).onLoad(session, id); ! } ! ! return assembledProps; ! } ! ! ! } Index: CollectionPersister.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/CollectionPersister.java,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** CollectionPersister.java 24 Nov 2002 11:48:10 -0000 1.84 --- CollectionPersister.java 26 Nov 2002 03:35:42 -0000 1.85 *************** *** 307,311 **** Object element = getElementType().nullSafeGet(rs, unquotedElementColumnNames, session, null); return element; ! } public Object readIndex(ResultSet rs, SessionImplementor session) throws HibernateException, SQLException { return getIndexType().nullSafeGet(rs, unquotedIndexColumnNames, session, null); --- 307,311 ---- Object element = getElementType().nullSafeGet(rs, unquotedElementColumnNames, session, null); return element; ! } public Object readIndex(ResultSet rs, SessionImplementor session) throws HibernateException, SQLException { return getIndexType().nullSafeGet(rs, unquotedIndexColumnNames, session, null); Index: FilterImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/FilterImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FilterImpl.java 24 Oct 2002 20:03:54 -0000 1.1 --- FilterImpl.java 26 Nov 2002 03:35:42 -0000 1.2 *************** *** 1,50 **** ! package cirrus.hibernate.impl; ! ! import java.sql.SQLException; ! import java.util.Iterator; ! import java.util.List; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.ScrollableResults; ! import cirrus.hibernate.engine.SessionImplementor; ! import cirrus.hibernate.type.Type; ! ! /** ! * ! */ ! public class FilterImpl extends QueryImpl { ! ! private Object collection; ! ! public FilterImpl(String queryString, Object collection, SessionImplementor session) { ! super(queryString, session); ! this.collection = collection; ! } ! ! ! /** ! * @see cirrus.hibernate.Query#iterate() ! */ ! public Iterator iterate() throws SQLException, HibernateException { ! values.add(0, null); ! types.add(0, null); ! return session.iterateFilter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); ! } ! ! /** ! * @see cirrus.hibernate.Query#list() ! */ ! public List list() throws SQLException, HibernateException { ! values.add(0, null); ! types.add(0, null); ! return session.filter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); ! } ! ! /** ! * @see cirrus.hibernate.Query#scroll() ! */ ! public ScrollableResults scroll() throws SQLException, HibernateException { ! throw new UnsupportedOperationException("Can't scroll filters"); ! } ! ! } --- 1,50 ---- ! package cirrus.hibernate.impl; ! ! import java.sql.SQLException; ! import java.util.Iterator; ! import java.util.List; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.ScrollableResults; ! import cirrus.hibernate.engine.SessionImplementor; ! import cirrus.hibernate.type.Type; ! ! /** ! * ! */ ! public class FilterImpl extends QueryImpl { ! ! private Object collection; ! ! public FilterImpl(String queryString, Object collection, SessionImplementor session) { ! super(queryString, session); ! this.collection = collection; ! } ! ! ! /** ! * @see cirrus.hibernate.Query#iterate() ! */ ! public Iterator iterate() throws SQLException, HibernateException { ! values.add(0, null); ! types.add(0, null); ! return session.iterateFilter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); ! } ! ! /** ! * @see cirrus.hibernate.Query#list() ! */ ! public List list() throws SQLException, HibernateException { ! values.add(0, null); ! types.add(0, null); ! return session.filter(collection, queryString, values.toArray(), (Type[]) types.toArray(NO_TYPES), selection, namedParams); ! } ! ! /** ! * @see cirrus.hibernate.Query#scroll() ! */ ! public ScrollableResults scroll() throws SQLException, HibernateException { ! throw new UnsupportedOperationException("Can't scroll filters"); ! } ! ! } Index: NonBatchingBatcher.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/NonBatchingBatcher.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NonBatchingBatcher.java 31 Oct 2002 16:58:14 -0000 1.1 --- NonBatchingBatcher.java 26 Nov 2002 03:35:42 -0000 1.2 *************** *** 1,29 **** ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.sql.PreparedStatement; ! import java.sql.SQLException; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.engine.SessionImplementor; ! ! /** ! * An implementation of the <tt>Batcher</tt> interface that does no batching ! */ ! public class NonBatchingBatcher extends BatcherImpl { ! ! public NonBatchingBatcher(SessionImplementor session) { ! super(session); ! } ! ! public void addToBatch(int expectedRowCount) throws SQLException, HibernateException { ! int rowCount = getStatement().executeUpdate(); ! //negative expected row count means we don't know how many rows to expect ! if ( expectedRowCount>0 && expectedRowCount!=rowCount ) ! throw new HibernateException("SQL update or deletion failed (row not found)"); ! } ! ! protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException { ! } ! ! } --- 1,29 ---- ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.sql.PreparedStatement; ! import java.sql.SQLException; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.engine.SessionImplementor; ! ! /** ! * An implementation of the <tt>Batcher</tt> interface that does no batching ! */ ! public class NonBatchingBatcher extends BatcherImpl { ! ! public NonBatchingBatcher(SessionImplementor session) { ! super(session); ! } ! ! public void addToBatch(int expectedRowCount) throws SQLException, HibernateException { ! int rowCount = getStatement().executeUpdate(); ! //negative expected row count means we don't know how many rows to expect ! if ( expectedRowCount>0 && expectedRowCount!=rowCount ) ! throw new HibernateException("SQL update or deletion failed (row not found)"); ! } ! ! protected void doExecuteBatch(PreparedStatement ps) throws SQLException, HibernateException { ! } ! ! } Index: ScrollableResultsImpl.java =================================================================== RCS file: /cvsroot/hibernate/Hibernate/cirrus/hibernate/impl/ScrollableResultsImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ScrollableResultsImpl.java 21 Nov 2002 09:03:12 -0000 1.6 --- ScrollableResultsImpl.java 26 Nov 2002 03:35:42 -0000 1.7 *************** *** 1,238 **** ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.math.BigDecimal; ! import java.sql.ResultSet; ! import java.sql.SQLException; ! import java.util.Calendar; ! import java.util.Date; ! import java.util.Locale; ! import java.util.TimeZone; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.ScrollableResults; ! import cirrus.hibernate.engine.*; ! import cirrus.hibernate.query.QueryTranslator; ! import cirrus.hibernate.type.Type; ! ! public class ScrollableResultsImpl implements ScrollableResults { ! ! private final ResultSet rs; ! private final SessionImplementor sess; ! private final Type[] types; ! private final boolean single; ! private final String[][] names; ! ! /** ! * @see cirrus.hibernate.ScrollableResults#advance(int) ! */ ! public boolean scroll(int i) throws SQLException, HibernateException { ! return rs.relative(i); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#first() ! */ ! public boolean first() throws SQLException, HibernateException { ! return rs.first(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#last() ! */ ! public boolean last() throws SQLException, HibernateException { ! return rs.last(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#advance() ! */ ! public boolean next() throws SQLException, HibernateException { ! return rs.next(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#retreat() ! */ ! public boolean previous() throws SQLException, HibernateException { ! return rs.previous(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#get() ! */ ! public Object[] get() throws SQLException, HibernateException { ! Object[] row = new Object[types.length]; ! for (int i=0; i<types.length; i++) { ! row[i] = types[i].nullSafeGet( rs, names[i], sess, null ); ! } ! return row; ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#get(int) ! */ ! public Object get(int col) throws SQLException, HibernateException { ! return types[col].nullSafeGet( rs, names[col], sess, null ); ! } ! ! public ScrollableResultsImpl(ResultSet rs, SessionImplementor sess, Type[] types) ! throws HibernateException, SQLException { ! ! this.rs=rs; ! this.sess = sess; ! this.types = types; ! ! single = types.length==1; ! ! names = new String[types.length][]; ! for (int i=0; i<types.length; i++) { ! int span = types[i].getColumnSpan( sess.getFactory() ); ! names[i] = new String[span]; ! for ( int j=0; j<span; j++ ) { ! names[i][j] = QueryTranslator.scalarName(i, j); ! } ! } ! ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getBigDecimal(int) ! */ ! public BigDecimal getBigDecimal(int col) ! throws SQLException, HibernateException { ! return (BigDecimal) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getBinary(int) ! */ ! public byte[] getBinary(int col) throws SQLException, HibernateException { ! return (byte[]) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getBoolean(int) ! */ ! public Boolean getBoolean(int col) throws SQLException, HibernateException { ! return (Boolean) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getByte(int) ! */ ! public Byte getByte(int col) throws SQLException, HibernateException { ! return (Byte) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getCharacter(int) ! */ ! public Character getCharacter(int col) throws SQLException, HibernateException { ! return (Character) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getDate(int) ! */ ! public Date getDate(int col) throws SQLException, HibernateException { ! return (Date) get(col); ! } ! ! public Calendar getCalendar(int col) throws SQLException, HibernateException { ! return (Calendar) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getDouble(int) ! */ ! public Double getDouble(int col) throws SQLException, HibernateException { ! return (Double) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getFloat(int) ! */ ! public Float getFloat(int col) throws SQLException, HibernateException { ! return (Float) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getInteger(int) ! */ ! public Integer getInteger(int col) throws SQLException, HibernateException { ! return (Integer) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getLong(int) ! */ ! public Long getLong(int col) throws SQLException, HibernateException { ! return (Long) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getShort(int) ! */ ! public Short getShort(int col) throws SQLException, HibernateException { ! return (Short) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getString(int) ! */ ! public String getString(int col) throws SQLException, HibernateException { ! return (String) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#afterLast() ! */ ! public void afterLast() throws SQLException, HibernateException { ! rs.afterLast(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#beforeFirst() ! */ ! public void beforeFirst() throws SQLException, HibernateException { ! rs.beforeFirst(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#close() ! */ ! public void close() throws SQLException, HibernateException { ! rs.close(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getLocale(int) ! */ ! public Locale getLocale(int col) throws SQLException, HibernateException { ! return (Locale) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getCurrency(int) ! */ ! /*public Currency getCurrency(int col) throws SQLException, HibernateException { ! return (Currency) get(col); ! }*/ ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getTimeZone(int) ! */ ! public TimeZone getTimeZone(int col) throws SQLException, HibernateException { ! return (TimeZone) get(col); ! } ! ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getType(int) ! */ ! public Type getType(int i) { ! return types[i]; ! } ! ! } --- 1,238 ---- ! //$Id$ ! package cirrus.hibernate.impl; ! ! import java.math.BigDecimal; ! import java.sql.ResultSet; ! import java.sql.SQLException; ! import java.util.Calendar; ! import java.util.Date; ! import java.util.Locale; ! import java.util.TimeZone; ! ! import cirrus.hibernate.HibernateException; ! import cirrus.hibernate.ScrollableResults; ! import cirrus.hibernate.engine.*; ! import cirrus.hibernate.query.QueryTranslator; ! import cirrus.hibernate.type.Type; ! ! public class ScrollableResultsImpl implements ScrollableResults { ! ! private final ResultSet rs; ! private final SessionImplementor sess; ! private final Type[] types; ! private final boolean single; ! private final String[][] names; ! ! /** ! * @see cirrus.hibernate.ScrollableResults#advance(int) ! */ ! public boolean scroll(int i) throws SQLException, HibernateException { ! return rs.relative(i); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#first() ! */ ! public boolean first() throws SQLException, HibernateException { ! return rs.first(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#last() ! */ ! public boolean last() throws SQLException, HibernateException { ! return rs.last(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#advance() ! */ ! public boolean next() throws SQLException, HibernateException { ! return rs.next(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#retreat() ! */ ! public boolean previous() throws SQLException, HibernateException { ! return rs.previous(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#get() ! */ ! public Object[] get() throws SQLException, HibernateException { ! Object[] row = new Object[types.length]; ! for (int i=0; i<types.length; i++) { ! row[i] = types[i].nullSafeGet( rs, names[i], sess, null ); ! } ! return row; ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#get(int) ! */ ! public Object get(int col) throws SQLException, HibernateException { ! return types[col].nullSafeGet( rs, names[col], sess, null ); ! } ! ! public ScrollableResultsImpl(ResultSet rs, SessionImplementor sess, Type[] types) ! throws HibernateException, SQLException { ! ! this.rs=rs; ! this.sess = sess; ! this.types = types; ! ! single = types.length==1; ! ! names = new String[types.length][]; ! for (int i=0; i<types.length; i++) { ! int span = types[i].getColumnSpan( sess.getFactory() ); ! names[i] = new String[span]; ! for ( int j=0; j<span; j++ ) { ! names[i][j] = QueryTranslator.scalarName(i, j); ! } ! } ! ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getBigDecimal(int) ! */ ! public BigDecimal getBigDecimal(int col) ! throws SQLException, HibernateException { ! return (BigDecimal) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getBinary(int) ! */ ! public byte[] getBinary(int col) throws SQLException, HibernateException { ! return (byte[]) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getBoolean(int) ! */ ! public Boolean getBoolean(int col) throws SQLException, HibernateException { ! return (Boolean) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getByte(int) ! */ ! public Byte getByte(int col) throws SQLException, HibernateException { ! return (Byte) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getCharacter(int) ! */ ! public Character getCharacter(int col) throws SQLException, HibernateException { ! return (Character) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getDate(int) ! */ ! public Date getDate(int col) throws SQLException, HibernateException { ! return (Date) get(col); ! } ! ! public Calendar getCalendar(int col) throws SQLException, HibernateException { ! return (Calendar) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getDouble(int) ! */ ! public Double getDouble(int col) throws SQLException, HibernateException { ! return (Double) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getFloat(int) ! */ ! public Float getFloat(int col) throws SQLException, HibernateException { ! return (Float) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getInteger(int) ! */ ! public Integer getInteger(int col) throws SQLException, HibernateException { ! return (Integer) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getLong(int) ! */ ! public Long getLong(int col) throws SQLException, HibernateException { ! return (Long) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getShort(int) ! */ ! public Short getShort(int col) throws SQLException, HibernateException { ! return (Short) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getString(int) ! */ ! public String getString(int col) throws SQLException, HibernateException { ! return (String) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#afterLast() ! */ ! public void afterLast() throws SQLException, HibernateException { ! rs.afterLast(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#beforeFirst() ! */ ! public void beforeFirst() throws SQLException, HibernateException { ! rs.beforeFirst(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#close() ! */ ! public void close() throws SQLException, HibernateException { ! rs.close(); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getLocale(int) ! */ ! public Locale getLocale(int col) throws SQLException, HibernateException { ! return (Locale) get(col); ! } ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getCurrency(int) ! */ ! /*public Currency getCurrency(int col) throws SQLException, HibernateException { ! return (Currency) get(col); ! }*/ ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getTimeZone(int) ! */ ! public TimeZone getTimeZone(int col) throws SQLException, HibernateException { ! return (TimeZone) get(col); ! } ! ! ! /** ! * @see cirrus.hibernate.ScrollableResults#getType(int) ! */ ! public Type getType(int i) { ! return types[i]; ! } ! ! } |