01: /*
02: * Copyright 2004 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: PersistentIDROF.java,v 1.4 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
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;
16:
17: public class PersistentIDROF implements Query.ResultObjectFactory {
18: private final PersistenceManager pm;
19: private final Class candidateClass;
20: private final int[] fieldNumbers;
21: private final ColumnMapping[] fieldMappings;
22: private final int[] columnNumbersByField;
23: private final ColumnMapping idMapping;
24:
25: public PersistentIDROF(PersistenceManager pm, Class candidateClass) {
26: this (pm, candidateClass, null, null, null);
27: }
28:
29: public PersistentIDROF(PersistenceManager pm, Class candidateClass,
30: int[] fieldNumbers, ColumnMapping[] fieldMappings,
31: int[] columnNumbersByField) {
32: this .pm = pm;
33: this .candidateClass = candidateClass;
34: this .fieldNumbers = fieldNumbers;
35: this .fieldMappings = fieldMappings;
36: this .columnNumbersByField = columnNumbersByField;
37:
38: idMapping = (ColumnMapping) pm.getStoreManager()
39: .getDatabaseAdapter().getMapping(OID.class);
40: }
41:
42: public Object getObject(ResultSet rs) {
43: Object id = idMapping.getObject(pm, rs, 1);
44:
45: if (fieldNumbers != null) {
46: FieldManager fm = new ResultSetGetter(pm, rs,
47: fieldMappings, columnNumbersByField);
48:
49: return pm.getObjectById(id, candidateClass, fieldNumbers,
50: fm);
51: } else
52: return pm.getObjectById(id, candidateClass, false);
53: }
54: }
|