KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > store > PersistentIDROF


1 /*
2  * Copyright 2004 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: PersistentIDROF.java,v 1.4 2004/01/18 03:01:06 jackknifebarber Exp $
9  */

10
11 package com.triactive.jdo.store;
12
13 import com.triactive.jdo.FieldManager;
14 import com.triactive.jdo.PersistenceManager;
15 import java.sql.ResultSet JavaDoc;
16
17
18 public class PersistentIDROF implements Query.ResultObjectFactory
19 {
20     private final PersistenceManager pm;
21     private final Class JavaDoc candidateClass;
22     private final int[] fieldNumbers;
23     private final ColumnMapping[] fieldMappings;
24     private final int[] columnNumbersByField;
25     private final ColumnMapping idMapping;
26
27     public PersistentIDROF(PersistenceManager pm, Class JavaDoc candidateClass)
28     {
29         this(pm, candidateClass, null, null, null);
30     }
31
32     public PersistentIDROF(PersistenceManager pm,
33                            Class JavaDoc candidateClass,
34                            int[] fieldNumbers,
35                            ColumnMapping[] fieldMappings,
36                            int[] columnNumbersByField)
37     {
38         this.pm = pm;
39         this.candidateClass = candidateClass;
40         this.fieldNumbers = fieldNumbers;
41         this.fieldMappings = fieldMappings;
42         this.columnNumbersByField = columnNumbersByField;
43
44         idMapping = (ColumnMapping)pm.getStoreManager().getDatabaseAdapter().getMapping(OID.class);
45     }
46
47     public Object JavaDoc getObject(ResultSet JavaDoc rs)
48     {
49         Object JavaDoc id = idMapping.getObject(pm, rs, 1);
50
51         if (fieldNumbers != null)
52         {
53             FieldManager fm = new ResultSetGetter(pm, rs, fieldMappings, columnNumbersByField);
54
55             return pm.getObjectById(id, candidateClass, fieldNumbers, fm);
56         }
57         else
58             return pm.getObjectById(id, candidateClass, false);
59     }
60 }
61
Popular Tags