1 19 20 package org.apache.cayenne.access.util; 21 22 import java.io.PrintWriter ; 23 import java.util.ArrayList ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import java.util.Map ; 28 29 import org.apache.cayenne.CayenneException; 30 import org.apache.cayenne.access.OperationObserver; 31 import org.apache.cayenne.access.ResultIterator; 32 import org.apache.cayenne.query.Query; 33 import org.apache.cayenne.util.Util; 34 35 46 public class DefaultOperationObserver implements OperationObserver { 47 48 protected List globalExceptions = new ArrayList (); 49 protected Map queryExceptions = new HashMap (); 50 51 54 public void printExceptions(PrintWriter out) { 55 if (globalExceptions.size() > 0) { 56 if (globalExceptions.size() == 1) { 57 out.println("Global Exception:"); 58 } 59 else { 60 out.println("Global Exceptions:"); 61 } 62 63 Iterator it = globalExceptions.iterator(); 64 while (it.hasNext()) { 65 Throwable th = (Throwable ) it.next(); 66 th.printStackTrace(out); 67 } 68 } 69 70 if (queryExceptions.size() > 0) { 71 if (queryExceptions.size() == 1) { 72 out.println("Query Exception:"); 73 } 74 else { 75 out.println("Query Exceptions:"); 76 } 77 78 Iterator it = queryExceptions.keySet().iterator(); 79 while (it.hasNext()) { 80 Throwable th = (Throwable ) queryExceptions.get(it.next()); 81 th.printStackTrace(out); 82 } 83 } 84 } 85 86 87 public List getGlobalExceptions() { 88 return globalExceptions; 89 } 90 91 92 public Map getQueryExceptions() { 93 return queryExceptions; 94 } 95 96 100 public boolean hasExceptions() { 101 return globalExceptions.size() > 0 || queryExceptions.size() > 0; 102 } 103 104 public void nextCount(Query query, int resultCount) { 105 } 106 107 public void nextBatchCount(Query query, int[] resultCount) { 108 109 } 110 111 public void nextDataRows(Query query, List dataRows) { 112 } 114 115 119 public void nextDataRows(Query query, ResultIterator it) { 120 if (it != null) { 121 try { 122 it.close(); 123 } 124 catch (CayenneException ex) { 125 nextQueryException(query, ex); 127 } 128 } 129 } 130 131 137 public void nextGeneratedDataRows(Query query, ResultIterator keysIterator) { 138 if (keysIterator != null) { 139 try { 140 keysIterator.close(); 141 } 142 catch (CayenneException ex) { 143 nextQueryException(query, ex); 145 } 146 } 147 } 148 149 public void nextQueryException(Query query, Exception ex) { 150 queryExceptions.put(query, Util.unwindException(ex)); 151 } 152 153 public void nextGlobalException(Exception ex) { 154 globalExceptions.add(Util.unwindException(ex)); 155 } 156 157 160 public boolean isIteratedResult() { 161 return false; 162 } 163 } 164 | Popular Tags |