EMMA Coverage Report (generated Sat Nov 03 21:53:04 GMT 2007)
[all classes][sf.qof.codegen]

COVERAGE SUMMARY FOR SOURCE FILE [ResultMappingGenerator.java]

nameclass, %method, %block, %line, %
ResultMappingGenerator.java100% (1/1)100% (23/23)97%  (1151/1182)98%  (254/258)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ResultMappingGenerator100% (1/1)100% (23/23)97%  (1151/1182)98%  (254/258)
generateGetString (ResultMapping): void 100% (1/1)90%  (52/58)93%  (13/14)
visit (Mapper, AdapterMapping): void 100% (1/1)94%  (286/305)96%  (55/57)
generateParameterMapping (AbstractDateTimeMapping, Type, Signature, Signature... 100% (1/1)97%  (197/203)98%  (44/45)
ResultMappingGenerator (CodeEmitter, Local, Local, Local, boolean, Local []):... 100% (1/1)100% (21/21)100% (8/8)
generateResultMapping (ResultMapping, Type, Signature, Signature): void 100% (1/1)100% (265/265)100% (59/59)
generateStoreString (ResultMapping): void 100% (1/1)100% (63/63)100% (14/14)
getSqlColumn (ResultMapping): String 100% (1/1)100% (15/15)100% (1/1)
getSqlIndex (ResultMapping): int 100% (1/1)100% (15/15)100% (1/1)
visit (Mapper, AbstractCharacterMapping$CharacterMapping): void 100% (1/1)100% (132/132)100% (28/28)
visit (Mapper, AbstractCharacterMapping$StringMapping): void 100% (1/1)100% (20/20)100% (5/5)
visit (Mapper, AbstractCharacterMapping): void 100% (1/1)100% (5/5)100% (2/2)
visit (Mapper, AbstractDateTimeMapping$DateMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractDateTimeMapping$TimeMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractDateTimeMapping$TimestampMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractDateTimeMapping): void 100% (1/1)100% (5/5)100% (2/2)
visit (Mapper, AbstractNumberMapping$BooleanMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping$ByteMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping$DoubleMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping$FloatMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping$IntegerMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping$LongMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping$ShortMapping): void 100% (1/1)100% (7/7)100% (2/2)
visit (Mapper, AbstractNumberMapping): void 100% (1/1)100% (5/5)100% (2/2)

1/*
2 * Copyright 2007 brunella ltd
3 *
4 * Licensed under the LGPL Version 3 (the "License");
5 * you may not use this file except in compliance with the License.
6 *
7 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
9 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
10 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
11 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
12 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
13 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
14 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
15 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
16 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
17 * THE POSSIBILITY OF SUCH DAMAGE.
18 */
19package sf.qof.codegen;
20 
21import static sf.qof.codegen.Constants.SIG_getBoolean;
22import static sf.qof.codegen.Constants.SIG_getBooleanNamed;
23import static sf.qof.codegen.Constants.SIG_getByte;
24import static sf.qof.codegen.Constants.SIG_getByteNamed;
25import static sf.qof.codegen.Constants.SIG_getDate;
26import static sf.qof.codegen.Constants.SIG_getDateNamed;
27import static sf.qof.codegen.Constants.SIG_getDouble;
28import static sf.qof.codegen.Constants.SIG_getDoubleNamed;
29import static sf.qof.codegen.Constants.SIG_getFloat;
30import static sf.qof.codegen.Constants.SIG_getFloatNamed;
31import static sf.qof.codegen.Constants.SIG_getInt;
32import static sf.qof.codegen.Constants.SIG_getIntNamed;
33import static sf.qof.codegen.Constants.SIG_getLong;
34import static sf.qof.codegen.Constants.SIG_getLongNamed;
35import static sf.qof.codegen.Constants.SIG_getShort;
36import static sf.qof.codegen.Constants.SIG_getShortNamed;
37import static sf.qof.codegen.Constants.SIG_getString;
38import static sf.qof.codegen.Constants.SIG_getStringNamed;
39import static sf.qof.codegen.Constants.SIG_getTime;
40import static sf.qof.codegen.Constants.SIG_getTimeLong;
41import static sf.qof.codegen.Constants.SIG_getTimeNamed;
42import static sf.qof.codegen.Constants.SIG_getTimestamp;
43import static sf.qof.codegen.Constants.SIG_getTimestampNamed;
44import static sf.qof.codegen.Constants.SIG_wasNull;
45import static sf.qof.codegen.Constants.TYPE_Character;
46import static sf.qof.codegen.Constants.TYPE_Date;
47import static sf.qof.codegen.Constants.TYPE_String;
48import static sf.qof.codegen.Constants.TYPE_boolean;
49import static sf.qof.codegen.Constants.TYPE_byte;
50import static sf.qof.codegen.Constants.TYPE_double;
51import static sf.qof.codegen.Constants.TYPE_float;
52import static sf.qof.codegen.Constants.TYPE_int;
53import static sf.qof.codegen.Constants.TYPE_long;
54import static sf.qof.codegen.Constants.TYPE_short;
55import static sf.qof.codegen.Constants.TYPE_sqlDate;
56import static sf.qof.codegen.Constants.TYPE_sqlTime;
57import static sf.qof.codegen.Constants.TYPE_sqlTimestamp;
58 
59import java.lang.reflect.Method;
60 
61import net.sf.cglib.core.CodeEmitter;
62import net.sf.cglib.core.Local;
63import net.sf.cglib.core.Signature;
64 
65import org.objectweb.asm.Label;
66import org.objectweb.asm.Type;
67 
68import sf.qof.adapter.DynamicMappingAdapter;
69import sf.qof.adapter.GeneratorMappingAdapter;
70import sf.qof.mapping.AbstractCharacterMapping;
71import sf.qof.mapping.AbstractDateTimeMapping;
72import sf.qof.mapping.AbstractNumberMapping;
73import sf.qof.mapping.AdapterMapping;
74import sf.qof.mapping.CharacterMappingVisitor;
75import sf.qof.mapping.DateTimeMappingVisitor;
76import sf.qof.mapping.Mapper;
77import sf.qof.mapping.MappingVisitor;
78import sf.qof.mapping.NumberMappingVisitor;
79import sf.qof.mapping.ResultMapping;
80import sf.qof.mapping.AbstractCharacterMapping.CharacterMapping;
81import sf.qof.mapping.AbstractCharacterMapping.StringMapping;
82import sf.qof.mapping.AbstractDateTimeMapping.DateMapping;
83import sf.qof.mapping.AbstractDateTimeMapping.TimeMapping;
84import sf.qof.mapping.AbstractDateTimeMapping.TimestampMapping;
85import sf.qof.mapping.AbstractNumberMapping.BooleanMapping;
86import sf.qof.mapping.AbstractNumberMapping.ByteMapping;
87import sf.qof.mapping.AbstractNumberMapping.DoubleMapping;
88import sf.qof.mapping.AbstractNumberMapping.FloatMapping;
89import sf.qof.mapping.AbstractNumberMapping.IntegerMapping;
90import sf.qof.mapping.AbstractNumberMapping.LongMapping;
91import sf.qof.mapping.AbstractNumberMapping.ShortMapping;
92import sf.qof.util.ReflectionUtils;
93 
94/**
95 * Internal - ResultMappingGenerator is the generator class for result mappings. 
96 */
97public class ResultMappingGenerator implements MappingVisitor, NumberMappingVisitor, CharacterMappingVisitor,
98    DateTimeMappingVisitor {
99 
100  private CodeEmitter co;
101  private Local resultSetOrCallableStatement;
102  private Local result;
103  private Local mapKey;
104  private boolean constructorMappings;
105  private Local[] constructorParameters;
106 
107  public ResultMappingGenerator(CodeEmitter co, Local resultSetOrCallableStatement, Local result, Local mapKey, 
108      boolean constructorMappings, Local[] constructorParameters) {
109    this.co = co;
110    this.resultSetOrCallableStatement = resultSetOrCallableStatement;
111    this.result = result;
112    this.mapKey = mapKey;
113    this.constructorMappings = constructorMappings;
114    this.constructorParameters = constructorParameters;
115  }
116 
117  // implementation of MappingVisitor
118 
119  public final void visit(Mapper mapper, AbstractNumberMapping mapping) {
120    mapping.accept(mapper, (NumberMappingVisitor) this);
121  }
122 
123  public final void visit(Mapper mapper, AbstractCharacterMapping mapping) {
124    mapping.accept(mapper, (CharacterMappingVisitor) this);
125  }
126 
127  public final void visit(Mapper mapper, AbstractDateTimeMapping mapping) {
128    mapping.accept(mapper, (DateTimeMappingVisitor) this);
129  }
130 
131  // implementation of NumberMappingVisitor
132 
133  public void visit(Mapper mapper, ByteMapping mapping) {
134    generateResultMapping(mapping, TYPE_byte, SIG_getByte, SIG_getByteNamed);
135  }
136 
137  public void visit(Mapper mapper, ShortMapping mapping) {
138    generateResultMapping(mapping, TYPE_short, SIG_getShort, SIG_getShortNamed);
139  }
140 
141  public void visit(Mapper mapper, IntegerMapping mapping) {
142    generateResultMapping(mapping, TYPE_int, SIG_getInt, SIG_getIntNamed);
143  }
144 
145  public void visit(Mapper mapper, LongMapping mapping) {
146    generateResultMapping(mapping, TYPE_long, SIG_getLong, SIG_getLongNamed);
147  }
148 
149  public void visit(Mapper mapper, FloatMapping mapping) {
150    generateResultMapping(mapping, TYPE_float, SIG_getFloat, SIG_getFloatNamed);
151  }
152 
153  public void visit(Mapper mapper, DoubleMapping mapping) {
154    generateResultMapping(mapping, TYPE_double, SIG_getDouble, SIG_getDoubleNamed);
155  }
156 
157  public void visit(Mapper mapper, BooleanMapping mapping) {
158    generateResultMapping(mapping, TYPE_boolean, SIG_getBoolean, SIG_getBooleanNamed);
159  }
160 
161  private void generateResultMapping(ResultMapping mapping, Type primitiveType, Signature signatureGet,
162      Signature signatureGetNamed) {
163    if ((constructorMappings && mapping.getConstructorParameter() == null)
164        ||(!constructorMappings && mapping.getConstructorParameter() != null)) {
165      return;
166    }
167 
168    int sqlIndex = getSqlIndex(mapping);
169    String sqlColumn = getSqlColumn(mapping);
170    Method setter = mapping.getSetter();
171    Class<?> type = mapping.getType();
172    Local localResult = null;
173    
174    if (constructorMappings) {
175      type = mapping.getConstructor().getParameterTypes()[mapping.getConstructorParameter() - 1];
176      localResult = co.make_local(Type.getType(type));
177      constructorParameters[mapping.getConstructorParameter() - 1] = localResult;
178    } else {
179      if (mapping.isMapKey()) {
180        localResult = mapKey;
181      } else {
182        localResult = result;
183      }
184    }
185    
186    if (!type.isPrimitive()) {
187      // --------
188      Local localValue = co.make_local(primitiveType);
189      Label labelWasNull = co.make_label();
190      Label labelEnd = co.make_label();
191      co.load_local(resultSetOrCallableStatement);
192      if (sqlColumn == null) {
193        co.push(sqlIndex);
194        co.invoke_interface(resultSetOrCallableStatement.getType(), signatureGet);
195      } else {
196        co.push(sqlColumn);
197        co.invoke_interface(resultSetOrCallableStatement.getType(), signatureGetNamed);
198      }
199      co.store_local(localValue);
200      co.load_local(resultSetOrCallableStatement);
201      co.invoke_interface(resultSetOrCallableStatement.getType(), SIG_wasNull);
202      co.if_jump(CodeEmitter.NE, labelWasNull);
203 
204      if (setter != null) {
205        co.load_local(localResult);
206        co.load_local(localValue);
207        EmitUtils.boxUsingValueOf(co, primitiveType);
208        co.invoke_virtual(Type.getType(setter.getDeclaringClass()), ReflectionUtils.getMethodSignature(setter));
209        co.goTo(labelEnd);
210 
211        co.mark(labelWasNull);
212        co.load_local(localResult);
213        co.aconst_null();
214        co.invoke_virtual(Type.getType(setter.getDeclaringClass()), ReflectionUtils.getMethodSignature(setter));
215      } else {
216        co.load_local(localValue);
217        EmitUtils.boxUsingValueOf(co, primitiveType);
218        co.store_local(localResult);
219        co.goTo(labelEnd);
220 
221        co.mark(labelWasNull);
222        co.aconst_null();
223        co.store_local(localResult);
224      }
225      co.mark(labelEnd);
226    } else {
227      // it's an int, etc
228      // ... = getInt(index);
229      if (setter != null) {
230        co.load_local(localResult);
231      }
232      co.load_local(resultSetOrCallableStatement);
233      if (sqlColumn == null) {
234        co.push(sqlIndex);
235        co.invoke_interface(resultSetOrCallableStatement.getType(), signatureGet);
236      } else {
237        co.push(sqlColumn);
238        co.invoke_interface(resultSetOrCallableStatement.getType(), signatureGetNamed);
239      }
240      if (setter != null) {
241        co.invoke_virtual(Type.getType(setter.getDeclaringClass()), ReflectionUtils.getMethodSignature(setter));
242      } else {
243        co.store_local(localResult);
244      }
245    }
246  }
247 
248  // implementation of CharacterMappingVisitor
249 
250  public final void visit(Mapper mapper, StringMapping mapping) {
251    if ((constructorMappings && mapping.getConstructorParameter() == null)
252        ||(!constructorMappings && mapping.getConstructorParameter() != null)) {
253      return;
254    }
255 
256    generateGetString(mapping);
257    generateStoreString(mapping);
258  }
259 
260  public final void visit(Mapper mapper, CharacterMapping mapping) {
261    if ((constructorMappings && mapping.getConstructorParameter() == null)
262        ||(!constructorMappings && mapping.getConstructorParameter() != null)) {
263      return;
264    }
265 
266    generateGetString(mapping);
267    
268    Class<?> type;
269    if (constructorMappings) {
270      type = mapping.getConstructor().getParameterTypes()[mapping.getConstructorParameter() - 1];
271    } else {
272      type = mapping.getType();
273    }
274    // get first char:
275    // Character c = (s == null) || (s.length() == 0) ? null :
276    // Character.valueOf(s.charAt(0));
277    // char c = (s == null) || (s.length() == 0) ? 0 : s.charAt(0);
278    Local localValue = co.make_local(TYPE_String);
279    co.store_local(localValue);
280 
281    Label labelNull = co.make_label();
282    Label labelEnd = co.make_label();
283 
284    co.load_local(localValue);
285    co.ifnull(labelNull);
286    co.load_local(localValue);
287    co.invoke_virtual(TYPE_String, new Signature("length", "()I"));
288    co.if_jump(CodeEmitter.EQ, labelNull);
289    co.load_local(localValue);
290    co.push(0);
291    co.invoke_virtual(TYPE_String, new Signature("charAt", "(I)C"));
292    if (!type.isPrimitive()) {
293      co.invoke_static(TYPE_Character, new Signature("valueOf", "(C)Ljava/lang/Character;"));
294    }
295    co.goTo(labelEnd);
296 
297    co.mark(labelNull);
298    if (type.isPrimitive()) {
299      co.push(0);
300    } else {
301      co.aconst_null();
302    }
303    co.mark(labelEnd);
304    
305    generateStoreString(mapping);
306  }
307 
308  private void generateGetString(ResultMapping mapping) {
309    int sqlIndex = getSqlIndex(mapping);
310    String sqlColumn = getSqlColumn(mapping);
311    Method setter = mapping.getSetter();
312 
313    // ... = getString(index);
314    if (setter != null) {
315      if (mapping.isMapKey()) {
316        co.load_local(mapKey);
317      } else {
318        co.load_local(result);
319      }
320    }
321    co.load_local(resultSetOrCallableStatement);
322    if (sqlColumn == null) {
323      co.push(sqlIndex);
324      co.invoke_interface(resultSetOrCallableStatement.getType(), SIG_getString);
325    } else {
326      co.push(sqlColumn);
327      co.invoke_interface(resultSetOrCallableStatement.getType(), SIG_getStringNamed);
328    }
329  }
330 
331  private void generateStoreString(ResultMapping mapping) {
332    Method setter = mapping.getSetter();
333    Class<?> type = mapping.getType();
334    Local localResult = null;
335    
336    if (constructorMappings) {
337      type = mapping.getConstructor().getParameterTypes()[mapping.getConstructorParameter() - 1];
338      localResult = co.make_local(Type.getType(type));
339      constructorParameters[mapping.getConstructorParameter() - 1] = localResult;
340    } else {
341      if (mapping.isMapKey()) {
342        localResult = mapKey;
343      } else {
344        localResult = result;
345      }
346    }
347    if (setter != null) {
348      co.invoke_virtual(Type.getType(setter.getDeclaringClass()), ReflectionUtils.getMethodSignature(setter));
349    } else {
350      co.store_local(localResult);
351    }
352  }
353 
354  // implementation of DateTimeVisitor
355 
356  public void visit(Mapper mapper, DateMapping mapping) {
357    generateParameterMapping(mapping, TYPE_sqlDate, SIG_getDate, SIG_getDateNamed);
358  }
359 
360  public void visit(Mapper mapper, TimeMapping mapping) {
361    generateParameterMapping(mapping, TYPE_sqlTime, SIG_getTime, SIG_getTimeNamed);
362  }
363 
364  public void visit(Mapper mapper, TimestampMapping mapping) {
365    generateParameterMapping(mapping, TYPE_sqlTimestamp, SIG_getTimestamp, SIG_getTimestampNamed);
366  }
367 
368  public final void generateParameterMapping(AbstractDateTimeMapping mapping, Type sqlType, Signature sqlTypeGet, Signature sqlTypeGetNamed) {
369    if ((constructorMappings && mapping.getConstructorParameter() == null)
370        ||(!constructorMappings && mapping.getConstructorParameter() != null)) {
371      return;
372    }
373 
374    int sqlIndex = getSqlIndex(mapping);
375    String sqlColumn = getSqlColumn(mapping);
376    Method setter = mapping.getSetter();
377    Class<?> type = mapping.getType();
378    Local localResult = null;
379    
380    if (constructorMappings) {
381      type = mapping.getConstructor().getParameterTypes()[mapping.getConstructorParameter() - 1];
382      localResult = co.make_local(Type.getType(type));
383      constructorParameters[mapping.getConstructorParameter() - 1] = localResult;
384    } else {
385      if (mapping.isMapKey()) {
386        localResult = mapKey;
387      } else {
388        localResult = result;
389      }
390    }
391 
392    // ... = getDate(index);
393    if (setter != null) {
394      if (mapping.isMapKey()) {
395        co.load_local(mapKey);
396      } else {
397        co.load_local(localResult);
398      }
399    }
400    co.load_local(resultSetOrCallableStatement);
401    if (sqlColumn == null) {
402      co.push(sqlIndex);
403      co.invoke_interface(resultSetOrCallableStatement.getType(), sqlTypeGet);
404    } else {
405      co.push(sqlColumn);
406      co.invoke_interface(resultSetOrCallableStatement.getType(), sqlTypeGetNamed);
407    }
408    // convert java.sql.Date to java.util.Date
409    Local date = co.make_local(sqlType);
410    co.store_local(date);
411    Label labelNull = co.make_label();
412    Label labelEnd = co.make_label();
413    co.load_local(date);
414    co.ifnull(labelNull);
415 
416    co.new_instance(TYPE_Date);
417    co.dup();
418    co.load_local(date);
419    co.invoke_virtual(sqlType, SIG_getTimeLong);
420    co.invoke_constructor(TYPE_Date, new Signature("<init>", "(J)V"));
421    co.goTo(labelEnd);
422 
423    co.mark(labelNull);
424    co.aconst_null();
425 
426    co.mark(labelEnd);
427    if (setter != null) {
428      co.invoke_virtual(Type.getType(setter.getDeclaringClass()), ReflectionUtils.getMethodSignature(setter));
429    } else {
430      if (mapping.isMapKey()) {
431        co.store_local(mapKey);
432      } else {
433        co.store_local(localResult);
434      }
435    }
436  }
437 
438  public final void visit(Mapper mapper, AdapterMapping mapping) {
439    if ((constructorMappings && mapping.getConstructorParameter() == null)
440        ||(!constructorMappings && mapping.getConstructorParameter() != null)) {
441      return;
442    }
443 
444    int[] sqlIndexes = mapping.getSqlIndexes();
445    String[] sqlColumns = mapping.getSqlColumns();
446    Method setter = mapping.getSetter();
447    Class<?> type = mapping.getType();
448    Local localResult = null;
449    
450    if (constructorMappings) {
451      type = mapping.getConstructor().getParameterTypes()[mapping.getConstructorParameter() - 1];
452      localResult = co.make_local(Type.getType(type));
453      constructorParameters[mapping.getConstructorParameter() - 1] = localResult;
454    } else {
455      if (mapping.isMapKey()) {
456        localResult = mapKey;
457      } else {
458        localResult = result;
459      }
460    }
461 
462    if (setter != null) {
463      if (mapping.isMapKey()) {
464        co.load_local(mapKey);
465      } else {
466        co.load_local(localResult);
467      }
468    }
469    if (mapping.getAdapter() instanceof GeneratorMappingAdapter) {
470      if (sqlColumns != null) {
471        ((GeneratorMappingAdapter) mapping.getAdapter()).generateFromResultSet(mapping, co, resultSetOrCallableStatement, sqlColumns);
472      } else {
473        ((GeneratorMappingAdapter) mapping.getAdapter()).generateFromResult(mapping, co, resultSetOrCallableStatement, sqlIndexes);
474      }
475      // type check of the result
476      if (mapping.isMapKey()) {
477        if (!mapping.getMapKeyType().isPrimitive()) {
478          co.checkcast(Type.getType(mapping.getMapKeyType()));
479        }
480      } else {
481        if (!type.isPrimitive()) {
482          co.checkcast(Type.getType(type));
483        }
484      }
485    } else if (mapping.getAdapter() instanceof DynamicMappingAdapter) {
486      co.getfield(QueryObjectGenerator.getAdapterFieldName(mapping.getAdapter().getClass()));
487      co.load_local(resultSetOrCallableStatement);
488      if (sqlColumns != null) {
489        // push columns
490        co.push(sqlColumns.length);
491        co.newarray(TYPE_String);
492        for (int i = 0; i < sqlColumns.length; i++) {
493          co.dup();
494          co.push(i);
495          co.push(sqlColumns[i]);
496          co.array_store(TYPE_String);
497        }
498        co.invoke_interface(Type.getType(DynamicMappingAdapter.class), new Signature("get",
499            "(Ljava/sql/ResultSet;[Ljava/lang/String;)Ljava/lang/Object;"));
500      } else {
501        // push indexes
502        co.push(sqlIndexes.length);
503        co.newarray(TYPE_int);
504        for (int i = 0; i < sqlIndexes.length; i++) {
505          co.dup();
506          co.push(i);
507          co.push(sqlIndexes[i]);
508          co.array_store(TYPE_int);
509        }
510        // either get from a ResultSet or CallableStatement
511        co.invoke_interface(Type.getType(DynamicMappingAdapter.class), new Signature("get",
512            "("+ resultSetOrCallableStatement.getType().getDescriptor() + "[I)Ljava/lang/Object;"));
513      }
514      if (mapping.isMapKey()) {
515        co.checkcast(Type.getType(mapping.getMapKeyType()));
516      } else {
517        co.checkcast(Type.getType(mapping.getType()));
518      }
519    } else {
520      throw new RuntimeException("Unsupported adapter type " + mapping.getAdapter());
521    }
522    if (setter != null) {
523      co.invoke_virtual(Type.getType(setter.getDeclaringClass()), ReflectionUtils.getMethodSignature(setter));
524    } else {
525      if (mapping.isMapKey()) {
526        co.store_local(mapKey);
527      } else {
528        co.store_local(localResult);
529      }
530    }
531  }
532 
533  private String getSqlColumn(ResultMapping mapping) {
534    return mapping.getSqlColumns() != null && mapping.getSqlColumns().length == 1 ? mapping.getSqlColumns()[0] : null;
535  }
536 
537  private int getSqlIndex(ResultMapping mapping) {
538    return mapping.getSqlIndexes() != null && mapping.getSqlIndexes().length == 1 ? mapping.getSqlIndexes()[0] : -1;
539  }
540}

[all classes][sf.qof.codegen]
EMMA 2.0.5312 (C) Vladimir Roubtsov