1 23 24 package org.hammurapi.results.persistent.jdbc; 25 26 import java.sql.SQLException ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 30 import org.hammurapi.HammurapiRuntimeException; 31 import org.hammurapi.WaiverSet; 32 import org.hammurapi.results.AggregatedResults; 33 34 import com.pavelvlasov.convert.Converter; 35 import com.pavelvlasov.util.ConvertingCollection; 36 37 42 public class CompositeResults extends DetailedResults implements org.hammurapi.results.CompositeResults { 43 public CompositeResults(int id, ResultsFactory factory) throws SQLException { 44 super(id, factory); 45 } 46 47 private Collection children; 48 49 public Collection getChildren() { 50 if (children==null) { 51 try { 52 Collection childrenKeys=factory.getResultsEngine().getResultChildren(getId(),new ArrayList ()); 53 54 children=new ConvertingCollection( 55 childrenKeys, 56 new Converter() { 57 public Object convert(Object source) { 58 return factory.getResult(source); 59 } 60 }, 61 new Converter() { 62 public Object convert(Object source) { 63 return new Integer (((BasicResults) source).getId()); 64 } 65 }); 66 } catch (SQLException e) { 67 throw new HammurapiRuntimeException(e); 68 } 69 } 70 return children; 71 } 72 73 public void add(AggregatedResults child) { 74 aggregate(child); 75 children=null; 76 } 77 78 CompositeResults(String name, WaiverSet waiverSet, ResultsFactory factory) throws SQLException { 79 super(name, waiverSet, factory); 80 } 81 82 public int size() { 83 try { 84 return factory.getResultsEngine().getCompositeResultSize(getId())-1; 85 } catch (SQLException e) { 86 throw new HammurapiRuntimeException(e); 87 } 88 } 89 } 90 | Popular Tags |