KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > results > persistent > jdbc > CompositeResults


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23
24 package org.hammurapi.results.persistent.jdbc;
25
26 import java.sql.SQLException JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Collection JavaDoc;
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 /**
38  *
39  * @author Pavel Vlasov
40  * @version $Revision: 1.6 $
41  */

42 public class CompositeResults extends DetailedResults implements org.hammurapi.results.CompositeResults {
43     public CompositeResults(int id, ResultsFactory factory) throws SQLException JavaDoc {
44         super(id, factory);
45     }
46     
47     private Collection JavaDoc children;
48     
49     public Collection JavaDoc getChildren() {
50         if (children==null) {
51             try {
52                 Collection JavaDoc childrenKeys=factory.getResultsEngine().getResultChildren(getId(),new ArrayList JavaDoc());
53                 
54                 children=new ConvertingCollection(
55                         childrenKeys,
56                         new Converter() {
57                             public Object JavaDoc convert(Object JavaDoc source) {
58                                 return factory.getResult(source);
59                             }
60                         },
61                         new Converter() {
62                             public Object JavaDoc convert(Object JavaDoc source) {
63                                 return new Integer JavaDoc(((BasicResults) source).getId());
64                             }
65                         });
66             } catch (SQLException JavaDoc 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 JavaDoc name, WaiverSet waiverSet, ResultsFactory factory) throws SQLException JavaDoc {
79         super(name, waiverSet, factory);
80     }
81
82     public int size() {
83         try {
84             return factory.getResultsEngine().getCompositeResultSize(getId())-1;
85         } catch (SQLException JavaDoc e) {
86             throw new HammurapiRuntimeException(e);
87         }
88     }
89 }
90
Popular Tags