1 56 package org.objectstyle.cayenne.access.jdbc; 57 58 import java.sql.ResultSet ; 59 import java.sql.SQLException ; 60 import java.util.List ; 61 62 import org.objectstyle.cayenne.CayenneException; 63 import org.objectstyle.cayenne.access.OperationObserver; 64 import org.objectstyle.cayenne.access.QueryLogger; 65 import org.objectstyle.cayenne.dba.DbAdapter; 66 import org.objectstyle.cayenne.map.EntityResolver; 67 import org.objectstyle.cayenne.query.GenericSelectQuery; 68 import org.objectstyle.cayenne.query.SQLAction; 69 70 76 public abstract class BaseSQLAction implements SQLAction { 77 78 protected DbAdapter adapter; 79 protected EntityResolver entityResolver; 80 81 public BaseSQLAction(DbAdapter adapter, EntityResolver entityResolver) { 82 this.adapter = adapter; 83 this.entityResolver = entityResolver; 84 } 85 86 public DbAdapter getAdapter() { 87 return adapter; 88 } 89 90 public EntityResolver getEntityResolver() { 91 return entityResolver; 92 } 93 94 97 protected void readResultSet( 98 ResultSet resultSet, 99 RowDescriptor descriptor, 100 GenericSelectQuery query, 101 OperationObserver delegate) throws SQLException , Exception { 102 103 long t1 = System.currentTimeMillis(); 104 JDBCResultIterator resultReader = new JDBCResultIterator( 105 null, 106 null, 107 resultSet, 108 descriptor, 109 query.getFetchLimit()); 110 111 if (!delegate.isIteratedResult()) { 112 List resultRows = resultReader.dataRows(false); 113 QueryLogger.logSelectCount(query.getLoggingLevel(), resultRows.size(), System 114 .currentTimeMillis() 115 - t1); 116 117 delegate.nextDataRows(query, resultRows); 118 } 119 else { 120 try { 121 resultReader.setClosingConnection(true); 122 delegate.nextDataRows(query, resultReader); 123 } 124 catch (Exception ex) { 125 126 try { 127 resultReader.close(); 128 } 129 catch (CayenneException cex) { 130 } 132 133 throw ex; 134 } 135 } 136 } 137 } | Popular Tags |