1 10 11 package com.triactive.jdo.store; 12 13 import com.triactive.jdo.model.ClassMetaData; 14 import com.triactive.jdo.util.IntArrayList; 15 import javax.jdo.JDOFatalInternalException; 16 17 18 25 26 abstract class RequestUsingFields extends Request 27 { 28 32 protected final int[] colFields; 33 34 38 protected final int[] cpxFields; 39 40 45 protected final ColumnMapping[] colFieldMappings; 46 47 52 protected final ComplexMapping[] cpxFieldMappings; 53 54 55 62 63 protected RequestUsingFields(final ClassBaseTable table) 64 { 65 this(table, new FieldIterator() 66 { 67 private ClassMetaData cmd = table.getClassMetaData(); 68 private int fn = cmd.getInheritedFieldCount(); 69 private int end = fn + cmd.getFieldCount(); 70 71 public int nextFieldNumber() 72 { 73 return fn < end ? fn++ : -1; 74 } 75 }); 76 } 77 78 79 88 89 protected RequestUsingFields(final ClassBaseTable table, final int[] fieldNumbers) 90 { 91 this(table, new FieldIterator() 92 { 93 private ClassMetaData cmd = table.getClassMetaData(); 94 private int start = cmd.getInheritedFieldCount(); 95 private int end = start + cmd.getFieldCount(); 96 private int idx = 0; 97 98 public int nextFieldNumber() 99 { 100 while (idx < fieldNumbers.length) 101 { 102 int fn = fieldNumbers[idx++]; 103 104 if (fn >= start && fn < end) 105 return fn; 106 } 107 108 return -1; 109 } 110 }); 111 } 112 113 114 118 119 private RequestUsingFields(ClassBaseTable table, FieldIterator fieldIterator) 120 { 121 super(table); 122 123 ClassMetaData cmd = table.getClassMetaData(); 124 int declaredFieldCount = cmd.getFieldCount(); 125 int inheritedFieldCount = cmd.getInheritedFieldCount(); 126 int totalFieldCount = inheritedFieldCount + declaredFieldCount; 127 128 IntArrayList colfn = new IntArrayList(declaredFieldCount); 129 IntArrayList cpxfn = new IntArrayList(declaredFieldCount); 130 ColumnMapping[] colfm = new ColumnMapping[totalFieldCount]; 131 ComplexMapping[] cpxfm = new ComplexMapping[totalFieldCount]; 132 133 int field; 134 135 while ((field = fieldIterator.nextFieldNumber()) >= 0) 136 { 137 if (table.isFieldPersistent(field)) 138 { 139 Mapping m = table.getFieldMapping(field); 140 141 if (m instanceof ColumnMapping) 142 { 143 colfn.add(field); 144 colfm[field] = (ColumnMapping)m; 145 } 146 else if (m instanceof ComplexMapping) 147 { 148 cpxfn.add(field); 149 cpxfm[field] = (ComplexMapping)m; 150 } 151 else 152 throw new JDOFatalInternalException("Unknown mapping: " + m); 153 } 154 } 155 156 if (colfn.isEmpty()) 157 { 158 colFields = null; 159 colFieldMappings = null; 160 } 161 else 162 { 163 colFields = colfn.toArray(); 164 colFieldMappings = colfm; 165 } 166 167 if (cpxfn.isEmpty()) 168 { 169 cpxFields = null; 170 cpxFieldMappings = null; 171 } 172 else 173 { 174 cpxFields = cpxfn.toArray(); 175 cpxFieldMappings = cpxfm; 176 } 177 } 178 179 180 183 private interface FieldIterator 184 { 185 190 int nextFieldNumber(); 191 } 192 } 193 | Popular Tags |