01: package net.sourceforge.jaxor.util;
02:
03: import net.sourceforge.jaxor.PrimaryKeySet;
04: import net.sourceforge.jaxor.api.FieldAdapter;
05:
06: import java.util.ArrayList;
07: import java.util.List;
08:
09: /**
10: * Created By: Mike
11: * Date: Dec 20, 2003
12: * Time: 10:39:48 PM
13: *
14: * Last Checkin: $Author: mrettig $
15: * Date: $Date: 2004/01/21 04:09:52 $
16: * Revision: $Revision: 1.3 $
17: */
18:
19: /**
20: * This class creates a new entity row instance by adding field adapters. This is for performance reasons so
21: * we don't keep recalculating the row list and primary key.
22: */
23: public class EntityRowBuilder {
24: private final List _list = new ArrayList();
25: private List _pkList = new ArrayList();
26:
27: public FieldAdapter[] getFields() {
28: return toFieldAdapter(_list);
29: }
30:
31: public PrimaryKeySet getPrimaryKey() {
32: return new PrimaryKeySet(toFieldAdapter(_pkList));
33: }
34:
35: public void add(FieldAdapter adapt) {
36: _list.add(adapt);
37: if (adapt.isPrimaryKey())
38: _pkList.add(adapt);
39: }
40:
41: private FieldAdapter[] toFieldAdapter(List list) {
42: return (FieldAdapter[]) list.toArray(new FieldAdapter[list
43: .size()]);
44: }
45: }
|