1 19 20 package org.apache.cayenne.access.jdbc; 21 22 import java.sql.ResultSet ; 23 import java.sql.SQLException ; 24 import java.util.List ; 25 26 import org.apache.cayenne.CayenneException; 27 import org.apache.cayenne.access.OperationObserver; 28 import org.apache.cayenne.access.QueryLogger; 29 import org.apache.cayenne.dba.DbAdapter; 30 import org.apache.cayenne.map.EntityResolver; 31 import org.apache.cayenne.query.Query; 32 import org.apache.cayenne.query.SQLAction; 33 34 40 public abstract class BaseSQLAction implements SQLAction { 41 42 protected DbAdapter adapter; 43 protected EntityResolver entityResolver; 44 45 public BaseSQLAction(DbAdapter adapter, EntityResolver entityResolver) { 46 this.adapter = adapter; 47 this.entityResolver = entityResolver; 48 } 49 50 public DbAdapter getAdapter() { 51 return adapter; 52 } 53 54 public EntityResolver getEntityResolver() { 55 return entityResolver; 56 } 57 58 61 protected void readResultSet( 62 ResultSet resultSet, 63 RowDescriptor descriptor, 64 Query query, 65 OperationObserver delegate) throws SQLException , Exception { 66 67 long t1 = System.currentTimeMillis(); 68 JDBCResultIterator resultReader = new JDBCResultIterator( 69 null, 70 null, 71 resultSet, 72 descriptor, 73 query.getMetaData(getEntityResolver()).getFetchLimit()); 74 75 if (!delegate.isIteratedResult()) { 76 List resultRows = resultReader.dataRows(false); 77 QueryLogger 78 .logSelectCount(resultRows.size(), System.currentTimeMillis() - t1); 79 80 delegate.nextDataRows(query, resultRows); 81 } 82 else { 83 try { 84 resultReader.setClosingConnection(true); 85 delegate.nextDataRows(query, resultReader); 86 } 87 catch (Exception ex) { 88 89 try { 90 resultReader.close(); 91 } 92 catch (CayenneException cex) { 93 } 95 96 throw ex; 97 } 98 } 99 } 100 } 101 | Popular Tags |